简体   繁体   中英

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, eg, 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 (eg whether functional, their types, etc.), or even provide additional rules to allow different forms of inference when analysing the data (eg 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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM