Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Fix for PCL and OM individual issues
Browse files Browse the repository at this point in the history
  • Loading branch information
henrietteharmse committed Aug 4, 2022
1 parent 6f9a98d commit 7f03a0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ private void indexProperties(BatchInserter inserter, OntologyLoader loader, Map<
}

private void indexIndividuals(BatchInserter inserter, OntologyLoader loader,
Map<String, Long> nodeMap, Map<String, Long> mergedNodeMap, Map<String, Long> classNodeMap) {
Map<String, Long> nodeMap, Map<String, Long> mergedNodeMap, Map<String, Long> classNodeMap,
Map<String, Long> relatedIndividualNodeMap) {

getLogger().debug("Creating Neo4j index for " + loader.getAllIndividualIRIs().size() + " individuals");

for (IRI individualIri : loader.getAllIndividualIRIs()) {

// avoid duplicating individuals already related to a class
if (classNodeMap.containsKey(individualIri.toString())) {
nodeMap.put(individualIri.toString(), classNodeMap.get(individualIri.toString()));
if (relatedIndividualNodeMap.containsKey(individualIri.toString())) {
nodeMap.put(individualIri.toString(), relatedIndividualNodeMap.get(individualIri.toString()));
}

Long node = NodeCreator.getOrCreateNode(inserter, nodeMap, loader, individualIri,
Expand Down Expand Up @@ -293,7 +294,7 @@ private void indexRelations(Long node, Map<IRI, Collection<IRI>> relatedIndividu
*/
private void indexRelatedIndividuals(Long node, Map<IRI, Collection<IRI>> relatedIndividuals,
BatchInserter inserter, OntologyLoader loader, Map<String, Long> nodeMap,
Collection<Label> nodeLabels) {
Collection<Label> nodeLabels, Map<String, Long> relatedIndividualNodeMap) {

for (IRI relation : relatedIndividuals.keySet()) {
Map<String, Object> relatedProperties = new HashMap<>();
Expand All @@ -306,14 +307,15 @@ private void indexRelatedIndividuals(Long node, Map<IRI, Collection<IRI>> relate
//TODO review right parameters
Long relatedNode = NodeCreator.getOrCreateNode(inserter, nodeMap, loader,
relatedTerm, nodeLabels);
relatedIndividualNodeMap.put(relatedTerm.toString(), relatedNode);
inserter.createRelationship(node, relatedNode, relatedIndividual, relatedProperties);
}

}
}

void indexClasses(BatchInserter inserter, OntologyLoader loader, Map<String, Long> nodeMap,
Map<String, Long> mergedNodeMap) {
Map<String, Long> mergedNodeMap, Map<String, Long> relatedIndividualNodeMap) {
getLogger().debug("Creating Neo4j index for " + loader.getAllClasses().size() + " classes");

for (IRI classIri : loader.getAllClasses()) {
Expand All @@ -334,11 +336,11 @@ void indexClasses(BatchInserter inserter, OntologyLoader loader, Map<String, Lon

Long node = nodeMap.get(classIri.toString());

indexRelatedNodes(inserter, loader, nodeMap, classIri, node);
indexRelatedNodes(inserter, loader, nodeMap, classIri, node, relatedIndividualNodeMap);

indexRelatedIndividuals(node, loader.getRelatedIndividualsToClass(classIri), inserter,
loader, nodeMap, new LinkedList<Label>(Arrays.asList(
instanceLabel, nodeOntologyLabel, _instanceLabel)));
instanceLabel, nodeOntologyLabel, _instanceLabel)), relatedIndividualNodeMap);
}
}

Expand All @@ -360,36 +362,9 @@ private void addParentAndRelatedParentNodesWithRelationships(BatchInserter inser
}
}

void indexClassesDeprecated(BatchInserter inserter, OntologyLoader loader, Map<String, Long> nodeMap,
Map<String, Long> mergedNodeMap) {

getLogger().debug("Creating Neo4j index for " + loader.getAllClasses().size() + " classes");

for (IRI classIri : loader.getAllClasses()) {

Long node = NodeCreator.getOrCreateNode(inserter, nodeMap, loader, classIri,
new LinkedList<Label>(Arrays.asList(nodeLabel, nodeOntologyLabel, _nodeLabel)));

Long mergedNode = getOrCreateMergedNode(inserter, mergedNodeMap, loader, classIri,
mergedClassLabel);

// add refers link
inserter.createRelationship(node, mergedNode, refersTo, null);

addParentAndRelatedParentNodesWithRelationships(inserter, loader, nodeMap, classIri, node);


indexRelatedNodes(inserter, loader, nodeMap, classIri, node);

indexRelatedIndividuals(node, loader.getRelatedIndividualsToClass(classIri), inserter,
loader, nodeMap, new LinkedList<Label>(Arrays.asList(
instanceLabel, nodeOntologyLabel, _instanceLabel)));
}

}

private void indexRelatedNodes(BatchInserter inserter, OntologyLoader loader,
Map<String, Long> nodeMap, IRI classIri, Long node) {
Map<String, Long> nodeMap, IRI classIri, Long node,
Map<String, Long> relatedIndividualNodeMap) {

Map<IRI, Collection<IRI>> relatedterms = loader.getRelatedTerms(classIri);

Expand Down Expand Up @@ -419,8 +394,8 @@ private void indexRelatedNodes(BatchInserter inserter, OntologyLoader loader,
relatedTreeProperties);
}
}
relatedIndividualNodeMap.put(relatedTerm.toString(), relatedNode);
}

}
}

