3

Is there a way to always force single objects to arrays with EasyRdf?

If there are multiple values as rdf:type I get an array like this one. Note the @type property is an array.

{
    "@context": {
        "ethon": "http://ethon.consensys.net/",
        "ethstats": "http://ethereum.ethstats.io/"
    },
    "@graph": [{
        "@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
        "@type": ["ethon:Uncle", "ethon:Block"],
        "ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
        "ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
        "ethon:number": "1"
    }]
}

But if there is only one rdf:type the @type property is not an array.

{
    "@context": {
        "ethon": "http://ethon.consensys.net/",
        "ethstats": "http://ethereum.ethstats.io/"
    },
    "@graph": [{
        "@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
        "@type": "ethon:Uncle",
        "ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
        "ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
        "ethon:number": "1"
    }]
}

When serializing the graph, I send to EasyRdf the options

'frame' => (object) [
    '@context' => (object) [
        'ethon' => 'http://ethon.consensys.net/',
        'ethstats' => 'http://ethereum.ethstats.io/',
],

Is there a way to send the @set option for the rdf:type / @type property?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Daniel Luca CleanUnicorn
  • 1,087
  • 1
  • 12
  • 30

1 Answers1

0

Yes! When framing, pass additionally the @context option:

"@context": {
    ...
    "@type": {"@container": "@set"}
}

See it in use.
(Click on Flattened and (back to) Framed tab if for some reason it doesn't show correctly on load.)

K3---rnc
  • 6,717
  • 3
  • 31
  • 46