Beispiel #1
0
        public void AddChild(codeLocation loc) //Recursive Implementation [be careful!]
        {

            if (this.children.Count == 0)
            {
                if (loc.code.Equals("x"))
                {
                    codeLocation locLeft = new codeLocation();
                    locLeft.code = "-";
                    locLeft.codeRef = loc.codeRef;
                    locLeft.wordRef = loc.wordRef;
                    locLeft.word = loc.word;
                    patternTree childLeft = new patternTree(locLeft);
                    children.Add(childLeft);
                    codeLocation locRight = new codeLocation();
                    locRight.code = "=";
                    locRight.codeRef = loc.codeRef;
                    locRight.wordRef = loc.wordRef;
                    locRight.word = loc.word;
                    patternTree childRight = new patternTree(locRight);
                    children.Add(childRight);
                }
                else
                {
                    patternTree child = new patternTree(loc);
                    children.Add(child);
                }
            }
            else
            {
                for (int i = 0; i < this.children.Count; i++)
                    this.children[i].AddChild(loc);
            }
        }
Beispiel #2
0
 public void AddChild(codeLocation loc) //Recursive Implementation [be careful!]
 {
     if (this.children.Count == 0)
     {
         if (loc.code.Equals("x"))
         {
             codeLocation locLeft = new codeLocation();
             locLeft.code    = "-";
             locLeft.codeRef = loc.codeRef;
             locLeft.wordRef = loc.wordRef;
             locLeft.word    = loc.word;
             patternTree childLeft = new patternTree(locLeft);
             children.Add(childLeft);
             codeLocation locRight = new codeLocation();
             locRight.code    = "=";
             locRight.codeRef = loc.codeRef;
             locRight.wordRef = loc.wordRef;
             locRight.word    = loc.word;
             patternTree childRight = new patternTree(locRight);
             children.Add(childRight);
         }
         else
         {
             patternTree child = new patternTree(loc);
             children.Add(child);
         }
     }
     else
     {
         for (int i = 0; i < this.children.Count; i++)
         {
             this.children[i].AddChild(loc);
         }
     }
 }
Beispiel #3
0
        private List <scanPath> getCode(scanPath scn)
        {
            List <scanPath> mainList = new List <scanPath>();

            if (this.children.Count > 0)
            {
                codeLocation wordCode = new codeLocation();
                for (int k = 0; k < this.children.Count; k++)
                {
                    scanPath scpath = new scanPath();
                    for (int i = 0; i < scn.location.Count; i++)
                    {
                        scpath.location.Add(scn.location[i]);
                    }

                    scpath.location.Add(this.children[k].location);
                    List <scanPath> temp;
                    temp = new List <scanPath>();
                    temp = this.children[k].getCode(scpath);

                    for (int i = 0; i < temp.Count; i++)
                    {
                        mainList.Add(temp[i]);
                    }
                    // scn.location.Add(this.children[k].location);
                }
            }
            else  //tree leaf
            {
                mainList.Add(scn);
            }
            return(mainList);
        }
Beispiel #4
0
        public void AddChild(codeLocation loc) //Recursive Implementation [be careful!]
        {

            if (this.children.Count > 0)
            {
                if (this.children[0].location.wordRef == loc.wordRef)
                {
                    bool flag = false;
                    for (int i = 0; i < this.children.Count; i++)
                    {
                        if (loc.codeRef == this.children[i].location.codeRef)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        CodeTree child = new CodeTree(loc);
                        child.errorParam = errorParam;
                        this.children.Add(child);
                    }
                }
                else
                {
                    for (int i = 0; i < this.children.Count; i++)
                    {
                        this.children[i].errorParam = errorParam;
                        this.children[i].AddChild(loc);
                    }
                }
            }
            else
            {
                if (this.location.wordRef == loc.wordRef - 1)
                {
                    CodeTree child = new CodeTree(loc);
                    child.errorParam = errorParam;
                    children.Add(child);
                }
            }
        }
