/// <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>
 /// 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());
 }
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 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>
        /// 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>
        /// 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;
        }
        /// <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;
        }