Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of @vocab in JSON-LD and what is the difference to @context?

Tags:

rdf

json-ld

What is the @vocab attribute in JSON-LD for? As I see it you can "import" a remote vocabulary, but isn't this the same you can do with @context? If I'm not wrong then you can "import" a remote source for @context as well. So where is the difference between @vocab and @context?

Extra question: Can I have more then one @vocab? For example the first referrers to schema.org and the other to rdfs?

like image 787
el-lugy Avatar asked Jun 19 '15 19:06

el-lugy


1 Answers

@vocab is used specifically to declare a default vocabulary from which all terms derive, without having to declare specific mappings for each term (as you normally do in a @context).

For example, see this snippet (taken from the JSON-LD 1.0 spec):

{
  "@context": {
    "@vocab": "http://schema.org/"
  }
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Brew Eats"
  ...
}

In this fragment, @vocab is used to define that in this context, all terms derive from the schema.org vocabulary. So in the following fragments, Restaurant maps to http://schema.org/Restaurant, and name maps to http://schema.org/name. You could of course have done this with explicit mappings in the @context as well:

{
  "@context": {
    "Restaurant": "http://schema.org/Restaurant",
    "name" : "http://schema.org/name" 
  }
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Brew Eats"
  ...
}

but this quickly becomes tedious as you start using more and more terms from the same vocabulary. @vocab is just a useful short way to say: "if I don't have an explicit mapping for a term, this is what it maps to".

As for whether you can use more than one @vocab: you can have more than one @vocab in a JSON-LD document (just as you can have more than one @context), but you can not have more than one in the same @context. I trust that the explanation that it defines a default also makes it clear why you can't have two in the same context.

like image 199
Jeen Broekstra Avatar answered Oct 12 '22 07:10

Jeen Broekstra