Skip to content

Latest commit

 

History

History
171 lines (150 loc) · 3.95 KB

serializations.md

File metadata and controls

171 lines (150 loc) · 3.95 KB

aREF serializations

An aREF document can be expressed both in data structuring languages (JSON, YAML...) and in type systems of programming languages (Python, Ruby, Perl...).

The following examples express the same aREF document in different languages. The RDF graph encoded in aREF can be expressed in Turtle syntax as following:

```turtle @prefix dct: . @prefix foaf: .

http://example.com/people#alice a foaf:Person ; foaf:name "Alice Smith" ; foaf:age 42 ; foaf:homepage http://personal.example.org/~alice/, http://work.example.com/asmith/ ; foaf:knows [ foaf:name "John" ; dct:description "a nice guy"@en ] .

</div>

<div class="note">
Please add your favorite data or programming language at
<https://github.com/gbv/aREF/issues> to be included here!
</div>

### YAML {.unnumbered}

The most condensed readable serialization of aREF is probably possible in
**YAML**:

<div class="example">
```yaml
---
_ns: 
    dct: http://purl.org/dc/terms/
    foaf: http://xmlns.com/foaf/0.1/
_id: http://example.com/people#alice
a: foaf_Person
foaf_name: Alice Smith
foaf_age: 42^xsd_integer 
foaf_homepage: 
    - http://personal.example.org/~alice/ 
    - http://work.example.com/asmith/ 
foaf_knows:
    _id: _:1
    foaf_name: John
    dct_description: a nice guy@en

JSON {.unnumbered}

The same in JSON requires more brackets and delimiters:

```json { "_ns": { "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/" }, "_id": "http://example.com/people#alice", "a": "foaf:Person", "foaf_name": "Alice Smisth", "foaf_age": "42^xsd_integer", "foaf_homepage": [ "http://personal.example.org/~alice/", "http://work.example.com/asmith/" ], "foaf_knows": { "_id": "_:1", "foaf_name": "John", "dct_description": "a nice guy@en" } } ```

JavaScript {.unnumbered}

In JavaScript one can omit quotes around map keys by using underscores for prefixed names:

```javascript { _ns: { dct: 'http://purl.org/dc/terms/', foaf: 'http://xmlns.com/foaf/0.1/' }, _id: 'http://example.com/people#alice', a: 'foaf:Person', foaf_name: 'Alice Smisth', foaf_age: '42^xsd_integer', foaf_homepage: [ 'http://personal.example.org/~alice/', 'http://work.example.com/asmith/' ], foaf_knows: { _id: '_:1', foaf_name: 'John', dct_description: 'a nice guy@en' } } ```

Perl {.unnumbered}

Similar rules apply to aREF in Perl:

```perl { _ns => { dct => 'http://purl.org/dc/terms/', foaf => 'http://xmlns.com/foaf/0.1/', }, _id => 'http://example.com/people#alice', a => 'foaf:Person', foaf_name => 'Alice Smith', foaf_age => '42^xsd_integer', foaf_homepage => [ 'http://personal.example.org/~alice/', 'http://work.example.com/asmith/' ], foaf_knows => { _id => '_:1' foaf_name => 'John', dct_description => 'a nice guy@en', } } ```

PHP {.unnumbered}

Although PHP does not fully differntiate arrays and maps, one can express both. A PHP array is a map unless all PHP array keys are numeric:

```php [ "_ns" => [ "dct" => "http://purl.org/dc/terms/", "foaf" => "http://xmlns.com/foaf/0.1/" ], "_id" => "http://example.com/people#alice", "a" => "foaf_Person", "foaf_name" => "Alice Smith", "foaf_age" => "42^xsd_integer", "foaf_homepage" => [ "http://personal.example.org/~alice/", /* key "0" */ "http://work.example.com/asmith/" /* key "1" */ ], "foaf_knows" => [ "_id" => "_:1", "foaf_name" => "John", "dct_description" => "a nice guy@en" ] ]; ```