An interactive Turtle shell

Wouldn’t it be nice to have an interactive environment where you quickly hack together an RDF model and then show it to your clients or colleagues in a more accessible format – i.e. a diagram?

Don’t know if there’s anything like that already, but the other day while polishing up the OntosPy library I’ve taken a couple of hours of fun-coding and put together a module that lets you do that.

The idea is simple: load an interactive environment where you can quickly sketch out a few ideas using the (very readable) Turtle rdf format.

Then export it onto a different representation e.g. a graphical one, so that it can be shown to people. Or just to keep working on it via a medium that offers different affordances.

So here it is:

Good morning. Ready to Turtle away. Type docs() for help.
In [1]: docs()

====Sketch v 0.2====

add()  ==> add statements to the graph
...........'class' = owl:Class
...........'sub' = rdfs:subClassOf
...........TURTLE SYNTAX:

show() ==> shows the graph. Can take an OPTIONAL argument for the format. one of['xml', 'n3', 'turtle', 'nt', 'pretty-xml', dot']

clear()	 ==> clears the graph
...........all triples are removed

omnigraffle() ==> creates a dot file and opens it with omnigraffle
...........First you must set Omingraffle as your system default app for dot files!

quit() ==> exit

====Have fun!====

In [2]: add()
Multi-line input. Enter ### when finished.
:person a class
:mike a :person
:person sub :agent
:organization sub :agent
:worksIn rdfs:domain :person
:worksIn rdfs:range :organization
:mike :worksIn :DamageInc
:DamageInc a :organization

In [3]: show()
@prefix : <http://this.sketch#> .
@prefix bibo: <> .
@prefix foaf: <> .
@prefix npg: <> .
@prefix npgg: <> .
@prefix npgx: <> .
@prefix owl: <> .
@prefix rdf: <> .
@prefix rdfs: <> .
@prefix skos: <> .
@prefix xml: <> .
@prefix xsd: <> .

:mike a :person ;
    :worksIn :DamageInc .

:worksIn rdfs:domain :person ;
    rdfs:range :organization .

:DamageInc a :organization .

:organization rdfs:subClassOf :agent .

:person a owl:Class ;
    rdfs:subClassOf :agent .

In [4]: show("xml")
<?xml version="1.0" encoding="UTF-8"?>
  <rdf:Description rdf:about="http://this.sketch#mike">
    <rdf:type rdf:resource="http://this.sketch#person"/>
    <worksIn rdf:resource="http://this.sketch#DamageInc"/>
  <rdf:Description rdf:about="http://this.sketch#organization">
    <rdfs:subClassOf rdf:resource="http://this.sketch#agent"/>
  <rdf:Description rdf:about="http://this.sketch#DamageInc">
    <rdf:type rdf:resource="http://this.sketch#organization"/>
  <rdf:Description rdf:about="http://this.sketch#person">
    <rdf:type rdf:resource=""/>
    <rdfs:subClassOf rdf:resource="http://this.sketch#agent"/>
  <rdf:Description rdf:about="http://this.sketch#worksIn">
    <rdfs:domain rdf:resource="http://this.sketch#person"/>
    <rdfs:range rdf:resource="http://this.sketch#organization"/>

In [5]: omnigraffle()
### saves a dot file and tries to open it with your default editor
### if you're on a mac and have omnigraffle - that could be the one!

In [6]: quit()

If you are mac based and you have associated .dot files to the excellent Omnigraffle app, you’d see something like this:

Sketch Screen Shot 2014 10 12 at 10 12 48

Sketch Screen Shot 2014 10 12 at 10 13 32

That speeded up my work quite a bit – especially in situations where you don’t mind about precision but are more interested in quickly showing the merits of a modelling approach.

Any comments or ideas on how to develop this further?