Difference between revisions of "Snapquery Query Experiment 2025-12-03"

From BITPlan cr Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
= Prompt =
+
= Prompt 2025-12-03 =
 
<pre>
 
<pre>
 
Given https://gitingest.com/ of https://github.com/WolfgangFahl/pyLodStorage and the example query
 
Given https://gitingest.com/ of https://github.com/WolfgangFahl/pyLodStorage and the example query
 
In which films directed by Garry Marshall was Julia Roberts starring? from the paper Understanding the structure of knowledge graphs with ABSTAT profiles https://journals.sagepub.com/doi/pdf/10.3233/SW-223181 create an endpoints.yaml with potential sources such as wikidata and dbpedia and a queries.yaml with parameterized queries that allow to specify director and actor.
 
In which films directed by Garry Marshall was Julia Roberts starring? from the paper Understanding the structure of knowledge graphs with ABSTAT profiles https://journals.sagepub.com/doi/pdf/10.3233/SW-223181 create an endpoints.yaml with potential sources such as wikidata and dbpedia and a queries.yaml with parameterized queries that allow to specify director and actor.
 
</pre>  
 
</pre>  
 +
Via OpenRouter to 4 different LLMs at cost of approx $1 total
 
{{LLMHint}}
 
{{LLMHint}}
 +
 
= Results =
 
= Results =
 
== Gemini3 Pro Preview ==
 
== Gemini3 Pro Preview ==

Latest revision as of 11:04, 3 December 2025

Prompt 2025-12-03

Given https://gitingest.com/ of https://github.com/WolfgangFahl/pyLodStorage and the example query
In which films directed by Garry Marshall was Julia Roberts starring? from the paper Understanding the structure of knowledge graphs with ABSTAT profiles https://journals.sagepub.com/doi/pdf/10.3233/SW-223181 create an endpoints.yaml with potential sources such as wikidata and dbpedia and a queries.yaml with parameterized queries that allow to specify director and actor.

Via OpenRouter to 4 different LLMs at cost of approx $1 total

⚠️ LLM-generated content notice: Parts of this page may have been created or edited with the assistance of a large language model (LLM). The prompts that have been used might be on the page itself, the discussion page or in straight forward cases the prompt was just "Write a mediawiki page on X" with X being the page name. While the content has been reviewed it might still not be accurate or error-free.

Results

Gemini3 Pro Preview

Based on the pyLodStorage structure and the requirement to facilitate the query "In which films directed by Garry Marshall was Julia Roberts starring?", here are the configuration files.

Endpoints.yaml

This file defines the knowledge graph endpoints (Wikidata and DBpedia) along with standard prefixes to make the queries cleaner.

# Endpoint definitions for pyLodStorage
wikidata:
  endpoint: "https://query.wikidata.org/sparql"
  method: GET
  prefixes: |
    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#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX schema: <http://schema.org/>

dbpedia:
  endpoint: "https://dbpedia.org/sparql"
  method: GET
  prefixes: |
    PREFIX dbo: <http://dbpedia.org/ontology/>
    PREFIX dbr: <http://dbpedia.org/resource/>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>

queries.yaml

This file contains the parameterized SPARQL queries. The placeholders %(director)s and %(actor)s allow strict string formatting injection (standard Python syntax) to swap names (e.g., "Garry Marshall" and "Julia Roberts") dynamically.

# Parameterized queries for Actor/Director relationships
# Usage: format with dictionary, e.g., {'director': 'Garry Marshall', 'actor': 'Julia Roberts'}

