How to describe a device capability with an RDF graph using JSON-LD serialization?

145 Views Asked by At

I need to describe the capability of devices and how to invoke the capabilities functions semantically. In order to achieve that I created a super simple RDF Graph and used @rdfjs/serializer-jsonld library to serialize the graph to JSON-LD file with the following code:

const rdf = require('@rdfjs/data-model')
const Readable = require('stream').Readable
const SerializerJsonld = require('@rdfjs/serializer-jsonld')

const serializerJsonld = new SerializerJsonld()
const input = new Readable({
  objectMode: true,
  read: () => {
    input.push(rdf.quad(
      rdf.literal('Device001'),
      rdf.namedNode('https://schema.org/potentialAction'),
      rdf.namedNode('https://schema.org/PhotographAction')))
    input.push(rdf.quad(
      rdf.namedNode('https://schema.org/PhotographAction'),
      rdf.namedNode('https://w3id.org/function/ontology#Function'),
      rdf.literal('takePhoto')))
    input.push(null)
  }
})
const output = serializerJsonld.import(input)

output.on('data', jsonld => {
  console.log(jsonld)
})

which creates the following JSON-LD file.

[
    {
        "@id": "Device001",
        "https://schema.org/potentialAction": {
            "@id": "https://schema.org/PhotographAction"
        }
    },
    {
        "@id": "https://schema.org/PhotographAction",
        "https://w3id.org/function/ontology#Function": "takePhoto"
    }
]

Is this semantically correct? Is is okay to combine [schema.org] ontology (https://schema.org/) and function ontology without using RDF Schema or any class or type? Is there a better way to combine 2 ontologies? JSON-LD playground gives no errors but is there a better way to validate?

1

There are 1 best solutions below

5
unor On
{
    "@id": "Device001",
    "https://schema.org/potentialAction": {
        "@id": "https://schema.org/PhotographAction"
    }
}

Here you are creating a class-less instance identified by the URI https://schema.org/PhotographAction, but you probably want to create an instance that has the class https://schema.org/PhotographAction, and that is identified by an URI under your control.

{
    "@id": "Device001",
    "https://schema.org/potentialAction": {
        "@type": "https://schema.org/PhotographAction"
        "@id": "Action001"
    }
}

{
    "@id": "https://schema.org/PhotographAction",
    "https://w3id.org/function/ontology#Function": "takePhoto"
}

Here you are saying something about the class https://schema.org/PhotographAction, but you probably want to say something about your instance that has this class (where the instance is identified by the URI you provided in the first node).

{
    "@id": "Action001",
    "https://w3id.org/function/ontology#Function": "takePhoto"
}

I’m not familiar with the Function Ontology, but as https://w3id.org/function/ontology#Function is a class, your probably don’t want to use it as property.