Ejemplo n.º 1
0
        /// <summary>
        /// Gets a short name representation for an ontology, based on the last segment
        /// of the ontology IRI or (in the case of anonymous ontologies) the ontology hash.
        /// Useful for qname prefixes.
        /// </summary>
        /// <param name="ontology"></param>
        /// <returns></returns>
        public static string GetShortName(this Ontology ontology)
        {
            // Fallback way of getting a persistent short identifier in the
            // (unlikely?) case that we are dealing w/ an anonymous ontology
            if (!ontology.IsNamed())
            {
                return(ontology.GetHashCode().ToString(invariantCulture));
            }

            // This is a simple string handling thing
            string ontologyUriString = ontology.GetIri().ToString();

            // Trim any occurences of entity separation characters
            if (ontologyUriString.EndsWith("/", StringComparison.Ordinal) || ontologyUriString.EndsWith("#", StringComparison.Ordinal))
            {
                char[] trimChars = { '/', '#' };
                ontologyUriString = ontologyUriString.Trim(trimChars);
            }

            // Get the last bit of the string
            ontologyUriString = ontologyUriString.Substring(ontologyUriString.LastIndexOf('/') + 1);

            // If the string contains dots, treat them as file ending delimiter and get rid of them
            // one at a time
            while (ontologyUriString.Contains('.', StringComparison.Ordinal))
            {
                ontologyUriString = ontologyUriString.Substring(0, ontologyUriString.LastIndexOf('.'));
            }

            return(ontologyUriString);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the version IRI of the ontology, if it is defined, or the ontology
 /// IRI if it is not. If neither is defined (i.e. the ontology is anonymous),
 /// throws an exception.
 /// </summary>
 /// <param name="ontology"></param>
 /// <returns></returns>
 public static Uri GetVersionOrOntologyIri(this Ontology ontology)
 {
     if (ontology.HasVersionIri())
     {
         return(ontology.GetVersionIri());
     }
     return(ontology.GetIri());
 }