-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
This section of the wiki is a quick start guide for the infrastructure you’ll need to use the library. Triple stores, owl/rdf, and sparql are their own beasts and this guide will not explain them. For more information on those topics see the Resources page.
Allegro graph is a triple store written in allegro common lisp. There is a java version available as well, but this guide uses the lisp version. You’ll need to follow this guide to setup allegro graph. To interact with your triple store via a lisp console you can run the mlisp or alisp program from the command line. In the lisp console you’ll need to run the following commands to start up allegro graph:
(require :agraph) (in-package :triple-store-user) (setf *synchronize-automatically* t) (use-package :db.agraph.sparql)
If all runs smoothly you’ve got a running triple store. If all does not run smoothly you’ll need to dig through Allegro Graphs docs to understand why. Note for Lispers: There is a guide to setting up slime with allegro cl here.
Similar to a relational database, allegro graph uses namespaces to segregate triple stores being hosted by the server. To create a new triple store run the following commands in your lisp console:
(create-triple-store "/some-directory-path/name-of-your-new-triple-store" :if-exists :supersede)
Subsequent forays into the lisp console will have you running the following to open rather than overwrite your triple store:
(open-triple-store "/some-directory-path/name-of-your-new-triple-store")
For more information on creating and deleting triple stores see the api docs for allegro or the allegro graph tutorial
To connect to Allegro Graph over http you’ll need to start the http server and publish the triple store you’ve created to the server.
(defvar sesame-server (make-sesame-server :start (list :port 8111))) ;; Creates the server and assigns it to the sesame-server variable (export-to-sesame sesame-server :name "name-of-your-new-triple-store" :directory "/some-directory-path/") ;; publishes a triple store to the server
To double check that your server is now running point your browser to http://localhost:8111/sesame/repositories This should give you an xml document which lists your triple store among the repositories.
There are several ways to add triples to allegro graph. In all cases you should remember that this is rdf/owl which is xml based which use name spaces to clarify information sources and segregate duplicate tag names (and in this case triples) into their proper contexts. For more information on this see: OWL Namespaces
You can add triples directly in the allegro console as described here, but I’d suggest grabbing an ontology in rdf/owl or ntriples format and using the following command:
;; Once you have your triple store open (load-xml/rdf "/path-to-your-owl-file/owl-or-rdf-file")
Now that you have a triple store and a sesame server it’s time to bust out the irb and play with Active Sesame.
Lets create a repository object which will interact with AllegroGraph:
require 'active_sesame'
repo = ActiveSesame::Repository.new(SesameProtocol, {:repository_uri => "http://localhost:8111/sesame/repositories", :triple_store_id => "name-of-your-triple-store", :location => "http://localhost:8111/sesame/repositories/name-of-your-triple-store", :base_uri => "http://www.owl-ontologies.com/Ontology12345.owl#"})
# The base uri is a convenience when writing sparql queries so that you don't have to type out the whole uri for your triples
results = repo.find_by_sparql("SELECT ?subject ?predicate ?object { ?subject ?predicate ?object }") #This will select every triple in your triple store
triples = ActiveSesame::ResultParser.tableize(results) #This turns the sparql result xml into a list of hashes
That’s the most basic function of the library. See the other wiki pages for more information about using the library to make interacting with your triple store cleaner. To learn more about the underlying technology of the semantic see the resources page.