I have written a simple module to store and manipulate an ontology which is provided in a flat file using Perl. For this, I use the Graph module which is excellent.
One issue I am having to deal with is how to store the textual definitions for the vertexes in the ontology. Each term has a small text description which I want to store and retrieve. At the moment, as Graph does not support this directly, I use an internal hash.
I was wondering, is there a more elegant way of having a single data structure to store both the ontology graph and the definitions/data associated with nodes?
Following things come to mind:
if this is just a "simple ontology", i.e. a taxonomy, or even simpler, a nested list of terms, then a simple YAML file sounds sufficient. Once deserialized into a Perl hash, you have mapped any nesting into hashes/arrays.
if you want your ontology (dictionary, subterms, superterms) to be more standardized you may want to look at RDF::SKOS. SKOS is the W3C standard for simply (non-logic) ontologies.
if you are daring, you may also want to look at TM (topic maps). It has a similar "functionality" as SKOS, but is an ISO (not W3C) standard.
if you expect your ontology to grow/evolve and also hold simple logic statements (see Description Logics), you may want to look at one of the RDF packages. I have used RDF::Redland, but also RDF::Simple or what Toby and Kjetil do, are worth trying. Lots of activity recently.
if your ontology is BIG, or you want to store A LOT of instance data alongside your ontology, then RDF::AllegroGraph is the way to go. But that uses an external server. Serious software.
Parting note: Not everything which looks like a graph is one. Neither Topic Maps nor RDF are graph structures actually.
The Graph
module allows you to attach attributes to the vertices and edges. Is that what you mean when you say you are currently using an internal hash? If not, perhaps this will help:
use Graph;
my $g = Graph->new;
my ($v1, $v2) = qw(A B);
$g->add_edge($v1, $v2);
$g->set_vertex_attribute($_, 'desc', "Vertex $_") for $v1, $v2;
print $g->get_vertex_attribute($_, 'desc'), "\n" for $v1, $v2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With