Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

Fuzzy Ontology Framework

4.92/5 (12 votes)
17 Mar 2012CPOL19 min read 68.4K   7.5K  
Integration of fuzzy OWL ontology modelling with .NET

Introduction

The library helps to integrate a fuzzy ontology with object-oriented programming (OOP) classes written in .NET. It is a hybrid integration, i.e. some OWL concepts can be mapped directly to OOP classes, yet most OWL concepts are derived just from OOP instance properties, with no direct mapping to a .NET class. Hence the OOP instance- OWL concept(s) mapping can evolve dynamically in the course of time. The implementation currently supports FuzzyOWL2 ontologies [2] together with FuzzyDL reasoner to infer affiliation of OOP instances to particular OWL concepts. It can be however easily modified to support any fuzzy ontology notation as well as any fuzzy reasoner.

Background 

Capturing knowledge with ontology modelling 

One way of capturing and storing knowledge in a structured and machine-interpretable way is the use of ontology engineering.  Ontology is a concrete form of a conceptualisation of community’s knowledge in a specific domain. Ontology includes a vocabulary of terms together with the specification of their meaning. From the explicitly declared facts, an inference mechanism allows to elicit additional implicit knowledge. Such a mechanism is implemented by means of ontology reasoners.

Web Ontology Language (OWL)

In past, number of HTML, XML, and frame-based knowledge representation languages has been designed. OWL 2 is nowadays one of the most popular languages for authoring ontologies. It has been originally intended just for publishing semantic content of web pages, i.e. to build semantic webs. But eventually, it has attracted strong academic and commercial interest. OWL is endorsed by the World Wide Web Consortium (W3C). There are numerous OWL-supporting ontology editors available, such as open-source Java-based Protégé being developed at Stanford University, as well as various reasoners like FaCT++, HermiT or Pellet. Formal semantics of OWL 2 is based on Description Logic (DL), a subset of First Order Logic, of type SROIQ(D). OWL comes with three variants (sublanguages), ordered by increasing expressiveness as OWL Lite, OWL DL and OWL Full

 Figure 1 – The structure of OWL 2 [10]

Figure 1 – The structure of OWL 2 [10] 

Figure 1 reveals the boundary between OWL syntax and semantic layer. It is worth to notice that there exist various concrete syntaxes that can be used to serialize and exchange OWL ontologies. For the rest of this article, we will focus on RDF/XML, the main syntax. RDF (Resource Description Framework) is a concept modelling approach that aims on building a collection of statements about resources in the form of subject-predicate-object expressions. Resources are identified by Unified Resource Identifier (URI).  RDF/XML based-ontologies are built upon RDF together with RDF Schema (RDFS), a RDF-based vocabulary intended to structure the resources. As the result, the collection in fact describes a directed, labelled multi-graph. 

OWL-OOP Integration

As shown in Table 1, a comparison of ontology and object modelling reveals handful of similarities. Indeed, integration of ontology with mainstream object oriented programming languages (OOPLs) like C# or Java, suggests itself quite obviously.

OWL ontology element

C# OOP element 

Concept (TBox level)

Class

Individual (ABox level)

Instance

Object Property (role, slot) ... relation between two OWL individuals

Member (i.e. field or property) type object[]

Data Property (data slot), ...relation between individual and literal.

Member (i.e. field or property) type boolean[], int[], double[], string[]...

Datatype (literal)

Data type boolean, int, double, string, ...

 Table 1 – Analogy between OWL ontology and C# OOP modelling elements 

There are, however, also several differences, such as:

  • Unlike all the mainstream OOPLs, most knowledge-representation systems allow multiple inheritances in the class hierarchy. The same applies to an individual belonging to multiple classes in ontology vs. strict object conformance in OOPLs.
  • Ontology only captures static state without the possibility to define any state transition. Hence OOP element method does not have any equivalent in the ontology world.
  • Unlike lax type conformance in ontology properties, OOPLs are type-safe,
  • Unlike OOPLs, ontology modelling is based on open world assumption.
  • Ontology property features like inversibility, reflexivity, transitivity etc. are not natively handled by OOPLs, although they might be simulated in a property definition. 

