From 1375b09adf2fc2a7fc87d69ac30b60de8bbda83f Mon Sep 17 00:00:00 2001 From: patrycjamia Date: Wed, 23 Dec 2020 13:56:12 +0100 Subject: [PATCH] add 'equivalent to' type to the function Signed-off-by: patrycjamia --- .../weasel/ontology/data/OwlDataHandler.java | 34 +++++++++++++------ .../spec/fibo/weasel/utils/OwlUtils.java | 10 ++++-- web-app/config/ontology_config.xml | 3 +- 3 files changed, 33 insertions(+), 14 deletions(-) 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 63da02d0..ac9d69e2 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 @@ -60,6 +60,7 @@ import org.semanticweb.owlapi.model.OWLDataPropertyAxiom; import org.semanticweb.owlapi.model.OWLDatatype; import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLProperty; @@ -94,6 +95,8 @@ public class OwlDataHandler { private AppConfiguration config; @Autowired private ScopeIriOntology scopeIriOntology; + @Autowired + private RestrictionGraphDataHandler restrictionGraphDataHandler; private final Set unwantedEndOfLeafIri = new HashSet<>(); @@ -129,10 +132,9 @@ public OwlListDetails handleParticularClass(IRI iri, OWLOntology ontology) { List subclasses = getSubclasses(axioms); //List taxElements = extracttTaxonomyElements(subclasses); - List subclasses2 = getSubclasses(clazz, ontology); List taxElements2 = extracttTaxonomyElements(subclasses2); - + OwlDetailsProperties directSubclasses = handleDirectSubclasses(ontology, clazz); OwlDetailsProperties individuals = handleInstances(ontology, clazz); @@ -334,7 +336,7 @@ private OwlTaxonomyImpl extractTaxonomy(List subElements, IRI obj OwlTaxonomyImpl subCLassTax = extractTaxonomy(subTax, entity.getIRI(), ontology, type); String label = labelExtractor.getLabelOrDefaultFragment(objIri); - + OwlTaxonomyElementImpl taxEl = new OwlTaxonomyElementImpl(objIri.getIRIString(), label); if (subCLassTax.getValue().size() > 0) { @@ -723,8 +725,8 @@ private List getSuperElements(OWLEntity entity, OWLOntology ontol * This method is used to display SubClassOf * * @param ontology This is a loaded ontology. - * @param clazz Clazz are all properties of Inherited Axioms. - * @return properties of Inherited Axioms. + * @param clazz Clazz are all properties of direct Subclasses. + * @return Properties of direct Subclasses. */ public OwlDetailsProperties handleDirectSubclasses(OWLOntology ontology, OWLClass clazz) { OwlDetailsProperties result = new OwlDetailsProperties<>(); @@ -749,8 +751,8 @@ public OwlDetailsProperties handleDirectSubclasses(OWLOntology on * This method is used to display Particular Individual * * @param ontology This is a loaded ontology. - * @param clazz Clazz are all properties of Inherited Axioms. - * @return properties of Inherited Axioms. + * @param clazz Clazz are all Instances. + * @return All instances of a given class; */ private OwlDetailsProperties handleInstances(OWLOntology ontology, OWLClass clazz) { OwlDetailsProperties result = individualDataHandler.handleClassIndividuals(ontology, clazz); @@ -762,22 +764,34 @@ private OwlDetailsProperties handleInstances(OWLOntology ontology * This method is used to handle Inherited Axioms * * @param ontology Paramter which loaded ontology. - * @param clazz Class are all properties of Inherited Axioms. - * @return properties of Inherited Axioms. + * @param clazz Clazz are all properties of Inherited Axioms. + * @return Properties of Inherited Axioms. */ private OwlDetailsProperties handleInheritedAxioms(OWLOntology ontology, OWLClass clazz) { OwlDetailsProperties result = new OwlDetailsProperties<>(); String subClassOfKey = ViewerIdentifierFactory.createId(ViewerIdentifierFactory.Type.axiom, "SubClassOf"); + String equivalentClassKey = ViewerIdentifierFactory.createId(ViewerIdentifierFactory.Type.axiom, "EquivalentClasses"); + Set rset = owlUtils.getSuperClasses(clazz, ontology); rset.stream() .map((c) -> handleAxioms(c, ontology)) .forEachOrdered((handleAxioms) -> { + for (Map.Entry> entry : handleAxioms.getProperties().entrySet()) { - if (entry.getKey().equals(subClassOfKey)) { + if (entry.getKey().equals(subClassOfKey) || entry.getKey().equals(equivalentClassKey)) { for (PropertyValue propertyValue : entry.getValue()) { if (propertyValue.getType() != WeaselOwlType.TAXONOMY) { + + if (entry.getKey().equals(equivalentClassKey)) { + OwlAxiomPropertyValue opv = (OwlAxiomPropertyValue) propertyValue; + String val = opv.getValue(); + String[] values = val.split(" "); + values[0] = values[1] = ""; + val = String.join(" ", values); + opv.setValue(val); + } String key = ViewerIdentifierFactory.createId(ViewerIdentifierFactory.Type.function, WeaselOwlType.ANONYMOUS_ANCESTOR.name().toLowerCase()); result.addProperty(key, propertyValue); 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 83112024..76f92040 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 @@ -39,7 +39,13 @@ public final Boolean isRestriction(T axiom) { return isRestriction; } - + /** + * The method collects all subclasses of the given class, excluding direct classes. + * + * @param clazz Clazz are all SubClasses of given class. + * @param ontology This is a loaded ontology. + * @return All subclasses; + */ public Set getSuperClasses(OWLClass clazz, OWLOntology ontology) { Set result = new HashSet<>(); List subClasses = EntitySearcher.getSuperClasses(clazz, ontology).collect(Collectors.toList()); @@ -47,7 +53,7 @@ public Set getSuperClasses(OWLClass clazz, OWLOntology ontology) { LOG.debug("getSuperClasses -> subClass {}", subClass); Optional e = subClass.signature().findFirst(); LOG.debug("\tgetSuperClasses -> enity iri {}", e.get().getIRI()); - if (subClass.getClassExpressionType() == ClassExpressionType.OWL_CLASS) { + if (subClass.getClassExpressionType() == ClassExpressionType.OWL_CLASS) { result.add(e.get().asOWLClass()); result.addAll(getSuperClasses(e.get().asOWLClass(), ontology)); } diff --git a/web-app/config/ontology_config.xml b/web-app/config/ontology_config.xml index 3bd9ed30..d2b52d00 100644 --- a/web-app/config/ontology_config.xml +++ b/web-app/config/ontology_config.xml @@ -6,9 +6,8 @@ - https://spec.edmcouncil.org/fibo/ontology/MetadataFIBO/ - https://spec.edmcouncil.org/fibo/ontology/AboutFIBODev/ + https://spec.edmcouncil.org/fibo/ontology/AboutFIBODev/ ontologies staticOntologies fiboMapper