0.0
No commit activity in last 3 years
No release in over 3 years
a small domain specific language for writing owl based ontologies
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.7.2
~> 0.7.0
~> 0.9
~> 10.2
~> 2.14
~> 0.7.1
 Project Readme

ontology-united

Gem Version Build Status Coverage Status

ontology-united is a small DSL (domain specific language) for writing OWL ontologies.

It is mainly intended as a gem to be used as part of the ontohub project to create ontologies for testing in order to not rely on fixtures. See the corresponding issue (ontohub/ontohub#786).

Currently it supports only the manchester syntax as serialization mechanism and is fairly limited in its owl support. However it will be further developed, maintained and extended.

Installation

Add this line to your application's Gemfile:

gem 'ontology-united'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ontology-united

Usage

First you'll need to require the gem (unless you are using bundler):

require 'ontology-united'

After doing this you'll be able to create an ontology in two different ways. Either by explicitly using the defined method:

OntologyUnited::DSL::OntologyDSL.define('MyOntologyName') do
end

or by including the convenience module, which will give you a more useful/shorter method call:

# you'll only need to do this once per namespace
include OntologyUnited::Convenience

define_ontology('MyOntologyName') do
end

Building your ontology

Usually there is more than one way to building your ontology, i will elaborate on the benefits and drawbacks of each method. However i will now use the convenience method of building an ontology.

Prefix

In order to benefit from ontology-united you'll first need to create a prefix. As the block passed to define_ontology is instance_evaled on the ontology, self will be the current ontology. So you can create a prefix which points to the current ontology.

define_ontology('MyOntologyName') do
  this = prefix('thisOntology', self)
end

However technically you can also pass an IRI (internationalized resource identifier) instead of self. But then you're pretty much on your own. You'll need to handle iri-management yourself.

# Handling iri-management yourself:
define_ontology('MyOntologyName') do
  this = prefix('thisOntology', 'http://example.com/MyOntologyName#')
end

Class (OWL)

define_ontology('MyOntologyName') do
  this = prefix('thisOntology', self)
  this.class('ASampleClass')
end

The .class method on a prefix, will create a prefixed class inside of the current ontology. If you do not want to rely on prefixes you can also use ontology_class() but then the argument has to be an IRI instead of a name. And again (as with prefixes) your currently on your own for iri-management.

# Handling iri-management yourself:
define_ontology('MyOntologyName') do
  ontology_class('http://example.com/MyOntology#ASampleClass')
end

By the way, you do not need to store ontology classes inside variables in order to use them again (i.e. in sentences). You can just define them again. The system will figure out by itself, that you actually meant the same class.

Sentence

Currently ontology-united only supports sub_class_of sentences. This will be extended in the future, but it has to be enough for now.

define_ontology('MyOntologyName') do
  this = prefix('thisOntology', self)
  this.class('ASampleClass').sub_class_of this.class('AParentClass')
end

Imports

You can define ontologies inside of other ontologies, through the inner define-method, which works exactly as the standard define method (also called define_ontology in convenience mode).

define_ontology('Foo') do
  this = prefix('this', self)
  define('Bar') do
    rr = prefix('rr', self)
    rr.class('SomeBar')
  end
  this.class('Bar').sub_class_of this.class('Foo')
  this.class('something')
  this.class('something').sub_class_of this.class('Foo')
end

As you might've guessed this is pretty useful when using imports, as this would allow you to import an ontology which you just defined in-place. Let's take a look at this:

define_ontology('Foo') do
  import define('Bar') do
    rr = prefix('rr', self)
    rr.class('SomeBar')
  end
  this.class('Bar').sub_class_of this.class('Foo')
end

The import method is key, and that is basically it.

Serialization

Let's assume we have an ontology:

ontology = define_ontology('Foo') do
  rr = prefix('rr', self)
  imports define('Bar') do
    rr = prefix('rr', self)
    rr.class('SomeBar')
  end
  rr.class('Bar').sub_class_of rr.class('Foo')
  rr.class('something')
  rr.class('something').sub_class_of rr.class('Foo')
end

If we want to work with it, we can query it for its IRI like this: ontology.iri, which will return a file://-schema IRI.

If we want access to the Tempfile (which ontology-united uses internally), we can call ontology.file.

Both methods will ensure that the corresponding file is created and serialized, including all imported ontologies.