Esempio n. 1
0
        public void ExportGuesses()
        {
            //NOTE: The new test paragraphs need to have all new words w/o duplicates so we can predict the guesses
            //xxxcrayzee xxxyouneek xxxsintents.

            // copy a text of first paragraph into a new paragraph to generate guesses.
            StTxtPara paraGlossed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
            StTxtPara paraGuessed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;

            paraGlossed.Contents.UnderlyingTsString = StringUtils.MakeTss("xxxcrayzee xxxyouneek xxxsintents.", Cache.DefaultVernWs);
            paraGuessed.Contents.UnderlyingTsString = paraGlossed.Contents.UnderlyingTsString;

            // collect expected guesses from the glosses in the first paragraph.
            ParagraphAnnotator paGlossed       = new ParagraphAnnotator(paraGlossed);
            List <int>         expectedGuesses = paGlossed.SetupDefaultWordGlosses();

            // then verify we've created guesses for the new text.
            ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed);
            bool fDidParse;

            ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);
            paGuessed.LoadParaDefaultAnalyses();

            // export the paragraph and test the Display results
            m_choices.Add(InterlinLineChoices.kflidWord);
            m_choices.Add(InterlinLineChoices.kflidWordGloss);
            XmlDocument exportedDoc = ExportToXml();

            ValidateExportedParagraph(exportedDoc, m_choices, paraGuessed);
        }
