在下面的查询中,我想使用?uri
标识 DBpedia 资源的变量从 DBpedia SPARQL 服务获取 DBpedia 元素,但它不返回任何结果,因为它期望 URI 在<>
.
我也尝试过<?uri>
,但再次没有返回结果。当我直接编写 URI 时,它会返回所需的结果,但我无法通过使用变量来管理它。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX lit: <http://purl.org/net/cnyt-literature#>
SELECT distinct ?writer ?play ?character ?uri ?type WHERE {
{
?writer lit:writerOf ?play .
?play lit:character ?character .
?character lit:dbpediaUri ?uri
}
SERVICE <http://dbpedia.org/sparql> {
?uri rdf:type ?type
}
}
LIMIT 50
这是省略 SERVICE 部分的查询结果:
当我将 SERVICE 部分中的 ?uri 替换为“ http://dbpedia.org/resource/Julius_Caesar ”时,它会从 dbpedia 获取信息,但我不知道如何使用 ?uri 变量来做到这一点。
这是我的猫头鹰文件:
<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.org/net/cnyt-literature#"
xml:base="http://purl.org/net/cnyt-literature"
xmlns:literature="http://purl.org/net/cnyt-literature#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
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://purl.org/net/cnyt-literature"/>
<!--
//
// Object Properties
//
<!-- http://purl.org/net/cnyt-literature#character -->
<owl:ObjectProperty rdf:about="http://purl.org/net/cnyt-literature#character">
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Play"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human"/>
</owl:ObjectProperty>
<!-- http://purl.org/net/cnyt-literature#writerOf -->
<owl:ObjectProperty rdf:about="http://purl.org/net/cnyt-literature#writerOf">
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Play"/>
</owl:ObjectProperty>
<!-- http://www.w3.org/2002/07/owl#sameAs -->
<owl:ObjectProperty rdf:about="http://www.w3.org/2002/07/owl#sameAs">
<rdfs:domain rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdfs:range rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:ObjectProperty>
<!--
//
// Data properties
//
<!-- http://purl.org/net/cnyt-literature#dbpediaUri -->
<owl:DatatypeProperty rdf:about="http://purl.org/net/cnyt-literature#dbpediaUri">
<rdfs:subPropertyOf rdf:resource="http://www.w3.org/2002/07/owl#topDataProperty"/>
</owl:DatatypeProperty>
<!-- http://purl.org/net/cnyt-literature#name -->
<owl:DatatypeProperty rdf:about="http://purl.org/net/cnyt-literature#name">
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Literary_Work"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Politician"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:DatatypeProperty>
<!-- http://purl.org/net/cnyt-literature#source -->
<owl:DatatypeProperty rdf:about="http://purl.org/net/cnyt-literature#source"/>
<!-- http://purl.org/net/cnyt-literature#wikidataUri -->
<owl:DatatypeProperty rdf:about="http://purl.org/net/cnyt-literature#wikidataUri"/>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#uri -->
<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#uri"/>
<!-- http://www.w3.org/2002/07/owl#sameAs -->
<owl:DatatypeProperty rdf:about="http://www.w3.org/2002/07/owl#sameAs"/>
//
// Classes
//
<!-- http://purl.org/net/cnyt-literature#Novel -->
<owl:Class rdf:about="http://purl.org/net/cnyt-literature#Novel">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Literary_Work"/>
</owl:Class>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human"/>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Literary_Work -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Literary_Work"/>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Play -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Play">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Literary_Work"/>
</owl:Class>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Politician -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Politician">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human"/>
</owl:Class>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer -->
<owl:Class rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Human"/>
</owl:Class>
//
// Individuals
//
<!-- http://purl.org/net/cnyt-literature#JackLondon -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JackLondon">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer"/>
<writerOf rdf:resource="http://purl.org/net/cnyt-literature#WhiteFang"/>
<name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Jack London</name>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#JuliusCaesar -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesar">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Politician"/>
<dbpediaUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/resource/Julius_Caesar</dbpediaUri>
<wikidataUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q1048</wikidataUri>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/resource/Julius_Caesar</owl:sameAs>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q1048</owl:sameAs>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#JuliusCaesarDbpedia -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarDbpedia">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">dbpedia</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/page/Julius_Caesar</literature1:uri>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#JuliusCaesarPlayDbpedia -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarPlayDbpedia">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">dbpedia</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/resource/Julius_Caesar_(play)</literature1:uri>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#JuliusCaesarPlayWikidata -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarPlayWikidata">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">wikidata</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q215750</literature1:uri>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#JuliusCaesarWikidata -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarWikidata">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">wikidata</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q1048</literature1:uri>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#WhiteFang -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#WhiteFang">
<rdf:type rdf:resource="http://purl.org/net/cnyt-literature#Novel"/>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#WilliamShakespeareDbpedia -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#WilliamShakespeareDbpedia">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">dbpedia</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">dbpedia.org/page/William_Shakespeare</literature1:uri>
</owl:NamedIndividual>
<!-- http://purl.org/net/cnyt-literature#WilliamShakespeareWikidata -->
<owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#WilliamShakespeareWikidata">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#ExternalItem"/>
<source rdf:datatype="http://www.w3.org/2001/XMLSchema#string">wikidata</source>
<literature1:uri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q692</literature1:uri>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#JuliusCaesarPlay -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#JuliusCaesarPlay">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Play"/>
<character rdf:resource="http://purl.org/net/cnyt-literature#JuliusCaesar"/>
<dbpediaUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/page/Julius_Caesar_(play)</dbpediaUri>
<wikidataUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q1048</wikidataUri>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/page/Julius_Caesar_(play)</owl:sameAs>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q1048</owl:sameAs>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#WilliamShakespeare -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#WilliamShakespeare">
<rdf:type rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#Writer"/>
<writerOf rdf:resource="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#JuliusCaesarPlay"/>
<dbpediaUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/page/William_Shakespeare</dbpediaUri>
<wikidataUri rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q692</wikidataUri>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://dbpedia.org/page/William_Shakespeare</owl:sameAs>
<owl:sameAs rdf:datatype="http://www.w3.org/2001/XMLSchema#string">https://www.wikidata.org/wiki/Q692</owl:sameAs>
</owl:NamedIndividual>
</rdf:RDF>
<!-- Generated by the OWL API (version 4.2.6.20160910-2108) https://github.com/owlcs/owlapi -->