3

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?

Anjan Kaur
  • 33
  • 3

2 Answers2

1

The rdf:li expansion in to rdf:_n is a feature of RDF/XML, which is really the only format to provide native support for rdf:Alt/Bag/Seq. As you note, these are considered archaic, so don't look for any native support in other serializations, including JSON-LD.

For other ways of collecting information, other than RDF Collections, which have semantic support in RDF Concepts, and are directly supported by most RDF serializations, look to ontologies such as the Ordered List Ontology, which shows how you might do something similar to rdf:Alt semantics using semantics, rather than syntax.

For example, schema.org has a Choose Action, which seems like it is similar to what you want to do. The related Vote Action is also similar.

Gregg Kellogg
  • 1,831
  • 12
  • 8
1

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.

  • JSON-LD ignores the difference between open and closed.
  • JSON-LD ignores the aforementioned pragmatic differences.
  • JSON-LD keeps the difference between ordered and unordered.
  • JSON-LD keeps the difference between (lexically) non-distinct and distinct,
    identifying this difference with the previous one.

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"]
}
Community
  • 1
  • 1
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • Thanks for the [link](https://stackoverflow.com/questions/29001433/how-rdfbag-rdfseq-and-rdfalt-is-different-while-using-them/29012938#29012938). As you mentioned, rdf:Alt/Seq/Bag basically tell the user what is intended do with the data. Intent of rdf:Alt is that one item is required from the collection of items. Whereas rdf:Seq is ordered list where all items are required. So if I am using @list for both of these in JSON-LD, user won't be able to distinguish between the intent of these two. – Anjan Kaur Jul 10 '17 at 19:53
  • @AnjanKaur, I'm glad you understand. – Stanislav Kralin Jul 11 '17 at 06:56
  • Yeah, for my purpose @list can't be used. As I need to make this intent clear to the user. But you mentioned in your answer that one should use "@list", Am I missing something? – Anjan Kaur Jul 11 '17 at 11:54
  • Unfortunately, it is impossible to express this pragmatic (i.e. related to the language pragmatics) intention in JSON-LD data model. One have to use a vocabulary, e.g RDFS. – Stanislav Kralin Jul 11 '17 at 12:09
  • 1
    Your example is not correct. From what I have http://schema.org/optionseen, [option](http://schema.org/option) is used with [Choose](http://schema.org/ChooseAction) like gregg mentioned. So you have to add "@type": "schema:ChooseAction" in your example for it to work. – Anjan Kaur Jul 13 '17 at 06:40
  • Most likely, you are right. I have fixed my example. BTW, in XMP vocabulary, there exists something called `Choice` ([p. 22](https://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/cs6/XMPSpecificationPart1.pdf)). – Stanislav Kralin Jul 13 '17 at 07:02