Esempio n. 2
0
        public void ExportPhraseWordGuids()
        {
            // create two paragraphs with two identical sentences.
            // copy a text of first paragraph into a new paragraph to generate guesses.
            StTxtPara paraGlossed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
            StTxtPara paraGuessed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;

            paraGlossed.Contents.UnderlyingTsString = StringUtils.MakeTss(
                "xxxwordone xxxwordtwo xxxwordthree. xxxwordone xxxwordtwo xxxwordthree.",
                Cache.DefaultVernWs);
            paraGuessed.Contents.UnderlyingTsString = paraGlossed.Contents.UnderlyingTsString;

            // collect expected guesses from the glosses in the first paragraph.
            ParagraphAnnotator paGlossed       = new ParagraphAnnotator(paraGlossed);
            List <int>         expectedGuesses = paGlossed.SetupDefaultWordGlosses();

            // then verify we've created guesses for the new text.
            ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed);
            bool fDidParse;

            ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);
            paGuessed.LoadParaDefaultAnalyses();

            // export the paragraph and test the Display results
            m_choices.Add(InterlinLineChoices.kflidWord);
            m_choices.Add(InterlinLineChoices.kflidWordGloss);
            m_choices.Add(InterlinLineChoices.kflidMorphemes);
            m_choices.Add(InterlinLineChoices.kflidLexEntries);
            m_choices.Add(InterlinLineChoices.kflidLexGloss);
            m_choices.Add(InterlinLineChoices.kflidLexPos);

            XmlDocument exportedDoc = ExportToXml("elan");
            // validate that we included the expected metadata
            string exportName = XmlUtils.GetOptionalAttributeValue(exportedDoc.DocumentElement, "exportTarget");

            Assert.AreEqual("elan", exportName);
            string version = XmlUtils.GetOptionalAttributeValue(exportedDoc.DocumentElement, "version");

            Assert.AreEqual("1", version);
            ExportedInterlinearReader         exportReader = new ExportedInterlinearReader(exportedDoc, m_choices);
            ExportedParagraphValidatorForELAN validator    = new ExportedParagraphValidatorForELAN(exportReader, paraGlossed);

            validator.ValidateParagraphs(paraGlossed, exportReader.GetParaNode(paraGlossed.IndexInOwner));
            validator.ValidateParagraphs(paraGuessed, exportReader.GetParaNode(paraGuessed.IndexInOwner));
            // only expecting to collect a total of 2 paragraph guids,
            // each paragraph with 2 phrase guids (2*2)
            // and each phrase with 3 word guids (2*2*3).
            validator.ValidateNonrepeatingGuidCount(2 + 2 * 2 + 2 * 2 * 3);
        }
		public void ExportPhraseWordGuids()
		{
			// create two paragraphs with two identical sentences.
			// copy a text of first paragraph into a new paragraph to generate guesses.
			StTxtPara paraGlossed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			StTxtPara paraGuessed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			paraGlossed.Contents.UnderlyingTsString = StringUtils.MakeTss(
				"xxxwordone xxxwordtwo xxxwordthree. xxxwordone xxxwordtwo xxxwordthree.",
				Cache.DefaultVernWs);
			paraGuessed.Contents.UnderlyingTsString = paraGlossed.Contents.UnderlyingTsString;

			// collect expected guesses from the glosses in the first paragraph.
			ParagraphAnnotator paGlossed = new ParagraphAnnotator(paraGlossed);
			List<int> expectedGuesses = paGlossed.SetupDefaultWordGlosses();

			// then verify we've created guesses for the new text.
			ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed);
			bool fDidParse;
			ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);
			paGuessed.LoadParaDefaultAnalyses();

			// export the paragraph and test the Display results
			m_choices.Add(InterlinLineChoices.kflidWord);
			m_choices.Add(InterlinLineChoices.kflidWordGloss);
			m_choices.Add(InterlinLineChoices.kflidMorphemes);
			m_choices.Add(InterlinLineChoices.kflidLexEntries);
			m_choices.Add(InterlinLineChoices.kflidLexGloss);
			m_choices.Add(InterlinLineChoices.kflidLexPos);

			XmlDocument exportedDoc = ExportToXml("elan");
			// validate that we included the expected metadata
			string exportName = XmlUtils.GetOptionalAttributeValue(exportedDoc.DocumentElement, "exportTarget");
			Assert.AreEqual("elan", exportName);
			string version = XmlUtils.GetOptionalAttributeValue(exportedDoc.DocumentElement, "version");
			Assert.AreEqual("1", version);
			ExportedInterlinearReader exportReader = new ExportedInterlinearReader(exportedDoc, m_choices);
			ExportedParagraphValidatorForELAN validator = new ExportedParagraphValidatorForELAN(exportReader, paraGlossed);
			validator.ValidateParagraphs(paraGlossed, exportReader.GetParaNode(paraGlossed.IndexInOwner));
			validator.ValidateParagraphs(paraGuessed, exportReader.GetParaNode(paraGuessed.IndexInOwner));
			// only expecting to collect a total of 2 paragraph guids,
			// each paragraph with 2 phrase guids (2*2)
			// and each phrase with 3 word guids (2*2*3).
			validator.ValidateNonrepeatingGuidCount(2 + 2*2 + 2*2*3);
		}
		public void ExportGuesses()
		{
			//NOTE: The new test paragraphs need to have all new words w/o duplicates so we can predict the guesses
			//xxxcrayzee xxxyouneek xxxsintents.

			// copy a text of first paragraph into a new paragraph to generate guesses.
			StTxtPara paraGlossed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			StTxtPara paraGuessed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			paraGlossed.Contents.UnderlyingTsString = StringUtils.MakeTss("xxxcrayzee xxxyouneek xxxsintents.", Cache.DefaultVernWs);
			paraGuessed.Contents.UnderlyingTsString = paraGlossed.Contents.UnderlyingTsString;

			// collect expected guesses from the glosses in the first paragraph.
			ParagraphAnnotator paGlossed = new ParagraphAnnotator(paraGlossed);
			List<int> expectedGuesses = paGlossed.SetupDefaultWordGlosses();

			// then verify we've created guesses for the new text.
			ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed);
			bool fDidParse;
			ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);
			paGuessed.LoadParaDefaultAnalyses();

			// export the paragraph and test the Display results
			m_choices.Add(InterlinLineChoices.kflidWord);
			m_choices.Add(InterlinLineChoices.kflidWordGloss);
			XmlDocument exportedDoc = ExportToXml();
			ValidateExportedParagraph(exportedDoc, m_choices, paraGuessed);
		}
