问题
How can I access two seperate vocabs in JSON-LD, can I use 2 @contexts? e.g.
{
"@context": {
"@vocab": "http://schema.org/",
"first_name": "givenName",
"last_name": "familyName
}
"@context": {
"@vocab": "http://our_own_schema.org/",
"Time": "inputTime"
}
}
回答1:
You can provide multiple @context
. If they contain duplicated terms, the most recently defined term gets used. See examples 27 and 28. But if you want to mix vocabularies within the same object, this doesn’t work.
To allow mixing vocabularies within the same object, you could define all vocabularies in the @context
at the top of the document. Each vocabulary can have a prefix, which allows you to use compact IRIs. One vocabulary can be the default one (without prefix).
With default vocabulary:
"@context": [ "http://schema.org/", {"oos": "http://our_own_schema.org/"} ],
The key
name
expands tohttp://schema.org/name
,
the keyoos:name
expands tohttp://our_own_schema.org/name
.Without default vocabulary:
"@context": { "schema": "http://schema.org/", "oos": "http://our_own_schema.org/" },
The key
name
would be ignored,
the keyschema:name
expands tohttp://schema.org/name
,
the keyoos:name
expands tohttp://our_own_schema.org/name
.
Note: It’s always possible to use absolute IRIs as keys. You don’t have to define these in a context.
来源:https://stackoverflow.com/questions/47227586/multiple-contexts-in-json-ld