Beispiel #1
0
        private void fwdELCA()
        {
            Item2 v = null;

            int[] w;
            while (!fwdEof())
            {
                if (fwdGetCA(out v))
                {
                    while (S.Count > 0 && S.Peek()[0] != v.PIDPos)
                    {
                        w = S.Pop();
                        modTop(w);
                        if (isELCA(w))
                        {
                            ELCAs.Add(Ls2[0][w[0]]);
                        }
                    }

                    S.Push((int[])cursors.Clone());
                }
                fwdAdvance();
            }
            while (S.Count > 0)
            {
                w = S.Pop();
                modTop(w);
                if (isELCA(w))
                {
                    ELCAs.Add(Ls2[0][w[0]]);
                }
            }
        }
Beispiel #2
0
        private void bwdSLCA()
        {
            for (int i = 0; i < Ls2.Count; i++)
            {
                cursors[i] = Ls2[i].Count - 1;
            }
            int   u = -1;
            Item2 v = null;

            while (!bwdEof())
            {
                if (bwdGetCA(out v))
                {
                    if (u != Ls2[0].IndexOf(v))
                    {
                        SLCAs.Add(v);
                    }
                    u = v.PIDPos;
                }
                else
                {
                    break;
                }
                bwdAdvance();
            }
        }
Beispiel #3
0
 public Item2(Item2 other)
 {
     ID     = other.ID;
     PIDPos = other.PIDPos;
     Ndesc  = other.Ndesc;
     value  = other.value;
     name   = other.name;
 }
Beispiel #4
0
 public void printLs2()
 {
     for (int i = 0; i < Ls2.Count; i++)
     {
         Console.Write(String.Format("{0}:", keywords[i]));
         for (int j = 0; j < Ls2[i].Count; j++)
         {
             Item2 item2 = Ls2[i][j];
             Console.Write(String.Format("[ID:{0}, name:{1}, PIDPos:{2}, Ndesc:{3}]-", item2.ID, item2.name, item2.PIDPos, item2.Ndesc));
         }
         Console.WriteLine();
     }
 }
Beispiel #5
0
 private void printLs2()
 {
     for (int i = 0; i < Ls2.Count; i++)
     {
         Console.WriteLine(keywords[i] + ":");
         for (int j = 0; j < Ls2[i].Count; j++)
         {
             Item2 item = Ls2[i][j];
             Console.WriteLine("[ID:" + item.ID + ",name:" + item.name + ",PIDPos:" + item.PIDPos + ",Ndesc:" + item.Ndesc + ",n:" + item.n);
         }
         Console.WriteLine("-----------------------");
     }
 }
Beispiel #6
0
        public string printSLCAs(bool isConsole)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SLCAs for keywords {");
            foreach (string keyword in keywords)
            {
                sb.Append(keyword);
                sb.Append(",");
            }
            sb.Replace(',', '}', sb.Length - 1, 1);
            sb.Append("\r\n");
            for (int i = 0; i < SLCAs.Count; i++)
            {
                Item2 item = SLCAs[i];
                sb.Append("[ID:");
                sb.Append(item.ID);
                sb.Append(", Name:");
                sb.Append(item.name);
                sb.Append(", PIDPos:");
                sb.Append(item.PIDPos);
                sb.Append(", Ndesc:");
                sb.Append(item.Ndesc);
                sb.Append(", Value:");
                sb.Append(item.value == null ? "NULL" : item.value);
                sb.Append("]");
                sb.Append("\r\n");
            }
            sb.Append("# of SLCAs:");
            sb.Append(SLCAs.Count);
            sb.Append("\r\n");
            sb.Append("------------------------------------------------------------------------------------\r\n");
            if (isConsole)
            {
                Console.Write(sb.ToString());
            }
            else
            {
                return(sb.ToString());
            }
            return(null);
        }
Beispiel #7
0
        private void fwdSLCA()
        {
            int   u = -1;
            Item2 v = null;

            while (!fwdEof())
            {
                if (fwdGetCA(out v))
                {
                    if (u != v.PIDPos)
                    {
                        SLCAs.Add(Ls2[0][u]);
                    }
                    u = Ls2[0].IndexOf(v);
                    fwdAdvance();
                }
                else
                {
                    SLCAs.Add(Ls2[0][u]);
                    break;
                }
            }
        }
Beispiel #8
0
        private void bwdELCA()
        {
            Item2 v = null;

            int[] w;
            while (!bwdEof())
            {
                if (bwdGetCA(out v))
                {
                    if (S.Count == 0)
                    {
                        ELCAs.Add(v);
                        if (v.PIDPos == -1)
                        {
                            break;
                        }
                        pushParent();
                    }
                    else
                    {
                        if (v.ID == Ls2[0][S.Peek()[0]].ID)
                        {
                            Console.WriteLine("==");
                            w = S.Pop();
                            if (isELCA(w))
                            {
                                ELCAs.Add(Ls2[0][w[0]]);
                            }
                            if (S.Count == 0)
                            {
                                if (v.PIDPos == -1)
                                {
                                    break;
                                }
                                else
                                {
                                    pushParent();
                                }
                            }
                            else if (Ls2[0][v.PIDPos].ID == Ls2[0][S.Peek()[0]].ID)
                            {
                                modTop(cursors);
                            }
                            else
                            {
                                pushParent();
                            }
                        }
                        else
                        {
                            Console.WriteLine("!=");
                            ELCAs.Add(v);
                            if (Ls2[0][v.PIDPos].ID == Ls2[0][S.Peek()[0]].ID)
                            {
                                modTop(cursors);
                            }
                            else
                            {
                                pushParent();
                            }
                        }
                    }
                }
                else
                {
                    break;
                }
                bwdAdvance();
            }
        }
Beispiel #9
0
        public bool bwdGetCA(out Item2 c)
        {
            bool success;

            do
            {
                success = true;
                bool  FOL     = false;
                int   minID   = Int32.MaxValue;
                int[] tempCur = cursors;

                for (int i = 0; i < cursors.Length; i++)
                {
                    int Id = Ls2[i][cursors[i]].ID;
                    if (minID > Id)
                    {
                        minID = Id;
                    }
                }

                for (int n = 0; n < Ls2.Count; n++)
                {
                    int Pos = bwdBinSearch(n, minID);
                    if (Pos == -1)
                    {
                        FOL = true;
                        break;
                    }
                    if (Pos == -2)
                    {
                        success = false;
                        break;
                    }
                    else
                    {
                        tempCur[n] = Pos;
                    }
                }

                if (FOL)
                {
                    c       = null;
                    success = false;
                    break;
                }

                if (success)
                {
                    cursors = tempCur;
                    c       = Ls2[0][cursors[0]];
                    break;
                }
                else
                {
                    bwdAdvance();
                    if (bwdEof())
                    {
                        success = false;
                        c       = null;
                        break;
                    }
                }
            } while (true);
            return(success);
        }
Beispiel #10
0
        public bool fwdGetCA(out Item2 c)
        {
            bool success = true;

            do
            {
                success = true;
                bool  EOL     = false;
                int   maxID   = -1;
                int[] tempCur = cursors;

                for (int i = 0; i < cursors.Length; i++)
                {
                    int Id = Ls2[i][cursors[i]].ID;
                    if (maxID < Id)
                    {
                        maxID = Id;
                    }
                }

                for (int n = 0; n < Ls2.Count; n++)
                {
                    int Pos = fwdBinSearch(n, maxID);
                    if (Pos >= Ls2[n].Count)
                    {
                        EOL = true;
                        break;
                    }
                    if (Pos == -1)
                    {
                        success = false;
                        break;
                    }
                    else
                    {
                        tempCur[n] = Pos;
                    }
                }

                if (EOL)
                {
                    c       = null;
                    success = false;
                    break;
                }

                if (success)
                {
                    cursors = tempCur;
                    c       = Ls2[0][cursors[0]];
                    break;
                }
                else
                {
                    fwdAdvance();
                    if (fwdEof())
                    {
                        success = false;
                        c       = null;
                        break;
                    }
                }
            } while (true);

            return(success);
        }
Beispiel #11
0
        public void buildLs2(string xmlPath, string p)
        {
            keywords = Regex.Split(p.Trim(), @" +").ToList <String>();
            Ls2.Clear();
            for (int i = 0; i < keywords.Count; i++)
            {
                Ls2.Add(new List <Item2>());
            }
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Parse;
            XmlReader     xmlReader    = XmlReader.Create(xmlPath, settings);
            int           currID       = 1;
            Stack <Item2> parentsLinks = new Stack <Item2>();
            int           depth        = 0;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    Item2 item2 = new Item2(currID++, xmlReader.Name);
                    parentsLinks.Push(item2);
                    depth++;
                    break;

                case XmlNodeType.Text:
                    for (int i = 0; i < keywords.Count; i++)
                    {
                        if (xmlReader.Value.ToLower().Contains(keywords[i].ToLower()))
                        {
                            Item2[] ancestors = parentsLinks.ToArray();
                            Array.Reverse(ancestors);
                            int  j         = ancestors.Length - 1;
                            int  k         = Ls2[i].Count - 1;
                            bool goThrough = false;
                            while (k >= 0 && j >= 0)
                            {
                                goThrough = true;
                                if (Ls2[i][k].ID < ancestors[j].ID)
                                {
                                    j--;
                                }
                                else if (Ls2[i][k].ID == ancestors[j].ID)
                                {
                                    break;
                                }
                                else
                                {
                                    k--;
                                }
                            }
                            if (j >= 0 && k >= 0)
                            {
                                if (Ls2[i][k].ID != ancestors[j].ID)
                                {
                                    throw new Exception("Not Merging into a same ancestors");
                                }
                                else
                                {
                                    int pidPos = k;
                                    while (k >= 0)
                                    {
                                        Ls2[i][k].Ndesc++;
                                        k = Ls2[i][k].PIDPos;
                                    }
                                    j++;
                                    int nextPidPos = Ls2[i].Count;
                                    while (j < ancestors.Length)
                                    {
                                        Item2 it = new Item2(ancestors[j]);
                                        it.PIDPos = pidPos;
                                        it.Ndesc++;
                                        Ls2[i].Add(it);
                                        pidPos = nextPidPos;
                                        nextPidPos++;
                                        j++;
                                    }
                                }
                            }
                            else
                            {
                                if (k == -1 && !goThrough)
                                {
                                    j = 0;
                                    int pidPos = -1;
                                    while (j < ancestors.Length)
                                    {
                                        Item2 it = new Item2(ancestors[j]);
                                        it.Ndesc++;
                                        it.PIDPos = pidPos;
                                        pidPos++;
                                        Ls2[i].Add(it);
                                        j++;
                                    }
                                }
                                else
                                {
                                    throw new Exception(String.Format("Something won't happen happened, j={0}, k={1}, goThrough={2}", j, k, goThrough));
                                }
                            }
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    depth--;
                    parentsLinks.Pop();
                    break;
                }
            }
            sort();
        }