How can terms in a JSON-LD context compact OWL NamedIndividuals to JavaScript objects? - protege

An expanded JSON-LD file was saved from Protege and I would like to write a context that compacts the JSON-LD such that the NamedIndividuals become Javascript objects. My JSON-LD file provides orbital parameters for planets.
I attempted to define "earth" as a term but it did not have the desired effect of replacing the #id and #type. What I'd like is a compact JSON-LD file that I can parse into an object and access parameter values with something similar to mars.inclination, or graph[i].inclination. Guidance and examples would be appreciated. Thanks.
Here is a portion yet complete JSON-LD file with the context I developed in JSON-LD Playground:
{
"#context": {
"demo": "http://example.org/demo#",
"decimal": "http://www.w3.org/2001/XMLSchema#decimal",
"owl": "http://www.w3.org/2002/07/owl#",
"label": "http://www.w3.org/2000/01/rdf-schema#label",
"comment": "http://www.w3.org/2000/01/rdf-schema#comment",
"eccentricity": {
"#id": "demo:eccentricity",
"#type": "decimal"
},
"inclination": {
"#id": "demo:inclination",
"#type": "decimal"
},
"omega": {
"#id": "demo:omega",
"#type": "decimal"
},
"sma": {
"#id": "demo:sma",
"#type": "decimal"
},
"raan": {
"#id": "demo:raan",
"#type": "decimal"
},
"tau": {
"#id": "demo:tau",
"#type": "decimal"
},
"period": {
"#id": "demo:period",
"#type": "decimal"
},
"earth": {
"#id": "demo:Earth",
"#type": "owl:namedIndividual"
}
},
"#graph": [
{
"#id": "demo:Earth",
"#type": [
"owl:NamedIndividual",
"demo:Orbit"
],
"eccentricity": "0.016708",
"inclination": "7.155",
"omega": "-11.26064",
"period": "365.256363",
"raan": "23.4392811",
"sma": "1",
"tau": "114.20783",
"label": "Earth"
},
{
"#id": "demo:Mars",
"#type": [
"owl:NamedIndividual",
"demo:Orbit"
],
"eccentricity": "0.0934",
"inclination": "5.65",
"omega": "49.558",
"period": "686.971",
"raan": "317.68143",
"sma": "1.523679",
"tau": "286.502",
"label": "Mars"
},
{
"#id": "demo:Mercury",
"#type": [
"owl:NamedIndividual",
"demo:Orbit"
],
"eccentricity": "0.20563",
"inclination": "3.38",
"omega": "48.331",
"period": "88",
"raan": "281.01",
"sma": "0.387098",
"tau": "29.124",
"label": "Mercury"
},
{
"#id": "demo:Orbit",
"#type": "owl:Class"
}
]
}

Related

Properly Create a Device Template from a Live Device in Azure IOT Central

I have LoRaWAN IoT devices from the TTN network, which I have brought to Azure IoT Central. I would like to get specific data inside the JSON in order to make alert rules. Here is a sample of the JSON I receive from a Milesight PIR & Light Sensor. Suppose I only want to get the "battery", "daylight" and "pir" values to make the alert, how do I go about that?
{
"end_device_ids": {
"device_id": "eui-24e124538c195063",
"application_ids": {
"application_id": "test-1117"
},
"dev_eui": "24E124538C195063",
"join_eui": "24E124C0002A0001",
"dev_addr": "260D82F3"
},
"received_at": "2023-02-01T13:52:47.892042526Z",
"uplink_message": {
"session_key_id": "AYYLj9wg6AeehHWwDLrzLg==",
"f_port": 85,
"f_cnt": 38,
"frm_payload": "AXVkAwAABAAA",
"decoded_payload": {
"battery": 100,
"daylight": "dark",
"pir": "normal"
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-24e124fffef5531c",
"eui": "24E124FFFEF5531C"
},
"time": "2023-02-01T13:52:47.429725885Z",
"timestamp": 2696081442,
"rssi": -64,
"channel_rssi": -64,
"snr": 13,
"uplink_token": "CiIKIAoUZXVpLTI0ZTEyNGZmZmVmNTUzMWMSCCThJP/+9VMcEKLgy4UKGgwIr93pngYQ94rGxQIg0Ino17uJFw==",
"received_at": "2023-02-01T13:52:47.596682842Z"
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "867700000",
"timestamp": 2696081442,
"time": "2023-02-01T13:52:47.429725885Z"
},
"received_at": "2023-02-01T13:52:47.683989041Z",
"confirmed": true,
"consumed_airtime": "0.061696s",
"network_ids": {
"net_id": "000013",
"tenant_id": "ttn",
"cluster_id": "au1",
"cluster_address": "au1.cloud.thethings.network"
}
},
"_eventtype": "Telemetry",
"_timestamp": "2023-02-01T13:52:49.35Z"
}
I was able to get the values by uploading my own DTDL.
Once the device sends data to Azure IOT Central from TTN, the device will have no template.
I first created a template from the raw telemetry sent.
I went to the new device template created, clicked EDIT DTDL, then placed the following JSON:
{
"#id": "dtmi:telavi:eui24e124538c195063;1",
"#type": "Interface",
"contents": [
{
"#type": [
"Telemetry",
"DateTimeValue"
],
"displayName": {
"en": "received_at"
},
"name": "received_at",
"schema": "dateTime"
},
{
"#type": [
"Telemetry",
"NumberValue"
],
"description": {
"en": "battery"
},
"displayName": {
"en": "battery"
},
"name": "battery",
"schema": "integer"
},
{
"#type": [
"Telemetry",
"StringValue"
],
"description": {
"en": "daylight"
},
"displayName": {
"en": "daylight"
},
"name": "daylight",
"schema": "string"
},
{
"#type": [
"Telemetry",
"StringValue"
],
"description": {
"en": "pir"
},
"displayName": {
"en": "pir"
},
"name": "pir",
"schema": "string"
}
],
"displayName": {
"en": "eui-24e124538c195063"
},
"#context": [
"dtmi:iotcentral:context;2",
"dtmi:dtdl:context;2"
]
}