There are two types of OOP modelling. i) Direct (traditional) models use classes and instances to represent concepts and individuals of the real world, respectively. ii) Indirect models keep both concepts and individuals in instances, whereas OOP classes represent real-world meta-classes [6]. Similar to these models, one can speak about direct or indirect Ontology-OOP integration, depending if ontology concepts map to OOP classes or OOP instances, respectively [4]. 

  • Direct Ontology-OOP Integration - Ontology concepts are linked to OOP classes, whereas ontology individuals correspond to OOP instances. Direct integration automatically compiles a strong-typed domain specific class model, and hence allows an easy further SW development. Yet, there are difficulties in handling multiple inheritances in ontology, as well as the type-safety in OOP. Moreover, if the ontology alters, the OOP model has to be recompiled, too. Example of direct integration toolkits between ontology in OWL and object structures in .NET are Rowlex and Zhi#. 
  • Indirect Ontology-OOP Integration – After all, all low level APIs with read/write access to ontology can be considered indirect integration. Here, OWL concepts are represented only by runtime objects. Example is SemWeb on the .NET platform or OWL API on Java. 
  • Hybrid Ontology-OOP Integration is a combination of both former approaches. Some essential OWL concepts are represented by an OOP class, whereas others, less important, just by an OOP object. The mapping is implementable by a C# interface, C# attributes or Java annotations. Example of Java-based hybrid integration is Moop [4].

Fuzzy Logic in Ontology Modelling

Classical ontology languages are not appropriate to deal with imprecision or vagueness in knowledge. Therefore, Description Logics for the semantic web has been enhanced by various approaches to handle probabilistic & possibilistic uncertainty, and vagueness.

Regarding vagueness, most popular is fuzzy SHOIN(D), a fuzzy generalization of SHOIN(D). This approach allows concrete domains (datatypes) to be represented by fuzzy sets. Moreover, it introduces fuzzy modifiers, fuzzy axioms, fuzzy RBoxes, fuzzy TBoxes, and fuzzy ABoxes. Regarding its application, fuzzy SHOIN(D) has been originally proposed for logic-based information retrieval in a document management system [5].

Besides the research on the theoretical framework, number of fuzzy DL reasoners has also been implemented, examples are fuzzyDL [8] and DeLorean (DEscription LOgic REasoner with vAgueNess)[3]. The former reasoner represents queries as a linear optimization problem, the latter one computes a rough equivalent non-fuzzy representation from a fuzzy source assuming a finite chain of degrees of truth.

In fact, SHOIN(D) is an equivalent of OWL DL, and so is fuzzy SHOIN (D) convenient as a formal background to bring vagueness into OWL. There are numerous proposals to encode vague information into OWL, such as using OWL extension, transforming fuzzy DL into classical DL, and last but not least using OWL2 annotations.

Annotations are standard part of OWL. OWL DL allows annotations on classes, properties, individuals and ontology headers [10]. In an approach called FuzzyOWL2, OWL annotations contain xml snippets with fuzzy-related information [2]. I have chosen to use this approach in this project because it is well documented, and it only needs a standard OWL editor. Also standard reasoners might be used, provided that the fuzzy part of information will be discarded. Currently, there is a fuzzy logic plugin available for the popular Protégé ontology editor.

FuzzyOWL2 allows to encode i) linear and triangular fuzzy modifiers, ii) left-shoulder, right-shoulder, triangular and trapezoidal fuzzy data types iii) fuzzy concepts iv) fuzzy roles v) fuzzy axioms.

For the purpose of our project, it is important to express following two kinds of fuzzy axioms: 

  • Concept subsumption is  a statement type TBox of form C ? D > a. Example is a statement stating that Cm ? Cc > 0.8, denoting inf x??I{Cm(x) ? Cc} > 0.8, where Cm is a concept representing managers, Cc represents coaches , and ?I is an interpretation domain, declaring that every manager is at least a 0.8 coach.  
  • Instance-concept affiliation is an ABox type statement of form C(a) > a where C denotes a fuzzy concept, a is an individual, and a is a degree of membership. C(a) gives us to what extent the individual a can be considered as an element of the fuzzy concept C. If Cc stays for concept representing coaches, then employee a belongs to this concept at least to the degree of a out from interval [0, 1].

