I am trying to map an array defined in JSON Schema to OWL 2.
This is a simple example of JSON Schema:
{
"properties": {
"nm_prop": {
"type": "array",
"items": {"type": "number"}
}
}
}
And this is the OWL code produced from above JSON Schema:
:nm_prop subPropertyOf owl:topObjectProperty
:nm_prop rdfs:domain :JS_id
:nm_prop rdfs:range OntoDT:OntoDT_110287
OntoDT:OntoDT_110287 is an ontology that defines an array.
The problem is how to define in OWL that the elements of an array will be of a certain data type (e.g., xsd:string or xsd:integer) ??
Based in cmungall's response, I proposed a new definition for the JSON Schema example above.
My goal is to map JSON Schemas to OWL for later use in a data integration application.
Using the JSON Schema example of the original question and cmungall's explanation, a possible representation of the schema in OWL would be:
:JS_id rdf:type owl:Class .
:array_integer rdfs:subClassOf OntoDT:OntoDT_110287 ,
[ rdf:type owl:Restriction ;
owl:onProperty OntoDT:OntoDT_0000405 ;
owl:allValuesFrom xsd:integer ] .
:nm_prop rdfs:subPropertyOf owl:topObjectProperty ;
rdfs:domain :JS_id ;
rdfs:range :array_integer .
Where:
:JS_id is the main class;
array_integer is a definition of an array datatype, that extend the array definition in OntoDT;
array_integer have a restriction: It only accepts integers;
nm_prop is the array atribute in the schema.
And a new question: is this writing correct and would it be equivalent to the JSON Schema in the example?
There are multiple ways you could store an array in OWL. But assuming that you explicitly want an array structure (as opposed to say a linked list, as in rdf:list), e.g of form:
[e_0,e_1,..,e_n]
you could represent this as:
[] a my:Array ;
my:length n;
my:contains
[
a my:ArrayElement ;
my:index 0 ;
my:value e_0
],
[
a my:ArrayElement ;
my:index 1 ;
my:value e_1
],
...
[
a my:ArrayElement ;
my:index n ;
my:value e_n
] .
(Assuming "my" is a vocabulary defining classes for Array, ArrayElement, and additional properties
You could then define (switching to manchester syntax for clarity):
ArrayOfInts EquivalentTo Array and my:contains only (my:value some integer)
And assert your array to be of this type.
You could add other axioms declaring my:value and my:index to be functional.
But it's worth pausing here and asking what your broader goals are. OWL is not a great language for representing and reasoning about computational data structures. For one thing, OWL makes the Open World Assumption, and for reasoning about data structures (e.g. for validation purposes) you typically want the Closed World assumption. However, there may be circumstances where this is an accord with your use case, e.g. if you want to reason about incomplete information about a program or data structure. But even then there may be other branches of logic that are better suited.
It's often the case that when something is modeled in a computer program as an array, there is a more natural non-array representation in OWL. For example, if we wanted to represent a list of runners ordered by their finishing position in a race, it would be more natural to model the event of finishing the race for each runner, together with a timing, and derive the array at query time.
I don't know your exact use case, but hopefully this is relevant to you.