コード例 #1
0
 public OntologyClass(String name, List <String> parentNames)
 {
     this.name = new OntologyName(name);
     if (parentNames != null)
     {
         foreach (String nn in parentNames)
         {
             this.parentNames.Add(new OntologyName(nn));
         }
     }
 }
コード例 #2
0
        public String AsString()
        {
            // generate a string which may be used to present or identify the particular path.
            String retval  = "";
            int    counter = 0;

            foreach (Triple tt in this.tripleList)
            {
                String from = new OntologyName(tt.GetSubject()).GetLocalName();
                String via  = new OntologyName(tt.GetPredicate()).GetLocalName();
                String to   = new OntologyName(tt.GetObject()).GetLocalName();

                retval += "[" + from + "." + via + "] to ";

                // If "to" does not equal first class in next triple then put it in too
                if (counter == (this.tripleList.Count() - 1) || !(to.Equals(new OntologyName(this.tripleList[counter + 1].GetObject()).GetLocalName())))
                {
                    retval += to + " ";
                }
                counter++;
            }
            return(retval);
        }
コード例 #3
0
 public Boolean Equals(OntologyName oName)
 {
     return(this.name.Equals(oName.name));
 }
コード例 #4
0
 public OntologyProperty(String name, String range)
 {
     this.name  = new OntologyName(name);
     this.range = new OntologyRange(range);
 }
コード例 #5
0
        public String GenerateUserPathString(Node anchorNode, Boolean singleLoopFlag)
        {
            String anchorNodeName = anchorNode.GetSparqlID();
            String retval         = anchorNodeName + ": ";

            // handle the loop case:
            if (singleLoopFlag)
            {
                String classID   = new OntologyName(this.GetClass0Name(0)).GetLocalName();
                String attribute = new OntologyName(this.GetAttributeName(0)).GetLocalName();
                retval += anchorNode.GetSparqlID() + "-" + attribute + "->" + classID + "_NEW";
            }
            else
            {
                String first = new OntologyName(this.GetStartClassName()).GetLocalName();
                retval += first;
                if (!first.Equals(anchorNode.GetUri(true)))
                {
                    retval += "_NEW";
                }
                String last = first;

                for (int i = 0; i < this.GetLength(); i++)
                {
                    String class0 = new OntologyName(this.GetClass0Name(i)).GetLocalName();
                    String att    = new OntologyName(this.GetAttributeName(i)).GetLocalName();
                    String class1 = new OntologyName(this.GetAttributeName(i)).GetLocalName();
                    String sub0   = "";
                    String sub1   = "";

                    // mark connecting node on last hop of this generation.
                    if (i == (this.GetLength() - 1))
                    {
                        if (class0.Equals(last))
                        {
                            sub0 = anchorNode.GetSparqlID();
                        }
                        else
                        {
                            sub1 = anchorNode.GetSparqlID();
                        }
                    }

                    if (class0.Equals(last))
                    {
                        retval += "-" + att + "->";
                        retval += (!sub1.Equals("")) ? sub1 : class1;
                        last    = class1;
                    }
                    else
                    {
                        retval += "<-" + att + "-";
                        retval += (!sub0.Equals("")) ? sub0 : class0;
                        last    = class0;
                    }
                }
                if (!last.Equals(anchorNode.GetUri(true)))
                {
                    retval += "_NEW";
                }
            }

            return(retval);
        }
コード例 #6
0
        public List <OntologyPath> FindAllPaths(String FromClassName, List <String> targetClassNames, String domain)
        {
            this.pathWarnings = new List <String>();
            List <OntologyPath> waitingList = new List <OntologyPath>();

            waitingList.Add(new OntologyPath(FromClassName));
            List <OntologyPath>      ret        = new List <OntologyPath>();
            Dictionary <String, int> targetHash = new Dictionary <String, int>(); // hash of all possible ending classes:  targetHash[className] = 1

            long t0 = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            int LENGTH_RANGE     = 2;
            int SEARCH_TIME_MSEC = 5000;
            int LONGEST_PATH     = 10;

            // return if there is no endpoint
            if (targetClassNames.Count == 0)
            {
                return(ret);
            }

            // set up targetHash[targetClass] = 1
            for (int i = 0; i < targetClassNames.Count; i++)
            {
                if (!targetHash.ContainsKey(targetClassNames[i]))
                {
                    targetHash.Add(targetClassNames[i], 1);
                }
            }

            // STOP CRITERIA A: search as long as there is a waiting list
            while (waitingList.Count != 0)
            {
                // pull one off the waiting list
                OntologyPath item = waitingList[0];
                waitingList.RemoveAt(0);
                String       waitClass = item.GetEndClassName();
                OntologyPath waitPath  = item;

                // STOP CRITERIA B: also stop searching if:
                // this is the final path (with 1 added connection) will be longer than the first (shortest) already found path
                if (!(ret.Count == 0) && (waitPath.GetLength() + 1 > ret[0].GetLength() + LENGTH_RANGE))
                {
                    break;
                }

                // STOP CRITERIA C: stop if the path is too long.
                if (waitPath.GetLength() > LONGEST_PATH)
                {
                    break;
                }

                // STOP CRITERIA D: too much time spent searching.
                long tt = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                if (tt - t0 > SEARCH_TIME_MSEC)
                {
                    this.pathWarnings.Add("Note: Path-finding timing out.  Search incomplete.");
                }

                // get all of the one-hop connections and loop through them.
                List <OntologyPath> conn = this.GetConnList(waitClass);
                foreach (OntologyPath currPath in conn)
                {
                    // each connection is a path with only one node (the 0th)
                    // grab the name of the newly-found class

                    String       newClass = "";
                    OntologyPath newPath  = null;
                    Boolean      loopFlag = false;

                    // if the newfound class is pointed to by an attribute of one on the wait list
                    if (currPath.GetStartClassName().ToLower().Equals(waitClass.ToLower()))
                    {
                        newClass = currPath.GetEndClassName();
                    }
                    else
                    {
                        newClass = currPath.GetStartClassName();
                    }

                    // check for loops in the path before adding the class
                    if (waitPath.ContainsClass(newClass))
                    {
                        loopFlag = true;
                    }

                    // build the new path.
                    Triple t = currPath.GetTriple(0);
                    newPath = waitPath.DeepCopy();
                    newPath.AddTriple(t.GetSubject(), t.GetPredicate(), t.GetObject());

                    // if the path leads anywhere in domain, store it.
                    OntologyName name = new OntologyName(newClass);
                    if (name.IsInDomain(domain))
                    {   // if the path leads to a target, push onth the ret list
                        if (targetHash.ContainsKey(newClass))
                        {
                            ret.Add(newPath);
                        }
                        else if (loopFlag == false)
                        {   // try extending an already found path.
                            waitingList.Add(newPath);
                        }
                    }
                }
            }
            return(ret);
        }