Skip to content

Commit

Permalink
Merge pull request #15 from TIBHannover/11-several-ontologies-of-tib-…
Browse files Browse the repository at this point in the history
…fail-in-ingestion

Added null check while parsing anootators
  • Loading branch information
giraygi authored Jun 3, 2024
2 parents 1bf0bcd + f0bbf59 commit 5d32434
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package uk.ac.ebi.rdf2json.annotators;

import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -16,56 +17,62 @@ public static void annotateDisjointWith(OntologyGraph graph) {

long startTime3 = System.nanoTime();

for(String id : graph.nodes.keySet()) {
for (String id : graph.nodes.keySet()) {
OntologyNode c = graph.nodes.get(id);

if (c.types.contains(OntologyNode.NodeType.ALL_DISJOINT_CLASSES)) {

PropertyValue membersList = c.properties.getPropertyValue("http://www.w3.org/2002/07/owl#members");
List<PropertyValue> members = RdfListEvaluator.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);
PropertyValue membersList = c.properties.getPropertyValue("http://www.w3.org/2002/07/owl#members");
List<PropertyValue> members = RdfListEvaluator
.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);

List<OntologyNode> classNodes = members.stream().map(val -> graph.getNodeForPropertyValue(val)).collect(Collectors.toList());
List<OntologyNode> classNodes = members.stream().map(val -> graph.getNodeForPropertyValue(val))
.collect(Collectors.toList());

for(OntologyNode classNodeA : classNodes) {
for(OntologyNode classNodeB : classNodes) {
if(classNodeB.uri != classNodeA.uri) {
for (OntologyNode classNodeA : classNodes) {
for (OntologyNode classNodeB : classNodes) {
if (classNodeA != null && classNodeB != null && classNodeB.uri != classNodeA.uri) {
classNodeA.properties.addProperty("http://www.w3.org/2002/07/owl#disjointWith",
PropertyValueURI.fromUri(classNodeB.uri));
PropertyValueURI.fromUri(classNodeB.uri));
}
}
}

} else if (c.types.contains(OntologyNode.NodeType.ALL_DISJOINT_PROPERTIES)) {

PropertyValue membersList = c.properties.getPropertyValue("http://www.w3.org/2002/07/owl#members");
List<PropertyValue> members = RdfListEvaluator.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);
PropertyValue membersList = c.properties.getPropertyValue("http://www.w3.org/2002/07/owl#members");
List<PropertyValue> members = RdfListEvaluator
.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);

List<OntologyNode> propertyNodes = members.stream().map(val -> graph.getNodeForPropertyValue(val)).collect(Collectors.toList());
List<OntologyNode> propertyNodes = members.stream().map(val -> graph.getNodeForPropertyValue(val))
.collect(Collectors.toList());

for(OntologyNode propertyNodeA : propertyNodes) {
for(OntologyNode propertyNodeB : propertyNodes) {
if(propertyNodeB.uri != propertyNodeA.uri) {
for (OntologyNode propertyNodeA : propertyNodes) {
for (OntologyNode propertyNodeB : propertyNodes) {
if (propertyNodeB.uri != propertyNodeA.uri) {
propertyNodeA.properties.addProperty("http://www.w3.org/2002/07/owl#propertyDisjointWith",
PropertyValueURI.fromUri(propertyNodeB.uri));
PropertyValueURI.fromUri(propertyNodeB.uri));
}
}
}

} else if (c.types.contains(OntologyNode.NodeType.ALL_DIFFERENT)) {

PropertyValue membersList = c.properties.getPropertyValue("http://www.w3.org/2002/07/owl#distinctMembers");
List<PropertyValue> members = RdfListEvaluator.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);

List<OntologyNode> individualNodes = members.stream()
.map(val -> graph.getNodeForPropertyValue(val))
.filter(val -> val != null)
.collect(Collectors.toList());
} else if (c.types.contains(OntologyNode.NodeType.ALL_DIFFERENT)) {

for(OntologyNode individualNodeA : individualNodes) {
for(OntologyNode individualNodeB : individualNodes) {
if(individualNodeB.uri != individualNodeA.uri) {
individualNodeA.properties.addProperty("http://www.w3.org/2002/07/owl#differentFrom",
PropertyValueURI.fromUri(individualNodeB.uri));
PropertyValue membersList = c.properties
.getPropertyValue("http://www.w3.org/2002/07/owl#distinctMembers");
if (membersList != null) {
List<PropertyValue> members = RdfListEvaluator
.evaluateRdfList(graph.getNodeForPropertyValue(membersList), graph);

List<OntologyNode> individualNodes = members.stream().map(val -> graph.getNodeForPropertyValue(val))
.filter(val -> val != null).collect(Collectors.toList());

for (OntologyNode individualNodeA : individualNodes) {
for (OntologyNode individualNodeB : individualNodes) {
if (individualNodeB.uri != individualNodeA.uri) {
individualNodeA.properties.addProperty("http://www.w3.org/2002/07/owl#differentFrom",
PropertyValueURI.fromUri(individualNodeB.uri));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static void annotateRelated_Class_subClassOf_Restriction_hasValue(Ontolo

OntologyNode fillerNode = graph.nodes.get( ((PropertyValueURI) filler).getUri() );

if(fillerNode.types.contains(OntologyNode.NodeType.INDIVIDUAL)) {
if(fillerNode != null && fillerNode.types.contains(OntologyNode.NodeType.INDIVIDUAL)) {
// fillerNode is an individual
fillerNode.properties.addProperty("relatedTo", new PropertyValueRelated(fillerRestriction, propertyUri, classNode));
classNode.properties.addProperty("relatedFrom", new PropertyValueRelated(fillerRestriction, propertyUri, fillerNode));
Expand Down

0 comments on commit 5d32434

Please sign in to comment.