コード例 #1
0
        /// <summary>
        /// Temporary test, just to see how the stuff works.
        /// </summary>
        ///
        static public void Main(String[] args)
        {
            String[]     testCases = { "fiss", "h\u03a3" };
            CaseIterator ci        = new CaseIterator();

            for (int i = 0; i < testCases.Length; ++i)
            {
                String item = testCases[i];
                System.Console.Out.WriteLine();
                System.Console.Out.WriteLine("Testing: " + toName.Transliterate(item));
                System.Console.Out.WriteLine();
                ci.Reset(item);
                int count_0 = 0;
                for (String temp = ci.Next(); temp != null; temp = ci.Next())
                {
                    System.Console.Out.WriteLine(toName.Transliterate(temp));
                    count_0++;
                }
                System.Console.Out.WriteLine("Total: " + count_0);
            }

            // generate a list of all caseless characters -- characters whose
            // case closure is themselves.

            UnicodeSet caseless = new UnicodeSet();

            for (int i_1 = 0; i_1 <= 0x10FFFF; ++i_1)
            {
                String cp = IBM.ICU.Text.UTF16.ValueOf(i_1);
                ci.Reset(cp);
                int    count_2 = 0;
                String fold    = null;
                for (String temp_3 = ci.Next(); temp_3 != null; temp_3 = ci.Next())
                {
                    fold = temp_3;
                    if (++count_2 > 1)
                    {
                        break;
                    }
                }
                if (count_2 == 1 && fold.Equals(cp))
                {
                    caseless.Add(i_1);
                }
            }

            System.Console.Out.WriteLine("caseless = " + caseless.ToPattern(true));

            UnicodeSet not_lc = new UnicodeSet("[:^lc:]");

            UnicodeSet a = new UnicodeSet();

            a.Set(not_lc);
            a.RemoveAll(caseless);
            System.Console.Out.WriteLine("[:^lc:] - caseless = " + a.ToPattern(true));

            a.Set(caseless);
            a.RemoveAll(not_lc);
            System.Console.Out.WriteLine("caseless - [:^lc:] = " + a.ToPattern(true));
        }
コード例 #2
0
        private void ReloadEverything()
        {
            // Set the caption
            string caption = "Transliterator Editor ";

            if (sourceLanguage != null)
            {
                caption += sourceLanguage.Code;
            }
            if (destinationLanguage != null)
            {
                caption += " -> " + destinationLanguage.Code;
            }
            Title = caption;

            // Load rules
            rules = new RuleCollection(repository);
            dataGridRules.ItemsSource                = rules;
            transliterator                           = new Transliterator(repository, sourceLanguage.Code, destinationLanguage.Code);
            TransliterationExample.Transliterator    = (s => transliterator.Transliterate(s, false));
            TransliterationExample.Trans_li_te_rator = (s => transliterator.Transliterate(s, true));
            rules.MyTransliterator                   = transliterator;

            // Load TransliterationExamples
            examplesCollection           = new ExampleCollection(repository);
            dataGridExamples.ItemsSource = examplesCollection;

            TransliterationExample.DestinationFunc = Oggy.TransliterationEditor.WordDistance.CalculateDistance;
            TextBox_TextChanged(null, null);
        }
コード例 #3
0
        static internal void CheckHTML()
        {
            String foo = "& n < b < \"ab\"";
            String fii = toHTML.Transliterate(foo);

            System.Console.Out.WriteLine("in: " + foo);
            System.Console.Out.WriteLine("out: " + fii);
            System.Console.Out.WriteLine("in*: " + fromHTML.Transliterate(fii));
            System.Console.Out.WriteLine("IN*: " + fromHTML.Transliterate(fii.ToUpper()));
        }
コード例 #4
0
        public void Transliterate_InvalidMultiplier(int multiplier)
        {
            const string source = @"김, 국삼";

            _trans = Transliterator.CreateInstance("Any-Latin; Latin-ASCII");
            Assert.That(() => _trans.Transliterate(source, multiplier), Throws.InstanceOf <ArgumentException>());
        }
コード例 #5
0
        public void Transliterate_Overflow()
        {
            const string source = @"김, 국삼";

            _trans = Transliterator.CreateInstance("Any-Latin; Latin-ASCII");
            Assert.That(() => _trans.Transliterate(source, 1), Throws.InstanceOf <OverflowException>());
        }
コード例 #6
0
        public void TestTransliterateReturns_WhiteSpace()
        {
            Transliterator transliterator = new Transliterator();
            string         result         = transliterator.Transliterate(" ");

            Assert.AreEqual(" ", result);
        }
