wikidata sparql query using string - sparql

I would like to query wikidata in order to obtain entries based_on some technologies (blockchain, solid, RDF and so on). These potential technologies would change dynamically, so that, I inject them as literals from a piece of code. The point is that I get no results when trying injecting literals (strings).
In the next piece of SPARQL, you can see five different approaches I tried (all of them fail), through https://query.wikidata.org/
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX xsd: <www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item
WHERE {
#test1 ?item wdt:P144 ?o FILTER (str(?o) = 'blockchain' ) .
#test2 ?item wdt:P144 ?o FILTER (regex (?o,'blockchain')) .
#test3 ?item wdt:P144 ?o FILTER (regex (?o,'^blockchain$')) .
#test4 ?item wdt:P144 'blockchain' .
#test5 ?item wdt:P144 "blockchain" .
}
Any clue?
Thx in advance for your time and support.

Related

How to query specific entities from Wikidata by ID using a SPARQL query?

I need a SPARQL query returning a specific Wikidata ID or a list of IDs. In real life such query is useless but I need it for testing purposes.
The easiest variant I could come up with was:
SELECT DISTINCT ?s
WHERE
{
?s ?p ?o
FILTER (?s = wd:Q151345).
}
I have to use DISTINCT because ?s ?p ?o matches every triple within Q151345, if I omit it it output the item as many times as many property-value pairs it has.
Is there any easier way?
With the keyword VALUES, it's possible to use multiple instances.
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?s
WHERE
{
VALUES ?s { wd:Q151345 wd:Q2996394 }
?s ?p ?o
}
LIMIT 10
Demo : http://linkedwiki.com/query/Query_multiple_instance_of_in_same_query
Doc: https://www.w3.org/TR/sparql11-query/#inline-data
#greatvovan You can try
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?s WHERE {
SELECT ?s WHERE
{
VALUES ?s { wd:Q151345 wd:Q2996394 }
?s ?p ?o
}
}

SPARQL DBpedia get properties of a person knowing their name

new to SPARQL. Trying to figure out why I get different results on these two queries. It's based on this other question, where I'm trying to match properties to a name of a person. For example, I'm curious to know the birthday of J.K. Rowling, without knowing her URI directly. Here's the code from the link above:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "Car"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
compared to the query I'd like with J.K.:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "J.K. Rowling"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
The first one works fine, however, when I replace "Car" with "J.K. Rowling" as in the second, nothing is returned (her URI is return if I remove the dbo:abstract line and the filter line for it). J.K. Rowling does have a dbo:abstract in English. I'm not sure why it works for one and not the other. The only thing I can see that that 'Car' is a 'Thing', while J.K. is a 'person'

Simple SPARQL Query

I am working from this example, and I want to archieve the same, however with a different topic - Climate change
All i need to output is the abstract from this page: http://dbpedia.org/page/Climate_change
PREFIX dbp-res: <http://dbpedia.org/resource/>
PREFIX dbp-ont: <http://dbpedia.org/ontology/>
PREFIX dbp-prop: <http://dbpedia.org/property/>
SELECT *
WHERE
{
?Resource a dbp-ont:Agent .
?Resource dbp-ont:abstract ?Description .
?Resource rdfs:label ?Label .
FILTER( STR(?Label) = 'Climate_change' )
FILTER (langMatches(lang(?Description),'en'))
FILTER (langMatches(lang(?Label),'en'))
}
The problem seems to be the Agent, but I have no clue, as to what to replace it with.
My query

How to query dbpedia.org with sparql

I'm very new in OpenData and try to write a query in SPARQL.
My goal is to get data for following set of criteria:
- Category: Home_automation
- select all items from type "Thing"
- with at least one entry in "is Product of"
- that have a picture-url with a German description
I tried the following:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
cat:Home_automation skos:broader ?x
}
But now I don't know how to add the other filters to the where clause.
I tried to user broader:... to get the items, but I think that was the wrong direction.
I tested the queries with: https://dbpedia.org/sparql
The result should be:
| (label) | (url)
|--------------------------|-----------------------------------
|"Kurzzeitwecker"#de | urls to the picture of the device
|"Staubsauger"#de | -||-
|"Waschmaschine"#de | -||-
|"Geschirrspülmaschine"#de | -||-
Does anyone have some tips please?
UPDATE: new query:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s ?label WHERE {
?s ?p cat:Home_automation .
?s rdf:type owl:Thing .
?s rdfs:label ?label
FILTER (LANG(?label)='de')
}
order by ?p
It is not clear what you want. You must first know what exact related information dbpedia contains and how they are structured.
However, you can try discovering what types of relationships cat:Home_automation is involved in, thus, you may know better what you want.
I suggest starting by generic queries, to specify how cat:Home_automation occurs in dbpedia, then, you might be able to go more specific, and pose further queries.
A query to list triples where cat:Home_automation is an subject:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?p ?o WHERE {
cat:Home_automation ?p ?o
}
order by ?p
A query to list triples where cat:Home_automation is an object:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?s ?p WHERE {
?s ?p cat:Home_automation
}
order by ?p
check the results, see what is interesting for you, and then continue with further queries.

dbpedia fetch entitites in language other than english

I'm trying to extract entity dictionary contains person name etc. from dbpedia using sparql.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:name ?name . FILTER(lang(?name) = "en")
}
The query above did succeed, but when I change the language name to fr, there is nothing to fetch.
How can I fetch names in other languages?
Moreover, why can't I filter language using query below?
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:language "English"
?person dbpprop:name ?name .
}
// this query returns nothing
I tried to fetch all languages using
SELECT DISTINCT ?lanName
WHERE {
?person a owl:Person .
?person dbpprop:language ?lanName .
}
and the result set contains English.
You need to filter based on the language of the value of the property. Not every property will have values in different languages, but some properties will. It seems, from your example, that dbpprop:name doesn't have values in every language. You may find more values in other languages if you look on the other language specific DBpediae.
However, for something like a name, you'll probably get multi-language results if you use the rdfs:label property. For instance, to get the names of Barack Obama, Daniel Webster, and Johnny Cash in Russian, you could do:
select ?label {
values ?person { dbpedia:Johnny_Cash dbpedia:Barack_Obama dbpedia:Daniel_Webster }
?person rdfs:label ?label .
filter langMatches(lang(?label),"ru")
}
SPARQL results
As an aside, note the use of langMatches rather than equality for matching language tags. This is usually a better approach, because it will correctly handle the different language tags within a language For example (from the SPARQL specification), you can find both of the French literals:
"Cette Série des Années Soixante-dix"#fr .
"Cette Série des Années Septante"#fr-BE .
with langMatches(lang(?title),"fr"), but only the first one with lang(?title) = "fr".
You are looking for rdfs:label for a name, of course all the names are English, you are looking at the English dbpedia.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
FILTER(lang(?name) = "fr")
}
Again, for the second one, if you replace the name with the rdfs: label you can have:
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
?person dbpprop:language <http://dbpedia.org/resource/English_language>.
}