NetworkedPlanet | TMCore Engine API Guide |
Three samples can be found in the examples
directory of your TMCore installation. These examples show some of the
basic operations that are described above.
Table 12.2. NPCL API Examples
Example Directory | Concepts Demonstrated |
---|---|
examples/CS/Npcl/CreateSchema | Programatically creating an NPCL Schema Model. Writing an NPCL Schema Model out as an NPCL XML file. |
examples/CS/Npcl/SchemaImporter | Reading an NPCL Schema Model from an NPCL XML file. Updating schema information in a topic map using an NPCL Schema Model. |
examples/CS/Npcl/SchemaInfo | Reading an NPCL Schema Model from an NPCL XML file. Accessing information from an NPCL Schema Model programatically. |
All of these examples are written in C#. Currently there are no Visual Basic equivalent of these examples.
To compile and run an example, open Visual Studio.NET and create a new blank solution; then add the .csproj contained in the example directory for the example to the solution. The project can then be built using the Build > Build Solution menu item. If the solution contains multiple projects, set the new example project to be the start-up project by right clicking the project in the Solution Explorer pane and selecting "Set as StartUp Project" from the pop-up menu.
The SchemaImporter example requires a connection to a TMCore database. The connection string for this is specified in the App.config file contained in the example directory. You must ensure that this file has the correct connection string before attempting to run the example.
This example shows how a new NPCL Schema model can be created and populated from scratch. This example creates a simple ontology consisting of the topic types "Person" and "Company" which are both subclasses of "Legal Entity". A Person can have an Age occurrence and can play the role "Employee" in an Employment association. Any topic of type "Legal Entity" can play the role of "Employer" in an Employment association, but this topic type is specified as abstract, meaning that end-users would only be allowed to create topics typed by one of its subclasses (Person or Company).
The example also shows how a schema model can be written out as an NPCL XML file.
The example runs as a console application and takes a single optional parameter. The parameter specifies the name of the XML file that the NPCL schema is to be written to. If the file already exists, it will be overwritten. If the parameter is not specified, the NPCL schema will be written out to the console.
This example shows how an NPCL Schema model can be read in from
one storage format (in this case from an NPCL XML file) and written
out to a different storage format (a topic map in the TMCore
database). A sample schema file is provided in the example directory
(the file simple-ontology.npcl
).
The example runs as a console application and takes a two required parameters. The first parameter specifies the name of the XML file that the NPCL schema model is to be imported from. The second parameter specifies the name of the topic map that the schema information is to be written to. If the named topic map does not already exist in the database, it will be created. If the topic map does already exist, the schema information will be used added to the topic map, overwriting any existing schema information for the same types (any other types in the topic map will be unaffected).
This example shows how to access an NPCL Schema Model from your code. In this case the schema information is read from an NPCL XML file.
The example runs as a console application and takes a single required parameter. The parameter specifies the name of the XML file that the NPCL schema model is to be imported from. When the application runs it first displays a count of the different types contained in the schema. You are then prompted to choose if you wish to see detailed information. The detailed information lists details on each topic type and association type in the schema and finally displays a complete class hierarchy for the schema showing all types and their subtypes.