public virtual void DoRandom(int iter, bool ignoreCase)
        {
            CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 1, ignoreCase);
            HashMap<string, int?> hmap = new HashMap<string, int?>();

            char[] key;
            for (int i = 0; i < iter; i++)
            {
                int len = Random().Next(5);
                key = new char[len];
                for (int j = 0; j < key.Length; j++)
                {
                    key[j] = (char)Random().Next(127);
                }
                string keyStr = new string(key);
                string hmapKey = ignoreCase ? keyStr.ToLower() : keyStr;

                int val = Random().Next();

                object o1 = map.Put(key, val);
                object o2 = hmap.Put(hmapKey, val);
                assertEquals(o1, o2);

                // add it again with the string method
                assertEquals(val, map.Put(keyStr, val));

                assertEquals(val, map.Get(key, 0, key.Length));
                assertEquals(val, map.Get(key));
                assertEquals(val, map.Get(keyStr));

                assertEquals(hmap.Count, map.size());
            }
        }
Esempio n. 2
0
        public virtual void doRandom(int iter, bool ignoreCase)
        {
            CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 1, ignoreCase);
            Dictionary<string, int?> hmap = new Dictionary<string, int?>();

            char[] key;
            for (int i = 0; i < iter; i++)
            {
              int len = random().Next(5);
              key = new char[len];
              for (int j = 0; j < key.Length; j++)
              {
            key[j] = (char)random().Next(127);
              }
              string keyStr = new string(key);
              string hmapKey = ignoreCase ? keyStr.ToLower(Locale.ROOT) : keyStr;

              int val = random().Next();

              object o1 = map.put(key, val);
              object o2 = hmap[hmapKey].Value = val;
              assertEquals(o1,o2);

              // add it again with the string method
              assertEquals(val, map.put(keyStr,val).intValue());

              assertEquals(val, map.get(key,0,key.Length).intValue());
              assertEquals(val, map.get(key).intValue());
              assertEquals(val, map.get(keyStr).intValue());

              assertEquals(hmap.Count, map.size());
            }
        }
Esempio n. 3
0
        public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable)
            : this(matchVersion, stopwords, stemExclusionTable,
#pragma warning disable 612, 618
                   matchVersion.OnOrAfter(LuceneVersion.LUCENE_36) ?
#pragma warning restore 612, 618
                   DefaultSetHolder.DEFAULT_STEM_DICT : CharArrayMap <string> .EmptyMap())
        {
            // historically, this ctor never the stem dict!!!!!
            // so we populate it only for >= 3.6
        }
Esempio n. 4
0
            private static CharArrayMap <string> LoadDefaultStemDict() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
            {
#pragma warning disable 612, 618
                var DEFAULT_STEM_DICT = new CharArrayMap <string>(LuceneVersion.LUCENE_CURRENT, 4, false);
#pragma warning restore 612, 618
                DEFAULT_STEM_DICT.Put("fiets", "fiets");         //otherwise fiet
                DEFAULT_STEM_DICT.Put("bromfiets", "bromfiets"); //otherwise bromfiet
                DEFAULT_STEM_DICT.Put("ei", "eier");
                DEFAULT_STEM_DICT.Put("kind", "kinder");
                return(DEFAULT_STEM_DICT);
            }
Esempio n. 5
0
            public object Create(Random random)
            {
                int num = random.nextInt(10);
                CharArrayMap <string> map = new CharArrayMap <string>(TEST_VERSION_CURRENT, num, random.nextBoolean());

                for (int i = 0; i < num; i++)
                {
                    // TODO: make nastier
                    map.Put(TestUtil.RandomSimpleString(random), TestUtil.RandomSimpleString(random));
                }
                return(map);
            }
Esempio n. 6
0
        public virtual void testToString()
        {
            CharArrayMap <int?> cm = new CharArrayMap <int?>(TEST_VERSION_CURRENT, Collections.singletonMap("test", 1), false);

            assertEquals("[test]", cm.Keys.ToString());
            assertEquals("[1]", cm.values().ToString());
            assertEquals("[test=1]", cm.entrySet().ToString());
            assertEquals("{test=1}", cm.ToString());
            cm.put("test2", 2);
            assertTrue(cm.Keys.ToString().Contains(", "));
            assertTrue(cm.values().ToString().Contains(", "));
            assertTrue(cm.entrySet().ToString().Contains(", "));
            assertTrue(cm.ToString().Contains(", "));
        }
