sparna-git / Sparnatural

Sparnatural : visual knowledge graph explorer with SPARQL, in the browser, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
225 stars 41 forks source link

Text description of a generated query (LLM-generated ?) #655

Open tfrancart opened 1 month ago

tfrancart commented 1 month ago

Could we ask an LLM to produce a text description of the query ? if we pass it the SHACL config with labels and the query ?

tfrancart commented 1 month ago

Prompt attempt with ChatGPT:

""" You are a bot that generate human-readable text from SPARQL queries. Using the following labels, generate a textual description of the following query. The textual description should be brief, 3 sentences maximum. Do not describe "LIMIT" values, and do not describe label languages criteria.

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
<http://dbpedia.org/ontology/Artwork> rdfs:label "Artwork"@en .
<http://dbpedia.org/ontology/museum> rdfs:label "in museum"@en .
<http://dbpedia.org/ontology/displays> rdfs:label "displays"@en .
<http://dbpedia.org/ontology/Museum> rdfs:label "Museum"@en .
<http://dbpedia.org/ontology/country> rdfs:label "in country"@en .
<http://dbpedia.org/resource/Italy> rdfs:label "Italy"@en .

The query:

PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# SELECT DISTINCT ?Artwork_1 ?Artwork_1_label ?Museum_2 ?Museum_2_label WHERE { ?Artwork_1 rdf:type http://dbpedia.org/ontology/Artwork; rdfs:label ?Artwork_1_label. FILTER((LANG(?Artwork_1_label)) = "en") ?Artwork_1 (http://dbpedia.org/ontology/museum|^http://dbpedia.org/ontology/displays) ?Museum_2. ?Museum_2 rdf:type http://dbpedia.org/ontology/Museum; rdfs:label ?Museum_2_label. FILTER((LANG(?Museum_2_label)) = "en") ?Museum_2 http://dbpedia.org/ontology/country http://dbpedia.org/resource/Italy. } LIMIT 1000 """

Answer:

""" The query retrieves artworks and their respective English labels that are either displayed in or belong to museums. It specifically focuses on museums located in Italy and fetches the English labels for those museums as well. The query aims to present a list of artworks, their labels, and the associated museums where they are located in Italy. """

tfrancart commented 1 month ago

Much better attempt:

""" You are a bot that generate human-readable summaries of SPARQL queries. Using the following labels, generate a summary of the following query. The summary should be brief. Do not describe "LIMIT" values, and do not describe languages criteria. Do not start the summary by "The query", instead start directly describing what the query does.

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
<http://dbpedia.org/ontology/XYZ> rdfs:label "Artwork"@en .
<http://dbpedia.org/ontology/museum> rdfs:label "in museum"@en .
<http://dbpedia.org/ontology/displays> rdfs:label "displays"@en .
<http://dbpedia.org/ontology/Museum> rdfs:label "Museum"@en .
<http://dbpedia.org/ontology/country> rdfs:label "in country"@en .
<http://dbpedia.org/resource/ABC345> rdfs:label "Italy"@en .

The query:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Artwork_1 ?Artwork_1_label ?Museum_2 ?Museum_2_label WHERE {
  ?Artwork_1 rdf:type <http://dbpedia.org/ontology/XYZ>;
    rdfs:label ?Artwork_1_label.
  FILTER((LANG(?Artwork_1_label)) = "en")
  ?Artwork_1 (<http://dbpedia.org/ontology/museum>|^<http://dbpedia.org/ontology/displays>) ?Museum_2.
  ?Museum_2 rdf:type <http://dbpedia.org/ontology/Museum>;
    rdfs:label ?Museum_2_label.
  FILTER((LANG(?Museum_2_label)) = "en")
  ?Museum_2 <http://dbpedia.org/ontology/country> <http://dbpedia.org/resource/ABC345>.
}
LIMIT 1000

"""

Answer:

""" Retrieves artworks and their labels, along with the museums and their labels, where the artworks are associated with museums in Italy. """