How set desired and reported properties for device twin in IoT Plug and Play DTDL model

I have this dtdl model I upload to local folder in IoT Plug and Play v0.15.4.0 (prior version behaviour is the same):
{
"#id": "dtmi:com:sergio:devkit;1",
"#type": "Interface",
"#context": [
"dtmi:dtdl:context;2"
],
"displayName": "Machine Part -v1",
"description": "Machine Part data",
"contents": [
{
"#type": "Property",
"name": "telemetryInterval",
"displayName": "telemetryInterval",
"description": "The time interval of this data",
"schema": "double",
"writable": true
},
{
"#type": "Property",
"name": "PartId",
"displayName": "PartId",
"description": "The unique id of the machine part",
"writable": true,
"schema": "string"
},
{
"#type": "Property",
"name": "Alert",
"displayName": "Alert",
"description": "whether or not this machine part needs maintenance",
"writable": true,
"schema": "boolean"
},
{
"#type": "Property",
"name": "ledState",
"displayName": "LED state",
"description": "Returns the current state of the onboard LED.",
"writable": true,
"schema": "boolean"
},
{
"#type": "Telemetry",
"name": "Description",
"schema": "string"
},
{
"#type": "Telemetry",
"name": "Code",
"schema": "integer"
},
{
"#type": "Telemetry",
"name": "Temperature",
"displayName": "Temperature",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "Humidity",
"displayName": "Humidity",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "pressure",
"displayName": "Pressure",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "magnetometerX",
"displayName": "Magnetometer X / mgauss",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "magnetometerY",
"displayName": "Magnetometer Y / mgauss",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "magnetometerZ",
"displayName": "Magnetometer Z / mgauss",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "accelerometerX",
"displayName": "Accelerometer X",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "accelerometerY",
"displayName": "Accelerometer Y",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "accelerometerZ",
"displayName": "Accelerometer Z",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "gyroscopeX",
"displayName": "Gyroscope X",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "gyroscopeY",
"displayName": "Gyroscope Y",
"schema": "double"
},
{
"#type": "Telemetry",
"name": "gyroscopeZ",
"displayName": "Gyroscope Z",
"schema": "double"
}
]
}
My expectation is that because properties ledState and Alert properties are writeable, these should be both reported and desired properties. However the IoT Hub Device in Azure portal (see below) shows them differently and I don't know why. How do I set the properties in the DTDL model I upload to IoT P&P to be reported or desired?
{
"deviceId": "mymxchip",
"etag": "AAAAAAAAAAk=",
"deviceEtag": "NDU1NDk0NDM4",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Connected",
"lastActivityTime": "2023-01-09T07:26:48.611708Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
},
"modelId": "dtmi:com:sergio:devkit;1",
"version": 164,
"properties": {
"desired": {
"telemetryInterval": 5,
"Alert": true,
"$metadata": {
"$lastUpdated": "2023-01-08T07:27:01.9659284Z",
"$lastUpdatedVersion": 9,
"telemetryInterval": {
"$lastUpdated": "2023-01-08T06:54:11.9502921Z",
"$lastUpdatedVersion": 8
},
"Alert": {
"$lastUpdated": "2023-01-08T07:27:01.9659284Z",
"$lastUpdatedVersion": 9
}
},
"$version": 9
},
"reported": {
"deviceInformation": {
"__t": "c",
"manufacturer": "MXCHIP",
"model": "AZ3166",
"swVersion": "1.0.0",
"osName": "Azure RTOS",
"processorArchitecture": "Arm Cortex M4",
"processorManufacturer": "STMicroelectronics",
"totalStorage": 1024,
"totalMemory": 128
},
"ledState": false,
"telemetryInterval": {
"ac": 200,
"av": 1,
"value": 5
},
"$metadata": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z",
"deviceInformation": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z",
"__t": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"manufacturer": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"model": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"swVersion": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"osName": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"processorArchitecture": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"processorManufacturer": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"totalStorage": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"totalMemory": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
}
},
"ledState": {
"$lastUpdated": "2023-01-09T07:28:25.7411971Z"
},
"telemetryInterval": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z",
"ac": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
},
"av": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
},
"value": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
}
}
},
"$version": 155
}
},
"capabilities": {
"iotEdge": false
}
}
You're correct that a DTDL writable property will appear as both a reported and desired property in the device twin. However, this is dependant and the behavior of the device.
If you set a desired property using a service API, that updates the desired property value in the device twin. The device should then send an Ack when it's received and processed the desired property - in your example above, it looks as if the device has done this for the telemetryInterval property. The device hasn't acknowledged the Alert desired property update.
When the device sends a reported property, the device twin is updated with the value sent by the device. In the example above, the device has sent deviceInformation, ledState, and telemetryInterval reported properties. The telemetryInterval was sent in response to a desired property.
You can find more details here:
https://learn.microsoft.com/en-us/azure/iot-develop/concepts-convention#writable-properties
https://learn.microsoft.com/en-us/azure/iot-develop/concepts-developer-guide-device#writable-properties (device code samples in multiple languages)
To following samples for a thermostat device all illustrate how to follow the PnP conventions for writable properties:
https://github.com/Azure/azure-iot-sdk-csharp/tree/main/iothub/device/samples/solutions/PnpDeviceSamples/Thermostat
https://github.com/Azure/azure-iot-sdk-java/tree/main/device/iot-device-samples/pnp-device-sample
https://github.com/Azure/azure-iot-sdk-node/tree/main/device/samples
https://github.com/Azure/azure-iot-sdk-python/tree/main/samples/pnp

List_card in AoG passing item title to the next query instead of key

In an app, I'm returning messages of type list_card with option key for an intent.
Here is the json of a sample query:
{
"id": "275212ef-cf97-4576-afa7-facfbc044ada",
"timestamp": "2017-07-17T17:36:03.655Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "who is Sneha",
"action": "cp.name_search",
"actionIncomplete": false,
"parameters": {
"keyword": "Sneha"
},
"contexts": [
{
"name": "cpname_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 2
},
{
"name": "cpuid_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 1
}
],
"metadata": {
"intentId": "86bd1a17-8e9a-4956-b270-5fb4ac952f5f",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 135,
"intentName": "cp.name_search"
},
"fulfillment": {
"speech": "Searching...",
"source": "agent",
"messages": [
{
"type": "simple_response",
"platform": "google",
"textToSpeech": "Here are the search results. \nWant anything else?"
},
{
"type": "list_card",
"platform": "google",
"title": "Search results",
"items": [
{
"optionInfo": {
"key": "uid 72",
"synonyms": []
},
"title": "Sneha Vasista",
"description": "Srinivas Institute of Technology",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2053",
"synonyms": []
},
"title": "Sneha Bhat",
"description": "Canara Engineering College",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2114",
"synonyms": []
},
"title": "Sneha Sajan",
"description": "P.A College of Engineering",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2320",
"synonyms": []
},
"title": "Sneha ",
"description": "sdit",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2363",
"synonyms": []
},
"title": "Sneha ",
"description": "Srinivas School of Engineering, Mukka",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
}
]
},
{
"type": "0",
"speech": "Here are the search results."
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "e6aa9e52-a9e1-481a-adb5-476c5b386e02"
}
Now the problem is, when I tap the list item in AoG simulator, it passes title of item to next query.
But while testing in Api.ai simulator, it behaves well and passes that key to the next query.
What can be the problem here?
Any hints?
If you're using API.AI, then it will appear in the Intent as an actions_intent_OPTION Event.
One good solution is to have the Intent that sends the list with an OutputContext. Then create a particular Fallback Intent with actions_intent_OPTION as Event and your desired action for that Context which should handle both the voice and press responses.
And you will find your option_key at ["originalRequest"]["data"]["inputs"][0]["arguments"][0]["textValue"] instead of parameter.
You can also see the response value in the actions_intent_option context.
What you need to do is set up a fallback intent directly under your current intent.
For example, if you display the list from the default welcome intent, you can do the following.
Click "Add follow-up intent" and choose fallback.
Don't forget to set the action and enable webhook in the fallback intent.
Now, you should be able to retrieve your answer from the fallback intent using the following code.
const param = app.getContextArgument('actions_intent_option','OPTION').value;

