I am managing a named graph (multiple resources per named graph pattern) and needs to update the named graph for any changes for versioning graphs.
To start with, I have a current version of the named graph.
problem statement: whenever I receive a delta turtle file (ttl will have only the changed triples), a new version named graph with delta change incorporated (current version + delta) has to be created.
named graph versions diagram
**V1 named graph**
prefix ex: http://example.org/def/
prefix id: http://example.org/id/
prefix graph: <http://example.org/graph/>
id:a ex:hasLabel "a" graph:v1 .
id:b ex:hasLabel "b" graph:v1.
id:b ex:hasChild id:d graph:v1.
id:c ex:hasLabel "c" graph:v1
id:c ex:hasChild id:d graph:v1 .
id:d ex:hasLabel "d" graph:v1.
**DELTA file**
id:b ex:hasLabel "B".
id:c ex:hasChild id:e .
id:e ex:hasLabel "e" .
**Expected V2 Named graph with the delta change incorporated**
id:a ex:hasLabel "a" graph:v2.
id:b ex:hasLabel "B" graph:v2.
id:b ex:hasChild id:d graph:v2.
id:c ex:hasLabel "c" graph:v2.
id:c ex:hasChild id:d graph:v2.
id:d ex:hasLabel "d" graph:v2.
id:c ex:hasChild id:e graph:v2.
id:e ex:hasLabel "e" graph:v2.
I POSTed named graph v1 to a new named graph V2. Tried HTTP PUT and PATCH to update, but it is just replacing it with the delta file (I need to keep unchanged nodes in new named graph).
Is it possible to do it using HTTP PATCH as I read in SPARQL 1.1 Graph Store HTTP Protocol :
With PATCH, however, the enclosed entity contains a set of
instructions describing how the RDF graph content residing on the
origin server should be modified to produce a new version.
Appreciate if anyone can give me some pointers or ideas to reach the solution. Thanks.
Related
Hi I am new to SPARQL and I would like to understand better some things regarding variable assigments. Lets say I have the below:
SELECT ?z WHERE
{
?x n:type 'Type_1' .
?x n:belongs ?r .
?r n:belongs ?z .
?y n:type 'Type_1' .
?y n:belongs ?r_2 .
?r_2 n:belongs ?z . FILTER(?x != ?y)
}
In the above example query ?r and ?r_2 from my understanding have different values stored inside .Does the same applies for both variables ?z, or because both have the same name also have the same value stored inside?. An explanation would be appreciated. Cheers!
You can think of SPARQL as a template. It is a declarative language where you explicitly put in the things you know, and you put in variables for the things you don't.
The query executes, and puts the values of the things you don't yet know, into the response, against the variable names.
A variable called 'x' is the same variable throughout the query. It's response value is 'bound' to the parameter 'x'.
There is a SPARQL tutorial which I wrote in the open source graph-notebook project found here: https://github.com/aws/graph-notebook
After you run the notebook, navigate to 06-LANGUAGE-TUTORIALS
Although it was originally built for Amazon Neptune, it is open source and will work with any SPARQL 1.1 endpoint.
I've just started using the triple store RDF4J (I am using its workbench, version 2.3.1, run on Windows 10 with Tomcat 9.0)
I want to use the SPIN rules in RDF4J. Therefore, I created a new repository (In memory with RDFS+SPIN support).
I wanted to start with the SPIN example in RDF4J documentation concerning how to add SPIN rules. That is, I added the data (in Turtle, and imported to RDF4J)
#prefix ex: <http://example.org/>.
ex:John a ex:Father ;
ex:parentOf ex:Lucy .
ex:Lucy a ex:Person .
And the rule:
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix sp: <http://spinrdf.org/sp#>.
#prefix spin: <http://spinrdf.org/spin#>.
#prefix ex: <http://example.org/>.
ex:Person a rdfs:Class ;
spin:rule [
a sp:Construct ;
sp:text """PREFIX ex: <http://example.org/>
CONSTRUCT { ?this ex:childOf ?parent . }
WHERE { ?parent ex:parentOf ?this . }"""
] .
And as instructed in the documentation, I exposed the query (with the checkbox 'Include inferred statements' checked),
PREFIX ex: <http://example.org/>
SELECT ?child
WHERE { ?child ex:childOf ?parent }
However, no result returned:
Could someone, please tell me am I doing something wrong, why the SPIN rule doesn't work in my RDF4J workbench, have I missed something?
(reposting my comment as an answer for future readers)
The SPIN reasoner currently assumes that all data is in the default context, I think. Make sure that your data was not added to a named graph.
I'm doing some work with RDF Data Cubes vocabulary for publishing time-series of various data, among others sensors. The measurement of the sensor is taken at a specific time at a specific station.
Both time and station I will model as qb:DimensionProperty, the measurement itself as qb:MeasureProperty. I would also like to state what unit the measurement is in. In this particular example it is atmospheric pressure at the height of the station. My understanding from the spec is that this would be modeled as qb:AttributeProperty.
In the description of the data structure I would have something like this:
<dsd/prestas0> a qb:DataStructureDefinition ;
qb:component
[ qb:dimension <stn>; qb:order 1 ],
[ qb:dimension <time>; qb:order 2 ],
[ qb:attribute <unit>; qb:order 3 ],
[ qb:measure <prestas0>; qb:order 4 ] .
<stn> a qb:DimensionProperty ;
rdfs:label "Station°" .
<time> a qb:DimensionProperty ;
rdfs:label "Time" .
<unit> a qb:AttributeProperty ;
rdfs:label "Unit" ;
rdfs:comment "The unit of the measurement" .
<prestas0> a qb:MeasureProperty ;
rdfs:label "Measurement" ;
rdfs:range xsd:float .
# Units in use
<hPa> a qudt:Unit ;
rdfs:label "Atmospheric pressure (hPa)" ;
rdfs:comment "Atmospheric pressure on station level" ;
rdfs:subClassOf unit:Pascal .
As you can see I also created an instance of a unit, called <hPa>. In there I use rdfs:subClassOf to subclass from QUDT unit:Pascal.
Now my questions:
is my understanding of using qb:AttributeProperty for the unit correct?
Is it fine to sublass from QUDT the way I did? I am aware that I have hPa while QUDT defines Pa only so I would probably have to change the data accordingly
Can I in general simply use units from QUDT directly (in terms of their URIs) if they do not need a specific tailoring like I did in this example?
I have a RDF graph with several types of relations (relations with the same prefix and with different prefixes also). I need to call a service over the graph but filtering out some relations.
Example:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
#prefix myPref: <http://www.myPref.com/>.
#prefix otherPref: <http://www.otherPref.com/>.
myPref:1
myPref:label "1" ;
myPref:solid myPref:2 ;
myPref:dotted myPref:4 ;
otherPref:dashed myPref:3 ;
otherPref:dashed2 myPref:3 .
myPref:2
myPref:label "2" ;
myPref:solid myPref:3 .
myPref:3
myPref:label "3" .
myPref:4
myPref:label "4" ;
myPref:dotted myPref:3 .
I would like to run the service call over an extracted sub-graph containing only the solid and dotted relations (In this particular case, running a service calculating the shortest path between 1 to 3, I want to exclude those direct links).
I run the service (Over the entire graph) like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
PREFIX myPref: <http://www.myPref.com/>.
PREFIX otherPref: <http://www.otherPref.com/>.
PREFIX gas: <http://www.bigdata.com/rdf/gas#>
SELECT ?sp ?out {
SERVICE gas:service {
gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" .
gas:program gas:in myPref:1 .
gas:program gas:target myPref:3 .
gas:program gas:out ?out .
gas:program gas:out1 ?sp .
}
}
How can I extract a subgraph containing only the links I want (Dotted and solid) and the run the service call over the extracted sub-graph?
SPARQL doesn't provide any functionality for querying a constructed graph, unfortunately. I've come across places where it would make some queries very easy. Some endpoints do have extensions to support it, though. I think that dotNetRDF might support it. There are probably a few aspects: in many cases, it's not actually necessary; if the endpoint supports updates, you can create a new named graph and construct into it, and then launch a second query against it (which is pretty much what you're asking for, but in two steps); this could be a very expensive operation, so endpoints might disable it anyway, even if it was directly supported.
The first note, though, that it's often times not necessary, appears that it might be the case here.
I need to call a service over the graph but filtering out some relations.
In this case, you can query over the subgraph that you want, I think, by using property paths. You can ask for paths built from just solid and dashed edges like:
?s myPref:solid|myPref:dotted ?t
If you want an arbitrary path of them, you can repeat it:
?s (myPref:solid|myPref:dotted)+ ?t
If you have unique paths between sources and destinations, then you can figure out the lengths of paths using the standard "count the ways of splitting the path" technique:
select (count(?t) as ?length) {
?s (myPref:solid|myPref:dotted)* ?t
?t (myPref:solid|myPref:dotted)* ?u
}
group by ?s ?t
I am doing some experiments with importing triples formulated in the turtle language
within the openrdf-workbench webapp in Tomcat, which has incorporated a SPARQL endpoint.
I wonder if with turtle, or, generally, in RDF / RDFS is it possible to add a certain predicate/object declaration on all (implicit) subjects conditionally to the existence of another predicate/object.
For example, if I have the following triples defined:
foo:a foo:b foo:c
foo:d foo:b foo:c
foo:e foo:b foo:c
foo:f foo:b foo:c
I would like to automatically add the following predicate/subject to all subjects that match predicate=foo:b and object=foo:c:
(implicit subject) foo:g foo:h
in order to automatically produce the following triples:
foo:a foo:g foo:h
foo:d foo:g foo:h
foo:e foo:g foo:h
foo:f foo:g foo:h
Is this possible?
Alternatively: is there any way to define some triples in order to enable SPARQL to find foo:a/d/e/f when queried for subjects that have foo:g foo:h as predicate/object?
Part 1 - Creating additional information
The first part of your question can be solved in one of two ways:
Using Inference
Using SPARQL Update
Inferencing
Inference is a technique whereby you define rules that infer additional triple based on your existing triples. You typically either use a pre-defined set of rules or use your own custom rules. I think Sesame only supports pre-defined rule sets out of the box so you may want to take a look at OWLIM which is an alternative back end that can be used with Sesame and has much more customisable rules AFAIK.
Inferencing can typically be applied in two ways, one where you only store the rules and you compute the additional information every time a rule fires and another where you pre-compute all the additional information and add it to your database. Which you will want to use depends on how you intend to use your system and there are performance trade offs involved. I'm not going into detail because that's really a whole other question - see Forward vs Backward Chaining for some discussion
SPARQL Update
Alternatively if your rules are relatively simple and you are OK with pre-computing the extra information and adding it to your database you can write SPARQL Updates to do this e.g.
PREFIX foo: <http://example.org/foo#>
INSERT
{
?x foo:g foo:h .
}
WHERE
{
?x foo:b foo:c .
}
Part 2 - Querying the Data
I am guessing you are fairly new to SPARQL because from what you've described this sounds trivial to me.
If I wanted to find all subjects which had the predicate foo:g and the object foo:h I would simply write the following:
PREFIX foo: <http://example.org/foo#>
SELECT ?x
WHERE
{
?x foo:g foo:h .
}
You can do this type of inference using OWL with an axiom of the form
p value a ⊑ q value b
which says that if something has a as a value for property p, then it also has b as a value for property q. As an example, here's an ontology with four individuals (a, b, c, d), two object properties (p, q), and the axiom (p value c ⊑ q value d).
#prefix : <http://example.org/add-predicate-object#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/add-predicate-object> a owl:Ontology .
:p a owl:ObjectProperty .
:q a owl:ObjectProperty .
[ a owl:Restriction ;
owl:onProperty :p ;
owl:hasValue :c ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty :q ;
owl:hasValue :d ] . ] .
:a a owl:Thing, owl:NamedIndividual ; :p :c .
:b a owl:Thing, owl:NamedIndividual ; :p :c .
:c a owl:Thing, owl:NamedIndividual .
:d a owl:Thing, owl:NamedIndividual .
In Protégé, the axiom looks like this:
You can enable a reasoner and query for instances of q value d and see:
or you can browse to individuals and see the results: