# A Graph DB-Based Solution for Semantic Technologies in the Future Internet
## 4 Connection between the LPG and SW
### SPARQL Mapping  
Publishing a GraphBRAIN KG in the SW by entirely exporting it would require the translation to be run again after each modification of the KG. An approach that is more suitable for dynamic KGs would be to expose the KG as an online SPARQL endpoint, from which data can be fetched at need by any SW-compliant application. Of course, the mapping technicalities between the different underlying representations should be transparent to the users. In the following text, we identify the resources by generic property values, as is done in traditional DB settings, but not necessarily by URIs. In the following text, we refer again to the movie KG and to the mapping in Listing 5 and to the excerpt of a possible movie dataset shown in Figure 3. Two actors, '[PERSON]' and '[PERSON]', both acted in 'The Godfather Part II', but '[PERSON]' also acted in 'The Godfather', whose sequel is 'The Godfather Part II'. The two actors are labeled as 'Person', and the two films as 'Movie'. Note that we defined an equivalent concept for the relationship 'actedIn', but not for'sequel' (see Listing 5). Since one of the possible users of our SPARQL endpoint is GraphBRAIN's SKATEBOARD interface for KG browsing and exploration (see Section 5), here, we focus on three requests representing some of the most common SKATEBOARD queries. (1) Return the type of node having a property. This corresponds to the following SPARQL query:  
SELECT DISTINCT?object?objectclass WHERE  
{?object [property] [value]. ?object rdf:type?objectclass}  
Our parsing strategy recognizes the query type thanks to the keyword **rdf:type**, and then, using simple pattern matching of specific tags in the query, it extracts the property [property], and the value [value], e.g., suppose the query asks for the type of node whose name ([[http://schema.org/name](http://schema.org/name)]([http://schema.org/name](http://schema.org/name))) matches the string 'The Godfather'. We check in the mapping file whether '[[http://schema.org/name](http://schema.org/name)]([http://schema.org/name](http://schema.org/name))' corresponds to some property in the graph, and indeed, it has two correspondences: 'p.name' in PersonMapping, and'm.title' in MovieMapping. PersonMapping has as a logical source 'Person', while MovieMapping has as a logical source 'Movie'. So, we check the graph for all 'Person' nodes with the value 'The Godfather' as the property 'name' and all 'Movie' nodes with the value 'The Godfather' as the property 'title'. To do this, when the parser recognizes that we are looking for the type of resource given a property, we prepare a general parametric Cypher query to retrieve this information from the graph. In our case, we execute this query, which is the result of the interpretation of the SPARQL query after the mapping process:  
MATCH (n:Movie {title:'The Godfather'}) return labels(n)  
UNION ALL  
MATCH (n:Person {name:'The Godfather'}) return labels(n)  
As expected, the result is the film named 'The Godfather'. Clearly, we do not return the type extracted from the graph, but obtain its reverse mapping according to Listing 5. In the graph shown in Figure 3, the label of 'The Godfather' is 'Movie', but by reversing the mapping procedure, we return '[[http://schema.org/Movie](http://schema.org/Movie)]([http://schema.org/Movie](http://schema.org/Movie))'. This allows SW-based applications to infer new knowledge about the specific instance provided by the graph DB. Figure 3: Excerpt of KG about actors starring in films. (2) Return all links directly connected to a given node. This corresponds to the following SPARQL query:  
```
SELECTDISTINCT?linkWHERE{ {?object[property][value].?object?link?outObject. } UNION {?inObject?link?object.?object[property][value]. } }
```  
As shown in the previous scenario, we used a property value to identify the starting node. Since we do not care about the direction of the object property, the nodes we are looking for can be connected by an incoming or an outgoing arc to the given node, and we must return the union of these two cases.