Skip to content

Commit

Permalink
adaptions examples and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
elsdvlee committed Jul 16, 2024
1 parent 7d03739 commit 59099e8
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 193 deletions.
188 changes: 29 additions & 159 deletions spec/section/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,140 +246,23 @@ If no iterator is declared for a field, a default iterator is implied. If the re

For the application of the <a data-cite="RML-Core#dfn-expressions">expression</a> of a [=field=] on the records of the [=field parent=], the parent's reference formulation is used, resulting in [=record sequence=] *R*. Afterwards the field's iterator is applied on this resulting record sequence *R* to obtain the [=field record sequence=] defined by the field.

<aside class=example id=ex-mixed-format-csv-json>

In this example a [=logical view=] is defined on a <!-- TODO reference to core, dependent on https://github.com/kg-construct/rml-core/issues/127-->[logical source]() with reference formulation `rml:CSV`.
The [=field=] with [=declared name=] "item" has a declared <!-- TODO reference to core reference formulation when available-->[reference formulation]() `rml:JSONPath` and an implied iterator "$.*". First, the expression "item" is evaluated using the reference formulation of the [=field parent=]. Second, the implicit iterator of the field is applied on the resulting records.
The nested fields with [=declared name=] "type" and "weight" are evaluated using the reference formulation `rml:JSONPath' from their parent field with [=declared name=] "item" .

<aside class=ex-input>

```csv
name,item
alice,"{""type"":""sword"",""weight"":1500}"
alice, "{""type"":""shield"",""weight"":2500}"
bob,"{""type"":""flower"",""weight"":15}"
```
</aside>
<aside class=ex-mapping>

```turtle
:mixedCSVSource a rml:InputLogicalSource ;
rml:source :mixedCSVFile ;
rml:referenceFormulation rml:CSV .
:mixedCSVView a rml:LogicalView ;
rml:viewOn :mixedCSVSource ;
rml:field [
rml:fieldName "item" ;
rml:reference "item" ;
rml:referenceFormulation rml:JSONPath ;
rml:field [
rml:fieldName "type" ;
rml:reference "$.type" ; ] ;
rml:field [
rml:fieldName "weight" ;
rml:reference "$.weight" ; ] ; ] .
```

</aside>
Note some columns in the table below have been shortened for brevity.
<aside class="ex-intermediate">
<table>
<tr>
<td>#</td>
<td>

`<it>`
</td>
<td>item.#</td>
<td>item</td>
<td>item.type.#</td>
<td>time.type</td>
<td>item.weight.#</td>
<td>time.weight</td>
</tr>
<tr>
<td>0</td>
<td>alice,&quot;{...}&quot; </td>
<td>0</td>
<td>

```json
{
"type": "sword",
"weight": 1500
}
```

</td>
<td>0</td>
<td>sword</td>
<td>0</td>
<td>2500</td>
</tr>
<tr>
<td>1</td>
<td>alice,&quot;{...}&quot; </td>
<td>0</td>
<td>

```json
{
"type": "shield",
"weight": 2500
}
```

</td>
<td>0</td>
<td>shield</td>
<td>0</td>
<td>1500</td>
</tr>
<tr>
<td>2</td>
<td>bob,&quot;{...}&quot; </td>
<td>0</td>
<td>

```json
{
"type": "flower",
"weight": 15
}
```

</td>
<td>0</td>
<td>flower</td>
<td>0</td>
<td>15</td>
</tr>
</table>
</aside>

</aside>


<aside class=example id=ex-mixed-format-json-csv>

In this example a [=logical view=] is defined on a <!-- TODO reference to core, dependent on https://github.com/kg-construct/rml-core/issues/127-->[logical source]() with reference formulation `rml:JSONPath`.
The [=field=] with [=declared name=] "hobbies" has a declared <!-- TODO reference to core reference formulation when available-->[reference formulation]() `rml:CSV` and CSV row as implicit iterator.
First the expression "$.hobbies" is evaluated using the reference formulation of the [=field parent=]. Then the field's reference formulation and iterator is applied on the resulting records.
The nested fields with [=declared name=] "id" and "type" are evaluated using the reference formulation `rml:CSV` from their parent field with [=declared name=] "hobbies" .
<aside class=ex-input>
The [=field=] with [=declared name=] "item" has a declared <!-- TODO reference to core reference formulation when available-->[reference formulation]() `rml:CSV` and CSV row as implicit iterator.
First the expression "$.items" is evaluated using the reference formulation of the [=field parent=]. Second, the implicit iterator of the field is applied on the resulting records.
The nested fields with [=declared name=] "type" and "weight" are evaluated using the reference formulation `rml:CSV` from their parent field with [=declared name=] "item".

```json
{
"people": [
{
"name": "alice",
"hobbies": "id;type\n1;volleyball\n2;basketball\n3;horses"
"items": "type,weight\nsword,1500\nshield,2500"
},
{
"name": "bob",
"hobbies": "id;type\n1;football"
"items": "type,weight\nflower,15"
}
]
}
Expand All @@ -393,21 +276,20 @@ The nested fields with [=declared name=] "id" and "type" are evaluated using the
rml:referenceFormulation rml:JSONPath ;
rml:iterator "$.people[*]" .
:jsonView a rml:LogicalView ;
:mixedJSONView a rml:LogicalView ;
rml:viewOn :mixedJSONSource ;
rml:field [
rml:fieldName "hobbies" ;
rml:reference "$.hobbies" ;
rml:referenceFormulation rml:CSV;
# implicit default iterator is CSV row
rml:field [
rml:fieldName "id" ;
rml:reference "id" ;
] ;
rml:fieldName "item" ;
rml:reference "$.items" ;
rml:referenceFormulation rml:CSV;
rml:field [
rml:fieldName "type" ;
rml:reference "type" ;
] ;
rml:field [
rml:fieldName "weight" ;
rml:reference "weight" ;
] ;
] .
```

Expand All @@ -418,12 +300,12 @@ Note some columns in the table below have been shortened for brevity.
<tr>
<td>#</td>
<td>&lt;it&gt;</td>
<td>hobbies</td>
<td>hobbies.#</td>
<td>hobbies.id</td>
<td>hobbies.id.#</td>
<td>hobbies.type</td>
<td>hobbies.type.#</td>
<td>item</td>
<td>item.#</td>
<td>item.type</td>
<td>item.type.#</td>
<td>item.weight</td>
<td>item.weight.#</td>
</tr>
<tr>
<td>0</td>
Expand All @@ -435,11 +317,11 @@ Note some columns in the table below have been shortened for brevity.
```

