带引号的三元组中的扩展路径表达式?

问题描述 投票:0回答:1

我正在尝试查询类似维基百科的内容,其中对象相互连接,并且边缘具有链接它们的段落。我希望在弄清楚链接和实体的语义值之前先了解一下查询部分。

数据集目前看起来像这样(最终可能会改变):

PREFIX : <http://justin.abrah.ms/knowledge_base#>

:SteamCooked :title "Steaming" .

:KoreanFood 
  :title "Korean Food" ;
  :linksTo :SteamCooked
  .

:AlternativeMedicine :title "Alternative Medicine" .

:Cheong
  :title "Cheong (food)";
  :linksTo :KoreanFood;
  :linksTo :AlternativeMedicine .


<< :Cheong :linksTo :KoreanFood >> :inParagraph "Cheong (청; 淸) is a name for various sweetened foods in the form of syrups, marmalades, and fruit preserves. In Korean cuisine, cheong is used as a tea base, as a honey-or-sugar-substitute in cooking, as a condiment, and also as an alternative medicine to treat the common cold and other minor illnesses." .

<< :Cheong :linksTo :AlternativeMedicine >> :inParagraph "Cheong (청; 淸) is a name for various sweetened foods in the form of syrups, marmalades, and fruit preserves. In Korean cuisine, cheong is used as a tea base, as a honey-or-sugar-substitute in cooking, as a condiment, and also as an alternative medicine to treat the common cold and other minor illnesses." .

我可以使用此 sparql 查询来查询连接:

PREFIX : <http://justin.abrah.ms/knowledge_base#>

SELECT ?midNode WHERE {
    ?am :title "Alternative Medicine" .
    ?steam :title "Steaming" .
    ?am (:linksTo|^:linksTo)* ?midNode .
  ?midNode (:linksTo|^:linksTo)* ?steam .
}

无法似乎弄清楚如何查询边缘旁边的这些节点。我发现的最大问题是像

(:linksTo|^:linksTo)*
这样的路径扩展在引用的三元组内不起作用。这是 sparql 的限制吗?或者我只是错过了一个关键概念?

sparql rdf graphdb rdf-star
1个回答
0
投票

感谢上面的uninformeduser,我最终得到了这个查询,它将正确地为我提供相关段落的路径信息。

PREFIX : <http://justin.abrah.ms/knowledge_base#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?s ?o ?paragraph WHERE {
    ?am :title "Alternative Medicine" .
    ?kf :title "Korean Food" .
    
    ?term :inParagraph ?paragraph .
    filter(rdf:isTriple(?term)) .
    bind(rdf:subject(?term) as ?s) .
    bind(rdf:object(?term) as ?o) .
    filter(rdf:subject(?term) = ?midNode)
    
    ?am (:linksTo|^:linksTo)* ?midNode .
    ?midNode (:linksTo|^:linksTo)* ?kf .
    
    filter(?midNode = ?s) .
}

根据我自己的理解,这个查询说:

分解一个

:inParagraph
主语,从其左侧提取主语和宾语。

找到一种通过未知的

?am
将术语 A (
?kf
) 与术语 B (
?midNode
) 联系起来的方法。

确保

?midnode
包含在我们的
:inParagraph
条目中。

© www.soinside.com 2019 - 2024. All rights reserved.