Exemplo n.º 1
0
        public void TestCollation()
        {
            using (new ThreadCultureChange(_DEFAULT_LOCALE, _DEFAULT_LOCALE))
            {
                for (int i = 0; i < _LOCALE_NUMBER; i++)
                {
                    UCultureInfo oldLoc = _LOCALES[i][0];
                    UCultureInfo newLoc = _LOCALES[i][1];
                    if (!availableMap.TryGetValue(_LOCALES[i][1], out object value) || value == null)
                    {
                        Logln(_LOCALES[i][1] + " is not available. Skipping!");
                        continue;
                    }
                    Collator c1 = Collator.GetInstance(oldLoc);
                    Collator c2 = Collator.GetInstance(newLoc);

                    if (!c1.Equals(c2))
                    {
                        Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                    }

                    Logln("Collation old:" + oldLoc + "   new:" + newLoc);
                }
            }
        }
Exemplo n.º 2
0
        public static int CompareStringsUnicode(string a, string b)
        {
            Collator c   = Collator.GetInstance();
            int      res = c.Compare(a, b);

            return(res);
        }
Exemplo n.º 3
0
        public void TestCollation()
        {
            ULocale defLoc = ULocale.GetDefault();

            ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                ULocale oldLoc = _LOCALES[i][0];
                ULocale newLoc = _LOCALES[i][1];
                if (availableMap.Get(_LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                Collator c1 = Collator.GetInstance(oldLoc);
                Collator c2 = Collator.GetInstance(newLoc);

                if (!c1.Equals(c2))
                {
                    Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                }

                Logln("Collation old:" + oldLoc + "   new:" + newLoc);
            }
            ULocale.SetDefault(defLoc);
        }
Exemplo n.º 4
0
        public void TestCustomRules()
        {
            RuleBasedCollator baseCollator = (RuleBasedCollator)Collator.GetInstance(new ULocale("de_DE"));

            String DIN5007_2_tailorings =
                "& ae , a\u0308 & AE , A\u0308" +
                "& oe , o\u0308 & OE , O\u0308" +
                "& ue , u\u0308 & UE , u\u0308";

            RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.GetRules() + DIN5007_2_tailorings);
            string            tailoredRules    = tailoredCollator.GetRules();
            //
            // at this point, you would save these tailoredRules to a file,
            // and use the custom parameter.
            //
            String germanUmlaut = "Töne";
            String germanOE     = "Toene";
            IDictionary <String, String> args = new Dictionary <String, String>();

            args.Put("custom", "rules.txt");
            args.Put("strength", "primary");
            ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory(args);

            factory.Inform(new StringMockResourceLoader(tailoredRules));
            TokenStream tsUmlaut = factory.Create(
                new KeywordTokenizer(new StringReader(germanUmlaut)));
            TokenStream tsOE = factory.Create(
                new KeywordTokenizer(new StringReader(germanOE)));

            assertCollatesToSame(tsUmlaut, tsOE);
        }
Exemplo n.º 5
0
        public void TestDemo3()
        {
            // Logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\"");
            Collator col = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);


            String baseRules = ((RuleBasedCollator)col).GetRules();
            String newRules  = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";

            newRules = baseRules + newRules;
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator with rules:" + newRules);
                return;
            }

            int j, n;

            for (j = 0; j < TOTALTESTSET; j++)
            {
                for (n = j + 1; n < TOTALTESTSET; n++)
                {
                    DoTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], -1);
                }
            }
        }
Exemplo n.º 6
0
        public void TestIllformedLocale()
        {
            UCultureInfo        french   = new UCultureInfo("fr");
            Collator            collator = Collator.GetInstance(french);
            CultureDisplayNames names    = CultureDisplayNames.GetInstance(french,
                                                                           new DisplayContextOptions {
                Capitalization = Capitalization.UIListOrMenu
            });

            foreach (String malformed in new string[] { "en-a", "$", "ü--a", "en--US" })
            {
                try
                {
                    ISet <UCultureInfo> supported = new HashSet <UCultureInfo> {
                        new UCultureInfo(malformed)
                    };                                                                                        //Collections.singleton(new UCultureInfo(malformed));
                    names.GetUiList(supported, false, collator);
                    assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
                }
                catch (IllformedLocaleException e)
                {
                    Logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.ToString());
                }
            }
        }
