Number of incoming link fo each DBpedia resource - sparql

I have the SPARQL DBpedia Query below:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource ?url (count( (?o) as ?nb))
WHERE{
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
?resource dbpedia-owl:wikiPageWikiLink ?o
?Nom <bif:contains> "Apple".
FILTER ( langMatches( lang(?Nom), "EN" )).
MINUS {?resource dbo:wikiPageRedirects|dbo:wikiPageDisambiguates ?dis}
}
Group By ?Nom ?resource ?url
I want to get the number of incoming links of each entitie within wikipedia. How can I proceed?
Thanks

First of all syntax:
you are missing a dot after ?o,
also it should be bif:contains, not <bif:contains>.
Next:
i ran this simpler query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource
WHERE{
?resource rdfs:label ?Nom.
?Nom bif:contains "Apple".
}
which produced a lot of results....
now i added this triple:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource
WHERE{
?resource rdfs:label ?Nom.
?resource dbpedia-owl:wikiPageWikiLink ?o.
?Nom bif:contains "Apple".
}
which returned no results.
this means there is no triple containing apple in its object literal, where the subject has a wikiPageWikiLink in the whole endpoint.
If this property does exist, its instances are not included in the official endpoint since there is no triple containing this property (I checked). This is probably due to the fact, that the official endpoint does not hold every dbpedia dataset, or it might be deprecated.

Related

Sparql: Retrieve information on all people in dbpedia with bulk query

I can fetch several metadata fields for a particular person using the following query at https://dbpedia.org/sparql:
prefix dbpedia: <http://dbpedia.org/resource/>
prefix dbpedia-owl: <http://dbpedia.org/ontology/>
select * {
<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:birthName ?name.
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:birthDate ?birth_date}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:deathDate ?death_date}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:thumbnail ?thumbnail}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:abstract ?abstract FILTER (lang(?abstract) = 'en')}
}
I've also seen query syntax that shows how to get metadata fields on many people at once:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name
WHERE {
?resource rdf:type dbo:Person;
dbp:name ?name.
FILTER (lang(?name) = 'en')
}
ORDER BY ASC(?name)
LIMIT 10000 OFFSET 10000
How can I combine these two so that I can fetch the birth_date, death_date, thumbnail, and abstract (in English) for all people in DBPedia? Any pointers others can offer would be hugely helpful!

Try to look for all space missions in the solar system which have become a satellite of their target

The DBPedia SPARQL endpoint doesn't give any results.
What is wrong?
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
SELECT distinct ?s ?o
FROM <http://dbpedia.org/>
WHERE{
?s dcterms:subject/skos:broader*
dbc:Discovery_and_exploration_of_the_Solar_System ;
dbp:satelliteOf ?o .
}

SPARQL: Federated query gives no result when using local file, while same query on dbpedia does

the local file uploaded on stardog:
#prefix dbo: <http://dbpedia.org/ontology/> .
#prefix dbr: <http://dbpedia.org/resource/> .
dbr:United_States dbo:leader dbr:John_Roberts ,
dbr:Joe_Biden ,
dbr:Barack_Obama ,
dbr:Paul_Ryan .
1.query using the local file:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?person ?o
FROM <http://example.com/leaders.ttl>
WHERE{
dbr:United_States dbo:leader ?person .
SERVICE <http://dbpedia.org/sparql> { ?person dbo:abstract ?o .}
}
2.Same query using only dbpedia will give results:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?person ?o
FROM <http://example.com/leaders.ttl>
WHERE{
#dbr:United_States dbo:leader ?person .
SERVICE <http://dbpedia.org/sparql> { dbr:United_States dbo:leader ?person. ?person dbo:abstract ?o.}
}
Using the second query will result in a colum with the leaders and a column of abstract of the leaders in all languages available from dbpedia. Why does the first query where I use the local rdf file not work? The select query on the local file with dbr:United_States dbo:leader ?person . returns exactly the same column with the same leaders as running it directly on the dbpedia endpoint: dbpedia:John_Roberts, dbpedia:Joe_Biden, dbpedia:Barack_Obama, dbpedia:Paul_Ryan.
Why does the first query give no results?

SPARQL query to get all Person available in DBpedia is showing only some Person data, not all

I am writing SPARQL query to get all Person available in DBpedia. My query is ->
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name
WHERE {
?resource rdf:type dbo:Person;
dbp:name ?name.
FILTER (lang(?name) = 'en')
}
ORDER BY ASC(?name)
It's giving around 10000 rows,when I am taking the output as HTML/csv/spreadsheet format.
But when I am giving query to get total count
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT COUNT(*)
WHERE{
?resource rdf:type dbo:Person;
dbp:name ?name.
FILTER (lang(?name) = 'en')
}
It's giving -> 1783404
Can anyone suggest a solution to get all rows of Person available in DBpedia?
DBPedia is being smart enough here to not overload its servers with large queries, and capping matches at 10000. Since you are ordering the results, you can use LIMIT and OFFSET to get result in sets of 10000. For example, to get the second set of 10000 results use this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name
WHERE {
?resource rdf:type dbo:Person;
dbp:name ?name.
FILTER (lang(?name) = 'en')
}
ORDER BY ASC(?name)
LIMIT 10000 OFFSET 10000
Actually, since DBPedia is limiting the results to 10000 matches, the LIMIT isn't really necessary.

SPARQL: extract the dbo class for each result

I have a DBpedia request that give me a label, a Dpedia URI and the corresponding wikipedia link. I want to add a column to get the dbo class of each line. Can any one help me please?
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
?resource rdf:type ?p
FILTER(regex(?p,"http://dbpedia.org/ontology/"))
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
}
Firstly, if you have the solution, then you should post it as an answer and then mark it as accepted so that it is easier for others looking for the solution.
Secondly, I feel that the solution you came up would work but is not the right way to do it. For getting dbo: types, one should query for types that are owl:Class types.
This is how I would do it
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom ;
foaf:isPrimaryTopicOf ?url ;
a ?p .
?p a owl:Class .
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
} limit 100
Not sure what do you mean by:
get the dbo class of each line.
But if you mean to get all predicates related to each row, the following query may help. I limited them to English ones to see the results better.
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom.
?resource ?p ?dbo.
?resource foaf:isPrimaryTopicOf ?url.
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
FILTER langMatches( lang(?Nom), "en" )
}
limit 100