How do I run SPARQL-select to Wikidata from Protege? - sparql

I have a query that returns if page with such name exists in Wikidata.
SELECT ?boolean
WHERE{
BIND(EXISTS{?item ?label "Water"} AS ?boolean)
}
Now I need to run it from Protege tab SPARQL-query. What do I have to add to it to make it work? Maybe some prefixes? When I run it as it is now I always get false :(

Related

How to query sparql by value

I have ontology data (ontobible.owl) and its ready to download in https://teamtrainit.com/ontobible.owl
I have open it in Protege (Protege-5.5.0) like this screenshot
how to sparql query to select data where Verse is 1CH11_1 or 1CH11_2 and display verse_text, hasPerson,hasPlace?
Edit:
i've learn about sparql and try with dbpedia, I run this query in dbpedia,
SELECT * WHERE {
?person rdfs:label "Jesus"#en;
dbo:abstract ?abstract
}
its works
but when I try similar query with ontobible.owl in protege, it doesnt works

How to query Wikidata using SPARQL using entity names and also check alternative labels?

I'm trying to query Wikidata using entity names. My goal is to get the Wikidata ID of the entity. Right now I have something like:
SELECT ?item
WHERE {
?item rdfs:label "name_of_thing"#en
}
and while this usually gets the job done I also want to check whether the label is contained in the alternative names on Wikidata.
For example, if I replace "name_of_thing" with "Philippines AirAsia" then I don't get any results, but the reason why is because "AirAsia Philippines" is the proper name of the entry, with "Philippines AirAsia" contained in the "Also known as" column in the Wikidata page.
I want to query the page and if the first fetch fails then check whether the name is contained in the "Also known as" column. How should I go about doing this? Thanks.
The pipe operator works for me:
Query
SELECT ?item ?prefLabel WHERE {
VALUES ?prefLabel { "AirAsia Philippines"#en }
?item rdfs:label|skos:altLabel ?prefLabel
}

Get movie(s) based on book(s) from DBpedia

I am new to SPARQL and trying to fetch a movie adapted from specific book from dbpedia. This is what I have so far:
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT *
WHERE
{
<http://dbpedia.org/page/2001:_A_Space_Odyssey> a ?type.
?type onto:basedOn ?book .
?book a onto:Book
}
I can't get any results. How can I do that?
When using any web resource, and in your case the property :basedOn, you need to make sure that you have declared the right prefix. If you are querying from the DBpedia SPARQL endpoint, then you can directly use dbo:basedOneven without declaring it, as it is among predefined. Alternatively, if you want to use your own, or if you are using another SPARQL client, make sure that whatever short name you choose for this property, you declare the prefix for http://dbpedia.org/ontology/.
Then, first, to get more result you may not restrict the type of the subject of this triple pattern, as there could be movies that actually not type as such. So, a query like this
select distinct *
{
?movie dbo:basedOn ?book .
?book a dbo:Book .
}
will give you lots of good results but not all. For example, the resource from your example will be missing. You can easily check test the available properties between these two resource with a query like this:
select ?p
{
{<http://dbpedia.org/resource/2001:_A_Space_Odyssey_(film)> ?p <http://dbpedia.org/resource/2001:_A_Space_Odyssey> }
UNION
{ <http://dbpedia.org/resource/2001:_A_Space_Odyssey> ?p <http://dbpedia.org/resource/2001:_A_Space_Odyssey_(film)>}
}
You'll get only one result:
http://www.w3.org/2000/01/rdf-schema#seeAlso
(note that the URI is with 'resource', not with 'page')
Then you may search for any path between the two resource, using the method described here, or find a combination of other patterns that would increase the number of results.

Wikidata - Is this query possible?

I want to do a query on WikiData where I get all items, that are somehow connect to another item.
For example I have Item "Vienna" (Q1741). Now I want to get all Items, that have Item Vienna in any property.
The API I currently use is the one from wmflabs. Here I can do a query like
claim[189:1741]
This gives me every item with property "Place of discovery" (P189) = "Vienna" (Q1741).
But what I want is something like
claim[*:1741]
to get all items where any property fits "Vienna", for example "Birthplace" (P19), "Place of Death" (P20) or anything else. But wildcards are not working here.
Is this possible? How?
PS: I'm not bound to this API, I could use any API to wikidata accessible via JS. There are also some SparQL endpoints to Wikidata-Dumps available (like wikidataldf), but I don't know how stable they are. But if anyone could help with a solution using SPARQL, I would be glad, too.
you can use sparql query to Dbpedia to get result for you particular resource, which here is Vienna.
To get all property and their value of resource Vienna use can use
select ?property ?value where {
<http://dbpedia.org/resource/Vienna> ?property ?value
}
Check here
You can choose specific properties of resource using sparql query like this .
select ?country ?density ?timezone ?thumbnail where {
<http://dbpedia.org/resource/Vienna> dbpedia-owl:country ?country;
dbpedia-owl:populationDensity ?density;
dbpedia-owl:timeZone ?timezone;
dbpedia-owl:thumbnail ?thumbnail.
}
Check
maybe something like this:
SELECT ?node WHERE {?node ?pred wd:Q1741}
see on Wikidata Query Service
But what I want is something … to get all items where any property fits "Vienna"[.]
In SPARQL this is very easy. E.g., on DBpedia's SPARQL endpoint:
select ?resource where {
?resource ?property dbpedia:Vienna
}
SPARQL results (limited to 100)
There are already some SPARQL endpoints for Wikidata available. However, they are still beta and only reflect the data from the last dump.
Your query would be this one
See also this help page on Wikidata

Filtering results based on specific properties with specific values (cause timeout connection to DBpedia)

I'm trying to make a SPARQL query using Prolog and DBpedia. My objective is to tag in text all Persons, so for retrieving famous people I made this query that remove all results like Music groups(Band) and Organization, since I want to tag only real people and not abstract
select ?person where{
{
?person a dbpedia-owl:Person; rdfs:label "Name Surname" #it.
}
UNION
{
?person a dbpedia-owl:Person; foaf:name "Name"#it; foaf:surname "Surname"#it.
}
UNION
{
?person a dbpedia-owl:Person; foaf:name "Name Surname"#it.
}
FILTER NOT EXISTS {
{ ?subject <http://airpedia.org/ontology/type_with_conf#10> dbpedia-owl:Band .
?subject rdfs:label ?artistName .
FILTER ( str(?artistName) = "Name Surname" )
}
UNION
{
?subject <http://airpedia.org/ontology/type_with_conf#10> dbpedia-owl:Organisation .
?subject rdfs:label ?artistName .
FILTER ( str(?artistName) = "Name Surname" )
}
}
}
I use It. version of Dbpedia if you run this query use this version although the results will not be good for me.
So for example if I search "Metallica" as a person i don't want to get results cause is it a Band or(for me, but in this case is Metallica are an Organisation too) an Organisation
and it works good this are the results Metallica Query Results and those are for "Michael Jackson" Michael Jackson Query results
My problem is when i put someone that is not a Singer or a Music band for example if i try something like "Jim Carrey" i get " error transction timed out Jim Carrey.
I think I got this problem because those properties are Undefined for Jim Carrey, but i tried an to put an OPTIONAL marker in each subquery in the first filter, but i get too the same error
I put the code in a pastebin file so you can find all three query
I know that i should not use Static String in a query or there are a lot of better mode but i need that since i compose the query with prolog and than send to sparql online so i must do in this way.
TO #Joshua I tried to remove the FILTER(String) in the NOT EXIST (Filter) But I will not work anymore thanks however for helping me
Excuse me for too much editing but i resolved some part of the starting problem but didn't find a solution
First problem :Filtering results based on specific properties with specific values. (Works)
Second : The first works only for Things with that specific property (as show above) like(Metallica,Michael Jackson, The Beatles, ...) but not for thos without the properties in the filter.
(i can't use more than two link because I'm a newbe so i will put a link in the comments with a pastebin links with the 3 Query and the results of they)