geojson / geojson-ld

GeoJSON in JSON-LD contexts
Other
130 stars 13 forks source link

Aliasing id and type in context breaks JSON-LD parsers #39

Closed sgillies closed 8 years ago

sgillies commented 8 years ago

I've found a huge problem with the GeoJSON-LD contexts in this repo.

The aliasing of @id to id at https://github.com/geojson/geojson-ld/blob/master/contexts/geojson-base.jsonld and the aliasing of @type to type at https://github.com/geojson/geojson-ld/blob/master/contexts/geojson-base.jsonld#L27 breaks the http://json-ld.org/playground/ parser.

It says at http://www.w3.org/TR/json-ld/#aliasing-keywords

Since keywords cannot be redefined, they can also not be aliased to other keywords.

My interpretation was that "@id" was the keyword, not "id", but it seems I'm wrong. I remember running the contexts through the JSON-LD playground in the past without trouble, but that could be a bogus memory.

The consequence: ordinary GeoJSON can not be converted to JSON-LD merely by attaching one of this project's context docs. You'd actually need to edit the GeoJSON doc itself. A lot of my ambitions for this GeoJSON-LD project are going up in smoke.

Anybody else have a different take?

sgillies commented 8 years ago

I may have a separate problem in my example. See https://github.com/geojson/geojson-ld/issues/38#issuecomment-152583752.

letmaik commented 8 years ago

See https://github.com/geojson/geojson-ld/issues/38#issuecomment-152583752

sgillies commented 8 years ago

@neothemachine thanks!

letmaik commented 8 years ago

The parser complains because there is a comma too much in the context document. JSON doesn't allow superfluous commas.

sgillies commented 8 years ago

@neothemachine but even when that's fixed, I get

{
  "name": "jsonld.CompactError",
  "message": "Could not expand input before compaction.",
  "details": {
    "cause": {
      "name": "jsonld.SyntaxError",
      "message": "Invalid JSON-LD syntax; colliding keywords detected.",
      "details": {
        "code": "colliding keywords",
        "keyword": "@type"
      }
    }
  }
}
letmaik commented 8 years ago

Ah, you're right, I didn't try to use type and @type both together. Interesting, I also thought that worked in the past.

mitar commented 8 years ago

I am not sure what is the issue here. The following example works for me well:

{ 
  "@context": {
    "geojson": "http://ld.geojson.org/vocab#",
    "Feature": "geojson:Feature",
    "FeatureCollection": "geojson:FeatureCollection",
    "GeometryCollection": "geojson:GeometryCollection",
    "LineString": "geojson:LineString",
    "MultiLineString": "geojson:MultiLineString",
    "MultiPoint": "geojson:MultiPoint",
    "MultiPolygon": "geojson:MultiPolygon",
    "Point": "geojson:Point",
    "Polygon": "geojson:Polygon",
    "bbox": {
      "@container": "@list",
      "@id": "geojson:bbox"
    },
    "coordinates": "geojson:coordinates",
    "description": "http://purl.org/dc/terms/description",
    "features": {
      "@container": "@set",
      "@id": "geojson:features"
    },
    "geometry": "geojson:geometry",
    "id": "@id",
    "properties": "geojson:properties",
    "title": "http://purl.org/dc/terms/title",
    "type": "@type"
  },
  "type": "FeatureCollection",
  "id": "http://example.com/collections/1",
  "features": [
    { 
      "type": ["Feature", "Place"],
      "id": "http://example.com/collections/1/features/1",
      "properties": {"name": "Fort Collins, Colorado" },
      "geometry": {"type": "Point", "coordinates": [-105.078056, 40.559167]}
    },
    { 
      "type": ["Feature", "Place"],
      "id": "http://example.com/collections/1/features/2",
      "properties": {"name": "Boulder, Colorado" },
      "geometry": {"type": "Point", "coordinates": [-105.251945, 40.027435]}
    }
  ]
}

I combined the example from README with the context linked above.

The issue is of course that you cannot use both id and @id at the same time. But I think this is a reasonable restriction?

letmaik commented 8 years ago

@mitar This is not valid GeoJSON anymore as "type" must be a string.

mitar commented 8 years ago

Then make it only one of those types? Whatever is reasonable for GeoJSON use?