Select 如何使用sparql从具有给定对象属性和数据属性值的本体中选择实例?

Select 如何使用sparql从具有给定对象属性和数据属性值的本体中选择实例?,select,sparql,instance,Select,Sparql,Instance,嗨,朋友们,这是我的owl文件的一部分。我需要为我的应用程序选择sparql代码。例如,选择研究M201和CS101的实例,first_name=Josef,studentId=266814 <rdf:RDF xmlns="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#" xml:base="http://www.semanticweb.org/ozgur/ontologies/2019/9/

嗨,朋友们,这是我的owl文件的一部分。我需要为我的应用程序选择sparql代码。例如,选择研究M201和CS101的实例,first_name=Josef,studentId=266814

<rdf:RDF xmlns="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#"
 xml:base="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:uni="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2"/>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#Student1">
<rdf:type rdf:resource="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#Student"/>
<studies rdf:resource="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#CS101"/>
<studies rdf:resource="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#M201"/>
<studies rdf:resource="http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#M204"/>
<first_name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Josef</first_name>
<last_name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Baker</last_name>
<studentID rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">266814</studentID>
</owl:NamedIndividual>

约瑟夫
面包师
266814

为了便于阅读,下面是海龟转换(它基本上编写了
WHERE
子句本身):

@前缀owl:。
@前缀ns0:。
@前缀xsd:。
猫头鹰:本体论。
一只猫头鹰:名字叫个人;
ns0:研究ns0:CS101、ns0:M201、ns0:M204;
ns0:名字“约瑟夫”^^xsd:string;
ns0:姓氏“Baker”^^xsd:string;
ns0:studentID 266814。
所以您的SPARQL查询看起来像

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ns0: <http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?firstName ?lastName
WHERE
{
    ?student a owl:NamedIndividual ;
        ns0:first_name ?firstName ;
        ns0:last_name ?lastName ;
        ns0:studentID ?studentID ;
        ns0:studies ns0:M201 ;
        ns0:studies ns0:CS101 .

    FILTER (?studentID = 266814 && ?firstName = "Josef") .
}
前缀owl:
前缀ns0:
前缀xsd:
选择不同的?名字?姓氏
哪里
{
?学生a猫头鹰:姓名为个人;
ns0:名字?名字;
ns0:姓氏?姓氏;
ns0:学生ID?学生ID;
ns0:研究ns0:M201;
ns0:研究ns0:CS101。
过滤器(?studentID=266814&&?firstName=“约瑟夫”)。
}

WHERE
子句中,您只需描述需要匹配结果的RDF图结构:)

@jacky谢谢!如果你不介意接受这个答案,那就太好了!为什么你以前什么都没试过?我是说,这是任务的一部分,对吗?您应该首先开始阅读RDF和SPARQL。网上有很好的教程,即使是初学者。此外,W3C官方文档的信息量也很大。
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ns0: <http://www.semanticweb.org/ozgur/ontologies/2019/9/untitled-ontology-2#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?firstName ?lastName
WHERE
{
    ?student a owl:NamedIndividual ;
        ns0:first_name ?firstName ;
        ns0:last_name ?lastName ;
        ns0:studentID ?studentID ;
        ns0:studies ns0:M201 ;
        ns0:studies ns0:CS101 .

    FILTER (?studentID = 266814 && ?firstName = "Josef") .
}