Beispiel #1
0
        public void TestSingleAttribute()
        {
            var index = new WordIndex();

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[0]));

            index.Add("w2", "attr1");
            index.Add("w1", "attr1");
            index.Add("w3", "attr1");

            Assert.Throws<ArgumentException>(() => index.Add("w1", "attr1"));

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] {"attr1"}));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] {"w1", "w2", "w3"}));

            Assert.Throws<KeyNotFoundException>(() => index.Remove("wX", "attr1"));
            Assert.Throws<KeyNotFoundException>(() => index.Remove("w1", "attrX"));

            index.Remove("w2", "attr1");
            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] {"attr1"}));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] {"w1", "w3"}));

            index.Remove("w1", "attr1");
            index.Remove("w3", "attr1");
            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[0]));
        }
Beispiel #2
0
        public void TestUpdate()
        {
            var index = new WordIndex();

            index.Update(null, new List<string>(), "w1", new List<string> {"attr1"});

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] {"attr1"}));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] {"w1"}));

            index.Update("w1", new List<string> {"attr1"}, "w1", new List<string> {"attr2", "attr3"});

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] {"attr2", "attr3"}));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr2"), Is.EquivalentTo(new string[] {"w1"}));
            Assert.That(index.GetWordNames("attr3"), Is.EquivalentTo(new string[] {"w1"}));

            index.Update("w1", new List<string> {"attr2", "attr3"}, "w2", new List<string> {"attr3", "attr1"});

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] {"attr1", "attr3"}));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] {"w2"}));
            Assert.That(index.GetWordNames("attr2"), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr3"), Is.EquivalentTo(new string[] {"w2"}));
        }
Beispiel #3
0
 public IEnumerable <WordInfo> GetWordsWithTag(string tag)
 {
     return(tagIndex.GetWordNames(tag).Select(wordName => wordsByName[wordName]));
 }
Beispiel #4
0
 public IEnumerable <WordInfo> GetWordsWithTranslation(string translation)
 {
     return(translationIndex.GetWordNames(translation).Select(wordName => wordsByName[wordName]));
 }