Use SHACL to validate a date within a certain range - shacl

How can I use SHACL to validate if a date lies within a certain range? I tried using minInclusive, maxInclusive, minExclusive, maxExcluse and lessThan, but nothing seems to work. I am using the SHACL Playground with this data.
Shapes Graph
#prefix dash: <http://datashapes.org/dash#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ex: <http://example.com/> .
#prefix sh: <http://www.w3.org/ns/shacl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:QueryParameterShape
a sh:NodeShape ;
sh:targetClass ex:QueryParameter ;
sh:property [
sh:path ex:peildatum ;
sh:datatype xsd:date ;
sh:lessThan "2022-01-01"^^xsd:date ;
sh:maxCount 0 ;
sh:name "peildatum" ;
] .
Data Graph
[
{
"#context": { "#vocab": "http://example.com/" },
"#id": "http://example.com/query_variable_1",
"#type": "QueryParameter",
"peildatum": [
{
"#value": "2022-05-01",
"#type": "http://www.w3.org/2001/XMLSchema#date"
}
]
},
{
"#context": { "#vocab": "http://example.com/" },
"#id": "http://example.com/query_variable_2",
"#type": "QueryParameter",
"peildatum": [
{
"#value": "2021-05-01",
"#type": "http://www.w3.org/2001/XMLSchema#date"
}
]
}
]
The validation report states:
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape _:n3790 ;
sh:focusNode ex:query_variable_1 ;
sh:resultPath ex:peildatum ;
sh:resultMessage "More than 0 values" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape _:n3790 ;
sh:focusNode ex:query_variable_2 ;
sh:resultPath ex:peildatum ;
sh:resultMessage "More than 0 values" ;
] .
I added the maxCount 0 restriction to see if the validation report works at all. And yes, it does. But the restriction on the date does not work.
Any ideas?

sh:lessThan is used between a pair of properties, e.g. ex:birthDate sh:lessThan sh:deathDate. Use sh:minInclusive etc to compare with specific values.
https://www.w3.org/TR/shacl/#core-components-range
Having said this, the SHACL Playground hasn't been maintained for 5 years and has known limitations with the handling of < operations including sh:minInclusive, so you should not rely on it. There are plenty of other open source libraries available.

Just to be complete, the correct shapes graph should be:
#prefix dash: <http://datashapes.org/dash#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ex: <http://example.com/> .
#prefix sh: <http://www.w3.org/ns/shacl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:QueryParameterShape
a sh:NodeShape ;
sh:targetClass ex:QueryParameter ;
sh:property [
sh:path ex:peildatum ;
sh:datatype xsd:date ;
sh:maxInclusive "2021-12-31"^^xsd:date ;
sh:name "peildatum" ;
] .

Related

Is it possible to convert from JSON or YAML to XML using jq/yq/xq

