Difference between revisions of "Snapquery Cats LLM Rewrite Experiment"
Line 1: | Line 1: | ||
− | + | = Prompt = | |
Rewrite to make blazegraph independent | Rewrite to make blazegraph independent | ||
<source lang='bash'> | <source lang='bash'> | ||
Line 15: | Line 15: | ||
} | } | ||
</source> | </source> | ||
+ | == Prompt for second attempt == | ||
+ | <pre>the result does neither work on the wikidata query service nor on qlever</pre> | ||
+ | |||
= ChatGPT = | = ChatGPT = | ||
To rewrite your SPARQL query to be independent of Blazegraph and remove specific Wikidata or Wikibase dependencies like the SERVICE wikibase:label, you can simplify the query to work on most SPARQL endpoints that contain similar data. This would involve removing the SERVICE block and potentially including explicit property paths for labels if the endpoint doesn't support automated label service. | To rewrite your SPARQL query to be independent of Blazegraph and remove specific Wikidata or Wikibase dependencies like the SERVICE wikibase:label, you can simplify the query to work on most SPARQL endpoints that contain similar data. This would involve removing the SERVICE block and potentially including explicit property paths for labels if the endpoint doesn't support automated label service. | ||
Line 22: | Line 25: | ||
<source lang='sparql'> | <source lang='sparql'> | ||
− | + | = Claude AI 3.5 sonnet = | |
− | # | + | Here's a rewritten version of the SPARQL query that is independent of Blazegraph and Wikidata-specific features: |
+ | |||
+ | <source lang='sparql'> | ||
+ | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | ||
+ | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
+ | |||
SELECT ?item ?itemLabel | SELECT ?item ?itemLabel | ||
− | WHERE | + | WHERE { |
− | { | + | ?item rdf:type <http://example.org/ontology/Cat>. |
− | ?item | + | ?item rdfs:label ?itemLabel. |
− | + | ||
+ | # Language filter (optional, adjust as needed) | ||
+ | FILTER(LANG(?itemLabel) = "" || LANG(?itemLabel) = "en") | ||
} | } | ||
</source> | </source> | ||
− | + | This query has been modified to be more generic and work with standard SPARQL features. Here are the key changes: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Removed Wikidata-specific prefixes and replaced them with standard RDF and RDFS prefixes. | |
+ | Changed the property wdt:P31 (instance of) to a more generic rdf:type. | ||
+ | Replaced the Wikidata item wd:Q146 (cat) with a hypothetical URI <http://example.org/ontology/Cat>. | ||
+ | Removed the Wikidata-specific SERVICE wikibase:label and instead directly query for the label using rdfs:label. | ||
+ | Added an optional FILTER to handle language selection, which you can adjust or remove based on your needs. | ||
− | + | To use this query, you'll need to replace <http://example.org/ontology/Cat> with the appropriate URI for the "cat" concept in your ontology. Also, ensure that your data uses rdfs:label for labeling entities. If your ontology uses a different predicate for labels, you'll need to adjust the query accordingly. | |
+ | Would you like me to explain or break down this SPARQL query further? | ||
[[Category:snapquery]] | [[Category:snapquery]] |
Revision as of 15:32, 12 July 2024
Prompt
Rewrite to make blazegraph independent
# "Cats" example SPARQL query
# https://www.wikidata.org
# /wiki/Wikidata:SPARQL_query_service/queries/examples#Cats
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q146. # Must be a cat
SERVICE wikibase:label {
bd:serviceParam
wikibase:language "[AUTO_LANGUAGE],en".
}
}
Prompt for second attempt
the result does neither work on the wikidata query service nor on qlever
ChatGPT
To rewrite your SPARQL query to be independent of Blazegraph and remove specific Wikidata or Wikibase dependencies like the SERVICE wikibase:label, you can simplify the query to work on most SPARQL endpoints that contain similar data. This would involve removing the SERVICE block and potentially including explicit property paths for labels if the endpoint doesn't support automated label service.
Here's a generalized version of the query, assuming that the endpoint has straightforward label properties and doesn't require language specification:
= Claude AI 3.5 sonnet =
Here's a rewritten version of the SPARQL query that is independent of Blazegraph and Wikidata-specific features:
<source lang='sparql'>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item ?itemLabel
WHERE {
?item rdf:type <http://example.org/ontology/Cat>.
?item rdfs:label ?itemLabel.
# Language filter (optional, adjust as needed)
FILTER(LANG(?itemLabel) = "" || LANG(?itemLabel) = "en")
}
This query has been modified to be more generic and work with standard SPARQL features. Here are the key changes:
Removed Wikidata-specific prefixes and replaced them with standard RDF and RDFS prefixes. Changed the property wdt:P31 (instance of) to a more generic rdf:type. Replaced the Wikidata item wd:Q146 (cat) with a hypothetical URI <http://example.org/ontology/Cat>. Removed the Wikidata-specific SERVICE wikibase:label and instead directly query for the label using rdfs:label. Added an optional FILTER to handle language selection, which you can adjust or remove based on your needs.
To use this query, you'll need to replace <http://example.org/ontology/Cat> with the appropriate URI for the "cat" concept in your ontology. Also, ensure that your data uses rdfs:label for labeling entities. If your ontology uses a different predicate for labels, you'll need to adjust the query accordingly. Would you like me to explain or break down this SPARQL query further?