public static bool IsXsdDatatype(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return oClass.GetIri().ToString().StartsWith(XmlSpecsHelper.NamespaceXmlSchema, StringComparison.Ordinal);
     }
     return false;
 }
 public static IEnumerable <string> DtdlTypes(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return(oClass.GetUriNode().DtdlTypes());
     }
     return(new List <string>());
 }
 public static bool IsXsdDatatype(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return(oClass.GetUri().AbsoluteUri.StartsWith(XmlSpecsHelper.NamespaceXmlSchema, StringComparison.Ordinal));
     }
     return(false);
 }
示例#4
0
 public Relationship(OntologyProperty property, OntologyClass target)
 {
     if (!property.IsNamed() || !(target.IsNamed() || target.IsDatatype()))
     {
         throw new ArgumentException("Only named properties and named or datatype targets allowed.");
     }
     Property = property;
     Target   = target;
 }
        public static IEnumerable <Relationship> GetRelationships(this OntologyClass cls)
        {
            List <Relationship> relationships = new List <Relationship>();

            // Start w/ rdfs:domain declarations. At this time we only consider no-range (i.e.,
            // range is owl:Thing) or named singleton ranges
            IEnumerable <OntologyProperty> rdfsDomainProperties = cls.IsDomainOf.Where(
                property =>
                property.Ranges.Count() == 0 ||
                (property.Ranges.Count() == 1 && (property.Ranges.First().IsNamed() || property.Ranges.First().IsDatatype())));

            foreach (OntologyProperty property in rdfsDomainProperties)
            {
                Relationship newRelationship;
                if (property.Ranges.Count() == 0)
                {
                    OntologyGraph oGraph = cls.Graph as OntologyGraph;
                    OntologyClass target;
                    if (property.IsObjectProperty())
                    {
                        target = oGraph.CreateOntologyClass(VocabularyHelper.OWL.Thing);
                    }
                    else
                    {
                        target = oGraph.CreateOntologyClass(VocabularyHelper.RDFS.Literal);
                    }
                    newRelationship = new Relationship(property, target);
                }
                else
                {
                    OntologyClass range = property.Ranges.First();
                    newRelationship = new Relationship(property, range);
                }

                if (property.IsFunctional())
                {
                    newRelationship.ExactCount = 1;
                }

                relationships.Add(newRelationship);
            }

            // Continue w/ OWL restrictions on the class
            IEnumerable <OntologyRestriction> ontologyRestrictions = cls.DirectSuperClasses
                                                                     .Where(superClass => superClass.IsRestriction())
                                                                     .Select(superClass => new OntologyRestriction(superClass));

            foreach (OntologyRestriction ontologyRestriction in ontologyRestrictions)
            {
                OntologyProperty restrictionProperty = ontologyRestriction.OnProperty;
                OntologyClass    restrictionClass    = ontologyRestriction.OnClass;
                if (restrictionProperty.IsNamed() && (restrictionClass.IsNamed() || restrictionClass.IsDatatype()))
                {
                    Relationship newRelationship = new Relationship(restrictionProperty, restrictionClass);

                    int min     = ontologyRestriction.MinimumCardinality;
                    int exactly = ontologyRestriction.ExactCardinality;
                    int max     = ontologyRestriction.MaximumCardinality;

                    if (min != 0)
                    {
                        newRelationship.MinimumCount = min;
                    }
                    if (exactly != 0)
                    {
                        newRelationship.ExactCount = exactly;
                    }
                    if (max != 0)
                    {
                        newRelationship.MaximumCount = max;
                    }

                    relationships.Add(newRelationship);
                }
            }

            // Iterate over the gathered list of Relationships and narrow down to the most specific ones, using a Dictionary for lookup and the MergeWith() method for in-place narrowing
            Dictionary <OntologyProperty, Relationship> relationshipsDict = new Dictionary <OntologyProperty, Relationship>(new OntologyResourceComparer());

            foreach (Relationship relationship in relationships)
            {
                OntologyProperty property = relationship.Property;
                OntologyResource target   = relationship.Target;
                // If we already have this property listed in the dictionary, first narrow down the relationship by combining it with the old copy
                if (relationshipsDict.ContainsKey(property))
                {
                    Relationship oldRelationship = relationshipsDict[property];
                    relationship.MergeWith(oldRelationship);
                }
                // Put relationship in the dictionary
                relationshipsDict[property] = relationship;
            }

            // Return the values
            return(relationshipsDict.Values);
        }
 public static bool IsOwlThing(this OntologyClass oClass)
 {
     return(oClass.IsNamed() && oClass.GetUri().AbsoluteUri.Equals(OWL.Thing.AbsoluteUri));
 }
示例#7
0
 public static bool IsRdfsLiteral(this OntologyClass oClass)
 {
     return(oClass.IsNamed() && oClass.GetUri().AbsoluteUri.Equals(VocabularyHelper.OWL.Thing.AbsoluteUri));
 }
        public static bool IsOwlThing(this OntologyClass cls)
        {
            Uri owlThing = new Uri("http://www.w3.org/2002/07/owl#Thing");

            return(cls.IsNamed() && cls.GetIri().Equals(owlThing));
        }
 public static bool IsTopNamedClass(this OntologyClass cls)
 {
     return(cls.IsNamed() && !cls.DirectSuperClasses.Any(superCls => superCls.IsNamed() && !superCls.Resource.ToString().Equals("http://www.w3.org/2002/07/owl#Thing")));
 }