How to differentiate between facebook comments and their replies returned from facebook api?

I'm trying to fetch facebook comments along with their replies and likes for each of the comment and reply but no luck so far.
On trying out following api in explorer:
/v2.4/405944472923733/feed?fields=name,comments.summary(true).filter(stream).order(reverse_chronological)
I get following response:
{
"name": "XYZ Photos",
"comments": {
"data": [
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "cvnbkjcvnbvc",
"created_time": "2015-09-12T18:54:59+0000",
"id": "417121811805999"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "bncvvkjbncvlknbcv",
"created_time": "2015-09-12T18:54:58+0000",
"id": "417121718472675"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "nbkjncvvknbc",
"created_time": "2015-09-12T18:54:57+0000",
"id": "417121691806011"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "nlcvknbcvnb",
"created_time": "2015-09-12T18:54:56+0000",
"id": "417121688472678"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "nkcjbnknb",
"created_time": "2015-09-12T18:54:55+0000",
"id": "417121685139345"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "nbkjncvkjn",
"created_time": "2015-09-12T18:54:54+0000",
"id": "417121678472679"
},
{
"from": {
"name": "Rajveer Singh",
"id": "824840727631444"
},
"message": "nbkjncknb",
"created_time": "2015-09-12T18:54:50+0000",
"id": "417121665139347"
}
],
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTVRJeE5qWTFNVE01TXpRM09qRTBOREl3T0RRd09UQT0=",
"before": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTXpBM09UWTRORFUwTURVd09qRTBOREl4TkRZNU9UQT0="
},
"next": "nextUrl"
},
"summary": {
"order": "reverse_chronological",
"total_count": 76,
"can_comment": true
}
}
}
My problem is though I'm getting all comments and replies in a single call, there is no way I can distinguish between two. Also, it doesn't give any information about likes for a given comment or reply.
How can I get these other info ?
Use the parent field which will only be present if the comment is a reply.

Gmail Markup for Multiple Events

I'm developing event markup using json-ld to be included with confirmation emails.
Some of my events are recurring at regular intervals. However, recurring events are not supported by the latest Schema.org specifications so I've followed the advice offered here: http://lists.w3.org/Archives/Public/public-vocabs/2011Dec/0062.html and decided to embed a json list of the individual events.
The json-ld passes the tests in the Email Markup Tester provided by google (https://www.google.com/webmasters/markup-tester/u/0/).
However, when I test the google calendar integration by sending the email to myself, only 1 out of 6 events in the series appears in my calendar (oddly, it's neither the first or last event in the list).
Does gmail markup support multiple events in the same email? If so is there a better way to do it?
Example Markup:
<script type="application/ld+json">
[
{
"reservationNumber": "7e15afb6b2485005e55481be58de4141b70f85006bd25823",
"reservationFor": {
"startDate": "2015-05-09T16:00:00-07:00",
"endDate": "2015-05-09T22:30:00-07:00",
"description": "regularly schedule XXXX",
"location": {
"address": {
"addressCountry": "US",
"addressLocality": "XXX",
"addressRegion": "XXX",
"streetAddress": "XXX",
"postalCode": "XXX",
"#type": "PostalAddress"
},
"#type": "Place",
"name": "XXX"
},
"#type": "Event",
"name": "XXX Every 2 Weeks"
},
"modifyReservationUrl": "https://example.com/XXX",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"#type": "Person",
"name": "XXX"
},
"#context": "http://schema.org",
"#type": "EventReservation"
},
...
{
"reservationNumber": "40553edbce52f0052e153919a4dad49ec32516c15433bf4a",
"reservationFor": {
"startDate": "2015-05-23T16:00:00-07:00",
"endDate": "2015-05-23T22:30:00-07:00",
"description": "regularly schedule XXX",
"location": {
"address": {
"addressCountry": "US",
"addressLocality": "XXX",
"addressRegion": "XXX",
"streetAddress": "XXX",
"postalCode": "XXX",
"#type": "PostalAddress"
},
"#type": "Place",
"name": "XXX"
},
"#type": "Event",
"name": "XXX Every 2 Weeks"
},
"modifyReservationUrl": "https://example.com/XXX",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"#type": "Person",
"name": "XXX"
},
"#context": "http://schema.org",
"#type": "EventReservation"
},
]
</script>
You can try adding this markup in the html file by using the Quick Apps script tutorial mentioned in the documentation here.
Does making a list help: https://schema.org/ItemList
Haven't tested this out, but it might be a useful approach.

Resources