turtle – Parerga und Paralipomena http://www.michelepasin.org/blog At the core of all well-founded belief lies belief that is unfounded - Wittgenstein Sun, 12 Oct 2014 10:02:06 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.11 13825966 An interactive Turtle shell http://www.michelepasin.org/blog/2014/10/12/interactive-turtle-shell/ http://www.michelepasin.org/blog/2014/10/12/interactive-turtle-shell/#comments Sun, 12 Oct 2014 09:21:41 +0000 http://www.michelepasin.org/blog/?p=2495 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:

[michele.pasin]@here:~/code/python>sketch.py 
Good morning. Ready to Turtle away. Type docs() for help.
In [1]: docs()

====Sketch v 0.2====

add()  ==> add statements to the graph
...........SHORTCUTS:
...........'class' = owl:Class
...........'sub' = rdfs:subClassOf
...........TURTLE SYNTAX:  http://www.w3.org/TR/turtle/

show() ==> shows the graph. Can take an OPTIONAL argument for the format.
...........eg 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: <http://purl.org/ontology/bibo/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix npg: <http://ns.nature.com/terms/> .
@prefix npgg: <http://ns.nature.com/graphs/> .
@prefix npgx: <http://ns.nature.com/extensions/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

: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:RDF
   xmlns="http://this.sketch#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>
  <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:Description rdf:about="http://this.sketch#organization">
    <rdfs:subClassOf rdf:resource="http://this.sketch#agent"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://this.sketch#DamageInc">
    <rdf:type rdf:resource="http://this.sketch#organization"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://this.sketch#person">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <rdfs:subClassOf rdf:resource="http://this.sketch#agent"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://this.sketch#worksIn">
    <rdfs:domain rdf:resource="http://this.sketch#person"/>
    <rdfs:range rdf:resource="http://this.sketch#organization"/>
  </rdf:Description>
</rdf:RDF>

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?

 

]]>
http://www.michelepasin.org/blog/2014/10/12/interactive-turtle-shell/feed/ 1 2495
Textmate bundle for Turtle and Sparql http://www.michelepasin.org/blog/2013/08/13/textmate-bundle-for-turtle-and-sparql/ Tue, 13 Aug 2013 17:07:34 +0000 http://www.michelepasin.org/blog/?p=2392 I recently ran into the Textmate bundle for Turtle, an extension for the Textmate osx editor aimed at facilitating working with RDF and SPARQL. If you happen to be using these technologies, well I’d suggest you take a look at the following post.

The Resource Description Framework is a general-purpose language for representing information which is widely used on the web in order to encode metadata in a machine-interoperable format.

Turtle, the terse RDF Triple Language, is a textual syntax for RDF which aims at human readability and compactness (among other things).
This is what it looks like:


@prefix rdf: 
@prefix rdfs: 
@prefix xsd: .
@base 

:MotorVehicle a rdfs:Class.

:PassengerVehicle a rdfs:Class;
   rdfs:subClassOf :MotorVehicle.

:Person a rdfs:Class.

xsd:integer a rdfs:Datatype.

:registeredTo a rdf:Property;
   rdfs:domain :MotorVehicle;
   rdfs:range  :Person.

:myLittleCar a PassengerVehicle

The termite library in question, in a nutshell, provides a bunch of snippets and query mechanisms that make it easier to work with Turtle RDF and related technologies.
More precisely, here’s the official features breakdown:

  • Language grammar for Turtle and SPARQL 1.1
  • Powerful (!) auto-completion (live-aggregated)
  • Documentation for classes and roles/properties at your fingertips (live-aggregated)
  • Interactive SPARQL query scratchpad
  • Some snippets (prefixes and document skeleton)
  • Solid syntax validation
  • Commands for instant graph visualization of a knowledge base (requires Graphviz and Raptor)
  • Conversion between all common RDF formats
  • Example

    In order to query a SPARQL endpoint (eg DBPedia) just type this in and run it (apple-R):

    
    #QUERY <http://dbpedia.org/sparql>                    
    SELECT DISTINCT ?s ?label                             
    WHERE {                                               
        ?s <http://dbpedia.org/property/season> ?o .      
    }  
    

    Obviously you can query any endpoint, e.g. data.nature.com:

    
    
    #QUERY <http://data.nature.com/sparql>
    
    PREFIX bibo:<http://purl.org/ontology/bibo/>
    PREFIX dc:<http://purl.org/dc/elements/1.1/>
    PREFIX dcterms:<http://purl.org/dc/terms/>
    PREFIX foaf:<http://xmlns.com/foaf/0.1/>
    PREFIX npg:<http://ns.nature.com/terms/>
    PREFIX npgg:<http://ns.nature.com/graphs/>
    PREFIX npgx:<http://ns.nature.com/extensions/>
    PREFIX owl:<http://www.w3.org/2002/07/owl#>
    PREFIX prism:<http://prismstandard.org/namespaces/basic/2.1/>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX sc:<http://purl.org/science/owl/sciencecommons/>
    PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
    PREFIX void:<http://rdfs.org/ns/void#>
    PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
    
    
    SELECT *                            
    WHERE {                                                
        ?doi a npg:Article . 
        ?doi dc:title ?title .
        ?doi prism:publicationDate ?date
    } 
    limit 100 
    
    

    And this is just the tip of the iceberg. Autocompletion, visualisations etc… it may be the Textmate-Semantic Web swiss army knife you’ve been looking for.

     

     

     

     

    ]]>
    2392