コード例 #1
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="XmlTranslation"/> class.
		/// </summary>
		/// --------------------------------------------------------------------------------
		public PhraseCustomization(TranslatablePhrase tp)
		{
			Reference = tp.Reference;
			OriginalPhrase = tp.OriginalPhrase;
			ModifiedPhrase = tp.ModifiedPhrase;
			Type = tp.IsExcluded ? CustomizationType.Deletion : CustomizationType.Modification;
		}
コード例 #2
0
ファイル: EditQuestionDlg.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:EditQuestion"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public EditQuestionDlg(TranslatablePhrase question)
		{
			m_question = question;
			InitializeComponent();
			m_txtOriginal.Text = question.OriginalPhrase;
			m_txtModified.Text = question.PhraseInUse;
			Question q = question.QuestionInfo;
			if (q != null && q.AlternateForms != null)
			{
				System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditQuestionDlg));

				foreach (string alternateForm in q.AlternateForms.Skip(1))
				{
					RadioButton newBtn = new RadioButton();
					m_pnlAlternatives.Controls.Add(newBtn);
					resources.ApplyResources(newBtn, "m_rdoAlternative");
					m_pnlAlternatives.SetFlowBreak(newBtn, true);
					newBtn.Text = alternateForm;
					newBtn.CheckedChanged += m_rdoAlternative_CheckedChanged;
				}
				m_rdoAlternative.Text = q.AlternateForms.First();
				return;
			}
			m_pnlAlternatives.Hide();
		}
コード例 #3
0
ファイル: PhraseParser.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="PhraseParser"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		internal PhraseParser(Dictionary<Word, List<KeyTermMatch>> keyTermsTable,
			Dictionary<Regex, string> substituteStrings, TranslatablePhrase phrase,
			Func<IEnumerable<Word>, TranslatablePhrase, int, Part> yieldPart)
		{
			m_keyTermsTable = keyTermsTable;
			YieldPart = yieldPart;
			m_phrase = phrase;

			string phraseToParse = m_phrase.PhraseInUse;
			foreach (KeyValuePair<Regex, string> substituteString in substituteStrings)
				phraseToParse = substituteString.Key.Replace(phraseToParse, substituteString.Value);

			m_words = GetWordsInString(phraseToParse.Trim().ToLowerInvariant(), true);
		}
コード例 #4
0
		public void SelectCorrectTermRendering_RuleDisabled()
		{
			AddMockedKeyTerm("Jesus", "Cristo", new[] { "Jesucristo", "Jesus", "Cristo Jesus" });

			TranslatablePhrase phrase1 = new TranslatablePhrase("Who was the man Jesus healed?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());

			Assert.IsFalse(phrase1.HasUserTranslation);
			Assert.AreEqual("Cristo", phrase1.Translation);

			pth.TermRenderingSelectionRules = new List<RenderingSelectionRule>(new[] { new RenderingSelectionRule(@"\bman {0}", @"ucristo\b") });
			pth.TermRenderingSelectionRules[0].Disabled = true;

			Assert.AreEqual("Cristo", phrase1.Translation);
		}
コード例 #5
0
		public void SelectCorrectTermRendering_FillInTemplate_BasedOnSuffixRule()
		{
			AddMockedKeyTerm("magician", "mago", new[] { "brujo" });
			AddMockedKeyTerm("servant", "criado", new[] { "siervo" });
			AddMockedKeyTerm("heal", "sanar", new[] { "curada", "sanada", "sanara\u0301", "sanas", "curan", "cura", "sana", "sanado" });

			TranslatablePhrase phrase1 = new TranslatablePhrase("Was the servant healed?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Was the magician healed?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(1, phrase1.TranslatableParts.Count());
			Assert.AreEqual(1, phrase2.TranslatableParts.Count());

			phrase1.Translation = "\u00BFFue sanado el siervo?";

			Assert.IsFalse(phrase2.HasUserTranslation);
			Assert.AreEqual("\u00BFFue sanar el mago?", phrase2.Translation);

			pth.TermRenderingSelectionRules = new List<RenderingSelectionRule>(new[] {
				new RenderingSelectionRule(@"{0}\w*ed\b", @"o$")});

			Assert.AreEqual("\u00BFFue sanado el mago?", phrase2.Translation);
		}
コード例 #6
0
		public void TestFindTermRenderingInUse_RepeatedTerms()
		{
			IKeyTerm ktGod = AddMockedKeyTerm("God", "Dios", 1, 4);
			IKeyTerm ktPaul = AddMockedKeyTerm("Paul", "Pablo", 1, 2, 5);

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did God tell Paul?/What was Paul told by God");

			new PhraseTranslationHelper(new[] { phrase1 },
				m_dummyKtList, m_keyTermRules, new List<Substitution>());

			phrase1.Translation = "\u00BFQue\u0301 le dijo Dios a Pablo?/\u00BFQue\u0301 le fue dicho a Pablo por Dios?";

			SubstringDescriptor sd;

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, 0));
			Assert.AreEqual(14, sd.Offset);
			Assert.AreEqual(4, sd.Length);
			int endOfLastOccurrenceOfGod = sd.EndOffset;

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, 0));
			Assert.AreEqual(21, sd.Offset);
			Assert.AreEqual(5, sd.Length);
			int endOfLastOccurrenceOfPaul = sd.EndOffset;

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, endOfLastOccurrenceOfGod));
			Assert.AreEqual(59, sd.Offset);
			Assert.AreEqual(4, sd.Length);

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, endOfLastOccurrenceOfPaul));
			Assert.AreEqual(49, sd.Offset);
			Assert.AreEqual(5, sd.Length);
		}
