Search code examples
rdfentity-attribute-valuer2rml

Is R2RML suitable for EAV tables?


Beginning to read about R2RML I wonder if this language would also be suitable for mapping database tables that follow the entity-attribute-value model to RDF and how a simple example would look like.

A survey of RDB to RDF translation approaches and tools refers to a "1 table to n classes" feature as followed:

Ability to use the values of a column as a categorization pattern: tuples of the table will be translated into instances of different ontological classes based on the value of this attribute. This feature can be seen as an extension of the "select conditions" feature as it results in not only filtering out rows, but the filter helps selecting rows to be converted into instance of one class or another.


Solution

  • A simple mapping could look like this:

    [
      rr:logicalTable [ rr:tableName "eav_table" ] ;
      rr:subjectMap [ rr:template "http://example.com/ontology.rdf#Entity/{entity_column}/" ] ;
      rr:predicateObjectMap [
        rr:predicateMap [
          rr:template "http://example.com/ontology.rdf#{attribute_column}"
        ] ;
        rr:objectMap [
          rr:template "http://example.com/ontology.rdf#Value/{value_column}/"
        ]
      ]
    ] .
    

    If a more sophisticated SQL statement is needed, one would use rr:sqlQuery instead of rr:tableName:

      rr:logicalTable [
        rr:sqlQuery "SELECT entity_column, attribute_column, value_column FROM eav_table;"
      ] ;
    

    For the set of available attributes, the corresponding predicates may be further characterized by additional mappings.