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