/// <summary>
 /// Checks if the given fact is member of the given class within the given ontology
 /// </summary>
 public static Boolean IsMemberOf(RDFOntologyFact ontFact,
                                  RDFOntologyClass ontClass,
                                  RDFOntology ontology,
                                  Boolean useBASEOntology = true)
 {
     return(ontFact != null && ontClass != null && ontology != null ? EnlistMembersOf(ontClass, ontology, useBASEOntology).Facts.ContainsKey(ontFact.PatternMemberID) : false);
 }
        /// <summary>
        /// Enlists the facts which are members of the given class within the given ontology
        /// </summary>
        public static RDFOntologyData EnlistMembersOf(RDFOntologyClass ontClass,
                                                      RDFOntology ontology,
                                                      Boolean useBASEOntology = true)
        {
            var result = new RDFOntologyData();

            if (ontClass != null && ontology != null)
            {
                if (useBASEOntology)
                {
                    ontology = ontology.UnionWith(RDFBASEOntology.Instance);
                }

                //DataRange/Literal-Compatible
                if (IsLiteralCompatibleClass(ontClass, ontology.Model.ClassModel))
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfLiteralCompatibleClass(ontClass, ontology);
                }

                //Restriction/Composite/Enumerate/Class
                else
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfNonLiteralCompatibleClass(ontClass, ontology);
                }

                if (useBASEOntology)
                {
                    ontology = ontology.DifferenceWith(RDFBASEOntology.Instance);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds the "ontologyFact -> rdf:type -> ontologyClass" relation to the data.
 /// </summary>
 public RDFOntologyData AddClassTypeRelation(RDFOntologyFact ontologyFact,
                                             RDFOntologyClass ontologyClass)
 {
     if (ontologyFact != null && ontologyClass != null)
     {
         //Enforce preliminary check on usage of BASE classes
         if (!RDFOntologyChecker.CheckReservedClass(ontologyClass))
         {
             //Enforce taxonomy checks before adding the ClassType relation
             if (RDFOntologyChecker.CheckClassTypeCompatibility(ontologyClass))
             {
                 this.Relations.ClassType.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDF.TYPE.ToRDFOntologyObjectProperty(), ontologyClass));
             }
             else
             {
                 //Raise warning event to inform the user: ClassType relation cannot be added to the data because only plain classes can be explicitly assigned as class types of facts
                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("ClassType relation between fact '{0}' and class '{1}' cannot be added to the data because only plain classes can be explicitly assigned as class types of facts.", ontologyFact, ontologyClass));
             }
         }
         else
         {
             //Raise warning event to inform the user: ClassType relation cannot be added to the data because usage of BASE reserved classes compromises the taxonomy consistency
             RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("ClassType relation between fact '{0}' and class '{1}' cannot be added to the data because because usage of BASE reserved classes compromises the taxonomy consistency.", ontologyFact, ontologyClass));
         }
     }
     return(this);
 }
        /// <summary>
        /// Enlists the facts which are members of the given non literal-compatible class within the given ontology
        /// (internal-only method for performance purposes, used during validation and reasoning logics)
        /// </summary>
        internal static RDFOntologyData EnlistMembersOfNonLiteralCompatibleClass(RDFOntologyClass ontClass,
                                                                                 RDFOntology ontology)
        {
            var result = new RDFOntologyData();

            if (ontClass != null && ontology != null)
            {
                //Restriction
                if (ontClass.IsRestrictionClass())
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfRestriction((RDFOntologyRestriction)ontClass, ontology);
                }

                //Composite
                else if (ontClass.IsCompositeClass())
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfComposite(ontClass, ontology);
                }

                //Enumerate
                else if (ontClass.IsEnumerateClass())
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfEnumerate((RDFOntologyEnumerateClass)ontClass, ontology);
                }

                //Class
                else
                {
                    result = RDFSemanticsUtilities.EnlistMembersOfClass(ontClass, ontology);
                }
            }
            return(result);
        }
        /// <summary>
        /// Static-ctor to initialize structures needed by SemanticsUtilities
        /// </summary>
        static RDFSemanticsUtilities() {
            RDFSemanticsUtilities.DefaultClasses = new Dictionary<Int64, RDFOntologyClass>();

            //owl:Thing
            var owlThing      = new RDFOntologyClass(RDFVocabulary.OWL.THING);
            RDFSemanticsUtilities.DefaultClasses.Add(owlThing.PatternMemberID,    owlThing);

            //rdfs:Literal
            var rdfsLiteral   = new RDFOntologyClass(RDFVocabulary.RDFS.LITERAL);
            RDFSemanticsUtilities.DefaultClasses.Add(rdfsLiteral.PatternMemberID, rdfsLiteral);
            
            //rdfs:Literal subclassOf owl:Thing
            owlThing.DirectSubClasses.Add(rdfsLiteral.PatternMemberID,   rdfsLiteral);
            rdfsLiteral.DirectSuperClasses.Add(owlThing.PatternMemberID, owlThing);

            //rdfs:Datatype
            RDFDatatypeRegister.Instance.Register.ForEach(dt => {
                if (!dt.ToString().Equals(rdfsLiteral.ToString(), StringComparison.Ordinal)) {
                    var dtCls = new RDFOntologyClass(new RDFResource(dt.ToString()));
                    RDFSemanticsUtilities.DefaultClasses.Add(dtCls.PatternMemberID, dtCls);

                    //rdfs:Datatype subclassOf rdfs:Literal
                    rdfsLiteral.DirectSubClasses.Add(dtCls.PatternMemberID,   dtCls);
                    dtCls.DirectSuperClasses.Add(rdfsLiteral.PatternMemberID, rdfsLiteral);
                }
            });            

        }
 /// <summary>
 /// Checks if the given class can be assigned as classtype of facts
 /// </summary>
 internal static Boolean CheckClassTypeCompatibility(RDFOntologyClass ontologyClass)
 {
     return(!ontologyClass.IsRestrictionClass() &&
            !ontologyClass.IsCompositeClass() &&
            !ontologyClass.IsEnumerateClass() &&
            !ontologyClass.IsDataRangeClass());
 }
 /// <summary>
 /// Adds the given ontology class to this union class
 /// </summary>
 public RDFOntologyUnionClass AddCompositingClass(RDFOntologyClass compositingClass) {
     if (compositingClass != null) {
         if (!this.CompositingClasses.ContainsKey(compositingClass.PatternMemberID)) {
             this.CompositingClasses.Add(compositingClass.PatternMemberID, compositingClass);
         }
     }
     return this;
 }
 /// <summary>
 /// Checks if the given aclass can be set disjointwith the given bclass
 /// </summary>
 internal static Boolean CheckDisjointWithCompatibility(RDFOntologyClassModel classModel,
                                                        RDFOntologyClass aClass,
                                                        RDFOntologyClass bClass)
 {
     return(!classModel.CheckIsSubClassOf(aClass, bClass) &&
            !classModel.CheckIsSuperClassOf(aClass, bClass) &&
            !classModel.CheckIsEquivalentClassOf(aClass, bClass));
 }
 /// <summary>
 /// Default-ctor to build an "owl:SomeValuesFrom" ontology restriction with the given name on the given property and the given fromClass
 /// </summary>
 public RDFOntologySomeValuesFromRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty, RDFOntologyClass fromClass): base(restrictionName, onProperty) {
     if (fromClass     != null) {
         this.FromClass = fromClass;
     }
     else {
         throw new RDFSemanticsException("Cannot create RDFOntologySomeValuesFromRestriction because given \"fromClass\" parameter is null.");
     }
 }
 /// <summary>
 /// Default-ctor to build a complement class of the given one
 /// </summary>
 public RDFOntologyComplementClass(RDFOntologyClass complementClass): base(new RDFResource()) {
     if (complementClass     != null) {
         this.ComplementClass = complementClass;
     }
     else {
         throw new RDFSemanticsException("Cannot create ontology complement class because given \"complementClass\" parameter is null.");
     }
 }
 /// <summary>
 /// Removes the given ontology class from this union class
 /// </summary>
 public RDFOntologyUnionClass RemoveCompositingClass(RDFOntologyClass compositingClass) {
     if (compositingClass != null) {
         if (this.CompositingClasses.ContainsKey(compositingClass.PatternMemberID)) {
             this.CompositingClasses.Remove(compositingClass.PatternMemberID);
         }
     }
     return this;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Sets the domain of this ontology property to the given ontology class
 /// </summary>
 public RDFOntologyProperty SetDomain(RDFOntologyClass domainClass)
 {
     if (!this.IsAnnotationProperty())
     {
         this.Domain = domainClass;
     }
     return(this);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Removes the "ontologyFact -> rdf:type -> ontologyClass" relation from the data
 /// </summary>
 public RDFOntologyData RemoveClassTypeRelation(RDFOntologyFact ontologyFact, RDFOntologyClass ontologyClass)
 {
     if (ontologyFact != null && ontologyClass != null)
     {
         this.Relations.ClassType.RemoveEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFBASEOntology.Instance.Model.PropertyModel.SelectProperty(RDFVocabulary.RDF.TYPE.ToString()), ontologyClass));
     }
     return(this);
 }
 /// <summary>
 /// Checks if the given childclass can be set subclassof the given motherclass
 /// </summary>
 internal static Boolean CheckSubClassOfCompatibility(RDFOntologyClassModel classModel,
                                                      RDFOntologyClass childClass,
                                                      RDFOntologyClass motherClass)
 {
     return(!classModel.CheckIsSubClassOf(motherClass, childClass) &&
            !classModel.CheckIsEquivalentClassOf(motherClass, childClass) &&
            !classModel.CheckIsDisjointClassWith(motherClass, childClass));
 }
 /// <summary>
 /// Default-ctor to build an ontology complement class of the given class and with the given name
 /// </summary>
 public RDFOntologyComplementClass(RDFResource className, RDFOntologyClass complementOf): base(className) {
     if (complementOf     != null) {
         this.ComplementOf = complementOf;
     }
     else {
         throw new RDFSemanticsException("Cannot create RDFOntologyComplementClass because given \"complementOf\" parameter is null.");
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Sets the range of this ontology property to the given ontology class
 /// </summary>
 public RDFOntologyProperty SetRange(RDFOntologyClass rangeClass)
 {
     if (!this.IsAnnotationProperty())
     {
         this.Range = rangeClass;
     }
     return(this);
 }
 /// <summary>
 /// Default-ctor to build an ontology "ValuesFrom" restriction of the given category on the given property
 /// </summary>
 public RDFOntologyValuesFromRestriction(RDFOntologyProperty onProperty, RDFSemanticsEnums.RDFOntologyValuesFromRestrictionCategory restrictionCategory, RDFOntologyClass fromClass): base(onProperty) {
     if (fromClass != null) {
         this.FromClass = fromClass;
         this.Category  = restrictionCategory;
     }
     else {
         throw new RDFSemanticsException("Cannot create ontology restriction because given \"fromClass\" parameter is null.");
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Removes the "ontologyFact -> rdf:type -> ontologyClass" relation from the data
 /// </summary>
 public RDFOntologyData RemoveClassTypeRelation(RDFOntologyFact ontologyFact,
                                                RDFOntologyClass ontologyClass)
 {
     if (ontologyFact != null && ontologyClass != null)
     {
         this.Relations.ClassType.RemoveEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDF.TYPE.ToRDFOntologyObjectProperty(), ontologyClass));
     }
     return(this);
 }
 /// <summary>
 /// Default-ctor to build an "owl:AllValuesFrom" ontology restriction with the given name on the given property and the given fromClass
 /// </summary>
 public RDFOntologyAllValuesFromRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty, RDFOntologyClass fromClass) : base(restrictionName, onProperty)
 {
     if (fromClass != null)
     {
         this.FromClass = fromClass;
     }
     else
     {
         throw new RDFSemanticsException("Cannot create RDFOntologyAllValuesFromRestriction because given \"fromClass\" parameter is null.");
     }
 }
Exemplo n.º 20
0
 /// <summary>
 /// Default-ctor to build an ontology complement class of the given class and with the given name
 /// </summary>
 public RDFOntologyComplementClass(RDFResource className, RDFOntologyClass complementOf) : base(className)
 {
     if (complementOf != null)
     {
         this.ComplementOf = complementOf;
     }
     else
     {
         throw new RDFSemanticsException("Cannot create RDFOntologyComplementClass because given \"complementOf\" parameter is null.");
     }
 }
        /// <summary>
        /// Enlists the disjointClasses with the given class within the given class model
        /// </summary>
        public static RDFOntologyClassModel EnlistDisjointClassesWith(RDFOntologyClass ontClass,
                                                                      RDFOntologyClassModel classModel)
        {
            var result = new RDFOntologyClassModel();

            if (ontClass != null && classModel != null)
            {
                result = RDFSemanticsUtilities.EnlistDisjointClassesWith_Core(ontClass, classModel, null)
                         .RemoveClass(ontClass);                          //Safety deletion
            }
            return(result);
        }
        /// <summary>
        /// Checks if the given ontology class is compatible with 'rdfs:Literal' within the given class model
        /// </summary>
        public static Boolean IsLiteralCompatibleClass(RDFOntologyClass ontClass,
                                                       RDFOntologyClassModel classModel)
        {
            var result = false;

            if (ontClass != null && classModel != null)
            {
                result = (ontClass.IsDataRangeClass() ||
                          ontClass.Equals(RDFVocabulary.RDFS.LITERAL.ToRDFOntologyClass()) ||
                          IsSubClassOf(ontClass, RDFVocabulary.RDFS.LITERAL.ToRDFOntologyClass(), classModel));
            }
            return(result);
        }
        /// <summary>
        /// Checks if the given ontology class is compatible with 'rdfs:Literal' within the given class model
        /// </summary>
        public static Boolean IsLiteralCompatibleClass(RDFOntologyClass ontClass,
                                                       RDFOntologyClassModel classModel)
        {
            var result = false;

            if (ontClass != null && classModel != null)
            {
                result = (ontClass.IsDataRangeClass() ||
                          ontClass.Equals(RDFBASEOntology.Instance.Model.ClassModel.SelectClass(RDFVocabulary.RDFS.LITERAL.ToString())) ||
                          IsSubClassOf(ontClass, RDFBASEOntology.Instance.Model.ClassModel.SelectClass(RDFVocabulary.RDFS.LITERAL.ToString()), classModel) ||
                          IsEquivalentClassOf(ontClass, RDFBASEOntology.Instance.Model.ClassModel.SelectClass(RDFVocabulary.RDFS.LITERAL.ToString()), classModel));
            }
            return(result);
        }
        /// <summary>
        /// Enlists the superClasses of the given class within the given class model
        /// </summary>
        public static RDFOntologyClassModel EnlistSuperClassesOf(RDFOntologyClass ontClass, RDFOntologyClassModel classModel) {
            var result       = new RDFOntologyClassModel();
            if (ontClass    != null && classModel != null) {

                //Step 1: Reason on the given class
                result       = RDFSemanticsUtilities.EnlistSuperClassesOf_Core(ontClass, classModel);

                //Step 2: Reason on the equivalent classes of the given class
                foreach(var ec in RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(ontClass, classModel)) {
                    result   = result.UnionWith(RDFSemanticsUtilities.EnlistSuperClassesOf_Core(ec, classModel));
                }

            }
            return result;
        }
        /// <summary>
        /// Enlists the superClasses of the given class within the given class model
        /// </summary>
        public static RDFOntologyClassModel EnlistSuperClassesOf(RDFOntologyClass ontClass,
                                                                 RDFOntologyClassModel classModel)
        {
            var result = new RDFOntologyClassModel();

            if (ontClass != null && classModel != null)
            {
                //Step 1: Reason on the given class
                result = RDFSemanticsUtilities.EnlistSuperClassesOf_Core(ontClass, classModel);

                //Step 2: Reason on the equivalent classes
                foreach (var ec in EnlistEquivalentClassesOf(ontClass, classModel))
                {
                    result = result.UnionWith(RDFSemanticsUtilities.EnlistSuperClassesOf_Core(ec, classModel));
                }
            }
            return(result);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Adds the "ontologyFact -> rdf:type -> ontologyClass" relation to the data.
 /// </summary>
 public RDFOntologyData AddClassTypeRelation(RDFOntologyFact ontologyFact,
                                             RDFOntologyClass ontologyClass)
 {
     if (ontologyFact != null && ontologyClass != null)
     {
         //Enforce taxonomy checks before adding the classType relation
         //Only plain classes can be explicitly assigned as classtypes of facts
         if (!ontologyClass.IsRestrictionClass() &&
             !ontologyClass.IsCompositeClass() &&
             !ontologyClass.IsEnumerateClass() &&
             !ontologyClass.IsDataRangeClass() &&
             //owl:Nothing cannot be assigned as classtype of facts
             !ontologyClass.Equals(RDFBASEOntology.Instance.Model.ClassModel.SelectClass(RDFVocabulary.OWL.NOTHING.ToString())))
         {
             this.Relations.ClassType.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFBASEOntology.Instance.Model.PropertyModel.SelectProperty(RDFVocabulary.RDF.TYPE.ToString()), ontologyClass));
         }
         else
         {
             //Raise warning event to inform the user: ClassType relation cannot be added to the data because only plain classes can be explicitly assigned as class types of facts
             RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("ClassType relation between fact '{0}' and class '{1}' cannot be added to the data because only plain classes can be explicitly assigned as class types of facts.", ontologyFact, ontologyClass));
         }
     }
     return(this);
 }
 /// <summary>
 /// Checks if the given ontology class is range of the given ontology property within the given ontology class model
 /// </summary>
 public static Boolean IsRangeClassOf(RDFOntologyClass rangeClass,
                                      RDFOntologyProperty ontProperty,
                                      RDFOntologyClassModel classModel)
 {
     return(rangeClass != null && ontProperty != null && classModel != null ? EnlistRangeClassesOf(ontProperty, classModel).Classes.ContainsKey(rangeClass.PatternMemberID) : false);
 }
