Skip to content

Support reserved character "@" to be used in predicate naming #4897

@MichelDiz

Description

@MichelDiz

Experience Report

reference: https://discuss.dgraph.io/t/support-json-ld-on-dgraph/7162

What you wanted to do

Have the possibility to insert JSON-LD directly into Dgraph instead of having to convert the entire dataset manually.

What you actually did

I tried to run a JSON-LD with JSON mutation.

{
   "set": [
      {
         "@context": "http://schema.org/",
         "@type": "Movie",
         "name": "Avatar",
         "Director": {
            "@type": "Person",
            "name": "James Cameron",
            "birthDate": "1954-08-16"
         },
         "genre": "Science fiction",
         "trailer": "../movies/avatar-theatrical-trailer.html"
      }
   ]
}

Why that wasn't great, with examples

The "@" character is a character reserved for language support. However, it is a character that is used between two words and not at the beginning of a word. Therefore, it makes no sense to reserve it that way.

Releasing this character would have a "kind of JSON-LD support".

This would be a good step to allow different RDF based datasets to be loaded into Dgraph.

Any external references to support your case

Code reference
https://github.com/dgraph-io/dgraph/blob/2a091db1608e4d3035f5f51546e67f5ff6c0b13b/worker/mutation.go#L356

User comment about JSON-LD
#1 (comment)

Also check
#616

Tests I made with other characters

Can not be mutate

_: b0 <@context> "test".
_: b0 <\ context> "test".
_: b0 <\ context> "test".
_: b0 <~ context> "test".
_: b0 <^ context> "test".
_: b0 <`context>" test ".
_: b0 <{context> "test".
_: b0 <} context> "test".

Can

_: b0 <´context> "test".
_: b0 <[context> "test".
_: b0 <] context> "test".
_: b0 <'context> "test".

Captura de Tela 2020-03-07 às 18 33 12

Other JSON-LD examples:

{
  "@context": "http://schema.org/",
  "@type": "Person",
  "name": "Jane Doe",
  "jobTitle": "Professor",
  "telephone": "(425) 123-4567",
  "url": "http://www.janedoe.com"
}
{
  "@context": {
    "ical": "http://www.w3.org/2002/12/cal/ical#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "ical:dtstart": {
      "@type": "xsd:dateTime"
    }
  },
  "ical:summary": "Lady Gaga Concert",
  "ical:location": "New Orleans Arena, New Orleans, Louisiana, USA",
  "ical:dtstart": "2011-04-09T20:00:00Z"
}
{
  "@context": {
    "name": "http://schema.org/name",
    "description": "http://schema.org/description",
    "image": {
      "@id": "http://schema.org/image",
      "@type": "@id"
    },
    "geo": "http://schema.org/geo",
    "latitude": {
      "@id": "http://schema.org/latitude",
      "@type": "xsd:float"
    },
    "longitude": {
      "@id": "http://schema.org/longitude",
      "@type": "xsd:float"
    },
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "name": "The Empire State Building",
  "description": "The Empire State Building is a 102-story landmark in New York City.",
  "image": "http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg",
  "geo": {
    "latitude": "40.75",
    "longitude": "73.98"
  }
}
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "@type": "Create",
  "actor": {
    "@type": "Person",
    "@id": "acct:sally@example.org",
    "name": "Sally"
  },
  "object": {
    "@type": "Note",
    "content": "This is a simple note"
  },
  "published": "2015-01-25T12:34:56Z"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalearea/mutationsRelated to mutations JSON or RDF.area/parsingIssues related to the parser or lexer.dgraphIssue or PR created by an internal Dgraph contributor.kind/bugSomething is broken.priority/P3Low priority, something to be done once everything else seems fixed.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions