i'm trying to find the way to collect all the things that have this property:
"http://purl.org/stuff/rev#hasReview"
So I tryed to do this query on the
http://sparql.sindice.com/ endpoint:
PREFIX rev: <http://purl.org/stuff/rev#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE
{
?thing rev:hasReview ?review .
}
And the result was just a few, I think that if you don't provide the uri graph, it will search on his own graph. Is it on that way?
And my other doubt is, how can I know which is the graph uri from http://revyu.com/ for example?
Thanks.
The following query gets the graph:
PREFIX rev: <http://purl.org/stuff/rev#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
{ GRAPH ?graph { ?thing rev:hasReview ?review . } }
}
In case you also want to get the triples in the default graph, you can use:
PREFIX rev: <http://purl.org/stuff/rev#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
{ GRAPH ?graph { ?thing rev:hasReview ?review . } }
UNION
{ ?thing rev:hasReview ?review . }
}
Related
Im trying to query a knowledge graph and im trying print the max occurrence of ?n in the result and i have tried running following query but it just doesn't prints anything
here is my SPARQL Query
PREFIX : <http://www.tafsirtabari.com/ontology#>
PREFIX RDF:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select
?n
(MAX( xsd:int(?countOfSharedLikedItems)) as ?max)
(COUNT(?n) as ?countOfSharedLikedItems)
where {
?h :hasTheme :lugha .
?h RDF:type :Hadith .
?h :hasHadithNo ?o.
?p :isPartOfHadith ?h.
{
?p :hasNarratorSegment ?nc.
?nc :refersTo+/:hasName ?n.
}
Union
{
?p :hasRootNarratorSegment ?rnc.
?rnc :refersTo+/:hasName ?n.
}
}
i have also tried following by using group by ?n
PREFIX : <http://www.tafsirtabari.com/ontology#>
PREFIX RDF:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select
(MAX(?countOfSharedLikedItems) as ?max)
(COUNT(?n) as ?countOfSharedLikedItems)
where {
?h :hasTheme :lugha .
?h RDF:type :Hadith .
?h :hasHadithNo ?o.
?p :isPartOfHadith ?h.
{
?p :hasNarratorSegment ?nc.
?nc :refersTo+/:hasName ?n.
}
Union
{
?p :hasRootNarratorSegment ?rnc.
?rnc :refersTo+/:hasName ?n.
}
} group by ?n
You can try this
PREFIX : <http://www.tafsirtabari.com/ontology#>
select (COUNT(?o ) AS ?triples) where {
?k :heardFrom ?o
}
6. Which RAWI narrated most hadiths about TOPIC_A
PREFIX hash: <http://www.tafsirtabari.com/ontology#>
PREFIX W3:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://www.tafsirtabari.com/ontology#>
SELECT ?total WHERE{
select DISTINCT ?n (COUNT(?n) as ?total) where {
?commentary hash:mentions hash:اهل_المعرفه .
?segment hash:containsCommentary ?commentary.
?segment ?Fr ?h .
?h W3:type hash:Hadith.
?p :isPartOfHadith ?h.
{
?p :hasNarratorSegment ?nc.
?nc :refersTo+/:hasName ?n.
}
Union
{
?p :hasRootNarratorSegment ?rnc.
?rnc :refersTo+/:hasName ?n.
}
}GROUP BY ?n
}ORDER BY DESC(?total)
LIMIT 1
I am getting these results:
[
...
{
resource: {
type: 'uri',
value: 'http://dbpedia.org/resource/Benjamin_Swan_(Vermont)'
},
name: {
type: 'literal',
'xml:lang': 'en',
value: 'Balogun Yakub Abiodun'
}
},
{
resource: {
type: 'uri',
value: 'http://dbpedia.org/resource/Benjamin_Swan_(Vermont_politician)'
},
name: {
type: 'literal',
'xml:lang': 'en',
value: 'Balogun Yakub Abiodun'
}
},
{
resource: {
type: 'uri',
value: 'http://dbpedia.org/resource/Benjamin_Swearer'
},
name: {
type: 'literal',
'xml:lang': 'en',
value: 'Balogun Yakub Abiodun'
}
},
{
resource: {
type: 'uri',
value: 'http://dbpedia.org/resource/Benjamin_Sweet'
},
name: {
type: 'literal',
'xml:lang': 'en',
value: 'Balogun Yakub Abiodun'
}
}
...
]
For this query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name
WHERE {
?resource rdf:type dbo:Person .
?person a dbo:Person .
?person dbp:name ?name .
FILTER (LANG(?name) = 'en') .
}
offset 0
limit 50
The resource is linking to an English-named resource, yet the name returned is not English, even though marked as English. How do I just get the people names and their wikipedia links? It also appears I am requesting two separate things perhaps... How would you get their photo as well?
This is what I've ended up with but it seems to be returning things like List of Scottish X, and other non-people links.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name ?depiction
WHERE {
?resource rdf:type dbo:Person .
?resource dbp:name ?name .
?resource foaf:depiction ?depiction .
FILTER (LANG(?name) = 'en') .
}
order by ?name
offset 0
limit 50
Is it possible to implement blank node skolemization in SPARQL without iteration? It seems to me that iteration is required to skolemize chains of blank nodes, such as:
#prefix : <http://example.com/> .
[ a :A ;
:p1 [
a :B
]
] .
A SPARQL Update operation for skolemization can start from the blank nodes that appear as subjects only in triples without blank node objects:
DELETE {
?b1 ?outP ?outO .
?inS ?inP ?b1 .
}
INSERT {
?iri ?outP ?outO .
?inS ?inP ?iri .
}
WHERE {
{
SELECT ?b1 (uuid() AS ?iri)
WHERE {
{
SELECT DISTINCT ?b1
WHERE {
?b1 ?p1 [] .
FILTER isBlank(?b1)
FILTER NOT EXISTS {
?b1 ?p2 ?b2 .
FILTER isBlank(?b2)
}
}
}
}
}
?b1 ?outP ?outO .
OPTIONAL {
?inS ?inP ?b1 .
}
}
This operation can be repeated until no blank nodes are found in the data:
ASK {
?bnode ?p [] .
FILTER isBlank(?bnode)
}
Is it possible to avoid the iteration and implement the blank node skolemization in a single SPARQL Update operation?
(Also, this approach assumes there are no "orphan" blank nodes (i.e. blank nodes that appear only as objects).)
I found a two-step solution skolemising subjects and objects separately and storing the blank node aliases (links between blank nodes and IRIs via owl:sameAs) as intermediate data:
PREFIX : <http://example.com/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
####################
# Rewrite subjects #
####################
DELETE {
?bnode ?p ?o .
}
INSERT {
?iri ?p ?o .
GRAPH :aliases {
?bnode owl:sameAs ?iri .
}
}
WHERE {
{
SELECT ?bnode (uuid() AS ?iri)
WHERE {
{
SELECT DISTINCT ?bnode
WHERE {
?bnode ?p [] .
FILTER isBlank(?bnode)
}
}
}
}
?bnode ?p ?o .
}
;
###################
# Rewrite objects #
###################
DELETE {
?s ?p ?bnode .
}
INSERT {
?s ?p ?iri .
}
WHERE {
{
SELECT ?bnode ?iri
WHERE {
{
SELECT DISTINCT ?bnode
WHERE {
[] ?p ?bnode .
FILTER isBlank(?bnode)
}
}
OPTIONAL {
GRAPH :aliases {
?bnode owl:sameAs ?_iri .
}
}
BIND (coalesce(?_iri, uuid()) AS ?iri)
}
}
?s ?p ?bnode .
}
;
############################
# Clear blank node aliases #
############################
CLEAR GRAPH :aliases
I have this 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 dbpedia_property: <http://dbpedia.org/property/>
PREFIX dbpedia_ontology: <http://dbpedia.org/ontology/>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX schema: <http://schema.org/>
SELECT * WHERE
{
{
SELECT ?school, ?name, ?snippet, ?url, ?pageid, ?alias_1, ?alias_2, ?alias_3
WHERE
{
{ ?school rdf:type schema:EducationalOrganization . }
UNION
{ ?school rdf:type yago:EducationalInstitution108276342 . }
?school rdfs:label ?name .
OPTIONAL {
?school foaf:isPrimaryTopicOf ?url .
}
OPTIONAL {
?school dbpedia_ontology:wikiPageID ?pageid .
}
OPTIONAL {
?school rdfs:comment ?snippet .
FILTER (langMatches(lang(?snippet),"en"))
}
OPTIONAL {
?school dbpedia_property:name ?alias_1 .
FILTER ( langMatches(lang(?alias_1),"en") )
}
OPTIONAL {
?school foaf:name ?alias_2 .
FILTER ( langMatches(lang(?alias_2),"en") )
}
OPTIONAL {
?school dbpedia_ontology:wikiPageRedirects ?temp .
?temp rdfs:label ?alias_3 .
FILTER ( langMatches(lang(?alias_3),"en") )
}
OPTIONAL {
?school rdf:type ?excluded .
FILTER (?excluded = schema:Library)
}
FILTER ( langMatches(lang(?name),"en") && !BOUND(?excluded) )
}
ORDER BY ?name
}
}
LIMIT 1
OFFSET 0
You can see that the result gives the resource
http://dbpedia.org/resource/"Wesleyan_Methodist_College"
This will be redirected to
http://dbpedia.org/page/Southern_Wesleyan_University
Why doesn't Virtuoso resolve the resource and give the final destination?
Is there a way to instruct it to ignore the redirects?
The /resource/ and the /page/ about the resource are different things. One has a length in bytes, for example.
A web page is not an schema:EducationalOrganization.
If you look up with HTTP the /resource/, DBpedia sends back an HTTP 303 which a browser will then follows. That's your browser's choice.
See the output from:
wget --max-redirect 0 -O/dev/null -S http://dbpedia.org/resource/Wesleyan_Methodist_College
or
curl -v --max-redirs 0 http://dbpedia.org/resource/Wesleyan_Methodist_College
I'd like to do something like
{
SELECT ?page, "A" AS ?type WHERE
{
?s rdfs:label "Microsoft"#en;
foaf:page ?page
}
}
UNION
{
SELECT ?page, "B" AS ?type WHERE
{
?s rdfs:label "Apple"#en;
foaf:page ?page
}
}
But this gives a syntax error. How can I union two select queries in SPARQL?
You can union them like this:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * WHERE
{
{
SELECT ?page ("A" AS ?type) WHERE
{
?s rdfs:label "Microsoft"#en;
foaf:page ?page
}
}
UNION
{
SELECT ?page ("B" AS ?type) WHERE
{
?s rdfs:label "Apple"#en;
foaf:page ?page
}
}
}
(check with the SPARQL validator)
However I don't think you need sub queries at all for this case. For example:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?page ?type WHERE
{
?s foaf:page ?page .
{ ?s rdfs:label "Microsoft"#en . BIND ("A" as ?type) }
UNION
{ ?s rdfs:label "Apple"#en . BIND ("B" as ?type) }
}
Based on #user205512's answer, here's one that works on Virtuoso:
SELECT * {
?s foaf:page ?page .
{
SELECT ?page ("A" AS ?type) {
?s rdfs:label "Microsoft"#en;
foaf:page ?page
}
} UNION {
SELECT ?page ("B" AS ?type) {
?s rdfs:label "Apple"#en;
foaf:page ?page
}
}
}
The trick was just do add an additional ?s foaf:page ?page triple outside of the UNION. This is obviously redundant, but it seems to avoid the Virtuoso bug, which is apparently caused when you have a “naked” UNION with subqueries.