protected internal virtual void MakeBlock(ICollection <TransducerGraph.Arc> members) { ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> block = new ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>(Generics.NewHashSet(members)); foreach (TransducerGraph.Arc member in block.GetMembers()) { if (member != SinkNode) { memberToBlock[member] = block; } } foreach (object o in GetSymbols()) { TransducerGraph.Arc symbol = (TransducerGraph.Arc)o; AddActivePair(new Pair <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, TransducerGraph.Arc>(block, symbol)); } }
/// <summary>For testing only.</summary> /// <remarks>For testing only. Doubles combined by addition.</remarks> public virtual double GetOutputOfPathInGraph(IList path) { double score = 0.0; object node = GetStartNode(); foreach (object input in path) { TransducerGraph.Arc arc = GetArcBySourceAndInput(node, input); // next input in path if (arc == null) { System.Console.Out.WriteLine(" NOT ACCEPTED :" + path); return(double.NegativeInfinity); } score += ((double)arc.GetOutput()); node = arc.GetTargetNode(); } return(score); }
protected internal virtual void AddSplits(FastExactAutomatonMinimizer.Block block) { IDictionary symbolToTarget = new Hashtable(); foreach (object member in block.GetMembers()) { foreach (object o in GetInverseArcs(member)) { TransducerGraph.Arc arc = (TransducerGraph.Arc)o; object symbol = arc.GetInput(); object target = arc.GetTargetNode(); Maps.PutIntoValueArrayList(symbolToTarget, symbol, target); } } foreach (object symbol_1 in symbolToTarget.Keys) { AddSplit(new FastExactAutomatonMinimizer.Split((IList)symbolToTarget[symbol_1], symbol_1, block)); } }
protected internal virtual ICollection GetInverseImages(FastExactAutomatonMinimizer.Split split) { IList inverseImages = new ArrayList(); object symbol = split.GetSymbol(); FastExactAutomatonMinimizer.Block block = split.GetBlock(); foreach (object member in split.GetMembers()) { if (!block.GetMembers().Contains(member)) { continue; } ICollection arcs = GetInverseArcs(member, symbol); foreach (object arc1 in arcs) { TransducerGraph.Arc arc = (TransducerGraph.Arc)arc1; object source = arc.GetSourceNode(); inverseImages.Add(source); } } return(inverseImages); }
/// <summary>Takes time linear in number of arcs.</summary> public static ClassicCounter ComputeLambda(TransducerGraph graph) { ArrayList queue = new ArrayList(); ClassicCounter lambda = new ClassicCounter(); ClassicCounter length = new ClassicCounter(); IDictionary first = new Hashtable(); ISet nodes = graph.GetNodes(); foreach (object node in nodes) { lambda.SetCount(node, 0); length.SetCount(node, double.PositiveInfinity); } ISet endNodes = graph.GetEndNodes(); foreach (object o in endNodes) { lambda.SetCount(o, 0); length.SetCount(o, 0); queue.AddLast(o); } // Breadth first search // get the first node from the queue object node_1 = null; try { node_1 = queue.RemoveFirst(); } catch (NoSuchElementException) { } while (node_1 != null) { double oldLen = length.GetCount(node_1); ISet arcs = graph.GetArcsByTarget(node_1); if (arcs != null) { foreach (object arc1 in arcs) { TransducerGraph.Arc arc = (TransducerGraph.Arc)arc1; object newNode = arc.GetSourceNode(); IComparable a = (IComparable)arc.GetInput(); double k = ((double)arc.GetOutput()); double newLen = length.GetCount(newNode); if (newLen == double.PositiveInfinity) { // we are discovering this queue.AddLast(newNode); } IComparable f = (IComparable)first[newNode]; if (newLen == double.PositiveInfinity || (newLen == oldLen + 1 && a.CompareTo(f) < 0)) { // f can't be null, since we have a newLen // we do this to this to newNode when we have new info, possibly many times first[newNode] = a; // ejecting old one if necessary length.SetCount(newNode, oldLen + 1); // this may already be the case lambda.SetCount(newNode, k + lambda.GetCount(node_1)); } } } // get a new node from the queue node_1 = null; try { node_1 = queue.RemoveFirst(); } catch (NoSuchElementException) { } } return(lambda); }
protected internal Arc(TransducerGraph.Arc <NODE, IN, OUT> a) : this(a.GetSourceNode(), a.GetTargetNode(), a.GetInput(), a.GetOutput()) { }
/// <returns>true if and only if it created a new Arc and added it to the graph.</returns> public virtual bool AddArc(object source, object target, object input, object output) { TransducerGraph.Arc a = new TransducerGraph.Arc(source, target, input, output); return(AddArc(a)); }