Architecture 

Image 2

Figure 2 – FuzzyOntologyFramework together with surrounding IS, and linked components

The overall architecture is depicted in Figure 2. FuzzyOntologyFramework (FOF) is aimed to be used by an information system written in .NET. Basically, it obtains a collection of .NET instances from the Business Layer, and stores them as individuals in specified OWL ontology. Based on the member values of these instances, and the specified ontology, the reasoner can subsequently assign the individuals (i.e. instances) to one or more OWL concepts. The concept affiliation is returned back to the Business Layer, which can in turn use this information at its discretion. It would be typically used in a decision process.

If fact, not all instances are stored in the ontology. Some instances like those representing countries can be stored in the ontology, whereas others like those representing employees would only be stored in the FOF internal structures. The reason is that several thousand individuals would hamper manipulation with the xml file.

Why hybrid OWL-OOP integration? Well, we assume that: 

  • Some OWL concepts will be mapped 1:1 directly to specific .NET classes. This is accomplished by a simple declaration. We can specify that a .NET object belongs to OWL concept Employee iff its Class.FullName = "AdventureWorks.Employee", for example. 
  • In other cases, the relation might be much more subtle. There can be several .NET classes mapped to a single OWL concept and vice versa. To reveal such a relationship, we can invoke :OntologyIntegrator.FindIndividal(object ind).Concepts to obtain a fuzzy collection of OWL concepts for the individual specified, or similarily :OntologyIntegrator.Concepts(x).Members to obtain a fuzzy collection of individuals for the concept specified.

Linked Components 

  • Fuzzy Framework [7] is a .NET component intended to work with fuzzy logic sets and relations [11]. It overloads .NET operators, so that one can effortlessly build and evaluate fuzzy logic expressions directly in .NET. 
  • SemWeb is a low-level API facilitating access into RDF/XML OWL ontologies from .NET. [9]. 
  • Fuzzy DL Reasoner is a java-based reasoner allowing working with vague information [8]. Prior to its usage with OWL ontologies, it requires launching a FuzzyOwl2.jar convertor to translate the OWL file into a FuzzyDL native definition language. 
  • Gurobi is a math programming library focused on MILP, MIQP, LP and QP. It is used within the Fuzzy DL reasoner for MILP calculations. The library is available at www.gurobi.com with the possibility to obtain free trial or academic licence. 
  • Protégé  is an open source OWL ontology editor and a knowledge acquisition system. It is available for free download at http://protege.stanford.edu/download/download.html.
  • FuzzyOWL plugin facilitates encoding of vagueness into standard OWL ontology by means of annotations. Available for download at http://gaia.isti.cnr.it/~straccia/software/FuzzyOWL/FuzzyOWL2.1.1.zip.

Essential classes and methods  in FOF

Image 3
 Figure 3 – UML diagram with important classes in FOF. Fuzzy relations are in blue.

OntologyIntegrator is the main class within the library. It provides the following methods:

Method 

Description 

public OntologyIntegrator()

 

Initializes new instance of OntologyIntegrator. Next steps are to set the settings (if not specified in an App.config file), and to invoke methods UpdateIndividuals and UpdateOntology.

void

UpdateIndividuals

( IEnumerable<object> individuals)

 

Iterates through the collection, registers all objects as OWL individuals, and stores them in the Individuals property. It depends on the definition of the individual’s class if the individual will be really written into the ontology RDF/XML file, or just stored in the memory for reasoning. See the [Individual(StoreInOntology=true/false)] attribute. In addition to the initial invocation, individuals should be updated each time their properties change. This can be accomplished by an event encapsulated in the specific object.

void UpdateOntology()

 

