NetworkedPlanet | TMCore Engine API Guide |
The Application Ontology object is configured in two steps. The first step is to define the mappings between short identifiers (or short identifier prefixes) and subject identifiers (or subject identifier prefixes), and the second step is to specify which topic map or topic maps should be searched for topics with the mapped subject identifiers during a look-up.
The definition of the mappings can be done using an XML fragment. This fragment can be part of a larger configuration file or a separate file itself. The TMCore library provides a helper class to allow you to embed the mappings as part of an application configuration (or web.config) file.
The format of the XML fragment is as follows:
<ontology> <identifierPrefix prefix="..." value="..."/> <subject key="..." identifier="..."/> </ontology>
The root element for the configuration fragment.
This element specifies a mapping between a short identifier
prefix and a subject identifier prefix. The short identifier prefix
is specified as the value of the prefix
attribute
and the subject identifier prefix is specified as the value of the
value
attribute.
This element specifies a mapping between a short identifier
and a full subject identifier for a topic. The short identifier is
specified as the value of the key
attribute and
the full subject identifier is specified as the value of the
identifier
attribute.
The ontology element may contain any number of
identifierPrefix
or subject
elements in any order.
If you wish your application to use an Application Ontology object
configured from the application's configuration file, you can make use
of the application section handler that is part of the TMCore library.
To do this you will need to add the following line into the
configSections
part of the application configuration
file:
<section name="ontology" type="NetworkedPlanet.TMCore.Utils.OntologySectionHandler, tmcore"/>
From within your code, you can then use this section handler to retrieve an instance of the NetworkedPlanet.TMCore.Utils.ApplicationOntology class that represents the configured Application Ontology. e.g.
ApplicationOntology ontology = System.Configuration.ConfigurationSettings.GetConfig( "ontology") as ApplicationOntology;
If you wish to use the XML configuration from some configuration file other than the application configuration file, you must instead pass the XmlElement object that represents the ontology element to the constructor of the ApplicationOntology class. e.g.
ApplicationOntology applicationOntology; XmlDocument configDoc = new XmlDocument(); configDoc.Load("myconfig.xml") XmlElement ontologyElement = configDoc.SelectSingleNode("/config/ontology"); if (ontologyElement != null) { applicationOntology = new ApplicationOntology(ontologyElement); } else { applicationOntology = new ApplicationOntology(); }
Finally, it is also possible to set up all of the mappings for the
Application Ontology directly from code. The methods for doing this are
ApplicationOntology.AddPrefix(string shortIdPrefix, string
subjectIdentifierPrefix)
and
ApplicationOntology.AddIdentifier(string shortId, string
subjectIdentifier)
. e.g.
ApplicationOntology ontology = new ApplicationOntology(); ontology.AddPrefix("org", "http://www.networkedplanet.com/2005/01/organisation/"); ontology.AddIdentifier("title", "http://purl.org/dc/1.1/title");
The second step in configuring an ApplicationOntology instance for
use is to specify the topic map or topic maps on which it operates.
These topic maps are the ones in which the Application Ontology object
will search for topics by their full subject identifier. The Application
Ontology object will search the topic maps it is connected to in strict
order, returning the first topic that matches. A topic map can be added
to the end of the search list using the method
ApplicationOntology.AddTopicMap(ITopicMap tm)
and can be removed using the method
ApplicationOntology.RemoveTopicMap(ITopicMap tm).
e.g.
ITopicMap coreMap = m_topicMapSystem.GetTopicMap("core.xtm"); ontology.AddTopicMap(coreMap)
Whenever you add a new topic map to the search list for an ApplicationOntology instance or remove a topic map from its search list, the cache of topics found up until that point will be dropped. You should therefore avoid constantly reconfiguring the list of topic maps connected to an ApplicationOntology instance to maximise the potential for caching.
In some cases you may want to combine a predefined set of mappings that are set up programatically with a user-defined set of mappings which could be specified in an app.config or other XML configuration file. To support this you may nest one ApplicationOntology instance within another. Every ApplicationOntology instance supports just one nested instance. When an ApplicationOntology is asked to map a short identifier, it will first attempt to perform the mapping to a full subject identifier and then to a topic using its own configured mappings and topic maps, if that fails to find a match the short identifier will then be passed to the nested ApplicationOntology instance for it to resolve (and if that instance cannot resolve the short identifier, it will in turn pass the identifier on to its nested instance - if any - and so on).
The nested ontology can only be specified through the use of the appropriate constructor for the ApplicationOntology object. e.g.
// Get the inner ontology from the application configuration file ApplicationOntology innerOntology = System.Configuration.ConfigurationSettings.GetConfig( "ontology") as ApplicationOntology; // Create an outer ontology programatically: ApplicationOntology outerOntology = new ApplicationOntology(innerOntology); outerOntology.AddPrefix("org", "http://www.networkedplanet.com/2005/01/organisation/");
It is still possible to use an ApplicationOntology instance which is nested inside another instance directly too, bypassing the outer ontology's lookups if necessary. In the example above your code could use either outerOntology (which adds a mapping for the prefix "org") or innerOntology to avoid the additional mappings specified by outerOntology.