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); } }
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); } } }
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; }
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); }