Esempio n. 5
0
		public void CheckValidGuessesAfterInsertNewWord_LT8467()
		{
			//NOTE: The new test paragraphs need to have all new words w/o duplicates so we can predict the guesses
			//xxxcrayzee xxxyouneek xxxsintents.

			// copy a text of first paragraph into a new paragraph to generate guesses.
			StTxtPara paraGlossed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			StTxtPara paraGuessed = m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()) as StTxtPara;
			paraGlossed.Contents.UnderlyingTsString = StringUtils.MakeTss("xxxcrayzee xxxyouneek xxxsintents.", Cache.DefaultVernWs);
			paraGuessed.Contents.UnderlyingTsString = paraGlossed.Contents.UnderlyingTsString;

			// collect expected guesses from the glosses in the first paragraph.
			ParagraphAnnotator paGlossed = new ParagraphAnnotator(paraGlossed);
			List<int> expectedGuesses = paGlossed.SetupDefaultWordGlosses();

			// then verify we've created guesses for the new text.
			ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed);
			bool fDidParse;
			ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);

			paGuessed.LoadParaDefaultAnalyses();
			List<int> expectedGuessesBeforeEdit = new List<int>(expectedGuesses);
			ValidateGuesses(expectedGuessesBeforeEdit, paraGuessed);

			// now edit the paraGuessed and expected Guesses.
			paraGuessed.Contents.UnderlyingTsString = StringUtils.MakeTss("xxxcrayzee xxxguessless xxxyouneek xxxsintents.", Cache.DefaultVernWs);
			List<int> expectedGuessesAfterEdit = new List<int>(expectedGuesses);
			// we don't expect a guess for the inserted word, so insert 0 after first twfic.
			expectedGuessesAfterEdit.Insert(1, 0);

			// Note: we need to use ParseText rather than ReparseParagraph, because it uses
			// code to Reuse dummy annotations.
			ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse);
			paGuessed.LoadParaDefaultAnalyses();
			ValidateGuesses(expectedGuessesAfterEdit, paraGuessed);
		}
