org.semanticweb.HermiT.hierarchy.HierarchyDumperFSS Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.semanticweb.hermit Show documentation
Show all versions of org.semanticweb.hermit Show documentation
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 a value representing the OWLAPI release it is compatible with. Note that the group id for the upstream HermiT is com.hermit-reasoner, while this fork is released under net.sourceforge.owlapi.
This fork exists to allow HermiT users to use newer OWLAPI versions than the ones supported by the original HermiT codebase.
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.
The 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.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;
/**HierarchyDumperFSS.*/
public class HierarchyDumperFSS {
protected final PrintWriter m_out;
/**
* @param out out
*/
public HierarchyDumperFSS(PrintWriter out) {
m_out=out;
}
/**
* @param atomicConceptHierarchy atomicConceptHierarchy
*/
public void printAtomicConceptHierarchy(Hierarchy atomicConceptHierarchy) {
for (HierarchyNode node : atomicConceptHierarchy.getAllNodesSet()) {
SortedSet equivs=new TreeSet<>(HierarchyDumperFSS::atomicConceptCompare);
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();
}
/**
* @param objectRoleHierarchy objectRoleHierarchy
*/
public void printObjectPropertyHierarchy(Hierarchy objectRoleHierarchy) {
for (HierarchyNode node : objectRoleHierarchy.getAllNodesSet()) {
SortedSet equivs=new TreeSet<>(HierarchyDumperFSS::objectRoleCompare);
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();
}
/**
* @param dataRoleHierarchy dataRoleHierarchy
*/
public void printDataPropertyHierarchy(Hierarchy dataRoleHierarchy) {
for (HierarchyNode node : dataRoleHierarchy.getAllNodesSet()) {
SortedSet equivs=new TreeSet<>(HierarchyDumperFSS::dataRoleCompare);
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 int atomicConceptCompare(AtomicConcept atomicConcept1,AtomicConcept atomicConcept2) {
int comparison=getAtomicConceptClass(atomicConcept1)-getAtomicConceptClass(atomicConcept2);
if (comparison!=0)
return comparison;
return atomicConcept1.getIRI().compareTo(atomicConcept2.getIRI());
}
protected static int getAtomicConceptClass(AtomicConcept atomicConcept) {
if (AtomicConcept.NOTHING.equals(atomicConcept))
return 0;
else if (AtomicConcept.THING.equals(atomicConcept))
return 1;
else
return 2;
}
protected static int objectRoleCompare(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 static 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 static AtomicRole getInnerAtomicRole(Role role) {
if (role instanceof AtomicRole)
return (AtomicRole)role;
else
return ((InverseRole)role).getInverseOf();
}
protected static int getRoleDirection(Role role) {
return role instanceof AtomicRole ? 0 : 1;
}
protected static int dataRoleCompare(AtomicRole atomicRole1,AtomicRole atomicRole2) {
int comparison=getAtomicRoleClass(atomicRole1)-getAtomicRoleClass(atomicRole2);
if (comparison!=0)
return comparison;
return atomicRole1.getIRI().compareTo(atomicRole2.getIRI());
}
protected static 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;
}
}