README: Functions
May 30, 2022 ยท View on GitHub
Built-in functions
Two function libraries are supported out of the box in RMLStreamer:
- GREL functions (https://github.com/FnOio/grel-functions-java)
- IDLab functions (https://github.com/FnOio/idlab-functions-java)
No extra configuration or parameters need to be provided to use those.
Check out src/test/resources/fno-testcases for example RML Mappings.
Using other function libraries
RMLStreamer can also execute functions from other libraries. To use functions, three things have to be provided:
- A JAR file containing the code to execute functions;
- Function descriptions: a document describing the functions in the library semantically using FnO.
- Implementation mappings: a document mapping the functions from the function descriptions to the implementation in the JAR file, also using FnO.
Often the function descriptions an the implementation mappings are bundled in one document.
How to do this is explained as an example in the Function Agent library, which is used by RMLStreamer to handle functions.
A minimal example is provided in the tests: src/test/resources/sandbox/function_related/external_jar/
If there are a JAR file and FnO descriptions, RMLStreamer can be invoked with the -f or --function-descriptions
parameter, like so:
$ FLINK_BIN run [Flink options] -c io.rml.framework.Main <path to RMLStreamer jar> \
toFile \
--output-path /tmp/helloworld.nt \
--mapping-file /<path to RMLStreamer root>/src/test/resources/sandbox/function_related/external_jar/mapping.ttl \
--function-descriptions /<path to RMLStreamer root>/src/test/resources/sandbox/function_related/external_jar/simple-test-function-fno.ttl
Notes
- The paths to funtion descriptions or JAR files can also be URLs;
- One can pass multiple function description locations to the
--function-descriptionsparameter separated by a space.
Test Cases
FnO Tests
The official FnO testcases that are working can be found at src/test/resources/fno-testcases.
SandboxTests
These tests are still experimental.
The resources can be found at src/test/resources/sandbox/function_related
and are executed from io.rml.framework.SandboxTests.
Every test output is compared to the RMLMapper's output (e.g. output.ttl) for that test. A test passes when its output is equal to the RMLMapper's output.
Tests marked as pending should be considered as not working.
The sandbox testcases are
-
condition-function-on-po: uses the functionsidlab-fn:trueConditionidlab-fn:stringContainsOtherStringgrel:toUpperCase
-
condition-on-mapping-subject-function: uses the functionsidlab-fn:trueConditionidlab-fn:notEqual
-
condition-on-po: uses the functionsidlab-fn:trueConditionidlab-fn:equal
-
containsuses functiongrel:string_contains -
controls_if_contains: uses the functionsgrel:controls_ifgrel:string_contains
-
controls_if_true: uses the functionsgrel:controls_if. -
controls_if_false: uses the functionsgrel:controls_if -
equal: uses functionidlab-fn:equal -
external_jar: uses theHelloWorldfunction from an external JAR file. -
notEqual: uses functionidlab-fn:notEqual -
using_trueCondition_and_containsidlab-fn:trueConditiongrel:string_contains
-
using_trueCondition_and_equalidlab-fn:trueConditionidlab-fn:equal
Remarks
- When the RMLStreamer is unable to find a function description or function mapping, bind method parameters to values, it will be logged as a warning to the console and the function will not be applied.