Beispiel #5
0
 public void AddChild(codeLocation loc) //Recursive Implementation [be careful!]
 {
     if (this.children.Count > 0)
     {
         if (this.children[0].location.wordRef == loc.wordRef)
         {
             bool flag = false;
             for (int i = 0; i < this.children.Count; i++)
             {
                 if (loc.codeRef == this.children[i].location.codeRef)
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 CodeTree child = new CodeTree(loc);
                 child.errorParam = errorParam;
                 this.children.Add(child);
             }
         }
         else
         {
             for (int i = 0; i < this.children.Count; i++)
             {
                 this.children[i].errorParam = errorParam;
                 this.children[i].AddChild(loc);
             }
         }
     }
     else
     {
         if (this.location.wordRef == loc.wordRef - 1)
         {
             CodeTree child = new CodeTree(loc);
             child.errorParam = errorParam;
             children.Add(child);
         }
     }
 }
Beispiel #6
0
 public patternTree(codeLocation loc)
 {
     location = new codeLocation();
     location = loc;
     children = new List<patternTree>();
 }
Beispiel #7
0
        private List<scanPath> getCode(scanPath scn)
        {
            List<scanPath> mainList = new List<scanPath>();
            if (this.children.Count > 0)
            {
                codeLocation wordCode = new codeLocation();
                for (int k = 0; k < this.children.Count; k++)
                {
                    scanPath scpath = new scanPath();
                    for (int i = 0; i < scn.location.Count; i++)
                        scpath.location.Add(scn.location[i]);

                    scpath.location.Add(this.children[k].location);
                    List<scanPath> temp;
                    temp = new List<scanPath>();
                    temp = this.children[k].getCode(scpath);

                    for (int i = 0; i < temp.Count; i++)
                        mainList.Add(temp[i]);
                    // scn.location.Add(this.children[k].location);
                }
            }
            else  //tree leaf
            {
                mainList.Add(scn);
            }
            return mainList;
        }
Beispiel #8
0
        public List<scanPath> findMeter(List<int> meters)
        {
            bool flag = false;
            List<int> indices = new List<int>();
            if (meters.Count == 0)
            {
                for (int i = 0; i < Meters.numMeters; i++)
                {
                    if (Meters.usage[i] == 1)
                    {
                        indices.Add(i);
                    }
                }
                for (int i = 0; i < Meters.numMeters; i++)
                {
                    if (Meters.usage[i] == 0)
                    {
                        indices.Add(i);
                    }
                }
                for (int i = Meters.numMeters; i < Meters.numMeters + Meters.numRubaiMeters; i++)
                {
                    indices.Add(i);
                }
            }
            else
            {
                if (meters[0] == -2)
                {
                    for (int i = Meters.numMeters; i < Meters.numMeters + Meters.numRubaiMeters; i++)
                    {
                        indices.Add(i);
                    }
                }
                else
                {
                    for (int i = 0; i < meters.Count; i++)
                    {
                        if (meters[i] != -1)
                        {
                            indices.Add(meters[i]);
                        }
                        else
                        {
                            flag = true;
                        }

                    }
                }
            }
           
            //indices.Add(27);
            //indices.Add(18);
            List<scanPath> mainList = new List<scanPath>();
            List<scanPath> a = new List<scanPath>();
            List<scanPath> b = new List<scanPath>();
            scanPath scn = new scanPath();
            scn.meters = indices;
            scn.location.Add(new codeLocation());


            if (fuzzy)
            {
                mainList = traverseFuzzy(scn);
                //mainList = traverseFreeVerse(scn);
            }
            else if(freeVerse)
            {
                mainList = traverseFreeVerse(scn);
            }
            else
            {
                mainList = traverse(scn);
                //mainList = traverseFreeVerse(scn);

                if (flag || (meters.Count == 0))
                {
                    List<string> codeList = new List<string>();
                    a = getCode(scn);
                    codeLocation locs = new codeLocation();
                    locs.code = "root";
                    locs.word = "";
                    locs.wordRef = -1;
                    locs.codeRef = -1;
                    for (int i = 0; i < a.Count; i++)
                    {
                        patternTree pTree = new patternTree(locs);
                        for (int j = 0; j < a[i].location.Count; j++)
                        {
                            for (int k = 0; k < a[i].location[j].code.Length; k++)
                            {
                                codeLocation locn = new codeLocation();
                                locn.codeRef = a[i].location[j].codeRef;
                                locn.word = a[i].location[j].word;
                                locn.wordRef = a[i].location[j].wordRef;
                                locn.code = a[i].location[j].code[k].ToString();
                                if (j == a[i].location.Count - 1)
                                {
                                    if (k == a[i].location[j].code.Length - 1)
                                        if (locn.code.Equals("x"))
                                        {
                                            locn.code = "=";
                                        }
                                }
                                pTree.AddChild(locn);
                            }
                        }
                        b = pTree.isMatch();
                        if (b.Count > 0)
                        {
                            b = compressList(b);
                            for (int n = 0; n < b.Count; n++)
                                mainList.Add(b[n]);
                        }
                    }
                }
            }
            return mainList;
        }