Exemplo n.º 7
0
        public void TestThreads()
        {
            Collator theCollator = Collator.GetInstance(new CultureInfo("pl"));
            Random   r           = new Random();
            Control  control     = new Control();

            Thread[] threads = new Thread[10];
            for (int i = 0; i < threads.Length; ++i)
            {
                Collator coll;
                //try
                //{
                coll = (Collator)theCollator.Clone();
                //}
                //catch (CloneNotSupportedException e)
                //{
                //    // should not happen, if it does we'll get an exception right away
                //    Errln("could not clone");
                //    return;
                //}
                Test test = new Test("Collation test thread" + i, (string[])threadTestData.Clone(), coll,
                                     r, control);
                threads[i] = new Thread(() => test.Run());
            }

            RunThreads(threads, control);
        }
Exemplo n.º 8
0
        public void TestDemo2()
        {
            Logln("Demo Test 2 : Create a new table collation with rules \"& C < ch , cH, Ch, CH\"");
            Collator col = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);


            String baseRules = ((RuleBasedCollator)col).GetRules();
            String newRules  = "& C < ch , cH, Ch, CH";

            newRules = baseRules + newRules;
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator with rules:" + newRules);
                return;
            }

            int j, n;

            for (j = 0; j < TOTALTESTSET; j++)
            {
                for (n = j + 1; n < TOTALTESTSET; n++)
                {
                    DoTest(myCollation, testCases[results[9][j]], testCases[results[9][n]], -1);
                }
            }
        }
Exemplo n.º 9
0
 public void init()
 {
     if (myCollation == null)
     {
         myCollation = Collator.GetInstance(new CultureInfo("ja") /* Locale.JAPANESE */);
     }
 }
Exemplo n.º 10
0
 public void Init()
 {
     myCollation = Collator.GetInstance(new CultureInfo("de") /* Locale.GERMAN */);
     if (myCollation == null)
     {
         Errln("ERROR: in creation of collator of GERMAN locale");
     }
 }
Exemplo n.º 11
0
        public void TestNormalizedUnicodeChar()
        {
            // thai should have normalization on
            RuleBasedCollator th_th = null;

            try
            {
                th_th = (RuleBasedCollator)Collator.GetInstance(
                    new CultureInfo("th-TH"));
            }
            catch (Exception e)
            {
                Warnln("Error creating Thai collator");
                return;
            }
            StringBuffer source = new StringBuffer();

            source.Append('\uFDFA');
            CollationElementIterator iter
                = th_th.GetCollationElementIterator(source.ToString());

            CollationTest.BackAndForth(this, iter);
            for (char codepoint = (char)0x1; codepoint < 0xfffe;)
            {
                source.Delete(0, source.Length);
                while (codepoint % 0xFF != 0)
                {
                    if (UChar.IsDefined(codepoint))
                    {
                        source.Append(codepoint);
                    }
                    codepoint++;
                }

                if (UChar.IsDefined(codepoint))
                {
                    source.Append(codepoint);
                }

                if (codepoint != 0xFFFF)
                {
                    codepoint++;
                }

                /*if (((int)codepoint) >= 0xfe00) {
                 *  String str = source.substring(185, 190);
                 *  System.out.println(com.ibm.icu.impl.Utility.escape(str));
                 *  System.out.println("codepoint "
                 + Integer.toHexString(codepoint)
                 + "length " + str.Length);
                 +  iter = th_th.GetCollationElementIterator(str);
                 +  CollationTest.BackAndForth(this, iter);
                 */
                iter = th_th.GetCollationElementIterator(source.ToString());
                // A basic test to see if it's working at all
                CollationTest.BackAndForth(this, iter);
            }
        }
Exemplo n.º 12
0
        public void TestAddICUCollationDocValuesField()
        {
            ICUCollationDocValuesField field = null;
            Collator collator = Collator.GetInstance(new CultureInfo("en"));

            AssertDocumentExtensionAddsToDocument(document => field = document.AddICUCollationDocValuesField("theName", collator));
            Assert.AreEqual("theName", field.Name);
            Assert.AreEqual(collator, field.collator); // Collator is cloned, so we don't expect them to be the same instance
        }
Exemplo n.º 13
0
        // private methods -----------------------------------------------------

        private static RuleBasedCollator GetThaiCollator()
        {
            if (m_collator_ == null)
            {
                m_collator_ = (RuleBasedCollator)Collator.GetInstance(
                    new CultureInfo("th-TH"));
            }
            return(m_collator_);
        }
