From 866cc3a4ed2a4aee45e638bbb636bf688d196d5e Mon Sep 17 00:00:00 2001 From: johardi Date: Sat, 7 May 2016 13:16:26 -0700 Subject: [PATCH] Closes #13 --- .../ontograf/common/ProtegeGraphModel.java | 170 +++++++++--------- 1 file changed, 88 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/protege/ontograf/common/ProtegeGraphModel.java b/src/main/java/org/protege/ontograf/common/ProtegeGraphModel.java index 65fad33..175a166 100644 --- a/src/main/java/org/protege/ontograf/common/ProtegeGraphModel.java +++ b/src/main/java/org/protege/ontograf/common/ProtegeGraphModel.java @@ -75,7 +75,7 @@ public class ProtegeGraphModel extends DefaultGraphModel { /** current set of arc types available */ private Collection arcTypes; - private OWLOntology owlOntology; + private Set owlOntologies; private OWLModelManager owlModelManager; private OWLEditorKit owlEditorKit; @@ -86,7 +86,7 @@ public ProtegeGraphModel(OWLEditorKit owlEditorKit) { owlModelManager = owlEditorKit.getModelManager(); this.owlEditorKit = owlEditorKit; - owlOntology = owlModelManager.getActiveOntology(); + owlOntologies = owlModelManager.getActiveOntologies(); frameToArcCount = new HashMap>(); } @@ -337,28 +337,30 @@ private void unreifyRelationInstances() { artifactToUnreifiedRels = new HashMap>(); - for(OWLNamedIndividual individual : owlOntology.getIndividualsInSignature()) { - for (Entry> entry : EntitySearcher - .getObjectPropertyValues(individual, owlOntology).asMap() - .entrySet()) { - for(OWLIndividual refIndividual : entry.getValue()) { - GraphArc arc = createArc(individual, (OWLNamedIndividual)refIndividual, owlModelManager.getRendering(entry.getKey())); - - Set outgoingUnreifiedRels = artifactToUnreifiedRels.get(individual); - if (outgoingUnreifiedRels == null) { - outgoingUnreifiedRels = new HashSet(); - artifactToUnreifiedRels.put(individual, outgoingUnreifiedRels); - } - outgoingUnreifiedRels.add(arc); - - Set incomingUnreifiedRels = artifactToUnreifiedRels.get(refIndividual); - if (incomingUnreifiedRels == null) { - incomingUnreifiedRels = new HashSet(); - artifactToUnreifiedRels.put((OWLNamedIndividual)refIndividual, incomingUnreifiedRels); - } - incomingUnreifiedRels.add(arc); - } - } + for (OWLOntology owlOntology : owlOntologies) { + for(OWLNamedIndividual individual : owlOntology.getIndividualsInSignature()) { + for (Entry> entry : EntitySearcher + .getObjectPropertyValues(individual, owlOntology).asMap() + .entrySet()) { + for(OWLIndividual refIndividual : entry.getValue()) { + GraphArc arc = createArc(individual, (OWLNamedIndividual)refIndividual, owlModelManager.getRendering(entry.getKey())); + + Set outgoingUnreifiedRels = artifactToUnreifiedRels.get(individual); + if (outgoingUnreifiedRels == null) { + outgoingUnreifiedRels = new HashSet(); + artifactToUnreifiedRels.put(individual, outgoingUnreifiedRels); + } + outgoingUnreifiedRels.add(arc); + + Set incomingUnreifiedRels = artifactToUnreifiedRels.get(refIndividual); + if (incomingUnreifiedRels == null) { + incomingUnreifiedRels = new HashSet(); + artifactToUnreifiedRels.put((OWLNamedIndividual)refIndividual, incomingUnreifiedRels); + } + incomingUnreifiedRels.add(arc); + } + } + } } } @@ -374,7 +376,7 @@ private Set findIncomingIndividualRelationships(OWLEntity entityOfInte OWLNamedIndividual destIndiv = (OWLNamedIndividual) entityOfInterest; for (OWLClassExpression refNode : EntitySearcher.getTypes(destIndiv, - owlOntology)) { + owlOntologies)) { if(refNode instanceof OWLClass) { OWLClass clsOwner = (OWLClass)refNode; if (isDisplayableNode(clsOwner, mustBeVisible)) { @@ -395,40 +397,42 @@ private Set findIncomingConditionsRelationships(OWLEntity entityOfInte return arcs; } - OWLClass owlClass = (OWLClass) entityOfInterest; - Collection axioms = EntitySearcher.getReferencingAxioms( - owlClass, owlOntology); - for(OWLAxiom axiom : axioms) { - if(axiom.getAxiomType().equals(AxiomType.SUBCLASS_OF)) { - OWLSubClassOfAxiom subClassAxiom = (OWLSubClassOfAxiom)axiom; - OWLClassExpression subClassExpression = subClassAxiom.getSubClass(); - - if(subClassExpression instanceof OWLClass) { - OWLClassExpression superClassExpression = subClassAxiom.getSuperClass(); - if(superClassExpression instanceof OWLQuantifiedRestriction) { - OWLQuantifiedRestriction restriction = (OWLQuantifiedRestriction)superClassExpression; - if(restriction.getFiller() instanceof OWLClass) { - String relType = owlModelManager.getRendering(restriction.getProperty()); - if(restriction instanceof OWLObjectSomeValuesFrom) { - relType += SUB_CLASS_SOME_VALUE_OF; - } else { - relType += SUB_CLASS_ALL_VALUES; - } - - if(!filterManager.isArcTypeVisible(relType)) { - continue; - } - - OWLEntity source = (OWLClass)subClassExpression; - OWLEntity target = (OWLClass)restriction.getFiller(); - - if(isDisplayableNode(source, mustBeVisible) && isDisplayableNode(target, mustBeVisible)) { - arcs.add(createArc(source, target, relType)); - } - } - } - } - } + for (OWLOntology owlOntology : owlOntologies) { + OWLClass owlClass = (OWLClass) entityOfInterest; + Collection axioms = EntitySearcher.getReferencingAxioms( + owlClass, owlOntology, true); + for(OWLAxiom axiom : axioms) { + if(axiom.getAxiomType().equals(AxiomType.SUBCLASS_OF)) { + OWLSubClassOfAxiom subClassAxiom = (OWLSubClassOfAxiom)axiom; + OWLClassExpression subClassExpression = subClassAxiom.getSubClass(); + + if(subClassExpression instanceof OWLClass) { + OWLClassExpression superClassExpression = subClassAxiom.getSuperClass(); + if(superClassExpression instanceof OWLQuantifiedRestriction) { + OWLQuantifiedRestriction restriction = (OWLQuantifiedRestriction)superClassExpression; + if(restriction.getFiller() instanceof OWLClass) { + String relType = owlModelManager.getRendering(restriction.getProperty()); + if(restriction instanceof OWLObjectSomeValuesFrom) { + relType += SUB_CLASS_SOME_VALUE_OF; + } else { + relType += SUB_CLASS_ALL_VALUES; + } + + if(!filterManager.isArcTypeVisible(relType)) { + continue; + } + + OWLEntity source = (OWLClass)subClassExpression; + OWLEntity target = (OWLClass)restriction.getFiller(); + + if(isDisplayableNode(source, mustBeVisible) && isDisplayableNode(target, mustBeVisible)) { + arcs.add(createArc(source, target, relType)); + } + } + } + } + } + } } return arcs; @@ -444,13 +448,13 @@ private Set findOutgoingConditionsRelationships(OWLEntity entityOfInte OWLClass owlClass = (OWLClass) entityOfInterest; convertOWLClassExpressionsToArcs(owlClass, - EntitySearcher.getSuperClasses(owlClass, owlOntology), arcs, + EntitySearcher.getSuperClasses(owlClass, owlOntologies), arcs, null, mustBeVisible); OWLIconProviderImpl iconProvider = new OWLIconProviderImpl(owlModelManager); Icon icon = iconProvider.getIcon(owlClass); convertOWLClassExpressionsToArcs(owlClass, - EntitySearcher.getEquivalentClasses(owlClass, owlOntology), + EntitySearcher.getEquivalentClasses(owlClass, owlOntologies), arcs, icon, mustBeVisible); return arcs; @@ -577,7 +581,7 @@ private Set findOutgoingIndividualRelationships(OWLEntity entityOfInte OWLClass owlClass = (OWLClass) entityOfInterest; for (OWLIndividual individual : EntitySearcher.getIndividuals(owlClass, - owlOntology)) { + owlOntologies)) { if(individual instanceof OWLNamedIndividual) { OWLNamedIndividual namedIndividual = (OWLNamedIndividual)individual; if(isDisplayableNode(namedIndividual, mustBeVisible)) { @@ -622,26 +626,28 @@ private void createDomainRangeRels(Set domains, Set ranges private void createDomainRangeRels() { domainRangeRelsBuffer = new HashSet(); - Set properties = owlOntology.getObjectPropertiesInSignature(); - - for(OWLObjectProperty property : properties) { - for(OWLObjectProperty owlObjectProperty : property.getObjectPropertiesInSignature()) { - Collection domainVals = EntitySearcher - .getDomains(owlObjectProperty, owlOntology); - Collection rangeVals = EntitySearcher - .getRanges(owlObjectProperty, owlOntology); - - if (domainVals.isEmpty() && !rangeVals.isEmpty()) { - domainVals.add(owlModelManager.getOWLEntityFinder().getOWLClass("Thing")); - } else if (rangeVals.isEmpty() && !domainVals.isEmpty()) { - rangeVals.add(owlModelManager.getOWLEntityFinder().getOWLClass("Thing")); - } - - Set domains = getOWLClasses(domainVals); - Set ranges = getOWLClasses(rangeVals); - - createDomainRangeRels(domains, ranges, owlObjectProperty); - } + for (OWLOntology owlOntology : owlOntologies) { + Set properties = owlOntology.getObjectPropertiesInSignature(); + + for(OWLObjectProperty property : properties) { + for(OWLObjectProperty owlObjectProperty : property.getObjectPropertiesInSignature()) { + Collection domainVals = EntitySearcher + .getDomains(owlObjectProperty, owlOntology); + Collection rangeVals = EntitySearcher + .getRanges(owlObjectProperty, owlOntology); + + if (domainVals.isEmpty() && !rangeVals.isEmpty()) { + domainVals.add(owlModelManager.getOWLEntityFinder().getOWLClass("Thing")); + } else if (rangeVals.isEmpty() && !domainVals.isEmpty()) { + rangeVals.add(owlModelManager.getOWLEntityFinder().getOWLClass("Thing")); + } + + Set domains = getOWLClasses(domainVals); + Set ranges = getOWLClasses(rangeVals); + + createDomainRangeRels(domains, ranges, owlObjectProperty); + } + } } }