Esempio n. 6
0
		public void ConvertDummyToReal()
		{
			CheckDisposed();
			(m_fdoCache.LangProject.WordformInventoryOA as WordformInventory).SuspendUpdatingConcordanceWordforms = true;

			//xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.
			IStTxtPara para = (IStTxtPara)m_text1.ContentsOA.ParagraphsOS[(int)Text1ParaIndex.SimpleSegmentPara];
			ParagraphAnnotator ta = new ParagraphAnnotator(para);
			// 1. convert a twfic dummy wordform to real one.
			int hvoCba0_0 =  ta.GetSegmentForm(0,0) ;  // xxxpus
			ICmBaseAnnotation dummyCba0_0 = CmBaseAnnotation.CreateFromDBObject(Cache, hvoCba0_0);
			Assert.IsTrue(dummyCba0_0.IsDummyObject);
			int hvoDummyWordform0_0 = dummyCba0_0.InstanceOfRAHvo;
			IWfiWordform dummyWordform0_0 = WfiWordform.CreateFromDBObject(Cache, hvoDummyWordform0_0);
			Assert.IsTrue(dummyWordform0_0.IsDummyObject);
			// Lookup the form and see if we can find it.
			hvoDummyWordform0_0 = Cache.LangProject.WordformInventoryOA.GetWordformId(dummyWordform0_0.Form.GetAlternativeTss(Cache.DefaultVernWs));
			Assert.AreEqual(dummyWordform0_0.Hvo, hvoDummyWordform0_0);

			IWfiWordform realWordform0_0 = CmObject.ConvertDummyToReal(Cache, dummyWordform0_0.Hvo) as IWfiWordform;
			Assert.IsTrue(realWordform0_0.IsRealObject);
			Assert.AreEqual(dummyWordform0_0.Form.VernacularDefaultWritingSystem,
				realWordform0_0.Form.VernacularDefaultWritingSystem);
			// Make sure we can still lookup the form.
			int hvoRealWordform0_0 = Cache.LangProject.WordformInventoryOA.GetWordformId(realWordform0_0.Form.GetAlternativeTss(Cache.DefaultVernWs));
			Assert.AreEqual(realWordform0_0.Hvo, hvoRealWordform0_0);

			// Enhance: We could check virtual properties for wordform, e.g. wordform Occurrences.

			// 2. convert its twfic annotation to a real one.
			ICmBaseAnnotation realCba0_0 = CmObject.ConvertDummyToReal(Cache, hvoCba0_0) as ICmBaseAnnotation;
			FdoValidator validator = new FdoValidator(para);
			validator.CompareCbas(dummyCba0_0.Hvo, realCba0_0.Hvo,
				String.Format("Para{0}/Segment{1}/SegForm{2}", para.Hvo, 0, 0));

			// 3. convert a twfic annotation with a dummy wordform instanceOf to a real one,
			int hvoCba0_1 = ta.GetSegmentForm(0, 1); // xxxyalola
			ICmBaseAnnotation dummyCba0_1 = CmBaseAnnotation.CreateFromDBObject(Cache, hvoCba0_1);
			Assert.IsTrue(dummyCba0_1.IsDummyObject);
			Assert.IsTrue(Cache.IsDummyObject(dummyCba0_1.InstanceOfRAHvo));
			IWfiWordform dummyWordform0_1 = WfiWordform.CreateFromDBObject(Cache, dummyCba0_1.InstanceOfRAHvo) as IWfiWordform;
			ICmBaseAnnotation realCba0_1 = CmObject.ConvertDummyToReal(Cache, hvoCba0_1) as ICmBaseAnnotation;
			Assert.IsTrue(realCba0_1.IsRealObject);
			validator.CompareCbas(dummyCba0_1.Hvo, realCba0_1.Hvo,
				String.Format("Para{0}/Segment{1}/SegForm{2}", para.Hvo, 0, 1));
			// and confirm the wordform is now real as well.
			IWfiWordform realWordform0_1 = realCba0_1.InstanceOfRA as IWfiWordform;
			Assert.IsNotNull(realWordform0_1);
			Assert.IsTrue(realWordform0_1.IsRealObject);
			Assert.AreEqual(dummyWordform0_1.Form.VernacularDefaultWritingSystem,
				realWordform0_1.Form.VernacularDefaultWritingSystem);

			// 3. Try converting a dummy cba with an analysis to a real one,
			// and check to make sure we haven't altered the basic analysis
			// of another occurrence of the same wordform.
			int hvoCba1_0 = ta.GetSegmentForm(1, 0);  // xxxnihimbilira
			ICmBaseAnnotation dummyCba1_0 = CmBaseAnnotation.CreateFromDBObject(Cache, hvoCba1_0);
			Assert.IsTrue(dummyCba1_0.IsDummyObject);
			int hvoDummyWordform1_0 = dummyCba1_0.InstanceOfRAHvo;
			IWfiWordform dummyWordform1_0 = WfiWordform.CreateFromDBObject(Cache, hvoDummyWordform1_0);
			Assert.IsTrue(dummyWordform1_0.IsDummyObject);
			// this will establish a real wfiGloss analysis and convert cba to real one.
			string wordgloss;
			int hvoWordGloss = ta.SetDefaultWordGloss(1, 0, out wordgloss);
			hvoCba1_0 = ta.GetSegmentForm(1, 0);  // xxxnihimbilira
			Assert.IsFalse(Cache.IsDummyObject(hvoCba1_0));
			Assert.IsTrue(Cache.IsValidObject(hvoCba1_0));

			int hvoCba2_1 = ta.GetSegmentForm(2, 1);  // xxxnihimbilira (third instance)
			ICmBaseAnnotation dummyCba2_1 = CmBaseAnnotation.CreateFromDBObject(Cache, hvoCba2_1);
			Assert.IsTrue(dummyCba2_1.IsDummyObject);
			int hvoDummyWordform2_1 = dummyCba2_1.InstanceOfRAHvo;
			// the basic class of the InstanceOf should still be the same.
			Assert.AreEqual(WfiWordform.kClassId, Cache.GetClassOfObject(hvoDummyWordform2_1),
				"Cba2_1.InstanceOf should be WfiWordform.");
			// Instance of, should be real, however.
			Assert.IsFalse(Cache.IsDummyObject(hvoDummyWordform2_1), "Cba2_1.InstanceOf should not be dummy object.");
			// See if we can get the guess for this twfic.
			ta.LoadParaDefaultAnalyses();
			int tagTwficDefault = StTxtPara.TwficDefaultFlid(Cache);
			int hvoGuess2_1 = Cache.GetObjProperty(hvoCba2_1, tagTwficDefault);
			Assert.IsTrue(Cache.IsValidObject(hvoGuess2_1), "Cba2_1 should have a default analysis (guess).");
			// Convert it to a real, and then see if we still have the guess.
			ICmBaseAnnotation realCba2_1 = CmObject.ConvertDummyToReal(Cache, hvoCba2_1) as ICmBaseAnnotation;
			int hvoGuess2_1_real = Cache.GetObjProperty(realCba2_1.Hvo, tagTwficDefault);
			Assert.AreEqual(hvoGuess2_1, hvoGuess2_1_real, "Cba2_1 has unexpected twfic default after conversion.");
			(m_fdoCache.LangProject.WordformInventoryOA as WordformInventory).SuspendUpdatingConcordanceWordforms = false;
		}