New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modeling enumeration values semantically #997
Comments
I think this is a valid use case, however the example solution would not work since a TD consumer should understand it as sending exactly {
//...
"oneOf": [
{ "type": "string", "const":"on","@type":"myont:on" },
{ "type": "string", "const":"off","@type":"myont:off" },
{ "type": "string", "const":"auto","@type":"myont:auto" }
]
} |
Hi @egekorkan, many thanks for the feedback. I wasn't really hoping that that idea would work :-) For my understanding, would the following also work? {
"oneOf": [
{ "@id": "myont:on" },
{ "@id": "myont:off" },
{ "@id": "myont:auto" }
]
} I tried to express here that consumer should interact using IRIs with the thing. |
Theoretically yes if you want to annotate properly but |
Well, After further thinking, I understand that my essential need is enumerations of IRIs, instead of enumerations of strings or numbers. Once I have IRIs, I can relate them to an ontology, add specific protocol conversions, add translations... So going for IRIs, this would be my attempt: {
"oneOf": [
{ "const": {"@id": "myont:on" } },
{ "const": {"@id": "myont:off" } },
{ "const": {"@id": "myont:auto" } }
]
} From JSON schema POV: I would require the value to be an object type of one of the three values. Interpreting with JSON-LD support would further conclude that these are individuals with given IRIs. On this basis, I can add protocol bindings: {
"@id": "myont:on",
"htv:body": "on",
} This way on HTTP-level simple strings (on, off, auto) would be transmitted, while a thing consumer works with the linked IRIs. I can also extend it further with translations and other mechanisms. This is maybe a nicer solution than your "messy" one, but I understand that one would be more robust in that it would also work with non-JSON-LD-aware clients. |
I also agree but some are hard coding the meaning/parsing of DataSchema keywords rather than using JSON Schema based approaches. Regarding the rest, I am not sure if I understand everything. As far as I know, |
I cannot decide whether the issue here is more or less solved or not. Otherwise we should involve members from JSON Schema or JSON-LD here. |
@sebastiankb, @egekorkan, sorry I couldn't respond for a while. In summary, I think we found two alternative solutions: Alt. 1Example: {
"oneOf": [
{ "const": {"@id": "myont:on" } },
{ "const": {"@id": "myont:off" } },
{ "const": {"@id": "myont:auto" } }
]
}
Alt. 2{
"oneOf": [
{ "const":"on","@type":"myont:on" },
{ "const":"off","@type":"myont:off" },
{ "const":"auto","@type":"myont:auto" }
]
} //
ConclusionWe found ways to solve this problem, without needing to extend TD spec. IMHO Alt. 2 looks better. I think we can close this issue. Many thanks for the discussion. |
I also like the second alternative. However, I think that this can be included in the spec on how to provide such information on enum values. I am quite sure that there are others who would be interested. Even putting |
After examining JSON-LD mechanisms further, I came up with another (IMO better) alternative: Alt. 3"@context": {"const": {"@type": "@vocab", "@context": {"on": "myont:On", "off": "myont:Off", "auto": "myont:Auto"}}},
"oneOf": [
{"const": "on"},
{"const": "off"},
{"const": "auto"}
]
Please also see the example in JSON-LD playground. The expanded form shows that the enum values are expanded to IRIs. @egekorkan I understand this is all possible via context extension, foreseen in the spec. Do you think an extension to the spec is still necessary? We could provide an example, but I don't see an extension necessary at the moment. |
I sadly don't understand the example but that is my problem :) However, JSON LD playground throws an error. |
Ok :-), I try to dissect the example: The first
Then when I use these terms as simple strings, they will be expanded to IRIs as defined by the context. If parser doesn't understand JSON-LD, I tried the playground again, it worked for me. What do you get as the error message? |
This issue pointed to while discussing: ietf-wg-asdf/SDF#8 |
Alternative #2 above is closest to the semantic annotation pattern we use for events, actions, properties, and data fields of complex data schemas in similar other TD examples. It also allows adding labels, descriptions, and localization hints. I'd also recommend using "anyOf" (see the referenced ASDF discussion above - ietf-wg-asdf/SDF#8 ) . Here is an example using OneDM style example URIs.
|
The file uploaded to OneDM that this references looks like this:
You could also add some more "@type" statements to the TD to annotate the TD itself, and its properties and actions:
|
Some new discussion on this:
{
//...
"enum":[4,6,123],
"enumMap":{
// the map uses array indexes. This way, we are not coupled to value types in enum
"0": {"description":"Lowest speed for fan","@type":"myOnto:lowSpeed"}
"1": {"description":"Medium speed for fan","@type":"myOnto:midSpeed"}
"2": {"description":"Maxium speed for fan","@type":"myOnto:maxSpeed"}
}
} @lu-zero This also relates to the data mapping discussion. This is a rather common use case in bacnet devices. |
The overlap between in the end enum is an oneOf of consts w/out the chance to use additional metadata fields from DataSchema. |
Enumerations are used commonly in automation systems, a simple example would be a property having the value range "on", "off" or "auto". Building automation in particular uses them frequently via the multistate objects in BACnet.
TD spec. defers to JSON schema for data modeling. JSON schema provides the enum keyword for describing enumerations, however one can only describe primitives (numbers, strings), but cannot assign semantics to these enum values.
If we could assign semantics to enumerated values via a well-defined URI coming from an ontology, we could:
How could this be solved? Would a simple solution such as interpreting JSON schema's enum keyword via context extension work? For instance: instead of
enum: ["on", "off", "auto"]
we would useenum: ["myont:on", "myont:off", "myont:auto"]
wheremyont
is specified in@context
.p.s. I use enumerated value to refer to a member (e.g. "on") of an enumeration, where enumeration refers to the whole grouping "on", "off", "auto". I think if we can model enumerated values semantically, different groupings of them in different enumerations can be sufficiently handled in the data model with existing
enum
mechanism.See also
Google Digital Buildings refers to this need as well: https://github.com/google/digitalbuildings/blob/master/ontology/docs/ontology.md#multi-state-values
The text was updated successfully, but these errors were encountered: