public class ChangeClassifier {

    private final Map<OWLEntity, Collection<AxiomChangeData>> changesByEntity;

    public ChangeClassifier(final Collection<AxiomChangeData> changes) {
        changesByEntity = new HashMap<OWLEntity, Collection<AxiomChangeData>>();
        for (final AxiomChangeData c : changes)
            for (final OWLEntity e : c.getAxiom().getSignature()) {
                Collection<AxiomChangeData> affectingChanges = changesByEntity.get(e);
                if (affectingChanges == null) {
                    affectingChanges = new ArrayList<AxiomChangeData>();
                    changesByEntity.put(e, affectingChanges);
                }
                affectingChanges.add(c);
            }
    }

    public Collection<AxiomChangeData> getChangesByEntity(final OWLEntity e) {
        return changesByEntity.get(e);
    }

}
 public class EntityClassifier {

    private final Collection<OWLEntity> newEntities;
    private final Collection<OWLEntity> removedEntities;
    private final Collection<OWLEntity> modifiedEntities;

    public Collection<OWLEntity> getNewEntities() {
        return newEntities;
    }

    public Collection<OWLEntity> getRemovedEntities() {
        return removedEntities;
    }

    public Collection<OWLEntity> getModifiedEntities() {
        return modifiedEntities;
    }

    public Iterable<OWLEntity> getAllEntities() {
        return Iterables.concat(removedEntities, newEntities, modifiedEntities);
    }

    /**
     * Classify all entities into removed, added and modified ones.
     * 
     * @param parentEntities
     * @param childEntities
     * @param affectedEntities
     */
    public EntityClassifier(final OWLOntology parent, final OWLOntology child,
            final Collection<OWLEntity> affectedEntities,
            final Set<OWLEntity> newEntities,
            final Set<OWLEntity> removedEntities,
            final Set<OWLEntity> modifiedEntities) {
        this.newEntities = newEntities;
        this.removedEntities = removedEntities;
        this.modifiedEntities = modifiedEntities;
        for (final OWLEntity e : affectedEntities)
            if (parent.containsEntityInSignature(e)) {
                if (child.containsEntityInSignature(e))
                    modifiedEntities.add(e);
                else
                    removedEntities.add(e);
            } else
                // assert child.containsEntityInSignature(e);
                newEntities.add(e);
    }
} public class EntityCollector extends OWLEntityCollector implements
        CustomOntologyChangeDataVisitor<Object, EntityCollectorException> {

    public EntityCollector(final Set<OWLEntity> toReturn,
            final Collection<OWLAnonymousIndividual> anonsToReturn) {
        super(toReturn, anonsToReturn);
    }

    @Override
    public Object visit(AddAxiomData data) {
        data.getAxiom().accept(this);
        return null;
    }

    @Override
    public Object visit(RemoveAxiomData data) {
        data.getAxiom().accept(this);
        return null;
    }

    @Override
    public Object visit(AddOntologyAnnotationData data) {
        // We don't need to count annotation properties and datatypes as entities
        return null;
    }

    @Override
    public Object visit(RemoveOntologyAnnotationData data) {
        // We don't need to count annotation properties and datatypes as entities
        return null;
    }

    @Override
    public Object visit(SetOntologyIDData data) {
        return null;
    }

    @Override
    public Object visit(AddImportData data) {
        return null;
    }

    @Override
    public Object visit(RemoveImportData data) {
        return null;
    }

    @Override
    public Object visit(SetOntologyFormatData data) {
        return null;
    }

    @Override
    public Object visit(AddPrefixData data) {
        return null;
    }

    @Override
    public Object visit(RemovePrefixData data) {
        return null;
    }

    @Override
    public Object visit(ModifyPrefixData data) {
        return null;
    }

    @Override
    public Object visit(RenamePrefixData data) {
        return null;
    }
}
 public class EntityCollectorException extends Exception {

    private static final long serialVersionUID = -3348031579335250998L;

}
 public class PrefixExtractor {

    private final Map<String, String> prefixName2PrefixMap;

    public PrefixExtractor(final Collection<OWLEntity> entities,
            final Map<String, String> allPrefixes) {
        final Collection<String> prefixes = new HashSet<String>();
        for (final OWLEntity e : entities)
            prefixes.add(e.getIRI().getStart());
        prefixName2PrefixMap = new HashMap<String, String>();
        for (final Entry<String, String> e : allPrefixes.entrySet()) {
            final String prefix = e.getValue();
            if (prefixes.contains(prefix)) {
                final String prefixName = e.getKey();
                prefixName2PrefixMap.put(prefixName, prefix);
            }
        }
    }

    public Map<String, String> getPrefixName2PrefixMap() {
        return prefixName2PrefixMap;
    }
} public abstract class ChangeSet {

    protected ChangeSet() {
    }

    private SetOntologyFormatData formatChange;

    private Collection<PrefixChangeData> prefixChanges;

    private SetOntologyIDData ontologyIdChange;

    private Collection<ImportChangeData> importChanges;

    private Collection<OWLOntologyChangeData> annotationChanges;

    private Collection<AxiomChangeData> axiomChanges;

    public SetOntologyFormatData getFormatChange() {
        return formatChange;
    }

    public Collection<PrefixChangeData> getPrefixChanges() {
        return prefixChanges;
    }

    public SetOntologyIDData getOntologyIdChange() {
        return ontologyIdChange;
    }

    public Collection<ImportChangeData> getImportChanges() {
        return importChanges;
    }

    public Collection<OWLOntologyChangeData> getAnnotationChanges() {
        return annotationChanges;
    }

    public Collection<AxiomChangeData> getAxiomChanges() {
        return axiomChanges;
    }

    protected void setFormatChange(final SetOntologyFormatData formatChange) {
        this.formatChange = formatChange;
    }

    protected void setPrefixChanges(final Collection<PrefixChangeData> prefixChanges) {
        this.prefixChanges = prefixChanges;
    }

    protected void setOntologyIdChange(final SetOntologyIDData ontologyIdChange) {
        this.ontologyIdChange = ontologyIdChange;
    }

    protected void setImportChanges(final Collection<ImportChangeData> importChanges) {
        this.importChanges = importChanges;
    }

    protected void setAnnotationChanges(final Collection<OWLOntologyChangeData> annotationChanges) {
        this.annotationChanges = annotationChanges;
    }

    protected void setAxiomChanges(final Collection<AxiomChangeData> axiomChanges) {
        this.axiomChanges = axiomChanges;
    }

    /**
     * Count all changes.
     *
     * @return
     */
    public int size() {
        int sum = 0;
        if (formatChange != null)
            sum++;
        if (ontologyIdChange != null)
            sum++;
        sum += prefixChanges.size();
        sum += importChanges.size();
        sum += annotationChanges.size();
        sum += axiomChanges.size();
        return sum;
    }

    public Collection<Object> asCollection() {
        ArrayList<Object> result = new ArrayList<Object>();
        if (formatChange != null)
            result.add(formatChange);
        result.addAll(prefixChanges);
        if (ontologyIdChange != null)
            result.add(ontologyIdChange);
        result.addAll(importChanges);
        result.addAll(annotationChanges);
        result.addAll(axiomChanges);
        return result;
    }

    @SuppressWarnings({ "unchecked", "serial" })
    public Iterable<OWLOntologyChangeData> all() {
        return Iterables.concat(new ArrayList<OWLOntologyChangeData>() {
            {
                add(formatChange);
            }
        }, prefixChanges, new ArrayList<OWLOntologyChangeData>() {
            {
                add(ontologyIdChange);
            }
        }, importChanges, annotationChanges, axiomChanges);
    }

    public <R, E extends Exception> void accept(final CustomOntologyChangeDataVisitor<R, E> visitor)
            throws E {
        if (formatChange != null)
            formatChange.accept(visitor);
        for (final PrefixChangeData c : prefixChanges)
            c.accept(visitor);
        if (ontologyIdChange != null)
            ontologyIdChange.accept(visitor);
        for (final OWLOntologyChangeData c : importChanges)
            c.accept(visitor);
        for (final OWLOntologyChangeData c : annotationChanges)
            c.accept(visitor);
        for (final OWLOntologyChangeData c : axiomChanges)
            c.accept(visitor);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((annotationChanges == null) ? 0 : annotationChanges.hashCode());
        result = prime * result + ((axiomChanges == null) ? 0 : axiomChanges.hashCode());
        result = prime * result + ((formatChange == null) ? 0 : formatChange.hashCode());
        result = prime * result + ((importChanges == null) ? 0 : importChanges.hashCode());
        result = prime * result + ((ontologyIdChange == null) ? 0 : ontologyIdChange.hashCode());
        result = prime * result + ((prefixChanges == null) ? 0 : prefixChanges.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof ChangeSet))
            return false;
        ChangeSet other = (ChangeSet) obj;
        if (annotationChanges == null) {
            if (other.annotationChanges != null)
                return false;
        } else if (!setsEqual(annotationChanges, other.annotationChanges))
            return false;
        if (axiomChanges == null) {
            if (other.axiomChanges != null)
                return false;
        } else if (!setsEqual(axiomChanges, other.axiomChanges))
            return false;
        if (formatChange == null) {
            if (other.formatChange != null)
                return false;
        } else if (!formatChange.equals(other.formatChange))
            return false;
        if (importChanges == null) {
            if (other.importChanges != null)
                return false;
        } else if (!setsEqual(importChanges, other.importChanges))
            return false;
        if (ontologyIdChange == null) {
            if (other.ontologyIdChange != null)
                return false;
        } else if (!ontologyIdChange.equals(other.ontologyIdChange))
            return false;
        if (prefixChanges == null) {
            if (other.prefixChanges != null)
                return false;
        } else if (!setsEqual(prefixChanges, other.prefixChanges))
            return false;
        return true;
    }

    private <T> boolean setsEqual(Collection<T> c1, Collection<T> c2) {
        if ((c1 instanceof Set) && (c2 instanceof Set))
            return c1.equals(c2);
        if ((c1 instanceof Set))
            return c1.equals(new HashSet<T>(c2));
        if ((c2 instanceof Set))
            return new HashSet<T>(c1).equals(c2);
        return new HashSet<T>(c1).equals(new HashSet<T>(c2));
    }

    public boolean isEmpty() {
        return (formatChange == null) && (prefixChanges == null || prefixChanges.isEmpty())
                && (ontologyIdChange == null) && (importChanges == null || importChanges.isEmpty())
                && (annotationChanges == null || annotationChanges.isEmpty())
                && (axiomChanges == null || axiomChanges.isEmpty());
    }

    public void applyTo(final OWLOntology ontology) throws UnsupportedOntologyFormatException {
        OWLOntologyManager manager = ontology.getOWLOntologyManager();
        List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
        // prefix changes can only be applied to ontology in a prefix format
        OWLOntologyFormat oldFormat = manager.getOntologyFormat(ontology);
        Map<String, String> newPrefixMap = null;
        if (manager.getOntologyFormat(ontology).isPrefixOWLOntologyFormat()) {
            PrefixOWLOntologyFormat oldPrefixFormat = oldFormat.asPrefixOWLOntologyFormat();
            Map<String, String> oldPrefixMap = new HashMap<String, String>(
                    oldPrefixFormat.getPrefixName2PrefixMap());
            newPrefixMap = new HashMap<String, String>(oldPrefixMap);
            @SuppressWarnings("serial")
            OWLEntityRenamer renamer = new OWLEntityRenamer(manager, new HashSet<OWLOntology>() {
                {
                    add(ontology);
                }
            });
            for (PrefixChangeData c : prefixChanges) {
                if (c instanceof AddPrefixData) {
                    // prefix should not be there
                    assert oldPrefixMap.get(c.getPrefixName()) == null;
                    newPrefixMap.put(c.getPrefixName(), c.getPrefix());
                } else if (c instanceof RemovePrefixData) {
                    // prefix should already be there
                    assert oldPrefixMap.get(c.getPrefixName()).equals(c.getPrefix());
                    newPrefixMap.remove(c.getPrefixName());
                } else if (c instanceof ModifyPrefixData) {
                    ModifyPrefixData mc = (ModifyPrefixData) c;
                    // prefix should already be there
                    assert oldPrefixMap.get(mc.getPrefixName()) != null;
                    // and it should not be equal to new prefix
                    String oldPrefix = oldPrefixMap.get(mc.getPrefixName());
                    assert !oldPrefix.equals(mc.getPrefix());
                    newPrefixMap.put(mc.getPrefixName(), mc.getPrefix());
                    // rename entities
                    // don't add changes to the "changes" ArrayList but apply them at once
                    for (OWLEntity e : ontology.getSignature()) {
                        if (e.getIRI().getStart().equals(mc.getOldPrefix()))
                            manager.applyChanges(renamer.changeIRI(e, IRI.create(mc.getPrefix(), e.getIRI().getFragment())));
                    }
                } else if (c instanceof RenamePrefixData) {
                    String prefixToFind = c.getPrefix();
                    String oldPrefixName = null;
                    String newPrefixName = ((RenamePrefixData) c).getPrefixName();
                    for (Map.Entry<String, String> e : oldPrefixMap.entrySet()) {
                        if (e.getValue().equals(prefixToFind)) {
                            oldPrefixName = e.getKey();
                            break;
                        }
                    }
                    // prefix name should already be there
                    assert oldPrefixName != null;
                    // and it should not be equal to the new name
                    assert !oldPrefixName.equals(newPrefixName);

                    newPrefixMap.remove(oldPrefixName);
                    newPrefixMap.put(newPrefixName, c.getPrefix());
                }
            }
        }
        OWLOntologyFormat newFormat;
        if (formatChange != null) {
            newFormat = formatChange.getNewFormat();
        } else {
            newFormat = oldFormat;
        }
        // copy prefixes to new format
        if (newFormat.isPrefixOWLOntologyFormat()) {
            PrefixOWLOntologyFormat newPrefixFormat = newFormat.asPrefixOWLOntologyFormat();
            if (newPrefixMap != null) {
                newPrefixFormat.clearPrefixes();
                for (Map.Entry<String, String> e : newPrefixMap.entrySet()) {
                    newPrefixFormat.setPrefix(e.getKey(), e.getValue());
                }
            }
        }
        // apply format (with prefixes)
        manager.setOntologyFormat(ontology, newFormat);
        // ontology ID
        if (ontologyIdChange != null)
            manager.applyChange(ontologyIdChange.createOntologyChange(ontology));
        // prepare and apply other changes
        for (OWLOntologyChangeData c : axiomChanges)
            changes.add(c.createOntologyChange(ontology));
        for (OWLOntologyChangeData c : annotationChanges)
            changes.add(c.createOntologyChange(ontology));
        for (OWLOntologyChangeData c : importChanges)
            changes.add(c.createOntologyChange(ontology));
        manager.applyChanges(changes);
    }
}
 public class FullChangeSet extends ChangeSet {

    private final OWLOntology parent;

    public OWLOntology getParent() {
        return parent;
    }

    private final OWLOntology child;

    public OWLOntology getChild() {
        return child;
    }

    /**
     * Calculate changeset between the two ontologies.
     *
     * @param parent
     *            The original ontology
     * @param child
     *            The updated ontology
     * @throws OWLOntologyCreationException
     */
    public FullChangeSet(final OWLOntology parent, final OWLOntology child) throws OWLOntologyCreationException {
        this(parent, child, true);
    }

    /**
     * Calculate changeset between parent and child.
     *
     * @param parent
     *            The original ontology
     * @param child
     *            The updated ontology
     * @param cosiderPrefixModifications
     *            If true, changes of axioms that are caused just by prefix
     *            modifications are filtered out.
     *
     *            Note: this will change parent.
     * @throws OWLOntologyCreationException
     */
    public FullChangeSet(final OWLOntology parent, final OWLOntology child,
            final Boolean cosiderPrefixModifications) throws OWLOntologyCreationException {
        this.parent = parent;
        this.child = child;
        // Ontology format
        final OWLOntologyFormat parentFormat = parent.getOWLOntologyManager().getOntologyFormat(
                parent);
        final OWLOntologyFormat childFormat = child.getOWLOntologyManager()
                .getOntologyFormat(child);
        if (!parentFormat.equals(childFormat))
            setFormatChange(new SetOntologyFormatData(childFormat));
        // Prefixes
        setPrefixChanges(findPrefixChanges(parent, child));
        // Ontology ID
        if (!(parent.getOntologyID().isAnonymous() && child.getOntologyID().isAnonymous()))
            if (!parent.getOntologyID().equals(child.getOntologyID()))
                setOntologyIdChange(new SetOntologyIDData(child.getOntologyID()));
        // Imports
        setImportChanges(findImportChanges(parent, child));

        if (cosiderPrefixModifications) {
            // apply prefix modifications to a copy
            HashSet<OWLOntology> ontologies = new HashSet<OWLOntology>();
            OWLOntology modifiedParent = OntologyUtils.copyOntology(parent);
            ontologies.add(modifiedParent);
            OWLOntologyManager manager = modifiedParent.getOWLOntologyManager();
            OWLEntityRenamer renamer = new OWLEntityRenamer(manager,
                    ontologies);
            for (PrefixChangeData c : getPrefixChanges()) {
                if (c instanceof ModifyPrefixData) {
                    ModifyPrefixData mc = (ModifyPrefixData) c;
                    String oldPrefix = mc.getOldPrefix();
                    String newPrefix = mc.getPrefix();
                    for (OWLEntity e : modifiedParent.getSignature()) {
                        if (e.getIRI().getStart().equals(oldPrefix)) {
                            IRI newIRI = IRI.create(newPrefix, e.getIRI().getFragment());
                            // System.out.println("Renaming " + e.getIRI() + " to " + newIRI);
                            manager.applyChanges(renamer.changeIRI(e, newIRI));
                        }
                    }
                }
            }
            // Annotations
            setAnnotationChanges(findAnnotationChanges(modifiedParent, child));
            // Axioms
            setAxiomChanges(findAxiomChanges(modifiedParent, child));
        } else {
            // Annotations
            setAnnotationChanges(findAnnotationChanges(parent, child));
            // Axioms
            setAxiomChanges(findAxiomChanges(parent, child));
        }
    }

    public static Collection<ImportChangeData> findImportChanges(final OWLOntology parent,
            final OWLOntology child) {
        final Collection<ImportChangeData> importChanges = new ArrayList<ImportChangeData>();
        final Collection<OWLImportsDeclaration> parentImports = parent.getImportsDeclarations();
        final Collection<OWLImportsDeclaration> childImports = child.getImportsDeclarations();
        for (final OWLImportsDeclaration decl : parentImports)
            if (!childImports.contains(decl))
                importChanges.add(new RemoveImportData(decl));
        for (final OWLImportsDeclaration decl : childImports)
            if (!parentImports.contains(decl))
                importChanges.add(new AddImportData(decl));
        return importChanges;
    }

    public static Collection<OWLOntologyChangeData> findAnnotationChanges(final OWLOntology parent,
            final OWLOntology child) {
        final Collection<OWLOntologyChangeData> annotationChanges = new ArrayList<OWLOntologyChangeData>();
        final Collection<OWLAnnotation> parentAnnotations = parent.getAnnotations();
        final Collection<OWLAnnotation> childAnnotations = child.getAnnotations();
        for (final OWLAnnotation annotation : parentAnnotations)
            if (!childAnnotations.contains(annotation))
                annotationChanges.add(new RemoveOntologyAnnotationData(annotation));
        for (final OWLAnnotation annotation : childAnnotations)
            if (!parentAnnotations.contains(annotation))
                annotationChanges.add(new AddOntologyAnnotationData(annotation));
        return annotationChanges;
    }

    public static Collection<AxiomChangeData> findAxiomChanges(final OWLOntology parent,
            final OWLOntology child) {
        final Collection<AxiomChangeData> axiomChanges = new ArrayList<AxiomChangeData>();
        OWLOntologyFormat parentFormat = parent.getOWLOntologyManager().getOntologyFormat(parent);
        if (parentFormat instanceof ManchesterOWLSyntaxOntologyFormat) {
            // collect annotation properties
            final Set<OWLAnnotationProperty> parentAnnotationProperties = new HashSet<OWLAnnotationProperty>();
            for (final OWLAnnotation a : parent.getAnnotations())
                parentAnnotationProperties.add(a.getProperty());
            for (final OWLAxiom axiom : parent.getAxioms()) {
                if (!child.containsAxiom(axiom)) {
                    // ignore declarations of used entities
                    if (axiom.isOfType(AxiomType.DECLARATION)) {
                        final OWLEntity e = ((OWLDeclarationAxiom) axiom).getEntity();
                        if (parentAnnotationProperties.contains(e)
                                || (parent.getReferencingAxioms(e).size() > 1))
                            // skip this declaration axiom
                            continue;
                    }
                    axiomChanges.add(new RemoveAxiomData(axiom));
                }
            }
        } else
            for (final OWLAxiom axiom : parent.getAxioms())
                if (!child.containsAxiom(axiom))
                    axiomChanges.add(new RemoveAxiomData(axiom));
        OWLOntologyFormat childFormat = child.getOWLOntologyManager().getOntologyFormat(child);
        if (childFormat instanceof ManchesterOWLSyntaxOntologyFormat) {
            // collect annotation properties
            final Set<OWLAnnotationProperty> childAnnotationProperties = new HashSet<OWLAnnotationProperty>();
            for (final OWLAnnotation a : parent.getAnnotations())
                childAnnotationProperties.add(a.getProperty());
            for (final OWLAxiom axiom : child.getAxioms()) {
                if (!parent.containsAxiom(axiom)) {
                    if (axiom.isOfType(AxiomType.DECLARATION)) {
                        // ignore declarations of used entities
                        final OWLEntity e = ((OWLDeclarationAxiom) axiom).getEntity();
                        if (childAnnotationProperties.contains(e)
                                || (child.getReferencingAxioms(e).size() > 1))
                            // skip this declaration axiom
                            continue;
                    }
                    axiomChanges.add(new AddAxiomData(axiom));
                }
            }
        } else
            for (final OWLAxiom axiom : child.getAxioms())
                if (!parent.containsAxiom(axiom))
                    axiomChanges.add(new AddAxiomData(axiom));
        return axiomChanges;
    }

    public static Collection<PrefixChangeData> findPrefixChanges(final OWLOntology parent,
            final OWLOntology child) {
        final OWLOntologyFormat parentFormat = parent.getOWLOntologyManager().getOntologyFormat(
                parent);
        final OWLOntologyFormat childFormat = child.getOWLOntologyManager()
                .getOntologyFormat(child);
        final Collection<PrefixChangeData> prefixChanges = new ArrayList<PrefixChangeData>();
        if (parentFormat instanceof PrefixOWLOntologyFormat) {
            final PrefixOWLOntologyFormat parentPrefixFormat = (PrefixOWLOntologyFormat) parentFormat;
            if (childFormat instanceof PrefixOWLOntologyFormat) {
                final PrefixOWLOntologyFormat childPrefixFormat = (PrefixOWLOntologyFormat) childFormat;
                for (final String parentPrefixName : parentPrefixFormat.getPrefixNames()) {
                    final String parentPrefixValue = parentPrefixFormat.getPrefix(parentPrefixName);
                    final String childPrefixValue = childPrefixFormat.getPrefix(parentPrefixName);
                    if (parentPrefixValue.equals(childPrefixValue))
                        continue;
                    String childPrefixName = null;
                    for (final Entry<String, String> e : childPrefixFormat
                            .getPrefixName2PrefixMap().entrySet())
                        if (e.getValue().equals(parentPrefixValue))
                            childPrefixName = e.getKey();
                    if ((childPrefixValue != null) && (!childPrefixValue.equals(parentPrefixValue)))
                        prefixChanges.add(new ModifyPrefixData(parentPrefixName, parentPrefixValue,
                                childPrefixValue));
                    if ((childPrefixName != null) && (!childPrefixName.equals(parentPrefixName)))
                        prefixChanges.add(new RenamePrefixData(parentPrefixName, parentPrefixValue,
                                childPrefixName));
                    if ((childPrefixValue == null) && (childPrefixName == null))
                        prefixChanges
                                .add(new RemovePrefixData(parentPrefixName, parentPrefixValue));
                }
                for (final String childPrefixName : childPrefixFormat.getPrefixNames()) {
                    final String parentPrefixValue = parentPrefixFormat.getPrefix(childPrefixName);
                    final String childPrefixValue = childPrefixFormat.getPrefix(childPrefixName);
                    if (childPrefixValue.equals(parentPrefixValue))
                        continue;
                    String parentPrefixName = null;
                    for (final Entry<String, String> e : parentPrefixFormat
                            .getPrefixName2PrefixMap().entrySet())
                        if (e.getValue().equals(parentPrefixValue))
                            parentPrefixName = e.getKey();
                    if ((parentPrefixValue == null) && (parentPrefixName == null))
                        prefixChanges.add(new AddPrefixData(childPrefixName, childPrefixValue));
                }
            } else
                // Child has not-prefix format, remove all prefixes
                for (final String prefixName : parentPrefixFormat.getPrefixNames()) {
                    final String prefix = parentPrefixFormat.getPrefix(prefixName);
                    prefixChanges.add(new RemovePrefixData(prefixName, prefix));
                }
        } else if (childFormat instanceof PrefixOWLOntologyFormat) {
            // Parent has not-prefix format, add all child prefixes
            final PrefixOWLOntologyFormat childPrefixFormat = (PrefixOWLOntologyFormat) childFormat;
            for (final String prefixName : childPrefixFormat.getPrefixNames()) {
                final String prefix = childPrefixFormat.getPrefix(prefixName);
                prefixChanges.add(new AddPrefixData(prefixName, prefix));
            }
        }
        return prefixChanges;
    }

    /**
     * @return Prefix name to prefix map
     */
    public Map<String, String> getAllPrefixes() {
        final Map<String, String> prefixName2PrefixMap = new HashMap<String, String>();
        final Map<String, String> prefixName2PrefixMap1 = parent.getOWLOntologyManager()
                .getOntologyFormat(parent).asPrefixOWLOntologyFormat().getPrefixName2PrefixMap();
        final Map<String, String> prefixName2PrefixMap2 = child.getOWLOntologyManager()
                .getOntologyFormat(child).asPrefixOWLOntologyFormat().getPrefixName2PrefixMap();
        prefixName2PrefixMap.putAll(prefixName2PrefixMap1);
        prefixName2PrefixMap.putAll(prefixName2PrefixMap2);
        return prefixName2PrefixMap;
    }
}
 public enum ChangeFormat {
    COMPACT,
    INDENTED
}; public interface ChangeRenderer {

    String render(OWLOntologyChangeData change);
    Character getSymbol(OWLOntologyChangeData change);
}
 public class FullFormProvider implements ShortFormProvider {

    @Override
    public final String getShortForm(final OWLEntity entity) {
        return "<" + entity.getIRI().toString() + ">";
    }

    @Override
    public void dispose() {
    }

} public class FunctionalChangeRenderer implements ChangeRenderer {

    private OWLObjectRenderer objectRenderer;
    private ChangeFormat changeFormat;

    public FunctionalChangeRenderer(final ShortFormProvider provider,
            final ChangeFormat changeFormat) {
        objectRenderer = new SimplerRenderer();
        objectRenderer.setShortFormProvider(provider);
        this.changeFormat = changeFormat;
    }

    /**
     * Render ontology changes.
     */
    @Override
    public final String render(final OWLOntologyChangeData change) {
        if (change == null)
            return null;
        // Custom changes
        if (change instanceof SetOntologyFormatData)
            return render((SetOntologyFormatData) change);
        else if (change instanceof AddPrefixData)
            return render((AddPrefixData) change);
        else if (change instanceof RemovePrefixData)
            return render((RemovePrefixData) change);
        else if (change instanceof ModifyPrefixData)
            return render((ModifyPrefixData) change);
        else if (change instanceof RenamePrefixData)
            return render((RenamePrefixData) change);
        // Standard changes
        else if (change instanceof SetOntologyIDData)
            return render((SetOntologyIDData) change);
        else if (change instanceof AddImportData)
            return render((AddImportData) change);
        else if (change instanceof RemoveImportData)
            return render((RemoveImportData) change);
        else if (change instanceof AddOntologyAnnotationData)
            return render((AddOntologyAnnotationData) change);
        else if (change instanceof RemoveOntologyAnnotationData)
            return render((RemoveOntologyAnnotationData) change);
        else if (change instanceof AddAxiomData)
            return render((AddAxiomData) change);
        else if (change instanceof RemoveAxiomData)
            return render((RemoveAxiomData) change);
        else
            return "UnknownChangeType: " + change.getClass().getName();
    }

    public final String render(final SetOntologyFormatData change) {
        return indentString("*", "OntologyFormat(\""
                + change.getNewFormat().toString() + "\")");
    }

    public final String render(final AddPrefixData change) {
        return indentString("+", "Prefix(" + change.getPrefixName() + "=<"
                + change.getPrefix() + ">)");
    }

    public final String render(final RemovePrefixData change) {
        return indentString("-", "Prefix(" + change.getPrefixName() + "=<"
                + change.getPrefix() + ">)");
    }

    public final String render(final ModifyPrefixData change) {
        return indentString("*", "Prefix(" + change.getPrefixName() + "=<"
                + change.getOldPrefix() + "> <" + change.getPrefix() + ">)");
    }

    public final String render(final RenamePrefixData change) {
        return indentString("#", "Prefix(" + change.getOldPrefixName() + " "
                + change.getPrefixName() + "=<"
                + change.getPrefix() + ">)");
    }

    private String renderOntologyId(final OWLOntologyID id) {
        if (id.isAnonymous())
            return "";
        else {
            final StringBuilder sb = new StringBuilder();
            sb.append(id.getOntologyIRI().toQuotedString());
            if (id.getVersionIRI() != null) {
                sb.append(" ");
                sb.append(id.getVersionIRI().toQuotedString());
            }
            return sb.toString();
        }
    }

    public final String render(final SetOntologyIDData change) {
        final OWLOntologyID newid = change.getNewId();
        return indentString("*", "OntologyID(" + renderOntologyId(newid) + ")");
    }

    public final String render(final AddImportData change) {
        return indentString("+", "Import(<"
                + change.getDeclaration().getIRI().toString() + ">)");
    }

    public final String render(final RemoveImportData change) {
        return indentString("-", "Import(<"
                + change.getDeclaration().getIRI().toString() + ">)");
    }

    public final String render(final AddOntologyAnnotationData change) {
        return indentString("+", objectRenderer.render(change.getAnnotation()));
    }

    public final String render(final RemoveOntologyAnnotationData change) {
        return indentString("-", objectRenderer.render(change.getAnnotation()));
    }

    public final String render(final AddAxiomData change) {
        return indentString("+", objectRenderer.render(change.getAxiom()));
    }

    public final String render(final RemoveAxiomData change) {
        return indentString("-", objectRenderer.render(change.getAxiom()));
    }

    private String writeIndent(final StringBuilder sb, final int indent) {
        sb.append("\n");
        for (int i = 0; i < indent; i++)
            sb.append(" ");
        return sb.toString();
    }

    protected final String indentString(final String prefix,
            final String compactString) {
        String indentedString = compactString;
        if (changeFormat == ChangeFormat.INDENTED) {
            final int indentSize = 2;
            final StringBuilder sb = new StringBuilder();
            int indent;
            if (prefix != null)
                indent = prefix.length() + 1;
            else
                indent = 0;
            boolean quote = false;
            for (final char c : compactString.toCharArray())
                switch (c) {
                case '(':
                    indent += indentSize;
                    // sb.append(':');
                    writeIndent(sb, indent);
                    break;
                case ')':
                    indent -= indentSize;
                    writeIndent(sb, indent);
                    break;
                case ' ':
                    if (quote)
                        sb.append(c);
                    else
                        writeIndent(sb, indent);
                    break;
                case '"':
                    quote = !quote;
                default:
                    sb.append(c);
                }
            indentedString = sb.toString().trim();
        }
        if (prefix == null)
            return indentedString;
        else
            return prefix + " " + indentedString;
    }

    @Override
    public Character getSymbol(OWLOntologyChangeData change) {
        if (change == null)
            return '?';
        // Standard changes
        if (change instanceof SetOntologyFormatData)
            return '*';
        else if (change instanceof AddPrefixData)
            return '+';
        else if (change instanceof RemovePrefixData)
            return '-';
        else if (change instanceof ModifyPrefixData)
            return '*';
        else if (change instanceof RenamePrefixData)
            return '#';
        // Custom changes
        else if (change instanceof SetOntologyIDData)
            return '*';
        else if (change instanceof AddImportData)
            return '+';
        else if (change instanceof RemoveImportData)
            return '-';
        else if (change instanceof AddOntologyAnnotationData)
            return '+';
        else if (change instanceof RemoveOntologyAnnotationData)
            return '-';
        else if (change instanceof AddAxiomData)
            return '+';
        else if (change instanceof RemoveAxiomData)
            return '-';
        else
            return '?';
    }
}
 public enum IriFormat {
    SIMPLE,
    QNAME,
    FULL,
    LABEL
}; public class QNameMultiMapShortFormProvider implements ShortFormProvider {
    private final List<Map<String, String>> namespace2PrefixMaps;

    /** Creates a QNameMultiMapShortFormProvider where namespace prefix mappings will
     * automatically be generated. */
    public QNameMultiMapShortFormProvider() {
        this(new HashMap<String, String>());
    }

    /** Creates a QNameMultiMapShortFormProvider which does not generate any prefixes.
     *
     * @param prefix2NamespaceMaps
     *            The list which contains prefix -> namespace mappings. */
    public QNameMultiMapShortFormProvider(Map<String, String> prefix2NamespaceMap) {
        namespace2PrefixMaps = new ArrayList<Map<String, String>>();
        addPrefix2NamespaceMap(prefix2NamespaceMap);
    }

    /** Creates a QNameShortFormProvider which does not generate any prefixes.
    *
    * @param prefix2NamespaceMap
    *            The map which contains a prefix -> namespace mapping. */
    public QNameMultiMapShortFormProvider(List<Map<String, String>> prefix2NamespaceMaps) {
        namespace2PrefixMaps = new ArrayList<Map<String, String>>();
        for (Map<String, String> prefix2NamespaceMap : prefix2NamespaceMaps) {
            addPrefix2NamespaceMap(prefix2NamespaceMap);
        }
    }

    public void addPrefix2NamespaceMap(Map<String, String> prefix2NamespaceMap) {
        Map<String, String> namespace2PrefixMap = new HashMap<String, String>();
        for (Map.Entry<String, String> e : prefix2NamespaceMap.entrySet()) {
            String prefixName = e.getKey();
            if (prefixName.endsWith(":"))
                prefixName = prefixName.substring(0, prefixName.length() - 1);
            namespace2PrefixMap.put(e.getValue(), prefixName);
        }
        namespace2PrefixMaps.add(namespace2PrefixMap);
    }

    @Override
    public String getShortForm(OWLEntity entity) {
        IRI iri = entity.getIRI();
        String namespace = XMLUtils.getNCNamePrefix(iri.toString());
        String prefix = null;
        for (Map<String, String> namespace2PrefixMap : namespace2PrefixMaps) {
            prefix = namespace2PrefixMap.get(namespace);
            if (prefix != null) {
                break;
            }
        }
        String toReturn;
        if (prefix != null) {
            String localName = XMLUtils.getNCNameSuffix(iri.toString());
            toReturn = prefix + ":" + (localName != null ? localName : "");
        } else {
            toReturn = iri.toQuotedString();
        }
        return toReturn;
    }

    @Override
    public void dispose() { }
}
 public class QuotedAnnotationValueShortFormProvider implements
        ShortFormProvider {

    private final OWLOntologySetProvider ontologySetProvider;

    private final ShortFormProvider alternateShortFormProvider;

    private final IRIShortFormProvider alternateIRIShortFormProvider;

    private final List<OWLAnnotationProperty> annotationProperties;

    private final Map<OWLAnnotationProperty, List<String>> preferredLanguageMap;

    /**
     * Constructs an annotation short form provider.
     *
     * @param annotationProperties
     *            A <code>List</code> of preferred annotation properties. The
     *            list is searched from start to end, so that annotations that
     *            have a property at the start of the list have a higher
     *            priority and are selected over annotations with properties
     *            that appear towards or at the end of the list.
     * @param preferredLanguageMap
     *            A map which maps annotation properties to preferred languages.
     *            For any given annotation property there may be a list of
     *            preferred languages. Languages at the start of the list have a
     *            higher priority over languages at the end of the list. This
     *            parameter may be empty but it must not be <code>null</code>.
     * @param ontologySetProvider
     *            An <code>OWLOntologySetProvider</code> which provides a set of
     *            ontology from which candidate annotation axioms should be
     *            taken. For a given entity, all ontologies are examined.
     * @param alternateShortFormProvider
     *            A short form provider which will be used to generate the short
     *            form for an entity that does not have any annotations. This
     *            provider will also be used in the case where the value of an
     *            annotation is an <code>OWLIndividual</code> for providing the
     *            short form of the individual.
     * @param alternateIRIShortFormProvider
     *            the alternate IRI short form provider
     */
    public QuotedAnnotationValueShortFormProvider(
            final OWLOntologySetProvider ontologySetProvider,
            final ShortFormProvider alternateShortFormProvider,
            final IRIShortFormProvider alternateIRIShortFormProvider,
            final List<OWLAnnotationProperty> annotationProperties,
            final Map<OWLAnnotationProperty, List<String>> preferredLanguageMap) {
        this.ontologySetProvider = ontologySetProvider;
        this.alternateShortFormProvider = alternateShortFormProvider;
        this.alternateIRIShortFormProvider = alternateIRIShortFormProvider;
        this.annotationProperties = annotationProperties;
        this.preferredLanguageMap = preferredLanguageMap;
    }

    @Override
    public String getShortForm(final OWLEntity entity) {

        // visit the properties in order of preference
        for (final OWLAnnotationProperty prop : annotationProperties) {
            final AnnotationLanguageFilter checker = new AnnotationLanguageFilter(
                    prop, preferredLanguageMap.get(prop));

            for (final OWLOntology ontology : ontologySetProvider
                    .getOntologies())
                for (final OWLAnnotationAssertionAxiom ax : entity
                        .getAnnotationAssertionAxioms(ontology))
                    ax.accept(checker);
            if (checker.getMatch() != null)
                return getRendering(checker.getMatch());
        }

        return alternateShortFormProvider.getShortForm(entity);
    }

    /**
     * Obtains the rendering of the specified object. If the object is a
     * constant then the rendering is equal to the literal value, if the object
     * is an individual then the rendering is equal to the rendering of the
     * individual as provided by the alternate short form provider
     *
     * @param object
     *            The object to the rendered
     * @return The rendering of the object.
     */
    private String getRendering(final OWLObject object) {
        // We return the literal value of constants or use the alternate
        // short form provider to render individuals.
        if (object instanceof OWLLiteral)
            return "\"" + ((OWLLiteral) object).getLiteral() + "\"";
        else if (object instanceof IRI)
            return alternateIRIShortFormProvider.getShortForm((IRI) object);
        else
            return alternateShortFormProvider.getShortForm((OWLEntity) object);
    }

    /**
     * @return the annotation URIs that this short form provider uses.
     */
    public List<OWLAnnotationProperty> getAnnotationProperties() {
        return annotationProperties;
    }

    /**
     * @return the preferred language map
     */
    public Map<OWLAnnotationProperty, List<String>> getPreferredLanguageMap() {
        return preferredLanguageMap;
    }

    @Override
    public void dispose() {
    }

    private static class AnnotationLanguageFilter extends
            OWLObjectVisitorAdapter {

        private final OWLAnnotationProperty prop;

        private final List<String> preferredLanguages;

        private OWLObject candidateValue = null;

        private int lastLangMatchIndex = Integer.MAX_VALUE;

        AnnotationLanguageFilter(final OWLAnnotationProperty prop,
                final List<String> preferredLanguages) {
            this.prop = prop;
            this.preferredLanguages = preferredLanguages;
        }

        public OWLObject getMatch() {
            return candidateValue;
        }

        @Override
        public void visit(final OWLAnnotationAssertionAxiom anno) {
            // a perfect match - no need to carry on search
            if (lastLangMatchIndex > 0 && anno.getProperty().equals(prop))
                anno.getValue().accept(this);
        }

        @Override
        public void visit(final OWLLiteral node) {
            if (preferredLanguages == null || preferredLanguages.isEmpty()) {
                lastLangMatchIndex = 0;
                candidateValue = node;
            } else {
                final int index = preferredLanguages.indexOf(node.getLang());
                if (index >= 0 && index < lastLangMatchIndex) {
                    lastLangMatchIndex = index;
                    candidateValue = node;
                }
            }
        }

        @Override
        public void visit(final IRI iri) {
            // No language
            candidateValue = iri;
        }
    }
} public class OntologyUtils {
    protected OntologyUtils() {
    };

    public static OWLOntology loadOntology(final FileDocumentSource source)
            throws OWLOntologyCreationException {

        final OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
        config.setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
        final OWLOntologyManager manager = OntologyManagerThatDoesNotLoadImports.create();
        final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(source, config);
        return ontology;
    }

    public static OWLOntology loadOntology(final String name, Class<?> klass)
            throws OWLOntologyCreationException {
        final FileDocumentSource source = new FileDocumentSource(new File(
                klass.getResource(name).getFile()));
        return OntologyUtils.loadOntology(source);
    }

    public static OWLOntology copyOntology(OWLOntology original)
            throws OWLOntologyCreationException {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(original.getOntologyID().getOntologyIRI());
        manager.addAxioms(ontology, original.getAxioms());
        List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(
                original.getAnnotations().size() + original.getImportsDeclarations().size() + 2);
        // annotations
        for (OWLAnnotation a : original.getAnnotations()) {
            changes.add(new AddOntologyAnnotation(ontology, a));
        }
        // imports
        for (OWLImportsDeclaration decl : original.getImportsDeclarations()) {
            changes.add(new AddImport(ontology, decl));
        }
        manager.applyChanges(changes);
        OWLOntologyManager originalManager = original.getOWLOntologyManager();
        manager.setOntologyFormat(ontology, originalManager.getOntologyFormat(original));
        return ontology;
    }
}
 public class TimeTracker extends LinkedHashMap<String, Interval> {
    private static final long serialVersionUID = 4253748581102583813L;
    private final int nanosecondsPerMillisecond = 1000000;
    private ThreadMXBean bean = ManagementFactory.getThreadMXBean();

    protected long getTimeInMilliseconds() {
        if (bean.isCurrentThreadCpuTimeSupported())
            return bean.getCurrentThreadCpuTime() / nanosecondsPerMillisecond;
        else
            return System.nanoTime() / nanosecondsPerMillisecond;
    }

    public void start(final String name) {
        put(name, new Interval(getTimeInMilliseconds()));
    }

    public void end(final String name) {
        get(name).setEnd(getTimeInMilliseconds());
    }

    public void outputTable(int width, PrintStream out) {
        // Heading
        for (final Entry<String, Interval> e : entrySet())
            out.print(Strings.padStart(e.getKey(), width, ' ') + " ");
        out.println();
        // Values
        for (final Entry<String, Interval> e : entrySet())
            out.print(Strings.padStart(e.getValue().toString(), width, ' ') + " ");
        out.println();
    }
}

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.semanticweb.owlapi.change.AxiomChangeData;
import org.semanticweb.owlapi.change.OWLOntologyChangeData;
import org.semanticweb.owlapi.io.FileDocumentSource;
import org.semanticweb.owlapi.io.OWLOntologyInputSourceException;
import org.semanticweb.owlapi.io.UnparsableOntologyException;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyFormat;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.util.ShortFormProvider;
import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider;
import org.semanticweb.owlapi.util.SimpleShortFormProvider;
import owl2vcs.analysis.ChangeClassifier;
import owl2vcs.analysis.EntityClassifier;
import owl2vcs.analysis.EntityCollector;
import owl2vcs.analysis.EntityCollectorException;
import owl2vcs.analysis.PrefixExtractor;
import owl2vcs.changeset.ChangeSet;
import owl2vcs.changeset.FullChangeSet;
import owl2vcs.render.ChangeFormat;
import owl2vcs.render.ChangeRenderer;
import owl2vcs.render.FullFormProvider;
import owl2vcs.render.FunctionalChangeRenderer;
import owl2vcs.render.IriFormat;
import owl2vcs.render.QNameMultiMapShortFormProvider;
import owl2vcs.render.QuotedAnnotationValueShortFormProvider;
import owl2vcs.utils.OntologyUtils;
import owl2vcs.utils.TimeTracker;
import com.google.common.collect.Iterables;
package owl2vcs.tools;





class DiffSettings {

    @Argument(required = true, index = 0, metaVar = "parent.owl", usage = "Parent version")
    public String parentFilename;
    @Argument(required = true, index = 1, metaVar = "child.owl", usage = "Child version")
    public String childFilename;
    @Option(name = "--prefixes", aliases = { "-p" }, required = false, usage = "Display used prefixes")
    public Boolean prefixes = false;
    @Option(name = "--entities", aliases = { "-e" }, required = false, usage = "Display changed entities")
    public Boolean entities = false;
    @Option(name = "--changes", aliases = { "-c" }, required = false, usage = "Display changes")
    public Boolean changes = false;
    @Option(name = "--format", aliases = { "-f" }, metaVar = "format", required = false, usage = "Format of statements: compact or indented")
    public ChangeFormat format = ChangeFormat.COMPACT;
    @Option(name = "--iriformat", aliases = { "-i" }, metaVar = "iriformat", required = false, usage = "Format of IRIs: simple, qname (default), full, label")
    public IriFormat iriFormat = IriFormat.QNAME;
    @Option(name = "--verbose", aliases = { "-v" }, required = false, usage = "Verbose output")
    public Boolean verbose = false;
    @Option(name = "--wait", aliases = { "-w" }, required = false, usage = "Do not exit, wait until user presses Enter")
    public Boolean wait = false;
    @Option(name = "--measure", aliases = { "-m" }, required = false, usage = "Measure time")
    public Boolean measure = false;
}

public final class Diff {

    /**
     * Binary compare two document sources.
     *
     * @param parentSource
     * @param childSource
     * @return true if files are identical, false otherwise
     * @throws IOException
     */
    public static boolean binaryCompareSources(
            final FileDocumentSource parentSource,
            final FileDocumentSource childSource) throws IOException {
        final Reader sr = parentSource.getReader();
        final Reader cr = childSource.getReader();
        while (true) {
            final int a = sr.read();
            final int b = cr.read();
            if (a != b)
                break;
            if (a == -1)
                return true;
        }
        return false;
    }

    private Diff() {
    };

    private static int showFilesDiff(final String parent, final String child,
            final DiffSettings settings) {
        try {
            System.err.println("diff " + parent + " " + child);
            if (parent.equals(child)) {
                System.err.println("Same file");
                return 0;
            }
            final TimeTracker t = new TimeTracker();
            final FileDocumentSource parentSource = new FileDocumentSource(
                    new File(parent));
            final FileDocumentSource childSource = new FileDocumentSource(
                    new File(child));
            // binary compare
            final Boolean areIdenticalSources = binaryCompareSources(
                    parentSource, childSource);
            if (areIdenticalSources) {
                System.err.println("Binary identical files");
                return 0;
            }
            // when no options provided, assume user wants raw changes
            if (!settings.changes && !settings.entities)
                settings.changes = true;

            t.start("total");
            t.start("load");
            final OWLOntology o1 = OntologyUtils.loadOntology(parentSource);
            final OWLOntology o2 = OntologyUtils.loadOntology(childSource);
            t.end("load");

            t.start("diff");
            final FullChangeSet cs = new FullChangeSet(o1, o2);
            t.end("diff");

            final Set<OWLEntity> entities = new HashSet<OWLEntity>();
            final Set<OWLEntity> newEntities = new HashSet<OWLEntity>();
            final Set<OWLEntity> removedEntities = new HashSet<OWLEntity>();
            final Set<OWLEntity> modifiedEntities = new HashSet<OWLEntity>();
            if (settings.prefixes || settings.entities) {
                t.start("ce");
                cs.accept(new EntityCollector(entities,
                        new HashSet<OWLAnonymousIndividual>()));
                t.end("ce");

            }
            final OWLOntologyFormat parentFormat = o1.getOWLOntologyManager()
                    .getOntologyFormat(o1);
            final OWLOntologyFormat childFormat = o2.getOWLOntologyManager()
                    .getOntologyFormat(o2);
            if (settings.entities) {
                t.start("+-*");
                new EntityClassifier(o1, o2, entities, newEntities,
                        removedEntities, modifiedEntities);
                t.end("+-*");
            }
            t.end("total");

            final ShortFormProvider provider = createShortFormProvider(
                    settings.iriFormat, o1, o2);
            final ChangeRenderer changeRenderer = new FunctionalChangeRenderer(