RDF graph

The standard graph data model for semantic web.

Semantics

The known introduction to RDF(S) semantics is DBLP:books/crc/Hitzler2010, the different semantics simple, RDF, RDFS, D-entailment defines respectively the semantic of graph with labelled nulls, RDF properties, RDFS properties and datatypes.

In DBLP:journals/ws/Horst05, the problem raises by the fact that the blank nodes can not appear in property position, but such triple can be derived or use as required intermediate triples to derive correct triples. So they propose a alternative syntax for RDF graph, where blank nodes are allowed in property position. They also shows that decide whether \(G\) entails \(G'\) under RDFS semantics is NP-complete in general and P-complete if \(G'\) does not contain blank node.

Query answering

Tools

Conversion of format

Rapper is one of the more useful and efficient tools for RDF graph conversion. I have saved nice instructions about it. Unfortunately, rapper does not support JSON-LD format, so I used Apache Jena with the riot command line instead:

## INSTALLATION
# download apache jena archive from https://jena.apache.org/download/index.cgi
tar xvzf apache-jena-X.tar.gz
cp -r apache-jena-X $HOME/.jena
echo 'export PATH="$PATH:$HOME/.jena/bin/"' >> ~/.bashrc

## USAGE for json-ld to NTriple convertion
# see also: https://jena.apache.org/documentation/io/
riot --syntax=json-ld --output=ntriples example.json > example.nt

Visualization

Prefix Simplification

sed -i 's/http:\/\/www.w3.org\/2000\/01\/rdf-schema#/rdfs:/g' $FILE
sed -i 's/http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#/rdf:/g' $FILE
sed -i 's/http:\/\/xmlns.com\/foaf\/0.1\//foaf:/g' $FILE
sed -i 's$http://purl.org/dc/elements/1.1/$purl:$g' $FILE
sed -i 's$http://purl.org/dc/terms/$purl:$g' $FILE
sed -i 's$http://swrc.ontoware.org/ontology#$dblp:$g' $FILE

DOT output

A command line to create dot and svg files from turtle files:

rdf_img triples.ttl

If you want to switch the orientation, you can evaluate:

dot -Grankdir="LR" -Tsvg triples.dot > triples.svg

ASCII output

installation

sudo apt-get install cpanminus
sudo cpanm Graph::Easy

run on an example

cat ~/inria/virtual-graphs/RDF-GLAV-integration/BDA_presentation/img/graphs/rdf.dot   | graph-easy

----------- ex:mayorOf --------------- rdf:type ------------

ex:Dupont -------–—> ex:FieldsTown -----–—> ex:City

----------- --------------- ------------ ----------- ex:manages --------------- rdf:type ------------

ex:Smith -------–—> ex:SmallShop -----–—> ex:Company

----------- --------------- ------------

digraph {  
  this -> is
  this -> a
  a -> test 
}
graph-easy

---- ------

is <-- this

---- ------

v

------

a

------

v

 test 
digraph {  
contact -> phoneNumber
}
graph-easy

-------------

contact

-------------

v

 phoneNumber 

Web visualizations

We can use:

RDF visualizer performances can be improved by moving from D3 to Vis.js or sigma.js renderer, even if this latter seems a bit out dated.

FOAF

Database

There is a database built from a exploration of foaf documents in 2004, but the sql is not compatible with postgres

sed -i "s.\\\'.''.g" triple_person.sql
sed -i "s.) $.) ;$.g" triple_person.sql
psql -d foafdb -f triple_person.sql

Once load, we can extract a NT file from the database:

psql -F " " -t -d foafdb -c "SELECT subject, predicate, object from triple_person limit 1000;" > foaf.rdf
sed -i "s/\s*| />\t</g" foaf.rdf
sed -i "s/^ /</g" foaf.rdf
sed -i "s/ $/> ./g" foaf.rdf

This post accepts webmentions. Do you have the URL to your post?

Otherwise, send your comment on my service.

Or interact from the fediverse with your username:

fediverse logo Share on the Fediverse