Beispiel #9
0
        private List<scanPath> compressList(List<scanPath> lst)
        {
            List<scanPath> list = new List<scanPath>();
            for (int i = 0; i < lst.Count; i++)
            {
                scanPath sc = new scanPath();
                sc.meters = lst[i].meters;
                int j;
                string code = "";
                for (j = 0; j < lst[i].location.Count - 1; j++)
                {
                    if (j == 0) //first redundant element
                    {
                        codeLocation L = new codeLocation();
                        L.codeRef = -1;
                        L.word = "root";
                        L.wordRef = -1;
                        code += "";
                        L.code = code;
                        code = "";
                        sc.location.Add(L);
                    }
                    int wordRef = lst[i].location[j].wordRef;
                    if (wordRef == lst[i].location[j + 1].wordRef)
                    {
                        code += lst[i].location[j].code;
                    }
                    else
                    {
                        codeLocation cL = new codeLocation();
                        cL.codeRef = lst[i].location[j].codeRef;
                        cL.word = lst[i].location[j].word;
                        cL.wordRef = lst[i].location[j].wordRef;
                        code += lst[i].location[j].code;
                        cL.code = code;
                        code = "";
                        sc.location.Add(cL);
                    }
                }

                int wordRef2 = lst[i].location[j - 1].wordRef;
                if (wordRef2 == lst[i].location[lst[i].location.Count - 1].wordRef)
                {
                    code += lst[i].location[j].code;
                }
                else
                {
                    code = lst[i].location[j].code;
                }

                codeLocation cL2 = new codeLocation();
                cL2.codeRef = lst[i].location[j].codeRef;
                cL2.word = lst[i].location[j].word;
                cL2.wordRef = lst[i].location[j].wordRef;
                cL2.code = code;

                sc.location.Add(cL2);
                list.Add(sc);
            }
            return list;

        }
Beispiel #10
0
 public CodeTree(codeLocation loc)
 {
     location = new codeLocation();
     location = loc;
     children = new List<CodeTree>();
 }
