在SPARQL中查询相同属性下的数据

时间:2013-10-14 16:53:52

标签: rdf sparql

我有这样的RDF数据:(更新,完整文件)

我得到此RDF的来源是:http://reach.suny.edu/display/Hajagos_Janos 当你在个人资料图片下面的“回形针”按钮,你可以下载这个文件。 SPARQL端点是:http://link.informatics.stonybrook.edu/sparql/

    <rdf:RDF
    xmlns:geo="http://aims.fao.org/aos/geopolitical.owl#"
    xmlns:c4o="http://purl.org/spar/c4o/"
    xmlns:vitro-public="http://vitro.mannlib.cornell.edu/ns/vitro/public#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#"
    xmlns:ero="http://purl.obolibrary.org/obo/"
    xmlns:event="http://purl.org/NET/c4dm/event.owl#"
    xmlns:pvs="http://vivoweb.org/ontology/provenance-support#"
    xmlns:dcelem="http://purl.org/dc/elements/1.1/"
    xmlns:j.0="http://reach.suny.edu/ns#"
    xmlns:vivo="http://vivoweb.org/ontology/core#"
    xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:bibo="http://purl.org/ontology/bibo/"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:reach="http://reach.suny.edu/ontology/core#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:scires="http://vivoweb.org/ontology/scientific-research#"
    xmlns:fabio="http://purl.org/spar/fabio/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n2406">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeInterval"/>
    <vivo:start rdf:resource="http://reach.suny.edu/individual/n10121"/>
    <vivo:end rdf:resource="http://reach.suny.edu/individual/n3729"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n6042">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Role"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#PresenterRole"/>
    <vivo:roleRealizedIn rdf:resource="http://reach.suny.edu/individual/n3694"/>
    <vivo:dateTimeInterval rdf:resource="http://reach.suny.edu/individual/n2406"/>
    <vivo:presenterRoleOf rdf:resource="http://reach.suny.edu/individual/Hajagos_Janos"/>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Speaker</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n3694">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">VIVO Mini-Grant: Integrating the UMLS Ontology into VIVO for Linking Biomedical Scientists</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n4507">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Position"/>
    <vivo:positionForPerson rdf:resource="http://reach.suny.edu/individual/Hajagos_Janos"/>
    <vivo:positionInOrganization rdf:resource="http://reach.suny.edu/individual/n4644"/>
    <vivo:rank rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</vivo:rank>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Clinical Assistant Professor</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n5408">
    <rdfs:label>Semantic Web</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C0025088">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Medical Informatics</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://vivoweb.org/ontology/core#yearPrecision">
    <rdfs:label xml:lang="en-US">yearPrecision</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n4542">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Medical Informatics</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/a21575203">
    <rdfs:label>Linked open drug data for pharmaceutical research and development.</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C0010992">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Data Analysis</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C0085567">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">UMLS</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n10121">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
    <vivo:dateTimePrecision rdf:resource="http://vivoweb.org/ontology/core#yearPrecision"/>
    <vivo:dateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2011-01-01T00:00:00</vivo:dateTime>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n4418">
    <rdfs:label xml:lang="en-US">Semantic Web Architecture Group</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C0025071">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Medicaid</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C1882937">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">RDF</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/gHajagos_Janos_21575203">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Relationship"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Authorship"/>
    <vivo:linkedAuthor rdf:resource="http://reach.suny.edu/individual/Hajagos_Janos"/>
    <vivo:linkedInformationResource rdf:resource="http://reach.suny.edu/individual/a21575203"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n6907">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Position"/>
    <vivo:positionForPerson rdf:resource="http://reach.suny.edu/individual/Hajagos_Janos"/>
    <vivo:positionInOrganization rdf:resource="http://reach.suny.edu/individual/n4542"/>
    <vivo:rank rdf:datatype="http://www.w3.org/2001/XMLSchema#int">2</vivo:rank>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Senior Programmer/Data Analyst</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n2444">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Role"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#MemberRole"/>
    <vivo:memberRoleOf rdf:resource="http://reach.suny.edu/individual/Hajagos_Janos"/>
    <vivo:roleContributesTo rdf:resource="http://reach.suny.edu/individual/n4418"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n3729">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
    <vivo:dateTimePrecision rdf:resource="http://vivoweb.org/ontology/core#yearPrecision"/>
    <vivo:dateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2011-01-01T00:00:00</vivo:dateTime>
  </rdf:Description>
  <rdf:Description rdf:about="http://link.informatics.stonybrook.edu/umls/CUI/C0034379">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Health care quality</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/Hajagos_Janos">
    <foaf:lastName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Hajagos</foaf:lastName>
    <vivo:personInPosition rdf:resource="http://reach.suny.edu/individual/n4507"/>
    <vivo:educationalTraining rdf:resource="http://reach.suny.edu/individual/n20726"/>
    <vivo:authorInAuthorship rdf:resource="http://reach.suny.edu/individual/gHajagos_Janos_21575203"/>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C0010992"/>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C1882937"/>
    <vivo:personInPosition rdf:resource="http://reach.suny.edu/individual/n6907"/>
    <vivo:faxNumber>631-444-8873</vivo:faxNumber>
    <j.0:networkId>jhajagos</j.0:networkId>
    <vivo:hasMemberRole rdf:resource="http://reach.suny.edu/individual/n2444"/>
    <vivo:hasPresenterRole rdf:resource="http://reach.suny.edu/individual/n6042"/>
    <vivo:middleName>G</vivo:middleName>
    <vitro-public:mainImage rdf:resource="http://reach.suny.edu/individual/n1206"/>
    <vivo:email>risk.limits@gmail.com</vivo:email>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C0025071"/>
    <rdf:type rdf:resource="http://reach.suny.edu/ontology/core#SUNY_REACH_Investigator"/>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C0085567"/>
    <rdfs:label xml:lang="en-US">Hajagos, Janos</rdfs:label>
    <foaf:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Janos</foaf:firstName>
    <vivo:phoneNumber>631-444-1596</vivo:phoneNumber>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C0034379"/>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
    <vivo:hasResearchArea rdf:resource="http://reach.suny.edu/individual/n5408"/>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Agent"/>
    <vivo:preferredTitle>Senior Programmer/Analyst&lt;br /&gt;</vivo:preferredTitle>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <vivo:primaryEmail>janos.hajagos@stonybrook.edu</vivo:primaryEmail>
    <bibo:suffixName>Ph.D.</bibo:suffixName>
    <vivo:hasResearchArea rdf:resource="http://link.informatics.stonybrook.edu/umls/CUI/C0025088"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://reach.suny.edu/individual/n4644">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">BS/HS Program</rdfs:label>
  </rdf:Description>