</td>
<td>1;volleyball</td>
<td>sword,1500</td>
<td>0</td>
<td>1</td>
<td>sword</td>
<td>0</td>
<td>volleyball</td>
<td>1500</td>
<td>0</td>
</tr>
<tr>
Expand All @@ -452,15 +334,15 @@ Note some columns in the table below have been shortened for brevity.
```

</td>
<td>2;basketball</td>
<td>shield,2500</td>
<td>1</td>
<td>2</td>
<td>shield</td>
<td>0</td>
<td>basketball</td>
<td>2500</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>

```json
Expand All @@ -470,28 +352,16 @@ Note some columns in the table below have been shortened for brevity.


</td>
<td>3;horses</td>
<td>2</td>
<td>3</td>
<td>0</td>
<td>horses</td>
<td>flower,15</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td></td>
<td>1;football</td>
<td>0</td>
<td>1</td>
<td>flower</td>
<td>0</td>
<td>football</td>
<td>15</td>
<td>0</td>
</tr>
</table>
</aside>

</aside>

### Using field names in triples maps

A <dfn>field reference</dfn> is a <a data-cite="RML-Core#dfn-reference-expression">reference expression</a> that references a defined [=field=]. A [=field reference=] MUST be a defined [=field name=]. A [=field reference=] is a special type of <a data-cite="RML-Core#dfn-reference-expression">reference expression</a> for which no reference formulation need be defined.
Expand Down
11 changes: 7 additions & 4 deletions test-cases/RMLLVTC0006/mapping.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@
rml:reference "$.type" ; ] ;
rml:field [
rml:fieldName "weight" ;
rml:reference "$.weight" ; ] ; ] .
rml:reference "$.weight" ;
] ;
] .

:triplesMapItem a rml:TriplesMap ;
rml:logicalSource :mixedCSVView ;
rml:subjectMap [
rml:template "http://example.org/person/{name}/item/{item.#}/{item_type}" ;
rml:template "item_{#}_{item.#}" ;
rml:termType rml:BlankNode ;
] ;
rml:predicateObjectMap [
rml:predicate :hasType ;
rml:objectMap [
rml:reference "item_type" ;
rml:reference "item.type" ;
] ;
] ;
rml:predicateObjectMap [
rml:predicate :hasWeight ;
rml:objectMap [
rml:reference "item_weight" ;
rml:reference "item.weight" ;
rml:datatype xsd:integer ;
] ;
] .
12 changes: 6 additions & 6 deletions test-cases/RMLLVTC0006/output.nq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<http://example.org/person/alice/item/0/sword> <http://example.org/hasType> "sword" .
<http://example.org/person/alice/item/0/sword> <http://example.org/hasWeight> "1500"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/person/alice/item/1/shield> <http://example.org/hasType> "shield" .
<http://example.org/person/alice/item/1/shield> <http://example.org/hasWeight> "2500"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/person/bob/item/0/flower> <http://example.org/hasType> "flower" .
<http://example.org/person/bob/item/0/flower> <http://example.org/hasWeight> "15"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_0_0 <http://example.org/hasType> "sword" .
_:item_0_0 <http://example.org/hasWeight> "1500"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_0_1 <http://example.org/hasType> "shield" .
_:item_0_1 <http://example.org/hasWeight> "2500"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_1_0 <http://example.org/hasType> "flower" .
_:item_1_0 <http://example.org/hasWeight> "15"^^<http://www.w3.org/2001/XMLSchema#integer> .
11 changes: 7 additions & 4 deletions test-cases/RMLLVTC0007/mapping.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@
rml:reference "$.type" ; ] ;
rml:field [
rml:fieldName "weight" ;
rml:reference "$.weight" ; ] ; ] .
rml:reference "$.weight" ;
] ;
] .

:triplesMapItem a rml:TriplesMap ;
rml:logicalSource :mixedCSVView ;
rml:subjectMap [
rml:template "http://example.org/person/{name}/item/{item.#}/{item_type}" ;
rml:template "item_{#}_{item.#}" ;
rml:termType rml:BlankNode ;
] ;
rml:predicateObjectMap [
rml:predicate :hasType ;
rml:objectMap [
rml:reference "item_type" ;
rml:reference "item.type" ;
] ;
] ;
rml:predicateObjectMap [
rml:predicate :hasWeight ;
rml:objectMap [
rml:reference "item_weight" ;
rml:reference "item.weight" ;
rml:datatype xsd:integer ;
] ;
] .
12 changes: 6 additions & 6 deletions test-cases/RMLLVTC0007/output.nq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<http://example.org/person/alice/item/0/sword> <http://example.org/hasType> "sword" .
<http://example.org/person/alice/item/0/sword> <http://example.org/hasWeight> "1500"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/person/alice/item/0/shield> <http://example.org/hasType> "shield" .
<http://example.org/person/alice/item/0/shield> <http://example.org/hasWeight> "2500"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/person/bob/item/0/flower> <http://example.org/hasType> "flower" .
<http://example.org/person/bob/item/0/flower> <http://example.org/hasWeight> "15"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_0_0 <http://example.org/hasType> "sword" .
_:item_0_0 <http://example.org/hasWeight> "1500"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_1_0 <http://example.org/hasType> "shield" .
_:item_1_0 <http://example.org/hasWeight> "2500"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:item_2_0 <http://example.org/hasType> "flower" .
_:item_2_0 <http://example.org/hasWeight> "15"^^<http://www.w3.org/2001/XMLSchema#integer> .
28 changes: 20 additions & 8 deletions test-cases/RMLLVTC0008/mapping.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,39 @@
:mixedJSONView a rml:LogicalView ;
rml:viewOn :mixedJSONSource ;
rml:field [
rml:fieldName "hobby" ;
rml:reference "$.hobbies" ;
rml:referenceFormulation rml:CSV;
rml:field [
rml:fieldName "id" ;
rml:reference "id" ;
rml:fieldName "name" ;
rml:reference "$.name" ;
] ;
rml:field [
rml:fieldName "item" ;
rml:reference "$.items" ;
rml:referenceFormulation rml:CSV;
rml:field [
rml:fieldName "type" ;
rml:reference "type" ;
] ;
rml:field [
rml:fieldName "weight" ;
rml:reference "weight" ;
] ;
] .

:triplesMapItem a rml:TriplesMap ;
rml:logicalSource :mixedJSONView ;
rml:subjectMap [
rml:template "http://example.org/person/{name}/hobby/{hobby.#}/{hobby_id}" ;
rml:template "item_{#}_{item.#}" ;
rml:termType rml:BlankNode ;
] ;
rml:predicateObjectMap [
rml:predicate :hasType ;
rml:objectMap [
rml:reference "hobby_type" ;
rml:reference "item.type" ;
] ;
] ;
rml:predicateObjectMap [
rml:predicate :hasWeight ;
rml:objectMap [
rml:reference "item.weight" ;
rml:datatype xsd:integer ;
] ;
] .
Loading

0 comments on commit 59099e8

Please sign in to comment.