コード例 #7
0
		public void TestFindTermRenderingInUse_Present()
		{
			IKeyTerm ktGod = AddMockedKeyTerm("God", "Dios", 1, 4);
			IKeyTerm ktPaul = AddMockedKeyTerm("Paul", "Pablo", 1, 2, 5);
			IKeyTerm ktHave = AddMockedKeyTerm("have", "tenemos", 1, 2, 3, 4, 5, 6);
			IKeyTerm ktSay = AddMockedKeyTerm("say", "dice", 1, 2, 5);

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did God tell Paul?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("What does Paul say we have to give to God?");

			new PhraseTranslationHelper(new[] {phrase1, phrase2},
				m_dummyKtList, m_keyTermRules, new List<Substitution>());

			phrase1.Translation = "\u00BFQue\u0301 le dijo Dios a Pablo?";
			phrase2.Translation = "\u00BFQue\u0301 dice luaP que tenemos que dar a Dios?";

			SubstringDescriptor sd;

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, 0));
			Assert.AreEqual(14, sd.Offset);
			Assert.AreEqual(4, sd.Length);

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, 0));
			Assert.AreEqual(21, sd.Offset);
			Assert.AreEqual(5, sd.Length);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, 0));
			Assert.AreEqual(11, sd.Offset);
			Assert.AreEqual(4, sd.Length);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktSay, 0));
			Assert.AreEqual(6, sd.Offset);
			Assert.AreEqual(4, sd.Length);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktHave, 0));
			Assert.AreEqual(20, sd.Offset);
			Assert.AreEqual(7, sd.Length);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, 0));
			Assert.AreEqual(38, sd.Offset);
			Assert.AreEqual(4, sd.Length);
		}