Exemplo n.º 28
0
        /// <summary>
        /// Subsumes the "owl:equivalentClass" taxonomy to discover direct and indirect equivalentClasses of the given class
        /// </summary>
        internal static RDFOntologyClassModel EnlistEquivalentClassesOf_Core(RDFOntologyClass ontClass, 
                                                                             RDFOntologyClassModel classModel, 
                                                                             Dictionary<Int64, RDFOntologyClass> visitContext) {
            var result        = new RDFOntologyClassModel();

            #region visitContext
            if (visitContext == null) {
                visitContext  = new Dictionary<Int64, RDFOntologyClass>() { { ontClass.PatternMemberID, ontClass } };
            }
            else {
                if (!visitContext.ContainsKey(ontClass.PatternMemberID)) {
                     visitContext.Add(ontClass.PatternMemberID, ontClass);
                }
                else {
                    return result;
                }
            }
            #endregion

            // Transitivity of "owl:equivalentClass" taxonomy: ((A EQUIVALENTCLASSOF B)  &&  (B EQUIVALENTCLASS C))  =>  (A EQUIVALENTCLASS C)
            foreach (var      ec in classModel.Relations.EquivalentClass.SelectEntriesBySubject(ontClass)) {
                result.AddClass((RDFOntologyClass)ec.TaxonomyObject);
                result        = result.UnionWith(RDFSemanticsUtilities.EnlistEquivalentClassesOf_Core((RDFOntologyClass)ec.TaxonomyObject, classModel, visitContext));
            }

            return result;
        }
 /// <summary>
 /// Checks if the given aClass is disjointClass with the given bClass within the given class model
 /// </summary>
 public static Boolean IsDisjointClassWith(RDFOntologyClass aClass,
                                           RDFOntologyClass bClass,
                                           RDFOntologyClassModel classModel)
 {
     return(aClass != null && bClass != null && classModel != null ? EnlistDisjointClassesWith(aClass, classModel).Classes.ContainsKey(bClass.PatternMemberID) : false);
 }
 /// <summary>
 /// Enlists the disjointClasses with the given class within the given class model
 /// </summary>
 public   static RDFOntologyClassModel EnlistDisjointClassesWith(RDFOntologyClass ontClass, RDFOntologyClassModel classModel) {
     var result     = new RDFOntologyClassModel();
     if (ontClass  != null && classModel != null) {
         result     = RDFSemanticsUtilities.EnlistDisjointClassesWith_Core(ontClass, classModel, null).RemoveClass(ontClass);
     }
     return result;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Sets the range of this ontology property to the given ontology class
 /// </summary>
 public RDFOntologyProperty SetRange(RDFOntologyClass rangeClass) {
     if (!this.IsAnnotationProperty()) {
          this.Range = rangeClass;
     }
     return this;
 }
        /// <summary>
        /// Adds the given ontology class to the class types of this
        /// </summary>
        public RDFOntologyFact AddClassType(RDFOntologyClass classType) {
            if (classType != null) {

                //Class types can only be assigned to resource ontology facts
                if (this.IsObjectFact()) {

                    //Cannot assign a restriction or a composite/enumerate class as class type of a fact
                    if (!classType.IsCompositeClass() && !classType.IsEnumerateClass() && !classType.IsRestrictionClass()) {
                        if (!this.ClassTypes.ContainsKey(classType.PatternMemberID)) {
                            this.ClassTypes.Add(classType.PatternMemberID, classType);
                        }
                    }

                }                

            }
            return this;
        }
 /// <summary>
 /// Checks if the given aClass is superClass of the given bClass within the given class model
 /// </summary>
 public static Boolean IsSuperClassOf(RDFOntologyClass aClass,
                                      RDFOntologyClass bClass,
                                      RDFOntologyClassModel classModel)
 {
     return(aClass != null && bClass != null && classModel != null ? EnlistSubClassesOf(aClass, classModel).Classes.ContainsKey(bClass.PatternMemberID) : false);
 }
 /// <summary>
 /// Checks if the given fact is member of the given class within the given ontology
 /// </summary>
 public static Boolean IsMemberOf(RDFOntologyFact ontFact, RDFOntologyClass ontClass, RDFOntology ontology) { 
     return(ontFact != null && ontClass != null && ontology != null ? RDFOntologyReasoningHelper.EnlistMembersOf(ontClass, ontology).Facts.ContainsKey(ontFact.PatternMemberID) : false);
 }
        /// <summary>
        /// Enlists the facts which are members of the given class within the given ontology
        /// </summary>
        public static RDFOntologyData EnlistMembersOf(RDFOntologyClass ontClass, RDFOntology ontology) {
            var result      = new RDFOntologyData();
            if (ontClass   != null && ontology != null) {
                
                //Restriction
                if (ontClass.IsRestrictionClass()) {
                    result  = RDFSemanticsUtilities.EnlistMembersOfRestriction((RDFOntologyRestriction)ontClass,  ontology);
                }

                //Enumeration
                else if (ontClass.IsEnumerateClass()) {
                    result  = RDFSemanticsUtilities.EnlistMembersOfEnumerate((RDFOntologyEnumerateClass)ontClass, ontology);
                }

                //DataRange
                else if (ontClass.IsDataRangeClass()) {
                    result  = RDFSemanticsUtilities.EnlistMembersOfDataRange((RDFOntologyDataRangeClass)ontClass, ontology);
                }

                //Composite
                else if (ontClass.IsCompositeClass()) {
                    result  = RDFSemanticsUtilities.EnlistMembersOfComposite(ontClass, ontology);
                }

                //SimpleClass
                else {
                    result  = RDFSemanticsUtilities.EnlistMembersOfClass(ontClass, ontology);
                }

            }
            return result;
        }
 /// <summary>
 /// Checks if the given aClass is equivalentClass of the given bClass within the given class model
 /// </summary>
 public static Boolean IsEquivalentClassOf(RDFOntologyClass aClass, RDFOntologyClass bClass, RDFOntologyClassModel classModel) {
     return(aClass != null && bClass != null && classModel != null ? RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(aClass, classModel).Classes.ContainsKey(bClass.PatternMemberID) : false);
 }
Exemplo n.º 37
0
        internal static RDFOntologyClassModel EnlistSuperClassesOf_Core(RDFOntologyClass ontClass, RDFOntologyClassModel classModel) {
            var result1 = new RDFOntologyClassModel();
            var result2 = new RDFOntologyClassModel();

            // Step 1: Direct subsumption of "rdfs:subClassOf" taxonomy
            result1     = RDFSemanticsUtilities.EnlistSuperClassesOf(ontClass, classModel);

            // Step 2: Enlist equivalent classes of superclasses
            result2     = result2.UnionWith(result1);
            foreach(var sc in result1) {
                result2 = result2.UnionWith(RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(sc, classModel)
                                                .UnionWith(RDFOntologyReasoningHelper.EnlistSuperClassesOf(sc, classModel)));
            }

            return result2;
        }
Exemplo n.º 38
0
        /// <summary>
        /// Enlists the facts which are members of the given class within the given ontology
        /// </summary>
        internal static RDFOntologyData EnlistMembersOfClass(RDFOntologyClass ontClass, RDFOntology ontology) {
            var result         = new RDFOntologyData();

            //DataRange / Literal
            if (ontClass.IsDataRangeClass()                                                         
                || ontClass.Equals(RDFOntologyVocabulary.Classes.LITERAL)
                || RDFOntologyReasoningHelper.IsSubClassOf(ontClass, RDFOntologyVocabulary.Classes.LITERAL, ontology.Model.ClassModel)
                || RDFOntologyReasoningHelper.IsEquivalentClassOf(ontClass, RDFOntologyVocabulary.Classes.LITERAL, ontology.Model.ClassModel)) {

                //DataRange
                if (ontClass.IsDataRangeClass()) {
                    result     = RDFSemanticsUtilities.EnlistMembersOfDataRange((RDFOntologyDataRangeClass)ontClass, ontology);
                }

                //Literal
                else { 
                    
                    //Pure Literal
                    if (ontClass.Equals(RDFOntologyVocabulary.Classes.LITERAL)                                                            || 
                        RDFOntologyReasoningHelper.IsEquivalentClassOf(ontClass, RDFOntologyVocabulary.Classes.LITERAL, ontology.Model.ClassModel)) {
                        foreach (var ontLit in ontology.Data.Literals.Values) {
                            result.AddLiteral(ontLit);
                        }
                    }

                    //Derived Literal
                    else {

                        //String-Literals
                        var xsdStringClass          = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.STRING.ToString());
                        if (ontClass.Equals(xsdStringClass)                                                            || 
                            RDFOntologyReasoningHelper.IsEquivalentClassOf(ontClass, xsdStringClass, ontology.Model.ClassModel)) {
                            foreach (var ontLit    in ontology.Data.Literals.Values) {
                                if  (ontLit.Value  is RDFPlainLiteral) {
                                     result.AddLiteral(ontLit);
                                }
                                else {
                                    var dTypeClass  = ontology.Model.ClassModel.SelectClass(((RDFTypedLiteral)ontLit.Value).Datatype.ToString());
                                    if (dTypeClass != null) {
                                        if (dTypeClass.Equals(ontClass)                                                     ||
                                            RDFOntologyReasoningHelper.IsSubClassOf(dTypeClass, ontClass, ontology.Model.ClassModel) ||
                                            RDFOntologyReasoningHelper.IsEquivalentClassOf(dTypeClass, ontClass, ontology.Model.ClassModel)) {
                                            result.AddLiteral(ontLit);
                                        }
                                    }
                                    else {
                                        if (dTypeClass.Equals(ontClass)) {
                                            result.AddLiteral(ontLit);
                                        }
                                    }
                                }
                            }
                        }

                        //Other Literals
                        else {
                            foreach (var ontLit  in ontology.Data.Literals.Values.Where(l => l.Value is RDFTypedLiteral)) {
                                var  dTypeClass   = ontology.Model.ClassModel.SelectClass(((RDFTypedLiteral)ontLit.Value).Datatype.ToString());
                                if  (dTypeClass  != null) {
                                    if (dTypeClass.Equals(ontClass)                                                            ||
                                        RDFOntologyReasoningHelper.IsSubClassOf(dTypeClass, ontClass, ontology.Model.ClassModel)        ||
                                        RDFOntologyReasoningHelper.IsEquivalentClassOf(dTypeClass, ontClass, ontology.Model.ClassModel)) {
                                        result.AddLiteral(ontLit);
                                    }
                                }
                                else {
                                    if (dTypeClass.Equals(ontClass)) {
                                        result.AddLiteral(ontLit);
                                    }
                                }
                            }
                        }

                    }

                }

            }

            //Composite
            else if (ontClass.IsCompositeClass()) {
                result         = RDFSemanticsUtilities.EnlistMembersOfComposite(ontClass, ontology);
            }

            //Enumerate
            else if (ontClass.IsEnumerateClass()) {
                result         = RDFSemanticsUtilities.EnlistMembersOfEnumerate((RDFOntologyEnumerateClass)ontClass, ontology);
            }

            //Class
            else {

                //Get the compatible classes
                var compCls    = RDFOntologyReasoningHelper.EnlistSubClassesOf(ontClass, ontology.Model.ClassModel)
                                     .UnionWith(RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(ontClass, ontology.Model.ClassModel))
                                        .AddClass(ontClass);

                //Filter "classType" relations made with compatible classes
                var fTaxonomy  = new RDFOntologyTaxonomy();
                foreach (var   c in compCls) {
                    fTaxonomy  = fTaxonomy.UnionWith(ontology.Data.Relations.ClassType.SelectEntriesByObject(c));
                }
                foreach (var   tEntry in fTaxonomy) {

                    //Add the fact and its synonyms
                    if (tEntry.TaxonomySubject.IsFact()) {
                        result = result.UnionWith(RDFOntologyReasoningHelper.EnlistSameFactsAs((RDFOntologyFact)tEntry.TaxonomySubject, ontology.Data))
                                          .AddFact((RDFOntologyFact)tEntry.TaxonomySubject);
                    }

                }

            }

            return result;
        }