</rdf:RDF>

我想查找姓氏为"Hajagos"的人的出版物。从数据中,我们可以看到它位于<rdfs:label> "Linked open drug data for pharmaceutical research and development"下。但在同一<rdfs:label>下也有很多值。我怎么能查询这个。我尝试了以下SPARQL,但没有任何用处:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vivo: <http://vivoweb.org/ontology/core#>

SELECT ?publication
WHERE {
  ?person foaf:lastName "Hajagos" .
  ?person rdfs:label ?publication
}

通过此查询,我只能获得en-US,这也是属性<rdfs:label>的值。

1 个答案:

答案 0 :(得分:5)

如果您获取数据并将其转换为人类可读的格式(如Turtle),则可以更轻松地查看数据中的连接。特别是在转换之后,我们得到了以下对我们所关注的作者的描述:

<http://reach.suny.edu/individual/Hajagos_Janos>
        a                         reach:SUNY_REACH_Investigator , foaf:Person , foaf:Agent , owl:Thing ;
        rdfs:label                "Hajagos, Janos"@en-US ;
        bibo:suffixName           "Ph.D." ;
        j.0:networkId             "jhajagos" ;
        vitro-public:mainImage    <http://reach.suny.edu/individual/n1206> ;
        vivo:authorInAuthorship   <http://reach.suny.edu/individual/gHajagos_Janos_21575203> ;
        vivo:educationalTraining  <http://reach.suny.edu/individual/n20726> ;
        vivo:email                "risk.limits@gmail.com" ;
        vivo:faxNumber            "631-444-8873" ;
        vivo:hasMemberRole        <http://reach.suny.edu/individual/n2444> ;
        vivo:hasPresenterRole     <http://reach.suny.edu/individual/n6042> ;
        vivo:hasResearchArea      <http://link.informatics.stonybrook.edu/umls/CUI/C0010992> , <http://link.informatics.stonybrook.edu/umls/CUI/C1882937> , <http://link.informatics.stonybrook.edu/umls/CUI/C0025071> , <http://link.informatics.stonybrook.edu/umls/CUI/C0085567> , <http://link.informatics.stonybrook.edu/umls/CUI/C0034379> , <http://reach.suny.edu/individual/n5408> , <http://link.informatics.stonybrook.edu/umls/CUI/C0025088> ;
        vivo:middleName           "G" ;
        vivo:personInPosition     <http://reach.suny.edu/individual/n4507> , <http://reach.suny.edu/individual/n6907> ;
        vivo:phoneNumber          "631-444-1596" ;
        vivo:preferredTitle       "Senior Programmer/Analyst<br />" ;
        vivo:primaryEmail         "janos.hajagos@stonybrook.edu" ;
        foaf:firstName            "Janos"^^<http://www.w3.org/2001/XMLSchema#string> ;
        foaf:lastName             "Hajagos"^^<http://www.w3.org/2001/XMLSchema#string> .