コード例 #8
0
		public void ChangeTranslation_PreventUpdatedTranslationFromChangingGoodPartTranslation()
		{
			AddMockedKeyTerm("donkey", "asno");
			AddMockedKeyTerm("Balaam", "Balaam");

			TranslatablePhrase phrase1 = new TranslatablePhrase("When?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("When Balaam eats donkey.");
			TranslatablePhrase phrase3 = new TranslatablePhrase("What donkey eats?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("What Balaam eats?");
			TranslatablePhrase phrase5 = new TranslatablePhrase("Donkey eats?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2, phrase3, phrase4, phrase5 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(1, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(2, phrase3.TranslatableParts.Count());
			Assert.AreEqual(2, phrase4.TranslatableParts.Count());
			Assert.AreEqual(1, phrase5.TranslatableParts.Count());

			phrase1.Translation = "\u00BFCua\u0301ndo?";
			phrase2.Translation = "\u00BFCua\u0301ndo come Balaam al asno.";
			phrase3.Translation = "\u00BFQue\u0301 come el asno?";
			phrase4.Translation = "\u00BFQue\u0301 ingiere Balaam?";
			Assert.AreEqual("\u00BFasno come?", phrase5.Translation);

			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.IsTrue(phrase3.HasUserTranslation);
			Assert.IsTrue(phrase4.HasUserTranslation);
			Assert.IsFalse(phrase5.HasUserTranslation);
		}
コード例 #9
0
		public void SetTranslation_GuessAtOnePartPhraseThatDiffersBySingleKeyTerm()
		{
			AddMockedKeyTerm("Timothy", "Timoteo");
			AddMockedKeyTerm("Euticus", "Eutico");

			TranslatablePhrase phrase1 = new TranslatablePhrase("Who was Timothy?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Who was Euticus?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(1, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase1.GetParts().Count());
			Assert.AreEqual(1, phrase2.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.GetParts().Count());

			const string frame = "\u00BFQuie\u0301n era {0}?";
			phrase1.Translation = string.Format(frame, "Timoteo");

			Assert.AreEqual(string.Format(frame, "Timoteo"), phrase1.Translation);
			Assert.AreEqual(string.Format(frame, "Eutico"), phrase2.Translation);
			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsFalse(phrase2.HasUserTranslation);
		}
コード例 #10
0
		public void ChangeTranslation_GuessAtPhraseTranslationBasedOnTriangulation()
		{
			AddMockedKeyTerm("Jesus");
			AddMockedKeyTerm("lion");
			AddMockedKeyTerm("jar");

			TranslatablePhrase phrase1 = new TranslatablePhrase("Who was the man in the lions' den?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Who was the man with the jar?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("Who was the man Jesus healed?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2, phrase3 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(2, phrase3.TranslatableParts.Count());

			string partTrans = "Quie\u0301n era el hombre";
			string transCommon = "\u00BF" + partTrans;
			phrase1.Translation = "Quien fue lo hambre en la fosa de leones?";
			phrase2.Translation = transCommon + " con el jarro?";
			Assert.AreEqual("\u00BFmbre JESUS?", phrase3.Translation);
			Assert.AreEqual("mbre", phrase3[0].Translation);

			phrase1.Translation = transCommon + " en la fosa de leones?";

			Assert.AreEqual(transCommon + " en la fosa de leones?", phrase1.Translation);
			Assert.AreEqual(transCommon + " con el jarro?", phrase2.Translation);
			Assert.AreEqual(transCommon + " JESUS?", phrase3.Translation);
			Assert.AreEqual(partTrans, phrase3[0].Translation);
			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.IsFalse(phrase3.HasUserTranslation);
		}
コード例 #11
0
		public void SetTranslation_ClearingUserTranslationFlagRestoresTemplateBasedTranslation()
		{
			AddMockedKeyTerm("Jesus", "Jesu\u0301s");
			AddMockedKeyTerm("Phillip", "Felipe");
			AddMockedKeyTerm("Matthew", "Mateo");

			TranslatablePhrase phrase0 = new TranslatablePhrase("What asked Jesus Matthew?");
			TranslatablePhrase phrase1 = new TranslatablePhrase("What asked Jesus Phillip?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("What asked Phillip Matthew?");

			PhraseTranslationHelper helper = new PhraseTranslationHelper(
				new[] { phrase0, phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(helper, "m_justGettingStarted", false);


			phrase0.Translation = "\u00BFQue\u0301 le pregunto\u0301 Jesu\u0301s a Mateo?";
			phrase1.Translation = "\u00BFQue\u0301 le pregunto\u0301 Jesu\u0301s Felipe?";
			Assert.AreEqual("\u00BFQue\u0301 le pregunto\u0301 Felipe Mateo?", phrase2.Translation);
			Assert.IsFalse(phrase2.HasUserTranslation);

			phrase2.HasUserTranslation = true;
			Assert.AreEqual("\u00BFQue\u0301 le pregunto\u0301 Felipe Mateo?", phrase2.Translation);
			Assert.IsTrue(phrase2.HasUserTranslation);

			phrase2.HasUserTranslation = false;
			Assert.AreEqual("\u00BFQue\u0301 le pregunto\u0301 Felipe a Mateo?", phrase2.Translation);
			Assert.IsFalse(phrase2.HasUserTranslation);

			phrase2.HasUserTranslation = true;
			Assert.AreEqual("\u00BFQue\u0301 le pregunto\u0301 Felipe a Mateo?", phrase2.Translation);
			Assert.IsTrue(phrase2.HasUserTranslation);
		}
コード例 #12
0
		public void SetTranslation_FindKeyTermRenderingWhenKtHasMultiplesTranslations()
		{
			AddMockedKeyTerm("arrow", "flecha");
			AddMockedKeyTerm("arrow", "dardo");
			AddMockedKeyTerm("arrow", "dardos");
			AddMockedKeyTerm("lion", "leo\u0301n");
			AddMockedKeyTerm("boat", "nave");
			AddMockedKeyTerm("boat", "barco");
			AddMockedKeyTerm("boat", "barca");

			TranslatablePhrase phrase1 = new TranslatablePhrase("I shot the lion with the arrow.");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Who put the lion in the boat?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("Does the boat belong to the boat?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("I shot the boat with the arrow.");
			TranslatablePhrase phrase5 = new TranslatablePhrase("Who put the arrow in the boat?");
			TranslatablePhrase phrase6 = new TranslatablePhrase("Who put the arrow in the lion?");
			TranslatablePhrase phrase7 = new TranslatablePhrase("I shot the arrow with the lion.");
			TranslatablePhrase phrase8 = new TranslatablePhrase("Does the arrow belong to the lion?");

			PhraseTranslationHelper helper = new PhraseTranslationHelper(
				new[] { phrase1, phrase2, phrase3, phrase4, phrase5, phrase6, phrase7, phrase8 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(helper, "m_justGettingStarted", false);

			foreach (TranslatablePhrase phrase in helper.Phrases)
			{
				Assert.AreEqual(4, phrase.GetParts().Count(), "Wrong number of parts for phrase: " + phrase.OriginalPhrase);
				Assert.AreEqual(2, phrase.TranslatableParts.Count(), "Wrong number of translatable parts for phrase: " + phrase.OriginalPhrase);
			}

			phrase1.Translation = "Yo le pegue\u0301 un tiro al noil con un dardo.";
			Assert.AreEqual("Yo le pegue\u0301 un tiro al nave con un flecha.", phrase4.Translation);
			Assert.AreEqual("Yo le pegue\u0301 un tiro al flecha con un leo\u0301n.", phrase7.Translation);

			phrase2.Translation = "\u00BFQuie\u0301n puso el leo\u0301n en la barca?";
			Assert.AreEqual("\u00BFQuie\u0301n puso el flecha en la nave?", phrase5.Translation);
			Assert.AreEqual("\u00BFQuie\u0301n puso el flecha en la leo\u0301n?", phrase6.Translation);

			phrase3.Translation = "\u00BFEl taob le pertenece al barco?";
			// This is a bizarre special case where the original question has the same key term twice and
			// the user has translated it differently. Internal details of the logic (specifically, it finds
			// the longer rendering first) dictate the order in which the key terms are considered to have
			// been found. For the purposes of this test case, we don't care in which order the terms of the
			// untranslated question get substituted.
			Assert.IsTrue("\u00BFEl leo\u0301n le pertenece al flecha?" == phrase8.Translation ||
				"\u00BFEl flecha le pertenece al leo\u0301n?" == phrase8.Translation);

			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.IsTrue(phrase3.HasUserTranslation);
			Assert.IsFalse(phrase4.HasUserTranslation);
			Assert.IsFalse(phrase5.HasUserTranslation);
			Assert.IsFalse(phrase6.HasUserTranslation);
			Assert.IsFalse(phrase7.HasUserTranslation);
			Assert.IsFalse(phrase8.HasUserTranslation);
		}
コード例 #13
0
		public void ChangeTranslation_WholePhraseMatchesPartOfAnotherPhrase()
		{
			TranslatablePhrase shortPhrase = new TranslatablePhrase("Who was the man?");
			TranslatablePhrase longPhrase = new TranslatablePhrase("Who was the man with the jar?");
			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				shortPhrase, longPhrase }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(1, shortPhrase.TranslatableParts.Count());
			Assert.AreEqual(2, longPhrase.TranslatableParts.Count());

			shortPhrase.Translation = "Quiem fue el hambre?";
			string partTrans = "Quie\u0301n era el hombre";
			string trans = "\u00BF" + partTrans + "?";
			shortPhrase.Translation = trans;

			Assert.AreEqual(trans, shortPhrase.Translation);
			Assert.AreEqual(partTrans, shortPhrase[0].Translation);
			Assert.AreEqual(trans, longPhrase.Translation);
			Assert.AreEqual(partTrans, longPhrase[0].Translation);
			Assert.AreEqual(0, longPhrase[1].Translation.Length);
			Assert.IsTrue(shortPhrase.HasUserTranslation);
			Assert.IsFalse(longPhrase.HasUserTranslation);
		}
コード例 #14
0
		public void SetNewTranslation_AutoAcceptTranslationForAllIdenticalPhrases_WithUntranslatedKeyTerm()
		{
			AddMockedKeyTerm("man", (string)null);

			TranslatablePhrase phrase1 = new TranslatablePhrase(new TestQ("Who was the man?", "A", 1, 1), 1, 0);
			TranslatablePhrase phrase2 = new TranslatablePhrase(new TestQ("Who was the man?", "B", 2, 2), 1, 0);
			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			phrase1.Translation = "\u00BFQuie\u0301n era el hombre?";

			Assert.AreEqual(phrase1.Translation, phrase2.Translation);
			Assert.IsTrue(phrase2.HasUserTranslation);
		}
コード例 #15
0
		public void SetNewTranslation_AcceptTranslationConsistingOnlyOfInitialAndFinalPunctuation()
		{
			AddMockedKeyTerm("Paul", (string)null);
			AddMockedKeyTerm("Judas", (string)null);
			TranslatablePhrase phrase1 = new TranslatablePhrase(new TestQ("Who was Paul talking to?", "A", 1, 1), 1, 0);
			TranslatablePhrase phrase2 = new TranslatablePhrase(new TestQ("Who was Judas kissing?", "A", 1, 1), 1, 0);
			TranslatablePhrase phrase3 = new TranslatablePhrase(new TestQ("Why was Judas talking to Paul?", "B", 2, 2), 1, 0);
			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2, phrase3 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			phrase1.Translation = "\u00BFCon quie\u0301n estaba hablando Pablo?";
			phrase2.HasUserTranslation = true;

			Assert.AreEqual("\u00BF?", phrase2.Translation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.AreEqual(phrase2.Translation, phrase3.Translation);
		}
コード例 #16
0
		public void ChangeTranslation_PreventTrashingPartTranslationsWhenReCalculating()
		{
			AddMockedKeyTerm("Mary", "Mari\u0301a");
			AddMockedKeyTerm("Jesus");

			TranslatablePhrase phrase1 = new TranslatablePhrase("When?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Where did Mary find Jesus?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("Where did Jesus find a rock?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("Where did Mary eat?");
			TranslatablePhrase phrase5 = new TranslatablePhrase("When Mary went to the tomb, where did Jesus meet her?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2,
				phrase3, phrase4, phrase5 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(1, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(2, phrase3.TranslatableParts.Count());
			Assert.AreEqual(2, phrase4.TranslatableParts.Count());
			Assert.AreEqual(4, phrase5.TranslatableParts.Count());

			phrase1.Translation = "\u00BFCua\u0301ndo?";
			phrase2.Translation = "\u00BFDo\u0301nde encontro\u0301 Mari\u0301a a JESUS?";
			phrase3.Translation = "\u00BFDo\u0301nde encontro\u0301 JESUS una piedra?";
			phrase4.Translation = "\u00BFDo\u0301nde comio\u0301 Mari\u0301a?";
			Assert.AreEqual("\u00BFCua\u0301ndo Mari\u0301a Do\u0301nde JESUS?", phrase5.Translation);

			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.IsTrue(phrase3.HasUserTranslation);
			Assert.IsFalse(phrase5.HasUserTranslation);
		}
コード例 #17
0
		public void ChangeTranslation_FallbackToSmallerCommonSubstring_StartingInLargerSubstring()
		{
			AddMockedKeyTerm("the squirrel", "ardilla");
			AddMockedKeyTerm("donkey", "asno");
			AddMockedKeyTerm("Balaam", "Balaam");

			TranslatablePhrase phrase1 = new TranslatablePhrase("When did the donkey and the squirrel fight?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Where are Balaam and the squirrel?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("What did the donkey and Balaam do?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("and?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2, phrase3, phrase4 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase3.TranslatableParts.Count());
			Assert.AreEqual(1, phrase4.TranslatableParts.Count());

			phrase1.Translation = "\u00BFCua\u0301ndo pelearon el asno y la ardilla?";
			phrase2.Translation = "\u00BFDo\u0301nde esta\u0301n Balaam y la ardilla?";
			phrase3.Translation = "\u00BFQue\u0301 hicieron el asno y Balaam?";
			Assert.AreEqual("\u00BFy?", phrase4.Translation);

			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsTrue(phrase2.HasUserTranslation);
			Assert.IsTrue(phrase3.HasUserTranslation);
			Assert.IsFalse(phrase4.HasUserTranslation);
		}
コード例 #18
0
		public void SetTranslation_GuessAtTwoPartPhraseThatDiffersBySingleKeyTerm()
		{
			AddMockedKeyTerm("Jacob", "Jacobo");
			AddMockedKeyTerm("Matthew", "Mateo");

			TranslatablePhrase phrase1 = new TranslatablePhrase("Was Jacob one of the disciples?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Was Matthew one of the disciples?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase1.GetParts().Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.GetParts().Count());

			const string frame = "\u00BFFue {0} uno de los discipulos?";
			phrase1.Translation = string.Format(frame, "Jacobo");

			Assert.AreEqual(string.Format(frame, "Jacobo"), phrase1.Translation);
			Assert.AreEqual(string.Format(frame, "Mateo"), phrase2.Translation);
			Assert.IsTrue(phrase1.HasUserTranslation);
			Assert.IsFalse(phrase2.HasUserTranslation);
		}
コード例 #19
0
		public void GetPhrasesSortedByTranslation()
		{
			TranslatablePhrase tp1 = new TranslatablePhrase(new TestQ("What would God have me to say with respect to Paul?", "A", 1, 1), 1, 0);
			TranslatablePhrase tp2 = new TranslatablePhrase(new TestQ("What is Paul asking me to say with respect to that dog?", "B", 2, 2), 1, 0);
			TranslatablePhrase tp3 = new TranslatablePhrase(new TestQ("that dog", "C", 3, 3), 1, 0);
			TranslatablePhrase tp4 = new TranslatablePhrase(new TestQ("Is it okay for Paul me to talk with respect to God today?", "D", 4, 4), 1, 0);
			TranslatablePhrase tp5 = new TranslatablePhrase(new TestQ("that dog wishes this Paul and what is say radish", "E", 5, 5), 1, 0);
			TranslatablePhrase tp6 = new TranslatablePhrase(new TestQ("What is that dog?", "F", 6, 6), 1, 0);

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { tp1, tp2, tp3, tp4, tp5, tp6 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());

			tp1.Translation = "Z";
			tp2.Translation = "B";
			tp3.Translation = "alligator";
			tp4.Translation = "D";
			tp5.Translation = "e";
			tp6.Translation = "E";

			pth.Sort(PhraseTranslationHelper.SortBy.Translation, true);

			Assert.AreEqual(tp3, pth[0]);
			Assert.AreEqual(tp2, pth[1]);
			Assert.AreEqual(tp4, pth[2]);
			Assert.AreEqual(tp5, pth[3]);
			Assert.AreEqual(tp6, pth[4]);
			Assert.AreEqual(tp1, pth[5]);

			pth.Sort(PhraseTranslationHelper.SortBy.Translation, false);

			Assert.AreEqual(tp1, pth[0]);
			Assert.AreEqual(tp6, pth[1]);
			Assert.AreEqual(tp5, pth[2]);
			Assert.AreEqual(tp4, pth[3]);
			Assert.AreEqual(tp2, pth[4]);
			Assert.AreEqual(tp3, pth[5]);
		}
コード例 #20
0
		public void SetTranslation_PreventTranslationFromBeingUsedForMultipleParts()
		{
			AddMockedKeyTerm("Jacob", "Jacob");
			AddMockedKeyTerm("John", "Juan");
			AddMockedKeyTerm("Jesus", "Jesu\u0301s");
			AddMockedKeyTerm("Mary", "Mari\u0301a");
			AddMockedKeyTerm("Moses", "Moise\u0301s");

			TranslatablePhrase phrase1 = new TranslatablePhrase("So what did Jacob do?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("So what did Jesus do?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("What did Jacob do?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("What did Moses ask?");
			TranslatablePhrase phrase5 = new TranslatablePhrase("So what did John ask?");
			TranslatablePhrase phrase6 = new TranslatablePhrase("So what did Mary want?");
			TranslatablePhrase phrase7 = new TranslatablePhrase("What did Moses do?");
			TranslatablePhrase phrase8 = new TranslatablePhrase("Did Moses ask, \"What did Jacob do?\"");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2, phrase3,
				phrase4, phrase5, phrase6, phrase7, phrase8 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase1.GetParts().Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.GetParts().Count());
			Assert.AreEqual(2, phrase3.TranslatableParts.Count());
			Assert.AreEqual(3, phrase3.GetParts().Count());
			Assert.AreEqual(2, phrase4.TranslatableParts.Count());
			Assert.AreEqual(3, phrase4.GetParts().Count());
			Assert.AreEqual(2, phrase5.TranslatableParts.Count());
			Assert.AreEqual(3, phrase5.GetParts().Count());
			Assert.AreEqual(2, phrase6.TranslatableParts.Count());
			Assert.AreEqual(3, phrase6.GetParts().Count());
			Assert.AreEqual(2, phrase7.TranslatableParts.Count());
			Assert.AreEqual(3, phrase7.GetParts().Count());
			Assert.AreEqual(4, phrase8.TranslatableParts.Count());
			Assert.AreEqual(6, phrase8.GetParts().Count());

			phrase1.Translation = "\u00BFEntonces que\u0301 hizo Jacob?";
			phrase2.Translation = "\u00BFEntonces que\u0301 hizo Jesu\u0301s?";
			phrase3.Translation = "\u00BFQue\u0301 hizo Jacob?";
			phrase4.Translation = "\u00BFQue\u0301 pregunto\u0301 Moise\u0301s?";
			phrase5.Translation = "\u00BFEntonces que\u0301 pregunto\u0301 Juan?";

			Assert.AreEqual("\u00BFEntonces que\u0301 Mari\u0301a?", phrase6.Translation);
			Assert.AreEqual("\u00BFQue\u0301 hizo Moise\u0301s?", phrase7.Translation);
			Assert.AreEqual("Moise\u0301s pregunto\u0301 Que\u0301 Jacob hizo", phrase8.Translation);
		}
コード例 #21
0
		public void TestFindTermRenderingInUse_SomeMissing()
		{
			IKeyTerm ktGod = AddMockedKeyTerm("God", "Dios", 1, 4);
			IKeyTerm ktPaul = AddMockedKeyTerm("Paul", "Pablo", 1, 2, 5);
			IKeyTerm ktHave = AddMockedKeyTerm("have", "tenemos", 1, 2, 3, 4, 5, 6);
			IKeyTerm ktSay = AddMockedKeyTerm("say", "dice", 1, 2, 5);

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did God tell Paul?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("What does Paul say we have to give to God?");

			new PhraseTranslationHelper(new[] { phrase1, phrase2 },
				m_dummyKtList, m_keyTermRules, new List<Substitution>());

			phrase1.Translation = "\u00BFQue\u0301 le dijo Jehovah a Pablo?";
			phrase2.Translation = "Pi\u0301dale ayuda a Bill.";

			SubstringDescriptor sd;

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, 0));
			Assert.IsNull(sd);

			sd = phrase1.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, 0));
			Assert.AreEqual(24, sd.Offset);
			Assert.AreEqual(5, sd.Length);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktPaul, 0));
			Assert.IsNull(sd);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktSay, 0));
			Assert.IsNull(sd);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktHave, 0));
			Assert.IsNull(sd);

			sd = phrase2.FindTermRenderingInUse(new DummyKeyTermRenderingInfo(ktGod, 0));
			Assert.IsNull(sd);
		}
コード例 #22
0
		public void SetTranslation_UseStatsAndConfidenceToDeterminePartTranslations()
		{
			AddMockedKeyTerm("ask");
			AddMockedKeyTerm("give");
			AddMockedKeyTerm("want");
			AddMockedKeyTerm("whatever");
			AddMockedKeyTerm("thing");

			TranslatablePhrase phrase1 = new TranslatablePhrase("ABC ask DEF");
			TranslatablePhrase phrase2 = new TranslatablePhrase("ABC give XYZ");
			TranslatablePhrase phrase3 = new TranslatablePhrase("XYZ want ABC whatever EFG");
			TranslatablePhrase phrase4 = new TranslatablePhrase("EFG thing ABC");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2,
				phrase3, phrase4 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase1.GetParts().Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.GetParts().Count());
			Assert.AreEqual(3, phrase3.TranslatableParts.Count());
			Assert.AreEqual(5, phrase3.GetParts().Count());
			Assert.AreEqual(2, phrase4.TranslatableParts.Count());
			Assert.AreEqual(3, phrase4.GetParts().Count());

			phrase1.Translation = "def ASK abc";
			phrase2.Translation = "abc xyz GIVE";
			phrase3.Translation = "WANT xyz abc WHATEVER efg";

			Assert.AreEqual("efg THING abc", phrase4.Translation);
		}
コード例 #23
0
		public void SelectCorrectTermRendering_SomePartsTranslated_BasedOnFollowingWordRule()
		{
			AddMockedKeyTerm("Stephen", "Esteban");
			AddMockedKeyTerm("Mary", "Mari\u0301a");
			AddMockedKeyTerm("look", "mirar", new[] { "pareci\u0301a", "buscaba", "busca", "busco" });

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did Stephen look like to the priests and elders and other people present?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("What did Stephen do?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("What did Mary look for?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2, phrase3 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());
			Assert.AreEqual(2, phrase3.TranslatableParts.Count());

			phrase1.Translation = "\u00BFCo\u0301mo pareci\u0301a Esteban a los sacerdotes y ancianos y a los dema\u0301s?";
			phrase2.Translation = "\u00BFCo\u0301mo hizo Esteban?";

			Assert.IsFalse(phrase3.HasUserTranslation);
			Assert.AreEqual("\u00BFCo\u0301mo Mari\u0301a mirar?", phrase3.Translation);

			pth.TermRenderingSelectionRules = new List<RenderingSelectionRule>(new[] {
				new RenderingSelectionRule(@"{0} like\b", @"\bparec"),
				new RenderingSelectionRule(@"{0} for\b", @"\bbusc")});

			Assert.AreEqual("\u00BFCo\u0301mo Mari\u0301a buscaba?", phrase3.Translation);
		}
コード例 #24
0
		public void SetTranslation_UseStatisticalBestPartTranslations()
		{
			AddMockedKeyTerm("Isaac", "Isaac");
			AddMockedKeyTerm("Paul", "Pablo");

			TranslatablePhrase phraseBreakerA = new TranslatablePhrase("Now what?");
			TranslatablePhrase phraseBreakerB = new TranslatablePhrase("What did Isaac say?");
			TranslatablePhrase phrase1 = new TranslatablePhrase("So now what did those two brothers do?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("So what did they do about the problem?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("So what did he do?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("So now what was Isaac complaining about?");
			TranslatablePhrase phrase5 = new TranslatablePhrase("So what did the Apostle Paul say about that?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phraseBreakerA, phraseBreakerB,
				phrase1, phrase2, phrase3, phrase4, phrase5 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase1.GetParts().Count());
			Assert.AreEqual(3, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.GetParts().Count());
			Assert.AreEqual(3, phrase3.TranslatableParts.Count());
			Assert.AreEqual(3, phrase3.GetParts().Count());
			Assert.AreEqual(4, phrase4.TranslatableParts.Count());
			Assert.AreEqual(5, phrase4.GetParts().Count());
			Assert.AreEqual(4, phrase5.TranslatableParts.Count());
			Assert.AreEqual(5, phrase5.GetParts().Count());

			phrase1.Translation = "\u00BFEntonces ahora que\u0301 hicieron esos dos hermanos?";
			phrase2.Translation = "\u00BFEntonces que\u0301 hicieron acerca del problema?";
			phrase3.Translation = "\u00BFEntonces que\u0301 hizo?";
			phrase5.Translation = "\u00BFEntonces que\u0301 dijo Pablo acerca de eso?";

			Assert.AreEqual("\u00BFEntonces Isaac?", phrase4.Translation);
		}
コード例 #25
0
		public void SelectCorrectTermRendering_FillInTemplate_BasedOnSuffixRule_PreferDefault()
		{
			AddMockedKeyTerm("magician", "mago", new[] { "brujo" });
			AddMockedKeyTerm("servant", "criado", new[] { "siervo" });
			AddMockedKeyTerm("heal", "sanara\u0301", new[] { "curada", "sanada", "sanar", "curara\u0301", "sanas", "curan", "cura", "sana", "sanado" });

			TranslatablePhrase phrase1 = new TranslatablePhrase("Will the servant be healed?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Will the magician be healed?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] {
				phrase1, phrase2 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(2, phrase1.TranslatableParts.Count());
			Assert.AreEqual(2, phrase2.TranslatableParts.Count());

			phrase1.Translation = "\u00BFSe curara\u0301 el siervo?";

			Assert.IsFalse(phrase2.HasUserTranslation);
			Assert.AreEqual("\u00BFSe sanara\u0301 el mago?", phrase2.Translation);

			pth.TermRenderingSelectionRules = new List<RenderingSelectionRule>(new[] {
				new RenderingSelectionRule(@"Will .* {0}\w*\b", "ra\u0301$")});

			Dictionary<Word, List<KeyTermMatch>> keyTermsTable =
				(Dictionary<Word, List<KeyTermMatch>>)ReflectionHelper.GetField(pth, "m_keyTermsTable");

			keyTermsTable["heal"].First().BestRendering = "curara\u0301";

			Assert.AreEqual("\u00BFSe curara\u0301 el mago?", phrase2.Translation);
		}
コード例 #26
0
		public void SetTranslation_UseStatisticalBestPartTranslationsRatherThanCommonPartialWord()
		{
			AddMockedKeyTerm("Isaac", "Isaac");
			AddMockedKeyTerm("Paul", "Pablo");

			TranslatablePhrase phraseBreakerA = new TranslatablePhrase("Now what?");
			TranslatablePhrase phraseBreakerB = new TranslatablePhrase("What did Isaac say?");
			TranslatablePhrase phraseBreakerC = new TranslatablePhrase("What could Isaac say?");
			TranslatablePhrase phrase1 = new TranslatablePhrase("So now what did those two brothers do?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("So what could they do about the problem?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("So what did he do?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("So now what was Isaac complaining about?");
			TranslatablePhrase phrase5 = new TranslatablePhrase("So what did the Apostle Paul say about that?");
			TranslatablePhrase phrase6 = new TranslatablePhrase("Why did they treat the Apostle Paul so?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phraseBreakerA, phraseBreakerB, phraseBreakerC,
				phrase1, phrase2, phrase3, phrase4, phrase5, phrase6 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase1.GetParts().Count());
			Assert.AreEqual(3, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.GetParts().Count());
			Assert.AreEqual(3, phrase3.TranslatableParts.Count());
			Assert.AreEqual(3, phrase3.GetParts().Count());
			Assert.AreEqual(4, phrase4.TranslatableParts.Count());
			Assert.AreEqual(5, phrase4.GetParts().Count());
			Assert.AreEqual(4, phrase5.TranslatableParts.Count());
			Assert.AreEqual(5, phrase5.GetParts().Count());
			Assert.AreEqual(2, phrase6.TranslatableParts.Count());
			Assert.AreEqual(3, phrase6.GetParts().Count());

			phrase1.Translation = "Entonces AB Zuxelopitmyfor CD EF GH";
			phrase2.Translation = "Entonces Vuxelopitmyfor IJ KL MN OP QR";
			phrase3.Translation = "Entonces Wuxelopitmyfor ST";
			phrase5.Translation = "Entonces Xuxelopitmyfor dijo Pablo UV WX YZ";
			phrase6.Translation = "BG LP Yuxelopitmyfor DW MR Pablo";

			Assert.AreEqual("Entonces Isaac", phrase4.Translation);
		}
コード例 #27
0
		public void GetPhrasesFilteredOnlyByRef_IncludeExcluded()
		{
			AddMockedKeyTerm("God", 1, 4);
			AddMockedKeyTerm("Paul", 1, 2, 5);
			AddMockedKeyTerm("have", 1, 2, 3, 4, 5, 6);
			AddMockedKeyTerm("say", 1, 2, 5);

			TranslatablePhrase tp1 = new TranslatablePhrase(new TestQ("What would God have me to say with respect to Paul?", "A", 1, 1), 1, 0);       // what would (1)     | me to (3)       | with respect to (3)
			TranslatablePhrase tp2 = new TranslatablePhrase(new TestQ("What is Paul asking me to say with respect to that dog?", "B", 2, 2), 1, 0);   // what is (3)        | asking (1)      | me to (3)           | with respect to (3) | that dog (4)
			TranslatablePhrase tp3 = new TranslatablePhrase(new TestQ("that dog", "C", 3, 3), 1, 0);                                                  // that dog (4)
			TranslatablePhrase tp4 = new TranslatablePhrase(new TestQ("Is it okay for Paul me to talk with respect to God today?", "D", 4, 4), 1, 0); // is it okay for (1) | me to (3)       | talk (1)            | with respect to (3) | today (1)
			TranslatablePhrase tp5 = new TranslatablePhrase(new TestQ("that dog wishes this Paul and what is say radish", "E", 5, 5), 1, 0);          // that dog (4)       | wishes this (1) | and (1)             | what is (3)         | radish (1)
			TranslatablePhrase tp6 = new TranslatablePhrase(new TestQ("What is that dog?", "F", 6, 6), 1, 0);                                         // what is (3)        | that dog (4)
			tp4.IsExcluded = true;
			tp5.IsExcluded = true;

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { tp1, tp2, tp3, tp4, tp5, tp6 },
				m_dummyKtList, m_keyTermRules, new List<Substitution>());

			Assert.AreEqual(6, pth.Phrases.Count(), "Wrong number of phrases in helper");

			pth.Filter(null, false, PhraseTranslationHelper.KeyTermFilterType.All,
				((start, end, sref) => start >= 2 && end <= 5 && sref != "C"), false);
			pth.Sort(PhraseTranslationHelper.SortBy.Reference, true);
			Assert.AreEqual(1, pth.Phrases.Count(), "Wrong number of phrases in filtered list");
			Assert.AreEqual(tp2, pth[0]);

			pth.Filter(null, false, PhraseTranslationHelper.KeyTermFilterType.All,
				((start, end, sref) => start >= 2 && end <= 5 && sref != "C"), true);
			Assert.AreEqual(3, pth.Phrases.Count(), "Wrong number of phrases in filtered list");
			Assert.AreEqual(tp2, pth[0]);
			Assert.AreEqual(tp4, pth[1]);
			Assert.AreEqual(tp5, pth[2]);
		}
コード例 #28
0
		public void SetTranslation_DoNotTreatNormalLeadingPuncAsOpeningQuestionMark()
		{
			AddMockedKeyTerm("Isaiah", "Isai\u0301as");
			AddMockedKeyTerm("Paul", "Pablo");
			AddMockedKeyTerm("Silas", "Silas");

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did Paul and Silas do in jail?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Were Isaiah and Paul prophets?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2 },
				m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.TranslatableParts.Count());

			phrase1.Translation = "*\u00BFQue\u0301 hicieron Pablo y Silas en la carcel?";
			Assert.AreEqual("Isai\u0301as Pablo?", phrase2.Translation);
		}
コード例 #29
0
ファイル: KeyTermMatch.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the best rendering for this term in when used in the context of the given
		/// phrase.
		/// </summary>
		/// <remarks>If this term occurs more than once in the phrase, it is not possible to
		/// know which occurrence is which.</remarks>
		/// ------------------------------------------------------------------------------------
		public string GetBestRenderingInContext(TranslatablePhrase phrase)
		{
			IEnumerable<string> renderings = Renderings;
			if (!renderings.Any())
				return string.Empty;
			if (renderings.Count() == 1 || TranslatablePhrase.s_helper.TermRenderingSelectionRules == null)
				return Translation;

			List<string> renderingsList = null;
			foreach (RenderingSelectionRule rule in TranslatablePhrase.s_helper.TermRenderingSelectionRules.Where(r => !r.Disabled))
			{
				if (renderingsList == null)
				{
					renderingsList = new List<string>();
					foreach (string rendering in renderings)
					{
						if (rendering == Translation)
							renderingsList.Insert(0, rendering);
						else
							renderingsList.Add(rendering);
					}
				}
				string s = rule.ChooseRendering(phrase.PhraseInUse, Words, renderingsList);
				if (!string.IsNullOrEmpty(s))
					return s;
			}
			return Translation;
		}
コード例 #30
0
		public void ChangeTranslation_PreventPartTranslationFromBeingSetToPunctuation()
		{
			AddMockedKeyTerm("Isaiah", "Isai\u0301as");
			AddMockedKeyTerm("Paul", "Pablo");
			AddMockedKeyTerm("Silas", "Silas");

			TranslatablePhrase phrase1 = new TranslatablePhrase("What did Paul and Silas do in jail?");
			TranslatablePhrase phrase2 = new TranslatablePhrase("Were Isaiah and Paul prophets?");
			TranslatablePhrase phrase3 = new TranslatablePhrase("Did Paul and Silas run away?");
			TranslatablePhrase phrase4 = new TranslatablePhrase("And what did Paul do next?");

			PhraseTranslationHelper pth = new PhraseTranslationHelper(new[] { phrase1, phrase2,
				phrase3, phrase4 }, m_dummyKtList, m_keyTermRules, new List<Substitution>());
			ReflectionHelper.SetField(pth, "m_justGettingStarted", false);

			Assert.AreEqual(3, phrase1.TranslatableParts.Count());
			Assert.AreEqual(3, phrase2.TranslatableParts.Count());
			Assert.AreEqual(3, phrase3.TranslatableParts.Count());
			Assert.AreEqual(3, phrase4.TranslatableParts.Count());

			phrase1.Translation = "\u00BFQue\u0301 hicieron Pablo y Silas en la carcel?";
			phrase2.Translation = "\u00BFEran profetas Pablo e Isai\u0301as?";
			phrase3.Translation = "\u00BFSe corrieron Pablo y Silas?";
			Assert.AreEqual("\u00BFy Pablo?", phrase4.Translation);
		}