Esempio n. 7
0
 /// <summary>
 /// Reads a stem dictionary. Each line contains:
 /// <code>word<b>\t</b>stem</code>
 /// (i.e. two tab separated words)
 /// </summary>
 /// <returns> stem dictionary that overrules the stemming algorithm </returns>
 /// <exception cref="IOException"> If there is a low-level I/O error. </exception>
 public static CharArrayMap <string> GetStemDict(TextReader reader, CharArrayMap <string> result)
 {
     try
     {
         string line;
         while ((line = reader.ReadLine()) != null)
         {
             string[] wordstem = line.Split(new char[] { '\t' }, 2);
             result.Put(wordstem[0], wordstem[1]);
         }
     }
     finally
     {
         IOUtils.Dispose(reader);
     }
     return(result);
 }
Esempio n. 8
0
            static DefaultSetHolder()
            {
                try
                {
                    DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(typeof(SnowballFilter), DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);
                }
                catch (IOException)
                {
                    // default set should always be present as it is part of the
                    // distribution (JAR)
                    throw new Exception("Unable to load default stopword set");
                }

                DEFAULT_STEM_DICT = new CharArrayMap <>(Version.LUCENE_CURRENT, 4, false);
                DEFAULT_STEM_DICT.put("fiets", "fiets");         //otherwise fiet
                DEFAULT_STEM_DICT.put("bromfiets", "bromfiets"); //otherwise bromfiet
                DEFAULT_STEM_DICT.put("ei", "eier");
                DEFAULT_STEM_DICT.put("kind", "kinder");
            }
Esempio n. 9
0
        public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap <string> stemOverrideDict)
        {
            this.matchVersion = matchVersion;
            this.stoptable    = CharArraySet.UnmodifiableSet(CharArraySet.Copy(matchVersion, stopwords));
            this.excltable    = CharArraySet.UnmodifiableSet(CharArraySet.Copy(matchVersion, stemExclusionTable));
#pragma warning disable 612, 618
            if (stemOverrideDict.Count == 0 || !matchVersion.OnOrAfter(LuceneVersion.LUCENE_31))
#pragma warning restore 612, 618
            {
                this.stemdict     = null;
                this.origStemdict = CharArrayMap.UnmodifiableMap(CharArrayMap.Copy(matchVersion, stemOverrideDict));
            }
            else
            {
                this.origStemdict = null;
                // we don't need to ignore case here since we lowercase in this analyzer anyway
                StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false);
                using (CharArrayMap <string> .EntryIterator iter = (CharArrayMap <string> .EntryIterator)stemOverrideDict.EntrySet().GetEnumerator())
                {
                    CharsRef spare = new CharsRef();
                    while (iter.HasNext)
                    {
                        char[] nextKey = iter.NextKey();
                        spare.CopyChars(nextKey, 0, nextKey.Length);
                        builder.Add(new string(spare.Chars), iter.CurrentValue);
                    }
                }
                try
                {
                    this.stemdict = builder.Build();
                }
                catch (Exception ex) when(ex.IsIOException())
                {
                    throw RuntimeException.Create("can not build stem dict", ex);
                }
            }
        }
Esempio n. 10
0
            static DefaultSetHolder()
            {
                try
                {
                    DEFAULT_STOP_SET = WordlistLoader.GetSnowballWordSet(
                        IOUtils.GetDecodingReader(typeof(SnowballFilter), DEFAULT_STOPWORD_FILE, Encoding.UTF8),
#pragma warning disable 612, 618
                        LuceneVersion.LUCENE_CURRENT);
#pragma warning restore 612, 618
                }
                catch (IOException)
                {
                    // default set should always be present as it is part of the
                    // distribution (JAR)
                    throw new Exception("Unable to load default stopword set");
                }
#pragma warning disable 612, 618
                DEFAULT_STEM_DICT = new CharArrayMap <string>(LuceneVersion.LUCENE_CURRENT, 4, false);
#pragma warning restore 612, 618
                DEFAULT_STEM_DICT.Put("fiets", "fiets");         //otherwise fiet
                DEFAULT_STEM_DICT.Put("bromfiets", "bromfiets"); //otherwise bromfiet
                DEFAULT_STEM_DICT.Put("ei", "eier");
                DEFAULT_STEM_DICT.Put("kind", "kinder");
            }