コード例 #7
0
ファイル: ThreadTest.cs プロジェクト: SilentCC/ICU4N
        public void TestAnyTranslit()
        {
            Transliterator tx      = Transliterator.GetInstance("Any-Latin");
            List <Thread>  threads = new List <Thread>();

            for (int i = 0; i < 8; i++)
            {
                threads.Add(new Thread(() => { tx.Transliterate("διαφορετικούς"); }));
            }
            foreach (Thread th in threads)
            {
                th.Start();
            }
            foreach (Thread th in threads)
            {
#if !NETCOREAPP1_0
                try
                {
#endif
                th.Join();
#if !NETCOREAPP1_0
            }
            catch (ThreadInterruptedException e)
            {
                Errln("Uexpected exception: " + e);
            }
#endif
            }
        }
コード例 #8
0
        public void TestTransliterateReturns_RussianSumbols()
        {
            Transliterator transliterator = new Transliterator();
            string         result         = transliterator.Transliterate("asd by");

            Assert.AreEqual("аcд бы", result);
        }
コード例 #9
0
        public void TestTransliterateReturns_EnglishSumbols()
        {
            Transliterator transliterator = new Transliterator();
            string         result         = transliterator.Transliterate("бибидибабидибум");

            Assert.AreEqual("bibidibabidibum", result);
        }
コード例 #10
0
        public void TestTransliterateReturns_Exception4()
        {
            Transliterator transliterator = new Transliterator();
            string         result         = transliterator.Transliterate("jbvfhb; ");

            Assert.AreEqual(null, result);
        }
