/// <summary>Creates a new <see cref="Ontology"/> specification.</summary> /// <param name="displayName">Display name of the ontology.</param> /// <param name="namespace">Namespace prefix and base URI</param> /// <param name="terms">A collection of RDF classes and properties</param> public Ontology(string displayName, NamespaceSpecification @namespace, params Term[] terms) { _displayName = (displayName ?? String.Empty); Properties = terms.OfType<Property>().Select(property => property.InOntology(this)).ToList(); _namespace = @namespace; Classes = terms.OfType<Class>().Select(@class => @class.InOntology(this)).ToList(); }
/// <summary>Creates a new <see cref="Ontology"/> specification.</summary> /// <param name="displayName">Display name of the ontology.</param> /// <param name="namespace">Namespace prefix and base URI</param> /// <param name="terms">A collection of RDF classes and properties</param> public Ontology([AllowNull] string displayName, NamespaceSpecification @namespace, params Term[] terms) { _displayName = (displayName ?? String.Empty); Properties = terms.OfType<Property>().Select(property => property.InOntology(this)).ToList(); _namespace = @namespace; Classes = terms.OfType<Class>().Select(@class => @class.InOntology(this)).ToList(); }
private IOntology CreateFromXML(Stream fileStream) { bool isOwlBasedFile = true; XDocument document = XDocument.Load(fileStream); XElement ontologyElement = (from element in document.Descendants() where element.Name.LocalName == "Ontology" select element).FirstOrDefault(); if (ontologyElement == null) { isOwlBasedFile = false; ontologyElement = ( from element in document.Descendants() where (element.Name.LocalName == "Description") && (element.Descendants().Any(item => (item.Name.LocalName == "type") && (item.Attributes().Any(attribute => (attribute.Name.LocalName == "resource") && (attribute.Value == "http://www.w3.org/2002/07/owl#Ontology"))))) select element).FirstOrDefault(); if (ontologyElement == null) { throw new ArgumentOutOfRangeException("Provided stream does not contain ontology information suitable for usage."); } } NamespaceSpecification namespaceSpecification = null; string displayName = null; IEnumerable <Term> terms = null; namespaceSpecification = ( from attribute in ontologyElement.Attributes() where attribute.Name.LocalName == "about" select new NamespaceSpecification(ontologyElement.GetPrefixOfNamespace(attribute.Value), new Uri(attribute.Value))).FirstOrDefault(); displayName = ( from child in ontologyElement.Descendants() where (child.Name.LocalName == "label") || (child.Name.LocalName == "title") select child.Value).FirstOrDefault(); if (isOwlBasedFile) { terms = CreateFromOWLXML(document, namespaceSpecification.BaseUri); } else { terms = CreateFromRDFXML(document, namespaceSpecification.BaseUri); } return(new Ontology(displayName, namespaceSpecification, terms.ToArray())); }
/// <summary>Creates a new <see cref="Ontology"/> specification.</summary> /// <param name="namespace">Namespace prefix and base URI</param> /// <param name="terms">A collection of RDF classes and properties</param> public Ontology(NamespaceSpecification @namespace, params Term[] terms) : this(String.Empty, @namespace, terms) { }
#pragma warning restore private bool Equals(NamespaceSpecification other) { return(BaseUri.Equals(other.BaseUri) && string.Equals(Prefix, other.Prefix)); }
#pragma warning restore private bool Equals(NamespaceSpecification other) { return BaseUri.Equals(other.BaseUri) && string.Equals(Prefix, other.Prefix); }