public DictionaryInfo() { _author = null; _contents = null; _copyrightNotice = null; _foreignLanguageCollationRules = null; _foreignLanguageName = null; _nativeLanguageCollationRules = null; _nativeLanguageName = null; _title = null; _versionInfo = null; _foreignCollator = null; _nativeCollator = null; }
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); } }
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 = new HashSet <ULocale> { 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()); } } }
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."); } }
/* * Create a locale from language, with optional country and variant. * Then return the appropriate collator for the locale. */ private Collator createFromLocale(string language, string country, string variant) { Locale locale; if (language != null && country == null && variant != null) { throw new System.ArgumentException("To specify variant, country is required"); } else if (language != null && country != null && variant != null) { locale = new Locale(language, country, variant); } else if (language != null && country != null) { locale = new Locale(language, country); } else { locale = new Locale(language); } return(Collator.getInstance(locale)); }
public virtual void TestCustomRules() { // It is possible not to have the collator rules for a specific // country, fallback to the language if that is the case. var possiblelocales = new[] { new Locale("de-DE"), new Locale("de") }; var allRules = RuleBasedCollator.GetAvailableCollationLocales(); var localeToUse = possiblelocales.FirstOrDefault(locl => allRules.Contains(locl.Id)); Assert.True(localeToUse != default, "Should have found a matching collation locale given the two locales to use."); const string DIN5007_2_tailorings = "& ae , a\u0308 & AE , A\u0308" + "& oe , o\u0308 & OE , O\u0308" + "& ue , u\u0308 & UE , u\u0308"; var collationRules = Collator.GetCollationRules(localeToUse.Id); Assert.IsNotNull(collationRules, $"Rules should have been fetched for {localeToUse.Id}"); string tailoredRules = collationRules + DIN5007_2_tailorings; RuleBasedCollator tailoredCollator = new RuleBasedCollator(tailoredRules); // 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["custom"] = "rules.txt"; args["strength"] = "primary"; #pragma warning disable 612, 618 CollationKeyFilterFactory factory = new CollationKeyFilterFactory(args); #pragma warning restore 612, 618 factory.Inform(new StringMockResourceLoader(tailoredRules)); TokenStream tsUmlaut = factory.Create(new MockTokenizer(new StringReader(germanUmlaut), MockTokenizer.KEYWORD, false)); TokenStream tsOE = factory.Create(new MockTokenizer(new StringReader(germanOE), MockTokenizer.KEYWORD, false)); AssertCollatesToSame(tsUmlaut, tsOE); }
/// <summary> /// Create a new <see cref="CollationKeyAnalyzer"/>, using the specified collator. /// </summary> /// <param name="matchVersion"> See <see cref="CollationKeyAnalyzer"/> </param> /// <param name="collator"> <see cref="System.Globalization.SortKey"/> generator </param> public CollationKeyAnalyzer(LuceneVersion matchVersion, Collator collator) { this.matchVersion = matchVersion; this.collator = collator; this.factory = new CollationAttributeFactory(collator); }
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(); }
public virtual void Inform(IResourceLoader loader) { if (this.language != null) { // create from a system collator, based on Locale. this.collator = this.CreateFromLocale(this.language, this.country, this.variant); } else { // create from a custom ruleset this.collator = this.CreateFromRules(this.custom, loader); } // set the strength flag, otherwise it will be the default. if (this.strength != null) { if (this.strength.Equals("primary", StringComparison.OrdinalIgnoreCase)) { this.collator.Strength = CollationStrength.Primary; } else if (this.strength.Equals("secondary", StringComparison.OrdinalIgnoreCase)) { this.collator.Strength = CollationStrength.Secondary; } else if (this.strength.Equals("tertiary", StringComparison.OrdinalIgnoreCase)) { this.collator.Strength = CollationStrength.Tertiary; } else if (this.strength.Equals("identical", StringComparison.OrdinalIgnoreCase)) { this.collator.Strength = CollationStrength.Identical; } else { throw new ArgumentException("Invalid strength: " + this.strength); } } // LUCENENET TODO: Verify Decomposition > NormalizationMode mapping between the JDK and icu-dotnet // set the decomposition flag, otherwise it will be the default. if (this.decomposition != null) { if (this.decomposition.Equals("no", StringComparison.OrdinalIgnoreCase)) { this.collator.NormalizationMode = NormalizationMode.Default; // .Decomposition = Collator.NoDecomposition; } else if (this.decomposition.Equals("canonical", StringComparison.OrdinalIgnoreCase)) { this.collator.NormalizationMode = NormalizationMode.Off; //.Decomposition = Collator.CannonicalDecomposition; } else if (this.decomposition.Equals("full", StringComparison.OrdinalIgnoreCase)) { this.collator.NormalizationMode = NormalizationMode.On; //.Decomposition = Collator.FullDecomposition; } else { throw new ArgumentException("Invalid decomposition: " + this.decomposition); } } }
public void Test_compareLjava_lang_ObjectLjava_lang_Object() { Collator c = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.FRENCH); Object o, o2; c.SetStrength(ILOG.J2CsMapping.Text.Collator.IDENTICAL); o = "E"; o2 = "F"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on primary difference"); o = "e"; o2 = "\u00e9"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on secondary difference"); o = "e"; o2 = "E"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on tertiary difference"); o = "\u0001"; o2 = "\u0002"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on identical"); o = "e"; o2 = "e"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "a) Failed on equivalence"); NUnit.Framework.Assert.IsTrue(c.Compare("\u01db", "v") < 0, "a) Failed on primary expansion"); c.SetStrength(ILOG.J2CsMapping.Text.Collator.TERTIARY); o = "E"; o2 = "F"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on primary difference"); o = "e"; o2 = "\u00e9"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on secondary difference"); o = "e"; o2 = "E"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on tertiary difference"); o = "\u0001"; o2 = "\u0002"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "b) Failed on identical"); o = "e"; o2 = "e"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "b) Failed on equivalence"); c.SetStrength(ILOG.J2CsMapping.Text.Collator.SECONDARY); o = "E"; o2 = "F"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "c) Failed on primary difference"); o = "e"; o2 = "\u00e9"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "c) Failed on secondary difference"); o = "e"; o2 = "E"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on tertiary difference"); o = "\u0001"; o2 = "\u0002"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on identical"); o = "e"; o2 = "e"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on equivalence"); c.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY); o = "E"; o2 = "F"; NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "d) Failed on primary difference"); o = "e"; o2 = "\u00e9"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on secondary difference"); o = "e"; o2 = "E"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on tertiary difference"); o = "\u0001"; o2 = "\u0002"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on identical"); o = "e"; o2 = "e"; NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on equivalence"); try { c.Compare("e", new StringBuilder("Blah")); } catch (InvalidCastException e) { // correct return; } NUnit.Framework.Assert.Fail("Failed to throw ClassCastException"); }
public virtual void Inform(IResourceLoader loader) { if (localeID != null) { // create from a system collator, based on Locale. collator = CreateFromLocale(localeID); } else { // create from a custom ruleset collator = CreateFromRules(custom, loader); } // set the strength flag, otherwise it will be the default. if (strength != null) { if (strength.Equals("primary", StringComparison.OrdinalIgnoreCase)) { collator.Strength = CollationStrength.Primary; } else if (strength.Equals("secondary", StringComparison.OrdinalIgnoreCase)) { collator.Strength = CollationStrength.Secondary; } else if (strength.Equals("tertiary", StringComparison.OrdinalIgnoreCase)) { collator.Strength = CollationStrength.Tertiary; } else if (strength.Equals("quaternary", StringComparison.OrdinalIgnoreCase)) { collator.Strength = CollationStrength.Quaternary; } else if (strength.Equals("identical", StringComparison.OrdinalIgnoreCase)) { collator.Strength = CollationStrength.Identical; } else { throw new ArgumentException("Invalid strength: " + strength); } } // set the decomposition flag, otherwise it will be the default. if (decomposition != null) { if (decomposition.Equals("no", StringComparison.OrdinalIgnoreCase)) { collator.NormalizationMode = NormalizationMode.Off; // (Collator.NO_DECOMPOSITION); } else if (decomposition.Equals("canonical", StringComparison.OrdinalIgnoreCase)) { collator.NormalizationMode = NormalizationMode.On; //.setDecomposition(Collator.CANONICAL_DECOMPOSITION); } else { throw new ArgumentException("Invalid decomposition: " + decomposition); } } // expert options: concrete subclasses are always a RuleBasedCollator RuleBasedCollator rbc = (RuleBasedCollator)collator; if (alternate != null) { if (alternate.Equals("shifted", StringComparison.OrdinalIgnoreCase)) { rbc.AlternateHandling = AlternateHandling.Shifted;// .setAlternateHandlingShifted(true); } else if (alternate.Equals("non-ignorable", StringComparison.OrdinalIgnoreCase)) { rbc.AlternateHandling = AlternateHandling.NonIgnorable; //.setAlternateHandlingShifted(false); } else { throw new ArgumentException("Invalid alternate: " + alternate); } } if (caseLevel != null) { rbc.CaseLevel = bool.Parse(caseLevel) ? CaseLevel.On : CaseLevel.Off; // setCaseLevel(Boolean.parseBoolean(caseLevel)); } if (caseFirst != null) { if (caseFirst.Equals("lower", StringComparison.OrdinalIgnoreCase)) { rbc.CaseFirst = CaseFirst.LowerFirst; //.setLowerCaseFirst(true); } else if (caseFirst.Equals("upper", StringComparison.OrdinalIgnoreCase)) { rbc.CaseFirst = CaseFirst.UpperFirst; //.setUpperCaseFirst(true); } else { throw new ArgumentException("Invalid caseFirst: " + caseFirst); } } if (numeric != null) { rbc.NumericCollation = bool.Parse(numeric) ? NumericCollation.On : NumericCollation.Off; //.setNumericCollation(Boolean.parseBoolean(numeric)); } // LUCENENET TODO: variableTop is not supported by icu.net. Besides this, // it is deprecated as of ICU 53 and has been superceded by maxVariable, // but that feature is also not supported by icu.net at the time of this writing. //if (variableTop != null) //{ // rbc.setVariableTop(variableTop); //} }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testCollationKeySort() throws Exception public virtual void testCollationKeySort() { Analyzer usAnalyzer = new CollationKeyAnalyzer(TEST_VERSION_CURRENT, Collator.getInstance(Locale.US)); Analyzer franceAnalyzer = new CollationKeyAnalyzer(TEST_VERSION_CURRENT, Collator.getInstance(Locale.FRANCE)); Analyzer swedenAnalyzer = new CollationKeyAnalyzer(TEST_VERSION_CURRENT, Collator.getInstance(new Locale("sv", "se"))); Analyzer denmarkAnalyzer = new CollationKeyAnalyzer(TEST_VERSION_CURRENT, Collator.getInstance(new Locale("da", "dk"))); // The ICU Collator and Sun java.text.Collator implementations differ in their // orderings - "BFJDH" is the ordering for java.text.Collator for Locale.US. testCollationKeySort(usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer, oStrokeFirst ? "BFJHD" : "BFJDH", "EACGI", "BJDFH", "BJDHF"); }
/// <summary> /// Create a <see cref="CollationAttributeFactory"/>, using /// <see cref="AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY"/> as the /// factory for all other attributes. </summary> /// <param name="collator"> <see cref="System.Globalization.SortKey"/> generator </param> public CollationAttributeFactory(Collator collator) : this(AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY, collator) { }
/// <summary> /// Adds a new <see cref="ICUCollationDocValuesField"/>. /// <para/> /// NOTE: you should not create a new one for each document, instead /// just make one and reuse it during your indexing process, setting /// the value via <see cref="ICUCollationDocValuesField.SetStringValue(string)"/>. /// </summary> /// <param name="document">This <see cref="Document"/>.</param> /// <param name="name">Field name.</param> /// <param name="collator">Collator for generating collation keys.</param> /// <returns>The field that was added to this <see cref="Document"/>.</returns> public static ICUCollationDocValuesField AddICUCollationDocValuesField(this Document document, string name, Collator collator) { var field = new ICUCollationDocValuesField(name, collator); document.Add(field); return(field); }
public void TestCollationKey() { if (source.Length == 0) { Errln("CollationMonkeyTest.TestCollationKey(): source is empty - ICU_DATA not set or data missing?"); return; } Collator myCollator; try { myCollator = Collator.GetInstance(new CultureInfo("en-US")); } catch (Exception e) { Warnln("ERROR: in creation of collator of ENGLISH locale"); return; } Random rand = CreateRandom(); // use test framework's random seed int s = rand.Next(0x7fff) % source.Length; int t = rand.Next(0x7fff) % source.Length; int slen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; int tlen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; String subs = source.Substring(Math.Min(s, slen), Math.Min(s + slen, source.Length) - Math.Min(s, slen)); // ICU4N: Corrected 2nd parameter String subt = source.Substring(Math.Min(t, tlen), Math.Min(t + tlen, source.Length) - Math.Min(t, tlen)); // ICU4N: Corrected 2nd parameter CollationKey collationKey1, collationKey2; myCollator.Strength = (Collator.Tertiary); collationKey1 = myCollator.GetCollationKey(subs); collationKey2 = myCollator.GetCollationKey(subt); int result = collationKey1.CompareTo(collationKey2); // Tertiary int revResult = collationKey2.CompareTo(collationKey1); // Tertiary report(subs, subt, result, revResult); myCollator.Strength = (Collator.Secondary); collationKey1 = myCollator.GetCollationKey(subs); collationKey2 = myCollator.GetCollationKey(subt); result = collationKey1.CompareTo(collationKey2); // Secondary revResult = collationKey2.CompareTo(collationKey1); // Secondary report(subs, subt, result, revResult); myCollator.Strength = (Collator.Primary); collationKey1 = myCollator.GetCollationKey(subs); collationKey2 = myCollator.GetCollationKey(subt); result = collationKey1.CompareTo(collationKey2); // Primary revResult = collationKey2.CompareTo(collationKey1); // Primary report(subs, subt, result, revResult); String msg = ""; String addOne = subs + (0xE000).ToString(CultureInfo.InvariantCulture); collationKey1 = myCollator.GetCollationKey(subs); collationKey2 = myCollator.GetCollationKey(addOne); result = collationKey1.CompareTo(collationKey2); if (result != -1) { msg += "CollationKey("; msg += subs; msg += ") .LT. CollationKey("; msg += addOne; msg += ") Failed."; Errln(msg); } msg = ""; result = collationKey2.CompareTo(collationKey1); if (result != 1) { msg += "CollationKey("; msg += addOne; msg += ") .GT. CollationKey("; msg += subs; msg += ") Failed."; Errln(msg); } }
/// <summary> /// Create a new CollationKeyAnalyzer, using the specified collator. /// </summary> /// <param name="matchVersion"> See <a href="#version">above</a> </param> /// <param name="collator"> CollationKey generator </param> public CollationKeyAnalyzer(Version matchVersion, Collator collator) { this.matchVersion = matchVersion; this.collator = collator; this.factory = new CollationAttributeFactory(collator); }
/// <summary> /// Create a new CollatedTermAttributeImpl </summary> /// <param name="collator"> Collation key generator </param> public CollatedTermAttributeImpl(Collator collator) { // clone in case JRE doesn't properly sync, // or to reduce contention in case they do this.collator = (Collator) collator.clone(); }
/// <summary> /// Create a CollationAttributeFactory, using the supplied Attribute Factory /// as the factory for all other attributes. </summary> /// <param name="delegate"> Attribute Factory </param> /// <param name="collator"> CollationKey generator </param> public CollationAttributeFactory(AttributeSource.AttributeFactory @delegate, Collator collator) { this.@delegate = @delegate; this.collator = collator; }
/// <summary> /// Create a CollationAttributeFactory, using /// <seealso cref="org.apache.lucene.util.AttributeSource.AttributeFactory#DEFAULT_ATTRIBUTE_FACTORY"/> as the /// factory for all other attributes. </summary> /// <param name="collator"> CollationKey generator </param> public CollationAttributeFactory(Collator collator) : this(AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY, collator) { }
public void TestCompare() { if (source.Length == 0) { Errln("CollationMonkeyTest.TestCompare(): source is empty - ICU_DATA not set or data missing?"); return; } Collator myCollator; try { myCollator = Collator.GetInstance(new CultureInfo("en-US")); } catch (Exception e) { Warnln("ERROR: in creation of collator of ENGLISH locale"); return; } /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ Random rand = CreateRandom(); // use test framework's random seed int s = rand.Next(0x7fff) % source.Length; int t = rand.Next(0x7fff) % source.Length; int slen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; int tlen = Math.Abs(rand.Next(0x7fff) % source.Length - source.Length) % source.Length; String subs = source.Substring(Math.Min(s, slen), Math.Min(s + slen, source.Length) - Math.Min(s, slen)); // ICU4N: Corrected 2nd parameter String subt = source.Substring(Math.Min(t, tlen), Math.Min(t + tlen, source.Length) - Math.Min(t, tlen)); // ICU4N: Corrected 2nd parameter myCollator.Strength = (Collator.Tertiary); int result = myCollator.Compare(subs, subt); // Tertiary int revResult = myCollator.Compare(subt, subs); // Tertiary report(subs, subt, result, revResult); myCollator.Strength = (Collator.Secondary); result = myCollator.Compare(subs, subt); // Secondary revResult = myCollator.Compare(subt, subs); // Secondary report(subs, subt, result, revResult); myCollator.Strength = (Collator.Primary); result = myCollator.Compare(subs, subt); // Primary revResult = myCollator.Compare(subt, subs); // Primary report(subs, subt, result, revResult); String msg = ""; String addOne = subs + (0xE000).ToString(CultureInfo.InvariantCulture); result = myCollator.Compare(subs, addOne); if (result != -1) { msg += "Test : "; msg += subs; msg += " .LT. "; msg += addOne; msg += " Failed."; Errln(msg); } msg = ""; result = myCollator.Compare(addOne, subs); if (result != 1) { msg += "Test : "; msg += addOne; msg += " .GT. "; msg += subs; msg += " Failed."; Errln(msg); } }
internal TestAnalyzer(TestCollationKeyFilter outerInstance, Collator collator) { this.outerInstance = outerInstance; _collator = collator; }
/// <param name="input"> Source token stream </param> /// <param name="collator"> CollationKey generator </param> public CollationKeyFilter(TokenStream input, Collator collator) : base(input) { this.collator = collator; this.termAtt = this.AddAttribute <ICharTermAttribute>(); }
public void Init() { myCollation = Collator.GetInstance(new CultureInfo("ko") /* Locale.KOREAN */); myCollation.Decomposition = (Collator.CanonicalDecomposition); }
/// <summary> /// Create a <see cref="CollationAttributeFactory"/>, using the supplied Attribute Factory /// as the factory for all other attributes. </summary> /// <param name="delegate"> Attribute Factory </param> /// <param name="collator"> <see cref="System.Globalization.SortKey"/> generator </param> public CollationAttributeFactory(AttributeSource.AttributeFactory @delegate, Collator collator) { this.@delegate = @delegate; this.collator = collator; }
internal IDictionary <object, object> displayNames; // locale -> string internal CollatorInfo(UCultureInfo locale, Collator collator, IDictionary <object, object> displayNames) { this.locale = locale; this.collator = collator; this.displayNames = displayNames; }
/// <summary> /// Create a locale from <paramref name="localeID"/>. /// Then return the appropriate collator for the locale. /// </summary> /// <param name="localeID"></param> /// <returns>The appropriate collator for the locale.</returns> private Collator CreateFromLocale(string localeID) { return(Collator.Create(localeID)); }
public void TestRegister() { // register a singleton Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR")); Collator uscol = Collator.GetInstance(new UCultureInfo("en_US")); { // try override en_US collator Object key = Collator.RegisterInstance(frcol, new UCultureInfo("en_US")); Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!frcol.Equals(ncol)) { Errln("register of french collator for en_US failed"); } // coverage Collator test = Collator.GetInstance(new UCultureInfo("de_DE")); // CollatorFactory.handleCreate if (!test.ValidCulture.Equals(new UCultureInfo("de"))) { Errln("Collation from Germany is really " + test.ValidCulture); } if (!Collator.Unregister(key)) { Errln("failed to unregister french collator"); } ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!uscol.Equals(ncol)) { Errln("collator after unregister does not match original"); } } UCultureInfo fu_FU = new UCultureInfo("fu_FU_FOO"); { // try create collator for new locale Collator fucol = Collator.GetInstance(fu_FU); Object key = Collator.RegisterInstance(frcol, fu_FU); Collator ncol = Collator.GetInstance(fu_FU); if (!frcol.Equals(ncol)) { Errln("register of fr collator for fu_FU failed"); } UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); bool found = false; for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { found = true; break; } } if (!found) { Errln("new locale fu_FU not reported as supported locale"); } try { String name = Collator.GetDisplayName(fu_FU); if (!"fu (FU, FOO)".Equals(name) && !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */) { Errln("found " + name + " for fu_FU"); } } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } try { String name = Collator.GetDisplayName(fu_FU, fu_FU); if (!"fu (FU, FOO)".Equals(name) && !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */) { Errln("found " + name + " for fu_FU"); } } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } if (!Collator.Unregister(key)) { Errln("failed to unregister french collator"); } ncol = Collator.GetInstance(fu_FU); if (!fucol.Equals(ncol)) { Errln("collator after unregister does not match original fu_FU"); } } { // coverage after return to default UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { Errln("new locale fu_FU not reported as supported locale"); break; } } Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!ncol.ValidCulture.Equals(new UCultureInfo("en_US"))) { Errln("Collation from US is really " + ncol.ValidCulture); } } }
public void Init() { myCollation = Collator.GetInstance(new CultureInfo("tr")); }
public void TestRegisterFactory() { UCultureInfo fu_FU = new UCultureInfo("fu_FU"); UCultureInfo fu_FU_FOO = new UCultureInfo("fu_FU_FOO"); IDictionary <object, object> fuFUNames = new Dictionary <object, object> { { fu_FU, "ze leetle bunny Fu-Fu" }, { fu_FU_FOO, "zee leetel bunny Foo-Foo" }, { new UCultureInfo("en_US"), "little bunny Foo Foo" } }; Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR")); /* Collator uscol = */ Collator.GetInstance(new UCultureInfo("en_US")); Collator gecol = Collator.GetInstance(new UCultureInfo("de_DE")); Collator jpcol = Collator.GetInstance(new UCultureInfo("ja_JP")); Collator fucol = Collator.GetInstance(fu_FU); CollatorInfo[] info = { new CollatorInfo(new UCultureInfo("en_US"), frcol, null), new CollatorInfo(new UCultureInfo("fr_FR"), gecol, null), new CollatorInfo(fu_FU, jpcol, fuFUNames), }; TestFactory factory = null; try { factory = new TestFactory(info); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } // coverage { TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference! Object key = Collator.RegisterFactory(wrapper); String name = null; try { name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } Logln("*** default name: " + name); Collator.Unregister(key); UCultureInfo bar_BAR = new UCultureInfo("bar_BAR"); Collator col = Collator.GetInstance(bar_BAR); UCultureInfo valid = col.ValidCulture; String validName = valid.FullName; if (validName.Length != 0 && !validName.Equals("root")) { Errln("Collation from bar_BAR is really \"" + validName + "\" but should be root"); } } int n1 = checkAvailable("before registerFactory"); { Object key = Collator.RegisterFactory(factory); int n2 = checkAvailable("after registerFactory"); Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!frcol.Equals(ncol)) { Errln("frcoll for en_US failed"); } ncol = Collator.GetInstance(fu_FU_FOO); if (!jpcol.Equals(ncol)) { Errln("jpcol for fu_FU_FOO failed, got: " + ncol); } UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); bool found = false; for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { found = true; break; } } if (!found) { Errln("new locale fu_FU not reported as supported locale"); } String name = Collator.GetDisplayName(fu_FU); if (!"little bunny Foo Foo".Equals(name)) { Errln("found " + name + " for fu_FU"); } name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); if (!"zee leetel bunny Foo-Foo".Equals(name)) { Errln("found " + name + " for fu_FU in fu_FU_FOO"); } if (!Collator.Unregister(key)) { Errln("failed to unregister factory"); } int n3 = checkAvailable("after unregister"); assertTrue("register increases count", n2 > n1); assertTrue("unregister restores count", n3 == n1); ncol = Collator.GetInstance(fu_FU); if (!fucol.Equals(ncol)) { Errln("collator after unregister does not match original fu_FU"); } } }
/// <summary> /// Create a new <see cref="CollatedTermAttributeImpl"/> </summary> /// <param name="collator"> Collation key generator </param> public CollatedTermAttributeImpl(Collator collator) { // clone in case JRE doesn't properly sync, // or to reduce contention in case they do this.collator = (Collator)collator.Clone(); }
public void TestGetKeywordValues() { String[][] PREFERRED = { new string[] { "und", "standard", "eor", "search" }, new string[] { "en_US", "standard", "eor", "search" }, new string[] { "en_029", "standard", "eor", "search" }, new string[] { "de_DE", "standard", "phonebook", "search", "eor"}, new string[] { "de_Latn_DE", "standard", "phonebook", "search", "eor"}, new string[] { "zh", "pinyin", "stroke", "eor", "search", "standard"}, new string[] { "zh_Hans", "pinyin", "stroke", "eor", "search", "standard"}, new string[] { "zh_CN", "pinyin", "stroke", "eor", "search", "standard"}, new string[] { "zh_Hant", "stroke", "pinyin", "eor", "search", "standard"}, new string[] { "zh_TW", "stroke", "pinyin", "eor", "search", "standard"}, new string[] { "zh__PINYIN", "pinyin", "stroke", "eor", "search", "standard"}, new string[] { "es_ES", "standard", "search", "traditional", "eor"}, new string[] { "es__TRADITIONAL", "traditional", "search", "standard", "eor"}, new string[] { "und@collation=phonebook", "standard", "eor", "search" }, new string[] { "de_DE@collation=big5han", "standard", "phonebook", "search", "eor"}, new string[] { "zzz@collation=xxx", "standard", "eor", "search" }, }; for (int i = 0; i < PREFERRED.Length; i++) { String locale = PREFERRED[i][0]; UCultureInfo loc = new UCultureInfo(locale); String[] expected = PREFERRED[i]; String[] pref = Collator.GetKeywordValuesForLocale("collation", loc, true); for (int j = 1; j < expected.Length; ++j) { if (!arrayContains(pref, expected[j])) { Errln("Keyword value " + expected[j] + " missing for locale: " + locale); } } // Collator.getKeywordValues return the same contents for both commonlyUsed // true and false. String[] all = Collator.GetKeywordValuesForLocale("collation", loc, false); bool matchAll = false; if (pref.Length == all.Length) { matchAll = true; for (int j = 0; j < pref.Length; j++) { bool foundMatch = false; for (int k = 0; k < all.Length; k++) { if (pref[j].Equals(all[k])) { foundMatch = true; break; } } if (!foundMatch) { matchAll = false; break; } } } if (!matchAll) { Errln(string.Format(StringFormatter.CurrentCulture, "FAIL: All values for locale {0} got:{1} expected:{2}", loc, all, pref)); } } }
/// <summary> /// Get the summary of the referred to item in the data system to which the supplied collator belongs, cast to a given summary type /// </summary> /// <typeparam name="T">Summary type to get</typeparam> /// <returns>Summary of type T</returns> public virtual T GetSummary <T>(Collator coll) where T : Summary { return(Summary(coll) as T); }
/// <summary> /// Create a new ICUCollatedTermAttribute /// </summary> /// <param name="collator"><see cref="SortKey"/> generator.</param> public ICUCollatedTermAttribute(Collator collator) { // clone the collator: see http://userguide.icu-project.org/collation/architecture this.collator = (Collator)collator.Clone(); }
public CollationKeyAnalyzer(Collator collator) : this(LuceneVersion.LUCENE_31, collator) { }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void inform(ResourceLoader loader) throws java.io.IOException public virtual void inform(ResourceLoader loader) { if (language != null) { // create from a system collator, based on Locale. collator = createFromLocale(language, country, variant); } else { // create from a custom ruleset collator = createFromRules(custom, loader); } // set the strength flag, otherwise it will be the default. if (strength != null) { if (strength.Equals("primary", StringComparison.CurrentCultureIgnoreCase)) { collator.Strength = Collator.PRIMARY; } else if (strength.Equals("secondary", StringComparison.CurrentCultureIgnoreCase)) { collator.Strength = Collator.SECONDARY; } else if (strength.Equals("tertiary", StringComparison.CurrentCultureIgnoreCase)) { collator.Strength = Collator.TERTIARY; } else if (strength.Equals("identical", StringComparison.CurrentCultureIgnoreCase)) { collator.Strength = Collator.IDENTICAL; } else { throw new System.ArgumentException("Invalid strength: " + strength); } } // set the decomposition flag, otherwise it will be the default. if (decomposition != null) { if (decomposition.Equals("no", StringComparison.CurrentCultureIgnoreCase)) { collator.Decomposition = Collator.NO_DECOMPOSITION; } else if (decomposition.Equals("canonical", StringComparison.CurrentCultureIgnoreCase)) { collator.Decomposition = Collator.CANONICAL_DECOMPOSITION; } else if (decomposition.Equals("full", StringComparison.CurrentCultureIgnoreCase)) { collator.Decomposition = Collator.FULL_DECOMPOSITION; } else { throw new System.ArgumentException("Invalid decomposition: " + decomposition); } } }
private void DoTestRanges(IndexSearcher @is, String startPoint, String endPoint, Query query, Collator collator) { QueryUtils.Check(query); // positive test TopDocs docs = @is.Search(query, @is.IndexReader.MaxDoc); foreach (ScoreDoc doc in docs.ScoreDocs) { String value = @is.Doc(doc.Doc).Get("field"); assertTrue(collator.Compare(value, startPoint) >= 0); assertTrue(collator.Compare(value, endPoint) <= 0); } // negative test BooleanQuery bq = new BooleanQuery(); bq.Add(new MatchAllDocsQuery(), Occur.SHOULD); bq.Add(query, Occur.MUST_NOT); docs = @is.Search(bq, @is.IndexReader.MaxDoc); foreach (ScoreDoc doc in docs.ScoreDocs) { String value = @is.Doc(doc.Doc).Get("field"); assertTrue(collator.Compare(value, startPoint) < 0 || collator.Compare(value, endPoint) > 0); } }
/// <param name="input"> Source token stream </param> /// <param name="collator"> CollationKey generator </param> public CollationKeyFilter(TokenStream input, Collator collator) : base(input) { // clone in case JRE doesnt properly sync, // or to reduce contention in case they do this.collator = (Collator) collator.clone(); }
public void Init() { myCollation = Collator.GetInstance(new CultureInfo("ko") /* Locale.KOREAN */); myCollation.Decomposition = (Collator.CANONICAL_DECOMPOSITION); }
public CollationKeyAnalyzer(Collator collator) : this(Version.LUCENE_31, collator) { }