コード例 #11
0
ファイル: GrcRomanizerTextFilter.cs プロジェクト: vedph/embix
        public void Apply(StringBuilder text)
        {
            if (text is null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            // find the index and length of each Greek span in text
            // and process it via the transliterator
            int i = 0;

            while (i < text.Length)
            {
                if (UniData.IsInGreekRange(text[i]))
                {
                    int j = i + 1;
                    while (j < text.Length &&
                           (char.IsWhiteSpace(text[j]) ||
                            UniData.IsInGreekRange(text[j])))
                    {
                        j++;
                    }
                    string greek = text.ToString(i, j - i);
                    string roman = Transliterator.Transliterate(greek);
                    text.Remove(i, j - i);
                    text.Insert(i, roman);
                    i += roman.Length;
                }
                else
                {
                    i++;
                }
            }
        }
コード例 #12
0
        public void CheckIncrementalAux(Transliterator t, String input)
        {
            IReplaceable            test = new ReplaceableString(input);
            TransliterationPosition pos  = new TransliterationPosition(0, test.Length, 0, test.Length);

            t.Transliterate(test, pos);
            bool gotError = false;

            // we have a few special cases. Any-Remove (pos.start = 0, but also = limit) and U+XXXXX?X?
            if (pos.Start == 0 && pos.Limit != 0 && !t.ID.Equals("Hex-Any/Unicode"))
            {
                Errln("No Progress, " + t.ID + ": " + UtilityExtensions.FormatInput(test, pos));
                gotError = true;
            }
            else
            {
                Logln("PASS Progress, " + t.ID + ": " + UtilityExtensions.FormatInput(test, pos));
            }
            t.FinishTransliteration(test, pos);
            if (pos.Start != pos.Limit)
            {
                Errln("Incomplete, " + t.ID + ":  " + UtilityExtensions.FormatInput(test, pos));
                gotError = true;
            }
            if (!gotError)
            {
                //Errln("FAIL: Did not get expected error");
            }
        }
コード例 #13
0
        public void TestRoundTrip()
        {
            String[] HANGUL = { "\uAC03\uC2F8",
                                "\uC544\uC5B4" };

            Transliterator latinJamo  = Transliterator.GetInstance("Latin-Jamo");
            Transliterator jamoLatin  = latinJamo.GetInverse();
            Transliterator jamoHangul = Transliterator.GetInstance("NFC");
            Transliterator hangulJamo = Transliterator.GetInstance("NFD");

            StringBuffer buf = new StringBuffer();

            for (int i = 0; i < HANGUL.Length; ++i)
            {
                String hangul  = HANGUL[i];
                String jamo    = hangulJamo.Transliterate(hangul);
                String latin   = jamoLatin.Transliterate(jamo);
                String jamo2   = latinJamo.Transliterate(latin);
                String hangul2 = jamoHangul.Transliterate(jamo2);
                buf.Length = (0);
                buf.Append(hangul + " => " +
                           jamoToName(jamo) + " => " +
                           latin + " => " + jamoToName(jamo2)
                           + " => " + hangul2
                           );
                if (!hangul.Equals(hangul2))
                {
                    Errln("FAIL: " + Utility.Escape(buf.ToString()));
                }
                else
                {
                    Logln(Utility.Escape(buf.ToString()));
                }
            }
        }
コード例 #14
0
        public void TestIncrementalProgress(string lang, string text)
        {
            var targets = Transliterator.GetAvailableTargets(lang);

            foreach (string target in targets)
            {
                var variants = Transliterator.GetAvailableVariants(lang, target);
                foreach (var variant in variants)
                {
                    String id = lang + "-" + target + "/" + variant;
                    Logln("id: " + id);

                    Transliterator t = Transliterator.GetInstance(id);
                    CheckIncrementalAux(t, text);

                    String rev = t.Transliterate(text);

                    // Special treatment: This transliterator has no registered inverse, skip for now.
                    if (id.Equals("Devanagari-Arabic/"))
                    {
                        continue;
                    }

                    Transliterator inv = t.GetInverse();
                    CheckIncrementalAux(inv, rev);
                }
            }
        }
コード例 #15
0
        public void Unsupported_language_test()
        {
            const string input = "Неподдерживаемый язык транслитерации";

            var сultureInfo = CultureInfo.InvariantCulture;
            var transliterator = new Transliterator(сultureInfo);
            Assert.AreEqual(input, transliterator.Transliterate(input));
        }
コード例 #16
0
        public void Transliterate_CompoundTransliterateLonger()
        {
            const string source = @"김, 국삼";
            const string target = @"gim, gugsam";

            _trans = Transliterator.CreateInstance("Any-Latin; Latin-ASCII");
            Assert.That(_trans.Transliterate(source), Is.EqualTo(target));
        }
コード例 #17
0
        private void expect(Transliterator t, String source, String expectedResult)
        {
            String result = t.Transliterate(source);

            expectAux(t.ID + ":String", source, result, expectedResult);

            ReplaceableString rsource = new ReplaceableString(source);

            t.Transliterate(rsource);
            result = rsource.ToString();
            expectAux(t.ID + ":Replaceable", source, result, expectedResult);

            // Test keyboard (incremental) transliteration -- this result
            // must be the same after we finalize (see below).
            rsource.Replace(0, rsource.Length, "");
            TransliterationPosition index = new TransliterationPosition();
            StringBuffer            log   = new StringBuffer();

            for (int i = 0; i < source.Length; ++i)
            {
                if (i != 0)
                {
                    log.Append(" + ");
                }
                log.Append(source[i]).Append(" -> ");
                t.Transliterate(rsource, index,
                                source[i] + "");
                // Append the string buffer with a vertical bar '|' where
                // the committed index is.
                String s = rsource.ToString();
                log.Append(s.Substring(0, index.Start)). // ICU4N: Checked 2nd parameter
                Append('|').
                Append(s.Substring(index.Start));
            }

            // As a final step in keyboard transliteration, we must call
            // transliterate to finish off any pending partial matches that
            // were waiting for more input.
            t.FinishTransliteration(rsource, index);
            result = rsource.ToString();
            log.Append(" => ").Append(rsource.ToString());
            expectAux(t.ID + ":Keyboard", log.ToString(),
                      result.Equals(expectedResult),
                      expectedResult);
        }
コード例 #18
0
 /// <summary>
 /// Multiplies the specified token.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns>The original token and eventually its transliterated form.
 /// </returns>
 public IEnumerable <string> Multiply(string token)
 {
     if (!string.IsNullOrEmpty(token) &&
         token.Any(c => UniData.IsInGreekRange(c)))
     {
         return(new[] { token, Transliterator.Transliterate(token) });
     }
     return(new[] { token });
 }
コード例 #19
0
        private void _TestTransliterate
        (
            [NotNull] string word,
            [NotNull] string expected
        )
        {
            string actual = Transliterator.Transliterate(word);

            Assert.AreEqual(expected, actual);
        }
コード例 #20
0
        public void Test5789()
        {
            String rules =
                "IETR > IET | \\' R; # (1) do split ietr between t and r\r\n" +
                "I[EH] > I; # (2) friedrich";
            Transliterator trans  = Transliterator.CreateFromRules("foo", rules, Transliterator.FORWARD);
            String         result = trans.Transliterate("BLENKDIETRICH");

            assertEquals("Rule breakage", "BLENKDIET'RICH", result);
        }
コード例 #21
0
        private void loadTransliterator()
        {
            Task.Run(() =>
            {
                transliterator = new Transliterator(new SqlRepository(), repository.srcLanguage.Code, "SR");

                txtTransliteration.Dispatcher.Invoke(
                    () => { txtTransliteration.Text = transliterator.Transliterate(txtWord.Text); });
            });
        }
コード例 #22
0
ファイル: ThreadTest.cs プロジェクト: SilentCC/ICU4N
            public override void Run()
            {
                Transliterator tx = Transliterator.GetInstance("Latin-Thai");

                for (int loop = 0; loop < outerInstance.iterationCount; loop++)
                {
                    foreach (String s in WORDS)
                    {
                        count += tx.Transliterate(s).Length;
                    }
                }
            }
コード例 #23
0
        /// <summary>
        /// UnicodeReplacer API
        /// </summary>
        ///
        public virtual int Replace(Replaceable text, int start, int limit, int[] cursor)
        {
            // First delegate to subordinate replacer
            int len = replacer.Replace(text, start, limit, cursor);

            limit = start + len;

            // Now transliterate
            limit = translit.Transliterate(text, start, limit);

            return(limit - start);
        }
コード例 #24
0
        public void TransliteratorFrontTest()
        {
            try
            {
                string result = Transliterator.Transliterate("Иванов Иван Иваныч, г.Москва, Солнцевский пр-т, д. 7, к.1, кв. 86");

                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
コード例 #25
0
        public void Transliterate_CompoundTransliterateSameLength(int multiplier)
        {
            const string source = @"Κοντογιαννάτος, Βασίλης";
            const string target = @"Kontogiannatos, Basiles";

            using (var traceListener = new TestableTraceListener())
            {
                Trace.Listeners.Add(traceListener);
                _trans = Transliterator.CreateInstance("Any-Latin; Latin-ASCII");
                Assert.That(_trans.Transliterate(source, multiplier), Is.EqualTo(target));
                Assert.That(traceListener._output.ToString(), Is.EqualTo(""));
            }
        }
コード例 #26
0
        /// <summary>
        /// Проверка возможности конвертации в SWIFT-формат:
        /// Пример
        /// :72:/ACC/
        /// /PHONBEN/TEL:2352626556
        /// //ICBKCNBJAHI, ANHUI,
        /// //PROVINCIAL BRANCH
        /// -}
        /// </summary>
        public override bool Check(out string result, out string message)
        {
            result = Transliterator.Transliterate
                     (
                CurrencyConversion + Environment.NewLine +
                "/PHONBEN/TEL:" + BeneficiaryPhone + Environment.NewLine +
                "//" + this.SwiftCode
                     );
            bool isChecked = (result.Length <= this.Leght) && BeneficiaryPhone.CountryPhoneCode == Enums.CountryPhoneCode.CHN;

            message = isChecked ? string.Empty : String.Format(CHECK_MESSAGE, this.GetType().Name, this.Leght, "");
            return(isChecked);
        }
コード例 #27
0
ファイル: Sender.cs プロジェクト: dmitry-kiselev-1/SSSB
        /// <summary>
        /// Проверка возможности конвертации в SWIFT-формат: не более 140 символов суммарно по всем полям
        /// Пример:
        /// :50K://Wisel Andrea
        /// Yun Ding str Puskin bld. zip:
        /// twn.Aleksandro-Nevsky RUS
        /// </summary>
        public override bool Check(out string result, out string message)
        {
            result =
                Transliterator.Transliterate
                (
                    "//" + Name + Environment.NewLine +
                    Passport + Environment.NewLine +
                    Address
                );
            bool isChecked = (result.Length <= this.Leght);

            message = isChecked ? string.Empty : String.Format(CHECK_MESSAGE, this.GetType().Name, this.Leght, "");
            return(isChecked);
        }
コード例 #28
0
        private void ReverseTransliteration_Click(object sender, RoutedEventArgs e)
        {
            repository.SwapSourceAndDestination();
            Transliterator reverseTransliterator = new Transliterator(repository, repository.srcLanguage.Code, repository.dstLanguage.Code);
            RuleCollection ruleCollection        = (RuleCollection)(dataGridRules.ItemsSource);
            RuleCollection newRuleCollection     = new RuleCollection();

            var rules = repository.ListRules(true);

            foreach (var rule in rules)
            {
                if (rule.Destination.Length == 0)
                {
                    continue;
                }

                string newSource = rule.Destination, newDestination = rule.Source;

                if (newDestination.StartsWith("|"))
                {
                    newSource      = "|" + newSource;
                    newDestination = newDestination.Substring(1);
                }

                if (newDestination.EndsWith("|"))
                {
                    newSource      = newSource + "|";
                    newDestination = newDestination.Substring(0, newDestination.Length - 1);
                }

                if (!ruleCollection.All(r => newSource != r.Source))
                {
                    continue;
                }

                newRuleCollection.Add(new TransliterationRule(newSource,
                                                              newDestination,
                                                              reverseTransliterator.Transliterate(rule.Examples)
                                                              ));
            }

            // Show the dialog
            RuleCollection oldRules = (RuleCollection)(dataGridRules.ItemsSource);
            var            reverseTransliterationWindow = new ReverseTransliteration(newRuleCollection, oldRules);

            reverseTransliterationWindow.ShowDialog();

            repository.SwapSourceAndDestination();
        }
コード例 #29
0
        internal PrettyPrinter AppendQuoted(int codePoint)
        {
            if (toQuote.Contains(codePoint))
            {
                if (quoter != null)
                {
                    target.Append(quoter.Transliterate(IBM.ICU.Text.UTF16.ValueOf(codePoint)));
                    return(this);
                }
                if (codePoint > 0xFFFF)
                {
                    target.Append("\\U");
                    target.Append(IBM.ICU.Impl.Utility.Hex(codePoint, 8));
                }
                else
                {
                    target.Append("\\u");
                    target.Append(IBM.ICU.Impl.Utility.Hex(codePoint, 4));
                }
                return(this);
            }
            switch (codePoint)
            {
            case '[':     // SET_OPEN:
            case ']':     // SET_CLOSE:
            case '-':     // HYPHEN:
            case '^':     // COMPLEMENT:
            case '&':     // INTERSECTION:
            case '\\':    // BACKSLASH:
            case '{':
            case '}':
            case '$':
            case ':':
                target.Append('\\');
                break;

            default:
                // Escape whitespace
                if (patternWhitespace.Contains(codePoint))
                {
                    target.Append('\\');
                }
                break;
            }
            IBM.ICU.Text.UTF16.Append(target, codePoint);
            return(this);
        }
コード例 #30
0
        /// <summary>
        /// Проверка возможности конвертации в SWIFT-формат: не более 35 символов на каждое поле.
        /// Пример:
        /// :59:/9558820402002075269
        /// Pei Diu(0015 0012)
        /// str.Str bld. zip: twn.Guangzhou C
        /// ID 230206197101290216
        /// </summary>
        public override bool Check(out string result, out string message)
        {
            result = Transliterator.Transliterate
                     (
                "/" + AccountNumber + Environment.NewLine +
                base.FullName() + Environment.NewLine +
                Address
                     );
            bool isChecked = (result.Length <= this.Leght) &&
                             (this.AccountNumber.Length == 16 ||
                              this.AccountNumber.Length == 19);

            message = isChecked
                ? string.Empty
                : String.Format(CHECK_MESSAGE, this.GetType().Name, this.Leght,
                                "Номер счёта в Китае должен быть равен 16 либо 19 символов");
            return(isChecked);
        }
コード例 #31
0
        public string Convert(string value, string cultureFrom)
        {
            var transliterationSpecification = _transliterationRepository.Get(x => x.CultureFrom == cultureFrom);

            if (transliterationSpecification == null)
            {
                return(value);
            }

            var specification = GetSpecification(transliterationSpecification);

            Transliterator transliterator = Transliterator.FromSpecification(specification, fOptimizeForMemoryUsage);

            // TODO : Return the contents of this
            var transliteratorRuleTraceList = new TransliteratorRuleTraceList();

            return(transliterator.Transliterate(
                       value,
                       new StringBuilder(value.Length * 2),
                       transliteratorRuleTraceList));
        }
コード例 #32
0
        private void TransliterateButtonClick()
        {
            if (string.IsNullOrWhiteSpace(InputData))
            {
                OutputData = string.Empty;
                return;
            }

            var stopwatch = new Stopwatch();
            var cultureInfo = GetSelectedCultureInfo();

            stopwatch.Start();

            var translit = new Transliterator(cultureInfo);
            var output = translit.Transliterate(InputData);

            stopwatch.Stop();

            OutputData = string.Format(
                "Elapsed milliseconds: {0}\nInput length: {1}\nOutput length: {2}\n\n{3}",
                stopwatch.ElapsedMilliseconds, InputData.Length, output.Length, output);
        }
コード例 #33
0
 public void CultureInfo_argument_null_test()
 {
     var transliterator = new Transliterator(null);
     transliterator.Transliterate(null);
 }