我使用protege工具创建了一个OWL文件,我已经定义了一些关系。现在我想使用sparql查询数据。 如果我给出姓名,我需要获得该人的所有相关细节。对于例如如果我查询尼克,它应该给我所有的细节,如城市多伦多,性别作为男性等。请在查询部分建议。
"SELECT ?person ?city ?idPropOf ?Gender ?appersIn WHERE { " +
" ?person a base:Person ;"+
" base:livesIn ?city ;"+
" base:idPropOf ?idPropOf ;"+
" base:hasGender ?Gender ;"+
" base:appearsIn ?appersIn"+
"}";
上面的查询返回如下结果:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| person | city | idPropOf | Gender | appersIn |
=====================================================================================================================================================================================================================================================
| <http://www.semanticsoftware.info/domain.owl#28_Nick> | <http://www.semanticsoftware.info/domain.owl#30_Toronto1> | "28"^^<http://www.w3.org/2001/XMLSchema#int> | "male" | <http://www.semanticsoftware.info/nlp.owl#39_Nick_lives_in_Toronto1.> |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
在这里,值与uri一起出现,而且都不需要。
owl文件供参考:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns:nlp="http://www.semanticsoftware.info/nlp.owl#"
xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns="http://www.semanticsoftware.info/domain.owl#"
xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xml:base="http://www.semanticsoftware.info/domain.owl#">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.semanticsoftware.info/nlp.owl"/>
</owl:Ontology>
<rdfs:Class rdf:about="http://www.semanticsoftware.info/nlp.owl#Sentence"/>
<owl:Class rdf:ID="MoneyAmount"/>
<owl:Class rdf:ID="Province"/>
<owl:Class rdf:ID="Government"/>
<owl:Class rdf:ID="Company">
<rdfs:subClassOf>
<owl:Class rdf:ID="Organization"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="Human"/>
<owl:Class rdf:ID="Date"/>
<owl:Class rdf:ID="Department">
<rdfs:subClassOf rdf:resource="#Government"/>
</owl:Class>
<owl:Class rdf:ID="Region">
<rdfs:subClassOf>
<owl:Class rdf:ID="Location"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="Charity">
<rdfs:subClassOf rdf:resource="#Organization"/>
</owl:Class>
<owl:Class rdf:ID="Ministry">
<rdfs:subClassOf rdf:resource="#Government"/>
</owl:Class>
<owl:Class rdf:ID="MediaPerson">
<rdfs:subClassOf>
<owl:Class rdf:ID="Person"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="Sportsman">
<rdfs:subClassOf>
<owl:Class rdf:about="#Person"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="Politician">
<rdfs:subClassOf>
<owl:Class rdf:about="#Person"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="City">
<rdfs:subClassOf rdf:resource="#Location"/>
</owl:Class>
<owl:Class rdf:about="#Person">
<rdfs:subClassOf rdf:resource="#Human"/>
</owl:Class>
<owl:Class rdf:ID="BusinessMan">
<rdfs:subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:Class rdf:ID="Country">
<rdfs:subClassOf rdf:resource="#Location"/>
</owl:Class>
<owl:ObjectProperty rdf:ID="livesIn">
<rdfs:domain rdf:resource="#Human"/>
<rdfs:range rdf:resource="#Location"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:ID="appearsIn">
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Human"/>
<owl:Class rdf:about="#Location"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
<rdfs:range rdf:resource="http://www.semanticsoftware.info/nlp.owl#Sentence"/>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:ID="corefSentenceWithId">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Person"/>
<owl:Class rdf:about="#City"/>
<owl:Class rdf:about="#City"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:ID="corefStringWithId">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Person"/>
<owl:Class rdf:about="#City"/>
<owl:Class rdf:about="#City"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:ID="hasGender">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:domain rdf:resource="#Person"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:ID="idPropOf">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Person"/>
<owl:Class rdf:about="#City"/>
<owl:Class rdf:about="#City"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
</owl:DatatypeProperty>
<Person rdf:about="#28_Nick">
<appearsIn rdf:resource="http://www.semanticsoftware.info/nlp.owl#39_Nick_lives_in_Toronto."/>
<livesIn>
<City rdf:about="#30_Toronto">
<idPropOf rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>30</idPropOf>
<owl:sameAs>
<City rdf:about="#31_Toronto">
<idPropOf rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>31</idPropOf>
<appearsIn rdf:resource="http://www.semanticsoftware.info/nlp.owl#40_Toronto_is_a_six_hour_drive_from_Montreal."/>
<owl:sameAs rdf:resource="#30_Toronto"/>
</City>
</owl:sameAs>
<appearsIn rdf:resource="http://www.semanticsoftware.info/nlp.owl#39_Nick_lives_in_Toronto."/>
</City>
</livesIn>
<hasGender rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>male</hasGender>
<idPropOf rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>28</idPropOf>
</Person>
<City rdf:about="#36_Montreal">
<appearsIn rdf:resource="http://www.semanticsoftware.info/nlp.owl#40_Toronto_is_a_six_hour_drive_from_Montreal."/>
<idPropOf rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>36</idPropOf>
</City>
</rdf:RDF>
<!-- Created with Protege (with OWL Plugin 3.4, Build 533) http://protege.stanford.edu -->