@vocab
JSON-LD 中的属性是什么?如我所见,您可以“导入”远程词汇表,但这不与您可以做的相同@context
吗?如果我没记错,那么您也可以“导入”远程源@context
。那么@vocab
和 和有什么不一样@context
呢?
额外的问题:我可以多一个@vocab
吗?例如,第一个引用者是 schema.org,另一个是 rdfs?
@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.