public SentenceParser(RulesReader rr, ArrayList words) { // Initialize Lexicon //if(w!=null) //{ // Lexicon.tagged_only=w.tagged_only; // tagged_only=w.tagged_only; // threshold=w.threshold; // percent=w.percent; //} //else //{ Lexicon.tagged_only = false; tagged_only = false; threshold = 3; percent = 30; //} Words = words; for (int i = 0; i < words.Count; i++) { words[i] = ((string)words[i]).ToUpper(); } EdgesByStart = new ArrayList[words.Count]; for (int i = 0; i < EdgesByStart.Length; i++) { EdgesByStart[i] = new ArrayList(); } EdgesByEnd = new ArrayList[words.Count + 1]; for (int i = 0; i < EdgesByEnd.Length; i++) { EdgesByEnd[i] = new ArrayList(); } RR = rr; }
public RulesReader Minimize(Hashtable MissedCATs, int MaxIterations) { Hashtable KeyCount = new Hashtable(); foreach (string key in Keywords.Keys) { KeyCount.Add(key, ((ArrayList)Keywords[key]).Count); } ArrayList CurrentRules = Rules; Hashtable CurrentMissed = MissedCATs; for (int i = 0; i < MaxIterations && CurrentMissed.Count > 0; i++) { ArrayList NewRules = new ArrayList(); Hashtable AddedMissed = new Hashtable(); foreach (Rule r in CurrentRules) { bool ismissed = false; foreach (string missed in CurrentMissed.Keys) { if (r.RHS.Contains(missed)) { int nc = ((int)KeyCount[r.LHS]) - 1; KeyCount[r.LHS] = nc; ismissed = true; if (nc == 0) { AddedMissed.Add(r.LHS, null); } break; } } if (ismissed) { continue; } NewRules.Add(r); } CurrentRules = NewRules; CurrentMissed = AddedMissed; } RulesReader NewReader = new RulesReader(); NewReader.Rules = CurrentRules; NewReader.Keywords = new Hashtable(); for (int i = 0; i < CurrentRules.Count; i++) { Rule rl = (Rule)CurrentRules[i]; if (NewReader.Keywords.Contains(rl.LHS)) { ((ArrayList)NewReader.Keywords[rl.LHS]).Add(i); } else { NewReader.Keywords.Add(rl.LHS, new ArrayList(new int[] { i })); } } return(NewReader); }
private void Initialize() { int limit = 4; Edge edge = new Edge(); edge.Start = edge.End = 0; edge.Goal = "S'"; edge.Needed = new ArrayList(new string[] { "S" }); edge.Finished = new ArrayList(0); AddEdge(edge); Hashtable FoundCATs = new Hashtable(); ArrayList CurrEdges = null; for (int i = 0; i < Words.Count; i++) { CurrEdges = new ArrayList(); for (int j = 1; j + i <= Words.Count; j++) { string word = (string)Words[i]; for (int k = 1; k < j; k++) { word += "_" + Words[i + k]; } ArrayList CATs = Lexicon.GetCATs(word); if (j > 1 && CATs.Contains("VINF")) { CATs.Remove("VINF"); } if (j > limit)//(CATs==null || CATs.Count==0) )//&& ) { break; } /* * else if (CATs != null && CATs.Count != 0) * CurrEdges.Clear(); */ foreach (string cat in CATs) { edge = new Edge(); edge.Start = i; edge.End = i + j; edge.Goal = cat; edge.Needed = new ArrayList(0); CurrEdges.Add(edge); } } foreach (Edge e in CurrEdges) { AddEdge(e); if (!FoundCATs.Contains(e.Goal)) { FoundCATs.Add(e.Goal, null); } } } RR = RR.Minimize(Lexicon.GetDiff(FoundCATs), 2); RuleStarts = new BitArray[RR.Rules.Count]; for (int i = 0; i < RuleStarts.Length; i++) { RuleStarts[i] = new BitArray(Words.Count, false); } }