Talia Naming System

Maintainer: Daniel Hahn

This document is incomplete

Naming

Talia has many elements, which must be given names. Almost all elements in Talia are referred to by URI/URLs. The naming system allows to assign shortcuts to URIs and Namespaces, and makes it easier to work with them in the code.

The N module

All the naming functionality resides in the "N::" module/Ruby namespace. It's short for "Naming" ;) This requires a bit more typing than just using the global (Ruby) namespace, but it keeps things clean.

Using URIs

URIs are simple objects, that refer to a particular URI. They offer a few goodies that the URI String does not have ;)

Simple URIs

If a URI is created from a string, no checking is performed to see if the URI belongs to a namespace.

# The >> lines show the dump of the object returned by the previous call

uri = URI.new("http://www.mycoolsite.com/something/now/")
>> #<URI @uri_s="http://www.mycoolsit.com/something/now/">

uri.to_s
>> http://www.mycoolsite.com/something/now/

uri::more
>> #<URI @uri_s="http://www.mycoolsite.com/something/now/more">

URI shortcuts

Because URIs are long and complicated to type, you can register them as constants in the N:: namespace.

URI.shortcut(:mything, uri)
URI.shortcut(:new_uri, "http://www.newuri.com/")

N::MYTHING
>> #<URI @uri_s="http://www.mycoolsite.com/something/now/">

# Since this returns an URI object, you can also do
N::NEW_URI::more
>> #<URI @uri_s="http://www.newuri.com/more">

Types

A URI can point to elements of different types. To express that, subclasses of the URI class can be used

# This URI describes a namespace
class Namespace < URI
end

# This URI describes a class of Sources
class SourceClass < URI
end

# This URI describes a property or relation type
class PropertyType < URI
end

namespace = Namespace.shortcut(:foaf, "http://xmlns.com/foaf/0.1/")

ActiveRDF hint: ActiveRDF may only know the basic URI type, and no subclasses. Talia will use the subclasses above and add extra functionality.

Predefined namespaces

The Talia application will automatically predefine two namespaces

N::LOCAL 
>> Returns the "local" namespace of the node

N::DEFAULT
>> Returns a "default" namespace if no explicit namespace is given

Note: These predefined things may not be useful for ActiveRDF itself.

Using naming with the Source class

If you have registered URIs, you can use them to access properties and relations of the Source class:

uri = URI.new("http://localhost/mything");

source_type = SourceType.new("http://random.org/sourctype")
Namespace.shortcut(:foaf, "http://xmlns.com/foaf/0.1/")

# Defines a class of sources
SourceClass.shortcut(:person, N::FOAF:Person) # Register a source type from a namespace

# Defines a type of properties
PropertyType.shortcut(:knows, N::FOAF:knows) 


source = Source.new(uri) # You can use both URIs and
# also namespaces or strings to create a source
# you may also give types to the source.
person = Source.new(N::LOCAL::Luca, N::PERSON)

# You can now use the registered shortcuts in the accessor of
# the source object

# This would go directly to the registed property type
# "knows" is http://xmlns.com/foaf/0.1/knows, as registered above
person.knows 

# You can also access that information with
person.knows_type 
>> #<PropertyType @uri_s = "http://xmlns.com/foaf/0.1/knows">

# You can give the namespace directly
# This would mean http://xmlns.com/foaf/0.1/geekcode
person.foaf::geekcode 

# If you don't give a namespace, and there is no registered type:
# It goes to the default namespace
assert_equal(person.thing, person.default::thing)

# In the main Talia class, we will actually check if the
# shortcut refers to a namspace
assert_raises(RuntimeError) { person.knows::person }

# FUTURE ENHANCEMENT?
# This would also make sense

N::PERSON.register_property(:friend_of, property = PropertyType.new(N::FOAF::friend_of))
# Now you can do 
# (This would predefine a "shortcut" that is special for the "Person" class, and not used for
# any other souce.
assert_equal(person.friend_of_type, property)
# But this would still got to the default
assert_equal(source.friend_of, source.default::friend_of)

Note: In future versions, the "type" URIs can also carry constraints and checking information which will be used by the Source objects.

Advanced URI functionality

You will also be able to call some more advanced methods on the URIs, that will relate it to the registered things.

uri = URI.new("http://xmlns.com/foaf/0.1/name")

uri.local_name
>> "name"
uri.namespace
>> :FOAF

uri.local?
>> false