基于谓词节点检索特定RDF图三元组

基于谓词节点检索特定RDF图三元组,rdf,dotnetrdf,Rdf,Dotnetrdf,我使用dotnetrdf发送Sparql构造查询并计算结果 首先,我试图找到表示给定类型的个体的所有Uri节点,比如 http://www.example.com/InterestingThing 因此,我想使用,传递http://www.w3.org/1999/02/22-rdf-syntax-ns#type作为谓词和http://www.example.com/InterestingThing作为一个对象。该方法需要两个对象来实现,因此我尝试使用图的 问题:找不到谓词。 在调试器中查看IG

我使用dotnetrdf发送Sparql
构造
查询并计算结果

首先,我试图找到表示给定类型的个体的所有Uri节点,比如

http://www.example.com/InterestingThing
因此,我想使用,传递
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
作为谓词和
http://www.example.com/InterestingThing
作为一个对象。该方法需要两个对象来实现,因此我尝试使用图的

问题:找不到谓词。 在调试器中查看
IGraph
对象时,似乎
GetUriNode
只能找到图形中包含的内容,并且只包含用作主题或对象的Uri节点,但没有用作谓词的Uri节点

现在,谓词Uri节点显然就在那里——我在探索图的结构时可以看到它们。它们出现在中,可以直接从该对象检索,也可以在同一对象的中找到

有趣的是,
IGraph
的一些查询方法,例如or确实有重载,只接受一个而不是一个-但不接受

现在,各种可能的解决办法显而易见:

  • 使用只接受一个
    Uri
    实例的
    GetTriplesWithPredicate
    重载,然后手动过滤生成的三元组
  • 手动搜索所有三元组以获得所需的三元组
  • 手动搜索
    谓词节点列表
    ,并找到具有已搜索URI的节点
不过,所有这些看起来都不必要地麻烦,因为现有的方法乍一看就表明,应该能够使用
GetUriNode
检索两个节点,然后将它们传递给一个现成的查询方法,例如
GetTriplesWithObjectPredicate

因此,我的问题是:

我是否遗漏了dotnetrdf库中或概念上RDF中的任何内容,或者这种行为是否会给开发人员带来设计上的障碍?