The method is supposed to be invoked at the beginning of your code, after the :OntologyIntegrator creation. Furthermore, this method should be called each time the source ontology file has been modified by the outside world (i.e. redefined in an ontology editor, for instance). The method performs the following actions:

  • Stores appropriate individuals in the RDF/XML ontology source file.
  • Loads the RDF/XML source file into memory.
  • Puts all concepts found in the ontology into collection Concepts
  • Uses the specified reasoner to load the fuzzy relations between concepts (in the asserted hierarchy), in order to build an image of this hierarchy in .NET. Namely, this is done in the Ancestors and Descendants property for each concept. By other words, it calulates a concept subsumption Cm isa Cn for m, n ? 1..count of concepts.
  • Similar to the Cm x Cn relation, all relations between individuals at one side concepts at the other side are inferred. By other words, an instance–concept affiliation am belogns to Cn is calculated, where m ? 1 .. number of individuals, whereas n ? 1..number of concepts. 
public static readonly IDiscreteDimension CONCEPTS

Domain (dimension) of concepts

public static readonly IDiscreteDimension INDIVIDUALS

Domain (dimension) of individuals

public Concept[] Concepts

Concepts found in the RDF/XML ontology file.

public Individual[] Individuals

Individuals previously registered by the UpdateIndividuals method.

public event EventHandler  <UpdateOntologyProgress ChangedEventArgs> UpdateOntologyProgressChanged

Since he reasoning is time consuming, the event fires each time a progress appears within the UpdateOntology method allowing to report it in a progress bar.

Table 2 - :OntologyIntegrator methods 

Class Concept represents an OWL concept. It provides the following fuzzy sets:

  • fuzzy set of its descendant concepts 
  • fuzzy set of its ancestor concepts
  •  fuzzy set of its member individuals 

Similarly, class Individual provides fuzzy set of concepts the individual belongs to.

Class IndividualClass returns the .NET type of the .NET object. This information is used to provide a direct mapping between .NET classes and OWL concepts. Furthermore, the .NET type specifies what other properties and fields in addition to Type.FullName will be considered for the reasoning.

Ontology-related attributes

 .NET objects that are to be considered OWL individuals typically have numerous fields and attributes. Yet, only some of them are suitable for ontology reasoning. This is the main reason why we have introduced a collection of .NET attributes. They are used in the .NET class definition of the individuals.

Attribute name

Usage

Description 

IndividualAttribute (StoreInOntology : Boolean)

 

Class

Specifies that instances of this class will be treated as ontology individuals. If omitted in the class definition, instances of the respective class will be ignored by the UpdateIndividuals method.

StoreInOntology - If true, the individual will be stored directly in the source ontology file (typically *.owl file in the RDF/XML format). If false, the definition of the individual will be only prepared at hoc when querying a reasoner. Storing the individual entries in the OWL file is good to get one’s head around when studying the ontology, as well as for reasoning in an ontology editor. It is however time and resource-consuming to encode extensive collections of individuals to XML. Hence it is only recommended for smaller collections like countries.

IndividualActiveAttribute

 

Field, Property

This attribute can specify a boolean field or property which represents the object’s state. Example would be property Employee.Active. If Employee.Active = false for an object sent to the UpdateIndividuals method, the object will be removed from the collection of individuals.

IndividualPropertyAttribute

 

Field, Property

Specifies that the member will be exported to the ontology for reasoning. Possible types of such member are: string, string[], int, int[], double, double[], object which is also registered by the UpdateIndividuals method, object[], single-dimensional FuzzyRelation. 

Table 3 –Attributes intended to specify the OOP-OWL mapping

Configuration settings

There are two ways how configuration settings can be defined. First one is via the App.Config file, the second one via properties of an :OntologyIntegrator object. They should be specified before any further work with :OntologyIntegrator.

Property

Description 

Default 

bool BackupOntologyWhenModified

 

In case individuals are populated into the RDF/XML ontology file, it specifies whether the source ontology file should be archived each time it has been changed.

false

string PathToOntology

 

Full path to the ontology file. Example is “C:\OntologyStore\Employees.owl”.

Explicit specification required

