public static Ontology GetOntology()

in OWL2DTDL/DotNetRdfExtensions.cs [469:487]


        public static Ontology GetOntology(this OntologyGraph graph)
        {
            IUriNode rdfType = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            IUriNode owlOntology = graph.CreateUriNode(new Uri(OntologyHelper.OwlOntology));
            IEnumerable<IUriNode> ontologyNodes = graph.GetTriplesWithPredicateObject(rdfType, owlOntology)
                .Select(triple => triple.Subject)
                .UriNodes();

            switch (ontologyNodes.Count())
            {
                case 0:
                    throw new RdfException($"The graph {graph} doesn't contain any owl:Ontology declarations.");
                case 1:
                    return new Ontology(ontologyNodes.Single(), graph);
                default:
                    IUriNode ontologyNode = ontologyNodes.Where(node => node.Uri.AbsoluteUri.Equals(graph.BaseUri.AbsoluteUri)).DefaultIfEmpty(ontologyNodes.First()).First();
                    return new Ontology(ontologyNode, graph);
            }
        }