Exemplo n.º 39
0
        /// <summary>
        /// Subsumes the "rdfs:subClassOf" taxonomy to discover direct and indirect superClasses of the given class
        /// </summary>
        internal static RDFOntologyClassModel EnlistSuperClassesOf(RDFOntologyClass ontClass, RDFOntologyClassModel classModel) {
            var result  = new RDFOntologyClassModel();

            // Transitivity of "rdfs:subClassOf" taxonomy: ((A SUPERCLASSOF B)  &&  (B SUPERCLASSOF C))  =>  (A SUPERCLASSOF C)
            foreach(var sc in classModel.Relations.SubClassOf.SelectEntriesBySubject(ontClass)) {
                result.AddClass((RDFOntologyClass)sc.TaxonomyObject);
                result  = result.UnionWith(RDFSemanticsUtilities.EnlistSuperClassesOf((RDFOntologyClass)sc.TaxonomyObject, classModel));
            }

            return result;
        }
Exemplo n.º 40
0
        /// <summary>
        /// Gets an ontology representation of the given graph
        /// </summary>
        internal static RDFOntology FromRDFGraph(RDFGraph ontGraph) {
            RDFOntology ontology  = null;
            if (ontGraph         != null) {
                ontology          = new RDFOntology(new RDFResource(ontGraph.Context));

                #region Prefetch
                var versionInfo   = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.VERSION_INFO);
                var comment       = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.COMMENT);
                var label         = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.LABEL);
                var seeAlso       = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.SEE_ALSO);
                var isDefinedBy   = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.IS_DEFINED_BY);
                var imports       = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.IMPORTS);
                var bcwcompWith   = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.BACKWARD_COMPATIBLE_WITH);
                var incompWith    = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.INCOMPATIBLE_WITH);
                var priorVersion  = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.PRIOR_VERSION);

                var rdfType       = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDF.TYPE);
                var subclassOf    = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.SUB_CLASS_OF);
                var subpropOf     = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.SUB_PROPERTY_OF);
                var equivclassOf  = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.EQUIVALENT_CLASS);
                var equivpropOf   = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.EQUIVALENT_PROPERTY);
                var disjclassWith = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.DISJOINT_WITH);
                var domain        = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.DOMAIN);
                var range         = ontGraph.SelectTriplesByPredicate(RDFVocabulary.RDFS.RANGE);
                var onProperty    = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.ON_PROPERTY);
                var oneOf         = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.ONE_OF);
                var unionOf       = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.UNION_OF);
                var intersectionOf= ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.INTERSECTION_OF);
                var complementOf  = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.COMPLEMENT_OF);
                var inverseOf     = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.INVERSE_OF);
                var allvaluesFrom = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.ALL_VALUES_FROM);
                var somevaluesFrom= ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.SOME_VALUES_FROM);
                var hasvalue      = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.HAS_VALUE);
                var cardinality   = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.CARDINALITY);
                var mincardinality= ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.MIN_CARDINALITY);
                var maxcardinality= ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.MAX_CARDINALITY);
                var sameAs        = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.SAME_AS);
                var differentFrom = ontGraph.SelectTriplesByPredicate(RDFVocabulary.OWL.DIFFERENT_FROM);
                #endregion

                #region Load

                #region Ontology
                if (!rdfType.ContainsTriple(new RDFTriple((RDFResource)ontology.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.ONTOLOGY))) {
                     var ont     = rdfType.SelectTriplesByObject(RDFVocabulary.OWL.ONTOLOGY).FirstOrDefault();
                     if (ont    != null) {
                         ontology.Value           = ont.Subject;
                         ontology.PatternMemberID = ontology.Value.PatternMemberID;
                     }
                }
                #endregion

                #region OntologyModel

                #region PropertyModel

                #region AnnotationProperty
                foreach (var ap in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.ANNOTATION_PROPERTY)) {
                    ontology.Model.PropertyModel.AddProperty(new RDFOntologyAnnotationProperty((RDFResource)ap.Subject));
                }
                #endregion

                #region DatatypeProperty
                foreach (var dp in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.DATATYPE_PROPERTY)) {
                    var dtp   = new RDFOntologyDatatypeProperty((RDFResource)dp.Subject);
                    ontology.Model.PropertyModel.AddProperty(dtp);

                    #region DeprecatedProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)dtp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_PROPERTY))) {
                        dtp.SetDeprecated(true);
                    }
                    #endregion

                    #region FunctionalProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)dtp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.FUNCTIONAL_PROPERTY))) {
                        dtp.SetFunctional(true);
                    }
                    #endregion

                }
                #endregion

                #region ObjectProperty
                foreach (var op in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.OBJECT_PROPERTY)) {
                    var obp  = new RDFOntologyObjectProperty((RDFResource)op.Subject);
                    ontology.Model.PropertyModel.AddProperty(obp);

                    #region DeprecatedProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)obp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_PROPERTY))) {
                        obp.SetDeprecated(true);
                    }
                    #endregion

                    #region FunctionalProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)obp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.FUNCTIONAL_PROPERTY))) {
                        obp.SetFunctional(true);
                    }
                    #endregion

                    #region SymmetricProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)obp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.SYMMETRIC_PROPERTY))) {
                        obp.SetSymmetric(true);
                    }
                    #endregion

                    #region TransitiveProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)obp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.TRANSITIVE_PROPERTY))) {
                        obp.SetTransitive(true);
                    }
                    #endregion

                    #region InverseFunctionalProperty
                    if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)obp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.INVERSE_FUNCTIONAL_PROPERTY))) {
                        obp.SetInverseFunctional(true);
                    }
                    #endregion

                }

                #region SymmetricProperty
                foreach (var sp in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.SYMMETRIC_PROPERTY)) {
                    var syp  = ontology.Model.PropertyModel.SelectProperty(sp.Subject.ToString());
                    if (syp == null) {
                        syp  = new RDFOntologyObjectProperty((RDFResource)sp.Subject);
                        ontology.Model.PropertyModel.AddProperty(syp);

                        #region DeprecatedProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)syp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_PROPERTY))) {
                            syp.SetDeprecated(true);
                        }
                        #endregion

                        #region FunctionalProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)syp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.FUNCTIONAL_PROPERTY))) {
                            syp.SetFunctional(true);
                        }
                        #endregion

                    }
                    ((RDFOntologyObjectProperty)syp).SetSymmetric(true);
                }
                #endregion

                #region TransitiveProperty
                foreach (var tp in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.TRANSITIVE_PROPERTY)) {
                    var trp  = ontology.Model.PropertyModel.SelectProperty(tp.Subject.ToString());
                    if (trp == null) {
                        trp  = new RDFOntologyObjectProperty((RDFResource)tp.Subject);
                        ontology.Model.PropertyModel.AddProperty(trp);

                        #region DeprecatedProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)trp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_PROPERTY))) {
                            trp.SetDeprecated(true);
                        }
                        #endregion

                        #region FunctionalProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)trp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.FUNCTIONAL_PROPERTY))) {
                            trp.SetFunctional(true);
                        }
                        #endregion

                    }
                    ((RDFOntologyObjectProperty)trp).SetTransitive(true);
                }
                #endregion

                #region InverseFunctionalProperty
                foreach (var ip in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.INVERSE_FUNCTIONAL_PROPERTY)) {
                    var ifp  = ontology.Model.PropertyModel.SelectProperty(ip.Subject.ToString());
                    if (ifp == null) {
                        ifp  = new RDFOntologyObjectProperty((RDFResource)ip.Subject);
                        ontology.Model.PropertyModel.AddProperty(ifp);

                        #region DeprecatedProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)ifp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_PROPERTY))) {
                            ifp.SetDeprecated(true);
                        }
                        #endregion

                        #region FunctionalProperty
                        if (ontGraph.ContainsTriple(new RDFTriple((RDFResource)ifp.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.FUNCTIONAL_PROPERTY))) {
                            ifp.SetFunctional(true);
                        }
                        #endregion

                    }
                    ((RDFOntologyObjectProperty)ifp).SetInverseFunctional(true);
                }
                #endregion
                #endregion

                #endregion

                #region ClassModel

                #region Class
                foreach (var c   in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.CLASS)) {
                    var ontClass  = new RDFOntologyClass((RDFResource)c.Subject);
                    ontology.Model.ClassModel.AddClass(ontClass);
                    if   (ontGraph.ContainsTriple(new RDFTriple((RDFResource)ontClass.Value, RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.DEPRECATED_CLASS))) {
                          ontClass.SetDeprecated(true);
                    }
                }
                #endregion

                #region DeprecatedClass
                foreach (var dc  in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.DEPRECATED_CLASS)) {
                    var ontClass  = new RDFOntologyClass((RDFResource)dc.Subject);
                    ontClass.SetDeprecated(true);
                    ontology.Model.ClassModel.AddClass(ontClass);
                }
                #endregion

                #region Restriction
                foreach (var r in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.RESTRICTION)) {

                    #region OnProperty
                    var op   = onProperty.SelectTriplesBySubject((RDFResource)r.Subject).FirstOrDefault();
                    if (op  != null) {
                        var onProp     = ontology.Model.PropertyModel.SelectProperty(op.Object.ToString());
                        if (onProp    != null) {
                            var restr  = new RDFOntologyRestriction((RDFResource)r.Subject, onProp);
                            ontology.Model.ClassModel.AddClass(restr);
                        }
                        else {

                            //Raise warning event to inform the user: restriction cannot be imported from 
                            //graph, because definition of its applied property is not found in the model
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Restriction '{0}' cannot be imported from graph, because definition of its applied property '{1}' is not found in the model.", r.Subject, op.Object));

                        }
                    }
                    #endregion

                }
                #endregion

                #region DataRange
                foreach (var dr  in rdfType.SelectTriplesByObject(RDFVocabulary.OWL.DATA_RANGE)) {
                    ontology.Model.ClassModel.AddClass(new RDFOntologyDataRangeClass((RDFResource)dr.Subject));
                }
                #endregion

                #region Composite

                #region Union
                foreach (var u in unionOf) {
                    if  (u.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var uc          = ontology.Model.ClassModel.SelectClass(u.Subject.ToString());
                         if (uc         != null) {

                            #region ClassToUnionClass
                            if (!(uc    is RDFOntologyUnionClass)) {
                                  uc     = new RDFOntologyUnionClass((RDFResource)u.Subject);
                                  ontology.Model.ClassModel.Classes[uc.PatternMemberID] = uc;
                            }
                            #endregion

                            #region DeserializeUnionCollection
                            var nilFound = false;
                            var itemRest = (RDFResource)u.Object;
                            while (!nilFound) {

                                #region rdf:first
                                var first  = ontGraph.SelectTriplesBySubject(itemRest)
                                                     .SelectTriplesByPredicate(RDFVocabulary.RDF.FIRST)
                                                     .FirstOrDefault();
                                if (first != null   && first.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                                    var compClass    = ontology.Model.ClassModel.SelectClass(first.Object.ToString());
                                    if (compClass   != null) {
                                        ontology.Model.ClassModel.AddUnionOfRelation((RDFOntologyUnionClass)uc, compClass);
                                    }
                                    else {

                                        //Raise warning event to inform the user: union class cannot be completely imported
                                        //from graph, because definition of its compositing class is not found in the model
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("UnionClass '{0}' cannot be completely imported from graph, because definition of its compositing class '{1}' is not found in the model.", u.Subject, first.Object));
                                    
                                    }

                                    #region rdf:rest
                                    var rest         = ontGraph.SelectTriplesBySubject(itemRest)
                                                               .SelectTriplesByPredicate(RDFVocabulary.RDF.REST)
                                                               .FirstOrDefault();
                                    if (rest        != null) {
                                        if (rest.Object.Equals(RDFVocabulary.RDF.NIL)) {
                                            nilFound = true;
                                        }
                                        else {
                                            itemRest = (RDFResource)rest.Object;
                                        }
                                    }
                                    #endregion

                                }
                                else {
                                    nilFound = true;
                                }
                                #endregion

                            }
                            #endregion

                         }
                    }
                }
                #endregion

                #region Intersection
                foreach (var i in intersectionOf) {
                    if  (i.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var ic          = ontology.Model.ClassModel.SelectClass(i.Subject.ToString());
                         if (ic         != null) {

                            #region ClassToIntersectionClass
                            if (!(ic    is RDFOntologyIntersectionClass)) {
                                  ic     = new RDFOntologyIntersectionClass((RDFResource)i.Subject);
                                  ontology.Model.ClassModel.Classes[ic.PatternMemberID] = ic;
                            }
                            #endregion

                            #region DeserializeIntersectionCollection
                            var nilFound   = false;
                            var itemRest   = (RDFResource)i.Object;
                            while (!nilFound) {

                                #region rdf:first
                                var first  = ontGraph.SelectTriplesBySubject(itemRest)
                                                     .SelectTriplesByPredicate(RDFVocabulary.RDF.FIRST)
                                                     .FirstOrDefault();
                                if (first != null   && first.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                                    var compClass    = ontology.Model.ClassModel.SelectClass(first.Object.ToString());
                                    if (compClass   != null) {
                                        ontology.Model.ClassModel.AddIntersectionOfRelation((RDFOntologyIntersectionClass)ic, compClass);
                                    }
                                    else {

                                        //Raise warning event to inform the user: intersection class cannot be completely imported
                                        //from graph, because definition of its compositing class is not found in the model
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IntersectionClass '{0}' cannot be completely imported from graph, because definition of its compositing class '{1}' is not found in the model.", i.Subject, first.Object));
                                    
                                    }


                                    #region rdf:rest
                                    var rest         = ontGraph.SelectTriplesBySubject(itemRest)
                                                               .SelectTriplesByPredicate(RDFVocabulary.RDF.REST)
                                                               .FirstOrDefault();
                                    if (rest        != null) {
                                        if (rest.Object.Equals(RDFVocabulary.RDF.NIL)) {
                                            nilFound = true;
                                        }
                                        else {
                                            itemRest = (RDFResource)rest.Object;
                                        }
                                    }
                                    #endregion

                                }
                                else {
                                    nilFound = true;
                                }
                                #endregion

                            }
                            #endregion

                         }
                    }
                }
                #endregion

                #region Complement
                foreach (var c in complementOf) {
                    if  (c.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var cc  = ontology.Model.ClassModel.SelectClass(c.Subject.ToString());
                         if (cc != null) {
                             var compClass  = ontology.Model.ClassModel.SelectClass(c.Object.ToString());
                             if (compClass != null) {
                                 cc         = new RDFOntologyComplementClass((RDFResource)c.Subject, compClass);
                                 ontology.Model.ClassModel.Classes[cc.PatternMemberID] = cc;
                             }
                             else {

                                 //Raise warning event to inform the user: complement class cannot be imported
                                 //from graph, because definition of its complemented class is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Class '{0}' cannot be imported from graph, because definition of its complement class '{1}' is not found in the model.", c.Subject, c.Object));

                             }
                         }
                         else {

                             //Raise warning event to inform the user: complement class cannot be imported 
                             //from graph, because its definition is not found in the model
                             RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Class '{0}' cannot be imported from graph, because its definition is not found in the model.", c.Subject));

                         }
                    }
                }
                #endregion

                #endregion

                #endregion

                #endregion

                #region OntologyData

                #region Fact
                foreach (var c  in ontology.Model.ClassModel) {
                    foreach (var t in rdfType.SelectTriplesByObject((RDFResource)c.Value)) {
                        var f    = ontology.Data.SelectFact(t.Subject.ToString());
                        if (f   == null) {
                            f    = new RDFOntologyFact((RDFResource)t.Subject);
                            ontology.Data.AddFact(f);
                        }
                        ontology.Data.AddClassTypeRelation(f, c);
                    }
                }
                #endregion

                #endregion

                #region Finalization

                #region Restriction
                var restrictions = ontology.Model.ClassModel.Where(c => c.IsRestrictionClass()).ToList();
                foreach (var     r in restrictions) {

                    #region Cardinality
                    Int32 exC    = 0;
                    var  crEx    = cardinality.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (crEx    != null   && crEx.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                        if (crEx.Object   is RDFPlainLiteral) {
                            if (Regex.IsMatch(crEx.Object.ToString(), @"^[0-9]+$")) {
                                exC        = Int32.Parse(crEx.Object.ToString());
                            }
                        }
                        else {
                            if (((RDFTypedLiteral)crEx.Object).Datatype.Category == RDFModelEnums.RDFDatatypeCategory.Numeric) {
                                if (Regex.IsMatch(((RDFTypedLiteral)crEx.Object).Value, @"^[0-9]+$")) {
                                    exC    = Int32.Parse(((RDFTypedLiteral)crEx.Object).Value);
                                }
                            }
                        }
                    }
                    if (exC > 0) {
                        var cardRestr      = new RDFOntologyCardinalityRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, exC, exC);
                        ontology.Model.ClassModel.Classes[r.PatternMemberID] = cardRestr;
                        continue;
                    }

                    Int32 minC   = 0;
                    var  crMin   = mincardinality.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (crMin   != null   && crMin.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                        if (crMin.Object  is RDFPlainLiteral) {
                            if (Regex.IsMatch(crMin.Object.ToString(), @"^[0-9]+$")) {
                                minC       = Int32.Parse(crMin.Object.ToString());
                            }
                        }
                        else {
                            if (((RDFTypedLiteral)crMin.Object).Datatype.Category == RDFModelEnums.RDFDatatypeCategory.Numeric) {
                                if (Regex.IsMatch(((RDFTypedLiteral)crMin.Object).Value, @"^[0-9]+$")) {
                                    minC   = Int32.Parse(((RDFTypedLiteral)crMin.Object).Value);
                                }
                            }
                        }
                    }

                    Int32 maxC   = 0;
                    var  crMax   = maxcardinality.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (crMax   != null   && crMax.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                        if (crMax.Object  is RDFPlainLiteral) {
                            if (Regex.IsMatch(crMax.Object.ToString(), @"^[0-9]+$")) {
                                maxC       = Int32.Parse(crMax.Object.ToString());
                            }
                        }
                        else {
                            if (((RDFTypedLiteral)crMax.Object).Datatype.Category == RDFModelEnums.RDFDatatypeCategory.Numeric) {
                                if (Regex.IsMatch(((RDFTypedLiteral)crMax.Object).Value, @"^[0-9]+$")) {
                                    maxC   = Int32.Parse(((RDFTypedLiteral)crMax.Object).Value);
                                }
                            }
                        }
                    }
                    if (minC > 0  ||  maxC > 0) {
                        var cardRestr      = new RDFOntologyCardinalityRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, minC, maxC);
                        ontology.Model.ClassModel.Classes[r.PatternMemberID] = cardRestr;
                        continue;
                    }
                    #endregion

                    #region HasValue
                    var hvRes    = hasvalue.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (hvRes   != null) {
                        if (hvRes.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                            var hvFct             = ontology.Data.SelectFact(hvRes.Object.ToString());
                            if (hvFct            != null) {
                                var hasvalueRestr = new RDFOntologyHasValueRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, hvFct);
                                ontology.Model.ClassModel.Classes[r.PatternMemberID] = hasvalueRestr;
                                continue;
                            }
                            else {

                                //Raise warning event to inform the user: hasvalue restriction cannot be imported
                                //from graph, because definition of its required fact is not found in the data
                                RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Restriction '{0}' cannot be imported from graph, because definition of its required fact '{1}' is not found in the data.", r.Value, hvRes.Object));

                            }
                        }
                        else {
                            var hasvalueRestr     = new RDFOntologyHasValueRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, new RDFOntologyLiteral((RDFLiteral)hvRes.Object));
                            ontology.Model.ClassModel.Classes[r.PatternMemberID] = hasvalueRestr;
                            continue;
                        }
                    }
                    #endregion

                    #region AllValuesFrom
                    var avfRes       = allvaluesFrom.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (avfRes      != null   && avfRes.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                        var avfCls   = ontology.Model.ClassModel.SelectClass(avfRes.Object.ToString());
                        if (avfCls  != null) {
                            var allvaluesfromRestr = new RDFOntologyAllValuesFromRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, avfCls);
                            ontology.Model.ClassModel.Classes[r.PatternMemberID] = allvaluesfromRestr;
                            continue;
                        }
                        else {

                            //Raise warning event to inform the user: allvaluesfrom restriction cannot be imported
                            //from graph, because definition of its required class is not found in the model
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Restriction '{0}' cannot be imported from graph, because definition of its required class '{1}' is not found in the model.", r.Value, avfRes.Object));

                        }
                    }
                    #endregion

                    #region SomeValuesFrom
                    var svfRes      = somevaluesFrom.SelectTriplesBySubject((RDFResource)r.Value).FirstOrDefault();
                    if (svfRes     != null   && svfRes.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                        var svfCls  = ontology.Model.ClassModel.SelectClass(svfRes.Object.ToString());
                        if (svfCls != null) {
                            var somevaluesfromRestr = new RDFOntologySomeValuesFromRestriction((RDFResource)r.Value, ((RDFOntologyRestriction)r).OnProperty, svfCls);
                            ontology.Model.ClassModel.Classes[r.PatternMemberID] = somevaluesfromRestr;
                            continue;
                        }
                        else {

                            //Raise warning event to inform the user: somevaluesfrom restriction cannot be imported
                            //from graph, because definition of its required class is not found in the model
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Restriction '{0}' cannot be imported from graph, because definition of its required class '{1}' is not found in the model.", r.Value, svfRes.Object));

                        }
                    }
                    #endregion

                }
                #endregion

                #region Enumerate
                foreach (var e  in  oneOf) {
                    if  (e.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var ec          = ontology.Model.ClassModel.SelectClass(e.Subject.ToString());
                         if (ec         != null && !ec.IsDataRangeClass()) {

                            #region ClassToEnumerateClass
                            if (!ec.IsEnumerateClass()) {
                                 ec      = new RDFOntologyEnumerateClass((RDFResource)e.Subject);
                                 ontology.Model.ClassModel.Classes[ec.PatternMemberID] = ec;
                            }
                            #endregion

                            #region DeserializeEnumerateCollection
                            var nilFound   = false;
                            var itemRest   = (RDFResource)e.Object;
                            while (!nilFound) {

                                #region rdf:first
                                var first  = ontGraph.SelectTriplesBySubject(itemRest)
                                                     .SelectTriplesByPredicate(RDFVocabulary.RDF.FIRST)
                                                     .FirstOrDefault();
                                if (first != null   && first.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                                    var enumMember   = ontology.Data.SelectFact(first.Object.ToString());
                                    if (enumMember  != null) {
                                        ontology.Model.ClassModel.AddOneOfRelation((RDFOntologyEnumerateClass)ec, enumMember);
                                    }
									else {

                                        //Raise warning event to inform the user: enumerate class cannot be completely imported
                                        //from graph, because definition of its fact member is not found in the data
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("EnumerateClass '{0}' cannot be completely imported from graph, because definition of its fact member '{1}' is not found in the data.", e.Subject, first.Object));

			                        }

                                    #region rdf:rest
                                    var rest         = ontGraph.SelectTriplesBySubject(itemRest)
                                                               .SelectTriplesByPredicate(RDFVocabulary.RDF.REST)
                                                               .FirstOrDefault();
                                    if (rest        != null) {
                                        if (rest.Object.Equals(RDFVocabulary.RDF.NIL)) {
                                            nilFound = true;
                                        }
                                        else {
                                            itemRest = (RDFResource)rest.Object;
                                        }
                                    }
                                    #endregion

                                }
                                else {
                                    nilFound = true;
                                }
                                #endregion

                            }
                            #endregion

                         }
                         else {
                             if (ec     == null) {

                                 //Raise warning event to inform the user: enumerate class cannot be imported
                                 //from graph, because its definition is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("EnumerateClass '{0}' cannot be imported from graph, because its definition is not found in the model.", e.Subject));

                             }
                         }
                    }
                }
                #endregion

                #region DataRange
                foreach (var d in oneOf) {
                    if  (d.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var dr          = ontology.Model.ClassModel.SelectClass(d.Subject.ToString());
                         if (dr         != null && !dr.IsEnumerateClass()) {

                            #region ClassToDataRangeClass
                            if (!dr.IsDataRangeClass()) {
                                 dr      = new RDFOntologyDataRangeClass((RDFResource)d.Subject);
                                 ontology.Model.ClassModel.Classes[dr.PatternMemberID] = dr;
                            }
                            #endregion

                            #region DeserializeDataRangeCollection
                            var nilFound   = false;
                            var itemRest   = (RDFResource)d.Object;
                            while (!nilFound) {

                                #region rdf:first
                                var first  = ontGraph.SelectTriplesBySubject(itemRest)
                                                     .SelectTriplesByPredicate(RDFVocabulary.RDF.FIRST)
                                                     .FirstOrDefault();
                                if (first != null   && first.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                                    ontology.Model.ClassModel.AddOneOfRelation((RDFOntologyDataRangeClass)dr, new RDFOntologyLiteral((RDFLiteral)first.Object));

                                    #region rdf:rest
                                    var rest         = ontGraph.SelectTriplesBySubject(itemRest)
                                                               .SelectTriplesByPredicate(RDFVocabulary.RDF.REST)
                                                               .FirstOrDefault();
                                    if (rest        != null) {
                                        if (rest.Object.Equals(RDFVocabulary.RDF.NIL)) {
                                            nilFound = true;
                                        }
                                        else {
                                            itemRest = (RDFResource)rest.Object;
                                        }
                                    }
                                    #endregion

                                }
                                else {
                                    nilFound = true;
                                }
                                #endregion

                            }
                            #endregion

                         }
                         else {
                             if (dr     == null) {

                                 //Raise warning event to inform the user: datarange class cannot be imported from
                                 //graph, because its definition is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("DataRangeClass '{0}' cannot be imported from graph, because its definition is not found in the model.", d.Subject));

                             }
                         }
                    }
                }
                #endregion

                #region Domain/Range
                foreach (var p in ontology.Model.PropertyModel) {
                    
                    #region Domain
                    var d   = domain.SelectTriplesBySubject((RDFResource)p.Value).FirstOrDefault();
                    if (d  != null   && d.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                        var domainClass  = ontology.Model.ClassModel.SelectClass(d.Object.ToString());
                        if (domainClass != null) {
                            p.SetDomain(domainClass);
                        }
                        else {

                            //Raise warning event to inform the user: domain constraint cannot be imported from graph, 
                            //because definition of required class is not found in the model
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Domain constraint on property '{0}' cannot be imported from graph, because definition of required class '{1}' is not found in the model.", p.Value, d.Object));

                        }
                    }
                    #endregion

                    #region Range
                    var r   = range.SelectTriplesBySubject((RDFResource)p.Value).FirstOrDefault();
                    if (r  != null  && r.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                        var rangeClass  = ontology.Model.ClassModel.SelectClass(r.Object.ToString());
                        if (rangeClass != null) {
                            p.SetRange(rangeClass);
                        }
                        else {

                            //Raise warning event to inform the user: range constraint cannot be imported from graph, 
                            //because definition of required class is not found in the model
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Range constraint on property '{0}' cannot be imported from graph, because definition of required class '{1}' is not found in the model.", p.Value, r.Object));

                        }
                    }
                    #endregion

                }
                #endregion

                #region PropertyModel Relations
                foreach (var p in ontology.Model.PropertyModel) {
                    
                    #region SubPropertyOf
                    foreach (var spof in subpropOf.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (spof.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                             var superProp        = ontology.Model.PropertyModel.SelectProperty(spof.Object.ToString());
                             if (superProp       != null) {
                                 if (p.IsObjectProperty()        && superProp.IsObjectProperty()) {
                                     ontology.Model.PropertyModel.AddSubPropertyOfRelation((RDFOntologyObjectProperty)p,   (RDFOntologyObjectProperty)superProp);
                                 }
                                 else if (p.IsDatatypeProperty() && superProp.IsDatatypeProperty()) {
                                     ontology.Model.PropertyModel.AddSubPropertyOfRelation((RDFOntologyDatatypeProperty)p, (RDFOntologyDatatypeProperty)superProp);
                                 }
                             }
                             else {

                                 //Raise warning event to inform the user: subpropertyof relation cannot be imported
                                 //from graph, because definition of property is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SubPropertyOf relation on property '{0}' cannot be imported from graph, because definition of property '{1}' is not found in the model.", p.Value, spof.Object));

                             }
                        }
                    }
                    #endregion

                    #region EquivalentProperty
                    foreach (var eqpr in equivpropOf.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (eqpr.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                             var equivProp        = ontology.Model.PropertyModel.SelectProperty(eqpr.Object.ToString());
                             if (equivProp       != null) {
                                 if (p.IsObjectProperty()        && equivProp.IsObjectProperty()) {
                                     ontology.Model.PropertyModel.AddEquivalentPropertyRelation((RDFOntologyObjectProperty)p,   (RDFOntologyObjectProperty)equivProp);
                                 }
                                 else if (p.IsDatatypeProperty() && equivProp.IsDatatypeProperty()) {
                                     ontology.Model.PropertyModel.AddEquivalentPropertyRelation((RDFOntologyDatatypeProperty)p, (RDFOntologyDatatypeProperty)equivProp);
                                 }
                             }
                             else {

                                 //Raise warning event to inform the user: equivalentproperty relation cannot be imported
                                 //from graph, because definition of property is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("EquivalentProperty relation on property '{0}' cannot be imported from graph, because definition of property '{1}' is not found in the model.", p.Value, eqpr.Object));

                             }
                        }
                    }
                    #endregion

                    #region InverseOf
                    if (p.IsObjectProperty()) {
                        foreach (var inof in inverseOf.SelectTriplesBySubject((RDFResource)p.Value)) {
                            if  (inof.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                                 var invProp          = ontology.Model.PropertyModel.SelectProperty(inof.Object.ToString());
                                 if (invProp != null && invProp.IsObjectProperty()) {
                                     ontology.Model.PropertyModel.AddInverseOfRelation((RDFOntologyObjectProperty)p, (RDFOntologyObjectProperty)invProp);
                                 }
                                 else {

                                     //Raise warning event to inform the user: inverseof relation cannot be imported
                                     //from graph, because definition of property is not found in the model
                                     RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("InverseOf relation on property '{0}' cannot be imported from graph, because definition of property '{1}' is not found in the model.", p.Value, inof.Object));

                                 }
                            }
                        }
                    }
                    #endregion

                }
                #endregion

                #region ClassModel Relations
                foreach (var c in ontology.Model.ClassModel) {

                    #region SubClassOf
                    foreach (var scof in subclassOf.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (scof.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                             var superClass       = ontology.Model.ClassModel.SelectClass(scof.Object.ToString());
                             if (superClass      != null) {
                                 ontology.Model.ClassModel.AddSubClassOfRelation(c, superClass);
                             }
                             else {

                                 //Raise warning event to inform the user: subclassof relation cannot be imported
                                 //from graph, because definition of class is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SubClassOf relation on class '{0}' cannot be imported from graph, because definition of class '{1}' is not found in the model.", c.Value, scof.Object));

                             }
                        }
                    }
                    #endregion

                    #region EquivalentClass
                    foreach (var eqcl in equivclassOf.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (eqcl.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                             var equivClass       = ontology.Model.ClassModel.SelectClass(eqcl.Object.ToString());
                             if (equivClass      != null) {
                                 ontology.Model.ClassModel.AddEquivalentClassRelation(c, equivClass);
                             }
                             else {

                                 //Raise warning event to inform the user: equivalentclass relation cannot be imported
                                 //from graph, because definition of class is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("EquivalentClass relation on class '{0}' cannot be imported from graph, because definition of class '{1}' is not found in the model.", c.Value, eqcl.Object));

                             }
                        }
                    }
                    #endregion

                    #region DisjointWith
                    foreach (var djwt in disjclassWith.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (djwt.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                             var disjWith         = ontology.Model.ClassModel.SelectClass(djwt.Object.ToString());
                             if (disjWith        != null) {
                                 ontology.Model.ClassModel.AddDisjointWithRelation(c, disjWith);
                             }
                             else {

                                 //Raise warning event to inform the user: disjointwith relation cannot be imported
                                 //from graph, because definition of class is not found in the model
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("DisjointWith relation on class '{0}' cannot be imported from graph, because definition of class '{1}' is not found in the model.", c.Value, djwt.Object));

                             }
                        }
                    }
                    #endregion

                }
                #endregion

                #region Data Relations

                #region SameAs
                foreach (var t in sameAs) {
                    if  (t.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var subjFct       = ontology.Data.SelectFact(t.Subject.ToString());
                         if (subjFct      != null) {
                             var objFct    = ontology.Data.SelectFact(t.Object.ToString());
                             if (objFct   != null) {
                                 ontology.Data.AddSameAsRelation(subjFct, objFct);
                             }
                             else {

                                 //Raise warning event to inform the user: sameas relation cannot be imported
                                 //from graph, because definition of fact is not found in the data
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SameAs relation on fact '{0}' cannot be imported from graph, because definition of fact '{1}' is not found in the data.", t.Subject, t.Object));

                             }
                         }
                         else {

                             //Raise warning event to inform the user: sameas relation cannot be imported
                             //from graph, because definition of fact is not found in the data
                             RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SameAs relation on fact '{0}' cannot be imported from graph, because its definition is not found in the data.", t.Subject));

                         }
                    }
                }
                #endregion

                #region DifferentFrom
                foreach (var t in differentFrom) {
                    if  (t.TripleFlavor   == RDFModelEnums.RDFTripleFlavors.SPO) {
                         var subjFct       = ontology.Data.SelectFact(t.Subject.ToString());
                         if (subjFct      != null) {
                             var objFct    = ontology.Data.SelectFact(t.Object.ToString());
                             if (objFct   != null) {
                                 ontology.Data.AddDifferentFromRelation(subjFct, objFct);
                             }
                             else {

                                 //Raise warning event to inform the user: differentfrom relation cannot be imported
                                 //from graph, because definition of fact is not found in the data
                                 RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("DifferentFrom relation on fact '{0}' cannot be imported from graph, because definition of fact '{1}' is not found in the data.", t.Subject, t.Object));

                             }
                         }
                         else {

                             //Raise warning event to inform the user: differentfrom relation cannot be imported
                             //from graph, because its definition is not found in the data
                             RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("DifferentFrom relation on fact '{0}' cannot be imported from graph, because its definition is not found in the data.", t.Subject));

                         }
                    }
                }
                #endregion

                #region Assertion
                foreach (var p      in ontology.Model.PropertyModel) {
                    foreach (var t  in ontGraph.SelectTriplesByPredicate((RDFResource)p.Value)) {
                        var subjFct  = ontology.Data.SelectFact(t.Subject.ToString());
                        if (subjFct != null) {
                            if (p.IsObjectProperty()) {
                                if (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPO) {
                                    var objFct       = ontology.Data.SelectFact(t.Object.ToString());
                                    if (objFct      != null) {
                                        ontology.Data.AddAssertionRelation(subjFct, (RDFOntologyObjectProperty)p, objFct);
                                    }
                                    else {

                                        //Raise warning event to inform the user: assertion relation cannot be imported
                                        //from graph, because definition of fact is not found in the data
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation on fact '{0}' cannot be imported from graph, because definition of fact '{1}' is not found in the data.", t.Subject, t.Object));

                                    }
                                }
                                else {

                                    //Raise warning event to inform the user: assertion relation cannot be imported
                                    //from graph, because object property links to a literal
                                    RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation on fact '{0}' cannot be imported from graph, because object property '{1}' links to a literal.", t.Subject, p));

                                }
                            }
                            else if (p.IsDatatypeProperty()) {
                                 if (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                                     ontology.Data.AddAssertionRelation(subjFct, (RDFOntologyDatatypeProperty)p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                                 }
                                 else {

                                     //Raise warning event to inform the user: assertion relation cannot be imported
                                     //from graph, because datatype property links to a fact
                                     RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation on fact '{0}' cannot be imported from graph, because datatype property '{1}' links to a fact.", t.Subject, p));

                                 }
                            }
                        }
                        else {

                            //Raise warning event to inform the user: assertion relation cannot be imported
                            //from graph, because definition of fact is not found in the data
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation on fact '{0}' cannot be imported from graph, because definition of the fact is not found in the data. Ensure its classtype relation is specified.", t.Subject));

                        }
                    }
                }
                #endregion

                #endregion

                #region Annotations

                #region Ontology

                #region VersionInfo
                foreach (var t in versionInfo.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                         ontology.AddVersionInfoAnnotation(new RDFOntologyLiteral((RDFLiteral)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: versioninfo annotation on ontology 
                        //cannot be imported from graph, because it does not link a literal
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("VersionInfo annotation on ontology '{0}' cannot be imported from graph, because it does not link a literal.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region Comment
                foreach (var t in comment.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                         ontology.AddCommentAnnotation(new RDFOntologyLiteral((RDFLiteral)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: comment annotation on ontology 
                        //cannot be imported from graph, because it does not link a literal
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Comment annotation on ontology '{0}' cannot be imported from graph, because it does not link a literal.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region Label
                foreach (var t in label.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                         ontology.AddLabelAnnotation(new RDFOntologyLiteral((RDFLiteral)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: label annotation on ontology 
                        //cannot be imported from graph, because it does not link a literal
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Label annotation on ontology '{0}' cannot be imported from graph, because it does not link a literal.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region SeeAlso
                foreach (var t in seeAlso.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                         ontology.AddSeeAlsoAnnotation(new RDFOntologyLiteral((RDFLiteral)t.Object));
                    }
                    else {
                        RDFOntologyResource resource = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                        if (resource         == null) {
                            resource          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                            if (resource     == null) {
                                resource      = ontology.Data.SelectFact(t.Object.ToString());
                                if (resource == null) {
                                    resource  = new RDFOntologyResource();
                                    resource.Value           = t.Object;
                                    resource.PatternMemberID = t.Object.PatternMemberID;

                                    //Raise warning event to inform the user: seealso annotation on ontology 
                                    //has been imported from graph, but linking an unknown generic resource
                                    RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SeeAlso annotation on ontology '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", ontology.Value, t.Object));

                                }
                            }
                        }
                        ontology.AddSeeAlsoAnnotation(resource);
                    }
                }
                #endregion

                #region IsDefinedBy
                foreach (var t in isDefinedBy.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                         ontology.AddIsDefinedByAnnotation(new RDFOntologyLiteral((RDFLiteral)t.Object));
                    }
                    else {
                        RDFOntologyResource isDefBy = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                        if (isDefBy         == null) {
                            isDefBy          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                            if (isDefBy     == null) {
                                isDefBy      = ontology.Data.SelectFact(t.Object.ToString());
                                if (isDefBy == null) {
                                    isDefBy  = new RDFOntologyResource();
                                    isDefBy.Value           = t.Object;
                                    isDefBy.PatternMemberID = t.Object.PatternMemberID;

                                    //Raise warning event to inform the user: isdefinedby annotation on ontology 
                                    //has been imported from graph, but linking an unknown generic resource
                                    RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IsDefinedBy annotation on ontology '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", ontology.Value, t.Object));

                                }
                            }
                        }
                        ontology.AddIsDefinedByAnnotation(isDefBy);
                    }
                }
                #endregion

                #region BackwardCompatibleWith
                foreach (var t in bcwcompWith.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         ontology.AddBackwardCompatibleWithAnnotation(new RDFOntology((RDFResource)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: backwardcompatiblewith annotation on ontology 
                        //cannot be imported from graph, because it does not link a resource
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("BackwardCompatibleWith annotation on ontology '{0}' cannot be imported from graph, because it does not link a resource.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region IncompatibleWith
                foreach (var t in incompWith.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         ontology.AddIncompatibleWithAnnotation(new RDFOntology((RDFResource)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: incompatiblewith annotation on ontology 
                        //cannot be imported from graph, because it does not link a resource
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IncompatibleWith annotation on ontology '{0}' cannot be imported from graph, because it does not link a resource.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region PriorVersion
                foreach (var t in priorVersion.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO) {
                         ontology.AddPriorVersionAnnotation(new RDFOntology((RDFResource)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: priorversion annotation on ontology 
                        //cannot be imported from graph, because it does not link a resource
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("PriorVersion annotation on ontology '{0}' cannot be imported from graph, because it does not link a resource.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region Imports
                foreach(var t in imports.SelectTriplesBySubject((RDFResource)ontology.Value)) {
                    if (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPO) {
                        ontology.AddImportsAnnotation(new RDFOntology((RDFResource)t.Object));
                    }
                    else {

                        //Raise warning event to inform the user: imports annotation on ontology 
                        //cannot be imported from graph, because it does not link a resource
                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Imports annotation on ontology '{0}' cannot be imported from graph, because it does not link a resource.", ontology.Value, t.Object));

                    }
                }
                #endregion

                #region CustomAnnotations
                var annotProps   = ontology.Model.PropertyModel.AnnotationPropertiesEnumerator;
                while (annotProps.MoveNext()) {
                    foreach (var t in ontGraph.SelectTriplesBySubject((RDFResource)ontology.Value)
                                              .SelectTriplesByPredicate((RDFResource)annotProps.Current.Value)) {
                        if  (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.AddCustomAnnotation((RDFOntologyAnnotationProperty)annotProps.Current, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource custAnn = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (custAnn         == null) {
                                custAnn          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (custAnn     == null) {
                                    custAnn      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (custAnn == null) {
                                        custAnn  = new RDFOntologyResource();
                                        custAnn.Value           = t.Object;
                                        custAnn.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: custom annotation on ontology 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Custom annotation '{0}' on ontology '{1}' has been imported from graph, but linking an unknown generic resource '{2}'.", annotProps.Current.Value, ontology.Value, t.Object));

                                    }
                                }
                            }
                            ontology.AddCustomAnnotation((RDFOntologyAnnotationProperty)annotProps.Current, custAnn);
                        }

                    }
                }
                #endregion

                #endregion

                #region Classes
                foreach (var c in ontology.Model.ClassModel) {

                    #region VersionInfo
                    foreach (var t in versionInfo.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.ClassModel.AddVersionInfoAnnotation(c, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: versioninfo annotation on class 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("VersionInfo annotation on class '{0}' cannot be imported from graph, because it does not link a literal.", c.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Comment
                    foreach (var t in comment.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.ClassModel.AddCommentAnnotation(c, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: comment annotation on class 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Comment annotation on class '{0}' cannot be imported from graph, because it does not link a literal.", c.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Label
                    foreach (var t in label.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.ClassModel.AddLabelAnnotation(c, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: label annotation on class 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Label annotation on class '{0}' cannot be imported from graph, because it does not link a literal.", c.Value, t.Object));

                        }
                    }
                    #endregion

                    #region SeeAlso
                    foreach (var t in seeAlso.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.ClassModel.AddSeeAlsoAnnotation(c, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource resource = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (resource         == null) {
                                resource          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (resource     == null) {
                                    resource      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (resource == null) {
                                        resource  = new RDFOntologyResource();
                                        resource.Value           = t.Object;
                                        resource.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: seealso annotation on class 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SeeAlso annotation on class '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", c.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Model.ClassModel.AddSeeAlsoAnnotation(c, resource);
                        }
                    }
                    #endregion

                    #region IsDefinedBy
                    foreach (var t in isDefinedBy.SelectTriplesBySubject((RDFResource)c.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.ClassModel.AddIsDefinedByAnnotation(c, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource isDefBy = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (isDefBy         == null) {
                                isDefBy          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (isDefBy     == null) {
                                    isDefBy      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (isDefBy == null) {
                                        isDefBy  = new RDFOntologyResource();
                                        isDefBy.Value           = t.Object;
                                        isDefBy.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: isdefinedby annotation on class 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IsDefinedBy annotation on class '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", c.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Model.ClassModel.AddIsDefinedByAnnotation(c, isDefBy);
                        }
                    }
                    #endregion

                    #region CustomAnnotations
                    annotProps       = ontology.Model.PropertyModel.AnnotationPropertiesEnumerator;
                    while (annotProps.MoveNext()) {
                        foreach (var t in ontGraph.SelectTriplesBySubject((RDFResource)c.Value)
                                                  .SelectTriplesByPredicate((RDFResource)annotProps.Current.Value)) {
                            if  (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPL) {
                                 ontology.Model.ClassModel.AddCustomAnnotation(c, (RDFOntologyAnnotationProperty)annotProps.Current, new RDFOntologyLiteral((RDFLiteral)t.Object));
                            }
                            else {
                                RDFOntologyResource custAnn = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                                if (custAnn         == null) {
                                    custAnn          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                    if (custAnn     == null) {
                                        custAnn      = ontology.Data.SelectFact(t.Object.ToString());
                                        if (custAnn == null) {
                                            custAnn  = new RDFOntologyResource();
                                            custAnn.Value           = t.Object;
                                            custAnn.PatternMemberID = t.Object.PatternMemberID;

                                            //Raise warning event to inform the user: custom annotation on class 
                                            //has been imported from graph, but linking an unknown generic resource
                                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Custom annotation '{0}' on class '{1}' has been imported from graph, but linking an unknown generic resource '{2}'.", annotProps.Current.Value, c.Value, t.Object));

                                        }
                                    }
                                }
                                ontology.Model.ClassModel.AddCustomAnnotation(c, (RDFOntologyAnnotationProperty)annotProps.Current, custAnn);
                            }

                        }
                    }
                    #endregion

                }
                #endregion

                #region Properties
                foreach (var p in ontology.Model.PropertyModel) {

                    #region VersionInfo
                    foreach (var t in versionInfo.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.PropertyModel.AddVersionInfoAnnotation(p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: versioninfo annotation on property 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("VersionInfo annotation on property '{0}' cannot be imported from graph, because it does not link a literal.", p.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Comment
                    foreach (var t in comment.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.PropertyModel.AddCommentAnnotation(p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: comment annotation on property 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Comment annotation on property '{0}' cannot be imported from graph, because it does not link a literal.", p.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Label
                    foreach (var t in label.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.PropertyModel.AddLabelAnnotation(p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: label annotation on property 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Label annotation on property '{0}' cannot be imported from graph, because it does not link a literal.", p.Value, t.Object));

                        }
                    }
                    #endregion

                    #region SeeAlso
                    foreach (var t in seeAlso.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.PropertyModel.AddSeeAlsoAnnotation(p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource resource = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (resource         == null) {
                                resource          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (resource     == null) {
                                    resource      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (resource == null) {
                                        resource  = new RDFOntologyResource();
                                        resource.Value           = t.Object;
                                        resource.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: seealso annotation on property 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SeeAlso annotation on property '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", p.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Model.PropertyModel.AddSeeAlsoAnnotation(p, resource);
                        }
                    }
                    #endregion

                    #region IsDefinedBy
                    foreach (var t in isDefinedBy.SelectTriplesBySubject((RDFResource)p.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Model.PropertyModel.AddIsDefinedByAnnotation(p, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource isDefBy = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (isDefBy         == null) {
                                isDefBy          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (isDefBy     == null) {
                                    isDefBy      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (isDefBy == null) {
                                        isDefBy  = new RDFOntologyResource();
                                        isDefBy.Value           = t.Object;
                                        isDefBy.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: isdefinedby annotation on property 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IsDefinedBy annotation on property '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", p.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Model.PropertyModel.AddIsDefinedByAnnotation(p, isDefBy);
                        }
                    }
                    #endregion

                    #region CustomAnnotations
                    annotProps       = ontology.Model.PropertyModel.AnnotationPropertiesEnumerator;
                    while (annotProps.MoveNext()) {
                        foreach (var t in ontGraph.SelectTriplesBySubject((RDFResource)p.Value)
                                                  .SelectTriplesByPredicate((RDFResource)annotProps.Current.Value)) {
                            if  (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPL) {
                                 ontology.Model.PropertyModel.AddCustomAnnotation(p, (RDFOntologyAnnotationProperty)annotProps.Current, new RDFOntologyLiteral((RDFLiteral)t.Object));
                            }
                            else {
                                RDFOntologyResource custAnn = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                                if (custAnn         == null) {
                                    custAnn          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                    if (custAnn     == null) {
                                        custAnn      = ontology.Data.SelectFact(t.Object.ToString());
                                        if (custAnn == null) {
                                            custAnn  = new RDFOntologyResource();
                                            custAnn.Value           = t.Object;
                                            custAnn.PatternMemberID = t.Object.PatternMemberID;

                                            //Raise warning event to inform the user: custom annotation on property 
                                            //has been imported from graph, but linking an unknown generic resource
                                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Custom annotation '{0}' on property '{1}' has been imported from graph, but linking an unknown generic resource '{2}'.", annotProps.Current.Value, p.Value, t.Object));

                                        }
                                    }
                                }
                                ontology.Model.PropertyModel.AddCustomAnnotation(p, (RDFOntologyAnnotationProperty)annotProps.Current, custAnn);
                            }

                        }
                    }
                    #endregion

                }
                #endregion

                #region Facts
                foreach (var f in ontology.Data) {

                    #region VersionInfo
                    foreach (var t in versionInfo.SelectTriplesBySubject((RDFResource)f.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Data.AddVersionInfoAnnotation(f, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: versioninfo annotation on fact 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("VersionInfo annotation on fact '{0}' cannot be imported from graph, because it does not link a literal.", f.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Comment
                    foreach (var t in comment.SelectTriplesBySubject((RDFResource)f.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Data.AddCommentAnnotation(f, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: comment annotation on fact 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Comment annotation on fact '{0}' cannot be imported from graph, because it does not link a literal.", f.Value, t.Object));

                        }
                    }
                    #endregion

                    #region Label
                    foreach (var t in label.SelectTriplesBySubject((RDFResource)f.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Data.AddLabelAnnotation(f, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {

                            //Raise warning event to inform the user: label annotation on fact 
                            //cannot be imported from graph, because it does not link a literal
                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Label annotation on fact '{0}' cannot be imported from graph, because it does not link a literal.", f.Value, t.Object));

                        }
                    }
                    #endregion

                    #region SeeAlso
                    foreach (var t in seeAlso.SelectTriplesBySubject((RDFResource)f.Value)) {
                        if  (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Data.AddSeeAlsoAnnotation(f, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource resource = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (resource         == null) {
                                resource          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (resource     == null) {
                                    resource      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (resource == null) {
                                        resource  = new RDFOntologyResource();
                                        resource.Value           = t.Object;
                                        resource.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: seealso annotation on fact 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("SeeAlso annotation on fact '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", f.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Data.AddSeeAlsoAnnotation(f, resource);
                        }
                    }
                    #endregion

                    #region IsDefinedBy
                    foreach (var t in isDefinedBy.SelectTriplesBySubject((RDFResource)f.Value)) {
                        if  (t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL) {
                             ontology.Data.AddIsDefinedByAnnotation(f, new RDFOntologyLiteral((RDFLiteral)t.Object));
                        }
                        else {
                            RDFOntologyResource isDefBy = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                            if (isDefBy         == null) {
                                isDefBy          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                if (isDefBy     == null) {
                                    isDefBy      = ontology.Data.SelectFact(t.Object.ToString());
                                    if (isDefBy == null) {
                                        isDefBy  = new RDFOntologyResource();
                                        isDefBy.Value           = t.Object;
                                        isDefBy.PatternMemberID = t.Object.PatternMemberID;

                                        //Raise warning event to inform the user: isdefinedby annotation on fact 
                                        //has been imported from graph, but linking an unknown generic resource
                                        RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("IsDefinedBy annotation on fact '{0}' has been imported from graph, but linking an unknown generic resource '{1}'.", f.Value, t.Object));

                                    }
                                }
                            }
                            ontology.Data.AddIsDefinedByAnnotation(f, isDefBy);
                        }
                    }
                    #endregion

                    #region CustomAnnotations
                    annotProps       = ontology.Model.PropertyModel.AnnotationPropertiesEnumerator;
                    while (annotProps.MoveNext()) {
                        foreach (var t in ontGraph.SelectTriplesBySubject((RDFResource)f.Value)
                                                  .SelectTriplesByPredicate((RDFResource)annotProps.Current.Value)) {
                            if  (t.TripleFlavor  == RDFModelEnums.RDFTripleFlavors.SPL) {
                                 ontology.Data.AddCustomAnnotation(f, (RDFOntologyAnnotationProperty)annotProps.Current, new RDFOntologyLiteral((RDFLiteral)t.Object));
                            }
                            else {
                                RDFOntologyResource custAnn = ontology.Model.ClassModel.SelectClass(t.Object.ToString());
                                if (custAnn         == null) {
                                    custAnn          = ontology.Model.PropertyModel.SelectProperty(t.Object.ToString());
                                    if (custAnn     == null) {
                                        custAnn      = ontology.Data.SelectFact(t.Object.ToString());
                                        if (custAnn == null) {
                                            custAnn  = new RDFOntologyResource();
                                            custAnn.Value           = t.Object;
                                            custAnn.PatternMemberID = t.Object.PatternMemberID;

                                            //Raise warning event to inform the user: custom annotation on fact 
                                            //has been imported from graph, but linking an unknown generic resource
                                            RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Custom annotation '{0}' on fact '{1}' has been imported from graph, but linking an unknown generic resource '{2}'.", annotProps.Current.Value, f.Value, t.Object));

                                        }
                                    }
                                }
                                ontology.Data.AddCustomAnnotation(f, (RDFOntologyAnnotationProperty)annotProps.Current, custAnn);
                            }

                        }
                    }
                    #endregion

                }
                #endregion

                #endregion

                #endregion

                #endregion

            }
            return ontology;
        }
 /// <summary>
 /// Checks if the given ontology class is compatible with 'rdfs:Literal' within the given class model
 /// </summary>
 public static Boolean IsLiteralCompatibleClass(RDFOntologyClass ontClass, RDFOntologyClassModel classModel) {
     var result    = false;
     if (ontClass != null && classModel != null) {
         result    = (ontClass.IsDataRangeClass()                                                                 ||
                      ontClass.Equals(RDFOntologyVocabulary.Classes.LITERAL)                                      ||
                      RDFOntologyReasoningHelper.IsSubClassOf(ontClass, RDFOntologyVocabulary.Classes.LITERAL, classModel) ||
                      RDFOntologyReasoningHelper.IsEquivalentClassOf(ontClass, RDFOntologyVocabulary.Classes.LITERAL, classModel));
     }
     return result;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Sets the domain of this ontology property to the given ontology class
 /// </summary>
 public RDFOntologyProperty SetDomain(RDFOntologyClass domainClass) {
     if (!this.IsAnnotationProperty()) {
          this.Domain = domainClass;
     }            
     return this;
 }
 /// <summary>
 /// Checks if the given ontology class is range of the given ontology property within the given ontology class model
 /// </summary>
 public static Boolean IsRangeClassOf(RDFOntologyClass rangeClass, RDFOntologyProperty ontProperty, RDFOntologyClassModel classModel) {
     return (rangeClass != null && ontProperty != null && classModel != null ? RDFOntologyReasoningHelper.EnlistRangeClassesOf(ontProperty, classModel).Classes.ContainsKey(rangeClass.PatternMemberID) : false);
 }
Exemplo n.º 44
0
        /// <summary>
        /// Initializes the given ontology
        /// </summary>
        internal static void InitializeOntology(RDFOntology ontology) {

            //Classes
            ontology.Model.ClassModel.AddClass(RDFOntologyVocabulary.Classes.THING);
            ontology.Model.ClassModel.AddClass(RDFOntologyVocabulary.Classes.NOTHING);
            
            //Datatypes
            foreach (var dType  in RDFDatatypeRegister.Instance.Value) {
                var  dTypeCls    = new RDFOntologyClass(new RDFResource(dType.ToString()));
                ontology.Model.ClassModel.AddClass(dTypeCls);
            }

            //Taxonomies - Primitive Datatypes
            var rdfsLiteralCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.RDFS.LITERAL.ToString());
            var rdfXmlLitCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.RDF.XML_LITERAL.ToString());
            var xsdStringCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.STRING.ToString());
            var xsdBooleanCls    = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.BOOLEAN.ToString());
            var xsdBase64Cls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.BASE64_BINARY.ToString());
            var xsdHexBinCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.HEX_BINARY.ToString());
            var xsdFloatCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.FLOAT.ToString());
            var xsdDecimalCls    = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.DECIMAL.ToString());
            var xsdDoubleCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.DOUBLE.ToString());
            var xsdAnyUriCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.ANY_URI.ToString());
            var xsdQNameCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.QNAME.ToString());
            var xsdNotationCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NOTATION.ToString());
            var xsdDurationCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.DURATION.ToString());
            var xsdDateTimeCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.DATETIME.ToString());
            var xsdTimeCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.TIME.ToString());
            var xsdDateCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.DATE.ToString());            
            var xsdGYearMonthCls = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.G_YEAR_MONTH.ToString());
            var xsdGYearCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.G_YEAR.ToString());
            var xsdGMonthDayCls  = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.G_MONTH_DAY.ToString());
            var xsdGDayCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.G_DAY.ToString());
            var xsdGMonthCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.G_MONTH.ToString());
            ontology.Model.ClassModel.AddSubClassOfRelation(rdfXmlLitCls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdStringCls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdBooleanCls,    rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdBase64Cls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdHexBinCls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdFloatCls,      rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdDecimalCls,    rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdDoubleCls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdAnyUriCls,     rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdQNameCls,      rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNotationCls,   rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdDurationCls,   rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdDateTimeCls,   rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdTimeCls,       rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdDateCls,       rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdGYearMonthCls, rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdGYearCls,      rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdGMonthDayCls,  rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdGDayCls,       rdfsLiteralCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdGMonthCls,     rdfsLiteralCls);

            //Taxonomies - Derived Datatypes
            var xsdNormStringCls = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NORMALIZED_STRING.ToString());
            var xsdTokenCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.TOKEN.ToString());
            var xsdLanguageCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.LANGUAGE.ToString());
            var xsdNameCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NAME.ToString());
            var xsdNMTokenCls    = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NMTOKEN.ToString());
            var xsdNCNameCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NCNAME.ToString());
            var xsdIntegerCls    = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.INTEGER.ToString());
            var xsdNPIntegerCls  = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NON_POSITIVE_INTEGER.ToString());
            var xsdNIntegerCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NEGATIVE_INTEGER.ToString());
            var xsdNNIntegerCls  = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.NON_NEGATIVE_INTEGER.ToString());
            var xsdPIntegerCls   = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.POSITIVE_INTEGER.ToString());
            var xsdLongCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.LONG.ToString());
            var xsdIntCls        = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.INT.ToString());
            var xsdShortCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.SHORT.ToString());
            var xsdByteCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.BYTE.ToString());
            var xsdULongCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.UNSIGNED_LONG.ToString());
            var xsdUIntCls       = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.UNSIGNED_INT.ToString());
            var xsdUShortCls     = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.UNSIGNED_SHORT.ToString());
            var xsdUByteCls      = ontology.Model.ClassModel.SelectClass(RDFVocabulary.XSD.UNSIGNED_BYTE.ToString());
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNormStringCls, xsdStringCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdTokenCls,      xsdNormStringCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdLanguageCls,   xsdTokenCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNameCls,       xsdTokenCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNMTokenCls,    xsdTokenCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNCNameCls,     xsdNameCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdIntegerCls,    xsdDecimalCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNPIntegerCls,  xsdIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNNIntegerCls,  xsdIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdLongCls,       xsdIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdNIntegerCls,   xsdNPIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdIntCls,        xsdLongCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdShortCls,      xsdIntCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdByteCls,       xsdShortCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdPIntegerCls,   xsdNNIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdULongCls,      xsdNNIntegerCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdUIntCls,       xsdULongCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdUShortCls,     xsdUIntCls);
            ontology.Model.ClassModel.AddSubClassOfRelation(xsdUByteCls,      xsdUShortCls);

            //Taxonomy - Custom Datatypes
            foreach (var customDType  in RDFDatatypeRegister.Instance.Value.Where(dt =>
                                             !dt.Prefix.Equals(RDFVocabulary.XSD.PREFIX,  StringComparison.Ordinal)  &&
                                             !dt.Prefix.Equals(RDFVocabulary.RDF.PREFIX,  StringComparison.Ordinal)  &&
                                             !dt.Prefix.Equals(RDFVocabulary.RDFS.PREFIX, StringComparison.Ordinal))) {

                var customDTypeCls     = ontology.Model.ClassModel.SelectClass(customDType.ToString());
                if (customDTypeCls    != null) {
                    switch (customDType.Category) {
                        case RDFModelEnums.RDFDatatypeCategory.Boolean:
                            ontology.Model.ClassModel.AddSubClassOfRelation(customDTypeCls, xsdBooleanCls);
                            break;
                        case RDFModelEnums.RDFDatatypeCategory.DateTime:
                            ontology.Model.ClassModel.AddSubClassOfRelation(customDTypeCls, xsdDateTimeCls);
                            break;
                        case RDFModelEnums.RDFDatatypeCategory.Numeric:
                            ontology.Model.ClassModel.AddSubClassOfRelation(customDTypeCls, xsdDecimalCls);
                            break;
                        case RDFModelEnums.RDFDatatypeCategory.String:
                            ontology.Model.ClassModel.AddSubClassOfRelation(customDTypeCls, xsdStringCls);
                            break;
                        case RDFModelEnums.RDFDatatypeCategory.TimeSpan:
                            ontology.Model.ClassModel.AddSubClassOfRelation(customDTypeCls, xsdDurationCls);
                            break;
                    }
                }
            }

        }
 /// <summary>
 /// Checks if the given class is a reserved BASE ontology class
 /// </summary>
 internal static Boolean CheckReservedClass(RDFOntologyClass ontClass)
 {
     return(RDFBASEOntology.Instance.Model.ClassModel.Classes.ContainsKey(ontClass.PatternMemberID));
 }
Exemplo n.º 46
0
        internal static RDFOntologyClassModel EnlistDisjointClassesWith_Core(RDFOntologyClass ontClass, RDFOntologyClassModel classModel, Dictionary<Int64, RDFOntologyClass> visitContext) {
            var result1       = new RDFOntologyClassModel();
            var result2       = new RDFOntologyClassModel();

            #region visitContext
            if (visitContext == null) {
                visitContext  = new Dictionary<Int64, RDFOntologyClass>() { { ontClass.PatternMemberID, ontClass } };
            }
            else {
                if (!visitContext.ContainsKey(ontClass.PatternMemberID)) {
                     visitContext.Add(ontClass.PatternMemberID, ontClass);
                }
                else {
                    return result1;
                }
            }
            #endregion

            // Inference: ((A DISJOINTWITH B)   &&  (B EQUIVALENTCLASS C))  =>  (A DISJOINTWITH C)
            foreach (var      dw in classModel.Relations.DisjointWith.SelectEntriesBySubject(ontClass)) {
                result1.AddClass((RDFOntologyClass)dw.TaxonomyObject);
                result1       = result1.UnionWith(RDFSemanticsUtilities.EnlistEquivalentClassesOf_Core((RDFOntologyClass)dw.TaxonomyObject, classModel, visitContext));
            }

            // Inference: ((A DISJOINTWITH B)   &&  (B SUPERCLASS C))  =>  (A DISJOINTWITH C)
            result2           = result2.UnionWith(result1);
            foreach (var      c in result1) {
                result2       = result2.UnionWith(RDFSemanticsUtilities.EnlistSubClassesOf_Core(c, classModel));
            }
            result1           = result1.UnionWith(result2);

            // Inference: ((A EQUIVALENTCLASS B || A SUBCLASSOF B)  &&  (B DISJOINTWITH C))     =>  (A DISJOINTWITH C)
            var compatibleCls = RDFOntologyReasoningHelper.EnlistSuperClassesOf(ontClass, classModel)
                                        .UnionWith(RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(ontClass, classModel));
            foreach (var      ec in compatibleCls) {
                result1       = result1.UnionWith(RDFSemanticsUtilities.EnlistDisjointClassesWith_Core(ec, classModel, visitContext));
            }

            return result1;
        }
Exemplo n.º 47
0
        /// <summary>
        /// Enlists the facts which are members of the given composition within the given ontology
        /// </summary>
        internal static RDFOntologyData EnlistMembersOfComposite(RDFOntologyClass ontCompClass, RDFOntology ontology) {
            var result            = new RDFOntologyData();

            //Intersection
            if (ontCompClass      is RDFOntologyIntersectionClass) {

                //Filter "intersectionOf" relations made with the given intersection class
                var firstIter     = true;
                var iTaxonomy     = ontology.Model.ClassModel.Relations.IntersectionOf.SelectEntriesBySubject(ontCompClass);
                foreach (var      tEntry in iTaxonomy) {
                    if  (firstIter) {
                        result    = RDFOntologyReasoningHelper.EnlistMembersOf((RDFOntologyClass)tEntry.TaxonomyObject, ontology);
                        firstIter = false;
                    }
                    else {
                        result    = result.IntersectWith(RDFOntologyReasoningHelper.EnlistMembersOf((RDFOntologyClass)tEntry.TaxonomyObject, ontology));
                    }
                }

            }

            //Union
            else if (ontCompClass is RDFOntologyUnionClass) {

                //Filter "unionOf" relations made with the given union class
                var uTaxonomy     = ontology.Model.ClassModel.Relations.UnionOf.SelectEntriesBySubject(ontCompClass);
                foreach (var      tEntry in uTaxonomy) {
                    result        = result.UnionWith(RDFOntologyReasoningHelper.EnlistMembersOf((RDFOntologyClass)tEntry.TaxonomyObject, ontology));
                }

            }

            //Complement
            else if (ontCompClass is RDFOntologyComplementClass) {
                result            = ontology.Data.DifferenceWith(RDFOntologyReasoningHelper.EnlistMembersOf(ontCompClass, ontology));
            }

            return result;
        }
 /// <summary>
 /// Checks if the union class contains the given ontology class
 /// </summary>
 public Boolean ContainsCompositingClass(RDFOntologyClass compositingClass) {
     return (compositingClass != null && this.CompositingClasses.ContainsKey(compositingClass.PatternMemberID));
 }
 /// <summary>
 /// Removes the given ontology class from the class types of this
 /// </summary>
 public RDFOntologyFact RemoveClassType(RDFOntologyClass classType) {
     if (classType != null) {
         if (this.IsObjectFact()) {
             if (this.ClassTypes.ContainsKey(classType.PatternMemberID)) {
                 this.ClassTypes.Remove(classType.PatternMemberID);
             }
         }
     }
     return this;
 }