RML 和 FnO 未能 运行 在一起

RML and FnO fails to run together

我正在尝试在 RML 映射器中使用 FnO 函数(我喜欢做 string_split,比如 here)。 这是我的文件夹的样子:

我正在执行java -jar "rmlmapper.jar" -m mapping-cuisines.ttl -o output-cuisines.ttl -s turtle

但是,当我尝试实施 <#FunctionMap> 时,我收到以下错误消息:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
        at java.base/java.util.Objects.checkIndex(Objects.java:372)
        at java.base/java.util.ArrayList.get(ArrayList.java:458)
        at be.ugent.rml.functions.DynamicMultipleRecordsFunctionExecutor.execute(DynamicMultipleRecordsFunctionExecutor.java:66)
        at be.ugent.rml.functions.AbstractSingleRecordFunctionExecutor.execute(AbstractSingleRecordFunctionExecutor.java:17)
        at be.ugent.rml.termgenerator.LiteralGenerator.generate(LiteralGenerator.java:42)
        at be.ugent.rml.Executor.generatePredicateObjectGraphs(Executor.java:157)
        at be.ugent.rml.Executor.executeWithFunction(Executor.java:115)
        at be.ugent.rml.Executor.execute(Executor.java:76)
        at be.ugent.rml.cli.Main.main(Main.java:206)

对我来说没有任何意义。根据 git repo,函数是从我执行 rmlmapper 的地方动态加载的。

数据集:https://mega.nz/file/LsJAQRaR#84lfASPXVA08zm0RbuRfNvR7tx-vklS82D1KBGhhdA8

我的代码:

@base <http://example.org/data> .
@prefix ex: <http://example.org/ns#> .
@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 xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix csvw: <http://www.w3.org/ns/csvw#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .


<#LogicalSource>
    a rml:LogicalSource;
    rml:source "dataworld-restaurants-cuisines.csv";
    rml:referenceFormulation ql:CSV.


<#MyTriplesMap>
    a rr:TriplesMap;
    rml:logicalSource <#LogicalSource>;

    rr:subjectMap [
        rr:template "http://example.org/{id}";
    ];

    rr:predicateObjectMap [
        rr:predicate ex:aProperty;
        rr:objectMap <#FunctionMap>;
    ].

<#FunctionMap>
    fnml:functionValue [
        rml:logicalSource <#LogicalSource> ;
        rr:predicateObjectMap [
            rr:predicate fno:executes ;
            rr:objectMap [ rr:constant grel:toUpperCase ]
        ] ;
        rr:predicateObjectMap [
            rr:predicate grel:valueParameter ;                  
            rr:objectMap [
                rml:reference "spicy"                           
            ]
        ]
    ] .

我的functions.ttl:

@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix doap:    <http://usefulinc.com/ns/doap#> .
@prefix fno:     <https://w3id.org/function/ontology#> .
@prefix fnoi:    <https://w3id.org/function/vocabulary/implementation#> .
@prefix fnom:    <https://w3id.org/function/vocabulary/mapping#> .
@prefix grel:    <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .
@prefix grelm:   <http://fno.io/grel/rmlmapping#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .

grel:toUpperCase a fno:Function ;
  fno:name "to Uppercase" ;
  rdfs:label "to Uppercase" ;
  dcterms:description "Returns the input with all letters in upper case." ;
  fno:expects ( grel:valueParam ) ;
  fno:returns ( grel:stringOut ) .

grelm:javaString
    a                  fnoi:JavaClass ;
    doap:download-page "GrelFunctions.jar" ;
    fnoi:class-name    "io.fno.grel.StringFunctions" .

grelm:uppercaseMapping
    a                    fnoi:Mapping ;
    fno:function         grel:toUpperCase ;
    fno:implementation   grelm:javaString ;
    fno:methodMapping    [ a                fnom:StringMethodMapping ;
                           fnom:method-name "toUppercase" ] .

我试过你的映射文件,它工作正常。 您当前的映射文件将 spicy 中的数据转换为大写 并生成指定的 RDF 三元组。 由于函数 grel:toUpperCase 默认包含在 RLMMapper 中, 您不需要 functions.ttl 来指定这些函数。 仅当您想添加自己的自定义功能时才需要这样做。 可以在此处找到 RLMMapper 中所有包含函数的概述:https://rml.io/docs/rmlmapper/default-functions/

举个例子

  1. 从我们的 Github 存储库下载最新的 RLMMapper:https://github.com/RMLio/rmlmapper-java/releases
  2. 运行 为:java -jar <path to jar> -m mapping.rml.ttl
  3. 我得到下面列出的输出。

mapping.rml.ttl

@base <http://example.org/data> .
@prefix ex: <http://example.org/ns#> .
@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 xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix csvw: <http://www.w3.org/ns/csvw#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .


<#LogicalSource>
    a rml:LogicalSource;
    rml:source "dataworld-restaurants-cuisines.csv";
    rml:referenceFormulation ql:CSV.


<#MyTriplesMap>
    a rr:TriplesMap;
    rml:logicalSource <#LogicalSource>;

    rr:subjectMap [
        rr:template "http://example.org/{id}";
    ];

    rr:predicateObjectMap [
        rr:predicate ex:aProperty;
        rr:objectMap <#FunctionMap>;
    ].

