Is querying the pagerank value on DBpedia no longer available? - sparql

Since the Virtuoso version is updated recently, when I try to use the query below on the public DBpedai SPARQL endpoint. The result is empty.
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX vrank:<http://purl.org/voc/vrank#>
SELECT ?s ?v
FROM <http://dbpedia.org>
FROM <http://people.aifb.kit.edu/ath/#DBpedia_PageRank>
WHERE {
?s rdf:type dbo:University.
?s vrank:hasRank/vrank:rankValue ?v.
}
ORDER BY DESC(?v) LIMIT 50
Thank you!

There is also the option to query the Wikidata endpoint via query federation and map the result to DBpedia URIs:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX vrank: <http://purl.org/voc/vrank#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX schema: <http://schema.org/>
SELECT * WHERE {
{
SELECT DISTINCT ?uni (URI(REPLACE(str(?article), "https://en.wikipedia.org/wiki", "http://dbpedia.org/resource")) as ?dbpedia) WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?uni wdt:P31/wdt:P279* wd:Q3918.
?article schema:about ?uni .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/> .
}
}
}
OPTIONAL {
?uni vrank:pagerank ?rank.
}
} ORDER BY desc(?rank) LIMIT 50
Just run the HDT file with the Wikidata PageRank scores locally as explained on https://github.com/athalhammer/danker-hdt-docker. The result is cleaner (no resources such as dbpedia:Physics in the result set) and the query runs in < 3 seconds.

Related

Get Wikidata entity descriptions via SPARQL, without Wikidata label service

I found this following code snippet on opendata.stackexchange.com, which returns name and description of citizens of the US from Wikidata:
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?Name ?itemDescription WHERE {
?item wdt:P27 wd:Q30 .
?item rdfs:label ?Name
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
LIMIT 3
The query can be evaluated at https://query.wikidata.org/
I am trying to get a description of a particular entity, for example Q3(life). But it in this case, the labelService does not return anything.
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?Name ?itemDescription WHERE {
wd:Q3 rdfs:label ?Name
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
LIMIT 3
EDIT: I am using Virtuoso and therefore cannot rely on Wikidata Label Service.
I am using
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
SELECT ?o
WHERE
{
wd:Q3 schema:description ?o.
FILTER ( lang(?o) = "en" )
}
now, since I am querying a Virtuoso Server with Full-Text-Search capabilities, and it would be better to retrieve the description with other properties in one go.

Finding resource label

I'm currently learning SPARQL, and I'm exploring the data from dbpedia. Why does this query work:
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT
?label
WHERE {
dbr:Leipzig rdfs:label ?label.
} LIMIT 20
But this does not (i.e. id does not return anything)
PREFIX geo: <https://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT
?label ?lat
WHERE {
dbr:Leipzig rdfs:label ?label.
dbr:Leipzig geo:lat ?lat.
} LIMIT 20
Because the protocol of the WGS 84 Geo namespace is http and not https, i.e. http://www.w3.org/2003/01/geo/wgs84_pos#

Sparql - Conditional Output

I am very new to the semantic web and sparql. I have an internal ontology that uses SmartLogic in order to manage the data.
I am writing some simple queries to get started.
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> # Simple Knowledge Organization System - https://www.w3.org/2004/02/skos/
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix ap: <http://cv.ap.org/ns>
SELECT DISTINCT
?subjectPrefLabel ?p ?o ?oL
WHERE {
{
?subject skosxl:prefLabel ?subjectLabel .
?subjectLabel skosxl:literalForm ?subjectPrefLabel .
?subject ?p ?o .
OPTIONAL {?o skos:prefLabel ?oL}
}
FILTER regex(?subjectPrefLabel, "Trump", 'i')
} order by ?subjectPrefLabel
This query returns results that look like :
I am trying to merge the ?o and ?oL fields, so that it will replace the ?o field, if and only if there is a valid ?oL Field
I haven't been able to figure it out quite yet. If there is any suggestions please let me know.
A bit difficult without data for testing the query, but in SPARQL 1.1 you can use BIND(IF(condition,then,else) as ?result ):
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/>
PREFIX ap: <http://cv.ap.org/ns>
SELECT DISTINCT ?subjectPrefLabel ?p ?o
WHERE
{ ?subject skosxl:prefLabel ?subjectLabel .
?subjectLabel
skosxl:literalForm ?subjectPrefLabel .
?subject ?p ?o_tmp
OPTIONAL
{ ?o_tmp skos:prefLabel ?oL }
BIND(if(bound(?oL), ?oL, ?o_tmp) AS ?o)
FILTER regex(?subjectPrefLabel, "Trump", "i")
}
ORDER BY ?subjectPrefLabel

How to query DBpedia SPARQL by resource uri?

I'm querying DBpedia types in SPARQL (http://dbpedia.org/sparql) by resource's label
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://dbpedia.org/resource/>
PREFIX ru: <http://ru.dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?type ?superType WHERE { {
?res rdfs:label "HarryPotter"#en.
} UNION {
?redir dbo:wikiPageRedirects ?res .
?redir rdfs:label "HarryPotter"#en .
}
?res rdf:type ?type .
OPTIONAL {
?type rdfs:subClassOf ?superType .
}
}
It works fine.
But what if I know the exact resource - http://dbpedia.org/page/Harry_Potter? I tried something like:
?res a :Harry_Potter.
But it does not work.
How to query DBpedia types and supertypes if I know the resource URI? I can't figure out which property or operator I should use (e.g., rdfs:Resource, a, etc., which do not work)
When you write
?res a :Harry_Potter.
It doesn't work, because this means "a resource, which is of type :Harry_Potter". It is equivalent to
?res rdf:type :Harry_Potter.
:Harry_Potter identifies a resource and not the type, thus it should be used in place of ?res.
Also I think you mean Harry_Potter_(character), because that is the actual identifier and not redirect.
You query would be as simple as
SELECT ?type ?superType WHERE
{
# give me ?type of the resource
<http://dbpedia.org/resource/Harry_Potter_(character)> rdf:type ?type .
# give me ?superTypes of ?type
OPTIONAL {
?type rdfs:subClassOf ?superType .
}
}
You can just put the URI as the subject in there WHERE conditions.
SELECT ?title, ?releaseDate
WHERE {
<http://dbpedia.org/resource/Super_Mario_Bros._3> dbp:title ?title .
<http://dbpedia.org/resource/Super_Mario_Bros._3> dbo:releaseDate ?releaseDate .
}