下面是一个C#测试用例来重现问题(查询DBpedia):

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用VDS.RDF;
使用VDS.RDF.Query;
名称空间测试
{
班级计划
{
公共静态void Main(字符串[]args)
{
//质疑
//所有要分析的条目都声明为属于临时类型,并且
//两个属性映射到临时属性标识符。
Console.WriteLine();
var endpoint=new SparqlRemoteEndpoint(新Uri(“http://dbpedia.org/sparql"));
string query=“前缀dbpedia owl:\n”
+“前缀ex:\n”
+“\n”
+“构造{\n”
+“?r a ex:记录。\n”
+“?r ex:prop1?v1。\n”
+“?r ex:prop2?v2。\n”
+“}\n”
+“其中{\n”
+“{\n”
+“选择?r\n”
+“其中{\n”
+“?r a dbpedia owl:工作。\n”
+“筛选器(存在{r dbpedia owl:originalLanguage[]}&&EXISTS{r dbpedia owl:author/dbpedia owl:birthPlace[]})。\n”
+“}限制5\n”
+“}\n”
+“?r dbpedia owl:原始语言?v1。\n”
+“?r dbpedia owl:作者/dbpedia owl:出生地?v2。\n”
+ "}";
Console.WriteLine(查询);
Console.WriteLine();
IGraph graph=endpoint.QueryWithResultGraph(查询);
PrintNodes(“IGraph.Nodes”,graph.Nodes);
Console.WriteLine(“来自IGraph.triples:”)的所有三元组;
foreach(图中的变量三元组。三元组){
Console.WriteLine(“-S:+NodeToString(triple.Subject));
WriteLine(“P:+NodeToString(triple.Predicate));
WriteLine(“O:+NodeToString(triple.Object));
}
Console.WriteLine();
PrintNodes(“IGraph.Triples.SubjectNodes”,graph.Triples.SubjectNodes);
PrintNodes(“IGraph.Triples.PredicateNodes”,graph.Triples.PredicateNodes);
PrintNodes(“IGraph.Triples.ObjectNodes”,graph.Triples.ObjectNodes);
//图形分析
//下面的代码尝试准确地检索临时文件的项
//键入“记录”。
var typeNode=TryFindUriNode(图形,新Uri(NamespaceMapper.RDF+“类型”);
var recordNode=TryFindUriNode(图形,新Uri(“http://www.example.com/record"));
Console.WriteLine();
TryFindAllNodes(“subjects”,graph,graph.Triples.SubjectNodes.OfType().Select(node=>node.Uri));
TryFindAllNodes(“谓词”,graph,graph.Triples.PredicateNodes.OfType().Select(node=>node.Uri));
TryFindAllNodes(“objects”、graph、graph.Triples.ObjectNodes.OfType().Select(node=>node.Uri));
Console.WriteLine();
var createdTypeNode=graph.CreateUriNode(新Uri(NamespaceMapper.RDF+“类型”);
var createdRecordNode=graph.CreateUriNode(新Uri(“http://www.example.com/record"));
if((typeNode!=null)&&(recordNode!=null)){
WriteLine(“{0}个三元组,具有找到的谓词和找到的对象。”,
graph.GetTriplesWithPredicateObject(typeNode,recordNode.Count());
}
if(typeNode!=null){
WriteLine(“{0}个三元组,具有找到的谓词和创建的对象。”,
graph.GetTriplesWithPredicateObject(typeNode,createdRecordNode.Count());
}
if(recordNode!=null){
Console.WriteLine(“{0}个三元组),创建了pred
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX ex: <http://www.example.com/>

CONSTRUCT {
  ?r a ex:record.
  ?r ex:prop1 ?v1.
  ?r ex:prop2 ?v2.
}
WHERE {
  {
    SELECT ?r
    WHERE {
      ?r a dbpedia-owl:Work.
      FILTER(EXISTS { ?r dbpedia-owl:originalLanguage [] } && EXISTS { ?r dbpedia-owl:author/dbpedia-owl:birthPlace [] }).
    } LIMIT 5
  }
  ?r dbpedia-owl:originalLanguage ?v1.
  ?r dbpedia-owl:author/dbpedia-owl:birthPlace ?v2.
}

IGraph.Nodes:
- http://dbpedia.org/resource/Electra_(Sophocles) (UriNode)
- http://dbpedia.org/resource/Peer_Gynt (UriNode)
- http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
- http://dbpedia.org/resource/The_Field (UriNode)
- http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)
- http://www.example.com/record (UriNode)
- http://dbpedia.org/resource/Ancient_Greek (UriNode)
- http://dbpedia.org/resource/Colonus (UriNode)
- http://dbpedia.org/resource/Norwegian_language (UriNode)
- http://dbpedia.org/resource/Skien (UriNode)
- http://dbpedia.org/resource/Norway (UriNode)
- http://dbpedia.org/resource/Czech_language (UriNode)
- http://dbpedia.org/resource/Kingdom_of_Bohemia (UriNode)
- http://dbpedia.org/resource/Bohemia (UriNode)
- http://dbpedia.org/resource/Mal%C3%A9_Svato%C5%88ovice (UriNode)
- http://dbpedia.org/resource/Austria-Hungary (UriNode)
- http://dbpedia.org/resource/English_language (UriNode)
- http://dbpedia.org/resource/Irish_Free_State (UriNode)
- http://dbpedia.org/resource/Listowel (UriNode)
- http://dbpedia.org/resource/County_Kerry (UriNode)

All triples from IGraph.Triples:
- S: http://dbpedia.org/resource/Electra_(Sophocles) (UriNode)
  P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
  O: http://www.example.com/record (UriNode)
- S: http://dbpedia.org/resource/Electra_(Sophocles) (UriNode)
  P: http://www.example.com/prop1 (UriNode)
  O: http://dbpedia.org/resource/Ancient_Greek (UriNode)
- S: http://dbpedia.org/resource/Electra_(Sophocles) (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Colonus (UriNode)
- S: http://dbpedia.org/resource/Peer_Gynt (UriNode)
  P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
  O: http://www.example.com/record (UriNode)
- S: http://dbpedia.org/resource/Peer_Gynt (UriNode)
  P: http://www.example.com/prop1 (UriNode)
  O: http://dbpedia.org/resource/Norwegian_language (UriNode)
- S: http://dbpedia.org/resource/Peer_Gynt (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Skien (UriNode)
- S: http://dbpedia.org/resource/Peer_Gynt (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Norway (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
  O: http://www.example.com/record (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.example.com/prop1 (UriNode)
  O: http://dbpedia.org/resource/Czech_language (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Kingdom_of_Bohemia (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Bohemia (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Mal%C3%A9_Svato%C5%88ovice (UriNode)
- S: http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Austria-Hungary (UriNode)
- S: http://dbpedia.org/resource/The_Field (UriNode)
  P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
  O: http://www.example.com/record (UriNode)
- S: http://dbpedia.org/resource/The_Field (UriNode)
  P: http://www.example.com/prop1 (UriNode)
  O: http://dbpedia.org/resource/English_language (UriNode)
- S: http://dbpedia.org/resource/The_Field (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Irish_Free_State (UriNode)
- S: http://dbpedia.org/resource/The_Field (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Listowel (UriNode)
- S: http://dbpedia.org/resource/The_Field (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/County_Kerry (UriNode)
- S: http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)
  P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
  O: http://www.example.com/record (UriNode)
- S: http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)
  P: http://www.example.com/prop1 (UriNode)
  O: http://dbpedia.org/resource/Norwegian_language (UriNode)
- S: http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Skien (UriNode)
- S: http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)
  P: http://www.example.com/prop2 (UriNode)
  O: http://dbpedia.org/resource/Norway (UriNode)

IGraph.Triples.SubjectNodes:
- http://dbpedia.org/resource/Electra_(Sophocles) (UriNode)
- http://dbpedia.org/resource/Peer_Gynt (UriNode)
- http://dbpedia.org/resource/Pictures_from_the_Insects'_Life (UriNode)
- http://dbpedia.org/resource/The_Field (UriNode)
- http://dbpedia.org/resource/The_Lady_from_the_Sea (UriNode)

IGraph.Triples.PredicateNodes:
- http://www.w3.org/1999/02/22-rdf-syntax-ns#type (UriNode)
- http://www.example.com/prop1 (UriNode)
- http://www.example.com/prop2 (UriNode)

IGraph.Triples.ObjectNodes:
- http://www.example.com/record (UriNode)
- http://dbpedia.org/resource/Ancient_Greek (UriNode)
- http://dbpedia.org/resource/Colonus (UriNode)
- http://dbpedia.org/resource/Norwegian_language (UriNode)
- http://dbpedia.org/resource/Skien (UriNode)
- http://dbpedia.org/resource/Norway (UriNode)
- http://dbpedia.org/resource/Czech_language (UriNode)
- http://dbpedia.org/resource/Kingdom_of_Bohemia (UriNode)
- http://dbpedia.org/resource/Bohemia (UriNode)
- http://dbpedia.org/resource/Mal%C3%A9_Svato%C5%88ovice (UriNode)
- http://dbpedia.org/resource/Austria-Hungary (UriNode)
- http://dbpedia.org/resource/English_language (UriNode)
- http://dbpedia.org/resource/Irish_Free_State (UriNode)
- http://dbpedia.org/resource/Listowel (UriNode)
- http://dbpedia.org/resource/County_Kerry (UriNode)

Trying to find all subjects:
http://dbpedia.org/resource/Electra_(Sophocles) WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Peer_Gynt WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Pictures_from_the_Insects'_Life WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/The_Field WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/The_Lady_from_the_Sea WAS found by IGraph.GetUriNode.
Trying to find all predicates:
http://www.w3.org/1999/02/22-rdf-syntax-ns#type was NOT found by IGraph.GetUriNode.
http://www.example.com/prop1 was NOT found by IGraph.GetUriNode.
http://www.example.com/prop2 was NOT found by IGraph.GetUriNode.
Trying to find all objects:
http://www.example.com/record WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Ancient_Greek WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Colonus WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Norwegian_language WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Skien WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Norway WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Czech_language WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Kingdom_of_Bohemia WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Bohemia WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Mal‚_Svatonovice WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Austria-Hungary WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/English_language WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Irish_Free_State WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/Listowel WAS found by IGraph.GetUriNode.
http://dbpedia.org/resource/County_Kerry WAS found by IGraph.GetUriNode.

http://www.w3.org/1999/02/22-rdf-syntax-ns#type was NOT found by IGraph.GetUriNode.
http://www.example.com/record WAS found by IGraph.GetUriNode.
5 triple(s) with created predicate and found object.
5 triple(s) with created predicate and created object.