Esempio n. 11
0
        public virtual void testMethods()
        {
            CharArrayMap <int?>       cm = new CharArrayMap <int?>(TEST_VERSION_CURRENT, 2, false);
            Dictionary <string, int?> hm = new Dictionary <string, int?>();

            hm["foo"] = 1;
            hm["bar"] = 2;
            cm.putAll(hm);
            assertEquals(hm.Count, cm.size());
            hm["baz"] = 3;
            cm.putAll(hm);
            assertEquals(hm.Count, cm.size());

            CharArraySet cs = cm.Keys;
            int          n  = 0;

            foreach (object o in cs)
            {
                assertTrue(cm.containsKey(o));
                char[] co = (char[])o;
                assertTrue(cm.containsKey(co, 0, co.Length));
                n++;
            }
            assertEquals(hm.Count, n);
            assertEquals(hm.Count, cs.size());
            assertEquals(cm.size(), cs.size());
            cs.clear();
            assertEquals(0, cs.size());
            assertEquals(0, cm.size());
            try
            {
                cs.add("test");
                fail("keySet() allows adding new keys");
            }
            catch (System.NotSupportedException)
            {
                // pass
            }
            cm.putAll(hm);
            assertEquals(hm.Count, cs.size());
            assertEquals(cm.size(), cs.size());

            IEnumerator <KeyValuePair <object, int?> > iter1 = cm.entrySet().GetEnumerator();

            n = 0;
            while (iter1.MoveNext())
            {
                KeyValuePair <object, int?> entry = iter1.Current;
                object key = entry.Key;
                int?   val = entry.Value;
                assertEquals(cm.get(key), val);
                entry.Value = val * 100;
                assertEquals(val * 100, (int)cm.get(key));
                n++;
            }
            assertEquals(hm.Count, n);
            cm.clear();
            cm.putAll(hm);
            assertEquals(cm.size(), n);

            CharArrayMap <int?> .EntryIterator iter2 = cm.entrySet().GetEnumerator();
            n = 0;
            while (iter2.hasNext())
            {
                char[] keyc = iter2.nextKey();
                int?   val  = iter2.currentValue();
                assertEquals(hm[new string(keyc)], val);
                iter2.Value = val * 100;
                assertEquals(val * 100, (int)cm.get(keyc));
                n++;
            }
            assertEquals(hm.Count, n);

            cm.entrySet().clear();
            assertEquals(0, cm.size());
            assertEquals(0, cm.entrySet().size());
            assertTrue(cm.Empty);
        }
Esempio n. 12
0
 internal EntryIterator(CharArrayMap <V> outerInstance, bool allowModify)
 {
     this.outerInstance = outerInstance;
     this.allowModify   = allowModify;
     goNext();
 }
Esempio n. 13
0
 public DutchAnalyzer(Version matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap <string> stemOverrideDict)
 {
     this.matchVersion = matchVersion;
     this.stoptable    = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stopwords));
     this.excltable    = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stemExclusionTable));
     if (stemOverrideDict.Empty || !matchVersion.onOrAfter(Version.LUCENE_31))
     {
         this.stemdict     = null;
         this.origStemdict = CharArrayMap.unmodifiableMap(CharArrayMap.copy(matchVersion, stemOverrideDict));
     }
     else
     {
         this.origStemdict = null;
         // we don't need to ignore case here since we lowercase in this analyzer anyway
         StemmerOverrideFilter.Builder        builder = new StemmerOverrideFilter.Builder(false);
         CharArrayMap <string> .EntryIterator iter    = stemOverrideDict.entrySet().GetEnumerator();
         CharsRef spare = new CharsRef();
         while (iter.hasNext())
         {
             char[] nextKey = iter.nextKey();
             spare.copyChars(nextKey, 0, nextKey.Length);
             builder.add(spare, iter.currentValue());
         }
         try
         {
             this.stemdict = builder.build();
         }
         catch (IOException ex)
         {
             throw new Exception("can not build stem dict", ex);
         }
     }
 }
Esempio n. 14
0
 public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
     : this(matchVersion, stopwords, CharArraySet.EMPTY_SET,
            matchVersion.OnOrAfter(LuceneVersion.LUCENE_36) ? DefaultSetHolder.DEFAULT_STEM_DICT : CharArrayMap <string> .EmptyMap())
 {
     // historically, this ctor never the stem dict!!!!!
     // so we populate it only for >= 3.6
 }
