diff --git a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/model/property/OwlAxiomPropertyEntity.java b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/model/property/OwlAxiomPropertyEntity.java index 70a16682..57ba6f39 100644 --- a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/model/property/OwlAxiomPropertyEntity.java +++ b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/model/property/OwlAxiomPropertyEntity.java @@ -24,4 +24,11 @@ public void setLabel(String label) { this.label = label; } + @Override + public String toString() { + return "OwlAxiomPropertyEntity{" + "iri=" + iri + ", label=" + label + '}'; + } + + + } diff --git a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/data/OwlDataHandler.java b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/data/OwlDataHandler.java index 3d41d546..63da02d0 100644 --- a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/data/OwlDataHandler.java +++ b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/data/OwlDataHandler.java @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -50,9 +51,11 @@ import org.edmcouncil.spec.fibo.weasel.utils.StringUtils; import org.edmcouncil.spec.fibo.weasel.utils.UrlChecker; import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.ClassExpressionType; import org.semanticweb.owlapi.model.OWLAnnotationAxiom; import org.semanticweb.owlapi.model.OWLAnnotationProperty; import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.model.OWLDataProperty; import org.semanticweb.owlapi.model.OWLDataPropertyAxiom; import org.semanticweb.owlapi.model.OWLDatatype; @@ -63,6 +66,7 @@ import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; import org.semanticweb.owlapi.search.EntitySearcher; import org.springframework.stereotype.Component; +import org.w3c.dom.Entity; /** * @author MichaƂ Daniel (michal.daniel@makolab.com) @@ -123,8 +127,12 @@ public OwlListDetails handleParticularClass(IRI iri, OWLOntology ontology) { OwlDetailsProperties axioms = handleAxioms(clazz, ontology); List subclasses = getSubclasses(axioms); - List taxElements = extracttTaxonomyElements(subclasses); + //List taxElements = extracttTaxonomyElements(subclasses); + + List subclasses2 = getSubclasses(clazz, ontology); + List taxElements2 = extracttTaxonomyElements(subclasses2); + OwlDetailsProperties directSubclasses = handleDirectSubclasses(ontology, clazz); OwlDetailsProperties individuals = handleInstances(ontology, clazz); @@ -137,7 +145,7 @@ public OwlListDetails handleParticularClass(IRI iri, OWLOntology ontology) { subclasses = filterSubclasses(subclasses); - OwlTaxonomyImpl tax = extractTaxonomy(taxElements, iri, ontology, WeaselOwlType.AXIOM_CLASS); + OwlTaxonomyImpl tax = extractTaxonomy(taxElements2, iri, ontology, WeaselOwlType.AXIOM_CLASS); tax.sort(); OwlDetailsProperties annotations @@ -163,6 +171,38 @@ private List getSubclasses(OwlDetailsProperties ax return subclasses; } + private List getSubclasses(OWLClass clazz, OWLOntology ontology) { + LOG.debug("getSubclasses -> clazz {}", clazz.toString()); + List subClasses = EntitySearcher.getSuperClasses(clazz, ontology).collect(Collectors.toList()); + + List result = new LinkedList<>(); + for (OWLClassExpression subClass : subClasses) { + LOG.debug("\tgetSubclasses -> subClass {}", subClass); + Optional e = subClass.signature().findFirst(); + LOG.debug("\tgetSubclasses -> enity iri {}", e.get().getIRI()); + + if (subClass.getClassExpressionType() != ClassExpressionType.OWL_CLASS) { + continue; + } + + IRI entityIri = e.get().getIRI(); + if (entityIri.equals(clazz.getIRI())) { + continue; + } + OwlAxiomPropertyValue opv = new OwlAxiomPropertyValue(); + opv.setType(WeaselOwlType.TAXONOMY); + String key = StringUtils.getFragment(entityIri); + opv.setValue(key); + + OwlAxiomPropertyEntity propertyEntity = new OwlAxiomPropertyEntity(); + propertyEntity.setIri(entityIri.toString()); + propertyEntity.setLabel(labelExtractor.getLabelOrDefaultFragment(entityIri)); + opv.addEntityValues(key, propertyEntity); + result.add(opv); + } + return result; + } + private List extracttTaxonomyElements(List subclasses) { List taxElements = subclasses .stream() @@ -281,12 +321,12 @@ private OwlTaxonomyImpl extractTaxonomy(List subElements, IRI obj OwlAxiomPropertyValue axiomProperty = (OwlAxiomPropertyValue) property; LOG.debug("Axiom Property {}", axiomProperty.toString()); IRI sci = extractSubElementIri(axiomProperty, objIri); - if (sci == null) { - continue; - } + LOG.debug("extractSubElementIri: {}", extractSubElementIri(axiomProperty, objIri)); OWLEntity entity = createEntity(ontology, sci, type); + LOG.debug("createEntity: {}", createEntity(ontology, sci, type)); + LOG.trace("\t{} Sub Element Of {}", StringUtils.getFragment(objIri), StringUtils.getFragment(entity.getIRI())); List subTax = getSuperElements(entity, ontology, type); @@ -294,9 +334,7 @@ private OwlTaxonomyImpl extractTaxonomy(List subElements, IRI obj OwlTaxonomyImpl subCLassTax = extractTaxonomy(subTax, entity.getIRI(), ontology, type); String label = labelExtractor.getLabelOrDefaultFragment(objIri); - //OwlTaxonomyValue val1 = new OwlTaxonomyValue(WeaselOwlType.STRING, label); - - // OwlTaxonomyValue val2 = new OwlTaxonomyValue(WeaselOwlType.IRI, objIri.getIRIString()); + OwlTaxonomyElementImpl taxEl = new OwlTaxonomyElementImpl(objIri.getIRIString(), label); if (subCLassTax.getValue().size() > 0) { @@ -313,17 +351,12 @@ private OwlTaxonomyImpl extractTaxonomy(List subElements, IRI obj LOG.trace("\t\tEnd leaf on {}", StringUtils.getFragment(objIri)); String label = labelExtractor.getLabelOrDefaultFragment(objIri); - OwlTaxonomyValue val1 = new OwlTaxonomyValue(WeaselOwlType.STRING, label); - OwlTaxonomyValue val2 = new OwlTaxonomyValue(WeaselOwlType.IRI, objIri.getIRIString()); + OwlTaxonomyElementImpl taxEl = new OwlTaxonomyElementImpl(objIri.getIRIString(), label); List currentTax = new LinkedList<>(); if (!unwantedEndOfLeafIri.contains(objIri.toString())) { - OwlTaxonomyValue valThingLabel = null; - OwlTaxonomyValue valThingIri = null; - OwlTaxonomyElementImpl taxElThing = null; - switch (type) { case AXIOM_CLASS: label = labelExtractor.getLabelOrDefaultFragment(IRI.create("http://www.w3.org/2002/07/owl#Thing")); @@ -371,7 +404,7 @@ private OWLEntity createEntity(OWLOntology ontology, IRI sci, WeaselOwlType type private IRI extractSubElementIri(OwlAxiomPropertyValue axiomProperty, IRI objIri) { LOG.debug("Axiom Property SubElementIri {}", axiomProperty.toString()); - LOG.debug("Axiom Property entityMaping {}", axiomProperty.getEntityMaping()); + LOG.debug("extractSubElementIri -> obj {}", objIri); for (Map.Entry entry : axiomProperty.getEntityMaping().entrySet()) { LOG.debug("Axiom Property entry element {}", entry.toString()); if (!entry.getValue().getIri().equals(objIri.getIRIString())) { @@ -554,6 +587,7 @@ private void parseUrl(String probablyUrl, String[] splited, int j) { private void parseToIri(String probablyUrl, OwlAxiomPropertyValue opv, String key, String[] splited, int j, String generatedKey) { OwlAxiomPropertyEntity axiomPropertyEntity = new OwlAxiomPropertyEntity(); axiomPropertyEntity.setIri(probablyUrl); + LOG.debug("Probably URL {}", probablyUrl); String label = labelExtractor.getLabelOrDefaultFragment(IRI.create(probablyUrl)); axiomPropertyEntity.setLabel(label); opv.addEntityValues(key, axiomPropertyEntity); @@ -649,7 +683,7 @@ private List getSuperElements(OWLEntity entity, OWLOntology ontol OWLProperty prop = null; switch (type) { case AXIOM_CLASS: - return getSuperClasses(ontology, AxiomType.SUBCLASS_OF, entity); + return getSubclasses(entity.asOWLClass(), ontology); case AXIOM_DATA_PROPERTY: prop = entity.asOWLDataProperty(); propertyStream = EntitySearcher.getSuperProperties(prop, ontology); @@ -685,42 +719,6 @@ private List getSuperElements(OWLEntity entity, OWLOntology ontol return resultProperties; } - private List getSuperClasses(OWLOntology ontology, AxiomType subType, OWLEntity entity) { - List result = new LinkedList<>(); - ontology.axioms(subType) - .collect(Collectors.toList()) - .stream() - .filter((subClasse) - -> (subClasse.getSuperClass() instanceof OWLClass - && subClasse.getSubClass() instanceof OWLClass)) - .forEachOrdered((subClasse) -> { - - OWLClass superClazz = (OWLClass) subClasse.getSuperClass(); - OWLClass subClazz = (OWLClass) subClasse.getSubClass(); - if (subClazz.getIRI().equals(entity.getIRI())) { - IRI subClazzIri = subClazz.getIRI(); - IRI superClazzIri = superClazz.getIRI(); - - OwlAxiomPropertyValue pv = new OwlAxiomPropertyValue(); - pv.setType(WeaselOwlType.TAXONOMY); - OwlAxiomPropertyEntity entitySubClass = new OwlAxiomPropertyEntity(); - OwlAxiomPropertyEntity entitySuperClass = new OwlAxiomPropertyEntity(); - entitySubClass.setIri(subClazzIri.getIRIString()); - entitySubClass.setLabel(labelExtractor.getLabelOrDefaultFragment(subClazzIri)); - entitySuperClass.setIri(superClazzIri.getIRIString()); - entitySuperClass.setLabel(labelExtractor.getLabelOrDefaultFragment(superClazzIri)); - - pv.setType(WeaselOwlType.TAXONOMY); - pv.addEntityValues(StringUtils.getFragment(subClazzIri), entitySubClass); - pv.addEntityValues(StringUtils.getFragment(superClazzIri), entitySuperClass); - - pv.setValue(rendering.render(subClasse)); - result.add(pv); - } - }); - return result; - } - /** * This method is used to display SubClassOf * @@ -788,7 +786,6 @@ private OwlDetailsProperties handleInheritedAxioms(OWLOntology on } } }); - result.sortPropertiesInAlphabeticalOrder(); return result; } diff --git a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/scope/ScopeIriOntology.java b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/scope/ScopeIriOntology.java index a8249d23..997a8989 100644 --- a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/scope/ScopeIriOntology.java +++ b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/ontology/scope/ScopeIriOntology.java @@ -85,7 +85,7 @@ public Set getScopeIri(OWLOntology ontology) { public Boolean scopeIri(String uri) { for (String scope : scopes) { - LOG.debug("Contains: {} -> {}", uri, scope); + // LOG.debug("Contains: {} -> {}", uri, scope); if (uri.contains(scope.toString())) { return Boolean.TRUE; } diff --git a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/utils/OwlUtils.java b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/utils/OwlUtils.java index 55e8203a..83112024 100644 --- a/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/utils/OwlUtils.java +++ b/viewer-core/src/main/java/org/edmcouncil/spec/fibo/weasel/utils/OwlUtils.java @@ -1,13 +1,21 @@ package org.edmcouncil.spec.fibo.weasel.utils; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.edmcouncil.spec.fibo.weasel.ontology.data.OwlDataHandler; import org.edmcouncil.spec.fibo.weasel.ontology.visitor.OntologyVisitors; import org.semanticweb.owlapi.model.ClassExpressionType; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.search.EntitySearcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -18,6 +26,8 @@ @Component public class OwlUtils { + private static final Logger LOG = LoggerFactory.getLogger(OwlDataHandler.class); + @Autowired private OntologyVisitors ontologyVisitors; @@ -29,22 +39,22 @@ public final Boolean isRestriction(T axiom) { return isRestriction; } + public Set getSuperClasses(OWLClass clazz, OWLOntology ontology) { Set result = new HashSet<>(); - - ontology.subClassAxiomsForSubClass(clazz) - .collect(Collectors.toSet()) - .stream() - .filter((axiom) -> (axiom.getSubClass().getClassExpressionType() == ClassExpressionType.OWL_CLASS - && axiom.getSuperClass().getClassExpressionType() == ClassExpressionType.OWL_CLASS)).forEachOrdered((axiom) -> { - OWLClass owlClass = axiom.getSuperClass().asOWLClass(); - if (axiom.getSubClass().equals(clazz)) { - result.add(owlClass); - result.addAll(getSuperClasses(owlClass, ontology)); + List subClasses = EntitySearcher.getSuperClasses(clazz, ontology).collect(Collectors.toList()); + for (OWLClassExpression subClass : subClasses) { + LOG.debug("getSuperClasses -> subClass {}", subClass); + Optional e = subClass.signature().findFirst(); + LOG.debug("\tgetSuperClasses -> enity iri {}", e.get().getIRI()); + if (subClass.getClassExpressionType() == ClassExpressionType.OWL_CLASS) { + result.add(e.get().asOWLClass()); + result.addAll(getSuperClasses(e.get().asOWLClass(), ontology)); } - }); + } return result; + } } diff --git a/web-app/config/ontology_config.xml b/web-app/config/ontology_config.xml index 8b6841f6..3bd9ed30 100644 --- a/web-app/config/ontology_config.xml +++ b/web-app/config/ontology_config.xml @@ -5,9 +5,10 @@ - https://spec.edmcouncil.org/fibo/ontology/AboutFIBODev/ + + https://spec.edmcouncil.org/fibo/ontology/MetadataFIBO/ - + https://spec.edmcouncil.org/fibo/ontology/AboutFIBODev/ ontologies staticOntologies fiboMapper diff --git a/web-app/fiboMapper/catalog-v001.xml b/web-app/fiboMapper/catalog-v001.xml new file mode 100644 index 00000000..5cbe3cf2 --- /dev/null +++ b/web-app/fiboMapper/catalog-v001.xml @@ -0,0 +1,4 @@ + + + +