I have managed to successfully convert an XML file to a YAML file using xq
Is it possible using the following tools jq, yq, xq, to convert from either YAML or JSON back to an XML format ?
Here is a sample of my sample JSON file:
{
"security-settings": {
"#xmlns": "urn:activemq:core",
"security-setting": {
"#match": "#",
"permission": [
{
"#type": "createNonDurableQueue",
"#roles": "admins"
},
{
"#type": "deleteNonDurableQueue",
"#roles": "admins"
},
{
"#type": "manage",
"#roles": "admins"
}
]
}
}
}
Thank you kindely for any help or suggestion.
Additionnal Information:
The source XML I initially used is the following :
<?xml version="1.0"?>
<security-settings xmlns="urn:activemq:core">
<security-setting match="#">
<permission type="createNonDurableQueue" roles="admins"/>
<permission type="deleteNonDurableQueue" roles="admins"/>
<permission type="createDurableQueue" roles="admins"/>
<permission type="deleteDurableQueue" roles="admins"/>
<permission type="createAddress" roles="admins"/>
<permission type="deleteAddress" roles="admins"/>
<permission type="consume" roles="admins"/>
<permission type="browse" roles="admins"/>
<permission type="send" roles="admins"/>
<permission type="manage" roles="admins"/>
</security-setting>
</security-settings>
The forward conversion from XML to JSON using the command xq -yY < security-settings.xml generated the JSON output:
{
"security-settings": {
"#xmlns": "urn:activemq:core",
"security-setting": {
"#match": "#",
"permission": [
{
"#type": "createNonDurableQueue",
"#roles": "admins"
},
{
"#type": "deleteNonDurableQueue",
"#roles": "admins"
},
{
"#type": "createDurableQueue",
"#roles": "admins"
},
{
"#type": "deleteDurableQueue",
"#roles": "admins"
},
{
"#type": "createAddress",
"#roles": "admins"
},
{
"#type": "deleteAddress",
"#roles": "admins"
},
{
"#type": "consume",
"#roles": "admins"
},
{
"#type": "browse",
"#roles": "admins"
},
{
"#type": "send",
"#roles": "admins"
},
{
"#type": "manage",
"#roles": "admins"
}
]
}
}
}
The native conversion suggested by running yq -o=xml -P json_file for the backward conversion from JSON to to XML does not generate the same result as the source XML as previously shown.
<security-settings>
<#xmlns>urn:activemq:core</#xmlns>
<security-setting>
<#match>#</#match>
<permission>
<#type>createNonDurableQueue</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>deleteNonDurableQueue</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>createDurableQueue</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>deleteDurableQueue</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>createAddress</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>deleteAddress</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>consume</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>browse</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>send</#type>
<#roles>admins</#roles>
</permission>
<permission>
<#type>manage</#type>
<#roles>admins</#roles>
</permission>
</security-setting>
</security-settings>
I am running on a Fedora 36 virtual machine and this is the yq I have installed on the box
yq --version
yq 3.0.2
yq --help
usage: yq [options] <jq filter> [input file...]
yq: Command-line YAML processor - jq wrapper for YAML documents
yq transcodes YAML documents to JSON and passes them to jq.
See https://github.com/kislyuk/yq for more information.
positional arguments:
jq_filter
files
options:
-h, --help show this help message and exit
--yaml-output, --yml-output, -y
Transcode jq JSON output back into YAML and emit it
--yaml-roundtrip, --yml-roundtrip, -Y
Transcode jq JSON output back into YAML and emit it. Preserve YAML tags and styles by representing them as extra items in their enclosing mappings and sequences while in JSON. This option is incompatible with jq filters that do not expect these extra items.
--width WIDTH, -w WIDTH
When using --yaml-output, specify string wrap width
--indentless-lists, --indentless
When using --yaml-output, indent block style lists (sequences) with 0 spaces instead of 2
--in-place, -i Edit files in place (no backup - use caution)
--version show program's version number and exit
jq - commandline JSON processor [version 1.6]
Usage: jq [options] <jq filter> [file...]
jq [options] --args <jq filter> [strings...]
jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.
The simplest filter is ., which copies jq's input to its output
unmodified (except for formatting, but note that IEEE754 is used
for number representation internally, with all that that implies).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq
Example:
$ echo '{"foo": 0}' | jq .
{
"foo": 0
}
Some of the options include:
-c compact instead of pretty-printed output;
-n use `null` as the single input value;
-e set the exit status code based on the output;
-s read (slurp) all inputs into an array; apply filter to it;
-r output raw strings, not JSON texts;
-R read raw strings, not JSON texts;
-C colorize JSON;
-M monochrome (don't colorize JSON);
-S sort keys of objects on output;
--tab use tabs for indentation;
--arg a v set variable $a to value <v>;
--argjson a v set variable $a to JSON value <v>;
--slurpfile a f set variable $a to an array of JSON texts read from <f>;
--rawfile a f set variable $a to a string consisting of the contents of <f>;
--args remaining arguments are string arguments, not files;
--jsonargs remaining arguments are JSON arguments, not files;
-- terminates argument processing;
Named arguments are also available as $ARGS.named[], while
positional arguments are available as $ARGS.positional[].
See the manpage for more options.
#ikegami
Here is the output :
echo <ele attr_name="attr_value">ele_value</ele> | xq
{
"ele": {
"#attr_name": "attr_value",
"#text": "ele_value"
}
}
echo <ele attr_name="attr_value">ele_value</ele> | xq | ./yq_linux_amd64 -o=xml -P
<ele>
<#attr_name>attr_value</#attr_name>
<#text>ele_value</#text>
</ele>
First, get the version of yq from this github repository: https://github.com/mikefarah/yq/releases/download/v4.26.1/yq_linux_amd64
It provides flags/features that others might not support.
Then, one can use the following command to regenerate the XML:
./yq_linux_amd64 \
--xml-attribute-prefix # \
--xml-content-name '#text' \
--input-format yaml \
--output-format xml \
security-settings.yaml
The very same command works for the JSON inputs as well, since JSON is a subset of YAML.
jq:
"#" as $attr_prefix |
"#text" as $content_key |
# ">" only needs to be escaped if preceded by "]]".
# Some whitespace also need escaping, at least in attribute.
{ "&": "&", "<": "<", ">": ">" } as $escapes |
{ "&": "&", "<": "<", "\"": """ } as $attr_escapes |
def text_to_xml: split( "" ) | map( $escapes[.] // . ) | join( "" );
def text_to_xml_attr_val: split( "" ) | map( $attr_escapes [.] // . ) | join( "" );
def node_to_xml:
if type == "string" then
text_to_xml
else
(
if .attrs then
.attrs |
to_entries |
map( " " + .key + "=\"" + ( .value | text_to_xml_attr_val ) + "\"" ) |
join( "" )
else
""
end
) as $attrs |
if .children and ( .children | length ) > 0 then
( .children | map( node_to_xml ) | join( "" ) ) as $children |
"<" + .name + $attrs + ">" + $children + "</" + .name + ">"
else
"<" + .name + $attrs + "/>"
end
end
;
def fix_tree( $name ):
type as $type |
if $type == "array" then
.[] | fix_tree( $name )
elif $type == "object" then
reduce to_entries[] as { key: $k, value: $v } (
{ name: $name, attrs: {}, children: [] };
if $k[0:1] == $attr_prefix then
.attrs[ $k[1:] ] = $v
elif $k == $content_key then
.children += [ $v ]
else
.children += [ $v | fix_tree( $k ) ]
end
)
else
{ name: $name, attrs: {}, children: [ . ] }
end
;
def fix_tree: fix_tree( "" ) | .children[];
fix_tree | node_to_xml
Demo on jqplay
It's invoked using
jq -R 'above progam' file.json >file.xml
You can also place the program in a file (say json_to_xml.jq) and use the following:
jq -Rf json_to_xml.jq file.json >file.xml
I took a two-step approach. I first convert the input to an unambiguous format, then converting this result to XML. These two steps could be merged. Here's is the result of the first conversion of the provided input:
{
"name": "security-settings",
"attrs": {
"xmlns": "urn:activemq:core"
},
"children": [
{
"name": "security-setting",
"attrs": {
"match": "#"
},
"children": [
{
"name": "permission",
"attrs": {
"type": "createNonDurableQueue",
"roles": "admins"
},
"children": []
},
{
"name": "permission",
"attrs": {
"type": "deleteNonDurableQueue",
"roles": "admins"
},
"children": []
},
{
"name": "permission",
"attrs": {
"type": "manage",
"roles": "admins"
},
"children": []
}
]
}
]
}
Note that the format into which the original XML was converted is lossy. For example, it loses the relative order of XML elements with different names. This means the output of the above program may differ from the original XML in significant ways. But there's no escaping that unless you use a JSON schema that's not lossy.

Is there any way in rml / r2rml to take a value as an IRI?

I'm using RMLMapper to transfrom JSON to RDF. One of the values stored in the JSON is a URL. I would like to use this as the basis of an IRI for the object of RDF statements.
The input is
{
"documentId": {
"value": "http://example.org/345299"
},
...
I want the IRI for the subject of statements to be http://example.org/345299#item, e.g. <http://example.org/345299#item> a <http://schema.org/Thing> .
I tried
#prefix rr: <http://www.w3.org/ns/r2rml#>.
#prefix rml: <http://semweb.mmlab.be/ns/rml#>.
#prefix ql: <http://semweb.mmlab.be/ns/ql#>.
<#Mapping> a rr:TriplesMap ;
rml:logicalSource [
rml:source "input.json";
rml:referenceFormulation ql:JSONPath;
rml:iterator "$"
];
rr:subjectMap [
rr:template "{documentId.value}#item" ;
rr:class schema:Thing
]
gives and error that rr:template "{documentId.value}#item" doesn't produce a valid IRI.
Providing a value for #base gives a valid IRI, but it is the base with the url-encoded value appended to the base, e.g. <http://example.org/http%3A%2F%2Fexample.org%2Fjobposts%2F345299#item>
So is there any way in r2rml / rml to take a value and just use it as an IRI? Or to convert a string in to an IRI?
One option would be to not use a rr:template, but instead an FnO function to concatenate the stored URI with #item.
Documentation on how to do this can be found here.
In the example you give, replacing the subject map with this gives the required solution:
<#Mapping> rr:subjectMap [
a fnml:FunctionTermMap;
rr:termType rr:IRI;
fnml:functionValue [
rml:logicalSource <#Source> ;
rr:predicateObjectMap [
rr:predicate fno:executes ;
rr:objectMap [ rr:constant grel:array_join ] ;
] ;
rr:predicateObjectMap [
rr:predicate grel:p_array_a ;
rr:objectMap [ rml:reference "documentId.value" ] ;
] ;
rr:predicateObjectMap [
rr:predicate grel:p_array_a ;
rr:objectMap [ rr:constant "#item" ] ;
] ;
] .
Note: I contribute to RML and its technologies.
rml:reference is close enough.
rr:subjectMap [
rml:reference "documentId.value" ;
rr:class schema:Thing
]
Doesn't seem to let me append #item but it'll do for now.

Converting a CSV to RDF where one column is a set of values

I want to convert a CSV to RDF.
One of the column of that CSV is, in fact, a set of values joined with a separator character (in my case, the space character).
Here is a sample CSV (with header):
col1,col2,col3
"A","B C D","John"
"M","X Y Z","Jack"
I would like the conversion process to create a RDF similar to this:
:A :aProperty :B, :C, :D; :anotherProperty "John".
:M :aProperty :X, :Y, :Z; :anotherProperty "Jack".
I usually use Tarql for CSV conversion.
It is fine to iterate per row.
But it has no feature to sub-iterate "inside" a column value.
SPARQL-Generate may help (with iter:regex and sub-generate, as far as a I understand). But I cannot find any example that matches my use case.
PS: may be RML can help too. But I have no prior knowledge of this technology.
You can accomplish this with RML and FnO.
First, we need to access each row which can be accomplished with RML.
RML allows you to iterate over each row of the CSV file (ql:CSV) with a
LogicalSource.
Specifying the iterator (rml:iterator)
is not needed since the default iterator in RML is a row-based iterator.
This results into the following RDF (Turtle):
<#LogicalSource>
a rml:LogicalSource;
rml:source "data.csv";
rml:referenceFormulation ql:CSV.
The actually triples are generated with the help of a TriplesMap which
uses the LogicalSource to retrieve the data from each CSV row:
<#MyTriplesMap>
a rr:TriplesMap;
rml:logicalSource <#LogicalSource>;
rr:subjectMap [
rr:template "http://example.org/{col1}";
];
rr:predicateObjectMap [
rr:predicate ex:aProperty;
rr:objectMap <#FunctionMap>;
];
rr:predicateObjectMap [
rr:predicate ex:anotherProperty;
rr:objectMap [
rml:reference "col3";
];
].
The col3 CSV column be used to create the following triple:
<http://example.org/A> <http://example.org/ns#anotherProperty> "John".
However, the string in the CSV column col2 needs to be split first.
This can be achieved with Fno (Function Ontology) and an RML processor which
supports the execution of FnO functions. Such RML processor can be the
RML Mapper, but other processors can
be used too.
The following RDF is needed to invoke an FnO function which splits the input
string with a space as separator with our LogicalSource as input data:
<#FunctionMap>
fnml:functionValue [
rml:logicalSource <#LogicalSource>; # our LogicalSource
rr:predicateObjectMap [
rr:predicate fno:executes;
rr:objectMap [
rr:constant grel:string_split # function to use
];
];
rr:predicateObjectMap [
rr:predicate grel:valueParameter;
rr:objectMap [
rml:reference "col2" # input string
];
];
rr:predicateObjectMap [
rr:predicate grel:p_string_sep;
rr:objectMap [
rr:constant " "; # space separator
];
];
].
The supported FnO functions by the RML mapper are available here:
https://rml.io/docs/rmlmapper/default-functions/
You can find the function name and its parameters on that page.
Mapping rules
#base <http://example.org> .
#prefix rml: <http://semweb.mmlab.be/ns/rml#> .
#prefix rr: <http://www.w3.org/ns/r2rml#> .
#prefix ql: <http://semweb.mmlab.be/ns/ql#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
#prefix fno: <https://w3id.org/function/ontology#> .
#prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .
#prefix ex: <http://example.org/ns#> .
<#LogicalSource>
a rml:LogicalSource;
rml:source "data.csv";
rml:referenceFormulation ql:CSV.
<#MyTriplesMap>
a rr:TriplesMap;
rml:logicalSource <#LogicalSource>;
rr:subjectMap [
rr:template "http://example.org/{col1}";
];
rr:predicateObjectMap [
rr:predicate ex:aProperty;
rr:objectMap <#FunctionMap>;
];
rr:predicateObjectMap [
rr:predicate ex:anotherProperty;
rr:objectMap [
rml:reference "col3";
];
].
<#FunctionMap>
fnml:functionValue [
rml:logicalSource <#LogicalSource>;
rr:predicateObjectMap [
rr:predicate fno:executes;
rr:objectMap [
rr:constant grel:string_split
];
];
rr:predicateObjectMap [
rr:predicate grel:valueParameter;
rr:objectMap [
rml:reference "col2"
];
];
rr:predicateObjectMap [
rr:predicate grel:p_string_sep;
rr:objectMap [
rr:constant " ";
];
];
].
Output
<http://example.org/A> <http://example.org/ns#aProperty> "B".
<http://example.org/A> <http://example.org/ns#aProperty> "C".
<http://example.org/A> <http://example.org/ns#aProperty> "D".
<http://example.org/A> <http://example.org/ns#anotherProperty> "John".
<http://example.org/M> <http://example.org/ns#aProperty> "X".
<http://example.org/M> <http://example.org/ns#aProperty> "Y".
<http://example.org/M> <http://example.org/ns#aProperty> "Z".
<http://example.org/M> <http://example.org/ns#anotherProperty> "Jack".
Note: I contribute to RML and its technologies.
You can test this query on the playground https://ci.mines-stetienne.fr/sparql-generate/playground.html and check it behaves as expected:
BASE <http://data.example.com/>
PREFIX : <http://example.com/>
PREFIX iter: <http://w3id.org/sparql-generate/iter/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
GENERATE {
<{?col1}> :anotherProperty ?col3.
GENERATE{
<{?col1}> :aProperty <{ ?value }> ;
}
ITERATOR iter:Split( ?col2 , " " ) AS ?value .
}
ITERATOR iter:CSVStream("http://example.com/file.csv", 20, "*") AS ?col1 ?col2 ?col3
The Tabular Data Model and related specs target this use case, although as I recall, we didn't provide for combinations of valueUrl and separator to have sub-columns generate multiple URIs.
The metadata to describe this would be something like the following:
{
"#context": "http://www.w3.org/ns/csvw",
"url": "test.csv",
"tableSchema": {
"columns": [{
"name": "col1",
"titles": "col1",
"datatype": "string",
"required": true
}, {
"name": "col2",
"titles": "col2",
"datatype": "string",
"separator": " "
}, {
"name": "col3",
"titles": "col3",
"datatype": "string",
"propertyUrl": "http://example.com/anotherProperty",
"valueUrl": "http://example.com/{col3}"
}],
"primaryKey": "col1",
"aboutUrl": http://example.com/{col1}"
}
}

Parsing variables in curl with bash script

Hey I am using conduit curl method to create tasks from post. It work fine when I run from terminal with hardcoded values. But when I try to execute it with variables it throws an error:
Script:
#!/bin/bash
echo "$1"
echo "$2"
echo "$3"
echo "$4"
echo "$5"
echo '{
"transactions": [
{
"type": "title",
"value": "$1"
},
{
"type": "description",
"value": "$2"
},
{
"type": "status",
"value": "$3"
},
{
"type": "priority",
"value": "$4"
},
{
"type": "owner",
"value": "$5"
}
]
}' | arc call-conduit --conduit-uri https://mydomain.phacility.com/ --conduit-token mytoken maniphest.edit
execution:
./test.sh "test003 ticket from api post" "for testing" "open" "high" "ahsan"
Output:
test003 ticket from api post
for testing
open
high
ahsan
{"error":"ERR-CONDUIT-CORE","errorMessage":"ERR-CONDUIT-CORE: Validation errors:\n - User \"$5\" is not a valid user.\n - Task priority \"$4\" is not a valid task priority. Use a priority keyword to choose a task priority: unbreak, very, high, kinda, triage, normal, low, wish.","response":null}
As you can see in error its reading $4 and $5 as values not variables. And I am failing to understand how to use $variables as input in these arguments.
You're using single quotes around the last echo to so that you can use double-quotes inside the JSON, but that causes echo to print the string without expanding anything. You need to use double quotes for the string, so you'll have to escape the double quotes inside of it.
Replace the last echo with this:
echo "{
\"transactions\": [
{
\"type\": \"title\",
\"value\": \"$1\"
},
{
\"type\": \"description\",
\"value\": \"$2\"
},
{
\"type\": \"status\",
\"value\": \"$3\"
},
{
\"type\": \"priority\",
\"value\": \"$4\"
},
{
\"type\": \"owner\",
\"value\": \"$5\"
}
]
}"
and it'll work. To avoid issues like this you can check http://wiki.bash-hackers.org and http://mywiki.wooledge.org/BashGuide for some general tips for bash newbies. Also, you can use shellcheck with a lot of text editors, which will spot errors like this automatically.

What does simple JSON object format look like in RDF and OWL/WOL?

I have the following JSON objects...
var people = [
{"LName": "Smith", "FName": "Jane", "Gender": "Female", "Age": 20},
{"LName": "Doe", "FName": "John", "Gender": "Male", "Age": 40},
{"LName": "Smith", "FName": "Mary", "Gender": "Female", "Age": 29}
];
Note that the above representation is simply First Normal Form (1NF), representing three (3) denormalized objects, where each would be a row in a "People" table that has column names "LName", "FName", "Gender" and "Age".
Given the above, what would the above look like after being translated/converted to OWL/WOL?
There's no single way to do this. The same information could be encoded in RDF or OWL in numerous ways. It all depends on what kind of information you're trying to encode and preserve. If you just want information about three persons, then you might use the FOAF vocabulary to encode the information. Or if you want to preserve the JSON semantics, you might use an encoding of JSON structures. Or you might define an ontology with the properties that you need and encode according to that. Here's what those first two approaches might look like. You can obviously come up with others, though.
In FOAF
If you use the FOAF vocabulary (which isn't strictly OWL, but defines an RDF vocabulary, you might end up with something like this:
In N3
prefix foaf: <http://xmlns.com/foaf/0.1/>
[] a foaf:Person ;
foaf:firstName "Smith" ;
foaf:lastName "Jane" ;
foaf:gender "Female" ;
foaf:age 20 .
[] a foaf:Person ;
foaf:firstName "Doe" ;
foaf:lastName "John" ;
foaf:gender "Male" ;
foaf:age 40 .
[] a foaf:Person ;
foaf:firstName "Smith" ;
foaf:lastName "Mary" ;
foaf:gender "Female" ;
foaf:age 29 .
In RDF/XML
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person>
<foaf:firstName>Smith</foaf:firstName>
<foaf:lastName>Mary</foaf:lastName>
<foaf:gender>Female</foaf:gender>
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>29</foaf:age>
</foaf:Person>
<foaf:Person>
<foaf:firstName>Doe</foaf:firstName>
<foaf:lastName>John</foaf:lastName>
<foaf:gender>Male</foaf:gender>
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>40</foaf:age>
</foaf:Person>
<foaf:Person>
<foaf:firstName>Smith</foaf:firstName>
<foaf:lastName>Jane</foaf:lastName>
<foaf:gender>Female</foaf:gender>
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>20</foaf:age>
</foaf:Person>
</rdf:RDF>
JSON Encoding
If you want to preserve more of the JSON information, e.g., that you have an array, that it has three elements, etc., you might do something more like this:
In N3
prefix json: <urn:json:>
[] a json:Array ;
json:elements (
[ json:hasProperty [ json:propertyName "LName" ;
json:propertyValue "Smith" ] ,
[ json:propertyName "FName" ;
json:propertyValue "Jane" ] ,
[ json:propertyName "Gender" ;
json:propertyValue "Female" ] ,
[ json:propertyName "Age" ;
json:propertyValue 20 ] ]
[ json:hasProperty [ json:propertyName "LName" ;
json:propertyValue "Dow" ] ,
[ json:propertyName "FName" ;
json:propertyValue "John" ] ,
[ json:propertyName "Gender" ;
json:propertyValue "Male" ] ,
[ json:propertyName "Age" ;
json:propertyValue 40 ] ]
[ json:hasProperty [ json:propertyName "LName" ;
json:propertyValue "Smith" ] ,
[ json:propertyName "FName" ;
json:propertyValue "Mary" ] ,
[ json:propertyName "Gender" ;
json:propertyValue "Female" ] ,
[ json:propertyName "Age" ;
json:propertyValue 29 ] ]
) .
In RDF/XML
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:json="urn:json:">
<json:Array>
<json:elements rdf:parseType="Collection">
<rdf:Description>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>LName</json:propertyName>
<json:propertyValue>Smith</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>FName</json:propertyName>
<json:propertyValue>Jane</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Gender</json:propertyName>
<json:propertyValue>Female</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Age</json:propertyName>
<json:propertyValue rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>20</json:propertyValue>
</json:hasProperty>
</rdf:Description>
<rdf:Description>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>LName</json:propertyName>
<json:propertyValue>Dow</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>FName</json:propertyName>
<json:propertyValue>John</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Gender</json:propertyName>
<json:propertyValue>Male</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Age</json:propertyName>
<json:propertyValue rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>40</json:propertyValue>
</json:hasProperty>
</rdf:Description>
<rdf:Description>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>LName</json:propertyName>
<json:propertyValue>Smith</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>FName</json:propertyName>
<json:propertyValue>Mary</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Gender</json:propertyName>
<json:propertyValue>Female</json:propertyValue>
</json:hasProperty>
<json:hasProperty rdf:parseType="Resource">
<json:propertyName>Age</json:propertyName>
<json:propertyValue rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>29</json:propertyValue>
</json:hasProperty>
</rdf:Description>
</json:elements>
</json:Array>
</rdf:RDF>
It could take on a number of forms depending on how you want to model your data.
For example, you may decide to use some existing vocabulary or ontology (such as FOAF), or create your own home made ontology - in that case you may choose to define restrictions on the properties involved (e.g. whether functional, their types, etc.), or even provide additional rules to allow different forms of inference when analysing the data (e.g. auto-classify people with "female" gender as belonging to a Female class).
In general though, when creating an ontology you have two "sections" that you work with: the terminology (TBox) where you define the various restrictions/classes/properties of the model, and the assertions (ABox) where you instantiate things based on the model.
A bare bones representation (in Turtle syntax) skipping most of the above (except some basic property restrictions), could look like this:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix : <http://foo.bar#> .
# TBox
:Person a owl:Class .
:first_name a owl:DatatypeProperty;
rdfs:domain :Person;
rdfs:range xsd:string .
:last_name a owl:DatatypeProperty;
rdfs:domain :Person;
rdfs:range xsd:string .
:gender a owl:DatatypeProperty;
rdfs:domain :Person;
rdfs:range xsd:string .
:age a owl:DatatypeProperty;
rdfs:domain :Person;
rdfs:range xsd:integer .
# ABox
:person_1 a :Person;
:last_name "Smith;
:first_name "Jane";
:gender "female";
:age 20.
:person_2 a :Person;
:last_name "Doe;
:first_name "John";
:gender "male";
:age 40.
:person_3 a :Person;
:last_name "Smith;
:first_name "Mary";
:gender "female";
:age 29.
As an example of further modelling, you may decide that :gender can only take on the values "female" or "male". An alternative way to define :gender in that case would be:
:gender a owl:DatatypeProperty;
rdfs:range [
a rdfs:Datatype;
owl:oneOf ( "Female" "Male")
] .
I suppose you could also define gender to be a functional property (to have only one unique value for each instance of Person).