Exemplo n.º 14
0
        public void TestRules()
        {
            String[] testSourceCases =
            {
                "\u0061\u0062\u007a",
                "\u0061\u0062\u007a",
            };

            String[] testTargetCases =
            {
                "\u0061\u0062\u00e4",
                "\u0061\u0062\u0061\u0308",
            };

            int i = 0;

            Logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
            Collator col       = Collator.GetInstance(new CultureInfo("en-US"));
            String   baseRules = ((RuleBasedCollator)col).GetRules();
            String   newRules  = " & z < ";

            newRules = baseRules + newRules + (0x00e4).ToString(CultureInfo.InvariantCulture);
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Warnln("Demo Test 1 Table Collation object creation failed.");
                return;
            }

            for (i = 0; i < 2; i++)
            {
                doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
            }
            Logln("Demo Test 2 : Create a new table collation with rules \"& z < a 0x0308\"");
            newRules = "";
            newRules = baseRules + " & z < a" + (0x0308).ToString(CultureInfo.InvariantCulture);
            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Demo Test 1 Table Collation object creation failed.");
                return;
            }
            for (i = 0; i < 2; i++)
            {
                doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
            }
        }
Exemplo n.º 15
0
        public void TestThreadSafe()
        {
            int iters = 20 * RandomMultiplier;

            for (int i = 0; i < iters; i++)
            {
                CultureInfo locale   = new CultureInfo("de");
                Collator    collator = Collator.GetInstance(locale);
                collator.Strength = CollationStrength.Identical;
                AssertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator));
            }
        }
Exemplo n.º 16
0
 public void TestCollator()
 {
     CheckService("ja_JP_YOKOHAMA", new ServiceFacade(create: (req) =>
     {
         return(Collator.GetInstance(req));
     }), null, new Registrar(register: (loc, prototype) =>
     {
         return(Collator.RegisterInstance((Collator)prototype, loc));
     }, unregister: (key) =>
     {
         return(Collator.Unregister(key));
     }));
 }
Exemplo n.º 17
0
        public void TestRanges()
        {
            Directory         dir = NewDirectory();
            RandomIndexWriter iw  = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, dir);
            Document doc      = new Document();
            Field    field    = NewField("field", "", StringField.TYPE_STORED);
            Collator collator = Collator.GetInstance(CultureInfo.CurrentCulture); // uses -Dtests.locale

            if (Random.nextBoolean())
            {
                collator.Strength = CollationStrength.Primary;
            }
            ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);

            doc.Add(field);
            doc.Add(collationField);

            int numDocs = AtLeast(500);

            for (int i = 0; i < numDocs; i++)
            {
                String value = TestUtil.RandomSimpleString(Random);
                field.SetStringValue(value);
                collationField.SetStringValue(value);
                iw.AddDocument(doc);
            }

            IndexReader ir = iw.GetReader();

            iw.Dispose();
            IndexSearcher @is = NewSearcher(ir);

            int numChecks = AtLeast(100);

            for (int i = 0; i < numChecks; i++)
            {
                String   start    = TestUtil.RandomSimpleString(Random);
                String   end      = TestUtil.RandomSimpleString(Random);
                BytesRef lowerVal = new BytesRef(collator.GetCollationKey(start).ToByteArray());
                BytesRef upperVal = new BytesRef(collator.GetCollationKey(end).ToByteArray());
                Query    query    = new ConstantScoreQuery(FieldCacheRangeFilter.NewBytesRefRange("collated", lowerVal, upperVal, true, true));
                DoTestRanges(@is, start, end, query, collator);
            }

            ir.Dispose();
            dir.Dispose();
        }
