/// <summary> /// Adds the appropriate features for the token at the specified index with the /// specified array of previous outcomes to the specified list of features. /// </summary> /// <param name="features">The list of features to be added to.</param> /// <param name="tokens">The tokens of the sentence or other text unit being processed.</param> /// <param name="index">The index of the token which is currently being processed.</param> /// <param name="previousOutcomes">The outcomes for the tokens prior to the specified index.</param> public void CreateFeatures(List <string> features, string[] tokens, int index, string[] previousOutcomes) { List <string> cacheFeatures; if (tokens == prevTokens) { cacheFeatures = (List <string>)contextsCache.Get(index); if (cacheFeatures != null) { NumberOfCacheHits++; features.AddRange(cacheFeatures); return; } } else { contextsCache.Clear(); prevTokens = tokens; } cacheFeatures = new List <string>(); NumberOfCacheMisses++; generator.CreateFeatures(cacheFeatures, tokens, index, previousOutcomes); contextsCache.Put(index, cacheFeatures); features.AddRange(cacheFeatures); }
/// <summary> /// Adds the appropriate features for the token at the specified index with the /// specified array of previous outcomes to the specified list of features. /// </summary> /// <param name="features">The list of features to be added to.</param> /// <param name="tokens">The tokens of the sentence or other text unit being processed.</param> /// <param name="index">The index of the token which is currently being processed.</param> /// <param name="previousOutcomes">The outcomes for the tokens prior to the specified index.</param> public void CreateFeatures(List <string> features, string[] tokens, int index, string[] previousOutcomes) { generator.CreateFeatures(features, tokens, index, previousOutcomes); // previous features for (var i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { var prevFeatures = new List <string>(); generator.CreateFeatures(prevFeatures, tokens, index - i, previousOutcomes); foreach (var prevFeature in prevFeatures) { features.Add(PREV_PREFIX + i + prevFeature); } } } // next features for (var i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.Length) { var nextFeatures = new List <string>(); generator.CreateFeatures(nextFeatures, tokens, index + i, previousOutcomes); foreach (var nextFeature in nextFeatures) { features.Add(NEXT_PREFIX + i + nextFeature); } } } }