Filtering DBpedia disambiguation page

I have a SPARQL Query, and I want to eliminate all disambigution resources. How can I do this? This is my query:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
}
You can add the following prefix and filter to your query:
prefix dbo: <http://dbpedia.org/ontology/>
filter not exists {
?resource dbo:wikiPageRedirects*/dbo:wikiPageDisambiguates ?dis
}
This says to exclude resources and resources that redirect to a resources that disambiguate some articles. That gives you a query like this:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbo: <http://dbpedia.org/ontology/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
filter not exists {
?resource dbo:wikiPageRedirects*/dbo:wikiPageDisambiguates ?dis
}
}
SPARQL results
Now, even though that removes all the disambiguation pages, you may still have results that include "disambiguation" in the title. For instance, one of the results is:
The Little Apple (disambiguation)"#en
http://dbpedia.org/resource/The_Little_Apple_(disambiguation)
Even though that has "disambiguation" in the name, it's not a disambiguation page. It doesn't have any values for dbo:wikiPageDisambiguates. it does redirect to another page, though. You may want to filter out things that redirect to something else, too. You can modify the filter though:
filter not exists {
?resource dbo:wikiPageRedirects|dbo:wikiPageDisambiguates ?dis
}
That says to filter out any resource that either redirects to something, or that disambiguates something. This is actually a simpler filter, really. This makes your query:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbo: <http://dbpedia.org/ontology/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
filter not exists {
?resource dbo:wikiPageRedirects|dbo:wikiPageDisambiguates ?dis
}
}
SPARQL results