SPARQL - select from skos:category - Virtuoso 37000 - sparql

I have problem with SPARQL. I want to select something from category. For example subjects. I make query like this in http://dbpedia.org/snorql.
SELECT ?category ?subject WHERE
{
?category a skos:Concept .
?category skos:Concept: American_punk_rock_guitarists.
?category dct:subject ?subject .
} LIMIT 1000
I have error Virtuoso 37000. I don't understand why.
P.S. Is it good book for beginnier in SPARQL - Learning SPARQL, 2nd Edition
Querying and Updating with SPARQL 1.1 ?

You have at least one syntax error: the second colon (:) in the second triple.
Semantically... I don't really know the classes or predicates in dbpedia... but can skos:Concept be both a type and a predicate?
I wrote you a valid query that returns 10 members of the category "American_punk_rock_guitarists"
I put this together by going to dbpedia's faceted free text search and familiarizing myself with the concept of American punk rock guitarists, specifically Joey Ramone
prefix dbpcat: <http://dbpedia.org/resource/Category:>
SELECT ?subject ?category
WHERE
{ values ?category { dbpcat:American_punk_rock_guitarists } .
?subject dct:subject ?category }
LIMIT 10

Related

i want to get the names of similar types using sparql queries from dbpedia

I need to find the names of similar types from DBpedia so I'm trying to figure out a query which can return me the names of entities which have same subject type in its dct:subject (example I want to find similar types of white house so i want to write a query for same . I'm considering the dct:subject to find them ). If there is any other approach please mention it
Previously I tried it for rdf:type but the result are not so good and some time it shows time out
I have done my problem by the query mentioned below and now i want to consider dct:subject instead of rdf:type
select distinct ?label ?resource count(distinct ?type) as ?score where {
values ?type { dbo:Thing dbo:Organization yago:WikicatIslam-relatedControversies yago:WikicatIslamistGroups yago:WikicatRussianFederalSecurityServiceDesignatedTerroristOrganizations yago:Abstraction100002137 yago:Act100030358 yago:Cabal108241798 yago:Group100031264 yago:Movement108464601 yago:PoliticalMovement108472335
}
?resource rdfs:label ?label ;
foaf:name ?name ;
a ?type .
FILTER (lang(?label) = 'en').
}
ORDER BY DESC(?score)

How to exclude nodes from path?

I want to get all mathematicians from DBpedia, so I wrote this query for DBpedia's SPARQL service:
SELECT DISTINCT ?person
{
?person dct:subject ?category.
?category skos:broader* dbc:Mathematicians.
}
The problem with this is that the category Mathematicians is polluted, due to categories like dbc:Euclid, which then includes all of Euclidean geometry. I believe it's categories like these which cause the query to fail:
Virtuoso 42000 Error TN...: Exceeded 1000000000 bytes in transitive temp memory. use t_distinct, t_max or more T_MAX_memory options to limit the search or increase the pool
A lot of the problematic categories are in dbc:Wikipedia_categories_named_after_mathematicians.
Is there some way to ignore these categories in the skos:broader* path that would make the error go away?
You can list the categories that you don't want to include by filtering them out:
SELECT DISTINCT ?person
{
?person dct:subject ?category.
?category skos:broader* dbc:Mathematicians.
FILTER (?category NOT IN (dbc:Euclid))
}
But that won't remove the error because Virtuoso still needs to traverse the skos:broader hierarchy, exhausting 'transitive heap memory'. Other approaches include selecting specific categories or traversing part of the hierarchy.
The specific category could use UNION statements, but the VALUES shortcut is a simpler syntax:
SELECT DISTINCT ?person
{
VALUES ?category {dbc:Mathematicians dbc:Mental_calculators dbc:Lists_of_mathematicians}
?person dct:subject ?category.
}
For querying part of the hierarchy, you can use some property path expressions. This one will get parents and grandparents:
SELECT DISTINCT ?person
{
?person dct:subject ?category.
?category skos:broader | (skos:broader/skos:broader) dbc:Mathematicians.
# filter as desired - FILTER (?category NOT IN (dbc:Euclid))
}

Not able to get Indian cities abstract from Sparql

