helio-ecosystem / helio-handler-xml

This data handler allows extracting data from XML
0 stars 1 forks source link

Problem with lists #2

Closed Salva5297 closed 2 years ago

Salva5297 commented 2 years ago

I have a problem giving this mapping to helio, it says that the part of the second list is evaluated as a string, but it is an array of strings:

<#assign xpath=handlers('XmlHandler')>
<#assign dataset=providers(type='FileProvider', file='/Users/salva/Dropbox/cogito/cogito_wrapper_module/repository/schedule/files/schedule.xml')>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix data: <http://data.cogito.iot.linkeddata.es/resources/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix facility: <https://cogito.iot.linkeddata.es/def/facility#> .
@prefix process: <https://cogito.iot.linkeddata.es/def/process#> .
@prefix resource: <https://cogito.iot.linkeddata.es/def/resource#> .
@prefix const: <https://cogito.iot.linkeddata.es/def/construction#> .
@prefix time: <http://www.w3.org/2006/time#>
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix s4city: <https://saref.etsi.org/saref4city#> .
@prefix saref: <https://saref.etsi.org/core#> .
data:project/[=xpath.filter('./Project/Final_Project_ID/text()', dataset)]
    a facility:Project ;
    facility:isRelatedToProcess process:data/[=xpath.filter('./Project/GUID/text()', dataset)] .
data:process/[=xpath.filter('./Project/GUID/text()', dataset)]
    a process:Process ;
    process:processID '[=xpath.filter('./Project/GUID/text()', dataset)]' ;
    process:hasName '[=xpath.filter('./Project/Name/text()', dataset)]' ;
    process:hasCreationDate '[=xpath.filter('./Project/CreationDate/text()', dataset)]'^^<http://www.w3.org/2001/XMLSchema#dateTime>;
    process:hasCost data:cost/[=xpath.filter('./Project/GUID/text()', dataset)] ;
    process:isPlannedIn data:interval/[=xpath.filter('./Project/GUID/text()', dataset)] .
<#list xpath.filter('./Project/Tasks/Task[*]',dataset)>
<#items as task>
data:task/[=xpath.filter('./Task/GUID/text()', task)]
    a process:Task ;
    process:taskId '[=xpath.filter('./Task/GUID/text()', task)]' ;
    process:taskUid '[=xpath.filter('./Task/UID/text()', task)]' ;
    process:hasName '[=xpath.filter('./Task/Name/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasCreationDate '[=xpath.filter('./Task/CreationDate/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
    process:isPlannedIn data:interval/[=xpath.filter('./Task/GUID/text()', task)] ;
    process:hasPriority '[=xpath.filter('./Task/Priority/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#integer> ;
    process:hasProgress '[=xpath.filter('./Task/RemainingWork/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasStatus '[=xpath.filter('./Task/ActualWork/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasCost data:cost/[=xpath.filter('./Task/GUID/text()', task)] .
    <#if xpath.filter('./Task/Childs',task)?trim != ''>
    data:task/[=xpath.filter('./Task/GUID/text()', task)]
        process:hasChild
        <#assign childs = xpath.filter("./Task/Childs/WBS/text()",task)>
            <#list childs as child>
                [=child]
            </#list>
    <#else>
    ...
    </#if>
</#items>
</#list>
Salva5297 commented 2 years ago

It can be solved with:

<#assign xpath=handlers('XmlHandler')>
<#assign dataset=providers(type='FileProvider', file='/Users/salva/Dropbox/cogito/cogito_wrapper_module/repository/schedule/files/schedule.xml')>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix data: <http://data.cogito.iot.linkeddata.es/resources/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix facility: <https://cogito.iot.linkeddata.es/def/facility#> .
@prefix process: <https://cogito.iot.linkeddata.es/def/process#> .
@prefix resource: <https://cogito.iot.linkeddata.es/def/resource#> .
@prefix const: <https://cogito.iot.linkeddata.es/def/construction#> .
@prefix time: <http://www.w3.org/2006/time#>
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix s4city: <https://saref.etsi.org/saref4city#> .
@prefix saref: <https://saref.etsi.org/core#> .
data:project/[=xpath.filter('./Project/Final_Project_ID/text()', dataset)]
    a facility:Project ;
    facility:isRelatedToProcess process:data/[=xpath.filter('./Project/GUID/text()', dataset)] .
data:process/[=xpath.filter('./Project/GUID/text()', dataset)]
    a process:Process ;
    process:processID '[=xpath.filter('./Project/GUID/text()', dataset)]' ;
    process:hasName '[=xpath.filter('./Project/Name/text()', dataset)]' ;
    process:hasCreationDate '[=xpath.filter('./Project/CreationDate/text()', dataset)]'^^<http://www.w3.org/2001/XMLSchema#dateTime>;
    process:hasCost data:cost/[=xpath.filter('./Project/GUID/text()', dataset)] ;
    process:isPlannedIn data:interval/[=xpath.filter('./Project/GUID/text()', dataset)] .
<#list xpath.filter('./Project/Tasks/Task[*]',dataset)>
<#items as task>
data:task/[=xpath.filter('./Task/GUID/text()', task)]
    a process:Task ;
    process:taskId '[=xpath.filter('./Task/GUID/text()', task)]' ;
    process:taskUid '[=xpath.filter('./Task/UID/text()', task)]' ;
    process:hasName '[=xpath.filter('./Task/Name/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasCreationDate '[=xpath.filter('./Task/CreationDate/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
    process:isPlannedIn data:interval/[=xpath.filter('./Task/GUID/text()', task)] ;
    process:hasPriority '[=xpath.filter('./Task/Priority/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#integer> ;
    process:hasProgress '[=xpath.filter('./Task/RemainingWork/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasStatus '[=xpath.filter('./Task/ActualWork/text()', task)]'^^<http://www.w3.org/2001/XMLSchema#string> ;
    process:hasCost data:cost/[=xpath.filter('./Task/GUID/text()', task)] .
    <#if xpath.filter('./Task/Childs',task)?trim != ''>
    data:task/[=xpath.filter('./Task/GUID/text()', task)]
        process:hasChild
        <#assign childs = xpath.filter("./Task/Childs/WBS/text()",task)>
        <#if childs?is_sequence>
            <#list childs as child>
                [=child]
            </#list>
        <#else>
             [=childs]
        </#if>
    <#else>
    ...
    </#if>
</#items>
</#list>