Well I maybe be a newbie on SPARQL but I've bean using Jena and RDF4J crunching
data programmatically and avoid SPARQL as much as I can. So yes I've done
UNION/Intersect etc in code even in SPARQL but not federated. I've read the W3C
federated manual, copying the OPTIONAL syntax since there are no UNION example,
but no luck. Some syntax help would be appreciated?
SELECT ?s ?p ?o
WHERE
{
?s ?p ?o
UNION {
SERVICE <http://localhost:8080/fuseki/model2> {
?s ?p ?o
}
}
}
//Cheers
________________________________
Från: Bögershausen, Merlin <[email protected]>
Skickat: den 23 april 2020 16:43
Till: [email protected] <[email protected]>
Ämne: AW: Union different dataset in Fuseki
You are half way done ;)
Now use the UNION Key word [1].
UNION produces the UNION of two Collections of triples.
In your case the triple pattern ?s ?p ?o produces the first and the service
produces the second collection.
Best Merlin
[1] https://en.wikibooks.org/wiki/SPARQL/UNION
-----Ursprüngliche Nachricht-----
Von: Glenn TheMan <[email protected]>
Gesendet: Donnerstag, 23. April 2020 15:27
An: [email protected]
Betreff: Sv: Union different dataset in Fuseki
I see you point Merlin.
I am new to federated query as you guessed :) I do have two different datasets
with unnamed graphs (default graphs). I use one of the dataset endpoints and
link in the other with SERVICE. The query below give my a intersect instead of
the union. How to I perform a union between the to different dataset with
unnamed graphs?
PREFIX ex: <http://clearbyte.org/>
SELECT ?s ?p ?o
WHERE
{
?s ?p ?o
SERVICE <http://localhost:8080/fuseki/model2> {
?s ?p ?o
}
}
Result:
1
ex:Guernica<http://clearbyte.org/Guernica>
<http://www.w3.org/2000/01/rdf-schema#label><http://www.w3.org/2000/01/rdf-schema#label>
"Guernica"
2
ex:Picasso<http://clearbyte.org/Picasso>
ex:homeAddress<http://clearbyte.org/homeAddress>
_:b0
3
ex:Picasso<http://clearbyte.org/Picasso>
<http://xmlns.com/foaf/0.1/surname><http://xmlns.com/foaf/0.1/surname>
"Picasso"
4
ex:Picasso<http://clearbyte.org/Picasso>
ex:creatorOf<http://clearbyte.org/creatorOf>
ex:guernica<http://clearbyte.org/guernica>
5
ex:Picasso<http://clearbyte.org/Picasso>
<http://xmlns.com/foaf/0.1/firstName><http://xmlns.com/foaf/0.1/firstName>
"Pablo"
//Cheers
________________________________
Från: Bögershausen, Merlin <[email protected]>
Skickat: den 23 april 2020 14:35
Till: [email protected] <[email protected]>
Ämne: AW: Union different dataset in Fuseki
Hi,
Very interesting part seems still not clear. Do you have two graphs in the SAME
dataset which need to be merged or do you have two datasets with graphs that
need to be merged.
Two datasets (datasets are a set of graphs) mean that you have two SPARQL
endpoints in fuseki. A Query is send to exactly one endpoint.
If a query needs information from a second dataset the second endpoint need to
be queried. This is done with the SERVICE pattern, see example in [1]. (union
with federated query)
If the data is in two graph in the SAME dataset the FROM keyword does the
trick. In this ´scenario you must have at least one named graph.
Example see [2], this is the SPARQL language recommendation with good examples
to start from. (union with graph pattern)
Best Merlin
[1] https://www.w3.org/TR/sparql11-query/#specifyingDataset
[2] https://jena.apache.org/tutorials/sparql_datasets.html
-----Ursprüngliche Nachricht-----
Von: Glenn TheMan <[email protected]>
Gesendet: Donnerstag, 23. April 2020 13:49
An: [email protected]
Betreff: Sv: Union different dataset in Fuseki
Sorry if my question was imprecise and to upset people. Even the W3C guide for
federated states "... opportunity to merge data distributed across the Web"
But union of the two dataset is what I want. I was unclear about the syntax and
how to use prefix for the two local dataset in the query. My dataset's are
local so I don't need use the SERVICE keyword i guess, please provide an
example bases on the initial question?
Cheers
________________________________
Från: Bögershausen, Merlin <[email protected]>
Skickat: den 23 april 2020 12:24
Till: [email protected] <[email protected]>
Ämne: AW: Union different dataset in Fuseki
Hi Glenn,
"merge" and "redundant" are a very overloaded term, please be as specific as
possible ;-) And even equality is not that clear [1].
If the data is located in different datasets you should use federated queries
[2].
If they are in the same dataset but in different graphs the graph pattern
should be enough.
I suggest reading the SPARQL tutorial [3] to understand the basics of SPARQL.
Please understand the sources and repost the question afterwards, if still
relevant.
Best Merlin
[1] https://www.w3.org/TR/sparql11-query/#OperatorMapping
[2] https://jena.apache.org/documentation/query/service.html
[3] https://jena.apache.org/tutorials/sparql.html
-----Ursprüngliche Nachricht-----
Von: Lorenz Buehmann <[email protected]>
Gesendet: Donnerstag, 23. April 2020 12:09
An: [email protected]
Betreff: Re: Union different dataset in Fuseki
what do you mean by "merge"? What is the result? A proper RDF dataset?
Then indeed CONSTRUCT. "optional" is **not** a query type, so I don't
understand what you mean by this.
Please provide some more details, also what "redundant" means.
Also, if you have multiple models, Fuseki setup allows for configuring to query
the UNION of both
On 23.04.20 12:05, Glenn TheMan wrote:
> Hi, I am trying to merge two models (with some redundant info) that are
> persist in two different dataset's in Fuseki (3.14). I am using the included
> SPARQL query console and set the endpoint for the query to
> http://localhost:8080/fuseki/.
> How would the SPARQL syntax look like to merge the similar datasets (using
> select, construct or optional)?
>
> Greetings.
>
> This is my attempt;
> PREFIX a: <http://localhost:8080/fuseki/model1/>
> PREFIX b: <http://localhost:8080/fuseki/model2/>
> SELECT ?s ?p ?o
> WHERE
> {
> {
> ?s ?p ?o
> }
> UNION
> {
> ?s ?p ?p
> }
> }
>