public void TransliteratorConstructorTest() { var target = new Oggy.Transliterator.Transliterator(MockRepository.Create(), "EN", "SR"); Assert.AreEqual("mejn", target["main"]); Assert.AreEqual("ajd", target["id"]); Assert.AreEqual("Ej", target["Ai"]); Assert.AreEqual("EJ", target["AI"]); Assert.AreEqual("hrom", target["hrom"]); Assert.AreEqual("mejk", target["make"]); Assert.AreEqual("najs", target["nice"]); // Separation mark "|" Assert.AreEqual("", target[""]); Assert.AreEqual("|", target["|"]); Assert.AreEqual("||", target["||"]); // Quotation marks Assert.AreEqual("\"Mejn\"", target["\"Main\""]); // Capital letters Assert.AreEqual("Najs", target["Nice"]); Assert.AreEqual("NAJS", target["NICE"]); // I Assert.AreEqual("Aj", target["I"]); Assert.AreEqual("Ol h", target["All h"]); }
private void TestPronunciationWithThreshold(string srcLang, string dstLang, int failThreshold, int distanceTreshold) { // Load transliterator and examples repository.SetSourceLanguage(srcLang); repository.SetDstLanguage(dstLang); transliterator = new Oggy.Transliterator.Transliterator(repository, srcLang, dstLang); var examples = repository .ListExamples(true) .ToDictionary(example => example.Source, example => example.Destination); int total = 0, failed = 0, totalDistance = 0; foreach (var example in examples) { total++; string actual = transliterator[example.Key]; if (example.Value != actual) { failed++; totalDistance += Oggy.TransliterationEditor.WordDistance.CalculateDistance(example.Value, actual); } } int failedPercentage = (100 * failed) / total; Assert.IsTrue(failedPercentage < failThreshold, "There are " + failedPercentage + "% failed"); int distancePercentage = (100 * totalDistance) / total; Assert.IsTrue(distancePercentage < distanceTreshold, "The distance " + distancePercentage + "% exceeded threshold"); }
void Application_Start(object sender, EventArgs e) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); string s = config.ConnectionStrings.ConnectionStrings["RepositoryConnection"].ToString(); //s = config.ConnectionStrings.ConnectionStrings.ToString(); repository = new Oggy.Repository.SqlRepository(s); TransliteratorManager.Repository = repository; transliterator = new Transliterator(repository, "EN", "SR"); sessionCounter = translitCounter = 0; }
/// <summary> /// Tests all examples for given language pair. /// </summary> /// <param name="LangId1">Source language</param> /// <param name="LangId2">Destination language</param> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException"> /// When the test fails. /// </exception> private void TestLanguagePair(string LangId1, string LangId2) { // Set the src and dst languages repository.SetSourceLanguage(LangId1); repository.SetDstLanguage(LangId2); // ****** Read jokers, transliteration rules and transliteration examples transliterator = new Oggy.Transliterator.Transliterator(repository, LangId1, LangId2); var examples = repository .ListExamples(true) .ToDictionary(example => example.Source, example => example.Destination); // Test it as it is TestPronunciation(examples, LangId1, LangId2); #region ****** Removing rules ************************** //Get all keys var keys = transliterator.Rules.Select(item => item.RawSource).ToList(); foreach (var key in keys) { var rule = transliterator.Rules[key]; transliterator.Rules.Remove(key); bool test_succeeded = false; try { TestPronunciation(examples); } catch (AssertFailedException) { // Test succeded! test_succeeded = true; } //Re-add the rule transliterator.Rules.Add(rule); //Test fails if test_succeded has not been set to true Assert.IsTrue(test_succeeded, "(" + LangId1 + "," + LangId2 + ") The rule " + key + "->" + rule.Destination + " is needless. " + "Do one of the following:\n1) remove this rule\n2) set disable to true or\n3) add an example where this rule is applied"); } #endregion //TODO: try with removing the break (i.e. |) from the rules that have it, and see if still all the examples pass //if they all pass, the rule should be wihtout the break }
void Application_Start(object sender, EventArgs e) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); try { string connectionString = config.ConnectionStrings.ConnectionStrings["RepositoryConnection"].ToString(); repository = new Oggy.Repository.SqlRepository(connectionString); } catch (NullReferenceException) { repository = new Oggy.Repository.FakeRepository(); } TransliteratorManager.Repository = repository; transliterator = new Transliterator(repository, "EN", "SR"); sessionCounter = translitCounter = 0; }
public void CanApplyTest() { var target = new Oggy.Transliterator.Transliterator(MockRepository.Create(), "EN", "SR"); SourceTextWithIterator text = new SourceTextWithIterator("still"); Rule rule; // Can Apply rule = new Rule("|s", "", new Dictionary <char, string>(), null); Assert.IsTrue(rule.CanApply(text)); rule = new Rule("s", "", new Dictionary <char, string>(), null); Assert.IsTrue(rule.CanApply(text)); rule = new Rule("st", "", new Dictionary <char, string>(), null); Assert.IsTrue(rule.CanApply(text)); // Can not Apply rule = new Rule("s|", "", new Dictionary <char, string>(), null); Assert.IsFalse(rule.CanApply(text)); rule = new Rule("s@", "", new Dictionary <char, string>(), null); Assert.IsFalse(rule.CanApply(text)); rule = new Rule("stil|", "", new Dictionary <char, string>(), null); Assert.IsFalse(rule.CanApply(text)); }
public TransliteratorBase this[string src, string dst] { get { string key = src + dst; lock (this) { if (!transliterators.ContainsKey(key)) { if (src == dst) { return(emptyTransliterator); } if (src == SERBIAN.Code || dst == SERBIAN.Code) { Repository.SetSourceLanguage(src); Repository.SetDstLanguage(dst); transliterators[key] = new Transliterator(Repository, src, dst); } else { transliterators[key] = new MultiTransliterator( new List <Language>() { Repository.RetreiveLanguage(src), SERBIAN, Repository.RetreiveLanguage(dst) }, Repository); } } } return(transliterators[key]); } }
public void TransliteratorMultipleWordsTest() { var target = new Oggy.Transliterator.Transliterator(MockRepository.Create(), "EN", "SR"); Assert.AreEqual("mejn Hrom", target["main Hrom"]); }