Expand All @@ -441,6 +416,7 @@ public void createIndex(Collection<OntologyLoader> loaders) throws IndexingExcep
Map<String, Long> classNodeMap = new HashMap<>();
Map<String, Long> propertyNodeMap = new HashMap<>();
Map<String, Long> individualNodeMap = new HashMap<>();
Map<String, Long> relatedIndividualNodeMap = new HashMap<>();

// store a local cache of merged term nodes
Map<String, Long> mergedNodeMap = new HashMap<>();
Expand All @@ -452,15 +428,15 @@ public void createIndex(Collection<OntologyLoader> loaders) throws IndexingExcep

setOntologyLabel(loader.getOntologyName());
// index classes
indexClasses(inserter, loader, classNodeMap, mergedNodeMap);
indexClasses(inserter, loader, classNodeMap, mergedNodeMap, relatedIndividualNodeMap);
// index properties
indexProperties(inserter, loader, propertyNodeMap, mergedNodeMap);
// index individuals
// avoid duplicating Thing in the graph
if (classNodeMap.containsKey("http://www.w3.org/2002/07/owl#Thing")) {
individualNodeMap.put("http://www.w3.org/2002/07/owl#Thing", classNodeMap.get("http://www.w3.org/2002/07/owl#Thing"));
}
indexIndividuals(inserter, loader, individualNodeMap, mergedNodeMap, classNodeMap);
indexIndividuals(inserter, loader, individualNodeMap, mergedNodeMap, classNodeMap, relatedIndividualNodeMap);

OLSBatchIndexerCreator.createSchemaIndexes(inserter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,59 +105,14 @@ void testIndexClasses(String ontologyIRI, String namespace, String ontologyToInd

Map<String, Long> classNodeMap = new HashMap<>();
Map<String, Long> mergedNodeMap = new HashMap<>();
Map<String, Long> referencedIndividualNodeMap = new HashMap<>();

batchNeo4JIndexer.indexClasses(batchInserter, ontologyLoader, classNodeMap, mergedNodeMap);
batchNeo4JIndexer.indexClasses(batchInserter, ontologyLoader, classNodeMap, mergedNodeMap, referencedIndividualNodeMap);

batchInserterIndexProvider.shutdown();
batchInserter.shutdown();
}

@Disabled
@Order(2)
@ParameterizedTest
@MethodSource("provideOntologies")
void testIndexClassesDeprecated(String ontologyIRI, String namespace, String ontologyToIndex,
String baseUri, String neo4JDir) {

BatchInserter batchInserter = OLSBatchIndexerCreatorTestHelper
.createBatchInserter(null, INDEX_CLASSES_TEST_DEPRECATED_NEO4J_DIR);

OntologyResourceConfig.OntologyResourceConfigBuilder builder =
new OntologyResourceConfig.OntologyResourceConfigBuilder(ontologyIRI,
namespace, (new File(BASE_DIR_FOR_TEST_RESOURCES + ontologyToIndex).toURI()));

builder.setBaseUris(Collections.singleton(baseUri));

OntologyResourceConfig config = builder.build();

OntologyLoader ontologyLoader = null;
try {
ontologyLoader = new HermitOWLOntologyLoader(config);
} catch (OntologyLoadingException e) {
logger.error(e.getMessage(), e);
}

BatchInserterIndexProvider batchInserterIndexProvider =
new LuceneBatchInserterIndexProvider(batchInserter);
BatchInserterIndex batchInserterIndex = OLSBatchIndexerCreatorTestHelper
.createBatchInserterIndex(batchInserterIndexProvider);

BatchNeo4JIndexer batchNeo4JIndexer = new BatchNeo4JIndexerHelper(
ontologyLoader.getOntologyName(), batchInserterIndex, batchInserterIndexProvider,
batchInserter, neo4JDir);

Map<String, Long> classNodeMap = new HashMap<>();
Map<String, Long> mergedNodeMap = new HashMap<>();

batchNeo4JIndexer.indexClassesDeprecated(batchInserter, ontologyLoader, classNodeMap,
mergedNodeMap);


batchInserterIndexProvider.shutdown();
batchInserter.shutdown();
}


/**
* For now we just do a few naive checks.
*
Expand Down

0 comments on commit 7f03a0e

Please sign in to comment.