Skip to content

Commit

Permalink
Executor: fix crash when subject has null
Browse files Browse the repository at this point in the history
XPath expresssions may return null in subjects, do not crash then.

Fixes #236
  • Loading branch information
DylanVanAssche committed Jun 10, 2024
1 parent fd59a3e commit 144f9b4
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Serialization format TriG is now supported for Logical Targets (fixes GitHub [issue 225](https://github.com/RMLio/rmlmapper-java/issues/225)).

### Fixed
- Crash when null is returned in an XPath function for subject generation (fixes GitHub [issue 236](https://github.com/RMLio/rmlmapper-java/issues/236))

## [7.0.0] - 2024-06-07

### Fixed
Expand Down Expand Up @@ -114,8 +117,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update dependency to `idlab-functions-java`, fixing [issue #218](https://github.com/RMLio/rmlmapper-java/issues/218)

### Changed
<<<<<<< HEAD
- Dockefile: switched to Eclipse OpenJDK Docker base image because OpenJDK is deprecated
- Dockerfile: switched to Eclipse OpenJDK Docker base image because OpenJDK is deprecated
- CI: dropped GitHub release automation
- CI: verify if token is valid

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/be/ugent/rml/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ private List<ProvenancedTerm> getIRIsWithTrueCondition(Record child, Term triple

if (Boolean.TRUE.equals(expectedBoolean)) {
List<ProvenancedTerm> subjects = this.getSubject(triplesMap, mapping, parent, i);
iris.addAll(subjects);
if (subjects != null)
iris.addAll(subjects);
} else {
logger.warn("The used condition with the Parent Triples Map does not return a boolean.");
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/be/ugent/rml/MapperXMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,9 @@ public void evaluate_1033_XML() {
public void evaluate_1034_XML() {
doMapping("./test-cases/RMLTC1034-XML/mapping.ttl", "./test-cases/RMLTC1034-XML/output.nq");
}

@Test
public void evaluate_1035_XML() {
doMapping("./test-cases/RMLTC1035-XML/mapping.ttl", "./test-cases/RMLTC1035-XML/output.nq");
}
}
19 changes: 19 additions & 0 deletions src/test/resources/test-cases/RMLTC1035-XML/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<railML xmlns="https://www.railml.org/schemas/3.1">
<netElements>
<netElement id="A" x="1" y="3">
<name language="NO" name="NODE-1"/>
<relation ref="A_B"/>
</netElement>
<netElement id="B" x="6" y="8">
<name language="NO" name="NODE-2"/>
<relation ref="A_B"/>
</netElement>
</netElements>
<netRelations>
<netRelation id="A_B">
<elementA ref="A"/>
<elementB ref="B"/>
</netRelation>
</netRelations>
</railML>
63 changes: 63 additions & 0 deletions src/test/resources/test-cases/RMLTC1035-XML/mapping.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix ex: <http://data.example.org/resource/> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix idlab-fn: <http://example.com/idlab/function/> .

ex:Organizations a rr:TriplesMap;
rml:logicalSource [
rml:source "test.xml";
rml:iterator "/Directory/Organization";
rml:referenceFormulation ql:XPath
];
rr:subjectMap [
rr:template "http://data.example.org/resource/Organization_{ID}";
rr:class org:Organization
];
rr:predicateObjectMap [
rr:predicate org:name;
rr:objectMap
[
rml:reference "Name"
];
] ;
rr:predicateObjectMap [
rr:predicate org:address;
rr:objectMap
[
rr:parentTriplesMap ex:Addresses ;
rr:joinCondition [
rr:child "path(.)";
rr:parent "path(..)";
];
];
]
.

ex:Addresses a rr:TriplesMap;
rml:logicalSource [
rml:source "test.xml";
rml:iterator "/Directory/Organization/Address";
rml:referenceFormulation ql:XPath
];
rr:subjectMap [
# rr:template "http://data.example.org/resource/Address_{generate-id(.)}";
rml:reference "if(exists(StreetName)) then 'http://data.example.org/resource/Address_' || generate-id(.) else null";
rr:class org:Address
];
rr:predicateObjectMap [
rr:predicate org:streetName;
rr:objectMap
[
rml:reference "StreetName"
];
] ;
.
12 changes: 12 additions & 0 deletions src/test/resources/test-cases/RMLTC1035-XML/output.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<http://data.example.org/resource/Address_d0e33> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/org#Address> .
<http://data.example.org/resource/Address_d0e33> <http://www.w3.org/ns/org#streetName> "99 Maine St" .
<http://data.example.org/resource/Address_d0e9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/org#Address> .
<http://data.example.org/resource/Address_d0e9> <http://www.w3.org/ns/org#streetName> "ABC FastCo Lane" .
<http://data.example.org/resource/Organization_123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/org#Organization> .
<http://data.example.org/resource/Organization_123> <http://www.w3.org/ns/org#address> <http://data.example.org/resource/Address_d0e9> .
<http://data.example.org/resource/Organization_123> <http://www.w3.org/ns/org#name> "ABC FastCo" .
<http://data.example.org/resource/Organization_456> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/org#Organization> .
<http://data.example.org/resource/Organization_456> <http://www.w3.org/ns/org#name> "XYZ Inc." .
<http://data.example.org/resource/Organization_789> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/org#Organization> .
<http://data.example.org/resource/Organization_789> <http://www.w3.org/ns/org#address> <http://data.example.org/resource/Address_d0e33> .
<http://data.example.org/resource/Organization_789> <http://www.w3.org/ns/org#name> "MNO Ltd" .
23 changes: 23 additions & 0 deletions src/test/resources/test-cases/RMLTC1035-XML/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Directory>
<Organization>
<ID>123</ID>
<Name>ABC FastCo</Name>
<Address>
<StreetName>ABC FastCo Lane</StreetName>
</Address>
</Organization>
<Organization>
<ID>456</ID>
<Name>XYZ Inc.</Name>
<Address>
<Area>XYZ Metro</Area>
</Address>
</Organization>
<Organization>
<ID>789</ID>
<Name>MNO Ltd</Name>
<Address>
<StreetName>99 Maine St</StreetName>
</Address>
</Organization>
</Directory>

0 comments on commit 144f9b4

Please sign in to comment.