//goal = (Edge)interner.intern(goal); protected internal virtual void Initialize <_T0>(IList <_T0> words) where _T0 : IHasWord { length = words.Count; interner = new Interner(); agenda = new ArrayHeap <Item>(ScoredComparator.DescendingComparator); chart = new HookChart(); SetGoal(length); IList <Item> initialItems = MakeInitialItems(words); // scoreDependencies(); foreach (Item item in initialItems) { item = (Item)interner.Intern(item); //if (VERBOSE) log.info("Initial: "+item); DiscoverItem(item); } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.TypeLoadException"/> private void ReadObject(ObjectInputStream ois) { ois.DefaultReadObject(); // reinitialize the transient objects itwInterner = new Interner <IntTaggedWord>(); }
/// <summary>Parse a Sentence.</summary> /// <returns>true iff it could be parsed</returns> public virtual bool Parse <_T0>(IList <_T0> words) where _T0 : IHasWord { int nGoodRemaining = 0; if (op.testOptions.printFactoredKGood > 0) { nGoodRemaining = op.testOptions.printFactoredKGood; nGoodTrees.Clear(); } int spanFound = 0; long last = 0; int exHook = 0; relaxHook1 = 0; relaxHook2 = 0; relaxHook3 = 0; relaxHook4 = 0; builtHooks = 0; builtEdges = 0; extractedHooks = 0; extractedEdges = 0; if (op.testOptions.verbose) { Timing.Tick("Starting combined parse."); } dparser.binDistance = dparser.binDistance; // THIS IS TERRIBLE, BUT SAVES MEMORY Initialize(words); while (!agenda.IsEmpty()) { Item item = agenda.ExtractMin(); if (!item.IsEdge()) { exHook++; extractedHooks++; } else { extractedEdges++; } if (relaxHook1 > last + 1000000) { last = relaxHook1; if (op.testOptions.verbose) { log.Info("Proposed hooks: " + relaxHook1); log.Info("Unfiltered hooks: " + relaxHook2); log.Info("Built hooks: " + relaxHook3); log.Info("Waste hooks: " + relaxHook4); log.Info("Extracted hooks: " + exHook); } } if (item.end - item.start > spanFound) { spanFound = item.end - item.start; if (op.testOptions.verbose) { log.Info(spanFound + " "); } } //if (item.end < 5) log.info("Extracted: "+item+" iScore "+item.iScore+" oScore "+item.oScore+" score "+item.score()); if (item.Equals(goal)) { if (op.testOptions.verbose) { log.Info("Found goal!"); log.Info("Comb iScore " + item.iScore); // was goal.iScore Timing.Tick("Done, parse found."); log.Info("Built items: " + (builtEdges + builtHooks)); log.Info("Built hooks: " + builtHooks); log.Info("Built edges: " + builtEdges); log.Info("Extracted items: " + (extractedEdges + extractedHooks)); log.Info("Extracted hooks: " + extractedHooks); log.Info("Extracted edges: " + extractedEdges); } //postMortem(); if (op.testOptions.printFactoredKGood <= 0) { goal = (Edge)item; interner = null; agenda = null; return(true); } else { // Store the parse goal = (Edge)item; nGoodTrees.Add(goal); nGoodRemaining--; if (nGoodRemaining > 0) { } else { interner = null; agenda = null; return(true); } } } // Is the currently best item acceptable at all? if (item.Score() == double.NegativeInfinity) { // Do not report failure in nGood mode if we found something earlier. if (nGoodTrees.Count > 0) { goal = nGoodTrees[0]; interner = null; agenda = null; return(true); } log.Info("FactoredParser: no consistent parse [hit A*-blocked edges, aborting]."); if (op.testOptions.verbose) { Timing.Tick("FactoredParser: no consistent parse [hit A*-blocked edges, aborting]."); } return(false); } // Keep the number of items from getting too large if (op.testOptions.MaxItems > 0 && (builtEdges + builtHooks) >= op.testOptions.MaxItems) { // Do not report failure in kGood mode if we found something earlier. if (nGoodTrees.Count > 0) { log.Info("DEBUG: aborting search because of reaching the MAX_ITEMS work limit [" + op.testOptions.MaxItems + " items]"); goal = nGoodTrees[0]; interner = null; agenda = null; return(true); } log.Info("FactoredParser: exceeded MAX_ITEMS work limit [" + op.testOptions.MaxItems + " items]; aborting."); if (op.testOptions.verbose) { Timing.Tick("FactoredParser: exceeded MAX_ITEMS work limit [" + op.testOptions.MaxItems + " items]; aborting."); } return(false); } if (Verbose && item.Score() != double.NegativeInfinity) { System.Console.Error.Printf("Removing from agenda: %s score i %.2f + o %.2f = %.2f\n", item, item.iScore, item.oScore, item.Score()); if (item.backEdge != null) { log.Info(" Backtrace: " + item.backEdge.ToString() + " " + (item.IsEdge() ? (((Edge)item).backHook != null ? ((Edge)item).backHook.ToString() : string.Empty) : string.Empty)); } } ProcessItem(item); } // end while agenda is not empty // If we are here, the agenda is empty. // Do not report failure if we found something earlier. if (nGoodTrees.Count > 0) { log.Info("DEBUG: aborting search because of empty agenda"); goal = nGoodTrees[0]; interner = null; agenda = null; return(true); } log.Info("FactoredParser: emptied agenda, no parse found!"); if (op.testOptions.verbose) { Timing.Tick("FactoredParser: emptied agenda, no parse found!"); } return(false); }