[Python] SPARQL Query not retrieving all triples

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    In Python, I am querying SPARQL queries using SPARQLWRAPPER.

    I currently have two queries:

    # A lot of PREFIX definitions at the top of the query

    INSERT
    {{ GRAPH <https://graph-dev.golemlab.eu/graph/Dennis-01>
    {{ gd:{recent_id} a lrm:F1 ;
    lrm:R3_is_realised_in gd:{recent_id}.{expression_id} ;
    schema:title ?titleWithLang ;
    crm:p130_shows_features_of ?fandomId .

    gd:{recent_id}.{expression_id} a lrm:F2_Expression ;
    skos:prefLabel ?titleWithLang ;
    schema:language ?language .
    }}
    }}
    WHERE
    {{ GRAPH <http://example.com>
    {{ ?s golem:story_id {story_id} ;
    golem:title ?title ;
    golem:language ?language ;
    golem:fandom ?fandom .

    VALUES (?language ?langCode) {{
    {lang_map_sparql}
    }}
    BIND(STRLANG(STR(?title), STR(?langCode)) AS ?titleWithLang)
    }}

    GRAPH <https://graph-dev.golemlab.eu/graph/Dennis-01>
    {{ ?fandomId a gc:G15_Fandom .

    OPTIONAL {{ ?fandomId skos:prefLabel ?prefLabel . }}
    OPTIONAL {{ ?fandomId skos:alternativeLabel ?altLabel . }}
    }}
    BIND(COALESCE(?prefLabel, ?altLabel) AS ?fandomLabel)
    FILTER(?fandomLabel = ?fandom)
    }}


    and

    # A lot of PREFIX definitions at the top of the query

    INSERT
    {{ GRAPH <https://graph-dev.golemlab.eu/graph/Dennis-01>
    {{ gd:{recent_id}.{expression_id} schema:datePublished ?datePublishedNew ;
    schema:dateModified ?dateModifiedNew ;
    schema:endTime ?datePackagedNew .
    }}
    }}
    WHERE
    {{ GRAPH <http://example.com>
    {{ ?s golem:story_id {story_id} ;
    golem:datePublished ?datePublished ;
    golem:dateModified ?dateModified ;
    golem:datePackaged ?datePackaged .
    }}
    BIND(STRDT(REPLACE(STR(?datePublished)," ",""), xsd:date) AS ?datePublishedNew) .
    BIND(STRDT(REPLACE(STR(?dateModified)," ",""), xsd:date) AS ?dateModifiedNew) .
    BIND(STRDT(REPLACE(STR(?datePackaged)," ",""), xsd:dateTime) AS ?datePackagedNew) .
    }}


    When I query for the subgraph using:

    # A lot of PREFIX definitions at the top of the query

    WITH GRAPH <https://graph-dev.golemlab.eu/graph/Dennis-01>

    SELECT * WHERE {{
    ?s ?p ?o .
    FILTER NOT EXISTS {{ ?s a gc:G15_Fandom }}
    }}


    I am filtering out ?s where the object is a Fandom, since there are thousands of fandom instances in my subgraphs.

    I only get the triples that related to the date (my second query).

    I am expecting more instances than just the second query. For example, I'm expecting triples like: W01 schema:title "title"

    Is there something that I am doing wrong? How could I fix this?

    Continue reading...

Compartilhe esta Página