films_by_director_and_actor_wikidata:
  title: Films by Director starring Actor (Wikidata)
  endpoint: wikidata
  description: >
    Selects films where the specified director (P57) directed
    and the specified actor (P161) was a cast member.
  query: |
    SELECT DISTINCT ?film ?filmLabel ?date
    WHERE {
       # Film instance of Film
       ?film wdt:P31 wd:Q11424;
             wdt:P57 ?director;
             wdt:P161 ?actor.

       # Filter by Director Name
       ?director rdfs:label ?directorLabel.
       FILTER(REGEX(?directorLabel, "^%(director)s$", "i"))
       FILTER(LANG(?directorLabel) = "en")

       # Filter by Actor Name
       ?actor rdfs:label ?actorLabel.
       FILTER(REGEX(?actorLabel, "^%(actor)s$", "i"))
       FILTER(LANG(?actorLabel) = "en")

       # Optional Publication Date
       OPTIONAL { ?film wdt:P577 ?date. }

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

films_by_director_and_actor_dbpedia:
  title: Films by Director starring Actor (DBpedia)
  endpoint: dbpedia
  description: >
    Selects films defining dbo:director and dbo:starring relationships
    matching the input labels.
  query: |
    SELECT DISTINCT ?film ?filmLabel
    WHERE {
      ?film a dbo:Film;
            dbo:director ?director;
            dbo:starring ?actor.
      
      ?film rdfs:label ?filmLabel.
      
      # Match Director Label
      ?director rdfs:label ?directorLabel.
      FILTER(REGEX(?directorLabel, "^%(director)s$", "i"))
      FILTER(LANG(?directorLabel) = "en")

      # Match Actor Label
      ?actor rdfs:label ?actorLabel.
      FILTER(REGEX(?actorLabel, "^%(actor)s$", "i"))
      FILTER(LANG(?actorLabel) = "en")
      FILTER(LANG(?filmLabel) = "en")
    }

Claude Sonnet 4.5

Based on the pyLodStorage repository structure and the example query about films directed by Garry Marshall starring Julia Roberts, here are the two YAML configuration files:

Endpoints.yaml

# SPARQL Endpoints Configuration
endpoints:
  wikidata:
    name: wikidata
    endpoint: https://query.wikidata.org/sparql
    website: https://query.wikidata.org
    lang: sparql
    method: POST
    database: wikidata
    prefixes: |
      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#>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    
  dbpedia:
    name: dbpedia
    endpoint: https://dbpedia.org/sparql
    website: https://dbpedia.org/sparql
    lang: sparql
    method: POST
    database: dbpedia
    prefixes: |
      PREFIX dbo: <http://dbpedia.org/ontology/>
      PREFIX dbr: <http://dbpedia.org/resource/>
      PREFIX dbp: <http://dbpedia.org/property/>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      PREFIX foaf: <http://xmlns.com/foaf/0.1/>

queries.yaml

# Query Definitions
queries:
  films_by_director_and_actor_wd:
    name: films_by_director_and_actor_wd
    title: Films by Director and Actor (Wikidata)
    description: |
      Finds films directed by a specific director and starring a specific actor.
      Example: In which films directed by Garry Marshall was Julia Roberts starring?
    lang: sparql
    endpoint: wikidata
    formats:
      - "*:wikidata"
    params:
      - name: director
        type: string
        default: "Garry Marshall"
      - name: actor
        type: string
        default: "Julia Roberts"
    query: |
      SELECT DISTINCT ?film ?filmLabel ?year WHERE {
        ?directorEntity rdfs:label ?directorLabel .
        FILTER(LANG(?directorLabel) = "en" && LCASE(STR(?directorLabel)) = LCASE("$director$"))
        
        ?actorEntity rdfs:label ?actorLabel .
        FILTER(LANG(?actorLabel) = "en" && LCASE(STR(?actorLabel)) = LCASE("$actor$"))
        
        ?film wdt:P31 wd:Q11424 .          # instance of film
        ?film wdt:P57 ?directorEntity .     # director
        ?film wdt:P161 ?actorEntity .       # cast member
        
        OPTIONAL { ?film wdt:P577 ?pubDate . 
                   BIND(YEAR(?pubDate) AS ?year) }
        
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
      }
      ORDER BY ?year

  films_by_director_and_actor_dbpedia:
    name: films_by_director_and_actor_dbpedia
    title: Films by Director and Actor (DBpedia)
    description: |
      Finds films directed by a specific director and starring a specific actor using DBpedia.
      Example: In which films directed by Garry Marshall was Julia Roberts starring?
    lang: sparql
    endpoint: dbpedia
    params:
      - name: director
        type: string
        default: "Garry_Marshall"
      - name: actor
        type: string
        default: "Julia_Roberts"
    query: |
      SELECT DISTINCT ?film ?title ?year WHERE {
        ?film a dbo:Film ;
              dbo:director dbr:$director$ ;
              dbo:starring dbr:$actor$ .
        
        OPTIONAL { ?film rdfs:label ?title . FILTER(LANG(?title) = "en") }
        OPTIONAL { ?film dbo:releaseDate ?releaseDate . 
                   BIND(YEAR(?releaseDate) AS ?year) }
      }
      ORDER BY ?year

  films_by_director_and_actor_generic:
    name: films_by_director_and_actor_generic
    title: Films by Director and Actor (Generic)
    description: |
      Generic parameterized query to find films by director and actor.
      Can be used with different SPARQL endpoints.
    lang: sparql
    params:
      - name: director
        type: string
        required: true
        description: "Name of the film director"
      - name: actor
        type: string
        required: true
        description: "Name of the actor/actress"
      - name: limit
        type: integer
        default: 100
        description: "Maximum number of results"
    query: |
      # Query to be adapted based on endpoint
      # This is a template - modify based on your chosen endpoint
      SELECT DISTINCT ?film ?filmLabel ?year WHERE {
        # Add endpoint-specific patterns here
        # Use $director$ and $actor$ as parameter placeholders
      }
      LIMIT $limit$

Grok 4

Endpoints.yaml

# endpoints.yaml
# Configuration for SPARQL endpoints
wikidata:
  name: Wikidata
  endpoint: https://query.wikidata.org/sparql
  lang: sparql
  website: https://query.wikidata.org/
  method: GET

dbpedia:
  name: DBpedia
  endpoint: http://dbpedia.org/sparql
  lang: sparql
  website: https://dbpedia.org/sparql
  method: GET

queries.yaml

# Parameterized queries for films directed by a specified director starring a specified actor

films_by_director_starring_actor_wikidata:
  title: Films directed by {director} starring {actor}
  query: |
    SELECT ?film ?filmLabel WHERE {
      ?film wdt:P31 wd:Q11424 . # instance of film
      ?film wdt:P57 wd:{director} .
      ?film wdt:P161 wd:{actor} .
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
  lang: sparql
  endpoints:
    - wikidata
  parameters:
    - director
    - actor

films_by_director_starring_actor_dbpedia:
  title: Films directed by {director} starring {actor}
  query: |
    SELECT ?film WHERE {
      ?film a dbo:Film .
      ?film dbo:director dbr:{director} .
      ?film dbo:starring dbr:{actor} .
    }
  lang: sparql
  endpoints:
    - dbpedia
  parameters:
    - director
    - actor

GPT-5

Endpoints.yaml

# SPARQL endpoints for common open knowledge graph sources
endpoints:
  wikidata:
    name: wikidata
    website: https://query.wikidata.org
    endpoint: https://query.wikidata.org/sparql
    method: POST
    # Optional: will be prepended if you run with --prefixes
    prefixes: |-
      PREFIX wd: <http://www.wikidata.org/entity/>
      PREFIX wdt: <http://www.wikidata.org/prop/direct/>
      PREFIX wikibase: <http://wikiba.se/ontology#>
      PREFIX p: <http://www.wikidata.org/prop/>
      PREFIX ps: <http://www.wikidata.org/prop/statement/>
      PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
      PREFIX bd: <http://www.bigdata.com/rdf#>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

  dbpedia:
    name: dbpedia
    website: https://dbpedia.org/sparql
    endpoint: https://dbpedia.org/sparql
    method: GET
    prefixes: |-
      PREFIX dbo: <http://dbpedia.org/ontology/>
      PREFIX dbr: <http://dbpedia.org/resource/>
      PREFIX dbp: <http://dbpedia.org/property/>
      PREFIX foaf: <http://xmlns.com/foaf/0.1/>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

queries.yaml

# Parameterized SPARQL queries (director / actor)
# Placeholders:
#   {director} - a case-insensitive full label match for the director
#   {actor}    - a case-insensitive full label match for the actor
language: sparql
queries:

  films_by_director_and_actor_wikidata:
    title: Films by director and actor (Wikidata)
    description: >
      Returns films where an actor starred and the film was directed by the specified director,
      resolved by English labels on Wikidata.
    endpoint: wikidata
    # Optional: Use Wikidata-aware value formatting in pyLoDStorage result docs
    formats:
      - "*:wikidata"
    parameters:
      director:
        example: Garry Marshall
      actor:
        example: Julia Roberts
    query: |-
      PREFIX wd: <http://www.wikidata.org/entity/>
      PREFIX wdt: <http://www.wikidata.org/prop/direct/>
      PREFIX bd: <http://www.bigdata.com/rdf#>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

      SELECT ?film ?filmLabel ?publicationDate
      WHERE {
        ?film wdt:P31 wd:Q11424 ;     # instance of film
              wdt:P57 ?dir ;          # director
              wdt:P161 ?actor .       # cast member

        # match director by English label (case-insensitive exact match)
        ?dir rdfs:label ?dirName .
        FILTER(LANG(?dirName) = "en")
        FILTER(LCASE(STR(?dirName)) = LCASE("{director}"))

        # match actor by English label (case-insensitive exact match)
        ?actor rdfs:label ?actorName .
        FILTER(LANG(?actorName) = "en")
        FILTER(LCASE(STR(?actorName)) = LCASE("{actor}"))

        OPTIONAL { ?film wdt:P577 ?publicationDate. }
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      }
      ORDER BY ?filmLabel

  films_by_director_and_actor_dbpedia:
    title: Films by director and actor (DBpedia)
    description: >
      Returns films where an actor starred and the film was directed by the specified director,
      resolved by English labels on DBpedia.
    endpoint: dbpedia
    parameters:
      director:
        example: Garry Marshall
      actor:
        example: Julia Roberts
    query: |-
      PREFIX dbo: <http://dbpedia.org/ontology/>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

      SELECT DISTINCT ?film ?filmLabel ?releaseDate
      WHERE {
        ?film a dbo:Film ;
              dbo:director ?dir ;
              dbo:starring ?actor .

        # match director/actor by English label (case-insensitive exact match)
        ?dir rdfs:label ?dirLabel .
        FILTER(LANGMATCHES(LANG(?dirLabel), "en"))
        FILTER(LCASE(STR(?dirLabel)) = LCASE("{director}"))

        ?actor rdfs:label ?actorLabel .
        FILTER(LANGMATCHES(LANG(?actorLabel), "en"))
        FILTER(LCASE(STR(?actorLabel)) = LCASE("{actor}"))

        OPTIONAL {
          ?film rdfs:label ?filmLabel .
          FILTER(LANGMATCHES(LANG(?filmLabel), "en"))
        }
        OPTIONAL { ?film dbo:releaseDate ?releaseDate . }
      }
      ORDER BY ?filmLabel