\n");
ontology.getImportsDeclarations().stream().sorted().forEach(decl -> {
write("Imports: ");
write(decl.getIRI().toString());
write("\n");
});
write("
Classes
\n");
writeCollection(ontology.getClassesInSignature());
write("");
write("
");
write("
Axioms
\n");
writeListStart();
for (OWLAxiom ax : ontology.getAxioms()) {
writeListItemStart();
ax.accept(this);
writeListEnd();
}
writeListEnd();
write("");
footer();
}
public OWLTutorialSyntaxObjectRenderer write(@Nonnull String str, @Nonnull OWLObject o) {
write(str).write("(");
o.accept(this);
write(")");
return this;
}
private OWLTutorialSyntaxObjectRenderer write(@Nonnull Collection objects,
@Nonnull String separator) {
for (Iterator it = objects.iterator(); it.hasNext();) {
it.next().accept(this);
if (it.hasNext()) {
writeSpace();
write(separator);
writeSpace();
}
}
return this;
}
private OWLTutorialSyntaxObjectRenderer write(
@Nonnull Collection objects) {
return write(objects, "");
}
public OWLTutorialSyntaxObjectRenderer writeOpenBracket() {
return write("(");
}
public OWLTutorialSyntaxObjectRenderer writeCloseBracket() {
return write(")");
}
public OWLTutorialSyntaxObjectRenderer writeSpace() {
return write(" ");
}
public OWLTutorialSyntaxObjectRenderer writeAnnotations(
@SuppressWarnings("unused") OWLAxiom ax) {
return this;
}
public OWLTutorialSyntaxObjectRenderer writeListStart() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeListEnd() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableStart() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableEnd() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableRowStart() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableRowEnd() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableCellStart() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeTableCellEnd() {
return write(" | \n");
}
public OWLTutorialSyntaxObjectRenderer writeListItemStart() {
return write("
\n");
}
public OWLTutorialSyntaxObjectRenderer writeListItemEnd() {
return write("\n");
}
@SuppressWarnings("unused")
public OWLTutorialSyntaxObjectRenderer writePropertyCharacteristic(String str, OWLAxiom ax,
@Nonnull OWLPropertyExpression prop) {
write(keyword(str));
writeSpace();
prop.accept(this);
return this;
}
@Override
public void visit(@Nonnull OWLAsymmetricObjectPropertyAxiom axiom) {
writePropertyCharacteristic("asymmetric", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLClassAssertionAxiom axiom) {
axiom.getIndividual().accept(this);
write(keyword(":")).writeSpace();
axiom.getClassExpression().accept(this);
}
@Override
public void visit(@Nonnull OWLDataPropertyAssertionAxiom axiom) {
axiom.getSubject().accept(this);
writeSpace();
axiom.getProperty().accept(this);
writeSpace();
axiom.getObject().accept(this);
}
@Override
public void visit(@Nonnull OWLDataPropertyDomainAxiom axiom) {
axiom.getProperty().accept(this);
writeSpace();
write(keyword("domain"));
writeSpace();
axiom.getDomain().accept(this);
}
@Override
public void visit(@Nonnull OWLDataPropertyRangeAxiom axiom) {
axiom.getProperty().accept(this);
writeSpace();
write(keyword("range"));
writeSpace();
axiom.getRange().accept(this);
}
@Override
public void visit(@Nonnull OWLSubDataPropertyOfAxiom axiom) {
axiom.getSubProperty().accept(this);
writeSpace();
write(keyword("subProperty"));
writeSpace();
axiom.getSuperProperty().accept(this);
}
@Override
public void visit(OWLDeclarationAxiom axiom) {}
@Override
public void visit(@Nonnull OWLDifferentIndividualsAxiom axiom) {
write(axiom.getIndividuals(), keyword("!="));
}
@Override
public void visit(@Nonnull OWLDisjointClassesAxiom axiom) {
write(axiom.getClassExpressions(), keyword("|"));
}
@Override
public void visit(@Nonnull OWLDisjointDataPropertiesAxiom axiom) {
write(axiom.getProperties(), keyword("|"));
}
@Override
public void visit(@Nonnull OWLDisjointObjectPropertiesAxiom axiom) {
write(keyword("disjoint")).write(axiom.getProperties(), keyword("|"));
}
@Override
public void visit(@Nonnull OWLDisjointUnionAxiom axiom) {
axiom.getOWLClass().accept(this);
writeSpace().write(keyword("==")).writeSpace().write(axiom.getClassExpressions(),
keyword("|"));
}
@Override
public void visit(@Nonnull OWLEquivalentClassesAxiom axiom) {
write(axiom.getClassExpressions(), keyword("=="));
}
@Override
public void visit(@Nonnull OWLEquivalentDataPropertiesAxiom axiom) {
write(axiom.getProperties(), keyword("=="));
}
@Override
public void visit(@Nonnull OWLEquivalentObjectPropertiesAxiom axiom) {
write(axiom.getProperties(), keyword("=="));
}
@Override
public void visit(@Nonnull OWLFunctionalDataPropertyAxiom axiom) {
writePropertyCharacteristic("functional", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLFunctionalObjectPropertyAxiom axiom) {
writePropertyCharacteristic("functional", axiom, axiom.getProperty());
}
public void visit(@Nonnull OWLImportsDeclaration axiom) {
write(keyword("imports")).write(axiom.getIRI());
}
@Override
public void visit(@Nonnull OWLInverseFunctionalObjectPropertyAxiom axiom) {
writePropertyCharacteristic("inversefunctional", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLInverseObjectPropertiesAxiom axiom) {
axiom.getFirstProperty().accept(this);
writeSpace().write(keyword("inverse")).writeSpace();
axiom.getSecondProperty().accept(this);
}
@Override
public void visit(@Nonnull OWLIrreflexiveObjectPropertyAxiom axiom) {
writePropertyCharacteristic("Irreflexive", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLNegativeDataPropertyAssertionAxiom axiom) {
axiom.getSubject().accept(this);
writeSpace().write(keyword("notvalue"));
axiom.getProperty().accept(this);
writeSpace();
axiom.getObject().accept(this);
}
@Override
public void visit(@Nonnull OWLNegativeObjectPropertyAssertionAxiom axiom) {
axiom.getSubject().accept(this);
writeSpace().write(keyword("notvalue"));
axiom.getProperty().accept(this);
writeSpace();
axiom.getObject().accept(this);
}
@Override
public void visit(@Nonnull OWLObjectPropertyAssertionAxiom axiom) {
axiom.getSubject().accept(this);
writeSpace();
axiom.getProperty().accept(this);
writeSpace();
axiom.getObject().accept(this);
}
@Override
public void visit(@Nonnull OWLSubPropertyChainOfAxiom axiom) {
write("chain").writeOpenBracket().write(axiom.getPropertyChain()).writeCloseBracket();
writeSpace().write(keyword("subProperty")).writeSpace();
axiom.getSuperProperty().accept(this);
}
@Override
public void visit(@Nonnull OWLObjectPropertyDomainAxiom axiom) {
axiom.getProperty().accept(this);
writeSpace().write(keyword("domain")).writeSpace();
axiom.getDomain().accept(this);
}
@Override
public void visit(@Nonnull OWLObjectPropertyRangeAxiom axiom) {
axiom.getProperty().accept(this);
writeSpace().write(keyword("range")).writeSpace();
axiom.getRange().accept(this);
}
@Override
public void visit(@Nonnull OWLSubObjectPropertyOfAxiom axiom) {
axiom.getSubProperty().accept(this);
writeSpace().write(keyword("subProperty")).writeSpace();
axiom.getSuperProperty().accept(this);
}
@Override
public void visit(@Nonnull OWLReflexiveObjectPropertyAxiom axiom) {
writePropertyCharacteristic("reflexive", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLSameIndividualAxiom axiom) {
write(axiom.getIndividuals(), keyword("="));
}
@Override
public void visit(@Nonnull OWLSubClassOfAxiom axiom) {
axiom.getSubClass().accept(this);
writeSpace().write(keyword("subClass")).writeSpace();
axiom.getSuperClass().accept(this);
}
@Override
public void visit(@Nonnull OWLSymmetricObjectPropertyAxiom axiom) {
writePropertyCharacteristic("symmetric", axiom, axiom.getProperty());
}
@Override
public void visit(@Nonnull OWLTransitiveObjectPropertyAxiom axiom) {
writePropertyCharacteristic("transitive", axiom, axiom.getProperty());
}
@Override
public void visit(OWLClass ce) {
write("
" + labelFor(ce) + "");
}
private OWLTutorialSyntaxObjectRenderer writeRestriction(@Nonnull String str,
@Nonnull OWLCardinalityRestriction restriction,
@Nonnull OWLPropertyExpression property) {
write(str).writeOpenBracket().write(restriction.getCardinality()).writeSpace();
property.accept(this);
if (restriction.isQualified()) {
writeSpace();
restriction.getFiller().accept(this);
}
writeCloseBracket();
return this;
}
private OWLTutorialSyntaxObjectRenderer writeRestriction(@Nonnull String str,
@Nonnull OWLQuantifiedDataRestriction restriction) {
return writeRestriction(str, restriction.getProperty(), restriction.getFiller());
}
private OWLTutorialSyntaxObjectRenderer writeRestriction(@Nonnull String str,
@Nonnull OWLQuantifiedObjectRestriction restriction) {
return writeRestriction(str, restriction.getProperty(), restriction.getFiller());
}
private OWLTutorialSyntaxObjectRenderer writeRestriction(@Nonnull String str,
@Nonnull OWLPropertyExpression prop, @Nonnull OWLObject filler) {
write(str).writeOpenBracket();
prop.accept(this);
writeSpace();
filler.accept(this);
writeCloseBracket();
return this;
}
@Override
public void visit(OWLDataAllValuesFrom ce) {
writeRestriction(operator("only"), ce);
}
@Override
public void visit(@Nonnull OWLDataExactCardinality ce) {
writeRestriction("exact", ce, ce.getProperty());
}
@Override
public void visit(@Nonnull OWLDataMaxCardinality ce) {
writeRestriction("atmost", ce, ce.getProperty());
}
@Override
public void visit(@Nonnull OWLDataMinCardinality ce) {
writeRestriction("atleast", ce, ce.getProperty());
}
@Override
public void visit(OWLDataSomeValuesFrom ce) {
writeRestriction(operator("some"), ce);
}
@Override
public void visit(@Nonnull OWLDataHasValue ce) {
writeRestriction("has-value", ce.getProperty(), ce.getFiller());
}
@Override
public void visit(OWLObjectAllValuesFrom ce) {
writeRestriction(operator("only"), ce);
}
@Override
public void visit(@Nonnull OWLObjectComplementOf ce) {
write(operator("not"), ce.getOperand());
}
@Override
public void visit(@Nonnull OWLObjectExactCardinality ce) {
writeRestriction("exact", ce, ce.getProperty());
}
@Override
public void visit(@Nonnull OWLObjectIntersectionOf ce) {
writeOpenBracket().write(ce.getOperands(), keyword("and")).writeCloseBracket();
}
@Override
public void visit(@Nonnull OWLObjectMaxCardinality ce) {
writeRestriction("atmost", ce, ce.getProperty());
}
@Override
public void visit(@Nonnull OWLObjectMinCardinality ce) {
writeRestriction("atleast", ce, ce.getProperty());
}
@Override
public void visit(@Nonnull OWLObjectOneOf ce) {
write(operator("one-of")).writeOpenBracket().write(ce.getIndividuals()).writeCloseBracket();
}
@Override
public void visit(@Nonnull OWLObjectHasSelf ce) {
write("self", ce.getProperty());
}
@Override
public void visit(OWLObjectSomeValuesFrom ce) {
writeRestriction(operator("some"), ce);
}
@Override
public void visit(@Nonnull OWLObjectUnionOf ce) {
writeOpenBracket().write(ce.getOperands(), " or ").writeCloseBracket();
}
@Override
public void visit(@Nonnull OWLObjectHasValue ce) {
writeRestriction("hasValue", ce.getProperty(), ce.getFiller());
}
@Override
public void visit(@Nonnull OWLDataComplementOf node) {
write(operator("not"), node.getDataRange());
}
@Override
public void visit(@Nonnull OWLDataOneOf node) {
write(operator("one-of")).write("(").write(node.getValues()).write(")");
}
@Override
public void visit(@Nonnull OWLDatatype node) {
write("Datatype").writeOpenBracket().write(node.getIRI()).writeCloseBracket();
}
@Override
public void visit(@Nonnull OWLDatatypeRestriction node) {
write("DatatypeRestriction").writeOpenBracket();
node.getDatatype().accept(this);
for (OWLFacetRestriction restriction : node.getFacetRestrictions()) {
writeSpace();
restriction.accept(this);
}
writeCloseBracket();
}
@Override
public void visit(@Nonnull OWLFacetRestriction node) {
write(node.getFacet().getIRI()).writeSpace();
node.getFacetValue().accept(this);
}
@Override
public void visit(@Nonnull OWLLiteral node) {
write("\"").write(node.getLiteral()).write("\"");
if (node.hasLang()) {
write("@").write(node.getLang());
} else {
write("^^").write(node.getDatatype().getIRI());
}
}
@Override
public void visit(OWLDataProperty property) {
write("
" + labelFor(property) + "");
}
@Override
public void visit(OWLObjectProperty property) {
write("
" + labelFor(property) + "");
}
@Override
public void visit(@Nonnull OWLObjectInverseOf property) {
write("inv").writeOpenBracket();
property.getInverse().accept(this);
writeCloseBracket();
}
@Override
public void visit(OWLNamedIndividual individual) {
write("
" + labelFor(individual) + "");
}
@Override
public void visit(SWRLRule rule) {}
@Nonnull
public String keyword(String str) {
return "
" + str + "";
}
@Nonnull
public String operator(String str) {
return "
" + str + "";
}
}