public static List ShortestParentPathToOwlThing()

in OWL2DTDL/DotNetRdfExtensions.cs [239:274]


        public static List<string> ShortestParentPathToOwlThing(this OntologyClass oClass)
        {
            IUriNode rdfsSubClassOf = oClass.Graph.CreateUriNode(RDFS.subClassOf);
            IEnumerable<OntologyClass> directSuperClasses = oClass.DirectSuperClasses.Where(
                parentClass => 
                    parentClass.IsNamed() && 
                    !parentClass.IsDeprecated() &&
                    !Program.PropertyAssertionIsDeprecated(oClass.GetUriNode(), rdfsSubClassOf, parentClass.GetUriNode())
            );

            // If we have no superclass or one of our superclasses is OWL:Thing, then we have reached the top level; return
            if (directSuperClasses.Count() < 1 || directSuperClasses.Any(superClass => superClass.IsOwlThing()))
            {
                return new List<string>();
            }
            else
            {
                // Assume the first parent has the shortest path; if not, it will be replaced in subsequent foreach
                OntologyClass shortestParent = directSuperClasses.First();
                List<string> shortestParentPath = shortestParent.ShortestParentPathToOwlThing();
                // Iterate through the other parents to see if any is shorter
                foreach (OntologyClass possibleSuperClass in directSuperClasses.Skip(1))
                {
                    List<string> possibleSuperClassParents = possibleSuperClass.ShortestParentPathToOwlThing();
                    if (possibleSuperClassParents.Count() < shortestParentPath.Count())
                    {
                        shortestParent = possibleSuperClass;
                        shortestParentPath = possibleSuperClassParents;
                    }
                }

                // At this point shortestParentPath + shortestParent should together contain the shortest path to the root; return them
                shortestParentPath.Add(shortestParent.GetLocalName());
                return shortestParentPath;
            }
        }