From 3c7f995ed3075e1d3dafc474276a28496d711504 Mon Sep 17 00:00:00 2001 From: Paul Cuddihy Date: Thu, 11 Nov 2021 12:34:56 -0500 Subject: [PATCH] Re-fixed the bug fix for loading ontologies from multiple graphs --- .../semtk/ontologyTools/OntologyInfo.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/OntologyInfo.java b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/OntologyInfo.java index 92f213e9c..050aaf9e8 100644 --- a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/OntologyInfo.java +++ b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/OntologyInfo.java @@ -231,7 +231,15 @@ public void addClass(OntologyClass oClass) throws Exception { throw new Exception("Internal error: class already exists in ontology. Cannot re-add it: " + classnameStr); } this.classHash.put(classnameStr, oClass); + this.updateSuperSubClassHash(oClass); + } + + /** + * Needs to be called any time new superclasses are added. + * @param oClass + */ + private void updateSuperSubClassHash(OntologyClass oClass) { // store info on the related subclasses ArrayList superClassNames = oClass.getParentNameStrings(false); // get the parents. there may be more than one. // spin through the list and find the ones that need to be added. @@ -248,6 +256,7 @@ public void addClass(OntologyClass oClass) throws Exception { } } } + public boolean hasSubclass(String className) { return this.subclassHash.get(className) != null; } @@ -1145,28 +1154,23 @@ public void loadSuperSubProperties(String subPropNames[], String superPropNames[ } } - /** - * process the results of the query to get all of the sub- and super-class query and loads - * them into the OntologyInfo object. - * - * for unknown historical reasons, the subclass is added along with names of superclasses - * but the superclasses are added later. - * - **/ - public void loadSuperSubClasses(String subList[], String superList[]) throws Exception{ + + public void loadSuperSubClasses(String subList[], String superList[]) throws Exception{ + for (int i=0; i < subList.length; i++) { - String subClassUri = subList[i]; - String superClassUri = superList[i]; - - // create subclass if it is missing - if (!this.containsClass(subClassUri)) { - OntologyClass subClass = new OntologyClass(subClassUri, null); - this.addClass(subClass); + + // check for the existence of the current class. + // (loading multiple graphs or a class with multiple superclasses) + if(!this.containsClass(subList[i])){ + OntologyClass c = new OntologyClass(subList[i], null); + this.addClass(c); } - // get the subclass and add the parent. - this.getClass(subClassUri).addParentName(superClassUri); + // get the current class and add the parent. + OntologyClass c = this.getClass(subList[i]); + c.addParentName(superList[i]); + this.updateSuperSubClassHash(c); } }