/// <summary>
 /// Default-ctor to build an "owl:HasValue" ontology restriction with the given name on the given property and the given required value
 /// </summary>
 public RDFOntologyHasValueRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty, RDFOntologyLiteral requiredValue): base(restrictionName, onProperty) {
     if (requiredValue     != null) {
         this.RequiredValue = requiredValue;
     }
     else {
         throw new RDFSemanticsException("Cannot create RDFOntologyHasValueRestriction because given \"requiredValue\" parameter is null.");
     }
 }
 /// <summary>
 /// Default-ctor to build an ontology value restriction on the given property and requiring the given fact
 /// </summary>
 public RDFOntologyHasValueRestriction(RDFOntologyProperty onProperty, RDFOntologyFact requiredFact): base(onProperty) {
     if (requiredFact     != null) {
         this.RequiredFact = requiredFact;
     }
     else {
         throw new RDFSemanticsException("Cannot create ontology restriction because given \"requiredFact\" parameter is null.");
     }
 }
 /// <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 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.");
     }
 }
 /// <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.");
     }
 }
Beispiel #6
0
 /// <summary>
 /// Default-ctor to build an "owl:HasValue" ontology restriction with the given name on the given property and the given required value
 /// </summary>
 public RDFOntologyHasValueRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty, RDFOntologyLiteral requiredValue) : base(restrictionName, onProperty)
 {
     if (requiredValue != null)
     {
         this.RequiredValue = requiredValue;
     }
     else
     {
         throw new RDFSemanticsException("Cannot create RDFOntologyHasValueRestriction because given \"requiredValue\" parameter is null.");
     }
 }
        /// <summary>
        /// Enlists the equivalentProperties of the given property within the given property model
        /// </summary>
        public static RDFOntologyPropertyModel EnlistEquivalentPropertiesOf(RDFOntologyProperty ontProperty,
                                                                            RDFOntologyPropertyModel propertyModel)
        {
            var result = new RDFOntologyPropertyModel();

            if (ontProperty != null && propertyModel != null)
            {
                result = RDFSemanticsUtilities.EnlistEquivalentPropertiesOf_Core(ontProperty, propertyModel, null)
                         .RemoveProperty(ontProperty);                              //Safety deletion
            }
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Default-ctor to build an ontology cardinality restriction with the given name on the given property
        /// </summary>
        public RDFOntologyCardinalityRestriction(RDFResource restrictionName,
                                                 RDFOntologyProperty onProperty,
                                                 Int32 minCardinality,
                                                 Int32 maxCardinality) : base(restrictionName, onProperty)
        {
            //MinCardinality
            if (minCardinality > 0)
            {
                if (maxCardinality > 0)
                {
                    if (minCardinality <= maxCardinality)
                    {
                        this.MinCardinality = minCardinality;
                    }
                    else
                    {
                        throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because given \"minCardinality\" parameter (" + minCardinality + ") must be less or equal than given \"maxCardinality\" parameter (" + maxCardinality + ")");
                    }
                }
                else
                {
                    this.MinCardinality = minCardinality;
                }
            }

            //MaxCardinality
            if (maxCardinality > 0)
            {
                if (minCardinality > 0)
                {
                    if (maxCardinality >= minCardinality)
                    {
                        this.MaxCardinality = maxCardinality;
                    }
                    else
                    {
                        throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because given \"maxCardinality\" parameter (" + maxCardinality + ") must be greater or equal than given \"minCardinality\" parameter (" + minCardinality + ")");
                    }
                }
                else
                {
                    this.MaxCardinality = maxCardinality;
                }
            }

            if (this.MinCardinality == 0 && this.MaxCardinality == 0)
            {
                throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because at least one of the given \"minCardinality\" and \"maxCardinality\" parameters must be greater than 0.");
            }
        }
Beispiel #9
0
 /// <summary>
 /// Removes the "ontology -> ontologyProperty -> ontologyResource" relation from the ontology
 /// If the property is an annotation property, it redirects to the "RemoveCustomAnnotation" method
 /// </summary>
 public RDFOntology RemoveCustomRelation(RDFOntologyProperty ontologyProperty,
                                         RDFOntologyResource ontologyResource)
 {
     if (ontologyProperty != null && ontologyResource != null)
     {
         if (ontologyProperty.IsAnnotationProperty())
         {
             this.RemoveCustomAnnotation((RDFOntologyAnnotationProperty)ontologyProperty, ontologyResource);
         }
         else
         {
             this.Relations.CustomRelations.RemoveEntry(new RDFOntologyTaxonomyEntry(this, ontologyProperty, ontologyResource));
         }
     }
     return(this);
 }
        /// <summary>
        /// Default-ctor to build an ontology restriction with the given name on the given ontology property
        /// </summary>
        internal RDFOntologyRestriction (RDFResource restrictionName, RDFOntologyProperty onProperty): base(restrictionName) {
            if (onProperty != null) {

                //AnnotationProperty cannot be restricted
                if (!onProperty.IsAnnotationProperty()) {
                     this.OnProperty = onProperty;
                }
                else {
                    throw new RDFSemanticsException("Cannot create RDFOntologyRestriction because given \"onProperty\" parameter (" + onProperty + ") is an annotation property.");
                }

            }
            else {
                throw new RDFSemanticsException("Cannot create RDFOntologyRestriction because given \"onProperty\" parameter is null.");
            }
        }
        /// <summary>
        /// Enlists the range classes of the given property within the given ontology class model
        /// </summary>
        public static RDFOntologyClassModel EnlistRangeClassesOf(RDFOntologyProperty ontProperty,
                                                                 RDFOntologyClassModel classModel)
        {
            var result = new RDFOntologyClassModel();

            if (ontProperty != null && classModel != null)
            {
                if (ontProperty.Range != null)
                {
                    result = EnlistSubClassesOf(ontProperty.Range, classModel)
                             .UnionWith(EnlistEquivalentClassesOf(ontProperty.Range, classModel))
                             .AddClass(ontProperty.Range);
                }
            }
            return(result);
        }
        /// <summary>
        /// Default-ctor to build an ontology restriction on the given ontology property
        /// </summary>
        internal RDFOntologyRestriction (RDFOntologyProperty onProperty): base(new RDFResource()) {
            if (onProperty         != null) {

                //Cannot use annotation properties for ontology restrictions
                if (!onProperty.IsAnnotationProperty()) {
                    this.OnProperty = onProperty;
                }
                else {
                    throw new RDFSemanticsException("Cannot create ontology restriction because given \"onProperty\" parameter represents an annotation property.");
                }

            }
            else {
                throw new RDFSemanticsException("Cannot create ontology restriction because given \"onProperty\" parameter is null.");
            }
        }
        /// <summary>
        /// Default-ctor to build an ontology cardinality restriction on the given property
        /// </summary>
        public RDFOntologyCardinalityRestriction(RDFOntologyProperty onProperty, Int32 minCardinality, Int32 maxCardinality): base(onProperty) {
            
            //Cardinality restrictions are not allowed on transitive properties (OWL-DL constraint)
            if (onProperty.IsObjectProperty()) {
                if (((RDFOntologyObjectProperty)onProperty).Transitive) {
                    throw new RDFSemanticsException("Cannot create cardinality restriction because given \"onProperty\" parameter is a transitive property.");
                }
            }

            //Manage MinCardinality
            if (minCardinality > 0) {
                if (maxCardinality > 0) {
                    if (minCardinality <= maxCardinality) {
                        this.MinCardinality = minCardinality;
                    }
                    else {
                        throw new RDFSemanticsException("Cannot create cardinality restriction because given \"minCardinality\" parameter must be less or equal than \"maxCardinality\" parameter.");
                    }
                }
                else {
                    this.MinCardinality     = minCardinality;
                }
            }

            //Manage MaxCardinality
            if (maxCardinality > 0) {
                if (minCardinality > 0) {
                    if (maxCardinality >= minCardinality) {
                        this.MaxCardinality = maxCardinality;
                    }
                    else {
                        throw new RDFSemanticsException("Cannot create cardinality restriction because given \"maxCardinality\" parameter must be greater or equal than \"minCardinality\" parameter.");
                    }
                }
                else {
                    this.MaxCardinality     = maxCardinality;
                }
            }

            //Manage corner case, throwing exception
            if (this.MinCardinality == 0 && this.MaxCardinality == 0) {
                throw new RDFSemanticsException("Cannot create cardinality restriction because at least one of the given \"minCardinality\" and \"maxCardinality\" parameters must be greater than 0.");
            }

        }
        /// <summary>
        /// Enlists the super properties of the given property within the given property model
        /// </summary>
        public static RDFOntologyPropertyModel EnlistSuperPropertiesOf(RDFOntologyProperty ontProperty,
                                                                       RDFOntologyPropertyModel propertyModel)
        {
            var result = new RDFOntologyPropertyModel();

            if (ontProperty != null && propertyModel != null)
            {
                //Step 1: Reason on the given property
                result = RDFSemanticsUtilities.EnlistSuperPropertiesOf_Core(ontProperty, propertyModel);

                //Step 2: Reason on the equivalent properties
                foreach (var ep in EnlistEquivalentPropertiesOf(ontProperty, propertyModel))
                {
                    result = result.UnionWith(RDFSemanticsUtilities.EnlistSuperPropertiesOf_Core(ep, propertyModel));
                }
            }
            return(result);
        }