Esempio n. 15
0
 /// <summary>
 /// Reads a stem dictionary. Each line contains:
 /// <pre>word<b>\t</b>stem</pre>
 /// (i.e. two tab separated words)
 /// </summary>
 /// <returns> stem dictionary that overrules the stemming algorithm </returns>
 /// <exception cref="IOException"> If there is a low-level I/O error. </exception>
 public static CharArrayMap<string> GetStemDict(TextReader reader, CharArrayMap<string> result)
 {
     try
     {
         string line;
         while ((line = reader.ReadLine()) != null)
         {
             string[] wordstem = line.Split(new char[] { '\t' }, 2, StringSplitOptions.RemoveEmptyEntries);
             result.Put(wordstem[0], wordstem[1]);
         }
     }
     finally
     {
         IOUtils.Close(reader);
     }
     return result;
 }
Esempio n. 16
0
 public DutchAnalyzer(Version matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable) : this(matchVersion, stopwords, stemExclusionTable, matchVersion.onOrAfter(Version.LUCENE_36) ? DefaultSetHolder.DEFAULT_STEM_DICT : CharArrayMap.emptyMap <string>())
 {
     // historically, this ctor never the stem dict!!!!!
     // so we populate it only for >= 3.6
 }
Esempio n. 17
0
 public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap<string> stemOverrideDict)
 {
     this.matchVersion = matchVersion;
     this.stoptable = CharArraySet.UnmodifiableSet(CharArraySet.Copy(matchVersion, stopwords));
     this.excltable = CharArraySet.UnmodifiableSet(CharArraySet.Copy(matchVersion, stemExclusionTable));
     #pragma warning disable 612, 618
     if (stemOverrideDict.Count == 0 || !matchVersion.OnOrAfter(LuceneVersion.LUCENE_31))
     #pragma warning restore 612, 618
     {
         this.stemdict = null;
         this.origStemdict = CharArrayMap.UnmodifiableMap(CharArrayMap.Copy(matchVersion, stemOverrideDict));
     }
     else
     {
         this.origStemdict = null;
         // we don't need to ignore case here since we lowercase in this analyzer anyway
         StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false);
         CharArrayMap<string>.EntryIterator iter = (CharArrayMap<string>.EntryIterator)stemOverrideDict.EntrySet().GetEnumerator();
         CharsRef spare = new CharsRef();
         while (iter.HasNext)
         {
             char[] nextKey = iter.NextKey();
             spare.CopyChars(nextKey, 0, nextKey.Length);
             builder.Add(new string(spare.Chars), iter.CurrentValue);
         }
         try
         {
             this.stemdict = builder.Build();
         }
         catch (IOException ex)
         {
             throw new Exception("can not build stem dict", ex);
         }
     }
 }
Esempio n. 18
0
 public DutchAnalyzer(Version matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap<string> stemOverrideDict)
 {
     this.matchVersion = matchVersion;
     this.stoptable = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stopwords));
     this.excltable = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stemExclusionTable));
     if (stemOverrideDict.Empty || !matchVersion.onOrAfter(Version.LUCENE_31))
     {
       this.stemdict = null;
       this.origStemdict = CharArrayMap.unmodifiableMap(CharArrayMap.copy(matchVersion, stemOverrideDict));
     }
     else
     {
       this.origStemdict = null;
       // we don't need to ignore case here since we lowercase in this analyzer anyway
       StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false);
       CharArrayMap<string>.EntryIterator iter = stemOverrideDict.entrySet().GetEnumerator();
       CharsRef spare = new CharsRef();
       while (iter.hasNext())
       {
     char[] nextKey = iter.nextKey();
     spare.copyChars(nextKey, 0, nextKey.Length);
     builder.add(spare, iter.currentValue());
       }
       try
       {
     this.stemdict = builder.build();
       }
       catch (IOException ex)
       {
     throw new Exception("can not build stem dict", ex);
       }
     }
 }