string IndividualsUriBase

 

Specifies what IRI will be used for the individuals generated by the UpdateIndividuals method.

http://{machine name}/individuals.owl

bool IgnoreStringAttributes

 

Some reasoners have troubles with the support of string values. If true, attributes type string will not be considered in the ontology. This also applies for the isClass property.

false

string BackupFolder

Defines a backup folder to archive old versions of ontology.

PathToOntology

 

string TemporaryFolder 

Specifies a temporary folder to store text files when communicating with the reasoner.

PathToOntology

 

Table 4 – Configuration settings

Using the code

Prerequisites

Download and install the following applications: 

Installation & Configuration 

          Unzip the content of files FuzzyQueryWithOntology.zip and FuzzyQueryWithoutOntology.zip into two separate folders.

·         In the *.exe.config files in both projects, set up the connection string to MS SQL, database AdventureWorks.

·         Moreover, in the *.exe.config file on the FuzzyQueryWithOntology project, set up the following: 

  • path to a backup folder,
  • path to a temporary folder,
  • path to file salesPersons.owl. The file is located in the unzipped project folder. Example of the path is "D:\Temp\FuzzyQueryWithOntology\salesperson.owl".

Now you are ready to follow the two chapters below by executing the *.exe files in the project folders. The projects compare a non-ontology and ontology-based approach when assessing sales persons.

Sample project "Fuzzy Query without ontology"

In this project, we use the AdventureWorks sample database to find capable and cheap sales persons.  We want to use fuzzy logic because terms like capable or cheap are quite vague. The database diagram of the relevant tables is depicted in Figure 4. There is a 1:[0-1] relation between table Employee and SalesPerson, which means that every employee could be possibly a salesperson with his amount of sales, sales quota, bonus or commission.

Image 4

Figure 4 – DB tables used in the sample projects

To support fuzzy sets, we use FuzzyFramework [7]. For the purpose of our task, we have defined that terms highSales and lowCommission are represented by left or right-sided fuzzy number, respectively: 

C#
FuzzySet highSales = new LeftLinearSet(sales, "High Sales", 1000000, 2000000);

FuzzySet lowCommission = new RightLinearSet(commission, "Low Commission", 0.01m, 0.02m);  

 Image 5

Figure 5 – Graphical representation of low commission and high sales

We use the Microsoft Entity Framework as an E-R mapper to populate DB records into .NET objects class SalesPerson. So far, it is an ordinary information system. But as soon as we want to evaluate employees on how capable or cheap they are, we have to introduce the following hard-coded properties:

 locks of code should be set as style "Formatted" like this:  

C#
public double CheapSalesPerson
{
    get
    {
        return lowCommission.IsMember(this.CommissionPct);
    }
}

public double CapableSalesPerson
{
    get
    {
        return highSales.IsMember(this.SalesLastYear);
    }
}


public Nullable<double> CapableAndCheapSalesPerson
{
    get
    {
            return Math.Min(this.CheapSalesPerson, this.CapableSalesPerson);
    }
}

Afterwards, it is quite easy to generate the following grid with the CapableAndCheapSalesPerson column:

Image 6

 Figure 6 – Output of  sample project FuzzyQueryWithoutOntology 

Yet, each time we want to introduce a new search, this would not be possible without changes in code. To overcome this, information systems typically offer a SQL-like query functionality. A custom search is named, stored in a database, and invoked when necessary. But in the end, a user ends with plenty of custom searches without clear purpose and meaning.

Sample project "Fuzzy Query with ontology"

The solution described in the previous project works, yet we would like to have more flexible way to define what low commission or high sale amount is, and how these properties interact. This is exactly what can be achieved by means of a fuzzy ontology.

Using the Protégé ontology editor with the FuzzyOWL plugin, we have first defined fuzzy linguistic terms lowCommision and highSales.

Image 7 

Figure 7 - Definition of fuzzy set lowCommission in Protégé 

Next, we have defined who exactly are CheapSalesPerson, CapapableSalesPerson, and finally CapableAndCheapSalesPerson.

