Using the ApplicationOntology

The ApplicationOntology class provides two basic modes of use: as a dictionary of values or as a string filter.

To use the ApplicationOntology class as a dictionary, simply index into it using short identifiers as you would with any other IDictionary implementation. The ApplicationOntology class returns an ITopic instance if a match is found for the short identifier and null otherwise. e.g.

// Create a new ontology with one prefix mapping and one short identifier mapping
ApplicationOntology ontology = new ApplicationOntology();
ontology.AddPrefix("org", "http://www.networkedplanet.com/2005/01/organisation/");
ontology.AddIdentifier("title", "http://purl.org/dc/1.1/title");
ontology.AddTopicMap(myTopicMap);

ITopic person = ontology["org:person"];
ITopic title = ontology["title"];

The ApplicationOntology class also provides two methods which allow the class to act as a string processor. In this mode, the input string is searched for tokens enclosed in curly braces. These tokens are then matched against the ApplicationOntology and if an ITopic instance is returned, then the token and the braces are replaced by the unique object identifier for the ITopic instance. This is most useful in processing TMRQL query strings prior to evaluating them. The method ApplicationOntology.ReplaceReferences(string input) works in exactly this way, but the method ApplicationOntology.ReplaceReferences(string input, ITopic focusTopic) will also match the tokens {FocusTopic} and {TopicMap}, with the former being replaced by the unique object identifier of the ITopic that is specified in the focusTopic parameter and the latter being replaced by the unique object identifier of the ITopicMap instance that contains focusTopic.

// Assuming ontology is already configured as shown in the previous example

// A query string containing a replacement value
string query = "select topic_id from tm_topic where type_id={org:person}";

// Expand the query using the application ontology
string expandedQuery = ontology.ReplaceReferences(query);

// Finally, execute the expanded query
ITMCoreDataReader dr = myTopicMapSystem.ExecuteQuery(expandedQuery);