Click here to Skip to main content
15,879,239 members
Articles / Programming Languages / C#
Article

Simple Ontology Support for C#

Rate me:
Please Sign up or sign in to vote.
4.17/5 (11 votes)
11 Jul 20073 min read 67.6K   1.7K   47   13
Extending the class hierarchy with semantic information

Introduction

The class hierarchy of an object-oriented programming language represents a static ontology. It defines a terminology for entities, their attributes and relations. Problems arise when an application needs different classifications at runtime. This may lead to ambiguities because of multiple inheritance or hacks that are needed to implement this feature.

This article describes an approach that extends the existing class information by additional ontologies to provide rich and dynamic semantic information. A case study is presented, that shows the flexibility and added value of the concept and how it can be used. In addition, this method integrates well with the object-oriented design process.

Background

Gruber (1993) defines an Ontology as 'an explicit specification of a conceptualization', i.e. a view onto a system is described by a standardized terminology and relations between entities. In many cases, there is no single ontology but many different and concurrent ones (cmp. Hesse (2002)).

A class hierarchy of an object-oriented programming language, e.g. C#, defines a static Ontology; it describes a view onto a system in terms of objects, attributes and relationships. The following figure shows an example:

A sample class hierarchy.

The example is taken from an implementation of a bond graph. A bond graph consists of different types of nodes and bonds between them. The problem here is, that different algorithms require a special view onto the nodes, e.g. sometimes the nodes are classified by "type" and sometimes by their number of "ports". The SE and SF nodes, for example, can be classified as: by-type as sources and by-port as single ports.

Due to the lack of support of multiple inheritance in C#, it is not possible to implement this concurrent classification. Interfaces are a kind of solution but this would lose much valuable information.

The idea is to extend the class hierarchy by ontologies and to cross-reference the entities:

Ontology and Class Hierarchy.

Depending on the used ontology, a SE node is either a Source or a SinglePort. The advantage is that the ambiguity of the father-child relationship does not lead to a conflict and a single (clean) class hierarchy is maintained.

Using the code

Ontologies are implemented through the E56.Ontology library, which provides classes for semantic annotations of existing C# classes. SemanticType is the counterpart of System.Type and the base for the extension. A semantic type is virtual if no C# class with the same name exists, otherwise this class is cross-referenced. SemanticObject extends System.Object. To use a class in an ontology, it must be derived from SemanticObject.

An Example:

C#
class Element : SemanticObject { ... }
class Node : Element { ... }
class SE : Node { ... }

Different Ontologies can be loaded through:

C#
SemanticObject.Parse("by-port.xml");
SemanticObject.Parse("by-type.xml");

Now, we can use the additional information:

C#
// Create an instance of a class
SF sf = new SF();
// Zugriff auf dessen semantischen Typs
SemanticType root = sf.SemanticType;
// Using the schema 'by-port' sf is a...
SemanticType st1 = sf.IsA("by-port");
Console.WriteLine("'by-port': {0} is a {1}", root, st1);
// Using the schema 'by-typet' sf is a...
SemanticType st2 = sf.IsA("by-type");
Console.WriteLine("'by-type': {0} is a {1}", root, st2);

Through the SemanticType property, semantic type information can be accessed. This is implemented as a lookup of the C# type within the Ontology. The method IsA(string schema) traverses the hierarchy and returns the father object. The result is:

C#
'by-port': [SF/BondGraphs.Core.SF] is a [SinglePort/virtual]
'by-type': [SF/BondGraphs.Core.SF] is a [Source/virtual]

Technical information

The implementation is based on the System.Reflection API, that allows access to classes, methods, and even variables at runtime. The ontology itself is described in a simple XML format, which will be replaced by OWL. The Web Ontology Language (OWL) is a W3C standard for specifying semantic information in a machine readable way.

The by-type schema looks like this:

XML
<?xml version="1.0" ?>
<schema namespace="example">
  <object name="Element" />
  <object name="Node" isA="Element" />
  <object name="Source" isA="Node" />
  <object name="SF" isA="Source" />
  <object name="SE" isA="Source" />
</schema>

References

  • Gruber, T. R. (1993). A Translation Approach to Portable Ontology Specifications. Knowledge Acquisition, 5(2):199–220.
  • Hesse, W. (2002). Ontologie(n). Informatik Spektrum, 25(6):477–480.
  • W3C (2004). Web Ontology Language. http://www.w3.org/2004/OWL/, accessed 11 July 2007.

History

  • 11 July 2007 - Initial version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
Germany Germany
Utilizing my experience of industry-scale real-time graphics programming, design, development of software, as well as European research projects I want to bring in new ideas for creative projects.
Companies:
- 2009-now BTC AG: software for the renewable energy sector.
- 2007-2009 Digital Media: Audio, Graphics and GIS Web Services(http://maps.bremen.de)
- 2001-2007 artecLab://art/work/technology: Mixed Reality, Computer Games and eLearning
- 1998-2001 STN ATLAS Elektronik: real-time graphics for ground warfare simulation

For a complete resume see http://e56.de/download/resume.pdf

Comments and Discussions

 
QuestionWhat about E56 Pin
Mr.Sourav.Maitra21-Mar-11 10:02
Mr.Sourav.Maitra21-Mar-11 10:02 
It would be of great help, if you can explain E56 a bit. Or can provide some reference
QuestionPractical usage? Pin
Boudino29-Jul-07 6:55
Boudino29-Jul-07 6:55 
AnswerRe: Practical usage? Pin
mf04029-Jul-07 20:50
mf04029-Jul-07 20:50 
GeneralNice Pin
Paul Conrad15-Jul-07 7:57
professionalPaul Conrad15-Jul-07 7:57 
GeneralUsing Interfaces Pin
Alex Espinoza11-Jul-07 9:19
Alex Espinoza11-Jul-07 9:19 
AnswerRe: Using Interfaces Pin
mf04011-Jul-07 21:13
mf04011-Jul-07 21:13 
GeneralRe: Using Interfaces Pin
Alex Espinoza12-Jul-07 7:15
Alex Espinoza12-Jul-07 7:15 
AnswerRe: Using Interfaces Pin
mf04012-Jul-07 21:07
mf04012-Jul-07 21:07 
GeneralRe: Using Interfaces Pin
Alex Espinoza13-Jul-07 5:56
Alex Espinoza13-Jul-07 5:56 
GeneralRe: Using Interfaces Pin
mf04016-Jul-07 2:00
mf04016-Jul-07 2:00 
GeneralRe: Using Interfaces Pin
Alex Espinoza16-Jul-07 4:37
Alex Espinoza16-Jul-07 4:37 
GeneralCoupling question Pin
sadavoya11-Jul-07 2:55
sadavoya11-Jul-07 2:55 
AnswerRe: Coupling question Pin
mf04011-Jul-07 21:20
mf04011-Jul-07 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.