Beispiel #11
0
        public List <scanPath> findMeter(List <int> meters)
        {
            bool       flag    = false;
            List <int> indices = new List <int>();

            if (meters.Count == 0)
            {
                for (int i = 0; i < Meters.numMeters; i++)
                {
                    if (Meters.usage[i] == 1)
                    {
                        indices.Add(i);
                    }
                }
                for (int i = 0; i < Meters.numMeters; i++)
                {
                    if (Meters.usage[i] == 0)
                    {
                        indices.Add(i);
                    }
                }
                for (int i = Meters.numMeters; i < Meters.numMeters + Meters.numRubaiMeters; i++)
                {
                    indices.Add(i);
                }
            }
            else
            {
                if (meters[0] == -2)
                {
                    for (int i = Meters.numMeters; i < Meters.numMeters + Meters.numRubaiMeters; i++)
                    {
                        indices.Add(i);
                    }
                }
                else
                {
                    for (int i = 0; i < meters.Count; i++)
                    {
                        if (meters[i] != -1)
                        {
                            indices.Add(meters[i]);
                        }
                        else
                        {
                            flag = true;
                        }
                    }
                }
            }

            //indices.Add(27);
            //indices.Add(18);
            List <scanPath> mainList = new List <scanPath>();
            List <scanPath> a        = new List <scanPath>();
            List <scanPath> b        = new List <scanPath>();
            scanPath        scn      = new scanPath();

            scn.meters = indices;
            scn.location.Add(new codeLocation());


            if (fuzzy)
            {
                mainList = traverseFuzzy(scn);
                //mainList = traverseFreeVerse(scn);
            }
            else if (freeVerse)
            {
                mainList = traverseFreeVerse(scn);
            }
            else
            {
                mainList = traverse(scn);
                //mainList = traverseFreeVerse(scn);

                if (flag || (meters.Count == 0))
                {
                    List <string> codeList = new List <string>();
                    a = getCode(scn);
                    codeLocation locs = new codeLocation();
                    locs.code    = "root";
                    locs.word    = "";
                    locs.wordRef = -1;
                    locs.codeRef = -1;
                    for (int i = 0; i < a.Count; i++)
                    {
                        patternTree pTree = new patternTree(locs);
                        for (int j = 0; j < a[i].location.Count; j++)
                        {
                            for (int k = 0; k < a[i].location[j].code.Length; k++)
                            {
                                codeLocation locn = new codeLocation();
                                locn.codeRef = a[i].location[j].codeRef;
                                locn.word    = a[i].location[j].word;
                                locn.wordRef = a[i].location[j].wordRef;
                                locn.code    = a[i].location[j].code[k].ToString();
                                if (j == a[i].location.Count - 1)
                                {
                                    if (k == a[i].location[j].code.Length - 1)
                                    {
                                        if (locn.code.Equals("x"))
                                        {
                                            locn.code = "=";
                                        }
                                    }
                                }
                                pTree.AddChild(locn);
                            }
                        }
                        b = pTree.isMatch();
                        if (b.Count > 0)
                        {
                            b = compressList(b);
                            for (int n = 0; n < b.Count; n++)
                            {
                                mainList.Add(b[n]);
                            }
                        }
                    }
                }
            }
            return(mainList);
        }
Beispiel #12
0
        private List <scanPath> compressList(List <scanPath> lst)
        {
            List <scanPath> list = new List <scanPath>();

            for (int i = 0; i < lst.Count; i++)
            {
                scanPath sc = new scanPath();
                sc.meters = lst[i].meters;
                int    j;
                string code = "";
                for (j = 0; j < lst[i].location.Count - 1; j++)
                {
                    if (j == 0) //first redundant element
                    {
                        codeLocation L = new codeLocation();
                        L.codeRef = -1;
                        L.word    = "root";
                        L.wordRef = -1;
                        code     += "";
                        L.code    = code;
                        code      = "";
                        sc.location.Add(L);
                    }
                    int wordRef = lst[i].location[j].wordRef;
                    if (wordRef == lst[i].location[j + 1].wordRef)
                    {
                        code += lst[i].location[j].code;
                    }
                    else
                    {
                        codeLocation cL = new codeLocation();
                        cL.codeRef = lst[i].location[j].codeRef;
                        cL.word    = lst[i].location[j].word;
                        cL.wordRef = lst[i].location[j].wordRef;
                        code      += lst[i].location[j].code;
                        cL.code    = code;
                        code       = "";
                        sc.location.Add(cL);
                    }
                }

                int wordRef2 = lst[i].location[j - 1].wordRef;
                if (wordRef2 == lst[i].location[lst[i].location.Count - 1].wordRef)
                {
                    code += lst[i].location[j].code;
                }
                else
                {
                    code = lst[i].location[j].code;
                }

                codeLocation cL2 = new codeLocation();
                cL2.codeRef = lst[i].location[j].codeRef;
                cL2.word    = lst[i].location[j].word;
                cL2.wordRef = lst[i].location[j].wordRef;
                cL2.code    = code;

                sc.location.Add(cL2);
                list.Add(sc);
            }
            return(list);
        }
Beispiel #13
0
 public CodeTree(codeLocation loc)
 {
     location = new codeLocation();
     location = loc;
     children = new List <CodeTree>();
 }
Beispiel #14
0
 public patternTree(codeLocation loc)
 {
     location = new codeLocation();
     location = loc;
     children = new List <patternTree>();
 }