tfrancart commented 1 month ago

Third attempt, event better without the "_label" variables:

""" You are a bot that generate human-readable summaries of SPARQL queries. Using the following labels, generate a summary of the following query. The summary should be brief. Do not describe "LIMIT" values, and do not describe languages criteria. Do not start the summary by "The query", instead start directly describing what the query does. Do not consider the "_label" variables

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
<http://dbpedia.org/ontology/XYZ> rdfs:label "Artwork"@en .
<http://dbpedia.org/ontology/museum> rdfs:label "in museum"@en .
<http://dbpedia.org/ontology/displays> rdfs:label "displays"@en .
<http://dbpedia.org/ontology/Museum> rdfs:label "Museum"@en .
<http://dbpedia.org/ontology/country> rdfs:label "in country"@en .
<http://dbpedia.org/resource/ABC345> rdfs:label "Italy"@en .

The query:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Artwork_1 ?Artwork_1_label ?Museum_2 ?Museum_2_label WHERE {
  ?Artwork_1 rdf:type <http://dbpedia.org/ontology/XYZ>;
    rdfs:label ?Artwork_1_label.
  FILTER((LANG(?Artwork_1_label)) = "en")
  ?Artwork_1 (<http://dbpedia.org/ontology/museum>|^<http://dbpedia.org/ontology/displays>) ?Museum_2.
  ?Museum_2 rdf:type <http://dbpedia.org/ontology/Museum>;
    rdfs:label ?Museum_2_label.
  FILTER((LANG(?Museum_2_label)) = "en")
  ?Museum_2 <http://dbpedia.org/ontology/country> <http://dbpedia.org/resource/ABC345>.
}
LIMIT 1000

"""

Answer:

""" Retrieves a list of artworks and their corresponding museums, specifically focusing on artworks displayed in museums located in Italy. """

tfrancart commented 1 month ago

Fourth attempt, more complex, summary is perfect

image

""" You are a bot that generate human-readable summaries of SPARQL queries. Using the following labels, generate a summary of the following query. The summary should be brief. Do not describe "LIMIT" or "DISTINCT" clauses, and do not describe languages criteria. Do not start the summary by "The query", instead start directly describing what the query does. Ignore the "_label" variables

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
<http://dbpedia.org/ontology/XYZ> rdfs:label "Artwork"@en .
<http://dbpedia.org/ontology/author> rdfs:label "author"@en .
<http://dbpedia.org/ontology/Person> rdfs:label "Person"@en .
<http://dbpedia.org/ontology/birthPlace> rdfs:label "birth place"@en .
<http://dbpedia.org/ontology/country> rdfs:label "in country"@en .
<http://dbpedia.org/resource/country> rdfs:label "country"@en .
<http://purl.org/dc/terms/subject>  rdfs:label "category"@en.
<http://dbpedia.org/resource/Category:Artists_who_committed_suicide> rdfs:label "Artists who committed suicide"@en .
<http://dbpedia.org/property/year> rdfs:label "creation year"@en .

The query:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Artwork_1 ?Artwork_1_label ?Date_12 WHERE {
  ?Artwork_1 rdf:type <http://dbpedia.org/ontology/XYZ>;
    rdfs:label ?Artwork_1_label.
  FILTER((LANG(?Artwork_1_label)) = "en")
  ?Artwork_1 <http://dbpedia.org/ontology/author> ?Person_2.
  ?Person_2 rdf:type <http://dbpedia.org/ontology/Person>;
    (<http://dbpedia.org/ontology/birthPlace>/<http://dbpedia.org/ontology/country>) <http://dbpedia.org/resource/Italy>;
    <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Artists_who_committed_suicide>.
  ?Artwork_1 <http://dbpedia.org/property/year> ?Date_12.
}
LIMIT 1000

"""

Answer

""" Retrieve information about artworks created by Italian artists who are categorized as having committed suicide, including the artwork's name and creation year. """

ch-sander commented 1 week ago

See