Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added null check while parsing anootators #15

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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