Skip to content

Commit

Permalink
Fix bug in loading connection with multiple model graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Nov 11, 2021
1 parent c5716db commit 11af0a3
Showing 1 changed file with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,24 @@ public void loadSparqlConnection(SparqlQueryClientConfig clientConfig, SparqlCon
}

/**
* add a new class to the ontology info object. this includes information on super/sub classes
* being added to a hash of the known entities.
**/
public void addClass(OntologyClass oClass){

/**
* add a new class to the ontology info object. this includes information on super/sub classes
* being added to a hash of the known entities.
* @param oClass
* @throws Exception - if class already exists
*/
public void addClass(OntologyClass oClass) throws Exception {
String classnameStr = oClass.getNameString(false); // get the full name of the class and do not strip URI info.
this.connHash.clear();

this.classHash.put(classnameStr, oClass); // silently overwrites if the class is already present.
if (this.classHash.containsKey(classnameStr)) {
throw new Exception("Internal error: class already exists in ontology. Cannot re-add it: " + classnameStr);
}
this.classHash.put(classnameStr, oClass);

// store info on the related subclasses
ArrayList<String> 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.
Expand Down Expand Up @@ -1138,26 +1148,25 @@ 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 xList[], String yList[]) throws Exception{
public void loadSuperSubClasses(String subList[], String superList[]) throws Exception{

HashMap<String, OntologyClass> tempClasses = new HashMap<String, OntologyClass>();

for (int i=0; i < xList.length; i++) {
// check for the existence of the current class.
if(!tempClasses.containsKey(xList[i])){
OntologyClass c = new OntologyClass(xList[i], null);
tempClasses.put(xList[i], c);
}
// get the current class and add the parent.
OntologyClass c = tempClasses.get(xList[i]);
c.addParentName(yList[i]);
}
for (int i=0; i < subList.length; i++) {
String subClassUri = subList[i];
String superClassUri = superList[i];

// call addClass() on the temp list.
for(String keyName : tempClasses.keySet()){
OntologyClass oClass = tempClasses.get(keyName);
this.addClass(oClass);
// create subclass if it is missing
if (!this.containsClass(subClassUri)) {
OntologyClass subClass = new OntologyClass(subClassUri, null);
this.addClass(subClass);
}

// get the subclass and add the parent.
this.getClass(subClassUri).addParentName(superClassUri);
}

}
Expand Down Expand Up @@ -1188,9 +1197,10 @@ private static String getTopLevelClassQuery(String graphName, String domain){
public void loadTopLevelClasses(String xList[]) throws Exception{

for (int i=0; i < xList.length; i++) {
// add it.
OntologyClass c = new OntologyClass(xList[i], null);
this.addClass(c);
if (!this.containsClass(xList[i])) {
OntologyClass c = new OntologyClass(xList[i], null);
this.addClass(c);
}
}

}
Expand Down Expand Up @@ -2316,6 +2326,7 @@ public JSONObject toJson () {

// classPropertyRangeList
for (String c : this.classHash.keySet()) {

ArrayList<OntologyProperty> propList = this.classHash.get(c).getProperties();
for (int i=0; i < propList.size(); i++) {
OntologyProperty oProp = propList.get(i);
Expand Down

0 comments on commit 11af0a3

Please sign in to comment.