Click here to Skip to main content
Click here to Skip to main content

Simple Ontology Support for C#

, 11 Jul 2007
Rate this:
Please Sign up or sign in to vote.
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:

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

Different Ontologies can be loaded through:

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

Now, we can use the additional information:

  // 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:

  '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 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

Share

About the Author

mf040
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 PinmemberMr.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? PinmemberBoudino29-Jul-07 6:55 
AnswerRe: Practical usage? Pinmembermf04029-Jul-07 20:50 
GeneralNice PinmemberPaul Conrad15-Jul-07 7:57 
GeneralUsing Interfaces PinmemberAlex Espinoza11-Jul-07 9:19 
AnswerRe: Using Interfaces Pinmembermf04011-Jul-07 21:13 
GeneralRe: Using Interfaces PinmemberAlex Espinoza12-Jul-07 7:15 
AnswerRe: Using Interfaces Pinmembermf04012-Jul-07 21:07 
GeneralRe: Using Interfaces PinmemberAlex Espinoza13-Jul-07 5:56 
GeneralRe: Using Interfaces Pinmembermf04016-Jul-07 2:00 
GeneralRe: Using Interfaces PinmemberAlex Espinoza16-Jul-07 4:37 
GeneralCoupling question Pinmembersadavoya11-Jul-07 2:55 
AnswerRe: Coupling question Pinmembermf04011-Jul-07 21:20 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 11 Jul 2007
Article Copyright 2007 by mf040
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid