public void UpdateValue_KeyNotInDictionary_UpdateIntialValue()
        {
            const int key = 1;

            _target.UpdateValue(key, l => {
                l.Add("wow");
                return(l);
            },
                                new List <string>());

            Assert.That(_target[key], Has.Count.EqualTo(1));
            Assert.That(_target[key][0], Is.EqualTo("wow"));
        }
Beispiel #2
0
		public void Increment(TSample sample, int count)
		{
			if (count == 0)
				return;

			_sampleCounts.UpdateValue(sample, () => 0, c => c + count);
			SampleOutcomeCount += count;
		}
Beispiel #3
0
        public void UpdateValue_Arguments()
        {
            IDictionary <string, int> s = null;

            Assert.Throws <ArgumentNullException>(() => s.UpdateValue("key", v => v));
            s = new Dictionary <string, int> ();
            Assert.Throws <ArgumentNullException>(() => s.UpdateValue("key", null));
        }
Beispiel #4
0
 /// <summary>
 /// Notifies this analysis that the specified morphological rule was unapplied.
 /// </summary>
 /// <param name="mrule">The morphological rule.</param>
 /// <param name="realizational"> </param>
 internal void MorphologicalRuleUnapplied(IMorphologicalRule mrule, bool realizational)
 {
     CheckFrozen();
     _mrulesUnapplied.UpdateValue(mrule, () => 0, count => count + 1);
     if (!realizational)
     {
         _mrules.Push(mrule);
     }
 }
Beispiel #5
0
        public void Collect(TraversalState traversalState)
        {
            if (traversalState.CurrentInstance.IsModule())
            {
                return;
            }

            _result.UpdateValue(traversalState.CurrentInstance.ModuleName, count => ++ count, 0);
        }
Beispiel #6
0
        public void Collect(Instance instance)
        {
            if (instance.IsModule())
            {
                return;
            }

            _result.UpdateValue(instance.ModuleName,
                                i => instance.Net.Count <= i.Net.Count ? i : instance,
                                instance);
        }
Beispiel #7
0
 /// <summary>
 /// Notifies this word that the specified morphological rule was unapplied. Null
 /// indicates that an unknown compounding rule was unapplied. This is used when
 /// generating a compound word, because the compounding rule is usually not known just
 /// the non-head allomorph.
 /// </summary>
 internal void MorphologicalRuleUnapplied(IMorphologicalRule mrule)
 {
     CheckFrozen();
     if (mrule != null)
     {
         _mrulesUnapplied.UpdateValue(mrule, () => 0, count => count + 1);
     }
     if (!(mrule is RealizationalAffixProcessRule))
     {
         _mruleApps.Add(mrule);
         _mruleAppIndex++;
     }
 }
Beispiel #8
0
        private void WriteNgramCountsFile(string lmPrefix, int ngramSize)
        {
            int wordCount = 0;
            var ngrams    = new Dictionary <Ngram <string>, int>();
            var vocab     = new HashSet <string>();

            foreach (TextSegment segment in _parallelCorpus.TargetSegments
                     .Where((s, i) => !_tuneCorpusIndices.Contains(i) && !s.IsEmpty))
            {
                var words = new List <string> {
                    "<s>"
                };
                foreach (string word in segment.Segment.Preprocess(_targetPreprocessor))
                {
                    if (vocab.Contains(word))
                    {
                        words.Add(word);
                    }
                    else
                    {
                        vocab.Add(word);
                        words.Add("<unk>");
                    }
                }
                words.Add("</s>");
                if (words.Count == 2)
                {
                    continue;
                }
                wordCount += words.Count;
                for (int n = 1; n <= ngramSize; n++)
                {
                    for (int i = 0; i <= words.Count - n; i++)
                    {
                        var ngram = new Ngram <string>(Enumerable.Range(i, n).Select(j => words[j]));
                        ngrams.UpdateValue(ngram, () => 0, c => c + 1);
                    }
                }
            }

            using (var writer = new StreamWriter(lmPrefix))
            {
                foreach (KeyValuePair <Ngram <string>, int> kvp in ngrams.OrderBy(kvp => kvp.Key.Length)
                         .ThenBy(kvp => string.Join(" ", kvp.Key)))
                {
                    writer.Write("{0} {1} {2}\n", string.Join(" ", kvp.Key),
                                 kvp.Key.Length == 1 ? wordCount : ngrams[kvp.Key.TakeAllExceptLast()], kvp.Value);
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// Notifies this word synthesis that the specified morphological rule has applied.
 /// </summary>
 internal void MorphologicalRuleApplied(IMorphologicalRule mrule)
 {
     CheckFrozen();
     if (IsMorphologicalRuleApplicable(mrule))
     {
         _mruleAppIndex--;
     }
     // indicate that the current non-head was applied if this is a compounding rule
     if (mrule is CompoundingRule)
     {
         _nonHeadAppIndex--;
     }
     _mrulesApplied.UpdateValue(mrule, () => 0, count => count + 1);
 }
Beispiel #10
0
 public void UpdateValue()
 {
     #region UpdateValue
     var words = new[] {
         "Count",
         "the",
         "the",
         "repeated",
         "words",
     };
     var wordCounts = new Dictionary <string, int> ();
     foreach (var word in words)
     {
         int c;
         wordCounts.TryGetValue(word, out c);
         Assert.AreEqual(c + 1, wordCounts.UpdateValue(word, v => v + 1));
     }
     Assert.AreEqual(4, wordCounts.Count);
     Assert.AreEqual(1, wordCounts ["Count"]);
     Assert.AreEqual(2, wordCounts ["the"]);
     Assert.AreEqual(1, wordCounts ["repeated"]);
     Assert.AreEqual(1, wordCounts ["words"]);
     #endregion
 }
Beispiel #11
0
 /// <summary>
 /// Notifies this word synthesis that the specified morphological rule has applied.
 /// </summary>
 internal void MorphologicalRuleApplied(IMorphologicalRule mrule)
 {
     CheckFrozen();
     _mrulesApplied.UpdateValue(mrule, () => 0, count => count + 1);
 }
Beispiel #12
0
 public void UpdateValue_Arguments()
 {
     IDictionary<string, int> s = null;
     Assert.Throws<ArgumentNullException>(() => s.UpdateValue ("key", v => v));
     s = new Dictionary<string, int> ();
     Assert.Throws<ArgumentNullException>(() => s.UpdateValue ("key", null));
 }
Beispiel #13
0
 public void UpdateValue()
 {
     #region UpdateValue
     var words = new[]{
         "Count",
         "the",
         "the",
         "repeated",
         "words",
     };
     var wordCounts = new Dictionary<string, int> ();
     foreach (var word in words) {
         int c;
         wordCounts.TryGetValue (word, out c);
         Assert.AreEqual (c + 1, wordCounts.UpdateValue (word, v => v + 1));
     }
     Assert.AreEqual (4, wordCounts.Count);
     Assert.AreEqual (1, wordCounts ["Count"]);
     Assert.AreEqual (2, wordCounts ["the"]);
     Assert.AreEqual (1, wordCounts ["repeated"]);
     Assert.AreEqual (1, wordCounts ["words"]);
     #endregion
 }