All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.semanticweb.owlapi.util.SimpleRenderer Maven / Gradle / Ivy
/* This file is part of the OWL API.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright 2014, The University of Manchester
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
*
* Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package org.semanticweb.owlapi.util;
import static org.semanticweb.owlapi.util.CollectionFactory.sortOptionally;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import org.semanticweb.owlapi.formats.PrefixDocumentFormat;
import org.semanticweb.owlapi.io.OWLObjectRenderer;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
import org.semanticweb.owlapi.model.OWLDataComplementOf;
import org.semanticweb.owlapi.model.OWLDataExactCardinality;
import org.semanticweb.owlapi.model.OWLDataHasValue;
import org.semanticweb.owlapi.model.OWLDataIntersectionOf;
import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
import org.semanticweb.owlapi.model.OWLDataMinCardinality;
import org.semanticweb.owlapi.model.OWLDataOneOf;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLDataUnionOf;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom;
import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom;
import org.semanticweb.owlapi.model.OWLDocumentFormat;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLFacetRestriction;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectComplementOf;
import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
import org.semanticweb.owlapi.model.OWLObjectHasSelf;
import org.semanticweb.owlapi.model.OWLObjectHasValue;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectInverseOf;
import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectUnionOf;
import org.semanticweb.owlapi.model.OWLObjectVisitor;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLSameIndividualAxiom;
import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom;
import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.SWRLBuiltInAtom;
import org.semanticweb.owlapi.model.SWRLClassAtom;
import org.semanticweb.owlapi.model.SWRLDArgument;
import org.semanticweb.owlapi.model.SWRLDataPropertyAtom;
import org.semanticweb.owlapi.model.SWRLDataRangeAtom;
import org.semanticweb.owlapi.model.SWRLDifferentIndividualsAtom;
import org.semanticweb.owlapi.model.SWRLIndividualArgument;
import org.semanticweb.owlapi.model.SWRLLiteralArgument;
import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom;
import org.semanticweb.owlapi.model.SWRLRule;
import org.semanticweb.owlapi.model.SWRLSameIndividualAtom;
import org.semanticweb.owlapi.model.SWRLVariable;
/**
* A simple renderer that can be used for debugging purposes and provide an implementation of the
* toString method for different implementations.
*
* @author Matthew Horridge, The University Of Manchester, Bio-Health Informatics Group
* @since 2.0.0
*/
public class SimpleRenderer implements OWLObjectVisitor, OWLObjectRenderer {
private StringBuilder sb;
private ShortFormProvider shortFormProvider;
private IRIShortFormProvider iriShortFormProvider;
/** default constructor */
public SimpleRenderer() {
sb = new StringBuilder();
resetShortFormProvider();
}
/** reset the renderer. */
public void reset() {
sb = new StringBuilder();
}
/**
* @return true if default is used
*/
public boolean isUsingDefaultShortFormProvider() {
return shortFormProvider instanceof DefaultPrefixManager;
}
/**
* Resets the short form provider to the default short form provider, which is a PrefixManager
* with the default set of prefixes.
*/
public final void resetShortFormProvider() {
DefaultPrefixManager defaultPrefixManager = new DefaultPrefixManager();
shortFormProvider = defaultPrefixManager;
iriShortFormProvider = defaultPrefixManager;
}
/**
* Resets the short form provider and adds prefix name to prefix mappings based on the specified
* ontology's format (if it is a prefix format) and possibly the ontologies in the imports
* closure.
*
* @param ontology The ontology whose format will be used to obtain prefix mappings
* @param manager A manager which can be used to obtain the format of the specified ontology
* (and possibly ontologies in its imports closure)
* @param processImportedOntologies Specifies whether or not the prefix mapping should be
* obtained from imported ontologies.
*/
public void setPrefixesFromOntologyFormat(@Nonnull OWLOntology ontology,
@Nonnull OWLOntologyManager manager, boolean processImportedOntologies) {
resetShortFormProvider();
if (processImportedOntologies) {
for (OWLOntology importedOntology : manager.getImportsClosure(ontology)) {
if (!importedOntology.equals(ontology)) {
copyPrefixes(manager.getOntologyFormat(importedOntology));
}
}
}
OWLDocumentFormat format = manager.getOntologyFormat(ontology);
copyPrefixes(format);
}
private void copyPrefixes(OWLDocumentFormat ontologyFormat) {
if (!(ontologyFormat instanceof PrefixDocumentFormat)) {
return;
}
PrefixDocumentFormat prefixFormat = (PrefixDocumentFormat) ontologyFormat;
for (Map.Entry e : prefixFormat.getPrefixName2PrefixMap().entrySet()) {
setPrefix(e.getKey(), e.getValue());
}
}
/**
* Sets a prefix name for a given prefix. Note that prefix names MUST end with a colon.
*
* @param prefixName The prefix name (ending with a colon)
* @param prefix The prefix that the prefix name maps to
*/
public void setPrefix(@Nonnull String prefixName, @Nonnull String prefix) {
if (!isUsingDefaultShortFormProvider()) {
resetShortFormProvider();
}
((DefaultPrefixManager) shortFormProvider).setPrefix(prefixName, prefix);
}
@Override
public void setShortFormProvider(ShortFormProvider shortFormProvider) {
this.shortFormProvider = shortFormProvider;
}
/**
* @param iri the iri to shorten
* @return the short form
*/
public String getShortForm(@Nonnull IRI iri) {
return iriShortFormProvider.getShortForm(iri);
}
@Override
public String render(OWLObject object) {
reset();
object.accept(this);
return sb.toString();
}
protected void render(Set extends OWLObject> objects) {
render(objects, true);
}
protected void render(Collection extends OWLObject> objects, boolean sort) {
Collection extends OWLObject> sorted = objects;
if (sort) {
sorted = sortOptionally(objects);
}
for (Iterator extends OWLObject> it = sorted.iterator(); it.hasNext();) {
it.next().accept(this);
if (it.hasNext()) {
sb.append(' ');
}
}
}
@Override
public void visit(OWLOntology ontology) {
sb.append("Ontology(").append(ontology.getOntologyID()).append(" [Axioms: ")
.append(ontology.getAxiomCount()).append("] [Logical axioms: ")
.append(ontology.getLogicalAxiomCount()).append("])");
}
private void insertSpace() {
sb.append(' ');
}
/**
* @param axiom the axiom whose annotations should be written
*/
public void writeAnnotations(OWLAxiom axiom) {
for (OWLAnnotation anno : sortOptionally(axiom.getAnnotations())) {
anno.accept(this);
insertSpace();
}
}
@Override
public void visit(OWLSubClassOfAxiom axiom) {
sb.append("SubClassOf(");
writeAnnotations(axiom);
axiom.getSubClass().accept(this);
insertSpace();
axiom.getSuperClass().accept(this);
sb.append(')');
}
@Override
public void visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
sb.append("NegativeObjectPropertyAssertion(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getSubject().accept(this);
insertSpace();
axiom.getObject().accept(this);
sb.append(')');
}
@Override
public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
sb.append("AsymmetricObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLReflexiveObjectPropertyAxiom axiom) {
sb.append("ReflexiveObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDisjointClassesAxiom axiom) {
sb.append("DisjointClasses(");
writeAnnotations(axiom);
render(axiom.getClassExpressions());
sb.append(')');
}
@Override
public void visit(OWLDataPropertyDomainAxiom axiom) {
sb.append("DataPropertyDomain(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getDomain().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectPropertyDomainAxiom axiom) {
sb.append("ObjectPropertyDomain(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getDomain().accept(this);
sb.append(')');
}
@Override
public void visit(OWLEquivalentObjectPropertiesAxiom axiom) {
sb.append("EquivalentObjectProperties(");
writeAnnotations(axiom);
render(axiom.getProperties());
sb.append(')');
}
@Override
public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
sb.append("NegativeDataPropertyAssertion(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getSubject().accept(this);
insertSpace();
axiom.getObject().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDifferentIndividualsAxiom axiom) {
sb.append("DifferentIndividuals(");
writeAnnotations(axiom);
render(axiom.getIndividuals());
sb.append(')');
}
@Override
public void visit(OWLDisjointDataPropertiesAxiom axiom) {
sb.append("DisjointDataProperties(");
writeAnnotations(axiom);
render(axiom.getProperties());
sb.append(')');
}
@Override
public void visit(OWLDisjointObjectPropertiesAxiom axiom) {
sb.append("DisjointObjectProperties(");
writeAnnotations(axiom);
render(axiom.getProperties());
sb.append(')');
}
@Override
public void visit(OWLObjectPropertyRangeAxiom axiom) {
sb.append("ObjectPropertyRange(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getRange().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectPropertyAssertionAxiom axiom) {
sb.append("ObjectPropertyAssertion(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getSubject().accept(this);
insertSpace();
axiom.getObject().accept(this);
sb.append(')');
}
@Override
public void visit(OWLFunctionalObjectPropertyAxiom axiom) {
sb.append("FunctionalObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLSubObjectPropertyOfAxiom axiom) {
sb.append("SubObjectPropertyOf(");
writeAnnotations(axiom);
axiom.getSubProperty().accept(this);
insertSpace();
axiom.getSuperProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDisjointUnionAxiom axiom) {
sb.append("DisjointUnion(");
writeAnnotations(axiom);
axiom.getOWLClass().accept(this);
insertSpace();
render(axiom.getClassExpressions());
sb.append(')');
}
@Override
public void visit(OWLDeclarationAxiom axiom) {
sb.append("Declaration(");
writeAnnotations(axiom);
OWLEntity entity = axiom.getEntity();
if (entity.isOWLClass()) {
sb.append("Class(");
} else if (entity.isOWLObjectProperty()) {
sb.append("ObjectProperty(");
} else if (entity.isOWLDataProperty()) {
sb.append("DataProperty(");
} else if (entity.isOWLNamedIndividual()) {
sb.append("NamedIndividual(");
} else if (entity.isOWLDatatype()) {
sb.append("Datatype(");
} else if (entity.isOWLAnnotationProperty()) {
sb.append("AnnotationProperty(");
}
axiom.getEntity().accept(this);
sb.append("))");
}
@Override
public void visit(OWLAnnotationAssertionAxiom axiom) {
sb.append("AnnotationAssertion(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getSubject().accept(this);
insertSpace();
axiom.getValue().accept(this);
sb.append(')');
}
@Override
public void visit(OWLSymmetricObjectPropertyAxiom axiom) {
sb.append("SymmetricObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataPropertyRangeAxiom axiom) {
sb.append("DataPropertyRange(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getRange().accept(this);
sb.append(')');
}
@Override
public void visit(OWLFunctionalDataPropertyAxiom axiom) {
sb.append("FunctionalDataProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLEquivalentDataPropertiesAxiom axiom) {
sb.append("EquivalentDataProperties(");
writeAnnotations(axiom);
render(axiom.getProperties());
sb.append(')');
}
@Override
public void visit(OWLClassAssertionAxiom axiom) {
sb.append("ClassAssertion(");
writeAnnotations(axiom);
axiom.getClassExpression().accept(this);
insertSpace();
axiom.getIndividual().accept(this);
sb.append(')');
}
@Override
public void visit(OWLEquivalentClassesAxiom axiom) {
sb.append("EquivalentClasses(");
writeAnnotations(axiom);
render(axiom.getClassExpressions());
sb.append(')');
}
@Override
public void visit(OWLDataPropertyAssertionAxiom axiom) {
sb.append("DataPropertyAssertion(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
insertSpace();
axiom.getSubject().accept(this);
insertSpace();
axiom.getObject().accept(this);
sb.append(')');
}
@Override
public void visit(OWLTransitiveObjectPropertyAxiom axiom) {
sb.append("TransitiveObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
sb.append("IrreflexiveObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLSubDataPropertyOfAxiom axiom) {
sb.append("SubDataPropertyOf(");
writeAnnotations(axiom);
axiom.getSubProperty().accept(this);
insertSpace();
axiom.getSuperProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
sb.append("InverseFunctionalObjectProperty(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLSameIndividualAxiom axiom) {
sb.append("SameIndividual(");
writeAnnotations(axiom);
render(axiom.getIndividuals());
sb.append(')');
}
@Override
public void visit(OWLSubPropertyChainOfAxiom axiom) {
sb.append("SubObjectPropertyOf(");
writeAnnotations(axiom);
sb.append("ObjectPropertyChain(");
render(axiom.getPropertyChain(), false);
sb.append(')');
insertSpace();
axiom.getSuperProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLClass ce) {
sb.append(shortFormProvider.getShortForm(ce));
}
@Override
public void visit(OWLObjectIntersectionOf ce) {
sb.append("ObjectIntersectionOf(");
render(ce.getOperands());
sb.append(')');
}
@Override
public void visit(OWLObjectUnionOf ce) {
sb.append("ObjectUnionOf(");
render(ce.getOperands());
sb.append(')');
}
@Override
public void visit(OWLObjectComplementOf ce) {
sb.append("ObjectComplementOf(");
ce.getOperand().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectSomeValuesFrom ce) {
sb.append("ObjectSomeValuesFrom(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectAllValuesFrom ce) {
sb.append("ObjectAllValuesFrom(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectHasValue ce) {
sb.append("ObjectHasValue(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectMinCardinality ce) {
sb.append("ObjectMinCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectExactCardinality ce) {
sb.append("ObjectExactCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectMaxCardinality ce) {
sb.append("ObjectMaxCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectHasSelf ce) {
sb.append("ObjectHasSelf(");
ce.getProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLObjectOneOf ce) {
sb.append("ObjectOneOf(");
render(ce.getIndividuals());
sb.append(')');
}
@Override
public void visit(OWLDataSomeValuesFrom ce) {
sb.append("DataSomeValuesFrom(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataAllValuesFrom ce) {
sb.append("DataAllValuesFrom(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataHasValue ce) {
sb.append("DataHasValue(");
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataMinCardinality ce) {
sb.append("DataMinCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataExactCardinality ce) {
sb.append("DataExactCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataMaxCardinality ce) {
sb.append("DataMaxCardinality(");
sb.append(ce.getCardinality());
insertSpace();
ce.getProperty().accept(this);
insertSpace();
ce.getFiller().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDatatype node) {
sb.append(shortFormProvider.getShortForm(node));
}
@Override
public void visit(OWLDataComplementOf node) {
sb.append("DataComplementOf(");
node.getDataRange().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataOneOf node) {
sb.append("DataOneOf(");
render(node.getValues());
sb.append(')');
}
@Override
public void visit(OWLDatatypeRestriction node) {
sb.append("DatatypeRestriction(");
node.getDatatype().accept(this);
for (OWLFacetRestriction restriction : node.getFacetRestrictions()) {
insertSpace();
restriction.accept(this);
}
sb.append(')');
}
@Override
public void visit(OWLFacetRestriction node) {
sb.append("facetRestriction(");
sb.append(node.getFacet());
insertSpace();
node.getFacetValue().accept(this);
sb.append(')');
}
@Override
public void visit(OWLLiteral node) {
String literal = EscapeUtils.escapeString(node.getLiteral());
if (node.isRDFPlainLiteral()) {
// We can use a syntactic shortcut
sb.append('"').append(literal).append('"');
if (node.hasLang()) {
sb.append('@').append(node.getLang());
}
} else {
sb.append('"').append(literal).append("\"^^");
node.getDatatype().accept(this);
}
}
@Override
public void visit(OWLObjectProperty property) {
sb.append(shortFormProvider.getShortForm(property));
}
@Override
public void visit(OWLObjectInverseOf property) {
sb.append("ObjectInverseOf(");
property.getInverse().accept(this);
sb.append(')');
}
@Override
public void visit(OWLDataProperty property) {
sb.append(shortFormProvider.getShortForm(property));
}
@Override
public void visit(OWLNamedIndividual individual) {
sb.append(shortFormProvider.getShortForm(individual));
}
@Override
public void visit(OWLInverseObjectPropertiesAxiom axiom) {
sb.append("InverseObjectProperties(");
writeAnnotations(axiom);
axiom.getFirstProperty().accept(this);
sb.append(' ');
axiom.getSecondProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLHasKeyAxiom axiom) {
sb.append("HasKey(");
writeAnnotations(axiom);
axiom.getClassExpression().accept(this);
sb.append(" (");
render(axiom.getObjectPropertyExpressions());
sb.append(") (");
render(axiom.getDataPropertyExpressions());
sb.append("))");
}
@Override
public void visit(OWLDataIntersectionOf node) {
sb.append("DataIntersectionOf(");
render(node.getOperands());
sb.append(')');
}
@Override
public void visit(OWLDataUnionOf node) {
sb.append("DataUnionOf(");
render(node.getOperands());
sb.append(')');
}
@Override
public void visit(OWLAnnotationProperty property) {
sb.append(shortFormProvider.getShortForm(property));
}
@Override
public void visit(OWLAnnotationPropertyDomainAxiom axiom) {
sb.append("AnnotationPropertyDomain(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(' ');
axiom.getDomain().accept(this);
sb.append(')');
}
@Override
public void visit(OWLAnnotationPropertyRangeAxiom axiom) {
sb.append("AnnotationPropertyRange(");
writeAnnotations(axiom);
axiom.getProperty().accept(this);
sb.append(' ');
axiom.getRange().accept(this);
sb.append(')');
}
@Override
public void visit(OWLSubAnnotationPropertyOfAxiom axiom) {
sb.append("SubAnnotationPropertyOf(");
writeAnnotations(axiom);
axiom.getSubProperty().accept(this);
sb.append(' ');
axiom.getSuperProperty().accept(this);
sb.append(')');
}
@Override
public void visit(OWLAnonymousIndividual individual) {
sb.append(individual.getID());
}
@Override
public void visit(IRI iri) {
sb.append('<');
sb.append(iri);
sb.append('>');
}
@Override
public void visit(OWLAnnotation node) {
sb.append("Annotation(");
for (OWLAnnotation anno : sortOptionally(node.getAnnotations())) {
anno.accept(this);
sb.append(' ');
}
node.getProperty().accept(this);
sb.append(' ');
node.getValue().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLRule rule) {
sb.append("DLSafeRule(");
writeAnnotations(rule);
sb.append("Body(");
render(rule.getBody(), false);
sb.append(") Head(");
render(rule.getHead(), false);
sb.append("))");
}
@Override
public void visit(SWRLClassAtom node) {
sb.append("ClassAtom(");
node.getPredicate().accept(this);
sb.append(' ');
node.getArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLDataRangeAtom node) {
sb.append("DataRangeAtom(");
node.getPredicate().accept(this);
sb.append(' ');
node.getArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLDifferentIndividualsAtom node) {
sb.append("DifferentFromAtom(");
node.getFirstArgument().accept(this);
sb.append(' ');
node.getSecondArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLSameIndividualAtom node) {
sb.append("SameAsAtom(");
node.getFirstArgument().accept(this);
sb.append(' ');
node.getSecondArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLObjectPropertyAtom node) {
sb.append("ObjectPropertyAtom(");
node.getPredicate().accept(this);
sb.append(' ');
node.getFirstArgument().accept(this);
sb.append(' ');
node.getSecondArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLDataPropertyAtom node) {
sb.append("DataPropertyAtom(");
node.getPredicate().accept(this);
sb.append(' ');
node.getFirstArgument().accept(this);
sb.append(' ');
node.getSecondArgument().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLBuiltInAtom node) {
sb.append("BuiltInAtom(");
sb.append(getShortForm(node.getPredicate()));
sb.append(' ');
List arguments = node.getArguments();
for (int i = 0; i < arguments.size(); i++) {
if (i > 0) {
sb.append(' ');
}
arguments.get(i).accept(this);
}
sb.append(')');
}
@Override
public void visit(OWLDatatypeDefinitionAxiom axiom) {
sb.append("DatatypeDefinition(");
writeAnnotations(axiom);
axiom.getDatatype().accept(this);
sb.append(' ');
axiom.getDataRange().accept(this);
sb.append(')');
}
@Override
public void visit(SWRLVariable node) {
sb.append("Variable(");
sb.append(getShortForm(node.getIRI()));
sb.append(')');
}
@Override
public void visit(SWRLIndividualArgument node) {
node.getIndividual().accept(this);
}
@Override
public void visit(SWRLLiteralArgument node) {
node.getLiteral().accept(this);
}
@Override
public String toString() {
return sb.toString();
}
}