Image 8 

Figure 8 – Hierarchy of concepts in OWL ontology

 

Image 9
 
Figure 9 – Description of CapableAndCheapSalesPerson in Protégé.

So far this was the ontology definition. On the side of our information system, we have decorated the .NET class SalesPerson with IndividualAttribute(StoreInOntology=false), and the properties important for reasoning with IndividualProperty.

C#
[Individual(StoreInOntology=false)]
public class SalesPerson
{
…
               
    [IndividualProperty]
    public double SalesLastYear
    {
        get { … }
    }

               
    [IndividualProperty]
    public double CommissionPct
    {
        get { … }
    }
} 

The last step is just to invoke UpdateIndividuals and UpdateOntology methods. Afterwards, each individual has its Concepts collection; with information to what extend the specific object belongs to concept Employee, SalesPerson, CapableSalesPerson etc.

Image 10 

Figure 10 – Output of project FuzzyQueryWithOntology

Conclusion and Future Work

We have demonstrated that with the OOP-ontology integration, it is easy to define fuzzy knowledge structures by means of the ontology modelling, without the necessity to alter the .NET code. These structures can be later used in the code to infer an affiliation of an individual to a concept. This is desirable when ranking individuals in order to make a decision, for example.

The integration with Java-based FuzzyDL reasoner is quite slow. Therefore, the sample project performs the reasoning asynchronously, displaying the overall progress. This specific implementation is only sufficient for demonstrative purposes. The concept is however quite flexible, and allows its easy extension it with other  fuzzy reasoners like DeLorean. 

Resources

  1. SQL Server Sample Databases. In CodePlex Open Source Project Community. Microsoft, 2012. Available at: http://msftdbprodsamples.codeplex.com/
  2. BOBILLO F., STRACCIA U. Fuzzy Ontology Representation using OWL 2. In International Journal of Approximate Reasoning,  Vol. 52, Issue 7, p. 1073-1094, Oct 2011. ISSN:0888-613X. Available at: http://gaia.isti.cnr.it/~straccia/software/FuzzyOWL/IJAR11.pdf
  3. BOBILLO, F. DeLorean. University of Zaragoza, Spain, 2012. Available at: http://webdiis.unizar.es/~fbobillo/delorean
  4. FRENZEL, C. Mooop – A Generic Integration of Object-Oriented and Ontological Models. Augsburg, Germany 2010. Available at: http://opus.bibliothek.uni-augsburg.de/volltexte/2011/1695/pdf/TR_2010_14.pdf
  5. LUKASIEWICZ, T., STRACCIA, U.  Managing uncertainty and vagueness in description logics for the semantic web, In Journal of Web Semantics. Vol. 6 issue 4, p.291–308, 2008, 291–308. ISSN: 1570-8268 
  6. PULESTON, C., PARSIA, B., CONNINGHAM, J., RECTOR, A. Integrating Object-Oriented and Ontological Representations: A Case Study in Java and OWL. In The Semantic Web - ISWC 2008, pp. 140-153, Springer,Germany, 2008.  Available at: http://owl.cs.manchester.ac.uk/papers/ppcr08_oo%2Bo_iswc.pdf
  7. SLAVÍCEK V. Fuzzy Framework. In  CodeProject, Jan 2011. Available at: Fuzzy-Framework.aspx
  8. STRACIA, U. The fuzzy DL System. ISTI-CNR, Italy. 2012. Available at: http://gaia.isti.cnr.it/~straccia/software/fuzzyDL/fuzzyDL.html
  9. TAUBERER, J. SemWeb.NET: Semantic Web/RDF Library for C#/.NET. 2010 Available at: http://razor.occams.info/code/semweb/
  10. W3C OWL Working Group. OWL 2 Web Ontology Language : Document Overview. W3C, 2009. Available at: http://www.w3.org/2009/pdf/REC-owl2-overview-20091027.pdf
  11. ZADEH, L. A. Fuzzy Sets. In Information and Control, vol 8, issue 3, pp. 338-353, 1965. ISSN 0019-9958.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)