for (String label : sortedMap.keySet()) {
double probability = scoreMap.get(label);
// Check if the type contains domain
if(label.contains("|")){
Label domainURI = ontMgr.getUriLabel(label.split("\\|")[0]);
Label typeURI = ontMgr.getUriLabel(label.split("\\|")[1]);
if(domainURI == null || typeURI == null)
continue;
String clazzLocalNameWithPrefix = domainURI.getDisplayName();
if(domainURI.getPrefix() == null)
clazzLocalNameWithPrefix = domainURI.getUri() + "/" + domainURI.getLocalName();
int graphLastIndex = alignment.getLastIndexOfNodeUri(domainURI.getUri());
if (graphLastIndex == -1) { // No instance present in the graph
insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + "1 (add)",
domainURI.getUri(), domainURI.getUri() + "1",
typeURI.getDisplayName(), label.split("\\|")[1], probability);
} else {
boolean hasLastNodeFromSteinerTree = false;
for (int i=1; i<= graphLastIndex; i++) {
if (steinerTreeNodeIds.contains(domainURI.getUri() + i)) {
insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + i,
domainURI.getUri(),
domainURI.getUri() + i,
typeURI.getDisplayName(), label.split("\\|")[1], probability);
if (i == graphLastIndex)
hasLastNodeFromSteinerTree = true;
} else {
Node graphNode = alignment.getNodeById(domainURI.getUri() + i);
if (graphNode != null)
insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + i + " (add)",
graphNode.getUri(),
graphNode.getId(),
typeURI.getDisplayName(), label.split("\\|")[1], probability);
}
}
// Add an option to add one more node for the domain
if (hasLastNodeFromSteinerTree)
insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + (graphLastIndex+1) + " (add)",
domainURI.getUri(), domainURI.getUri() + (graphLastIndex+1),
typeURI.getDisplayName(), label.split("\\|")[1], probability);
}
} else {
Label typeURI = ontMgr.getUriLabel(label);
if(typeURI == null)
continue;
String clazzLocalNameWithPrefix = typeURI.getDisplayName();
int graphLastIndex = alignment.getLastIndexOfNodeUri(typeURI.getUri());
if (graphLastIndex == -1) { // No instance present in the graph
insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + "1 (add)", typeURI.getUri(), typeURI.getUri() + "1", probability);
} else {
boolean hasLastNodeFromSteinerTree = false;
for (int i=1; i<= graphLastIndex; i++) {
if (steinerTreeNodeIds.contains(typeURI.getUri() + (graphLastIndex))) {
insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + i, typeURI.getUri(), typeURI.getUri() + i, probability);
} else {
Node graphNode = alignment.getNodeById(typeURI.getUri() + i);
if (graphNode != null)
insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + i + " (add)", graphNode.getUri(), graphNode.getId(), probability);
}
}
// Add an option to add one more node for the domain
if (hasLastNodeFromSteinerTree)
insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + (graphLastIndex+1) + " (add)", typeURI.getUri(), typeURI.getUri() + (graphLastIndex+1), probability);
}
}
}
obj.put("Labels", arr);
return obj;