Hi Below is my sparql query which I am executing on https://dbpedia.org/sparql. However I am getting an error "Invalid floating point value converting 'United States:'" because of the presence of some characters values in grossincome and If I change my query to str(?grossincome) as ?grossincome1) then it executes correctly. My question is how can I convert all currencies on same scale to avoid this error?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select distinct (str(?resource) as ?movietitle) (xsd:float(?budget) as ?budget1) (xsd:float(?grossincome) as ?grossincome1) (str(?Country) as ?country1) ?ReleaseDate where {
?movie foaf:name ?resource.
?movie dbo:budget ?budget.
?movie dbp:gross ?grossincome.
?movie dbp:country ?Country.
?movie dbo:releaseDate ?ReleaseDate.
FILTER (lang(?resource) = 'en').
}
The data in DBpedia is not perfect as you already recognized it's quite heterogeneous for the untyped property dbp:gross. Among others, it contains values like BDT 2.52 crores, $34,994,648 USD, AU$178,000, 6892098.0, so it is almost impossible to handle different currencies via a SPARQL query such that it returns the values in the same currency.
I mean, you would have to know all different currencies and formats that occur and then handle each separately. But that's more the task of application logic and not the query itself.
Alternatively, you could try to use the data property http://dbpedia.org/ontology/gross instead, which is supposed to relate to values in $. At least that's what its label "gross ($)" states.
Related
I'm trying to write a SPARQL request, where I want to query country names from my own dataset, use the dbpedia resource to retrieve the countrie's latitude and longitude and then calculate the distance among them with the bif:st_distance function. The latitude and longitude I want to use are floats, so I have to convert them to points with bif:st_point first, since the function takes points only.
On my local machine I'm running a apache jena-fuseki server with my dataset loaded. I tried the following:
PREFIX rate: <http://MYNAME.bplaced.net/rating/index.ttl#>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX bif: <bif:>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX afn: <http://jena.apache.org/ARQ/function#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?from ?to ?latituded ?longituded ?latitudeo ?longitudeo ?distance WHERE{
{SELECT ?from ?to (AVG(?latd) as ?latituded)
(AVG(?longd) as ?longituded)
(AVG(?lato) as ?latitudeo)
(AVG(?longo) as ?longitudeo) WHERE {
?rating rate:from dbr:Germany.
?rating rate:year "1965"^^xsd:gYear.
?rating rate:from ?from.
?rating rate:to ?to.
SERVICE <http://dbpedia.org/sparql>{
?from geo:lat ?latd.
?from geo:long ?longd.
?to geo:lat ?lato.
?to geo:long ?longo.
}
} GROUP BY ?from ?to
}
BIND(bif:st_distance(
bif:st_point(?latituded,?longituded),
bif:st_point(?latitudeo,?longitudeo)
)AS ?distance).
}
This leaves me with this result:
The query result
As you can see: The distance column remains empty. I am sure it has something to do with whether or not the BIND statement is located within the SERVICE. Might some values be invisible to the BIND?
What am I doing wrong or what can I do differently to solve this?
Thanks in advance!
The spatial functions in the bif namespace are specific to Virtuoso, the software used by DBpedia. Therefore they will only work in the SERVICE clause where the query is executed on the Virtuoso server. So either use these functions in the SERVICE clause or take a look at the Jena spatial functions.
I am new to RDF, so it will be very nice if you can help me with this!
I am trying to query the subject of pickles called "Umeboshi"(It is japanese pickles) as follows:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?label ?subject
WHERE {
?Thing
rdfs:label ?label;
prop:subject?subject.
FILTER (?label = "Umeboshi")
}
This query doesn't give me any data.
As I don't know where to find available properties I am referring to the Umeboshi page on dbpedia http://live.dbpedia.org/page/Umeboshi.
Thank you very much for your help!
Two things I found:
In the page you give, the label is given in English, but in your query you omit the language.
subject has a different namespace. It is a dcterm concept and not a dbpedia property.
This leads to the following, changed query, which results in three bindings:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?label ?subject
WHERE {
?Thing
rdfs:label ?label;
dct:subject ?subject.
FILTER (?label = "Umeboshi"#en)
}
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: <http://dbpedia.org/>
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
WHERE
{
?school rdf:type yago:EducationalInstitution108276342 .
FILTER ( contains(str(?school), "Australia") )
}
ORDER BY ?school
}
}
Don't mind the extra brackets as this is part of a larger query.
What I want to know is why thi http://dbpedia.org/page/Academic_structure_of_the_Australian_National_University is included in the results since I specify rdf:type yago:EducationalInstitution108276342. This property is not included in the resource page. I'm using this endpoint: http://dbpedia.org/sparql
Looks like a bug in the Pubby Web interface or in the query that is used to get the data that will be shown.
The query
SELECT * WHERE{
<http://dbpedia.org/resource/Academic_Structure_of_the_Australian_National_University> ?p ?o
}
returns the necessary rdf:type statement.
The other strange thing is that even a SPARQL DESCRIBE query does not return the rdd:type triples:
DESCRIBE <http://dbpedia.org/resource/Academic_Structure_of_the_Australian_National_University>
Although DESCIBE is not really defined in the specs, a user would expect those triples for sure. And maybe this kind of query is used to retrieve the data for the Web pages of resources.
I am writing an SPARQL query where I am creating an RDF graph. I am using SPARQL CONSTRUCT. As a requirement of my work, I have to concatenate two subject values and used it with CONSTRUCT statement. I have tried to do following (my RDF graph is in Virtuoso):
prefix map: <#>
prefix db: <>
prefix vocab: <vocab/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>
prefix jdbc: <http://d2rq.org/terms/jdbc/>
prefix fn: <http://www.w3.org/2005/xpath-functions#>
CONSTRUCT {
?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE
{
<http://www.ndssl.bi.vt.edu/fuse#DataSource> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
<http://www.ndssl.bi.vt.edu/fuse#OracleDataSource> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.ndssl.bi.vt.edu/fuse#DataSource>.
?DB <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ndssl.bi.vt.edu/fuse#OracleDataSource>.
<http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
?Table <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion>.
BIND(CONCAT(?DB, ?Table) AS ?p1)
}
However, I am getting following Error:
Virtuoso RDF01 Error Bad variable value in CONSTRUCT: "http://www.ndssl.bi.vt.edu/fuse#PROTOPOPhttp://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1" (tag 246 box flags 0) is not a valid subject, only object of a triple can be a literal
Please let me know how to solve it.
The error is basically saying that you are concatenating two URIs:
http://www.ndssl.bi.vt.edu/fuse#PROTOPOP
http://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1
into a literal. I don't know what you are exactly trying to do, but do you really want to concat the WHOLE URI or only the last part after the #? If you want to concat after the # you need to omit the namespace.
bind (concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:))) as ?p)
Even at this stage the result of the bind is a literal that you need to convert into a URI.
bind (uri(concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:)))) as ?p)
Generally I would simplify your query massively:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix fuse: <http://www.ndssl.bi.vt.edu/fuse#>
prefix owl:<http://www.w3.org/2002/07/owl#>
CONSTRUCT {
?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE
{
fuse:DataSource a owl:Class.
fuse:OracleDataSource rdfs:subClassOf fuse:DataSource.
?DB a fuse:DataSource.
fuse:HouseholdsWithinAdminRegion a owl:Class.
?Table a fuse:HouseholdsWithinAdminRegion.
bind (uri(concat(strafter(str(?DB),str(fuse:)),
strafter(str(?Table),str(fuse:)))) as ?p)
}
I am learning how to create SPARQL queries. Currently, I am using Dbpedia datasets.
I tried to query about "What are the airports that are in Canada" with the following query:
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 : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?name ?country WHERE {
?name rdf:type <http://dbpedia.org/ontology/Airport>;
?name rdf:type <http://dbpedia.org/ontology/Country>
}
LIMIT 20
I am still confused about building SPARQL queries especially with resources and RDF graphs.
What I need is what is the mistake with the above query?
Thanks
The query you are looking for is something like:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?airport ?label WHERE {
?airport rdf:type <http://dbpedia.org/ontology/Airport>;
rdfs:label ?label;
dbpedia-owl:location <http://dbpedia.org/resource/Canada> .
}
This query however doesn't return much results and you would be better of with something like:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?airport ?label WHERE {
?airport rdf:type <http://dbpedia.org/class/yago/AirportsInOntario> ;
rdfs:label ?label .
}
There are various things wrong in your initial query that imply that you should get a better understanding of SPARQL. You need to revise the way you construct the triple patterns. I recommend you to have a look at the following tutorial:
http://www.cambridgesemantics.com/2008/09/sparql-by-example/
Also you will find exploratory SPARQL queries tremendously helpful:
exploratory SPARQL queries?
Your query is currently asking for objects (resources) that have type Airport AND have type Country. Needless to say, there are no results.
You query is also asking for ?country which is completely undefined.
See msalvadores' answer for a correct example...