Search code examples
jsonrdfsemantic-webowl

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?


Solution

  • 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>