Exemplo n.º 18
0
        public void TestUnicodeChar()
        {
            RuleBasedCollator        en_us = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en-US"));
            CollationElementIterator iter;
            char         codepoint;
            StringBuffer source = new StringBuffer();

            source.Append("\u0e4d\u0e4e\u0e4f");
            // source.append("\u04e8\u04e9");
            iter = en_us.GetCollationElementIterator(source.ToString());
            // A basic test to see if it's working at all
            CollationTest.BackAndForth(this, iter);
            for (codepoint = (char)1; codepoint < 0xFFFE;)
            {
                source.Delete(0, source.Length);
                while (codepoint % 0xFF != 0)
                {
                    if (UChar.IsDefined(codepoint))
                    {
                        source.Append(codepoint);
                    }
                    codepoint++;
                }

                if (UChar.IsDefined(codepoint))
                {
                    source.Append(codepoint);
                }

                if (codepoint != 0xFFFF)
                {
                    codepoint++;
                }

                /*if (codepoint >= 0x04fc) {
                 *  System.out.println("codepoint " + Integer.toHexString(codepoint));
                 *  String str = source.substring(230, 232);
                 *  System.out.println(com.ibm.icu.impl.Utility.escape(str));
                 *  System.out.println("codepoint " + Integer.toHexString(codepoint)
                 + "length " + str.Length);
                 +  iter = en_us.GetCollationElementIterator(str);
                 +  CollationTest.BackAndForth(this, iter);
                 + }
                 */
                iter = en_us.GetCollationElementIterator(source.ToString());
                // A basic test to see if it's working at all
                CollationTest.BackAndForth(this, iter);
            }
        }
Exemplo n.º 19
0
        public void TestRuleVsLocaleCreationMonkey()
        {
            //create a RBC from a collator reader by reading in a locale collation file
            //also create one simply from a rules string (which should be
            //pulled from the locale collation file)
            //and then do crazy monkey testing on it to make sure they are the same.
            int          x, y, z;
            Random       r = CreateRandom();
            String       randString1;
            CollationKey key1;
            CollationKey key2;


            CultureInfo[] locales = Collator.GetAvailableLocales();

            RuleBasedCollator localeCollator;
            RuleBasedCollator ruleCollator;

            for (z = 0; z < 60; z++)
            {
                x = r.Next(locales.Length);
                CultureInfo locale = locales[x];

                try
                {
                    //this is making the assumption that the only type of collator that will be made is RBC
                    localeCollator = (RuleBasedCollator)Collator.GetInstance(locale);
                    Logln("Rules for " + locale + " are: " + localeCollator.GetRules());
                    ruleCollator = new RuleBasedCollator(localeCollator.GetRules());
                }
                catch (Exception e)
                {
                    Warnln("ERROR: in creation of collator of locale " + locale.DisplayName + ": " + e);
                    return;
                }

                //do it several times for each collator
                int n = 3;
                for (y = 0; y < n; y++)
                {
                    randString1 = GenerateNewString(r);

                    key1 = localeCollator.GetCollationKey(randString1);
                    key2 = ruleCollator.GetCollationKey(randString1);

                    Report(locale.DisplayName, randString1, key1, key2);
                }
            }
        }
Exemplo n.º 20
0
        public void TestCollationKeySort()
        {
            Analyzer usAnalyzer = new TestAnalyzer(Collator.GetInstance(new CultureInfo("en-us")));
            Analyzer franceAnalyzer
                = new TestAnalyzer(Collator.GetInstance(new CultureInfo("fr")));
            Analyzer swedenAnalyzer
                = new TestAnalyzer(Collator.GetInstance(new CultureInfo("sv-se")));
            Analyzer denmarkAnalyzer
                = new TestAnalyzer(Collator.GetInstance(new CultureInfo("da-dk")));

            // The ICU Collator and java.text.Collator implementations differ in their
            // orderings - "BFJHD" is the ordering for the ICU Collator for Locale.US.
            TestCollationKeySort
                (usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer,
                "BFJHD", "ECAGI", "BJDFH", "BJDHF");
        }
Exemplo n.º 21
0
        public void TestJB581()
        {
            String   source = "THISISATEST.";
            String   target = "Thisisatest.";
            Collator coll   = null;

            try
            {
                coll = Collator.GetInstance(new CultureInfo("en") /*Locale.ENGLISH*/);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for : en_US\n");
                return;
            }

            int result = coll.Compare(source, target);

            // result is 1, secondary differences only for ignorable space characters
            if (result != 1)
            {
                Errln("Comparing two strings with only secondary differences in C failed.\n");
                return;
            }

            // To compare them with just primary differences
            coll.Strength = (Collator.PRIMARY);
            result        = coll.Compare(source, target);
            // result is 0
            if (result != 0)
            {
                Errln("Comparing two strings with no differences in C failed.\n");
                return;
            }

            // Now, do the same comparison with keys
            CollationKey sourceKeyOut, targetKeyOut;

            sourceKeyOut = coll.GetCollationKey(source);
            targetKeyOut = coll.GetCollationKey(target);
            result       = sourceKeyOut.CompareTo(targetKeyOut);
            if (result != 0)
            {
                Errln("Comparing two strings with sort keys in C failed.\n");
                return;
            }
        }
Exemplo n.º 22
0
        internal static Analyzer CreateAnalyzer(CultureInfo locale, Implementation impl)
        {
            // LUCENENET specific - senseless to use reflection here because we only have one
            // collator.
            object collator = Collator.GetInstance(locale);

            // LUCENENET TODO: The .NET equivalent to create a collator like the one in the JDK is:
            //CompareInfo.GetCompareInfo(locale.Name);

            Type clazz = impl.GetAnalyzerType();

            return((Analyzer)Activator.CreateInstance(clazz,
#pragma warning disable 612, 618
                                                      LuceneVersion.LUCENE_CURRENT,
#pragma warning restore 612, 618
                                                      collator));
        }
Exemplo n.º 23
0
        public void TestFrozen()
        {
            Collator theCollator = Collator.GetInstance(new CultureInfo("pl"));

            theCollator.Freeze();
            Random  r       = new Random();
            Control control = new Control();

            Thread[] threads = new Thread[10];
            for (int i = 0; i < threads.Length; ++i)
            {
                Test test = new Test("Frozen collation test thread " + i, (string[])threadTestData.Clone(), theCollator,
                                     r, control);
                threads[i] = new Thread(() => test.Run());
            }

            RunThreads(threads, control);
        }
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBean", typeof(SupportBean));

            string frenchForSin   = "p\u00E9ch\u00E9";
            string frenchForFruit = "p\u00EAche";

            string[] sortedFrench = new string[] {
                frenchForFruit,
                frenchForSin
            };

            // CurrentCulture cannot be assigned in .NET 4.5 and below

#if NET46 || NET47 || NETSTANDARD2_0
            var englishUS         = CultureInfo.GetCultureInfo("en-US");
            var englishUSComparer = StringComparer.Create(englishUS, false);

            CultureInfo.CurrentCulture = englishUS;

            var french         = CultureInfo.GetCultureInfo("fr-FR");
            var frenchComparer = StringComparer.Create(french, false);

            Assert.AreEqual(1, frenchForFruit.CompareTo(frenchForSin));
            Assert.AreEqual(-1, frenchForSin.CompareTo(frenchForFruit));

            CultureInfo.CurrentCulture = french;

