Skip to content

Commit

Permalink
Fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed Feb 14, 2024
1 parent 9cf47dc commit 371a1e8
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Fixed
- target disappears when it is used in combination with condition on po
(see [issue 11](https://gitlab.ilabt.imec.be/yarrrml/yarrrml-parser/-/issues/11)).

## [1.6.1] - 2023-09-18

### Fixed
Expand Down
17 changes: 12 additions & 5 deletions lib/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,13 @@ function expandConditionsOfPOs(predicateobjects) {
*/
function conditionToFunction(conditions, termMapDescription, defaultType = undefined) {
// TODO it's very weird that it's either value or complete map
value = defaultType === 'iri' ? (termMapDescription.type === 'blank' ? null : termMapDescription) : (termMapDescription.function ? termMapDescription : termMapDescription.value);
from = termMapDescription.function ? 'function' : 'subject';
type = termMapDescription.type ? termMapDescription.type : defaultType;
datatype = termMapDescription.datatype;
language = termMapDescription.language;
const value = defaultType === 'iri' ? (termMapDescription.type === 'blank' ? null : termMapDescription) : (termMapDescription.function ? termMapDescription : termMapDescription.value);
const from = termMapDescription.function ? 'function' : 'subject';
const type = termMapDescription.type ? termMapDescription.type : defaultType;
const datatype = termMapDescription.datatype;
const language = termMapDescription.language;
const targets = termMapDescription.targets;

termMapDescription = {
function: idlabfn + 'trueCondition',
parameters: [
Expand All @@ -603,10 +605,15 @@ function conditionToFunction(conditions, termMapDescription, defaultType = undef
if (datatype) {
termMapDescription.datatype = datatype;
}

if (language) {
termMapDescription.language = language;
}

if (targets) {
termMapDescription.targets = targets;
}

return termMapDescription;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/rml-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ describe('YARRRML to RML', function () {
work('condition-on-po-language/mapping.yarrrml', 'condition-on-po-language/mapping.rml.ttl', done, {includeMetadata: false});
});

it('condition on po with target', function (done) {
work('condition-on-po-target/mapping.yarrrml', 'condition-on-po-target/mapping.rml.ttl', done, {includeMetadata: false});
});

it('condition on mapping with function for subject', function (done) {
work('condition-on-mapping-subject-function/mapping.yarrrml', 'condition-on-mapping-subject-function/mapping.rml.ttl', done, {includeMetadata: false});
});
Expand Down
97 changes: 97 additions & 0 deletions test/condition-on-po-target/mapping.rml.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#>.
@prefix fno: <https://w3id.org/function/ontology#>.
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>.
@prefix void: <http://rdfs.org/ns/void#>.
@prefix dc: <http://purl.org/dc/terms/>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix : <http://mapping.example.com/>.
@prefix ex: <https://example.org/ns/test#>.
@prefix idlab-fn: <http://example.com/idlab/function/>.
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix prov: <http://www.w3.org/ns/prov#>.
@prefix rmlt: <http://semweb.mmlab.be/ns/rml-target#>.
@prefix formats: <http://www.w3.org/ns/formats/>.

:target_000 a rmlt:LogicalTarget;
rdfs:label "venus_target";
rmlt:serialization formats:Turtle;
rmlt:target :void_000.
:void_000 a void:Dataset;
void:dataDump <file://data/venus.ttl>.
:map_events_000 rml:logicalSource :source_000.
:source_000 a rml:LogicalSource;
rml:source "data.csv";
rml:referenceFormulation ql:CSV.
:map_events_000 a rr:TriplesMap;
rdfs:label "events".
:s_000 a rr:SubjectMap.
:map_events_000 rr:subjectMap :s_000.
:s_000 rr:template "https://example.org/ns/test#event_{id}".
:pom_000 a rr:PredicateObjectMap.
:map_events_000 rr:predicateObjectMap :pom_000.
:pm_000 a rr:PredicateMap.
:pom_000 rr:predicateMap :pm_000.
:pm_000 rr:constant ex:hasName.
:pom_000 rr:objectMap :om_000.
:om_000 a fnml:FunctionTermMap;
rr:termType rr:Literal;
rml:logicalTarget :target_000;
rml:languageMap :language_000.
:language_000 rr:constant "en".
:om_000 fnml:functionValue :fn_000.
:fn_000 rml:logicalSource :source_000;
rr:predicateObjectMap :pomexec_000.
:pomexec_000 rr:predicateMap :pmexec_000.
:pmexec_000 rr:constant fno:executes.
:pomexec_000 rr:objectMap :omexec_000.
:omexec_000 rr:constant "http://example.com/idlab/function/trueCondition";
rr:termType rr:IRI.
:fn_000 rr:predicateObjectMap :pom_001.
:pom_001 a rr:PredicateObjectMap;
rr:predicateMap :pm_001.
:pm_001 a rr:PredicateMap;
rr:constant idlab-fn:strBoolean.
:pom_001 rr:objectMap :om_001.
:om_001 a rr:ObjectMap, fnml:FunctionTermMap;
fnml:functionValue :fn_001.
:fn_001 rml:logicalSource :source_000;
rr:predicateObjectMap :pomexec_001.
:pomexec_001 rr:predicateMap :pmexec_001.
:pmexec_001 rr:constant fno:executes.
:pomexec_001 rr:objectMap :omexec_001.
:omexec_001 rr:constant "http://example.com/idlab/function/notEqual";
rr:termType rr:IRI.
:fn_001 rr:predicateObjectMap :pom_002.
:pom_002 a rr:PredicateObjectMap;
rr:predicateMap :pm_002.
:pm_002 a rr:PredicateMap;
rr:constant grel:valueParameter.
:pom_002 rr:objectMap :om_002.
:om_002 a rr:ObjectMap;
rml:reference "name";
rr:termType rr:Literal.
:fn_001 rr:predicateObjectMap :pom_003.
:pom_003 a rr:PredicateObjectMap;
rr:predicateMap :pm_003.
:pm_003 a rr:PredicateMap;
rr:constant grel:valueParameter2.
:pom_003 rr:objectMap :om_003.
:om_003 a rr:ObjectMap;
rr:constant "";
rr:termType rr:Literal.
:fn_000 rr:predicateObjectMap :pom_004.
:pom_004 a rr:PredicateObjectMap;
rr:predicateMap :pm_004.
:pm_004 a rr:PredicateMap;
rr:constant idlab-fn:str.
:pom_004 rr:objectMap :om_004.
:om_004 a rr:ObjectMap;
rml:reference "name";
rr:termType rr:Literal.

29 changes: 29 additions & 0 deletions test/condition-on-po-target/mapping.yarrrml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
prefixes:
ex: "https://example.org/ns/test#"
idlab-fn: "http://example.com/idlab/function/"
grel: "http://users.ugent.be/~bjdmeest/function/grel.ttl#"
xsd: "http://www.w3.org/2001/XMLSchema#"
prov: "http://www.w3.org/ns/prov#"

targets:
venus_target:
access: data/venus.ttl
type: void
serialization: turtle

mappings:
events:
sources:
- ['data.csv~csv']
s: ex:event_$(id)
po:
- p: ex:hasName
o:
- value: $(name)
language: en
targets: venus_target
condition:
function: idlab-fn:notEqual
parameters:
- [grel:valueParameter, $(name)]
- [grel:valueParameter2, ""]

0 comments on commit 371a1e8

Please sign in to comment.