I tried to create different individual axiom using OWLAPI 5 in Java. What I want is simple triple using vocab owl:differentFrom like:
test:A owl:differentFrom test:B
But what I get is triple using owl:AllDifferent:
_:genid234 rdf:type owl:AllDifferent
_:genid234 owl:distinctMembers _:genid236
_:genid236 rdf:rest _:genid235
_:genid236 rdf:rest rdf:nil
_:genid235 rdf:first test:A
_:genid235 rdf:type rdf:List
_:genid236 rdf:first test:B
_:genid236 rdf:type rdf:List
And the simple code is:
OWLNamedIndividual op1 = factory.getOWLNamedIndividual(baseIRI + A);
OWLNamedIndividual op2 = factory.getOWLNamedIndividual(baseIRI + B);
ont.add(factory.getOWLDifferentIndividualsAxiom(op1, op2));
And I already tried it with Protege 5.5.0, it produce exactly the same triple as OWLAPI.
There is an alternative implementation of OWLAPI-v5 that provides a direct way to work with underlying RDF data - ONT-API (by the way, RDF based Protege version also exists). If working via OWLAPI interface for two operands it produces a single triple.
Also it is possible to copy ontology between ont-api manager and owl-api-impl managers, if you prefer to store the data in the form of OWL axioms and need to solve only this particular problem with serialization.
example:
String iri = "http://test#";
OWLDataFactory factory = OntManagers.getDataFactory();
Ontology ont = OntManagers.createManager().createOntology();
ont.asGraphModel().setNsPrefix("test", iri);
OWLNamedIndividual ia = factory.getOWLNamedIndividual(iri + "A");
OWLNamedIndividual ib = factory.getOWLNamedIndividual(iri + "B");
OWLNamedIndividual ic = factory.getOWLNamedIndividual(iri + "C");
ont.add(factory.getOWLDifferentIndividualsAxiom(ia, ib, ic));
ont.add(factory.getOWLDifferentIndividualsAxiom(ia, ic));
OntModel g = ont.asGraphModel();
g.createIndividual(iri + "D").addDifferentIndividual(g.createIndividual(iri + "C"));
g.createDifferentIndividuals(g.createIndividual(iri + "e"), g.createIndividual(iri + "g"));
g.write(System.out, "ttl");
System.out.println("=".repeat(42));
ont.axioms().forEach(System.out::println);
out:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix test: <http://test#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
[ rdf:type owl:AllDifferent ;
owl:members ( test:e test:g )
] .
test:g rdf:type owl:NamedIndividual .
test:B rdf:type owl:NamedIndividual .
[ rdf:type owl:Ontology ] .
test:e rdf:type owl:NamedIndividual .
test:C rdf:type owl:NamedIndividual .
test:A rdf:type owl:NamedIndividual ;
owl:differentFrom test:C .
test:D rdf:type owl:NamedIndividual ;
owl:differentFrom test:C .
[ rdf:type owl:AllDifferent ;
owl:distinctMembers ( test:A test:B test:C )
] .
==========================================
Declaration(NamedIndividual(test:g))
Declaration(NamedIndividual(test:e))
Declaration(NamedIndividual(test:D))
Declaration(NamedIndividual(test:C))
Declaration(NamedIndividual(test:B))
Declaration(NamedIndividual(test:A))
DifferentIndividuals(test:C test:D)
DifferentIndividuals(test:A test:C)
DifferentIndividuals(test:e test:g)
DifferentIndividuals(test:A test:B test:C)