Exemple #1
0
 private void GenerateFeatures(string temp, List<string> inputSentance, int pos)
 {
     string[] tags = temp.Split(new char[] { ':' });
     if (tags.Length != 3)
     {
         throw new Exception(temp + " doesn't contain 3 tags");
     }
     var features = new Features(tags[0], tags[1], tags[2], inputSentance, pos);
     foreach (var feature in features.GetFeatures())
     {
         if (DictFeaturesToK.ContainsKey(feature))
             continue;
         DictFeaturesToK.Add(feature, _featureCount++);
     }
 }
 public float GetFeatureValue(string t2, string t1, string t, int pos, bool debug, out string debugStr)
 {
     var features = new Features(t2, t1, t, _sentence, pos);
     float sum = 0;
     debugStr = "@@";
     foreach (var feature in features.GetFeatures())
     {
         float weight = WeightVector.Get(feature);
         sum += weight;
         if (debug)
         {
             debugStr += feature + "#" + weight.ToString(CultureInfo.InvariantCulture) + "%%";
         }
     }
     debugStr += "@@";
     return sum;
 }
Exemple #3
0
        public IEnumerable<KeyValuePair<string, string>> NextFeature()
        {
            string t2 = "*", t1 = "*";
            for (; _pos < _sentence.Count; _pos++)
            {
                var t = _tags[_pos];
                if (_pos > 1)
                {
                    t2 = _tags[_pos - 2];
                    t1 = _tags[_pos - 1];
                }
                else if (_pos == 1)
                {
                    t1 = _tags[_pos - 1];
                }

                var features = new Features(t2, t1, t, _sentence, _pos);
                foreach (var f in features.GetFeatures())
                {
                    var pair = new KeyValuePair<string, string>(t, f);
                    yield return pair;
                }
            }
        }