<#FunctionMap>
    fnml:functionValue [
        rml:logicalSource <#LogicalSource> ;
        rr:predicateObjectMap [
            rr:predicate fno:executes ;
            rr:objectMap [ rr:constant grel:toUpperCase ]
        ] ;
        rr:predicateObjectMap [
            rr:predicate grel:valueParameter ;                  
            rr:objectMap [
                rml:reference "spicy"                           
            ]
        ]
    ] .

输出(截断)

<http://example.org/afghani> <http://example.org/ns#aProperty> "NO".
<http://example.org/african> <http://example.org/ns#aProperty> "YES".
<http://example.org/african_portuguese> <http://example.org/ns#aProperty> "YES".
<http://example.org/american> <http://example.org/ns#aProperty> "NO".
<http://example.org/andhra> <http://example.org/ns#aProperty> "YES".
<http://example.org/arabian> <http://example.org/ns#aProperty> "NO".
<http://example.org/arabian_lebanese> <http://example.org/ns#aProperty> "NO".
<http://example.org/arabian_mexican> <http://example.org/ns#aProperty> "NO".
<http://example.org/arabian_middle_eastern> <http://example.org/ns#aProperty> "YES".
<http://example.org/asian> <http://example.org/ns#aProperty> "YES".
<http://example.org/assamese> <http://example.org/ns#aProperty> "NO".
<http://example.org/australian> <http://example.org/ns#aProperty> "YES".
<http://example.org/awadhi> <http://example.org/ns#aProperty> "YES".
<http://example.org/awadhi_mughlai> <http://example.org/ns#aProperty> "NO".
<http://example.org/bakery> <http://example.org/ns#aProperty> "NO".

FnOstring_split

如果你想在RML中使用FnO的string_split,你可以这样实现:

  1. fno:executes: grel:string_split 使用 GREL 拆分功能。
  2. grel:valueParameter:要拆分的输入字符串。 我在这里引用了 CSV 列 cuisines.
  3. grel:p_string_sep:GREL拆分函数所在的字符串分隔符 必须拆分输入字符串。 我这里用了 ,来区分每个餐厅的不同菜系。

mapping.rml.ttl

@base <http://example.org> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .
@prefix ex: <http://example.org/ns#> .

<#LogicalSource>
    a rml:LogicalSource;
    rml:source "dataworld-restaurants-cuisines.csv";
    rml:referenceFormulation ql:CSV.


<#MyTriplesMap>
    a rr:TriplesMap;
    rml:logicalSource <#LogicalSource>;

    rr:subjectMap [
        rr:template "http://example.org/{id}";
    ];

    rr:predicateObjectMap [
        rr:predicate ex:cuisine;
        rr:objectMap <#FunctionMap>;
    ];
.

<#FunctionMap>
    fnml:functionValue [
        rml:logicalSource <#LogicalSource>;
        rr:predicateObjectMap [
            rr:predicate fno:executes; 
            rr:objectMap [ 
                rr:constant grel:string_split 
            ];
        ];
        rr:predicateObjectMap [
            rr:predicate grel:valueParameter;
            rr:objectMap [ 
                rml:reference "cuisines" 
            ];
        ];
        rr:predicateObjectMap [
            rr:predicate grel:p_string_sep;
            rr:objectMap [ 
                rr:constant ", ";
            ];
        ];
    ].

输出(截断)

<http://example.org/afghani> <http://example.org/ns#cuisine> "Afghani".
<http://example.org/african> <http://example.org/ns#cuisine> "African".
<http://example.org/african_portuguese> <http://example.org/ns#cuisine> "African".
<http://example.org/african_portuguese> <http://example.org/ns#cuisine> "Portuguese".
<http://example.org/american> <http://example.org/ns#cuisine> "american".
<http://example.org/andhra> <http://example.org/ns#cuisine> "Andhra".
<http://example.org/arabian> <http://example.org/ns#cuisine> "Arabian".
<http://example.org/arabian_lebanese> <http://example.org/ns#cuisine> "Arabian".
<http://example.org/arabian_lebanese> <http://example.org/ns#cuisine> "Lebanese".
<http://example.org/arabian_mexican> <http://example.org/ns#cuisine> "Arabian".
<http://example.org/arabian_mexican> <http://example.org/ns#cuisine> "Mexican".
<http://example.org/arabian_middle_eastern> <http://example.org/ns#cuisine> "Arabian".
<http://example.org/arabian_middle_eastern> <http://example.org/ns#cuisine> "Middle Eastern".
<http://example.org/asian> <http://example.org/ns#cuisine> "Asian".
<http://example.org/assamese> <http://example.org/ns#cuisine> "Assamese".
<http://example.org/australian> <http://example.org/ns#cuisine> "Australian".
<http://example.org/awadhi> <http://example.org/ns#cuisine> "Awadhi".
<http://example.org/awadhi_mughlai> <http://example.org/ns#cuisine> "Awadhi".
<http://example.org/awadhi_mughlai> <http://example.org/ns#cuisine> "Mughlai".
<http://example.org/bakery> <http://example.org/ns#cuisine> "bakery".
<http://example.org/bar_food> <http://example.org/ns#cuisine> "Bar Food".
<http://example.org/bar_food_brazilian> <http://example.org/ns#cuisine> "Bar Food".
<http://example.org/bar_food_brazilian> <http://example.org/ns#cuisine> "Brazilian".

注意:我从事RML和FnO技术