# A Graph DB-Based Solution for Semantic Technologies in the Future Internet
## 4 Connection between the LPG and SW
### Alignment with Existing Semantic Web Resources  
_rml:logicalSource_  
[_rml:referenceFormulation_ql: CypherPattern; _rml:iterator_ 'label name in GraphDB'];  
Next, we apply R2 RML directives (_rr:subjectMap and rr:predicateObjectMap_) to formalize the mapping with subject, predicate, and object of the ontology with which we want to map the DB graph entities found by the query execution. Let us introduce a small example that is useful for understanding how each single element is mapped. Consider an LPG-based KG about movies (node label :Movie) and people (node label :Person), where movies have a title (property title) and a release date (property release), and persons have a name (property name) and a birth date (property born). Both kinds of nodes have a numeric code (property id) to uniquely identify their instances. There is a relationship between people and the movies they have acted in (type :actedIn). Assuming that we want to map the LPG fragment in Listing 3 to the RDF using the classes and properties from the schema.org ([[https://schema.org/](https://schema.org/)]([https://schema.org/](https://schema.org/)), accessed on 9 September 2023) vocabulary. Listing 4 shows the desired result. To obtain this mapping, we must specify that LPG attribute 'name' is mapped onto'schema:name', 'born' onto'schema:birthDate', and so on. ```
1(:Person{id:1,name:\"[PERSON]\",born:date(\"1940-04-25\"))}
2(:Person{id:2,name:\"[PERSON]\",born:date(\"1943-08-17\"))}
3(:Movie{id:1,title:\"TheGodfatherPartII\",release:date(\"1975-06-20\")})
5(:Person{id:1})-[:actedIn]->(:Movie(id:1))
7(:Person{id:2})-[:actedIn]->(:Movie(id:1))
```  
Listing 3: Example of simple graph data. ```
1@prefixperson:<[[http://loc.example.com/person/](http://loc.example.com/person/)]([http://loc.example.com/person/](http://loc.example.com/person/))>. 2@prefixmovie:<[[http://loc.example.com/movie/](http://loc.example.com/movie/)]([http://loc.example.com/movie/](http://loc.example.com/movie/))>. 3}
4 person:1 schema:name\"[PERSON]\";schema:birthDate\"1940-04-25\"\"xsd:date. 5 person:2 schema:name\"[PERSON]\";schema:birthDate\"1943-08-17\"\"xsd:date. 6}
7 movie:1
8 schema:name\"TheGodfatherPartII\";
9 schema:datePublished\"1975-06-20\"\"xsd:date;
10 schema:actorperson:1,person:2. ```  
Listing 4: Example of mapping based on an extension of RML. We assume that the class and property names are unique. For the movie example, we specify the 'PersonMapping', in which all elements related to the label 'Person' (in the LPG graph) must be specified. In this section, we specify how to map all the attributes of nodes of type 'Person' ('name' and 'born', among the others). After doing the same for the other class in the example ('Movie'), we may specify how to map the relationship 'actedIn'. We understand that it has the same meaning as the standard object property'schema:actor'. In the mapping, we obviously also specify the mappings for the subject and the object. The full code of the mapping is shown in Listing 5. Let us briefly analyze it line by line. R2 RML and RML mappings consist of a set of 'triple maps', each representing a source of triples for the target RDF graph. Listing 5 defines 3 triple maps: <#PersonMapping> (lines 8-20), <#MovieMapping> (lines 22-33), and <#ActedInMapping> (lines 35-46). As per the RML specification, each triple map is based on a different _logical source_ which, in our case, is a Cypher pattern, i.e., an expression that can be used in the MATCH clause of a Cypher query. <#PersonMapping> maps any LPG node with the label :Person to an IRI of the type schema:Person built from the property id with a template mechanism. Its LPG properties name and born are mapped to the RDF properties schema:name and schema:birthDate, respectively. Similarly, <#MovieMapping> maps LPG nodes with the label :Movie onto IRIs of the type schema:Movie and their LPG properties onto the corresponding RDF properties.