cRML - Bind Condition


RML takes advantage of W3C-standardized or widely-accepted vocabularies, used to advertise services or datasets, to define how to retrieve and access data sources, available on the Web or not. Such descriptions, either derived from data owners/publishers or defined by data publishers/consumers, are considered, by mapping processors, acting as clients, to be aware of how to retrieve the data. The source might be static or dynamic. If the source is dynamically created, it is often required to instantiate a template, e.g., a URI template or a SQL/SPARQL query template. In these cases, the template is instantiated with values provided by the user who executes the mapping or the variables might be replaced with values derived from another input source (e.g. Referencing Object Maps).



<#TriplesMapX> rml:logicalSource <#InputX> .
@prefix hydra : <http://www.w3.org/ns/hydra/core#> .

<#InputX>
    rml:source <#API_template_source> ;
    rml:referenceFormulation ql:JSON;
    rml:iterator "$".

<#API_template_source>
    a hydra:IriTemplate
    hydra:template "https://biblio.ugent.be/publication/{id}?format={format}";
    hydra:mapping
        [ a hydra:TemplateMapping ;
          hydra:variable "id";
          hydra:required true ],
        [ a hydra:TemplateMapping ;
          hydra:variable "format";
          hydra:required false ] .
                             
A Triples Map mapping data from a Web API, described using Hydra, whose template is instantiated with certain values.

@prefix rml : <http://semweb.mmlab.be/rml#> .
@prefix d2rq : <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .

<#TriplesMapV> rml:logicalSource <#InputV> .

<#InputV>
    rml:source <#DB_source> ;
    rr:sqlVersion rr:SQL2008;
    rr:sqlQuery """
SELECT DEPTNO, DNAME, LOC,
       (SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO = %%DEPTNO%%) AS STAFF
FROM DEPT; """ .

<#DB_source>
    a d2rq:Database;
    d2rq:jdbcDSN "jdbc:mysql://localhost/example";
    d2rq:jdbcDriver "com.mysql.jdbc.Driver";
    d2rq:username "username";
    d2rq:password "password" .
                             
A Triples Map mapping data result of a query against a database.
The details regarding how the connection to the DB is established are described using D2RQ.

@prefix rml : <http://semweb.mmlab.be/rml#> .
@prefix sd : <http://www.w3.org/ns/sparql-service-description#> .

<#TriplesMapT> rml:logicalSource <#InputT> .

<#InputT>
    rml:source <#SPARQL_source> ;
    rml:referenceFormulation ql:XML;
    rml:iterator "/";
    rml:query " select distinct ?resource ?resource_label
                where { ?resource rdfs:label %%label%% } " .

<#SPARQL_source>
    a sd:Service ;
    sd:endpoint <http://dbpedia.org/sparql/> ;
    sd:supportedLanguage sd:SPARQL11Query ;
    sd:resultFormat <http://www.w3.org/ns/formats/SPARQL_Results_XML> .
                             
A Triples Map mapping data from a SPARQL endpoint, described using SPARQL-SD.
A Referencing Object Map might have a template-valued Logical Source that requires one or more values to fill in the source template. The Binding Condition specifies how the Logical Source, pointed by the Referencing Object Map, template is instantiated either with a value retrieved from the input source that is currently mapped, or with a constant value. In the first case, a reference that exists in the Logical Source of the Triples Map that contains the Referencing Object Map is provided. In the later case, a constant value is provided. If the Referencing Object Map’s Logical Source has more than one variables required, equal number of Binding Conditions is expected. A complete example follows:


@prefix rml : <http://semweb.mmlab.be/rml#> .
@prefix d2rq : <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .

<#TriplesMapA>
    rr:predicateObjectMap [
        rr:predicate foaf:account;
    rr:objectMap [
        rr:parentTriplesMap <#TriplesMapB> ;
        crml:bindCondition
            [ rml:reference "id_number" ;
              crml:condition "id" ],
            [ rr:constant "json" ;
              crml:condition "format" ]]].

<#TriplesMapB> rml:logicalSource <#InputB> ;
    rr:subjectMap [
        rr:template "http://ex.com/{account_ID}" ] .

<#InputB>
    rml:source <#API_template_source>;
    rml:referenceFormulation ql:JSONPath.

<#API_template_source>
    a hydra:IriTemplate
    hydra:template "https://biblio.ugent.be/publication/{id}?format={format}";
    hydra:mapping
        [ a hydra:TemplateMapping ;
          hydra:variable "id";
          hydra:required true ],
        [ a hydra:TemplateMapping ;
          hydra:variable "format";
          hydra:required false ] .
                             
A complete example with two Triples Maps one containing a Bind Condition.