Skip to content

Direct mapping vs. CSV2RDF, simple case with foreign keys

Gregg Kellogg edited this page Apr 17, 2015 · 6 revisions

Consider two simple tables, called People and Addresses, respectively:

ID fname addr
7 Bob 18
ID city state
18 Cambridge MA

RDB case

A relational table always has a schema, that the RDF Direct Mapping makes use of. In this example, the schema may define that:

  • For the People table
    • ID is a primary key in the table, and the cells are integers
    • The name column contains strings
    • The addr column contains integers
  • For the Addresses table
    • ID is primary key in the table, and the cells are integers
    • both the city and state columns contain strings
  • The addr column in the People table contains foreign keys that references the ID field of the Addresses table.

Using these information, the result of the Direct Mapping is something like:

<http://foo.example/DB/People/ID=7> rdf:type <http://foo.example/DB/People>;
    <http://foo.example/DB/People#ID> 7;
    <http://foo.example/DB/People#fname> "Bob";
    <http://foo.example/DB/People#addr> 18;
    <http://foo.example/DB/People#ref-addr> <http://foo.example/DB/Addresses/ID=18>
    .

<http://foo.example/DB/Addresses/ID=18> rdf:type <http://foo.example/DB/Addresses>.
    <http://foo.example/DB/Addresses#ID> 18.
    <http://foo.example/DB/Addresses#city> "Cambridge".
    <http://foo.example/DB/Addresses#addr> "MA"
    .

Where http://foo.example/DB/ is the URL for the database that contains the People table.

Compared to the simple case the difference is in

<http://foo.example/DB/People/ID=7> 
   <http://foo.example/DB/People#addr> <http://foo.example/DB/Addresses/ID=18>

which links the two tables.

CSV case with a simple metadata

A minimal metadata for that case can be:

{
    "@context": "http://www.w3.org/ns/csvw",
    "null": "",
    "resources" : [{
      "url": "http://foo.example/DB/People",
      "aboutUrl" : "http://foo.example/DB/People/ID={_row}",
      "tableSchema": {
        "columns": [{
          "name": "ID",
          "datatype": "integer"
        }, {
          "name": "fname",
        }, {
          "name": "addr",
          "datatype": "integer"
        }, {
          "name": "ref",
          "virtual": "true",
          "propertyUrl": "http://foo.example/DB/People#ref-addr",
          "valueUrl" : "http://foo.example/DB/Addresses/ID={addr}"
        }, {
          "name": "type",
          "virtual": "true",
          "propertyUrl": "rdf:type",
          "valueUrl" : "http://foo.example/DB/People"
        }],
      }
    }, {
      "url": "http://foo.example/DB/Addresses",
      "aboutUrl" : "http://foo.example/DB/Addresses/ID={_row}",
      "tableSchema": [{
        "columns": [{
          "name": "ID",
          "datatype": "integer"
        }, {
          "name": "city",
        }, {
          "name": "state",
        }, {
          "name": "type",
          "virtual": true,
          "propertyUrl": "rdf:type",
          "valueUrl" : "http://foo.example/DB/Addresses"
        }],
    }]
}

Using this metadata, the output of the CSV2RDF processor will be identical to the one produced by the RDF Direct Mapping. (Note that he CSV Metadata can also provide information on foreign keys but for validation purposes only.)

Clone this wiki locally