All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticweb.HermiT.hierarchy.HierarchyDumperFSS Maven / Gradle / Ivy

Go to download

HermiT is reasoner for ontologies written using the Web Ontology Language (OWL). Given an OWL file, HermiT can determine whether or not the ontology is consistent, identify subsumption relationships between classes, and much more. This is the maven build of HermiT and is designed for people who wish to use HermiT from within the OWL API. It is now versioned in the main HermiT version repository, although not officially supported by the HermiT developers. The version number of this package is a composite of the HermiT version and an value representing releases of this packaged version. So, 1.3.7.1 is the first release of the mavenized version of HermiT based on the 1.3.7 release of HermiT. This package includes the Jautomata library (http://jautomata.sourceforge.net/), and builds with it directly. This library appears to be no longer under active development, and so a "fork" seems appropriate. No development is intended or anticipated on this code base.

There is a newer version: 1.3.8.4
Show newest version
/* Copyright 2008, 2009, 2010 by the Oxford University Computing Laboratory

   This file is part of HermiT.

   HermiT is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   HermiT 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 Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with HermiT.  If not, see .
*/
package org.semanticweb.HermiT.hierarchy;

import java.io.PrintWriter;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

import org.semanticweb.HermiT.model.AtomicConcept;
import org.semanticweb.HermiT.model.AtomicRole;
import org.semanticweb.HermiT.model.InverseRole;
import org.semanticweb.HermiT.model.Role;

public class HierarchyDumperFSS {
    protected final PrintWriter m_out;

    public HierarchyDumperFSS(PrintWriter out) {
        m_out=out;
    }
    public void printAtomicConceptHierarchy(Hierarchy atomicConceptHierarchy) {
        for (HierarchyNode node : atomicConceptHierarchy.getAllNodesSet()) {
            SortedSet equivs=new TreeSet(AtomicConceptComparator.INSTANCE);
            equivs.addAll(node.getEquivalentElements());
            AtomicConcept representative=equivs.first();
            if (equivs.size()>1) {
                boolean first=true;
                for (AtomicConcept equiv : equivs) {
                    if (first) {
                        m_out.print("EquivalentClasses( <");
                        m_out.print(representative.getIRI());
                        m_out.print(">");
                        first=false;
                    }
                    else {
                        m_out.print(" <");
                        m_out.print(equiv.getIRI());
                        m_out.print(">");
                    }
                }
                m_out.print(" )");
                m_out.println();
            }
            if (!representative.equals(AtomicConcept.THING)) {
                for (HierarchyNode sub : node.getChildNodes()) {
                    AtomicConcept subRepresentative=sub.getRepresentative();
                    if (!subRepresentative.equals(AtomicConcept.NOTHING)) {
                        m_out.print("SubClassOf( <");
                        m_out.print(subRepresentative.getIRI());
                        m_out.print("> <");
                        m_out.print(representative.getIRI());
                        m_out.print("> )");
                        m_out.println();
                    }
                }
            }
        }
        m_out.println();
    }
    public void printObjectPropertyHierarchy(Hierarchy objectRoleHierarchy) {
        for (HierarchyNode node : objectRoleHierarchy.getAllNodesSet()) {
            SortedSet equivs=new TreeSet(ObjectRoleComparator.INSTANCE);
            equivs.addAll(node.getEquivalentElements());
            Role representative=equivs.first();
            if (equivs.size()>1) {
                boolean first=true;
                for (Role equiv : equivs) {
                    if (first) {
                        m_out.print("EquivalentObjectProperties( ");
                        print(representative);
                        first=false;
                    }
                    else {
                        m_out.print(" ");
                        print(equiv);
                    }
                }
                m_out.print(" )");
                m_out.println();
            }
            if (!representative.equals(AtomicRole.TOP_OBJECT_ROLE)) {
                for (HierarchyNode sub : node.getChildNodes()) {
                    Role subRepresentative=sub.getRepresentative();
                    if (!subRepresentative.equals(AtomicRole.BOTTOM_OBJECT_ROLE)) {
                        m_out.print("SubObjectPropertyOf( ");
                        print(subRepresentative);
                        m_out.print(" ");
                        print(representative);
                        m_out.print(" )");
                        m_out.println();
                    }
                }
            }
        }
        m_out.println();
    }
    public void printDataPropertyHierarchy(Hierarchy dataRoleHierarchy) {
        for (HierarchyNode node : dataRoleHierarchy.getAllNodesSet()) {
            SortedSet equivs=new TreeSet(DataRoleComparator.INSTANCE);
            equivs.addAll(node.getEquivalentElements());
            AtomicRole representative=equivs.first();
            if (equivs.size()>1) {
                boolean first=true;
                for (AtomicRole equiv : equivs) {
                    if (first) {
                        m_out.print("EquivalentDataProperties( <");
                        m_out.print(representative.getIRI());
                        m_out.print(">");
                        first=false;
                    }
                    else {
                        m_out.print(" >");
                        m_out.print(equiv.getIRI());
                        m_out.print(">");
                    }
                }
                m_out.print(" )");
                m_out.println();
            }
            if (!representative.equals(AtomicRole.TOP_DATA_ROLE)) {
                for (HierarchyNode sub : node.getChildNodes()) {
                    AtomicRole subRepresentative=sub.getRepresentative();
                    if (!subRepresentative.equals(AtomicRole.BOTTOM_DATA_ROLE)) {
                        m_out.print("SubDataPropertyOf( <");
                        m_out.print(subRepresentative.getIRI());
                        m_out.print("> <");
                        m_out.print(representative.getIRI());
                        m_out.print("> )");
                        m_out.println();
                    }
                }
            }
        }
        m_out.println();
    }
    protected void print(Role role) {
        if (role instanceof AtomicRole)
            print((AtomicRole)role);
        else {
            m_out.print("ObjectInverseOf( ");
            print(((InverseRole)role).getInverseOf());
            m_out.print(" )");
        }
    }
    protected void print(AtomicRole atomicRole) {
        m_out.print("<");
        m_out.print(atomicRole.getIRI());
        m_out.print(">");
    }

    protected static class AtomicConceptComparator implements Comparator {
        public static final AtomicConceptComparator INSTANCE=new AtomicConceptComparator();

        public int compare(AtomicConcept atomicConcept1,AtomicConcept atomicConcept2) {
            int comparison=getAtomicConceptClass(atomicConcept1)-getAtomicConceptClass(atomicConcept2);
            if (comparison!=0)
                return comparison;
            return atomicConcept1.getIRI().compareTo(atomicConcept2.getIRI());
        }
        protected int getAtomicConceptClass(AtomicConcept atomicConcept) {
            if (AtomicConcept.NOTHING.equals(atomicConcept))
                return 0;
            else if (AtomicConcept.THING.equals(atomicConcept))
                return 1;
            else
                return 2;
        }
    }

    protected static class ObjectRoleComparator implements Comparator {
        public static final ObjectRoleComparator INSTANCE=new ObjectRoleComparator();

        public int compare(Role role1,Role role2) {
            int comparison=getRoleClass(role1)-getRoleClass(role2);
            if (comparison!=0)
                return comparison;
            comparison=getRoleDirection(role1)-getRoleDirection(role2);
            if (comparison!=0)
                return comparison;
            return getInnerAtomicRole(role1).getIRI().compareTo(getInnerAtomicRole(role2).getIRI());
        }
        protected int getRoleClass(Role role) {
            if (AtomicRole.BOTTOM_OBJECT_ROLE.equals(role))
                return 0;
            else if (AtomicRole.TOP_OBJECT_ROLE.equals(role))
                return 1;
            else
                return 2;
        }
        protected AtomicRole getInnerAtomicRole(Role role) {
            if (role instanceof AtomicRole)
                return (AtomicRole)role;
            else
                return ((InverseRole)role).getInverseOf();
        }
        protected int getRoleDirection(Role role) {
            return role instanceof AtomicRole ? 0 : 1;
        }
    }

    protected static class DataRoleComparator implements Comparator {
        public static final DataRoleComparator INSTANCE=new DataRoleComparator();

        public int compare(AtomicRole atomicRole1,AtomicRole atomicRole2) {
            int comparison=getAtomicRoleClass(atomicRole1)-getAtomicRoleClass(atomicRole2);
            if (comparison!=0)
                return comparison;
            return atomicRole1.getIRI().compareTo(atomicRole2.getIRI());
        }
        protected int getAtomicRoleClass(AtomicRole atomicRole) {
            if (AtomicRole.BOTTOM_DATA_ROLE.equals(atomicRole))
                return 0;
            else if (AtomicRole.TOP_DATA_ROLE.equals(atomicRole))
                return 1;
            else
                return 2;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy