Example #1
0
		private double GetProbability(Production production, Dictionary<Nonterminal, ICollection<Production>> productionsByNonterminal) {
			var sum = productionsByNonterminal.LookupEnumerable(production.Lhs).Sum((p) => p.Weight);
			return production.Weight / sum;
		}
Example #2
0
		private IEnumerable<Production> UnitReplacementProductions(Production unitProduction, Dictionary<Nonterminal, ICollection<Production>> productionsByNonterminal) {
			var retval = new List<Production>();

			var productions = productionsByNonterminal.LookupEnumerable((Nonterminal)unitProduction.Rhs[0]);
			var weightSum = productions.Sum((p) => p.Weight);

			foreach (var production in productions) {
				var productionProb = production.Weight / weightSum;
				var newWeight = unitProduction.Weight * productionProb;
				var newProduction = new Production(unitProduction.Lhs, production.Rhs, newWeight);
				if (newProduction.IsSelfLoop) {
					continue;
				}
				retval.Add(newProduction);
			}

			return retval;
		}