Jakob Voß > SKOS-Simple-0.09_01 > SKOS::Simple



Annotate this POD


View/Report Bugs
Module Version: 0.09_01   Source  


SKOS::Simple - SKOS with entailment and without package dependencies


This module provides a simple class to create and handle Simple Knowledge Organization Systems (thesauri, classifications, etc.) in SKOS. In contrast to most RDF-related modules, SKOS::Simple does not depend on any non-core modules, so you can install it by just copying one file. The module implements basic entailment rules of the SKOS standard without the burden of a full RDF reasoning engine (actually this module internally does not use RDF, which is overrated anyway). For this reason the set of possible SKOS schemes, that can be handled by SKOS::Simple is limited by some basic assumptions.

The current version of this class is optimized form creating and serializing valid SKOS schemes, but not for reading and modifying them. A common use case of SKOS::Simple is to transform a given terminology from some custom format to SKOS, which is then serialized in Terse RDF Triple language (Turtle). You can then publish the Turtle data and/or process them with general RDF and SKOS tools.


The current version of this module aims at classifications only! Support for thesauri will be implemented later (or just write your own patch and send me for inclusion in SKOS::Simple).


An instance of SKOS::Simple holds exactely one skos:ConceptScheme with the following properties:


  my $skos = SKOS::Simple->new( 
      base  => 'http://example.com/kos/',
      title => 'My little Knowledge Organization System',

  $skos->add_concept( pref => { en => 'foo', ru => 'baz' } );
  $skos->add_concept( notation => '42.X-23' );

  print $skos->turtle;

SKOS::Simple only supports a limited set of possible RDF statements. To add more RDF data, you can use the serializing functions:

  use SKOS::Simple qw(:turtle);

  print $skos->turtle;



new( [ %properties ] )

Creates a new concept scheme with some given properties.


The URI prefix that is used for all concepts (not required but recommended).


The URI of the whole concept scheme (skos:conceptScheme). By default the base property is used as concept scheme URI.


Title(s) of the concept scheme. Must be either a string or a hash that maps language tags to strings.


An optional hash with additional namespaces. You can also override standard namespaces (e.g. skos => 'http://www.w3.org/2008/05/skos#' to use another SKOS namespace). All namespaces explicitly specified by this parameter are always included as @prefix in the Turtle output.






Either tree or multi or none (default). At the moment only tree is supported.








Additional properties as structured Turtle. Triples with predicates a, dc:title, and skos:... are not allowed but removed.

add_concept ( %properties )

Adds a concept with given properties. Only the identifying property to be used as concept id (notation or label) is mandatory. If there already is a concept with the same id, both are merged.

Returns the id of the added or modfied concept.

# label is not id, but unique if ( $self->{label} eq 'unique' and $self->{identity} ne 'label') { if ( $concept->{pref} push $concept->{pref}->{$lang} = $prefLabel; # TODO; check if already different! @labels = (); } ^

# croak 'Concepts must be unique per notation' # if $self->{u_notation}->{ $notation }; # $self->{u_notation}->{ $notation } = $id; # }

    } elsif ( $self->{label} eq 'unique' ) {
        # TODO: multiple labels
        croak 'Concepts must have a label' unless @labels;
        croak 'Concepts must have only one label' if @labels > 1;

        croak 'Concepts must be unique per notation' 
            if $self->{u_label}->{ $lang }->{ $labels[0] };
        $self->{u_label}->{ $lang }->{ $labels[0] } = $id;

top_concepts ( [ @ids ] )

Marks one or more concepts as top concepts. The given concepts must already exist and must not have any broader concepts. Without parameters, this methods returns a list of all top concept identifiers. Unless you explicitly specify top concepts, a list of all concepts without broader concepts is returned. As soon as you explicitly set some top concepts, they will be the only top concepts. You can reset the top concepts to all concepts without broader concepts, provide undef as only argument.

add_hashref ( $hashref )


concept_id ( notation => $notation | label => $label )

Returns the identifier of a concept with given notation and/or label. It is not checked whether the given concept exists in this scheme.

has_concept ( $id )

Returns whether there is a concept of the given id.


Returns the total number of concepts.


Returns a list of all concept's ids.


The following methods serialize the concept scheme or parts of it in Terse RDF Triple language (RDF/Turtle). A valid serialization must start with some namespace declarations, and a base declaration. Both are only included by the turtle method, but they can also be requested independently. All return values end with a newline unless they are the empty string.

A later version may also support 'hashref' format for serializing.

turtle ( [ %options ] )

Returns a full Turtle serialization of this concept scheme. The return value is equivalent to:

    $skos->namespaces_turtle .
    $skos->base_turtle .
    $skos->scheme_turtle .

The parameter lean => 1 enables a lean serialization, which does not include infereable RDF statements. Other parameters are passed to scheme_turtle and concepts_turtle as well.


Returns Turtle syntax namespace declarations for this scheme.


Returns a Turtle URI base declaration for this scheme. An empty string is returned if no URI base is set.

scheme_turtle ( [ top => 0 ] )

Returns RDF statements about the concept scheme in Turtle syntax. Details about concepts or namespace/base declarations are not included. The option top => 0 (enabled by default) can be used to supress serializing the skos:hasTopConcept property.

concept_turtle ( $id [, %options ] )

Returns a concept in Turtle syntax. With option top => 0 you can disable serializing the skos:topConceptOf property. By default, each concept is connected to its concept scheme with either skos:topConceptOf, or with skos:inScheme. With option scheme => 0 you can disable serializing the latter property. With scheme => 2 the property skos:inScheme is also included in the serialization if skos:topConceptOf is given, although the former can be derived as super-property of the latter.

concepts_turtle ( [ %options ] )

Returns all concepts in Turtle syntax.


The following functions can be exported on request. The export tags :turtle and :all can be used to export all turtle_... or all functions.


This is just a shortcut for SKOS::Simple->new.

The following methods Turtle serialization can also be exported as functions with the :turtle include parameter. Note that they do not implement a full Turtle serializer because they don't check whether the URIs, QNames, and/or language tags are valid. The followinge example shows some ways of use:

  print turtle_statement( 
      "a" => "<http://purl.org/ontology/bibo/Document>",
      "dc:creator" => [ 
          '"Terry Winograd"', 
          '"Fernando Flores"' 
      "dc:date" => turtle_literal( "1987", type => "xs:gYear" ),
      "dc:title" =>
          { en => "Understanding Computers and Cognition" },
      "dc:decription" => undef

turtle_statement ( $subject, $predicate => $object [, ... ] )

Returns a (set of) RDF statements in Turtle syntax. Subject and predicate parameters must be strings. Object parameters must either be strings or arrays of strings. This function strips undefined values and empty strings, but it does not further check or validate parameter values.

turtle_literal ( $string [ [ lang => ] $language | [ type => ] $datatype ] )

Returns a literal string escaped in Turtle syntax. You can optionally provide either a language or a full datatype URI (but their values are not validated). Returns the empty string instead of a Turtle value, if $string is undef or ""!

turtle_uri ( $uri )

Returns an URI in Turtle syntax, that is "<$uri>". Returns the empty string, if $uri is undef, but <> if $uri is the empty string. In most cases you better directly write "<$uri>".

turtle_literal_list ( $literal | @array_of_literals | { $language => $literal } )

Returns a list of literal strings in Turtle syntax.

is_uri ( $uri )

Copied from Data::Validate::URI, originally by Richard Sonnen.



The SKOS ontology and its semantics is defined in http://www.w3.org/TR/skos-primer and http://www.w3.org/TR/skos-reference.


Jakob Voss <jakob.voss@gbv.de>


Copyright (C) 2010 by Verbundzentrale Goettingen (VZG) and Jakob Voss

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

In addition you may fork this library under the terms of the GNU Affero General Public License.

syntax highlighting: