apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.12k stars 652 forks source link

ds.getUnionModel not working as expected #2854

Closed ebremer closed 6 days ago

ebremer commented 6 days ago

Version

5.2.0

What happened?

Run the following code

        Model a = ModelFactory.createDefaultModel();
        a.add(ResourceFactory.createResource("https://dummy.com/TripleA"), RDF.type, OWL.Thing);
        Model b = ModelFactory.createDefaultModel();
        b.add(ResourceFactory.createResource("https://dummy.com/TripleB"), RDF.type, OWL.Thing);

        Dataset ds = DatasetFactory.create();
        ds.setDefaultModel(a);
        ds.addNamedModel(ResourceFactory.createProperty("https://dummy.com/ngB"), b);

        System.out.println("Graph A ===========================================");
        a.write(System.out, "TTL");
        System.out.println("Graph B ===========================================");
        b.write(System.out, "TTL");
        System.out.println("UNION of A and B ===========================================");
        ds.getUnionModel().write(System.out, "TTL");

outputs

Graph A ===========================================
<https://dummy.com/TripleA>
        a       <http://www.w3.org/2002/07/owl#Thing> .
Graph B ===========================================
<https://dummy.com/TripleB>
        a       <http://www.w3.org/2002/07/owl#Thing> .
UNION of A and B ===========================================
<https://dummy.com/TripleB>
        a       <http://www.w3.org/2002/07/owl#Thing> .

I thought the union model would include the triples in the default graph as well.

Relevant output and stacktrace

No response

Are you interested in making a pull request?

None

ebremer commented 6 days ago

I read deeper in the Jena documentation and appears to be by design even though it differs from https://www.w3.org/TR/rdf11-datasets/#default-graph-as-union-or-as-merge

ebremer commented 6 days ago

Using ModelFactory.createUnion(a,b) to get around it.