那里并没有很多与作者身份有关,但有谓词和对象:

vivo:authorInAuthorship   <http://reach.suny.edu/individual/gHajagos_Janos_21575203> ;

如果我们遵循该对象,我们会看到:

<http://reach.suny.edu/individual/gHajagos_Janos_21575203>
        a                               owl:Thing , vivo:Relationship , vivo:Authorship ;
        vivo:linkedAuthor               <http://reach.suny.edu/individual/Hajagos_Janos> ;
        vivo:linkedInformationResource  <http://reach.suny.edu/individual/a21575203> .

可能是我们感兴趣的关联信息资源<http://reach.suny.edu/individual/a21575203>。关于这方面没有太多信息,但是有

<http://reach.suny.edu/individual/a21575203>
        rdfs:label  "Linked open drug data for pharmaceutical research and development." .

基于此结构,我们可以编写一个查询vivo:Authorship及其vivo:linkedAuthor s以及任何rdfs:label的{​​{1}} s的查询。要专门查询vivo:linkedInformationResource,您可以使用:

"Hajagos"

要获得更一般的结果(以及稍微清理一下查询),您可以使用:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vivo: <http://vivoweb.org/ontology/core#>

SELECT ?label
WHERE {
  ?authorship vivo:linkedAuthor ?author ;
              vivo:linkedInformationResource ?resource .
  ?author foaf:lastName "Hajagos" .
  ?resource rdfs:label ?label .
}

SPARQL results

使用您的数据产生这样的结果;

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix vivo: <http://vivoweb.org/ontology/core#>

select ?lastName ?label where {
  ?authorship vivo:linkedAuthor [ foaf:lastName ?lastName ] ;
              vivo:linkedInformationResource [ rdfs:label ?label ] .
}

在端点运行时有很多结果。也就是说,我没有在端点的结果中看到Hajagos的任何结果。我不知道为什么会这样(但下一节会有一些注意事项)。

注意事项

经过一些实验,似乎有一些警告。例如,如果我们使用对象$ sparql --data data2.n3 --query query.rq ------------------------------------------------------------------------------------------------------------------------------- | lastName | label | =============================================================================================================================== | "Hajagos"^^<http://www.w3.org/2001/XMLSchema#string> | "Linked open drug data for pharmaceutical research and development." | ------------------------------------------------------------------------------------------------------------------------------- 搜索三元组,我们会获得与搜索"Hajagos"时不同的三元组。例如,这个查询

"Hajagos"^^xsd:string

返回

select ?s ?p { ?s ?p "Hajagos" }

但是这个查询

s                                          p
http://reach.suny.edu/individual/Hajagos_J http://xmlns.com/foaf/0.1/lastName

返回

select ?s ?p { ?s ?p "Hajagos"^^xsd:string } 

请注意,个人不同!这不是一个伟大的事态。我们可以查询两者,但

s                                              p
http://reach.suny.edu/individual/Hajagos_Janos http://xmlns.com/foaf/0.1/lastName

找到

select ?s ?p { 
  { ?s ?p "Hajagos" } UNION { ?s ?p "Hajagos"^^xsd:string }
}