public IList <WNode> ConjugateLoosely(WNode node, string cform) { var i = cform.IndexOf('-'); var loose_cform = (i >= 0) ? cform.Substring(0, i) : cform; return(Conjugate(node, n => { var f = n.CForm; return f.StartsWith(loose_cform) && (f.Length == loose_cform.Length || f[loose_cform.Length] == '-') && n.CType == node.CType && n.OrthBase == node.OrthBase; })); }
private IList <WNode> Conjugate(WNode node, Func <WNode, bool> chooser) { if (!ConjugationTable.TryGetValue(node.Lemma_id, out var list)) { return(null); } list = list.Where(n => n.Surface != null && chooser(n)).ToList(); if (list.Count == 0) { return(null); } return(list); }
public WNode[] ChooseBest(IList <IList <WNode> > nodes) { var paths = new Path[nodes.Count][]; paths[0] = new Path[nodes[0].Count]; for (int i = 0; i < paths[0].Length; i++) { paths[0][i].Cost = nodes[0][i].WCost * (1 - CostMixFactor); } for (int p = 1; p < nodes.Count; p++) { paths[p] = new Path[nodes[p].Count]; for (int i = 0; i < paths[p].Length; i++) { double min_cost = double.MaxValue; for (int j = 0; j < paths[p - 1].Length; j++) { double cost = paths[p - 1][j].Cost + Dictionaries.MixedCostIncrease(CostMixFactor, nodes[p - 1][j], nodes[p][i]); if (cost < min_cost) { paths[p][i].Previous = j; min_cost = cost; } } paths[p][i].Cost = min_cost; } } var result = new WNode[nodes.Count]; var best_path = default(Path); // XXX int best_index = 0; for (int i = 0; i < paths[paths.Length - 1].Length; i++) { if (paths[paths.Length - 1][i].Cost < best_path.Cost) { best_path = paths[paths.Length - 1][i]; best_index = i; } } result[paths.Length - 1] = nodes[nodes.Count - 1][best_index]; int previous = paths[paths.Length - 1][best_index].Previous; for (int p = paths.Length - 2; p >= 0; --p) { result[p] = nodes[p][previous]; previous = paths[p][previous].Previous; } return(result); }
public IList <WNode> ConjugateStrictly(WNode node, string cform) { return(Conjugate(node, n => n.CForm == cform && n.CType == node.CType && n.OrthBase == node.OrthBase)); }