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.

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

All concepts share a common URI base.
By default this common prefix is also the URI of the concept scheme as whole.

All concepts must be identifyable by a unique string,
that is refered to as the concept identifier.
The URI of a concept is build of the common URI prefix and the concept's identifier.
The identifier must either be the skos:notation (so every concept must have one),
or the skos:prefLabel in one fixed language for all concepts.

Empty strings as literal values are ignored.
In most cases you can use undef and "" interchangeably.

All notations have the same Datatype URI (this may be changed).

The range of all documentation properties (skos:note,
skos:example,
skos:scopeNote etc.) is the plain literals instead of any resource.

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.

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.

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.

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.

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.

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:

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.

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 ""!

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.