Beispiel #15
0
 /// <summary>
 /// Default-ctor to build an ontology restriction with the given name on the given ontology property
 /// </summary>
 internal RDFOntologyRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty) : base(restrictionName)
 {
     if (onProperty != null)
     {
         //AnnotationProperty cannot be restricted
         if (!onProperty.IsAnnotationProperty())
         {
             this.OnProperty = onProperty;
         }
         else
         {
             throw new RDFSemanticsException("Cannot create RDFOntologyRestriction because given \"onProperty\" parameter (" + onProperty + ") is an annotation property.");
         }
     }
     else
     {
         throw new RDFSemanticsException("Cannot create RDFOntologyRestriction because given \"onProperty\" parameter is null.");
     }
 }
        /// <summary>
        /// Default-ctor to build an ontology cardinality restriction with the given name on the given property
        /// </summary>
        public RDFOntologyCardinalityRestriction(RDFResource restrictionName, RDFOntologyProperty onProperty, Int32 minCardinality, Int32 maxCardinality): base(restrictionName, onProperty) {
            
            //MinCardinality
            if (minCardinality > 0) {
                if (maxCardinality > 0) {
                    if (minCardinality <= maxCardinality) {
                        this.MinCardinality = minCardinality;
                    }
                    else {
                        throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because given \"minCardinality\" parameter (" + minCardinality + ") must be less or equal than given \"maxCardinality\" parameter (" + maxCardinality + ")");
                    }
                }
                else {
                    this.MinCardinality     = minCardinality;
                }
            }

            //MaxCardinality
            if (maxCardinality > 0) {
                if (minCardinality > 0) {
                    if (maxCardinality >= minCardinality) {
                        this.MaxCardinality = maxCardinality;
                    }
                    else {
                        throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because given \"maxCardinality\" parameter (" + maxCardinality + ") must be greater or equal than given \"minCardinality\" parameter (" + minCardinality + ")");
                    }
                }
                else {
                    this.MaxCardinality     = maxCardinality;
                }
            }

            if (this.MinCardinality == 0   && this.MaxCardinality == 0) {
                throw new RDFSemanticsException("Cannot create RDFOntologyCardinalityRestriction because at least one of the given \"minCardinality\" and \"maxCardinality\" parameters must be greater than 0.");
            }
        }
 /// <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);
 }
        /// <summary>
        /// Subsumes the "rdfs:subPropertyOf" taxonomy to discover direct and indirect superProperties of the given property
        /// </summary>
        internal static RDFOntologyPropertyModel EnlistSuperPropertiesOf(RDFOntologyProperty ontProperty, RDFOntologyPropertyModel propertyModel) {
            var result  = new RDFOntologyPropertyModel();

            // Transitivity of "rdfs:subPropertyOf" taxonomy: ((A SUPERPROPERTYOF B)  &&  (B SUPERPROPERTYOF C))  =>  (A SUPERPROPERTYOF C)
            foreach(var sp in propertyModel.Relations.SubPropertyOf.SelectEntriesBySubject(ontProperty)) {
                result.AddProperty((RDFOntologyProperty)sp.TaxonomyObject);
                result  = result.UnionWith(RDFSemanticsUtilities.EnlistSuperPropertiesOf((RDFOntologyProperty)sp.TaxonomyObject, propertyModel));
            }

            return result;
        }
        internal static RDFOntologyPropertyModel EnlistSuperPropertiesOf_Core(RDFOntologyProperty ontProperty, RDFOntologyPropertyModel propertyModel) {
            var result1 = new RDFOntologyPropertyModel();
            var result2 = new RDFOntologyPropertyModel();

            // Step 1: Direct subsumption of "rdfs:subPropertyOf" taxonomy
            result1     = RDFSemanticsUtilities.EnlistSuperPropertiesOf(ontProperty, propertyModel);

            // Step 2: Enlist equivalent properties of subproperties
            result2     = result2.UnionWith(result1);
            foreach(var sp in result1) {
                result2 = result2.UnionWith(RDFOntologyReasoningHelper.EnlistEquivalentPropertiesOf(sp, propertyModel)
                                                .UnionWith(RDFOntologyReasoningHelper.EnlistSuperPropertiesOf(sp, propertyModel)));
            }

            return result2;
        }
        /// <summary>
        /// Enlists the super properties of the given property within the given property model
        /// </summary>
        public static RDFOntologyPropertyModel EnlistSuperPropertiesOf(RDFOntologyProperty ontProperty, RDFOntologyPropertyModel propertyModel) {
            var result         = new RDFOntologyPropertyModel();
            if(ontProperty    != null && propertyModel != null) {

                //Step 1: Reason on the given property
                result         = RDFSemanticsUtilities.EnlistSuperPropertiesOf_Core(ontProperty, propertyModel);

                //Step 2: Reason on the equivalent properties of the given property
                foreach(var   ep in RDFOntologyReasoningHelper.EnlistEquivalentPropertiesOf(ontProperty, propertyModel)) {
                    result     = result.UnionWith(RDFSemanticsUtilities.EnlistSuperPropertiesOf_Core(ep, propertyModel));
                }

            }
            return result;
        }
 /// <summary>
 /// Default-ctor to build an ontology attribute with the given property and given value
 /// </summary>
 internal RDFOntologyAttribute(RDFOntologyProperty attrProperty, RDFOntologyFact attrValue) {
     if (attrProperty  != null) {
         if (attrValue != null) {
             this.AttributeProperty = attrProperty;
             this.AttributeValue    = attrValue;
             this.AttributeID       = RDFModelUtilities.CreateHash(this.ToString());
         }
         else {
             throw new RDFSemanticsException("Cannot create ontology attribute because given \"attrValue\" parameter is null.");
         }
     }
     else {
         throw new RDFSemanticsException("Cannot create ontology attribute because given \"attrProperty\" parameter is null.");
     }
 }
 /// <summary>
 /// Checks if the given property is a reserved BASE ontology property
 /// </summary>
 internal static Boolean CheckReservedProperty(RDFOntologyProperty ontProperty)
 {
     return(RDFBASEOntology.Instance.Model.PropertyModel.Properties.ContainsKey(ontProperty.PatternMemberID));
 }
 /// <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);
 }
 /// <summary>
 /// Removes the given ontology attribute from the attributes of this
 /// </summary>
 public RDFOntologyFact RemoveOntologyAttribute(RDFOntologyProperty attrProperty, RDFOntologyFact attrValue) {
     if (attrProperty != null && attrValue != null) {
         var attr      = new RDFOntologyAttribute(attrProperty, attrValue);
         if (this.OntologyAttributes.ContainsKey(attr.AttributeID)) {
             this.OntologyAttributes.Remove(attr.AttributeID);
         }
     }
     return this;
 }
 /// <summary>
 /// Enlists the equivalentProperties of the given property within the given property model
 /// </summary>
 public static RDFOntologyPropertyModel EnlistEquivalentPropertiesOf(RDFOntologyProperty ontProperty, RDFOntologyPropertyModel propertyModel) {
     var result         = new RDFOntologyPropertyModel();
     if (ontProperty   != null && propertyModel != null) {
         result         = RDFSemanticsUtilities.EnlistEquivalentPropertiesOf_Core(ontProperty, propertyModel, null).RemoveProperty(ontProperty);
     }
     return result;
 }
 /// <summary>
 /// Checks if the given aProperty is equivalentProperty of the given bProperty within the given property model
 /// </summary>
 public static Boolean IsEquivalentPropertyOf(RDFOntologyProperty aProperty, RDFOntologyProperty bProperty, RDFOntologyPropertyModel propertyModel) {
     return (aProperty != null && bProperty != null && propertyModel != null ? RDFOntologyReasoningHelper.EnlistEquivalentPropertiesOf(aProperty, propertyModel).Properties.ContainsKey(bProperty.PatternMemberID) : false);
 }
 /// <summary>
 /// Checks if the given aProperty is equivalentProperty of the given bProperty within the given property model
 /// </summary>
 public static Boolean IsEquivalentPropertyOf(RDFOntologyProperty aProperty,
                                              RDFOntologyProperty bProperty,
                                              RDFOntologyPropertyModel propertyModel)
 {
     return(aProperty != null && bProperty != null && propertyModel != null ? EnlistEquivalentPropertiesOf(aProperty, propertyModel).Properties.ContainsKey(bProperty.PatternMemberID) : false);
 }
        /// <summary>
        /// Subsumes the "owl:equivalentProperty" taxonomy to discover direct and indirect equivalentProperties of the given property
        /// </summary>
        internal static RDFOntologyPropertyModel EnlistEquivalentPropertiesOf_Core(RDFOntologyProperty ontProperty,
                                                                                   RDFOntologyPropertyModel propertyModel,
                                                                                   Dictionary<Int64, RDFOntologyProperty> visitContext) {
            var result        = new RDFOntologyPropertyModel();

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

            // Transitivity of "owl:equivalentProperty" taxonomy: ((A EQUIVALENTPROPERTY B)  &&  (B EQUIVALENTPROPERTY C))  =>  (A EQUIVALENTPROPERTY C)
            foreach (var      ep in propertyModel.Relations.EquivalentProperty.SelectEntriesBySubject(ontProperty)) {
                result.AddProperty((RDFOntologyProperty)ep.TaxonomyObject);
                result        = result.UnionWith(RDFSemanticsUtilities.EnlistEquivalentPropertiesOf_Core((RDFOntologyProperty)ep.TaxonomyObject, propertyModel, visitContext));
            }

            return result;
        }
        /// <summary>
        /// Adds the given ontology attribute to the attributes of this
        /// </summary>
        public RDFOntologyFact AddOntologyAttribute(RDFOntologyProperty attrProperty, RDFOntologyFact attrValue) {
            if (attrProperty != null && attrValue != null) {

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

                    //Maintain disjointness between property model and reserved RDF/RDFS/OWL vocabularies
                    if ( (!attrProperty.ToString().StartsWith(RDFVocabulary.RDF.BASE_URI.ToString(),  StringComparison.Ordinal)) &&
                         (!attrProperty.ToString().StartsWith(RDFVocabulary.RDFS.BASE_URI.ToString(), StringComparison.Ordinal)) &&
                         (!attrProperty.ToString().StartsWith(RDFVocabulary.OWL.BASE_URI.ToString(),  StringComparison.Ordinal)) ) {

                            //Check consistence of property type against range fact type
                            if( (attrProperty.IsObjectProperty()   && attrValue.IsObjectFact())  ||
                                (attrProperty.IsDatatypeProperty() && attrValue.IsLiteralFact())) {

                                var attr = new RDFOntologyAttribute(attrProperty, attrValue);
                                if (!this.OntologyAttributes.ContainsKey(attr.AttributeID)) {
                                    this.OntologyAttributes.Add(attr.AttributeID, attr);
                                }

                            }

                    }

                }

            }
            return this;
        }
 /// <summary>
 /// Enlists the range classes of the given property within the given ontology class model
 /// </summary>
 public static RDFOntologyClassModel EnlistRangeClassesOf(RDFOntologyProperty ontProperty, RDFOntologyClassModel classModel) {
     var result          = new RDFOntologyClassModel();
     if (ontProperty    != null && classModel != null) {
         if (ontProperty.Range  != null) {
             result      = RDFOntologyReasoningHelper.EnlistSubClassesOf(ontProperty.Range, classModel)
                              .UnionWith(RDFOntologyReasoningHelper.EnlistEquivalentClassesOf(ontProperty.Range, classModel))
                              .AddClass(ontProperty.Range);
         }
     }
     return result;
 }