I am trying to get abstract using Sqarql with dbpedia datasets.
When I am running the following query on Virtuoso,
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "London"#en }
}
LIMIT 10
I am getting the result, however if I modify the name to say 'Gokarna' which is a south indian tourist spot, I am not getting any data. However I do see the resource page online on dbpedia for Gokarna(http://dbpedia.org/page/Gokarna,_India). What am I doing wrong? I need to get similar data for close to 800 indian places.
When you use values, you'd get only those that exactly match your string. For Gokarna, that would work for #de, #it, #fr, but not for #en, as there the label is different, as you can see also from the previous answer.
I would suggest to use contains, instead of values:
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
FILTER langMatches(lang(?name),"en")
FILTER CONTAINS (?name, "Gokarna" )
}
LIMIT 10
I am not that experience with Sqarql but as much i can see in your code and checked with dbpedia library...
it is not just Gokarna. it is "Gokarna,_India".
This should work..
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "Gokarna,_India"#en }
}
LIMIT 10
If you look through the DBpedia page for Gokarna, India that you linked to, you'll notice that its rdfs:label is "Gokarna, India". But its foaf:name is just "Gokarna". This would mean you should modify your query to:
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ foaf:name ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "Gokarna"#en }
}
LIMIT 10
Though this will return other Gokarnas too: Gokarna, Nepal, Gokarna, Bangladesh and Gokarna (film). If you want to remove these, you will have to figure out another filter (possibly dbo:country dbr:India).

How to ASK if there is any country in the United Nations called “Paris” using SPARQL

I have been trying to do this query but im not sure about how is the syntax I need. I have seen a lot of examples of how to ask in a query to check if something is larger or shorter than other thing, but I have no idea of how to ask if something is IN other thing.
This is my last (failed) try:
PREFIX : <http:/dbpedia.org/resource/>
ASK
{
FILTER(<http:/dbpedia.org/resource/Paris> IN <http:/dbpedia.org/resource/Member_states_of_the_United_Nations>)
}
Part of the issue is that there's a DBpedia resource called
http:/dbpedia.org/resource/Member_states_of_the_United_Nations
but what you actually want, since its the value of the dct:subject property, is the category,
http://dbpedia.org/page/Category:Member_states_of_the_United_Nations
For instance, you can get a list of countries that are member states with a query like:
select ?country {
?country a dbo:Country ;
dct:subject dbc:Member_states_of_the_United_Nations
}
SPARQL results
However, Paris isn't a country that's a member. It's a city in France, which is a member. You can check whether something is a member with an ask query like:
ask {
dbr:France a dbo:Country ;
dct:subject dbc:Member_states_of_the_United_Nations
}
SPARQL results (true)
You could get a list of populated places in countries that are member with a query like:
select ?city ?country {
?city a dbo:PopulatedPlace ;
dbo:country ?country .
?country a dbo:Country ;
dct:subject dbc:Member_states_of_the_United_Nations .
}
SPARQL results (limited to 100)
and you can modify that to be an ask query that checks for cities with specific names. E.g.:
ask {
?city rdfs:label "Paris"#en ;
a dbo:PopulatedPlace ;
dbo:country ?country .
?country a dbo:Country ;
dct:subject dbc:Member_states_of_the_United_Nations .
}
SPARQL results (true)
Using the dc:hasPart term :
<http:/dbpedia.org/resource/Member_states_of_the_United_Nations> <http://dublincore.org/documents/dcmi-terms/#terms-hasPart> <http:/dbpedia.org/resource/Paris>
This is described in this w3 document.

Querying subclasses through Fuseki

I use the following simple SPARQL query to obtain a list of classes of an ontology and their subclasses through Fuseki:
SELECT DISTINCT ?subject ?object
WHERE { ?subject rdfs:subClassOf ?object }
This way, I can see the complete URI of all the classes. Now, I would like to query the subclasses of a specific class, say abc
I look at the output of the query and I see the URI of the class in focus abc is this:
http://blahblahblah/file.owl#abc
So, I pose the following SPARQL query to get its subclasses:
SELECT DISTINCT ?subject
WHERE { ?subject rdfs:subClassOf http://blahblahblah/file.owl#abc }
But the output is empty. I also trying enclosing the URL within single quote and double quotes, to no avail.
SELECT DISTINCT ?subject
WHERE { ?subject rdfs:subClassOf 'http://blahblahblah/file.owl#abc' }
SELECT DISTINCT ?subject
WHERE { ?subject rdfs:subClassOf "http://blahblahblah/file.owl#abc" }
What am I doing wrong?
Thanks,
The syntax for IRIs in SPARQL encloses IRIs in angle brackets (< and >). Your query should be written as:
SELECT DISTINCT ?subject
WHERE { ?subject rdfs:subClassOf <http://blahblahblah/file.owl#abc> }