Skip to content

Commit

Permalink
Merge pull request #47 from oeg-upm/dev
Browse files Browse the repository at this point in the history
Adding Functions support!
  • Loading branch information
dachafra authored Jan 21, 2023
2 parents cf70e3a + 417b3c0 commit 5a3b5dd
Show file tree
Hide file tree
Showing 64 changed files with 1,270 additions and 234 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
The tool translates mapping rules from YARRRML in a turtle-based serialization of RML or R2RML. The translation is based
on the [RML](https://rml.io/specs/rml/) and [YARRRML](https://rml.io/yarrrml/spec/) specifications.

## Limitations
We are working on including the following features which are not yet implemented:
- Functions using the [FnO](https://fno.io/) Ontology

## Installation:
```
pip install yarrrml-translator
Expand Down Expand Up @@ -69,6 +65,17 @@ list_yarrrml_mappings = ["content_mapping_yarrrml1", "content_mapping_yarrrml1"]
yarrrml_content = yarrrml_translator.merge_mappings(list_yarrrml_mappings)
```


## Specifications conformant:

These are the following specifications used by the translation process:
- YARRRML: https://github.com/kg-construct/yarrrml-spec (Proper website soon)
- R2RML: https://www.w3.org/TR/r2rml/
- RML: https://rml.io/spec
- RML-star: https://w3id.org/kg-construct/rml-star
- RML-Target: https://rml.io/specs/rml-target/
- RML-FNML: https://kg-construct.github.io/fnml-spec/

## Authors
Ontology Engineering Group:
- [David Chaves-Fraga](mailto:david.chaves@upm.es)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.1
0.8.2
11 changes: 6 additions & 5 deletions test/projects/PPDSTC/test_ppds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__author__ = "Marino Gonzalez Garcia"
__credits__ = ["Marino Gonzalez Garcia"]
__author__ = "David Chaves-Fraga"
__credits__ = ["David Chaves-Fraga"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"



import os
Expand All @@ -14,7 +15,7 @@
RML_URI = 'http://semweb.mmlab.be/ns/rml#'


def test_yarrrmltc0019():
def test_yarrrml_ppds():
expected_mapping = Graph()
expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl")

Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0008/test_yarrrmltc0008.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0009/test_yarrrmltc0009.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0010/test_yarrrmltc0010.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
5 changes: 2 additions & 3 deletions test/r2rml/YARRRMLTC-0011/test_yarrrmltc0011.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"

__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"

import os
from ruamel.yaml import YAML
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0012/test_yarrrmltc0012.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0013/test_yarrrmltc0013.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0014/test_yarrrmltc0014.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/r2rml/YARRRMLTC-0015/test_yarrrmltc0015.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0016/test_yarrrmltc0016.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0017/test_yarrrmltc0017.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0018/test_yarrrmltc0018.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0019/test_yarrrmltc0019.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0020/test_yarrrmltc0020.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0021/test_yarrrmltc0021.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
4 changes: 2 additions & 2 deletions test/rml-core/YARRRMLTC-0022/test_yarrrmltc0022.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__credits__ = ["Marino Gonzalez Garcia"]

__license__ = "Apache-2.0"
__maintainer__ = "Marino Gonzalez Garcia"
__email__ = "marino.gonzalez.garcia@alumnos.upm.es"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
Expand Down
6 changes: 3 additions & 3 deletions test/rml-datatype/YARRRMLTC-0032/test_yarrrmltc0032.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
__author__ = "Marino Gonzalez Garcia"
__credits__ = ["Marino Gonzalez Garcia"]
__author__ = "David Chaves-Fraga"
__credits__ = ["David Chaves-Fraga"]

__license__ = "Apache-2.0"
__maintainer__ = "David Chaves Fraga"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


Expand Down
6 changes: 3 additions & 3 deletions test/rml-datatype/YARRRMLTC-0033/test_yarrrmltc0033.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
__author__ = "Marino Gonzalez Garcia"
__credits__ = ["Marino Gonzalez Garcia"]
__author__ = "David Chaves-Fraga"
__credits__ = ["David Chaves-Fraga"]

__license__ = "Apache-2.0"
__maintainer__ = "David Chaves Fraga"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


Expand Down
53 changes: 53 additions & 0 deletions test/rml-fnml/YARRRMLTC-0040/mapping.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix ex: <http://example.com/>.
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@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 ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>.
@prefix schema: <http://schema.org/>.
@prefix formats: <http://www.w3.org/ns/formats/>.
@prefix comp: <http://semweb.mmlab.be/ns/rml-compression#>.
@prefix void: <http://rdfs.org/ns/void#>.
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#>.
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#>.
@base <http://example.com/ns#>.


<function_student2_0> a fnml:Execution;
fnml:function ex:toLowerCase ;
fnml:input
[
a fnml:Input;
fnml:parameter ex:input;
fnml:valueMap [
a fnml:ValueMap;
rml:reference "firstname";
];
].

<student2_0> a rr:TriplesMap;

rml:logicalSource [
a rml:LogicalSource;
rml:source "student.csv";
rml:referenceFormulation ql:CSV
];
rr:subjectMap [
a rr:SubjectMap;
rr:template "http://example.com/{Name}";
];
rr:predicateObjectMap [
rr:predicateMap [
a rr:PredicateMap;
rr:constant foaf:name;
];
rml:objectMap [
a rr:ObjectMap;
fnml:execution <function_student2_0>;
];
].


15 changes: 15 additions & 0 deletions test/rml-fnml/YARRRMLTC-0040/mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
prefixes:
foaf: http://xmlns.com/foaf/0.1/
ex: http://example.com/

mappings:
student2:
sources:
- [ 'student.csv~csv' ]
s: http://example.com/$(Name)
po:
- p: foaf:name
o:
- function: ex:toLowerCase
parameters:
- [ ex:input, $(firstname) ]
25 changes: 25 additions & 0 deletions test/rml-fnml/YARRRMLTC-0040/test_yarrrmltc0040.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
__author__ = "David Chaves-Fraga"
__credits__ = ["David Chaves-Fraga"]

__license__ = "Apache-2.0"
__maintainer__ = "David Chaves-Fraga"
__email__ = "david.chaves@upm.es"


import os
from ruamel.yaml import YAML
import yarrrml_translator
from rdflib.graph import Graph
from rdflib import compare


def test_yarrrmltc0040():
expected_mapping = Graph()
expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl")

translated_mapping = Graph()
yaml = YAML(typ='safe', pure=True)
mapping_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml')
translated_mapping.parse(data=yarrrml_translator.translate(yaml.load(open(mapping_path))), format="ttl")

assert compare.isomorphic(expected_mapping, translated_mapping)
51 changes: 51 additions & 0 deletions test/rml-fnml/YARRRMLTC-0041/mapping.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix ex: <http://example.com/>.
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@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 ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>.
@prefix schema: <http://schema.org/>.
@prefix formats: <http://www.w3.org/ns/formats/>.
@prefix comp: <http://semweb.mmlab.be/ns/rml-compression#>.
@prefix void: <http://rdfs.org/ns/void#>.
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#>.
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#>.
@base <http://example.com/ns#>.


<function_student2_0> a fnml:Execution;
fnml:function ex:toLowerCase ;
fnml:input
[
a fnml:Input;
fnml:parameter ex:input;
fnml:valueMap [
a fnml:ValueMap;
rml:reference "firstname";
];
].

<student2_0> a rr:TriplesMap;

rml:logicalSource [
a rml:LogicalSource;
rml:source "student.csv";
rml:referenceFormulation ql:CSV
];
rr:subjectMap [
a rr:SubjectMap;
fnml:execution <function_student2_0>;
];
rr:predicateObjectMap [
rr:predicateMap [
a rr:PredicateMap;
rr:constant foaf:firstName;
];
rr:objectMap [
a rr:ObjectMap;
rml:reference "name";
];
].
Loading

0 comments on commit 5a3b5dd

Please sign in to comment.