SPARQL:将参数从主查询传递到SERVICE查询

时间:2017-07-27 08:08:51

标签: sparql wikidata

在下面的查询中,我想将?wid参数传递给SERVICE查询,但它不会作为另一个空变量(如?child)传递和处理,因此查询返回不需要的结果(意味着它的行为?wid作为空变量,因为此代码在wikidata服务器上运行,因此它返回该变量的所有可能结果)。我正从我当地的jena fuseki服务器发出此查询。

PREFIX lit: <http://purl.org/net/cnyt-literature#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>

SELECT distinct ?writer ?play ?character ?uri ?wid ?type ?child ?childLabel WHERE {
    {
        ?writer lit:writerOf ?play .
        ?play lit:character ?character .
        ?character lit:dbpediaUri  ?db_uri . BIND (IRI(?uri) AS ?dbpedia_uri)
        ?character lit:wikidataUri  ?uri . BIND (IRI(CONCAT(str(wd:),?uri)) as ?wid)
    }

    SERVICE <http://query.wikidata.org/sparql> {
        select distinct ?child ?childLabel where {
            ?wid wdt:P40 ?child.
            SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
        }
    } 
}
LIMIT 50

基本上,我想做的是通过添加行来从维基百科中获取实体的标签名称

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

到select语句。

当我不使用SELECT语句时,它按预期工作并传递?wid参数,因此问题在于将此参数传递给WHERE语句,而不是SERVICE。在这个查询中,它返回了七个孩子的Julius Caesar for wid(Q1048),这是真的。

SERVICE <http://query.wikidata.org/sparql> {
            ?wid wdt:P40 ?child.
        } 

我的数据是:

个体

Writer William Shakespeare
Play JuliusCaesarPlay
Politican JuliusCaesar

三同

WilliamShakespeare writerOf JuliusCaesarPlay
JuliusCaesarPlay character JuliusCaesar
JuliusCaesar wikidataUri "Q1048"

这是整个猫头鹰文件:

<?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:literature1="http://www.semanticweb.org/cnytync/ontologies/2017/6/literature#"
     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://purl.org/net/cnyt-literature#Play"/>
        <rdfs:range rdf:resource="http://purl.org/net/cnyt-literature#Human"/>
    </owl:ObjectProperty>



    <!-- http://purl.org/net/cnyt-literature#wikidataId -->

    <owl:ObjectProperty rdf:about="http://purl.org/net/cnyt-literature#wikidataId"/>



    <!-- http://purl.org/net/cnyt-literature#writerOf -->

    <owl:ObjectProperty rdf:about="http://purl.org/net/cnyt-literature#writerOf">
        <rdfs:domain rdf:resource="http://purl.org/net/cnyt-literature#Writer"/>
        <rdfs:range rdf:resource="http://purl.org/net/cnyt-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://purl.org/net/cnyt-literature#Human"/>
        <rdfs:domain rdf:resource="http://purl.org/net/cnyt-literature#Literary_Work"/>
        <rdfs:domain rdf:resource="http://purl.org/net/cnyt-literature#Politician"/>
        <rdfs:domain rdf:resource="http://purl.org/net/cnyt-literature#Writer"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    </owl:DatatypeProperty>



    <!-- http://purl.org/net/cnyt-literature#nn -->

    <owl:DatatypeProperty rdf:about="http://purl.org/net/cnyt-literature#nn"/>



    <!-- 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#ExternalItem -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#ExternalItem"/>



    <!-- http://purl.org/net/cnyt-literature#Human -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Human"/>



    <!-- http://purl.org/net/cnyt-literature#Literary_Work -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Literary_Work"/>



    <!-- http://purl.org/net/cnyt-literature#Novel -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Novel">
        <rdfs:subClassOf rdf:resource="http://purl.org/net/cnyt-literature#Literary_Work"/>
    </owl:Class>



    <!-- http://purl.org/net/cnyt-literature#Play -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Play">
        <rdfs:subClassOf rdf:resource="http://purl.org/net/cnyt-literature#Literary_Work"/>
    </owl:Class>



    <!-- http://purl.org/net/cnyt-literature#Politician -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Politician">
        <rdfs:subClassOf rdf:resource="http://purl.org/net/cnyt-literature#Human"/>
    </owl:Class>



    <!-- http://purl.org/net/cnyt-literature#Writer -->

    <owl:Class rdf:about="http://purl.org/net/cnyt-literature#Writer">
        <rdfs:subClassOf rdf:resource="http://purl.org/net/cnyt-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://purl.org/net/cnyt-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://purl.org/net/cnyt-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">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://purl.org/net/cnyt-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#JuliusCaesarPlay -->

    <owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarPlay">
        <rdf:type rdf:resource="http://purl.org/net/cnyt-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://purl.org/net/cnyt-literature#JuliusCaesarPlayDbpedia -->

    <owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#JuliusCaesarPlayDbpedia">
        <rdf:type rdf:resource="http://purl.org/net/cnyt-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://purl.org/net/cnyt-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://purl.org/net/cnyt-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#WilliamShakespeare -->

    <owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#WilliamShakespeare">
        <rdf:type rdf:resource="http://purl.org/net/cnyt-literature#Writer"/>
        <writerOf rdf:resource="http://purl.org/net/cnyt-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>



    <!-- http://purl.org/net/cnyt-literature#WilliamShakespeareDbpedia -->

    <owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#WilliamShakespeareDbpedia">
        <rdf:type rdf:resource="http://purl.org/net/cnyt-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://purl.org/net/cnyt-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://purl.org/net/cnyt-literature#wd:Q1048 -->

    <owl:NamedIndividual rdf:about="http://purl.org/net/cnyt-literature#wd:Q1048">
        <rdf:type rdf:resource="http://purl.org/net/cnyt-literature#ExternalItem"/>
    </owl:NamedIndividual>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.2.6.20160910-2108) https://github.com/owlcs/owlapi -->

0 个答案:

没有答案