SPARQL Query Involving Chinese Characters - sparql

I am running the following query to obtain translations for the English word "father" on this public endpoint:
PREFIX dbnary: <http://kaiko.getalp.org/dbnary#>
select distinct ?l ?written where
{
dbnary-eng:father dbnary:describes ?le .
?t dbnary:isTranslationOf ?le .
?t dbnary:targetLanguage ?l .
?t dbnary:writtenForm ?written .
}
Among the strings returned, I can also find the Chinese translation "爸爸".
When I try to reverse the query, I do not receive any result for Chinese words (it works for other languages):
PREFIX dbnary: <http://kaiko.getalp.org/dbnary#>
select distinct ?c where
{
?c dbnary:describes ?le .
?t dbnary:isTranslationOf ?le .
?t dbnary:targetLanguage ?l .
?t dbnary:writtenForm "爸爸" .
}
What am I doing wrong?

As Stanislav Kralin correctly points out, the reason for the query not working is the missing language annotation. The correct query formulation is as follows:
PREFIX dbnary: <http://kaiko.getalp.org/dbnary#>
select distinct ?c where
{
?c dbnary:describes ?le .
?t dbnary:isTranslationOf ?le .
?t dbnary:targetLanguage ?l .
{?t dbnary:writtenForm "爸爸"#yue .}
UNION {?t dbnary:writtenForm "爸爸"#cmn .}
}

Related

Querying two RDF graphs in SPARQL

I have two RDF knowledge bases
KB1 (path/to/file1.rdf) wkich includes the two following triples
a b c
a f e
and KB2 (path/to/file2.rdf) with the following triple:
c t p
I want to get all paths include ones like ?a ?b ?c & ?c ?t ?p as c is common.
How can I do that in SPARQL?
In case of two KB, it is what we call a "Federated Query". Here is an example :
SELECT * WHERE {
SERVICE URI_for_path/to/file1.rdf {
?a ?b ?c .
OPTIONAL {
SERVICE URI_for_path/to/file2.rdf {
?c ?t ?p . } }
}
}
You will get ?t ?p only if it exists by the way.
Simpliest way is to load both files in a single KB and therefore have a simple query :
SELECT * WHERE {
?a ?b ?c .
?c ?t ?p .
}

SPARQL Query for all Books by George Orwell

I created this query to return all books that are notable works by George Orwell but it returns no result.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?title where {
?person foaf:name ?name .
?title dbo:author ?person .
?title dbo:notableWork dbp:George_Orwell .
}
I cannot seem to figure out why there is no result.
I am running the query in http://dbpedia.org/snorql
Don't you have the triples about notable works in the wrong order?
Try rewriting based on this working query
SELECT *
WHERE {
:George_Orwell dbo:notableWork ?title
}
.
title
:Nineteen_Eighty-Four
:Animal_Farm
You can also bind :George_Orwell to a variable and ask more about that:
SELECT *
WHERE {
values ?author { :George_Orwell } .
?author rdfs:label ?l .
?title ?p ?author .
?title rdf:type dbo:Book .
filter (lang(?l) = "en")
}
and DESCRIBE things
describe :Animal_Farm

Delete all triples about event time except earliest event time

I have several triples like this
:event1 :hasTimeStamp "2017-06-30T00:01:00Z" .
:event1 :hasTimeStamp "2017-06-30T00:02:00Z" .
:event1 :hasTimeStamp "2017-06-30T00:03:00Z" .
I would like to delete all of the assertions about :event1's timestamp except the earliest.
I know how to select the earliest, insert it into a scratch named graph, delete all :event1 timestamps, and then copy back from the scratch graph.
Is there a way to do the deletion in place, with no utilization of a temporary/scratch graph?
Here's a nested select, where the inner subselect gets the minimum time, which is then be compared with the individual times form the outer select.
Now I just have to wrap that in the delete.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT *
WHERE
{ ?s rdf:type <http://turbo.org/procStartTimeMeas> ;
<http://purl.obolibrary.org/obo/IAO_0000136> ?something .
?something <http://purl.obolibrary.org/obo/RO_0002223> ?another .
?another rdf:type <http://turbo.org/R2RInstantiation> .
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o
{ SELECT ?s (MIN(?o) AS ?earliest)
WHERE
{ ?s rdf:type <http://turbo.org/procStartTimeMeas> ;
<http://purl.obolibrary.org/obo/IAO_0000136> ?something .
?something <http://purl.obolibrary.org/obo/RO_0002223> ?another .
?another rdf:type <http://turbo.org/R2RInstantiation> .
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o
}
GROUP BY ?s
}
FILTER ( ?o != ?earliest )
}
Try this (not in the production environment):
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
DELETE {
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o2 .
}
WHERE {
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o2 .
?s rdf:type <http://turbo.org/procStartTimeMeas> .
FILTER EXISTS {
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o1 .
?s rdf:type <http://turbo.org/procStartTimeMeas> .
FILTER (?o2 > ?o1)
}
}
I'm not sure I understand correctly what these predicates mean.
I suppose <http://purl.obolibrary.org/obo/IAO_0000004> is :hasTimeStamp of the initial example.
In my answer, ?s rdf:type <http://turbo.org/procStartTimeMeas> is the only selection criterion. Please add other criteria.
(An alternative to the nice solution of #StansilavKralin)
I just did it based on the sample data
#prefix : <http://example.org/> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
:event1 :hasTimeStamp "2017-06-30T00:01:00Z"^^xsd:dateTime .
:event1 :hasTimeStamp "2017-06-30T00:02:00Z"^^xsd:dateTime .
:event1 :hasTimeStamp "2017-06-30T00:03:00Z"^^xsd:dateTime .
Not sure whether this is what you want, but at least it's pretty compact and I'm a big fan of MINUS which is at least more human readable (but maybe less performant):
PREFIX : <http://example.org/>
DELETE {
?event :hasTimeStamp ?ts .
}
WHERE
{ ?event :hasTimeStamp ?ts
MINUS
{ { SELECT ?event (MIN(?_ts) AS ?ts)
WHERE
{ ?event :hasTimeStamp ?_ts }
GROUP BY ?event
}
}
}
I think this does what I want, but I'd like to see suggestions from others. I don't want to be reckless with a deletion.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
DELETE {
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o .
}
WHERE
{ SELECT *
WHERE
{ ?s rdf:type <http://turbo.org/procStartTimeMeas> ;
<http://purl.obolibrary.org/obo/IAO_0000136> ?something .
?something <http://purl.obolibrary.org/obo/RO_0002223> ?another .
?another rdf:type <http://turbo.org/R2RInstantiation> .
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o
{ SELECT ?s (MIN(?o) AS ?earliest)
WHERE
{ ?s rdf:type <http://turbo.org/procStartTimeMeas> ;
<http://purl.obolibrary.org/obo/IAO_0000136> ?something .
?something <http://purl.obolibrary.org/obo/RO_0002223> ?another .
?another rdf:type <http://turbo.org/R2RInstantiation> .
?s <http://purl.obolibrary.org/obo/IAO_0000004> ?o
}
GROUP BY ?s
}
FILTER ( ?o != ?earliest )
}
}

How to use Sparql Contains to match similar String?

I'm trying to grab some definition in dbpedia inside my thesaurus.
Although can find country that have a label that match my country, i don't get all of them. So i try to match similar label with contains but it does not work.
Any idea why.
SELECT distinct ?idbcountry ?label ?labelDb ?def
WHERE {
?idbcountry a skos:Concept .
?idbcountry rdfs:label ?label .
?idbcountry skos:inScheme iadb:IdBCountries .
FILTER(lang(?label) = "en")
Service <http://dbpedia.org/sparql> {
?s a <http://dbpedia.org/ontology/Country> .
?s rdfs:label ?labelDb .
FILTER(CONTAINS (?labelDb, ?label)).
?s rdfs:comment ?def .
FILTER(lang(?def) = "en") .
FILTER(lang(?labelDb) = "en") .
}}
The exact matching query that works is as follows:
SELECT distinct ?idbcountry ?label ?def
WHERE {
?idbcountry a skos:Concept .
?idbcountry rdfs:label ?label .
?idbcountry skos:inScheme iadb:IdBCountries .
FILTER(lang(?label) = "en")
Service <http://dbpedia.org/sparql> {
?s a <http://dbpedia.org/ontology/Country> .
?s rdfs:label ?label .
?s rdfs:comment ?def
FILTER(lang(?def) = "en")
}
}
EDIT1
Data Samples:
<http://thesaurus.iadb.org/publicthesauri/10157002136735779158437>
rdf:type skos:Concept ;
dct:created "2015-03-27T16:43:48.052-04:00"^^xsd:dateTime ;
rdfs:label "BO"#en ;
rdfs:label "Bolivia"#en ;
rdfs:label "Bolivia"#es ;
rdfs:label "Bolivie"#fr ;
rdfs:label "Bolívia"#pt ;
skos:altLabel "BO"#en ;
skos:definition "Bolivia (/bəˈlɪviə/, Spanish: [boˈliβja], Quechua: Buliwya, Aymara: Wuliwya), officially known as the Plurinational State of Bolivia (Spanish: Estado Plurinacional de Bolivia locally: [esˈtaðo pluɾinasjoˈnal de βoˈliβja]), is a landlocked country located in western-central South America."#en ;
skos:inScheme :IdBCountries ;
skos:prefLabel "Bolivia"#en ;
skos:prefLabel "Bolivia"#es ;
skos:prefLabel "Bolivie"#fr ;
skos:prefLabel "Bolívia"#pt ;
skos:topConceptOf :IdBCountries ;
<http://xmlns.com/foaf/0.1/focus> <http://dbpedia.org/resource/Bolivia> ;
Without seeing your data, we can't know why your query isn't working. However, using contains is pretty straightforward. It's just a matter of contains(string,substring). As Jeen said, we can't reproduce your problem without knowing what your data looks like, but here's an example of contains in action:
select distinct ?country ?label {
?country a dbpedia-owl:Country ; #-- select countries
rdfs:label ?label . #-- and get labels
filter langMatches(lang(?label),"en") #-- but only English labels
filter contains(?label,"land") #-- containing "land"
}
SPARQL results

SPARQL Query to get Movie detail

To get movie detail from linkedmdb, I used sparql query :
PREFIX mdb: <http://data.linkedmdb.org/resource/movie/film>
SELECT DISTINCT ?Title ?Genre ?Actor ?Country ?Director ?Year WHERE {
?film mdb:id ?uri .
?film dc:title ?Title .
?film movie:genre ?filmgenre.
?filmgenre movie:film_genre_name ?Genre .
?film movie:actor ?cast .
?cast movie:actor_name ?Actor .
?film movie:country ?Ctr .
?Ctr movie:country_name ?Country .
?film dc:date ?Year .
?film movie:director ?Drc .
?Drc movie:director_name ?Director
FILTER regex(?Title, "Kingdom of Heaven")
}
But SPARQL results shown Title same as counted Actor . How to combine the query so that Title is not repeated?
I've try using GROUP_CONCAT but not working in LinkedMDB Endpoint?
Could someone guide me?