如何使用sparql从RDF三元组中提取主语(名称)与谓词

如何使用sparql从RDF三元组中提取主语(名称)与谓词,rdf,sparql,n-triples,Rdf,Sparql,N Triples,如果这是三人组,我想找到教授研究生课程的助理教授 http://www.example.com/teach.rdfs/John http://www.example.com/teach.rdfs#position "Full Professor" http://www.example.com/teach.rdfs/John http://www.example.com/teach.rdfs#course"Math" http://www.example.com/tea

如果这是三人组,我想找到教授研究生课程的助理教授

http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#position "Full Professor"        

http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#course"Math"

http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#student"Undergraduate"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#position "Assistant Professor"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#course"Web Engineering"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#student"Graduate"

如何使用SPARQL提取上述日期据我所知,您的数据没有任何合法的RDF序列化,但将其放入N3序列化中相当容易。看到这两个
http://.../teach.rdfs#
http://.../teach.rdfs/
用作同一文档中的前缀。看到一个或另一个是很常见的,但不是两个都看到。但这并不违法,所以我们可以用它。以下是N3格式的数据文件,
data.N3

 Lecturer       Position

 Arthur         Assistant Professor 
这个查询唯一有点不寻常的地方是使用了
VALUES?position{“助理教授”}
。我使用该表单的原因是,您想要的结果在输出中包含了
“助理教授”
。如果我们排除
值…
部分,我们可以将模式重写为

PREFIX teach1: <http://www.example.com/teach.rdfs/>
PREFIX teach2: <http://www.example.com/teach.rdfs#>

SELECT ?lecturer ?position WHERE {
  VALUES ?position { "Assistant Professor" }
  ?lecturer teach2:position ?position ;
            teach2:student "Graduate" .
}
并且仍然找到相同的
?讲师
s,但是没有绑定到
“助理教授”
的变量。有了数据和查询,我们可以使用Jena的ARQ命令行工具对数据运行查询:

  ?lecturer teach2:position "Assistant Professor" ;
            teach2:student "Graduate" .

据我所知,您的数据没有任何合法的RDF序列化,但将其放入N3序列化中相当容易。看到这两个
http://.../teach.rdfs#
http://.../teach.rdfs/
用作同一文档中的前缀。看到一个或另一个是很常见的,但不是两个都看到。但这并不违法,所以我们可以用它。以下是N3格式的数据文件,
data.N3

 Lecturer       Position

 Arthur         Assistant Professor 
这个查询唯一有点不寻常的地方是使用了
VALUES?position{“助理教授”}
。我使用该表单的原因是,您想要的结果在输出中包含了
“助理教授”
。如果我们排除
值…
部分,我们可以将模式重写为

PREFIX teach1: <http://www.example.com/teach.rdfs/>
PREFIX teach2: <http://www.example.com/teach.rdfs#>

SELECT ?lecturer ?position WHERE {
  VALUES ?position { "Assistant Professor" }
  ?lecturer teach2:position ?position ;
            teach2:student "Graduate" .
}
并且仍然找到相同的
?讲师
s,但是没有绑定到
“助理教授”
的变量。有了数据和查询,我们可以使用Jena的ARQ命令行工具对数据运行查询:

  ?lecturer teach2:position "Assistant Professor" ;
            teach2:student "Graduate" .