OWALAPI - Pass from OWLEquivalentClassesAxiom syntax to a Manchester OWL syntax (like Protege)
I want to know if it's possible pass from an expression like this:
EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )
to this type of expression, the problem here is not shorten the IRI, the problem here is to do the translations to "and,only..." using OWLAPI:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
The ontology that I'm using is http://owl.man.ac.uk/2006/07/sssw/people.owl and the method in that I obtain the expression is this (in this case, equivalents for vegetarian):
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
//OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
String equi = "";
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(e);
java owl owl-api
add a comment |
I want to know if it's possible pass from an expression like this:
EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )
to this type of expression, the problem here is not shorten the IRI, the problem here is to do the translations to "and,only..." using OWLAPI:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
The ontology that I'm using is http://owl.man.ac.uk/2006/07/sssw/people.owl and the method in that I obtain the expression is this (in this case, equivalents for vegetarian):
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
//OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
String equi = "";
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(e);
java owl owl-api
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call therender()
method on the axiom
– AKSW
Nov 15 '18 at 6:57
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29
add a comment |
I want to know if it's possible pass from an expression like this:
EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )
to this type of expression, the problem here is not shorten the IRI, the problem here is to do the translations to "and,only..." using OWLAPI:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
The ontology that I'm using is http://owl.man.ac.uk/2006/07/sssw/people.owl and the method in that I obtain the expression is this (in this case, equivalents for vegetarian):
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
//OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
String equi = "";
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(e);
java owl owl-api
I want to know if it's possible pass from an expression like this:
EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )
to this type of expression, the problem here is not shorten the IRI, the problem here is to do the translations to "and,only..." using OWLAPI:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
The ontology that I'm using is http://owl.man.ac.uk/2006/07/sssw/people.owl and the method in that I obtain the expression is this (in this case, equivalents for vegetarian):
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
//OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
String equi = "";
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(e);
java owl owl-api
java owl owl-api
edited Nov 15 '18 at 9:31
xKukum
asked Nov 14 '18 at 18:57
xKukumxKukum
13
13
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call therender()
method on the axiom
– AKSW
Nov 15 '18 at 6:57
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29
add a comment |
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call therender()
method on the axiom
– AKSW
Nov 15 '18 at 6:57
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call the
render()
method on the axiom– AKSW
Nov 15 '18 at 6:57
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call the
render()
method on the axiom– AKSW
Nov 15 '18 at 6:57
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29
add a comment |
2 Answers
2
active
oldest
votes
The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)n"
+ "Ontology(<file:test.owl>n" + axiom + "n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
Output is:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
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: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
add a comment |
The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(rend.render(e));
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307027%2fowalapi-pass-from-owlequivalentclassesaxiom-syntax-to-a-manchester-owl-syntax%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)n"
+ "Ontology(<file:test.owl>n" + axiom + "n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
Output is:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
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: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
add a comment |
The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)n"
+ "Ontology(<file:test.owl>n" + axiom + "n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
Output is:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
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: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
add a comment |
The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)n"
+ "Ontology(<file:test.owl>n" + axiom + "n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
Output is:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
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: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)n"
+ "Ontology(<file:test.owl>n" + axiom + "n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
Output is:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
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: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
answered Nov 16 '18 at 9:05
IgnazioIgnazio
8,03111022
8,03111022
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
add a comment |
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
Thank you for the answer, I'm going to answer to my question with the solution that works for me.
– xKukum
Nov 16 '18 at 11:01
add a comment |
The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(rend.render(e));
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
add a comment |
The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(rend.render(e));
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
add a comment |
The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(rend.render(e));
The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:
public static void getEquivalentClasses2() throws OWLOntologyCreationException
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
System.out.println(rend.render(e));
answered Nov 16 '18 at 11:18
xKukumxKukum
13
13
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
add a comment |
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
Take into account that you're relying on an implementation class that was not designed to be part of the public API. The solution might stop working in future OWLAPI versions.
– Ignazio
Nov 16 '18 at 14:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307027%2fowalapi-pass-from-owlequivalentclassesaxiom-syntax-to-a-manchester-owl-syntax%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call the
render()
method on the axiom– AKSW
Nov 15 '18 at 6:57
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it.
– xKukum
Nov 15 '18 at 9:29