I would like to know what are the triples that are in a repository but that are not included in other repository.
But for doing this, I would need to reference the two repositories in a federated query.
I'm using Allegrograph.
Example on FactForge (i. e., using SPARQL 1.1 federated queries, not Allegrograph's federated stores):
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
CONSTRUCT { ?s ?p ?o }
{
VALUES (?s) {(dbr:Yekaterinburg)}
?s ?p ?o.
MINUS
{
SERVICE <http://dbpedia.org/sparql>
{
VALUES (?s) {(dbr:Yekaterinburg)}
?s ?p ?o
}
}
}
Obviously, one can't subtract DBpedia from DBpedia Live in this way, at least one resultset should be relatively small. It seems that Allegrograph's federated stores couldn't help in such substraction task. Probably you should divide your triples into named graphs, not into separate stores.
With AllegroGraph there are 2 ways this can be achieved:
(1) AllegroGraph allows you to federate multiple local and/or remote triple stores into a single virtual store which can then be queried as a single triple store.
(2) You can use SPARQL 1.1 federated queries which use the SERVICE keyword. Here is an example from the Learning SPARQL book:
PREFIX gp: <http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/people/>
SELECT ?dbpProperty ?dbpValue ?gutenProperty ?gutenValue
WHERE
{
SERVICE <http://DBpedia.org/sparql>
{
<http://dbpedia.org/resource/Joseph_Hocking> ?dbpProperty ?dbpValue .
}
SERVICE <http://wifo5-04.informatik.uni-mannheim.de/gutendata/sparql>
{
gp:Hocking_Joseph ?gutenProperty ?gutenValue .
}
}
Related
I am querying an ontology on the Bioportal endpoint. The ontology (NIF) is stored as a graph, so I put it in the FROM clause as the endpoint instructed.
SELECT DISTINCT ?p
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?p a rdf:Property
}
limit 100
However, as can be seen below, the results came back showing few properties related to NIF and others to a different ontology called SKOS (Simple Knowledge Organization System).
In the Bioportal documentation it is said it maps some properties to SKOS properties, so I thought maybe the results are fine.
However, I had to test if I am querying the correct graph. So I used the below code to count the number of nodes since I know the NIF has around 3.6 million triples!
SELECT (count (*) as ?nodes)
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?s ?p ?o
}
This resulted in 7984 nodes with and without the FROM clause! So I guessed I should be using the "count" incorrectly!
So I wonder how I should make sure that I am just querying the NIF ontology. Also, how to count its nodes?
Thanks :)
Try using SERVICE keyword.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://bioportal.bioontology.org/ontologies/NIF>
{
?s ?p ?o
}
}
If this fails, possibly the service you are connecting is not correct or up.
Try below example which connects to DBpedia:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://DBpedia.org/sparql>
{
?s ?p ?o
}
}
By the way I can;t access URL http://bioportal.bioontology.org/ontologies/NIF. Seems to be unavailable or down.
I need some help to calculate the difference between two dates with SPARQL in Ontotext GraphDB. I know that SPARQL protocol does not support arithmetic operation on dates, however some SPARQL engines support it.
Just as an example in Fuseki I could do .
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?duration
WHERE {
BIND (("2011-02-04T14:45:13.815-05:00"^^xsd:dateTime - "2011-02-
02T14:45:13.815-05:00"^^xsd:dateTime) AS ?duration)
}
the result is duration: "P2DT0H0M0.000S"^^xsd:duration. Then I can get 2 days diff, or Virtuoso provides a built-in function bif:datediff.
My question is, if is there something similar on GraphDB to solve this easy problem without a big workaround.
Thanks in advance.
That was solved in 8.7.0 (released 28 September):
GDB-2887 As a GraphDB user I need support of “+” / “-” operations between xsd:dateTime and xsd:duration with SPARQL
Now your query should return "P2DT0H0M0.000S"^^xsd:dateTimeDuration.
Alternatively, one could use federated queries to public endpoints based on Virtuoso, Blazegraph, Fuseki etc.:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX bif: <bif:>
SELECT ?duration1 ?duration2 ?duration3 ?duration4 {
VALUES (?start ?end)
{("2011-02-02T14:45:14"^^xsd:dateTime "2011-02-04T14:45:13"^^xsd:dateTime)}
SERVICE <http://dbpedia.org/sparql> #-- Virtuoso
{ BIND ((?end - ?start)/86400.0 AS ?duration1) }
SERVICE <http://dbpedia.org/sparql> #-- Virtuoso
{ BIND (bif:datediff("day", ?start, ?end) AS ?duration2) }
SERVICE <https://query.wikidata.org/sparql> #-- Blazegraph
{ BIND ((?end - ?start) AS ?duration3) }
SERVICE <http://zbw.eu/beta/sparql/stw/query> #-- Fuseki
{ BIND (day(?end - ?start) AS ?duration4) }
}
Try on FactForge!
How can i query a remote endpoint (like endpoints of DBPedia or Wikidata) and insert resulting triples in a local graph? So far, i know that there are commands like INSERT, ADD, COPY etc. which can be used for such tasks. What i don't understand is how to address a remote endpoint while updating my local graph. Could someone provide a minimum example or the main steps?
I'm using Apache Jena Fuseki v2 on Windows and this is my query so far:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
INSERT
{ GRAPH <???> { ?s ?p ?o } } #don't know what to insert here for "GRAPH"
WHERE
{ GRAPH <???> #don't know what to insert here for "GRAPH" either
{ #a working example query for wikidata:
?s wdt:P31 wd:Q5. #humans
?s wdt:P54 wd:Q43310. #germans
?s wdt:P1344 wd:Q79859. #part of world cup 2014
?s ?p ?o.
}
}
My local endpoint i'm querying is http://localhost:3030/mylocaldb/update. I've read that /update is necessary to edit the database (i'm not sure if i understood that correctly though).
Is my approach correct so far? Or is more stuff like additional scripting outside SPARQL needed?
Taken from the SPARQL 1.1 Update W3C specs:
The syntax is
( WITH IRIref )?
INSERT QuadPattern
( USING ( NAMED )? IRIref )*
WHERE GroupGraphPattern
If the INSERT template specifies GRAPH blocks then these will be the graphs affected. Otherwise, the operation will be applied to the default graph, or, respectively, to the graph specified in the WITH clause, if one was specified. If no USING (NAMED) clause is present, then the pattern in the WHERE clause will be matched against the Graph Store, otherwise against the dataset specified by the USING (NAMED) clauses. The matches against the WHERE clause create bindings to be applied to the template for determining triples to be inserted (following the same rules as for DELETE/INSERT).
So this basically means, you can omit the GRAPH definition from the INSERT part if you want to store it in the default graph, otherwise it will be the graph in which you want to store the data.
Regarding the WHERE clause, usually you would have to use the SERVICE keyword here to apply federated querying on the Wikidata endpoint (https://query.wikidata.org/bigdata/namespace/wdq/sparql):
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
INSERT
{ ?s ?p ?o }
WHERE
{ SERVICE <https://query.wikidata.org/bigdata/namespace/wdq/sparql>
{ #a working example query for wikidata:
?s wdt:P31 wd:Q5. #humans
?s wdt:P54 wd:Q43310. #germans
?s wdt:P1344 wd:Q79859. #part of world cup 2014
?s ?p ?o.
}
}
I tested it with Apache Jena and it inserts 4462 triples into my local dataset.
Is there any graph that contains mappings between equivalent properties in DBPedia and Yago? My application requires to "merge" triples that express the same meaning in both datasets, but I couldn't find any.
The following query returns an empty result at the Yago endpoint and only very few entries at the DBPedia endpoint.
prefix owl: <http://www.w3.org/2002/07/owl#>
select ?s ?o
where {
?s owl:equivalentProperty ?o .
}
There are some tools that automatically generated mappings between classes and properties of DBpedia and Yago. You can download some of these files here:
Yago to DBpedia linking
Hello everybody i'm using a SPARQL query to retrieve properties and values of a specified resource. For example if i ask for Barry White, i obtain: birth place, associatedBand, recordLabels and so on.
Instead for any instance such as "Hammerfall", i obtain only this results:
Query results
But i want properties and values as shown in this page: Correct results.
My query is:
PREFIX db: <http://dbpedia.org/resource/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?property ?value
WHERE { db:Hammerfall?property ?value }
Anyone can tell me how to access to the correct resource and obtain corrects properties and values in every case?
select ?p ?o { dbpedia:HammerFall ?p ?o }
SPARQL results
The particular prefix doesn't matter; I just used dbpedia: because it's predefined on the endpoint as http://dbpedia.org/resource/, just like your db:. The issue is that HammerFall has a majuscule F in the middle, but your query uses a miniscule f.
As an alternative, since the results for Hammerfall (with a miniscule f) do include
http://dbpedia.org/ontology/wikiPageRedirects http://dbpedia.org/resource/HammerFall
you could use a property path to follow any wikiPageRedirects paths:
select ?p ?v {
dbpedia:Hammerfall dbpedia-owl:wikiPageRedirects* ?hammerfall .
?hammerfall ?p ?v
}
SPARQL results
See Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value? for more about that approach.