From: <lor...@us...> - 2012-12-25 13:19:20
|
Revision: 3881 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3881&view=rev Author: lorenz_b Date: 2012-12-25 13:19:09 +0000 (Tue, 25 Dec 2012) Log Message: ----------- Added equals+hashcode for literals. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/pom.xml 2012-12-25 13:19:09 UTC (rev 3881) @@ -169,6 +169,11 @@ <groupId>org.semanticweb.hermit</groupId> <artifactId>hermit</artifactId> </dependency> + + <dependency> + <groupId>eu.trowl</groupId> + <artifactId>trowl-core</artifactId> + </dependency> <dependency> <groupId>com.jamonapi</groupId> Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -22,6 +22,9 @@ import java.net.URI; import java.util.Map; +import org.semanticweb.owlapi.model.IRI; + + /** * @author Jens Lehmann * Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -120,6 +120,35 @@ String str = literal + datatype; String str2 = o.literal + ((TypedConstant)o).datatype; return str.compareTo(str2); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((datatype == null) ? 0 : datatype.hashCode()); + result = prime * result + ((getLiteral() == null) ? 0 : getLiteral().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TypedConstant other = (TypedConstant) obj; + if (datatype == null) { + if (other.datatype != null) + return false; + } else if (!datatype.equals(other.datatype)) + return false; + if(!getLiteral().equals(other.getLiteral())){ + return false; + } + return true; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -124,4 +124,36 @@ return str.compareTo(str2); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (hasLang ? 1231 : 1237); + result = prime * result + ((lang == null) ? 0 : lang.hashCode()); + result = prime * result + ((getLiteral() == null) ? 0 : getLiteral().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UntypedConstant other = (UntypedConstant) obj; + if (hasLang != other.hasLang) + return false; + if (lang == null) { + if (other.lang != null) + return false; + } else if (!lang.equals(other.lang)) + return false; + if(!getLiteral().equals(other.getLiteral())){ + return false; + } + return true; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -2,28 +2,22 @@ import java.io.UnsupportedEncodingException; import java.sql.SQLException; -import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.vocabulary.RDF; -import com.hp.hpl.jena.vocabulary.RDFS; public class ConciseBoundedDescriptionGeneratorImpl implements ConciseBoundedDescriptionGenerator{ private static final Logger logger = Logger.getLogger(ConciseBoundedDescriptionGeneratorImpl.class); - private static final int CHUNK_SIZE = 1000; + private int chunkSize = 0; private ExtractionDBCache cache; private SparqlEndpoint endpoint; @@ -37,6 +31,12 @@ this.cache = cache; } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, ExtractionDBCache cache, int maxRecursionDepth) { + this.endpoint = endpoint; + this.cache = cache; + this.maxRecursionDepth = maxRecursionDepth; + } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint) { this(endpoint, null); } @@ -53,8 +53,12 @@ return getModelChunked(resourceURI, depth); } + public void setChunkSize(int chunkSize) { + this.chunkSize = chunkSize; + } + private Model getModelChunked(String resource, int depth){ - String query = makeConstructQueryOptional(resource, CHUNK_SIZE, 0, depth); + String query = makeConstructQueryOptional(resource, chunkSize, 0, depth); Model all = ModelFactory.createDefaultModel(); try { Model model; @@ -65,9 +69,9 @@ } all.add(model); int i = 1; - while(model.size() != 0){ + do{ // while(model.size() == CHUNK_SIZE){ - query = makeConstructQueryOptional(resource, CHUNK_SIZE, i * CHUNK_SIZE, depth); + query = makeConstructQueryOptional(resource, chunkSize, i * chunkSize, depth); if(cache == null){ model = getModel(query); } else { @@ -75,7 +79,7 @@ } all.add(model); i++; - } + } while(chunkSize > 0 && model.size() != 0); } catch (UnsupportedEncodingException e) { logger.error(e); } catch (SQLException e) { @@ -124,8 +128,10 @@ sb.append("}"); } sb.append("}\n"); - sb.append("LIMIT ").append(limit).append("\n"); - sb.append("OFFSET ").append(offset); + if(chunkSize > 0){ + sb.append("LIMIT ").append(limit).append("\n"); + sb.append("OFFSET ").append(offset); + } return sb.toString(); } @@ -179,8 +185,8 @@ Logger.getRootLogger().setLevel(Level.DEBUG); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); cbdGen = new CachingConciseBoundedDescriptionGenerator(cbdGen); - cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); - Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 2); +// cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); + Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 3); System.out.println(cbd.size()); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -23,6 +23,7 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -99,7 +100,9 @@ import org.semanticweb.owlapi.model.UnknownOWLOntologyException; import org.semanticweb.owlapi.owllink.OWLlinkHTTPXMLReasonerFactory; import org.semanticweb.owlapi.owllink.OWLlinkReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.FreshEntitiesException; import org.semanticweb.owlapi.reasoner.FreshEntityPolicy; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.Node; @@ -107,8 +110,10 @@ import org.semanticweb.owlapi.reasoner.NullReasonerProgressMonitor; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; import org.semanticweb.owlapi.reasoner.ReasonerProgressMonitor; import org.semanticweb.owlapi.reasoner.SimpleConfiguration; +import org.semanticweb.owlapi.reasoner.TimeOutException; import org.semanticweb.owlapi.util.SimpleIRIMapper; import org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat; import org.springframework.beans.propertyeditors.StringTrimmerEditor; @@ -119,1103 +124,1000 @@ import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import de.tudresden.inf.lat.cel.owlapi.CelReasoner; +import eu.trowl.owlapi3.rel.reasoner.dl.RELReasonerFactory; /** - * Mapping to OWL API reasoner interface. The OWL API currently supports three - * reasoners: FaCT++, HermiT and Pellet. FaCT++ is connected using JNI and - * native libraries, while HermiT and Pellet are pure Java libraries. - * + * Mapping to OWL API reasoner interface. The OWL API currently + * supports three reasoners: FaCT++, HermiT and Pellet. FaCT++ is connected + * using JNI and native libraries, while HermiT and Pellet are pure Java + * libraries. + * * @author Jens Lehmann */ @ComponentAnn(name = "OWL API Reasoner", shortName = "oar", version = 0.8) public class OWLAPIReasoner extends AbstractReasonerComponent { - // private static Logger logger = Logger - // .getLogger(OWLAPIReasoner.class); +// private static Logger logger = Logger +// .getLogger(OWLAPIReasoner.class); - // private String reasonerType = "pellet"; - private OWLReasoner reasoner; - private OWLOntologyManager manager; + //private String reasonerType = "pellet"; + private OWLReasoner reasoner; + private OWLOntologyManager manager; - private OWLOntology ontology; - // the data factory is used to generate OWL API objects - private OWLDataFactory factory; - // static factory - // private static OWLDataFactory staticFactory = - // OWLManager.createOWLOntologyManager().getOWLDataFactory(); + private OWLOntology ontology; + // the data factory is used to generate OWL API objects + private OWLDataFactory factory; + // static factory +// private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); - private ConceptComparator conceptComparator = new ConceptComparator(); - private RoleComparator roleComparator = new RoleComparator(); - // private ClassHierarchy subsumptionHierarchy; - // private ObjectPropertyHierarchy roleHierarchy; - // private DatatypePropertyHierarchy datatypePropertyHierarchy; - // private Set<Description> allowedConceptsInSubsumptionHierarchy; + private ConceptComparator conceptComparator = new ConceptComparator(); + private RoleComparator roleComparator = new RoleComparator(); +// private ClassHierarchy subsumptionHierarchy; +// private ObjectPropertyHierarchy roleHierarchy; +// private DatatypePropertyHierarchy datatypePropertyHierarchy; +// private Set<Description> allowedConceptsInSubsumptionHierarchy; - // primitives - Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); - Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); - SortedSet<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> stringDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<Individual> individuals = new TreeSet<Individual>(); + // primitives + Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); + Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + SortedSet<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> stringDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<Individual> individuals = new TreeSet<Individual>(); - // namespaces - private Map<String, String> prefixes = new TreeMap<String, String>(); - private String baseURI; + // namespaces + private Map<String, String> prefixes = new TreeMap<String, String>(); + private String baseURI; - // references to OWL API ontologies - private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); - @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\", \"elk\", \"cel\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) - private String reasonerTypeString = "pellet"; - @ConfigOption(name = "owlLinkURL", description = "The URL to the owl server", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) - private String owlLinkURL; + // references to OWL API ontologies + private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); + @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\", \"elk\", \"cel\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String reasonerTypeString = "pellet"; + @ConfigOption(name = "owlLinkURL", description = "The URL to the owl server", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String owlLinkURL; - public OWLAPIReasoner() { - } + public OWLAPIReasoner() { - public OWLAPIReasoner(Set<KnowledgeSource> sources) { - super(sources); - } + } + + public OWLAPIReasoner(KnowledgeSource... sources) { + super(new HashSet<KnowledgeSource>(Arrays.asList(sources))); + } - public static String getName() { - return "OWL API reasoner"; - } + public OWLAPIReasoner(Set<KnowledgeSource> sources) { + super(sources); + } - @Override - public void init() throws ComponentInitException { - // reset variables (otherwise subsequent initialisation with - // different knowledge sources will merge both) - atomicConcepts = new TreeSet<NamedClass>(conceptComparator); - atomicRoles = new TreeSet<ObjectProperty>(roleComparator); - datatypeProperties = new TreeSet<DatatypeProperty>(); - booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - intDatatypeProperties = new TreeSet<DatatypeProperty>(); - stringDatatypeProperties = new TreeSet<DatatypeProperty>(); - individuals = new TreeSet<Individual>(); + public static String getName() { + return "OWL API reasoner"; + } - // create OWL API ontology manager - make sure we use a new data factory - // so that we don't default to the static one which can cause problems - // in a multi threaded environment. - manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + @Override + public void init() throws ComponentInitException { + // reset variables (otherwise subsequent initialisation with + // different knowledge sources will merge both) + atomicConcepts = new TreeSet<NamedClass>(conceptComparator); + atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + datatypeProperties = new TreeSet<DatatypeProperty>(); + booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + intDatatypeProperties = new TreeSet<DatatypeProperty>(); + stringDatatypeProperties = new TreeSet<DatatypeProperty>(); + individuals = new TreeSet<Individual>(); - // it is a bit cumbersome to obtain all classes, because there - // are no reasoner queries to obtain them => hence we query them - // for each ontology and add them to a set; a comparator avoids - // duplicates by checking URIs - Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { - public int compare(OWLNamedObject o1, OWLNamedObject o2) { - return o1.getIRI().compareTo(o2.getIRI()); - } - }; - Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); - Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>( - namedObjectComparator); - Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>( - namedObjectComparator); - Set<OWLNamedIndividual> owlIndividuals = new TreeSet<OWLNamedIndividual>( - namedObjectComparator); + // create OWL API ontology manager - make sure we use a new data factory so that we don't default to the static one which can cause problems in a multi threaded environment. + manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); - Set<OWLOntology> allImports = new HashSet<OWLOntology>(); - prefixes = new TreeMap<String, String>(); + // it is a bit cumbersome to obtain all classes, because there + // are no reasoner queries to obtain them => hence we query them + // for each ontology and add them to a set; a comparator avoids + // duplicates by checking URIs + Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { + public int compare(OWLNamedObject o1, OWLNamedObject o2) { + return o1.getIRI().compareTo(o2.getIRI()); + } + }; + Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); + Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>(namedObjectComparator); + Set<OWLNamedIndividual> owlIndividuals = new TreeSet<OWLNamedIndividual>(namedObjectComparator); - Set<OWLImportsDeclaration> directImports = new HashSet<OWLImportsDeclaration>(); + Set<OWLOntology> allImports = new HashSet<OWLOntology>(); + prefixes = new TreeMap<String, String>(); - for (KnowledgeSource source : sources) { + Set<OWLImportsDeclaration> directImports = new HashSet<OWLImportsDeclaration>(); - if (source instanceof OWLOntologyKnowledgeSource) { - ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); - owlAPIOntologies.add(ontology); - } else { - // This reasoner requires an ontology to process - throw new ComponentInitException( - "OWL API Reasoner Requires an OWLKnowledgeSource. Received a KS of type: " - + source.getClass().getName()); - } + for (KnowledgeSource source : sources) { - directImports.addAll(ontology.getImportsDeclarations()); + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + }else{ + //This reasoner requires an ontology to process + throw new ComponentInitException("OWL API Reasoner Requires an OWLKnowledgeSource. Received a KS of type: " + source.getClass().getName()); + } - try { - // imports includes the ontology itself - // FIXME this line throws the strange error - Set<OWLOntology> imports = manager.getImportsClosure(ontology); - allImports.addAll(imports); + directImports.addAll(ontology.getImportsDeclarations()); - // System.out.println(imports); - for (OWLOntology ont : imports) { - classes.addAll(ont.getClassesInSignature()); - owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); - owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); - owlIndividuals.addAll(ont.getIndividualsInSignature()); - } + try { + // imports includes the ontology itself + //FIXME this line throws the strange error + Set<OWLOntology> imports = manager.getImportsClosure(ontology); + allImports.addAll(imports); - } catch (UnknownOWLOntologyException uooe) { - logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); - } +// System.out.println(imports); + for (OWLOntology ont : imports) { + classes.addAll(ont.getClassesInSignature()); + owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); + owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); + owlIndividuals.addAll(ont.getIndividualsInSignature()); + } - // if several knowledge sources are included, then we can only - // guarantee that the base URI is from one of those sources (there - // can't be more than one); but we will take care that all prefixes - // are - // correctly imported - OWLOntologyFormat format = manager.getOntologyFormat(ontology); - if (format instanceof PrefixOWLOntologyFormat) { - prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); - baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); - prefixes.remove(""); - } + } catch (UnknownOWLOntologyException uooe) { + logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); + } - } + // if several knowledge sources are included, then we can only + // guarantee that the base URI is from one of those sources (there + // can't be more than one); but we will take care that all prefixes are + // correctly imported + OWLOntologyFormat format = manager.getOntologyFormat(ontology); + if (format instanceof PrefixOWLOntologyFormat) { + prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); + baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); + prefixes.remove(""); + } - // Now merge all of the knowledge sources into one ontology instance. - try { - // The following line illustrates a problem with using different - // OWLOntologyManagers. This can manifest itself if we have multiple - // sources who were created with different manager instances. - // ontology = - // OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner/all"), - // new HashSet<OWLOntology>(owlAPIOntologies)); - ontology = manager.createOntology(IRI.create("http://dl-learner/all"), - new HashSet<OWLOntology>(owlAPIOntologies)); - // we have to add all import declarations manually here, because - // this are no axioms - List<OWLOntologyChange> addImports = new ArrayList<OWLOntologyChange>(); - for (OWLImportsDeclaration i : directImports) { - addImports.add(new AddImport(ontology, i)); - } - manager.applyChanges(addImports); - } catch (OWLOntologyCreationException e1) { - e1.printStackTrace(); - } + } - // configure reasoner - ReasonerProgressMonitor progressMonitor = new NullReasonerProgressMonitor(); - FreshEntityPolicy freshEntityPolicy = FreshEntityPolicy.ALLOW; - long timeOut = Integer.MAX_VALUE; - IndividualNodeSetPolicy individualNodeSetPolicy = IndividualNodeSetPolicy.BY_NAME; - OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor, freshEntityPolicy, - timeOut, individualNodeSetPolicy); + //Now merge all of the knowledge sources into one ontology instance. + try { + //The following line illustrates a problem with using different OWLOntologyManagers. This can manifest itself if we have multiple sources who were created with different manager instances. + //ontology = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); + ontology = manager.createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); + //we have to add all import declarations manually here, because this are no axioms + List<OWLOntologyChange> addImports = new ArrayList<OWLOntologyChange>(); + for (OWLImportsDeclaration i : directImports) { + addImports.add(new AddImport(ontology, i)); + } + manager.applyChanges(addImports); + } catch (OWLOntologyCreationException e1) { + e1.printStackTrace(); + } - // create actual reasoner - if (getReasonerTypeString().equals("fact")) { - try { - reasoner = new FaCTPlusPlusReasonerFactory().createNonBufferingReasoner(ontology, - conf); + //configure reasoner + ReasonerProgressMonitor progressMonitor = new NullReasonerProgressMonitor(); + FreshEntityPolicy freshEntityPolicy = FreshEntityPolicy.ALLOW; + long timeOut = Integer.MAX_VALUE; + IndividualNodeSetPolicy individualNodeSetPolicy = IndividualNodeSetPolicy.BY_NAME; + OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor, freshEntityPolicy, timeOut, individualNodeSetPolicy); - } catch (Exception e) { - throw new RuntimeException(e); - } - System.out.println("Using FaCT++."); - } else if (getReasonerTypeString().equals("hermit")) { - // instantiate HermiT reasoner - reasoner = new ReasonerFactory().createNonBufferingReasoner(ontology, conf); - } else if (getReasonerTypeString().equals("pellet")) { - // instantiate Pellet reasoner - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology, - conf); - // change log level to WARN for Pellet, because otherwise log - // output will be very large - Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); - pelletLogger.setLevel(Level.WARN); - } else if (getReasonerTypeString().equals("elk")) { - // instantiate ELK reasoner - reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology, conf); - // reasoner = new - // MyElkReasonerFactory().createNonBufferingReasoner(ontology, - // conf); - } else if (getReasonerTypeString().equals("cel")) { - // instantiate CEL reasoner - reasoner = new CelReasoner(ontology, conf); - } else { - try { - OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); - URL url = new URL(getOwlLinkURL());// Configure the server - // end-point - OWLlinkReasonerConfiguration config = new OWLlinkReasonerConfiguration(url); - reasoner = factory.createNonBufferingReasoner(ontology, config); - System.out.println(reasoner.getReasonerName()); - } catch (Exception e) { - // e.printStackTrace(); - throw new ComponentInitException(e); - } - } + // create actual reasoner + if (getReasonerTypeString().equals("fact")) { + try { + reasoner = new FaCTPlusPlusReasonerFactory().createNonBufferingReasoner(ontology, conf); + } catch (Exception e) { + throw new RuntimeException(e); + } + System.out.println("Using FaCT++."); + } else if (getReasonerTypeString().equals("hermit")) { + // instantiate HermiT reasoner + reasoner = new ReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("pellet")) { + // instantiate Pellet reasoner + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology, conf); + // change log level to WARN for Pellet, because otherwise log + // output will be very large + Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); + pelletLogger.setLevel(Level.WARN); + } else if (getReasonerTypeString().equals("elk")) { + // instantiate ELK reasoner + reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("cel")) { + // instantiate CEL reasoner + reasoner = new CelReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("trowl")) { + // instantiate TrOWL reasoner + reasoner = new RELReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else { + try { + OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); + URL url = new URL(getOwlLinkURL());//Configure the server end-point + OWLlinkReasonerConfiguration config = new OWLlinkReasonerConfiguration(url); + reasoner = factory.createNonBufferingReasoner(ontology, config); + System.out.println(reasoner.getReasonerName()); + } catch (Exception e) { +// e.printStackTrace(); + throw new ComponentInitException(e); + } + } - /* - * Set<OWLOntology> importsClosure = - * manager.getImportsClosure(ontology); - * System.out.println("imports closure : " + importsClosure); try { - * reasoner.loadOntologies(importsClosure); } catch - * (OWLReasonerException e1) { // TODO Auto-generated catch block - * e1.printStackTrace(); } - */ + /* + Set<OWLOntology> importsClosure = manager.getImportsClosure(ontology); + System.out.println("imports closure : " + importsClosure); + try { + reasoner.loadOntologies(importsClosure); + } catch (OWLReasonerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ - // System.out.println(classes); - // System.out.println(properties); - // System.out.println(individuals); +// System.out.println(classes); +// System.out.println(properties); +// System.out.println(individuals); - // compute class hierarchy and types of individuals - // (done here to speed up later reasoner calls) - boolean inconsistentOntology = !reasoner.isConsistent(); + // compute class hierarchy and types of individuals + // (done here to speed up later reasoner calls) + boolean inconsistentOntology = !reasoner.isConsistent(); - if (!inconsistentOntology) { - reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY, - InferenceType.CLASS_ASSERTIONS); - } else { - throw new ComponentInitException("Inconsistent ontologies."); - } + if (!inconsistentOntology) { + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY, InferenceType.CLASS_ASSERTIONS); + } else { + throw new ComponentInitException("Inconsistent ontologies."); + } - factory = manager.getOWLDataFactory(); + factory = manager.getOWLDataFactory(); - // try { - // if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) - // System.out.println("DEFINED."); - // else - // System.out.println("NOT DEFINED."); - // } catch (OWLReasonerException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } +// try { +// if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) +// System.out.println("DEFINED."); +// else +// System.out.println("NOT DEFINED."); +// } catch (OWLReasonerException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } - // read in primitives - for (OWLClass owlClass : classes) - atomicConcepts.add(new NamedClass(owlClass.toStringID())); - for (OWLObjectProperty owlProperty : owlObjectProperties) - atomicRoles.add(new ObjectProperty(owlProperty.toStringID())); - for (OWLDataProperty owlProperty : owlDatatypeProperties) { - DatatypeProperty dtp = new DatatypeProperty(owlProperty.toStringID()); - Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); - Iterator<OWLDataRange> it = ranges.iterator(); - if (it.hasNext()) { - OWLDataRange range = it.next(); - if (range.isDatatype()) { - URI uri = ((OWLDatatype) range).getIRI().toURI(); - if (uri.equals(OWL2Datatype.BOOLEAN.getURI())) - booleanDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.DOUBLE.getURI())) - doubleDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.INT.getURI())) - intDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.STRING.getURI())) - stringDatatypeProperties.add(dtp); - } - } else { - stringDatatypeProperties.add(dtp); - } - datatypeProperties.add(dtp); - } - for (OWLNamedIndividual owlIndividual : owlIndividuals) { - individuals.add(new Individual(owlIndividual.toStringID())); - } + // read in primitives + for (OWLClass owlClass : classes) + atomicConcepts.add(new NamedClass(owlClass.toStringID())); + for (OWLObjectProperty owlProperty : owlObjectProperties) + atomicRoles.add(new ObjectProperty(owlProperty.toStringID())); + for (OWLDataProperty owlProperty : owlDatatypeProperties) { + DatatypeProperty dtp = new DatatypeProperty(owlProperty.toStringID()); + Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); + Iterator<OWLDataRange> it = ranges.iterator(); + if (it.hasNext()) { + OWLDataRange range = it.next(); + if (range.isDatatype()) { + URI uri = ((OWLDatatype) range).getIRI().toURI(); + if (uri.equals(OWL2Datatype.BOOLEAN.getURI())) booleanDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.DOUBLE.getURI())) doubleDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.INT.getURI())) intDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.STRING.getURI())) stringDatatypeProperties.add(dtp); + } + } else { + stringDatatypeProperties.add(dtp); + } + datatypeProperties.add(dtp); + } + for (OWLNamedIndividual owlIndividual : owlIndividuals) { + individuals.add(new Individual(owlIndividual.toStringID())); + } - // remove top and bottom properties (for backwards compatibility) - // atomicRoles.remove(new - // ObjectProperty("http://www.w3.org/2002/07/owl#bottomObjectProperty")); - // atomicRoles.remove(new - // ObjectProperty("http://www.w3.org/2002/07/owl#topObjectProperty")); - } + // remove top and bottom properties (for backwards compatibility) +// atomicRoles.remove(new ObjectProperty("http://www.w3.org/2002/07/owl#bottomObjectProperty")); +// atomicRoles.remove(new ObjectProperty("http://www.w3.org/2002/07/owl#topObjectProperty")); + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getAtomicConcepts() - */ - public Set<NamedClass> getNamedClasses() { - return Collections.unmodifiableSet(atomicConcepts); - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicConcepts() + */ + public Set<NamedClass> getNamedClasses() { + return Collections.unmodifiableSet(atomicConcepts); + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getAtomicRoles() - */ - public Set<ObjectProperty> getObjectProperties() { - return Collections.unmodifiableSet(atomicRoles); - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicRoles() + */ + public Set<ObjectProperty> getObjectProperties() { + return Collections.unmodifiableSet(atomicRoles); + } - @Override - public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { - return datatypeProperties; - } + @Override + public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { + return datatypeProperties; + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getIndividuals() - */ - public SortedSet<Individual> getIndividuals() { - return individuals; - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getIndividuals() + */ + public SortedSet<Individual> getIndividuals() { + return individuals; + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getReasonerType() - */ - @Override - public ReasonerType getReasonerType() { - if (getReasonerTypeString().equals("fact")) { - return ReasonerType.OWLAPI_FACT; - } else if (getReasonerTypeString().equals("hermit")) { - return ReasonerType.OWLAPI_HERMIT; - } else { - return ReasonerType.OWLAPI_PELLET; - } - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getReasonerType() + */ + @Override + public ReasonerType getReasonerType() { + if (getReasonerTypeString().equals("fact")) { + return ReasonerType.OWLAPI_FACT; + } else if (getReasonerTypeString().equals("hermit")) { + return ReasonerType.OWLAPI_HERMIT; + } else { + return ReasonerType.OWLAPI_PELLET; + } + } - // @Override - // public ObjectPropertyHierarchy prepareRoleHierarchy() { - // // code copied from DIG reasoner - // - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (ObjectProperty role : atomicRoles) { - // roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); - // roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); - // } - // - // roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, - // roleHierarchyDown); - // return roleHierarchy; - // } +// @Override +// public ObjectPropertyHierarchy prepareRoleHierarchy() { +// // code copied from DIG reasoner +// +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (ObjectProperty role : atomicRoles) { +// roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); +// roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); +// } +// +// roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, +// roleHierarchyDown); +// return roleHierarchy; +// } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) - */ - // public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { - // // code copied from DIG reasoner - // - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (ObjectProperty role : atomicRoles) { - // roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); - // roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); - // } - // - // roleHierarchy = new ObjectPropertyHierarchy(allowedRoles, - // roleHierarchyUp, - // roleHierarchyDown); - // } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) + */ +// public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { +// // code copied from DIG reasoner +// +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (ObjectProperty role : atomicRoles) { +// roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); +// roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); +// } +// +// roleHierarchy = new ObjectPropertyHierarchy(allowedRoles, roleHierarchyUp, +// roleHierarchyDown); +// } - // @Override - // public ObjectPropertyHierarchy getRoleHierarchy() { - // return roleHierarchy; - // } +// @Override +// public ObjectPropertyHierarchy getRoleHierarchy() { +// return roleHierarchy; +// } - // public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> - // allowedRoles) { - // // code copied from DIG reasoner - // - // TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> - // datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, - // TreeSet<DatatypeProperty>>( - // roleComparator); - // TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> - // datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, - // TreeSet<DatatypeProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (DatatypeProperty role : datatypeProperties) { - // datatypePropertyHierarchyDown.put(role, - // getMoreSpecialDatatypePropertiesImpl(role)); - // datatypePropertyHierarchyUp.put(role, - // getMoreGeneralDatatypePropertiesImpl(role)); - // } - // - // datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, - // datatypePropertyHierarchyUp, - // datatypePropertyHierarchyDown); - // } +// public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { +// // code copied from DIG reasoner +// +// TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( +// roleComparator); +// TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (DatatypeProperty role : datatypeProperties) { +// datatypePropertyHierarchyDown.put(role, getMoreSpecialDatatypePropertiesImpl(role)); +// datatypePropertyHierarchyUp.put(role, getMoreGeneralDatatypePropertiesImpl(role)); +// } +// +// datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, datatypePropertyHierarchyUp, +// datatypePropertyHierarchyDown); +// } - // @Override - // public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - // return datatypePropertyHierarchy; - // } +// @Override +// public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { +// return datatypePropertyHierarchy; +// } - @Override - public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) { - return reasoner.isEntailed(factory.getOWLSubClassOfAxiom( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(subConcept), - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(superConcept))); - } + @Override + public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) { + return reasoner.isEntailed(factory.getOWLSubClassOfAxiom(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(subConcept), OWLAPIDescriptionConvertVisitor.getOWLClassExpression(superConcept))); + } - @Override - protected boolean isEquivalentClassImpl(Description class1, Description class2) { - return reasoner.isEntailed(factory.getOWLEquivalentClassesAxiom( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class1), - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class2))); - } + @Override + protected boolean isEquivalentClassImpl(Description class1, Description class2) { + return reasoner.isEntailed(factory.getOWLEquivalentClassesAxiom(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class1), OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class2))); + } - @Override - protected TreeSet<Description> getSuperClassesImpl(Description concept) { - NodeSet<OWLClass> classes = null; + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { + NodeSet<OWLClass> classes = null; - classes = reasoner.getSuperClasses( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); + classes = reasoner.getSuperClasses(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); - return getFirstClasses(classes); - } + return getFirstClasses(classes); + } - @Override - protected TreeSet<Description> getSubClassesImpl(Description concept) { - NodeSet<OWLClass> classes = null; + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { + NodeSet<OWLClass> classes = null; - classes = reasoner.getSubClasses( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); + classes = reasoner.getSubClasses(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); - return getFirstClasses(classes); - } + return getFirstClasses(classes); + } - @Override - protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { - NodeSet<OWLObjectPropertyExpression> properties = null; + @Override + protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { + NodeSet<OWLObjectPropertyExpression> properties = null; - try { - properties = reasoner.getSuperObjectProperties( - OWLAPIConverter.getOWLAPIObjectProperty(role), true); - return getFirstObjectProperties(properties); - } catch (Exception e) { - TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); - return roles; - } - } + properties = reasoner.getSuperObjectProperties(OWLAPIConverter.getOWLAPIObjectProperty(role), true); - @Override - protected TreeSet<ObjectProperty> getSubPropertiesImpl(ObjectProperty role) { - NodeSet<OWLObjectPropertyExpression> properties = null; + return getFirstObjectProperties(properties); + } - try { - properties = reasoner.getSubObjectProperties( - OWLAPIConverter.getOWLAPIObjectProperty(role), true); - return getFirstObjectProperties(properties); - } catch (Exception e) { - TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); - return roles; - } + @Override + protected TreeSet<ObjectProperty> getSubPropertiesImpl(ObjectProperty role) { + NodeSet<OWLObjectPropertyExpression> properties = null; - } + properties = reasoner.getSubObjectProperties(OWLAPIConverter.getOWLAPIObjectProperty(role), true); - @Override - protected TreeSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) { - NodeSet<OWLDataProperty> properties = null; + return getFirstObjectProperties(properties); + } - properties = reasoner.getSuperDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), - true); + @Override + protected TreeSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) { + NodeSet<OWLDataProperty> properties = null; - return getFirstDatatypeProperties(properties); - } + properties = reasoner.getSuperDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), true); - @Override - protected TreeSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) { - NodeSet<OWLDataProperty> properties = null; + return getFirstDatatypeProperties(properties); + } - properties = reasoner.getSubDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), - true); + @Override + protected TreeSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) { + NodeSet<OWLDataProperty> properties = null; - return getFirstDatatypeProperties(properties); - } + properties = reasoner.getSubDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), true); - @Override - public boolean hasTypeImpl(Description concept, Individual individual) { - boolean test = false; - OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); - OWLNamedIndividual i = factory.getOWLNamedIndividual(IRI.create(individual.getName())); -// try { -// test = reasoner.isEntailed(factory.getOWLClassAssertionAxiom(d, i)); -// } catch (Exception e) { -// test = true; -// } - if(d.isAnonymous()){ - throw new UnsupportedOperationException("Can not do type checking for complex class expressions."); - } - for(OWLClass type : reasoner.getTypes(i, false).getFlattened()){ - if(type.equals(d.asOWLClass())){ - return true; - } - } - return test; - } + return getFirstDatatypeProperties(properties); + } - @Override - public SortedSet<Individual> getIndividualsImpl(Description concept) { - // OWLDescription d = getOWLAPIDescription(concept); - OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); - Set<OWLNamedIndividual> individuals = reasoner.getInstances(d, false).getFlattened(); - SortedSet<Individual> inds = new TreeSet<Individual>(); - for (OWLNamedIndividual ind : individuals) - // ugly code - if (ind != null) - inds.add(new Individual(ind.toStringID())); - return inds; - } + @Override + public boolean hasTypeImpl(Description concept, Individual individual) { + OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); + OWLIndividual i = factory.getOWLNamedIndividual(IRI.create(individual.getName())); + if(concept instanceof Thing) return true; + if(concept instanceof NamedClass && ((NamedClass)concept).getName().contains("Error"))return false; + return reasoner.isEntailed(factory.getOWLClassAssertionAxiom(d, i)); + } - @Override - public Set<NamedClass> getTypesImpl(Individual individual) { - Set<Node<OWLClass>> result = null; + @Override + public SortedSet<Individual> getIndividualsImpl(Description concept) { +// OWLDescription d = getOWLAPIDescription(concept); + OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); + Set<OWLNamedIndividual> individuals = reasoner.getInstances(d, false).getFlattened(); + SortedSet<Individual> inds = new TreeSet<Individual>(); + for (OWLNamedIndividual ind : individuals) + //ugly code + if (ind != null) inds.add(new Individual(ind.toStringID())); + return inds; + } - result = reasoner.getTypes(factory.getOWLNamedIndividual(IRI.create(individual.getName())), - false).getNodes(); + @Override + public Set<NamedClass> getTypesImpl(Individual individual) { + Set<Node<OWLClass>> result = null; - return getFirstClassesNoTopBottom(result); - } + result = reasoner.getTypes(factory.getOWLNamedIndividual(IRI.create(individual.getName())), false).getNodes(); - @Override - public boolean isSatisfiableImpl() { - return reasoner.isSatisfiable(factory.getOWLThing()); - } + return getFirstClassesNoTopBottom(result); + } - @Override - public Description getDomainImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + @Override + public boolean isSatisfiableImpl() { + return reasoner.isSatisfiable(factory.getOWLThing()); + } - // Pellet returns a set of nodes of named classes, which are more - // general than the actual domain/range - NodeSet<OWLClass> set; + @Override + public Description getDomainImpl(ObjectProperty objectProperty) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + + // Pellet returns a set of nodes of named classes, which are more + // general than the actual domain/range + NodeSet<OWLClass> set; try { set = reasoner.getObjectPropertyDomains(prop, false); return getDescriptionFromReturnedDomain(set); - } catch (Exception e) { - return getDescriptionFromReturnedDomain(null); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (FreshEntitiesException e) { + e.printStackTrace(); + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch(de.tudresden.inf.lat.cel.owlapi.UnsupportedReasonerOperationInCelException e){ + e.printStackTrace(); } - } + return Thing.instance; - @Override - public Description getDomainImpl(DatatypeProperty datatypeProperty) { - OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); + } - NodeSet<OWLClass> set = reasoner.getDataPropertyDomains(prop, true); - return getDescriptionFromReturnedDomain(set); + @Override + public Description getDomainImpl(DatatypeProperty datatypeProperty) { + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); - } + NodeSet<OWLClass> set = reasoner.getDataPropertyDomains(prop, true); + return getDescriptionFromReturnedDomain(set); - @Override - public Description getRangeImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + } - NodeSet<OWLClass> set; + @Override + public Description getRangeImpl(ObjectProperty objectProperty) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + + NodeSet<OWLClass> set; try { set = reasoner.getObjectPropertyRanges(prop, true); - if (set.isEmpty()) - return new Thing(); - OWLClass oc = set.iterator().next().getRepresentativeElement(); - if (oc.isOWLThing()) { - return Thing.instance; - } - return new NamedClass(oc.toStringID()); - } catch (Exception e) { - return Thing.instance; + if (set.isEmpty()) return new Thing(); + OWLClass oc = set.iterator().next().getRepresentativeElement(); + if (oc.isOWLThing()) { + return Thing.instance; + } + return new NamedClass(oc.toStringID()); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (FreshEntitiesException e) { + e.printStackTrace(); + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch(de.tudresden.inf.lat.cel.owlapi.UnsupportedReasonerOperationInCelException e){ + e.printStackTrace(); } - } + return Thing.instance; - private Description getDescriptionFromReturnedDomain(NodeSet<OWLClass> set) { - if (set.isEmpty()) - return new Thing(); + } - Set<OWLClassExpression> union = new HashSet<OWLClassExpression>(); - Set<OWLClassExpression> domains = new HashSet<OWLClassExpression>(); + private Description getDescriptionFromReturnedDomain(NodeSet<OWLClass> set) { + if (set.isEmpty()) return new Thing(); - for (Node<OWLClass> descs : set) { - for (OWLClassExpression desc : descs) { - union.add(desc); - } - } - for (OWLClassExpression desc : union) { - boolean isSuperClass = false; - for (Description d : getClassHierarchy().getSubClasses( - OWLAPIConverter.convertClass(desc.asOWLClass()))) { - if (union.contains(OWLAPIConverter.getOWLAPIDescription(d))) { - isSuperClass = true; - break; - } - } - if (!isSuperClass) { - domains.add(desc); - } - } + Set<OWLClassExpression> union = new HashSet<OWLClassExpression>(); + Set<OWLClassExpression> domains = new HashSet<OWLClassExpression>(); - OWLClass oc = (OWLClass) domains.iterator().next(); - if (oc.isOWLThing()) { - return new Thing(); - } else { - return new NamedClass(oc.toStringID()); - } - } + for (Node<OWLClass> descs : set) { + for (OWLClassExpression desc : descs) { + union.add(desc); + } + } + for (OWLClassExpression desc : union) { + boolean isSuperClass = false; + for (Description d : getClassHierarchy().getSubClasses(OWLAPIConverter.convertClass(desc.asOWLClass()))) { + if (union.contains(OWLAPIConverter.getOWLAPIDescription(d))) { + isSuperClass = true; + break; + } + } + if (!isSuperClass) { + domains.add(desc); + } + } - @Override - public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole); - Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); - for (Individual i : individuals) { - OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(i.getName())); + OWLClass oc = (OWLClass) domains.iterator().next(); + if (oc.isOWLThing()) { + return new Thing(); + } else { + return new NamedClass(oc.toStringID()); + } + } - // get all related individuals via OWL API - Set<OWLNamedIndividual> inds; - try { - inds = reasoner.getObjectPropertyValues(ind, prop).getFlattened(); - } catch (Exception e) { - inds = null; - } + @Override + public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole); + Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); + for (Individual i : individuals) { + OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(i.getName())); - // convert data back to DL-Learner structures - SortedSet<Individual> is = new TreeSet<Individual>(); - try { - for (OWLNamedIndividual oi : inds) - is.add(new Individual(oi.toStringID())); - map.put(i, is); - } catch (Exception e) { - map = null; - } - } - return map; - } + // get all related individuals via OWL API + Set<OWLNamedIndividual> inds = reasoner.getObjectPropertyValues(ind, prop).getFlattened(); - @Override - protected Map<ObjectProperty, Set<Individual>> getObjectPropertyRelationshipsImpl( - Individual individual) { - OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(individual.getName())); - Map<OWLObjectPropertyExpression, Set<OWLNamedIndividual>> mapAPI = new HashMap<OWLObjectPropertyExpression, Set<OWLNamedIndividual>>(); + // convert data back to DL-Learner structures + SortedSet<Individual> is = new TreeSet<Individual>(); + for (OWLNamedIndividual oi : inds) + ... [truncated message content] |