lanthaler / JsonLD

JSON-LD processor for PHP
MIT License
335 stars 62 forks source link

Problem parsing relative @id #78

Closed rhiaro closed 7 years ago

rhiaro commented 7 years ago

When I parse expanded JSON-LD with an @id with an empty string value or a string that doesn't start with http the results are weird. It should be treated as a relative URI. For example:

$quads = \ML\JsonLD\JsonLD::toRdf($data);

where $data is:

[
  {
    "http://www.w3.org/ns/activitystreams#object": [
      {
        "@id": "https://rhiaro.co.uk/2016/09/57dfffa1b5bfb"
      }
    ],
    "http://www.w3.org/ns/activitystreams#target": [
      {
        "@id": "https://linkedresearch.org/ldn/"
      }
    ],
    "@id": "#this",
    "@type": [
      "http://www.w3.org/ns/activitystreams#Announce"
    ]
  }
]

results in the subject of all triples being literally the string: "[ { "http://www.w3.org/ns/activitystreams#this

and

[
  {
    "@id": "",
    "@type": [
      "https://www.w3.org/ns/activitystreams#Announce"
    ],
    "https://www.w3.org/ns/activitystreams#object": {
      "@id": "https://linkedresearch.org/annotation/rhiaro/thesis/fe2273f6-ed65-4100-87b7-ce89a2b317b4"
    },
    "https://www.w3.org/ns/activitystreams#target": {
      "@id": "https://rhiaro.github.io/thesis/#abstract"
    },
    "https://www.w3.org/ns/activitystreams#updated": {
      "@type": "http://www.w3.org/2001/XMLSchema#dateTime",
      "@value": "2017-04-05T08:04:31.637Z"
    },
    "http://schema.org/license": {
      "@id": "https://creativecommons.org/licenses/by/4.0/"
    },
    "@context": [
      "https://www.w3.org/ns/activitystreams",
      {
        "oa": "http://www.w3.org/ns/anno.jsonld"
      }
    ]
  }
]

results in: [ { "@id": "", "@type": [ "https://www.w3.org/ns/activitystreams for the subject. ie.

<[  {    "@id": "",    "@type": [      "https://www.w3.org/ns/activitystreams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/ns/activitystreams#Announce> .
<[  {    "@id": "",    "@type": [      "https://www.w3.org/ns/activitystreams> <http://schema.org/license> <https://creativecommons.org/licenses/by/4.0/> .
<[  {    "@id": "",    "@type": [      "https://www.w3.org/ns/activitystreams> <https://www.w3.org/ns/activitystreams#object> <https://linkedresearch.org/annotation/rhiaro/thesis/fe2273f6-ed65-4100-87b7-ce89a2b317b4> .
<[  {    "@id": "",    "@type": [      "https://www.w3.org/ns/activitystreams> <https://www.w3.org/ns/activitystreams#target> <https://rhiaro.github.io/thesis/#abstract> .
<[  {    "@id": "",    "@type": [      "https://www.w3.org/ns/activitystreams> <https://www.w3.org/ns/activitystreams#updated> "2017-04-05T08:04:31.637Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .

It's like it's taking everything from the begining of the JSON-LD blob and continuing until it reaches the end of a URI?

Update: I tried passing a base and got the same result.

rhiaro commented 7 years ago

NEVER MIND I messed around with the base parameter some more and it worked. No idea what I did wrong the first time.