I have properties in my model which have value as alternate array (which indicates a collection of alternates from which only one value is to be chosen). Earlier I was using RDF/XML to do this using rdf:Alt. See the following example
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://ns.example.com/example/">
<rdf:Description>
<ex:prop1>
<rdf:Alt>
<rdf:li>100</rdf:li>
<rdf:li>120</rdf:li>
<rdf:li>130</rdf:li>
</rdf:Alt>
</ex:prop1>
</rdf:Description>
</rdf:RDF>
But now I want to do same thing in JSON-LD. I tried converting the above snippet to JSON-LD by online converter and got the following result
{
"@context": {
"ex": "http://ns.example.com/example/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph": [
{
"@id": "_:g70327238021300",
"ex:prop1": {
"@id": "_:g70327280101680"
}
},
{
"@id": "_:g70327280101680",
"@type": "rdf:Alt",
"rdf:_1": "100",
"rdf:_2": "120",
"rdf:_3": "130"
}
]
}
Actually I found out that rdf:Alt/Seq/Bag are marked as archaic by w3c. There is @list and @set for ordered and unordered arrays respectively in JSON-LD. So is there any other way to do this in JSON-LD without using "rdf:Alt" as @type?
RDFS
In RDFS, there exist RDF Containers (RDF:Container
) and RDF Collections (rdf:List
). The difference is that containers are open, whereas collections are closed, see also this question.
There are three kinds of rdf:Container
: rdf:Bag
, rdf:Seq
and rdf:Alt
.
There is not formal (i.e. semantic) difference between these kind of containers, the difference is rather pragmatic. The difference is in what the consumer is intended to do with the data, see this question.
Strictly speaking, both RDF Collections and RDF Containers are not parts of RDF data model, but rather elements of a particular RDF vocabulary (though this vocabulary is very common).
JSON-LD
JSON-LD data model is not well aligned with RDF, see e.g this article of one of the primary creators.
Mapping
From RDFS 1.1:
The same resource may appear in a container more than once.
The first member of the container, i.e. the value of the
rdf:_1
property, is the default choice.
Thus, in general, elements of rdf:Alt
are not unique, but ordered.
Hence, one should use @list
. However, if your alternatives are unique and unordered, you could use @set
.
In other cases, be aware that there is not any harm in asserting an order when there isn't any.
See also ISSUE-24 for discussion and motivation.
UPDATE
Yes, it is impossible to express pragmatic (i.e. related to language pragmatics) differences in the JSON-LD data model. For instance, it is impossible to express the difference between rdf:Seq
and rdf:Alt
. If you want to express these differences, you need a vocabulary.
RDFS is a kind of such vocabulary. Use JSON-LD as a serialization format for RDF abstract syntax and write "@type": "rdf:Alt"
etc. as you previously did.
Probably, you are confused by the abundance of surrogate @id
's in your JSON-LD. Just do not use blank nodes in your RDF, then JSON-LD will look like this:
{
"@context": {
"ex": "http://example.com/example/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph": [
{
"@id": "ex:object1",
"ex:availableOptions": {
"@id": "ex:optionsFor1"
}
},
{
"@id": "ex:optionsFor1",
"@type": "rdf:Alt",
"rdf:_1": "100",
"rdf:_2": "120",
"rdf:_3": "130"
}
]
}
Another option is to use another vocabulary, e.g. schema.org. I'm not sure that this example is correct:
{
"@context": {"schema": "http://schema.org/",
"adobe" : "http://ns.adobe.com/xap/1.0/smp/"},
"@type": "schema:ChooseAction",
"@id": "adobe:price",
"schema:option": ["100", "120", "130"]
}