#if FALSE
            Assert.AreEqual(1, frenchForFruit.CompareTo(frenchForSin));
            Assert.AreEqual(-1, frenchComparer.Compare(frenchForFruit, frenchForSin));
            Assert.AreEqual(-1, frenchForSin.CompareTo(frenchForFruit));
            Assert.AreEqual(1, frenchComparer.Compare(frenchForSin, frenchForFruit));
            Assert.IsFalse(frenchForSin.Equals(frenchForFruit));

            Collections.Sort(items);
            Log.Info("Sorted default" + items);

            Collections.Sort(items, new ProxyComparator <string>()
            {
                Collator collator = Collator.GetInstance(Locale.FRANCE);
Exemplo n.º 25
0
        public void TestIllformedLocale()
        {
            ULocale            french   = ULocale.FRENCH;
            Collator           collator = Collator.GetInstance(french);
            LocaleDisplayNames names    = LocaleDisplayNames.GetInstance(french,
                                                                         DisplayContext.CapitalizationForUIListOrMenu);

            foreach (String malformed in new string[] { "en-a", "$", "ü--a", "en--US" })
            {
                try
                {
                    ISet <ULocale> supported = ImmutableHashSet.Create(new ULocale(malformed)); //Collections.singleton(new ULocale(malformed));
                    names.GetUiList(supported, false, collator);
                    assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
                }
                catch (IllformedLocaleException e)
                {
                    Logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.ToString());
                }
            }
        }
Exemplo n.º 26
0
        public void TestG7Data()
        {
            CultureInfo[] locales =
            {
                new CultureInfo("en-US") /* Locale.US */,
                new CultureInfo("en-GB") /* Locale.UK */,
                new CultureInfo("en-CA") /* Locale.CANADA */,
                new CultureInfo("fr-FR") /* Locale.FRANCE */,
                new CultureInfo("fr-CA") /* Locale.CANADA_FRENCH */,
                new CultureInfo("de-DE") /* Locale.GERMANY */,
                new CultureInfo("ja-JP") /* Locale.JAPAN */,
                new CultureInfo("it-IT") /* Locale.ITALY */
            };
            int i = 0, j = 0;

            for (i = 0; i < locales.Length; i++)
            {
                Collator          myCollation = null;
                RuleBasedCollator tblColl1    = null;
                try
                {
                    myCollation = Collator.GetInstance(locales[i]);
                    tblColl1    = new RuleBasedCollator(((RuleBasedCollator)myCollation).GetRules());
                }
                catch (Exception foo)
                {
                    Warnln("Exception: " + foo.Message +
                           "; Locale : " + locales[i].DisplayName + " getRules failed");
                    continue;
                }
                for (j = 0; j < FIXEDTESTSET; j++)
                {
                    for (int n = j + 1; n < FIXEDTESTSET; n++)
                    {
                        DoTest(tblColl1, testCases[results[i][j]], testCases[results[i][n]], -1);
                    }
                }
                myCollation = null;
            }
        }
Exemplo n.º 27
0
        public void TestCommonCharacters()
        {
            char[]            tmp1 = { (char)0x3058, (char)0x30B8 };
            char[]            tmp2 = { (char)0x3057, (char)0x3099, (char)0x30B7, (char)0x3099 };
            CollationKey      key1, key2;
            int               result;
            String            string1 = new String(tmp1);
            String            string2 = new String(tmp2);
            RuleBasedCollator rb      = (RuleBasedCollator)Collator.GetInstance(ULocale.JAPANESE);

            rb.Strength = (Collator.QUATERNARY);
            rb.IsAlternateHandlingShifted = (false);

            result = rb.Compare(string1, string2);

            key1 = rb.GetCollationKey(string1);
            key2 = rb.GetCollationKey(string2);

            if (result != 0 || !key1.Equals(key2))
            {
                Errln("Failed Hiragana and Katakana common characters test. Expected results to be equal.");
            }
        }
Exemplo n.º 28
0
        public void TestPinYin()
        {
            String[] seq
                = { "\u963f", "\u554a", "\u54ce", "\u6371", "\u7231", "\u9f98",
                    "\u4e5c", "\u8baa", "\u4e42", "\u53c8" };
            RuleBasedCollator collator = null;

            try
            {
                collator = (RuleBasedCollator)Collator.GetInstance(
                    // ICU4N: See: https://stackoverflow.com/questions/9416435/what-culture-code-should-i-use-for-pinyin#comment11937203_9421566
                    new CultureInfo("zh-Hans"));                             //("zh", "", "PINYIN")); // ICU4N TODO: Can we replicate the 3rd parameter somehow?
            }
            catch (Exception e)
            {
                Warnln("ERROR: in creation of collator of zh__PINYIN locale");
                return;
            }
            for (int i = 0; i < seq.Length - 1; i++)
            {
                CollationTest.DoTest(this, collator, seq[i], seq[i + 1], -1);
            }
        }
Exemplo n.º 29
0
 public void Init()
 {
     myCollation = Collator.GetInstance(new CultureInfo("ko") /* Locale.KOREAN */);
     myCollation.Decomposition = (Collator.CANONICAL_DECOMPOSITION);
 }
Exemplo n.º 30
0
        public void TestBasic()
        {
            Directory         dir = NewDirectory();
            RandomIndexWriter iw  = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, dir);
            Document doc   = new Document();
            Field    field = NewField("field", "", StringField.TYPE_STORED);
            ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", Collator.GetInstance(new CultureInfo("en")));

            doc.Add(field);
            doc.Add(collationField);

            field.SetStringValue("ABC");
            collationField.SetStringValue("ABC");
            iw.AddDocument(doc);

            field.SetStringValue("abc");
            collationField.SetStringValue("abc");
            iw.AddDocument(doc);

            IndexReader ir = iw.GetReader();

            iw.Dispose();

            IndexSearcher @is = NewSearcher(ir);

            SortField sortField = new SortField("collated", SortFieldType.STRING);

            TopDocs td = @is.Search(new MatchAllDocsQuery(), 5, new Sort(sortField));

            assertEquals("abc", ir.Document(td.ScoreDocs[0].Doc).Get("field"));
            assertEquals("ABC", ir.Document(td.ScoreDocs[1].Doc).Get("field"));
            ir.Dispose();
            dir.Dispose();
        }