Esempio n. 19
0
 static DefaultSetHolder()
 {
     try
     {
         DEFAULT_STOP_SET = WordlistLoader.GetSnowballWordSet(
             IOUtils.GetDecodingReader(typeof(SnowballFilter), typeof(SnowballFilter).Namespace + "." + DEFAULT_STOPWORD_FILE, Encoding.UTF8),
     #pragma warning disable 612, 618
             LuceneVersion.LUCENE_CURRENT);
     #pragma warning restore 612, 618
     }
     catch (IOException)
     {
         // default set should always be present as it is part of the
         // distribution (JAR)
         throw new Exception("Unable to load default stopword set");
     }
     #pragma warning disable 612, 618
     DEFAULT_STEM_DICT = new CharArrayMap<string>(LuceneVersion.LUCENE_CURRENT, 4, false);
     #pragma warning restore 612, 618
     DEFAULT_STEM_DICT.Put("fiets", "fiets"); //otherwise fiet
     DEFAULT_STEM_DICT.Put("bromfiets", "bromfiets"); //otherwise bromfiet
     DEFAULT_STEM_DICT.Put("ei", "eier");
     DEFAULT_STEM_DICT.Put("kind", "kinder");
 }
        public void TestModifyOnUnmodifiable()
        {
            CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
            map.Put("foo", 1);
            map.Put("bar", 2);
            int size = map.Count;
            assertEquals(2, size);
            assertTrue(map.ContainsKey("foo"));
            assertEquals(1, map.Get("foo"));
            assertTrue(map.ContainsKey("bar"));
            assertEquals(2, map.Get("bar"));

            map = CharArrayMap.UnmodifiableMap(map);
            assertEquals("Map size changed due to unmodifiableMap call", size, map.Count);
            var NOT_IN_MAP = "SirGallahad";
            assertFalse("Test String already exists in map", map.ContainsKey(NOT_IN_MAP));
            assertNull("Test String already exists in map", map.Get(NOT_IN_MAP));

            try
            {
                map.Put(NOT_IN_MAP.ToCharArray(), 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            try
            {
                map.Put(NOT_IN_MAP, 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            try
            {
                map.Put(new StringBuilder(NOT_IN_MAP), 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            #region Added for better .NET support
            try
            {
                map.Add(NOT_IN_MAP, 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            try
            {
                map.Add(new KeyValuePair<string, int?>(NOT_IN_MAP, 3));
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            try
            {
                map[new StringBuilder(NOT_IN_MAP)] = 3;
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }

            try
            {
#pragma warning disable 612, 618
                map.Remove(new KeyValuePair<string, int?>("foo", 1));
#pragma warning restore 612, 618
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.Count);
            }
            #endregion

            try
            {
                map.Clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.EntrySet().Clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.Keys.Clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.Put((object)NOT_IN_MAP, 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.PutAll(Collections.SingletonMap<string, int?>(NOT_IN_MAP, 3));
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            assertTrue(map.ContainsKey("foo"));
            assertEquals(1, map.Get("foo"));
            assertTrue(map.ContainsKey("bar"));
            assertEquals(2, map.Get("bar"));
        }
Esempio n. 21
0
        public virtual void testModifyOnUnmodifiable()
        {
            CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
            map.put("foo",1);
            map.put("bar",2);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int size = map.size();
            int size = map.size();
            assertEquals(2, size);
            assertTrue(map.containsKey("foo"));
            assertEquals(1, map.get("foo").intValue());
            assertTrue(map.containsKey("bar"));
            assertEquals(2, map.get("bar").intValue());

            map = CharArrayMap.unmodifiableMap(map);
            assertEquals("Map size changed due to unmodifiableMap call", size, map.size());
            string NOT_IN_MAP = "SirGallahad";
            assertFalse("Test String already exists in map", map.containsKey(NOT_IN_MAP));
            assertNull("Test String already exists in map", map.get(NOT_IN_MAP));

            try
            {
              map.put(NOT_IN_MAP.ToCharArray(), 3);
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
              assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.put(NOT_IN_MAP, 3);
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
              assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.put(new StringBuilder(NOT_IN_MAP), 3);
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
              assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.clear();
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.entrySet().clear();
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.Keys.Clear();
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.put((object) NOT_IN_MAP, 3);
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
              assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
              map.putAll(Collections.singletonMap(NOT_IN_MAP, 3));
              fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
              assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
              assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            assertTrue(map.containsKey("foo"));
            assertEquals(1, map.get("foo").intValue());
            assertTrue(map.containsKey("bar"));
            assertEquals(2, map.get("bar").intValue());
        }
        public virtual void TestMethods()
        {
            CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
            Dictionary<string, int?> hm = new Dictionary<string, int?>();
            hm["foo"] = 1;
            hm["bar"] = 2;
            cm.PutAll(hm);
            assertEquals(hm.Count, cm.Count);
            hm["baz"] = 3;
            cm.PutAll(hm);
            assertEquals(hm.Count, cm.Count);

            // LUCENENET: Need to cast here - no implicit conversion.
            CharArraySet cs = cm.Keys as CharArraySet;
            int n = 0;
            foreach (string o in cs)
            {
                assertTrue(cm.ContainsKey(o));
                char[] co = o.ToCharArray();
                assertTrue(cm.ContainsKey(co, 0, co.Length));
                n++;
            }
            assertEquals(hm.Count, n);
            assertEquals(hm.Count, cs.Count);
            assertEquals(cm.Count, cs.Count);
            cs.Clear();
            assertEquals(0, cs.Count);
            assertEquals(0, cm.Count);
            try
            {
                cs.Add("test");
                fail("keySet() allows adding new keys");
            }
            catch (System.NotSupportedException)
            {
                // pass
            }
            cm.PutAll(hm);
            assertEquals(hm.Count, cs.Count);
            assertEquals(cm.Count, cs.Count);
            // LUCENENET: Need to cast here - no implicit conversion
            IEnumerator<KeyValuePair<string, int?>> iter1 = (IEnumerator<KeyValuePair<string, int?>>)cm.EntrySet().GetEnumerator();
            n = 0;
            while (iter1.MoveNext())
            {
                KeyValuePair<string, int?> entry = iter1.Current;
                object key = entry.Key;
                int? val = entry.Value;
                assertEquals(cm.Get(key), val);
                // LUCENENET: Need a cast to get to this method because it is not part of the IEnumerator<T> interface
                ((CharArrayMap<int?>.EntryIterator)iter1).SetValue(val * 100);
                assertEquals(val * 100, (int)cm.Get(key));
                n++;
            }
            assertEquals(hm.Count, n);
            cm.Clear();
            cm.PutAll(hm);
            assertEquals(cm.size(), n);

            CharArrayMap<int?>.EntryIterator iter2 = cm.EntrySet().GetEnumerator() as CharArrayMap<int?>.EntryIterator;
            n = 0;
            while (iter2.MoveNext())
            {
                var keyc = iter2.Current.Key;
                int? val = iter2.Current.Value;
                assertEquals(hm[keyc], val);
                iter2.SetValue(val * 100);
                assertEquals(val * 100, (int)cm.Get(keyc));
                n++;
            }
            assertEquals(hm.Count, n);

            cm.EntrySet().Clear();
            assertEquals(0, cm.size());
            assertEquals(0, cm.EntrySet().size());
            assertTrue(cm.Count == 0);
        }
Esempio n. 23
0
            static DefaultSetHolder()
            {
                try
                  {
                DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(typeof(SnowballFilter), DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);
                  }
                  catch (IOException)
                  {
                // default set should always be present as it is part of the
                // distribution (JAR)
                throw new Exception("Unable to load default stopword set");
                  }

                  DEFAULT_STEM_DICT = new CharArrayMap<>(Version.LUCENE_CURRENT, 4, false);
                  DEFAULT_STEM_DICT.put("fiets", "fiets"); //otherwise fiet
                  DEFAULT_STEM_DICT.put("bromfiets", "bromfiets"); //otherwise bromfiet
                  DEFAULT_STEM_DICT.put("ei", "eier");
                  DEFAULT_STEM_DICT.put("kind", "kinder");
            }
Esempio n. 24
0
 internal EntrySet(CharArrayMap <V> outerInstance, bool allowModify)
 {
     this.outerInstance = outerInstance;
     this.allowModify   = allowModify;
 }
Esempio n. 25
0
	  /// <summary>
	  /// Reads a stem dictionary. Each line contains:
	  /// <pre>word<b>\t</b>stem</pre>
	  /// (i.e. two tab separated words)
	  /// </summary>
	  /// <returns> stem dictionary that overrules the stemming algorithm </returns>
	  /// <exception cref="IOException"> If there is a low-level I/O error. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static CharArrayMap<String> getStemDict(java.io.Reader reader, CharArrayMap<String> result) throws java.io.IOException
	  public static CharArrayMap<string> getStemDict(Reader reader, CharArrayMap<string> result)
	  {
		BufferedReader br = null;
		try
		{
		  br = getBufferedReader(reader);
		  string line;
		  while ((line = br.readLine()) != null)
		  {
			string[] wordstem = line.Split("\t", 2);
			result.put(wordstem[0], wordstem[1]);
		  }
		}
		finally
		{
		  IOUtils.close(br);
		}
		return result;
	  }
Esempio n. 26
0
 public CharArraySetAnonymousInnerClassHelper(CharArrayMap <V> outerInstance, CharArrayMap (CharArrayMap) this) : base((CharArrayMap)this)
Esempio n. 27
0
        public virtual void testModifyOnUnmodifiable()
        {
            CharArrayMap <int?> map = new CharArrayMap <int?>(TEST_VERSION_CURRENT, 2, false);

            map.put("foo", 1);
            map.put("bar", 2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int size = map.size();
            int size = map.size();

            assertEquals(2, size);
            assertTrue(map.containsKey("foo"));
            assertEquals(1, map.get("foo").intValue());
            assertTrue(map.containsKey("bar"));
            assertEquals(2, map.get("bar").intValue());

            map = CharArrayMap.unmodifiableMap(map);
            assertEquals("Map size changed due to unmodifiableMap call", size, map.size());
            string NOT_IN_MAP = "SirGallahad";

            assertFalse("Test String already exists in map", map.containsKey(NOT_IN_MAP));
            assertNull("Test String already exists in map", map.get(NOT_IN_MAP));

            try
            {
                map.put(NOT_IN_MAP.ToCharArray(), 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.put(NOT_IN_MAP, 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.put(new StringBuilder(NOT_IN_MAP), 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.entrySet().clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.Keys.Clear();
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.put((object)NOT_IN_MAP, 3);
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            try
            {
                map.putAll(Collections.singletonMap(NOT_IN_MAP, 3));
                fail("Modified unmodifiable map");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
                assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
                assertEquals("Size of unmodifiable map has changed", size, map.size());
            }

            assertTrue(map.containsKey("foo"));
            assertEquals(1, map.get("foo").intValue());
            assertTrue(map.containsKey("bar"));
            assertEquals(2, map.get("bar").intValue());
        }
Esempio n. 28
0
 internal MapEntry(CharArrayMap <V> outerInstance, int pos, bool allowModify)
 {
     this.outerInstance = outerInstance;
     this.pos           = pos;
     this.allowModify   = allowModify;
 }
Esempio n. 29
0
 public virtual void testToString()
 {
     CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT, Collections.singletonMap("test",1), false);
     assertEquals("[test]",cm.Keys.ToString());
     assertEquals("[1]",cm.values().ToString());
     assertEquals("[test=1]",cm.entrySet().ToString());
     assertEquals("{test=1}",cm.ToString());
     cm.put("test2", 2);
     assertTrue(cm.Keys.ToString().Contains(", "));
     assertTrue(cm.values().ToString().Contains(", "));
     assertTrue(cm.entrySet().ToString().Contains(", "));
     assertTrue(cm.ToString().Contains(", "));
 }
Esempio n. 30
0
 UnmodifiableCharArrayMap(CharArrayMap <V> map)
 {
     base(map);
 }
Esempio n. 31
0
        public virtual void testMethods()
        {
            CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
            Dictionary<string, int?> hm = new Dictionary<string, int?>();
            hm["foo"] = 1;
            hm["bar"] = 2;
            cm.putAll(hm);
            assertEquals(hm.Count, cm.size());
            hm["baz"] = 3;
            cm.putAll(hm);
            assertEquals(hm.Count, cm.size());

            CharArraySet cs = cm.Keys;
            int n = 0;
            foreach (object o in cs)
            {
              assertTrue(cm.containsKey(o));
              char[] co = (char[]) o;
              assertTrue(cm.containsKey(co, 0, co.Length));
              n++;
            }
            assertEquals(hm.Count, n);
            assertEquals(hm.Count, cs.size());
            assertEquals(cm.size(), cs.size());
            cs.clear();
            assertEquals(0, cs.size());
            assertEquals(0, cm.size());
            try
            {
              cs.add("test");
              fail("keySet() allows adding new keys");
            }
            catch (System.NotSupportedException)
            {
              // pass
            }
            cm.putAll(hm);
            assertEquals(hm.Count, cs.size());
            assertEquals(cm.size(), cs.size());

            IEnumerator<KeyValuePair<object, int?>> iter1 = cm.entrySet().GetEnumerator();
            n = 0;
            while (iter1.MoveNext())
            {
              KeyValuePair<object, int?> entry = iter1.Current;
              object key = entry.Key;
              int? val = entry.Value;
              assertEquals(cm.get(key), val);
              entry.Value = val * 100;
              assertEquals(val * 100, (int)cm.get(key));
              n++;
            }
            assertEquals(hm.Count, n);
            cm.clear();
            cm.putAll(hm);
            assertEquals(cm.size(), n);

            CharArrayMap<int?>.EntryIterator iter2 = cm.entrySet().GetEnumerator();
            n = 0;
            while (iter2.hasNext())
            {
              char[] keyc = iter2.nextKey();
              int? val = iter2.currentValue();
              assertEquals(hm[new string(keyc)], val);
              iter2.Value = val * 100;
              assertEquals(val * 100, (int)cm.get(keyc));
              n++;
            }
            assertEquals(hm.Count, n);

            cm.entrySet().clear();
            assertEquals(0, cm.size());
            assertEquals(0, cm.entrySet().size());
            assertTrue(cm.Empty);
        }
Esempio n. 32
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testEmptyStemDictionary() throws java.io.IOException
        public virtual void testEmptyStemDictionary()
        {
            DutchAnalyzer a = new DutchAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET, CharArraySet.EMPTY_SET, CharArrayMap.emptyMap <string>());

            checkOneTerm(a, "fiets", "fiet");
        }
Esempio n. 33
0
	  private static CharArrayMap<DictEntry> initializeDictHash()
	  {
		DictEntry defaultEntry;
		DictEntry entry;

		CharArrayMap<DictEntry> d = new CharArrayMap<DictEntry>(Version.LUCENE_CURRENT, 1000, false);
		for (int i = 0; i < exceptionWords.Length; i++)
		{
		  if (!d.containsKey(exceptionWords[i]))
		  {
			entry = new DictEntry(exceptionWords[i], true);
			d.put(exceptionWords[i], entry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + exceptionWords[i] + "] already in dictionary 1");
		  }
		}

		for (int i = 0; i < directConflations.Length; i++)
		{
		  if (!d.containsKey(directConflations[i][0]))
		  {
			entry = new DictEntry(directConflations[i][1], false);
			d.put(directConflations[i][0], entry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + directConflations[i][0] + "] already in dictionary 2");
		  }
		}

		for (int i = 0; i < countryNationality.Length; i++)
		{
		  if (!d.containsKey(countryNationality[i][0]))
		  {
			entry = new DictEntry(countryNationality[i][1], false);
			d.put(countryNationality[i][0], entry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + countryNationality[i][0] + "] already in dictionary 3");
		  }
		}

		defaultEntry = new DictEntry(null, false);

		string[] array;
		array = KStemData1.data;

		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData2.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData3.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData4.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData5.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData6.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		array = KStemData7.data;
		for (int i = 0; i < array.Length; i++)
		{
		  if (!d.containsKey(array[i]))
		  {
			d.put(array[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + array[i] + "] already in dictionary 4");
		  }
		}

		for (int i = 0; i < KStemData8.data.Length; i++)
		{
		  if (!d.containsKey(KStemData8.data[i]))
		  {
			d.put(KStemData8.data[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + KStemData8.data[i] + "] already in dictionary 4");
		  }
		}

		for (int i = 0; i < supplementDict.Length; i++)
		{
		  if (!d.containsKey(supplementDict[i]))
		  {
			d.put(supplementDict[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + supplementDict[i] + "] already in dictionary 5");
		  }
		}

		for (int i = 0; i < properNouns.Length; i++)
		{
		  if (!d.containsKey(properNouns[i]))
		  {
			d.put(properNouns[i], defaultEntry);
		  }
		  else
		  {
			throw new Exception("Warning: Entry [" + properNouns[i] + "] already in dictionary 6");
		  }
		}

		return d;
	  }