-
Notifications
You must be signed in to change notification settings - Fork 48
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 |
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
andstate
columns contain strings
-
- The
addr
column in thePeople
table contains foreign keys that references theID
field of theAddresses
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.
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.)