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); }
public void ExportVariantTypeInformation_LT9374() { CheckDisposed(); m_choices.Add(InterlinLineChoices.kflidWord); m_choices.Add(InterlinLineChoices.kflidMorphemes); m_choices.Add(InterlinLineChoices.kflidLexEntries); m_choices.Add(InterlinLineChoices.kflidLexGloss); m_choices.Add(InterlinLineChoices.kflidLexPos); XmlDocument exportedDoc = ExportToXml(); IStTxtPara para1 = m_text1.ContentsOA.ParagraphsOS[1] as IStTxtPara; ValidateExportedParagraph(exportedDoc, m_choices, para1); // Set alternate case endings. ParagraphAnnotator ta = new ParagraphAnnotator(para1); string formLexEntry = "go"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); int clsidForm; ILexEntry leGo = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "go.pst", null); ta.SetVariantOf(0, 1, leGo, "fr. var."); exportedDoc = this.ExportToXml(); ValidateExportedParagraph(exportedDoc, m_choices, para1); }
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 AlternateCaseAnalyses_Baseline_LT5385() { CheckDisposed(); m_choices.Add(InterlinLineChoices.kflidWord); XmlDocument exportedDoc = ExportToXml(); IStTxtPara para0 = m_text1.ContentsOA.ParagraphsOS[0] as IStTxtPara; ValidateExportedParagraph(exportedDoc, m_choices, para0); // Set alternate case endings. ParagraphAnnotator ta = new ParagraphAnnotator(para0); string altCaseForm; ta.SetAlternateCase(0, 0, StringCaseStatus.allLower, out altCaseForm); Assert.AreEqual("xxxpus", altCaseForm); exportedDoc = this.ExportToXml(); ValidateExportedParagraph(exportedDoc, m_choices, para0); }
/// <exception cref="System.Exception"/> public static void Main(string[] args) { string home = "/home/mjfang/action_grammars/"; // make the first argument one for a base directory string specificFile = "1PPDevUncollapsed.props"; if (args.Length >= 1) { home = args[0]; } if (args.Length >= 2) { specificFile = args[1]; } System.Console.Out.WriteLine("Base directory: " + home); Properties props = StringUtils.PropFileToProperties(home + "ExtractQuotesXMLScripts/" + specificFile); XMLToAnnotation.Data data = XMLToAnnotation.ReadXMLFormat(props.GetProperty("file")); Properties propsPara = new Properties(); propsPara.SetProperty("paragraphBreak", "one"); ParagraphAnnotator pa = new ParagraphAnnotator(propsPara, false); pa.Annotate(data.doc); Properties annotatorProps = new Properties(); annotatorProps.SetProperty("charactersPath", props.GetProperty("charactersPath")); //"characterList.txt" annotatorProps.SetProperty("booknlpCoref", props.GetProperty("booknlpCoref")); annotatorProps.SetProperty("modelPath", props.GetProperty("modelPath")); //"model.ser"); QuoteAttributionAnnotator qaa = new QuoteAttributionAnnotator(annotatorProps); qaa.Annotate(data.doc); ChapterAnnotator ca = new ChapterAnnotator(); ca.Annotate(data.doc); Train(data, annotatorProps); }
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); }
public void ExportVariantTypeInformation_LT9374() { CheckDisposed(); m_choices.Add(InterlinLineChoices.kflidWord); m_choices.Add(InterlinLineChoices.kflidMorphemes); m_choices.Add(InterlinLineChoices.kflidLexEntries); m_choices.Add(InterlinLineChoices.kflidLexGloss); m_choices.Add(InterlinLineChoices.kflidLexPos); XmlDocument exportedDoc = ExportToXml(); IStTxtPara para1 = m_text1.ContentsOA.ParagraphsOS[1] as IStTxtPara; ValidateExportedParagraph(exportedDoc, m_choices, para1); // Set alternate case endings. ParagraphAnnotator ta = new ParagraphAnnotator(para1); string formLexEntry = "go"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); int clsidForm; ILexEntry leGo = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "go.pst", null); ta.SetVariantOf(0, 1, leGo, "fr. var."); exportedDoc = this.ExportToXml(); ValidateExportedParagraph(exportedDoc, m_choices, para1); }
public void AlternateCaseAnalyses_Baseline_LT5385() { CheckDisposed(); m_choices.Add(InterlinLineChoices.kflidWord); XmlDocument exportedDoc = ExportToXml(); IStTxtPara para0 = m_text1.ContentsOA.ParagraphsOS[0] as IStTxtPara; ValidateExportedParagraph(exportedDoc, m_choices, para0); // Set alternate case endings. ParagraphAnnotator ta = new ParagraphAnnotator(para0); string altCaseForm; ta.SetAlternateCase(0, 0, StringCaseStatus.allLower, out altCaseForm); Assert.AreEqual("xxxpus", altCaseForm); exportedDoc = this.ExportToXml(); ValidateExportedParagraph(exportedDoc, m_choices, para0); }
public virtual void Annotate(Annotation annotation) { bool perDocumentCharacterMap = false; if (buildCharacterMapPerAnnotation) { if (annotation.ContainsKey(typeof(CoreAnnotations.MentionsAnnotation))) { EntityMentionsToCharacterMap(annotation); } } // 0. pre-preprocess the text with paragraph annotations // TODO: maybe move this out, definitely make it so that you can set paragraph breaks Properties propsPara = new Properties(); propsPara.SetProperty("paragraphBreak", "one"); ParagraphAnnotator pa = new ParagraphAnnotator(propsPara, false); pa.Annotate(annotation); // 1. preprocess the text // a) setup coref IDictionary <int, string> pronounCorefMap = QuoteAttributionUtils.SetupCoref(CorefPath, characterMap, annotation); //annotate chapter numbers in sentences. Useful for denoting chapter boundaries new ChapterAnnotator().Annotate(annotation); // to incorporate sentences across paragraphs QuoteAttributionUtils.AddEnhancedSentences(annotation); //annotate depparse of quote-removed sentences QuoteAttributionUtils.AnnotateForDependencyParse(annotation); Annotation preprocessed = annotation; // 2. Quote->Mention annotation IDictionary <string, QMSieve> qmSieves = GetQMMapping(preprocessed, pronounCorefMap); foreach (string sieveName in qmSieveList.Split(",")) { qmSieves[sieveName].DoQuoteToMention(preprocessed); } // 3. Mention->Speaker annotation IDictionary <string, MSSieve> msSieves = GetMSMapping(preprocessed, pronounCorefMap); foreach (string sieveName_1 in msSieveList.Split(",")) { msSieves[sieveName_1].DoMentionToSpeaker(preprocessed); } // see if any speaker's could be matched to a canonical entity mention foreach (ICoreMap quote in QuoteAnnotator.GatherQuotes(annotation)) { int firstSpeakerTokenIndex = quote.Get(typeof(QuoteAttributionAnnotator.MentionBeginAnnotation)); if (firstSpeakerTokenIndex != null) { CoreLabel firstSpeakerToken = annotation.Get(typeof(CoreAnnotations.TokensAnnotation))[firstSpeakerTokenIndex]; int entityMentionIndex = firstSpeakerToken.Get(typeof(CoreAnnotations.EntityMentionIndexAnnotation)); if (entityMentionIndex != null) { // set speaker string ICoreMap entityMention = annotation.Get(typeof(CoreAnnotations.MentionsAnnotation))[entityMentionIndex]; int canonicalEntityMentionIndex = entityMention.Get(typeof(CoreAnnotations.CanonicalEntityMentionIndexAnnotation)); if (canonicalEntityMentionIndex != null) { ICoreMap canonicalEntityMention = annotation.Get(typeof(CoreAnnotations.MentionsAnnotation))[canonicalEntityMentionIndex]; // add canonical entity mention info to quote quote.Set(typeof(QuoteAttributionAnnotator.CanonicalMentionAnnotation), canonicalEntityMention.Get(typeof(CoreAnnotations.TextAnnotation))); // set first and last tokens of canonical entity mention IList <CoreLabel> canonicalEntityMentionTokens = canonicalEntityMention.Get(typeof(CoreAnnotations.TokensAnnotation)); CoreLabel canonicalEntityMentionFirstToken = canonicalEntityMentionTokens[0]; CoreLabel canonicalEntityMentionLastToken = canonicalEntityMentionTokens[canonicalEntityMentionTokens.Count - 1]; quote.Set(typeof(QuoteAttributionAnnotator.CanonicalMentionBeginAnnotation), canonicalEntityMentionFirstToken.Get(typeof(CoreAnnotations.TokenBeginAnnotation))); quote.Set(typeof(QuoteAttributionAnnotator.CanonicalMentionEndAnnotation), canonicalEntityMentionLastToken.Get(typeof(CoreAnnotations.TokenBeginAnnotation))); } } } } }
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. IStTxtPara paraGlossed = m_text1.ContentsOA.AddNewTextPara("Normal"); IStTxtPara paraGuessed = m_text1.ContentsOA.AddNewTextPara("Normal"); paraGlossed.Contents = TsStringUtils.MakeTss("xxxcrayzee xxxyouneek xxxsintents.", Cache.DefaultVernWs); paraGuessed.Contents = paraGlossed.Contents; // collect expected guesses from the glosses in the first paragraph. ParagraphAnnotator paGlossed = new ParagraphAnnotator(paraGlossed); ParagraphParser.ParseText(m_text1.ContentsOA); IList<IWfiGloss> expectedGuesses = paGlossed.SetupDefaultWordGlosses(); // then verify we've created guesses for the new text. ParagraphAnnotator paGuessed = new ParagraphAnnotator(paraGuessed); IList<IWfiGloss> expectedGuessesBeforeEdit = expectedGuesses; ValidateGuesses(expectedGuessesBeforeEdit, paraGuessed); // now edit the paraGuessed and expected Guesses. paraGuessed.Contents = TsStringUtils.MakeTss("xxxcrayzee xxxguessless xxxyouneek xxxsintents.", Cache.DefaultVernWs); IList<IWfiGloss> expectedGuessesAfterEdit = new List<IWfiGloss>(expectedGuesses); // we don't expect a guess for the inserted word, so insert 0 after first twfic. expectedGuessesAfterEdit.Insert(1, null); // Note: we need to use ParseText rather than ReparseParagraph, because it uses // code to Reuse dummy annotations. ParagraphParser.ParseText(m_text1.ContentsOA); ValidateGuesses(expectedGuessesAfterEdit, paraGuessed); }
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); }
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; }
//[Ignore("FWC-16 - this test causes NUnit to hang. Need to investigate further.")] public void LT6967_LimitingAutoSearch() { // first initialization should not load or clear matches. Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); m_concordanceControl.SelectLineOption(ConcordanceControl.ConcordanceLines.kBaseline); m_concordanceControl.MatchCase = true; m_concordanceControl.SearchOption = MockConcordanceControl.ConcordanceSearchOption.Anywhere; m_concordanceControl.SearchText = "XXX"; // should get all our twfics. List<int> results = m_concordanceControl.Search(); m_window.ProcessPendingItems(); Assert.AreEqual(6, results.Count); Assert.AreEqual(1, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); m_concordanceControl.ResetCounters(); // Do a refresh // the list should reload with the same results. this.MasterRefresh(); Assert.AreEqual(1, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(6, m_concordanceControl.Results().Count); m_concordanceControl.ResetCounters(); // switch tools and come back, without modifying anything. // The record list should reload, but not the virtual property. m_window.ActivateTool("wordListConcordance"); m_window.ProcessPendingItems(); SwitchToConcordanceTool(); Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(6, m_concordanceControl.Results().Count); m_concordanceControl.ResetCounters(); // switch tools, and modify the text. // the record list should clear, expecting the user to click 'Search' to do the search again. /// interlinearEdit m_window.ActivateTool("interlinearEdit"); m_window.ProcessPendingItems(); IStTxtPara para1 = m_text1.ContentsOA.ParagraphsOS[1] as IStTxtPara; using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT6967_LimitingAutoSearch.ModifyParagraph", "ConcordanceControlTests - LT6967_LimitingAutoSearch.ModifyParagraph")) { // does this issue a prop change? ITsStrFactory tsf = TsStrFactoryClass.Create(); para1.Contents.UnderlyingTsString = tsf.MakeString(para1.Contents.Text + " XXXinsertedTextZZZ", Cache.DefaultVernWs); } SwitchToConcordanceTool(); Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(1, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(0, m_concordanceControl.Results().Count); m_concordanceControl.ResetCounters(); // Do a refresh // we should still have no results, even though we have text in the search line. this.MasterRefresh(); Assert.AreEqual("XXX", m_concordanceControl.SearchText); Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(0, m_concordanceControl.Results().Count); m_concordanceControl.ResetCounters(); // Redo our search. m_concordanceControl.SelectLineOption(ConcordanceControl.ConcordanceLines.kWord); results = m_concordanceControl.Search(); m_window.ProcessPendingItems(); Assert.AreEqual(7, results.Count); Assert.AreEqual(1, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); m_concordanceControl.ResetCounters(); using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT6967_LimitingAutoSearch.MakeAndBreakPhrases", "ConcordanceControlTests - LT6967_LimitingAutoSearch.MakeAndBreakPhrases")) { ParagraphAnnotator ta = new ParagraphAnnotator(m_text1.ContentsOA.ParagraphsOS[1] as IStTxtPara); // 2. Make a basic phrase // XXXlocoZZZ, XXXsegmentZZZ?? [ZZZamazingXXX wonderfulXXXzzzcounselor] ta.MergeAdjacentAnnotations(1, 0); results = m_concordanceControl.Results(); // the merge should delete an annotation. Assert.AreEqual(6, results.Count); Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(7, m_concordanceControl.Clerk.ListSize); // we haven't refreshed our browse view yet. m_concordanceControl.ResetCounters(); results = m_concordanceControl.Search(); // the merge should result in new search results. m_window.ProcessPendingItems(); Assert.AreEqual(6, results.Count); Assert.AreEqual(1, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(6, m_concordanceControl.Clerk.ListSize); // we haven't refreshed our browse view yet. m_concordanceControl.ResetCounters(); } Cache.Undo(); // Undo MakePhrase // Test that the Undo resulted in the old results set. m_window.ProcessPendingItems(); results = m_concordanceControl.Results(); // the undo should delete our phrase annotation. // results count will be zero if Undo cleared our virtual property //Assert.AreEqual(6, results.Count); Assert.AreEqual(0, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(6, m_concordanceControl.Clerk.ListSize); // we haven't refreshed our browse view yet. m_concordanceControl.ResetCounters(); results = m_concordanceControl.Search(); Assert.AreEqual(1, m_concordanceControl.SearchForMatchesCount); Assert.AreEqual(0, m_concordanceControl.ClearMatchesCount); Assert.AreEqual(7, results.Count); Assert.AreEqual(7, m_concordanceControl.Clerk.ListSize); // we haven't refreshed our browse view yet. m_concordanceControl.ResetCounters(); }
void SetupTexts() { // First make a regular text. using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - SetupTexts()", "ConcordanceControlTests - SetupTexts()")) { m_text1 = Cache.LangProject.TextsOC.Add(new Text()); m_text1.ContentsOA = new StText(); StTxtPara para0 = new StTxtPara(); StTxtPara para1 = new StTxtPara(); m_text1.ContentsOA.ParagraphsOS.Append(para0); m_text1.ContentsOA.ParagraphsOS.Append(para1); ITsStrFactory tsf = TsStrFactoryClass.Create(); // 1 2 3 4 5 6 // 0123456789012345678901234567890123456789012345678901234567890123456789 // XXXXsecrecyZZZ; XXXsentenceZZZ!! // XXXlocoZZZ, XXXsegmentZZZ?? ZZZamazingXXX wonderfulXXXzzzcounselor!! para0.Contents.UnderlyingTsString = tsf.MakeString("XXXXsecrecyZZZ; XXXsentenceZZZ!!", Cache.DefaultVernWs); para1.Contents.UnderlyingTsString = tsf.MakeString("XXXlocoZZZ, XXXsegmentZZZ?? ZZZamazingXXX wonderfulXXXzzzcounselor!!", Cache.DefaultVernWs); // add scripture m_newBook1 = new ScrBook(); Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_newBook1); m_newBook1.TitleOA = new StText(); m_newBook1.TitleOA.ParagraphsOS.Append(new StTxtPara()); (m_newBook1.TitleOA.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("XXXnewBook1zzz.Title", Cache.DefaultVernWs); IScrSection newSection1_0 = m_newBook1.SectionsOS.Append(new ScrSection()); newSection1_0.ContentOA = new StText(); StTxtPara paraSection1_0 = new StTxtPara(); (newSection1_0.ContentOA as StText).ParagraphsOS.Append(paraSection1_0); paraSection1_0.Contents.UnderlyingTsString = tsf.MakeString("ZZZnewBook1.Section0.Introduction1XXX", Cache.DefaultVernWs); IScrSection newSection1_1 = m_newBook1.SectionsOS.Append(new ScrSection()); newSection1_1.ContentOA = new StText(); StTxtPara paraSection1_1 = new StTxtPara(); (newSection1_1.ContentOA as StText).ParagraphsOS.Append(paraSection1_1); paraSection1_1.Contents.UnderlyingTsString = tsf.MakeString("XXXnewBook1.Section1.1:1-1:20ZZZ", Cache.DefaultVernWs); // section.VerseRefEnd = book.CanonicalNum * 1000000 + 1 * 1000 + (introSection ? 0 : 1); newSection1_1.VerseRefEnd = 70 * 1000000 + 1 * 1000 + 1; // setup some basic analyses for the texts. string formLexEntry = "XXXlexEntry1"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); int clsidForm; StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs)); ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "XXXlexEntry1.sense1", null); ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0]; ILexSense lexEntry1_Sense2 = LexSense.CreateSense(lexEntry1_Entry, null, "XXXlexEntry1.sense2"); ParagraphAnnotator tapara0 = new ParagraphAnnotator(para0); ParagraphAnnotator tapara1 = new ParagraphAnnotator(para1); ParagraphAnnotator taSection1_0 = new ParagraphAnnotator(paraSection1_0); ParagraphAnnotator taSection1_1 = new ParagraphAnnotator(paraSection1_1); // currently setup mono-morphemic search ArrayList morphForms = new ArrayList(); formLexEntry = "XXXXsecrecyZZZ"; StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs)); ILexEntry lexEntry2_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "XXXlexEntry2.sense1", null); morphForms.Add(lexEntry2_Entry.LexemeFormOA); IWfiAnalysis wfiAnalysis = tapara0.BreakIntoMorphs(0, 0, morphForms); m_wfXXXXsecrecyZZZ = (wfiAnalysis as WfiAnalysis).Owner as IWfiWordform; ILexSense lexEntry2_Sense1 = lexEntry2_Entry.SensesOS[0]; tapara0.SetMorphSense(0, 0, 0, lexEntry2_Sense1); formLexEntry = "XXXsegmentZZZ"; StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs)); ILexEntry lexEntry3_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "XXXlexEntry3.sense1", null); morphForms[0] = lexEntry3_Entry.LexemeFormOA; tapara1.BreakIntoMorphs(0, 2, morphForms); ILexSense lexEntry3_Sense1 = lexEntry3_Entry.SensesOS[0]; tapara1.SetMorphSense(0, 2, 0, lexEntry3_Sense1); formLexEntry = "ZZZamazingXXX"; StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs)); ILexEntry lexEntry4_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "XXXlexEntry4.sense1", null); morphForms[0] = lexEntry4_Entry.LexemeFormOA; tapara1.BreakIntoMorphs(1, 0, morphForms); ILexSense lexEntry4_Sense1 = lexEntry4_Entry.SensesOS[0]; tapara1.SetMorphSense(1, 0, 0, lexEntry4_Sense1); //XXXlocoZZZ morphForms[0] = "XXXlocoZZZ"; tapara1.BreakIntoMorphs(0, 0, morphForms); tapara1.SetMorphSense(0, 0, 0, lexEntry1_Sense2); formLexEntry = paraSection1_0.Contents.Text; StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs)); ILexEntry lexEntry5_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "XXXlexEntry5.sense1", null); morphForms[0] = lexEntry5_Entry.LexemeFormOA; taSection1_0.BreakIntoMorphs(0, 0, morphForms); ILexSense lexEntry5_Sense1 = lexEntry5_Entry.SensesOS[0]; taSection1_0.SetMorphSense(0, 0, 0, lexEntry5_Sense1); morphForms[0] = paraSection1_1.Contents.Text; taSection1_1.BreakIntoMorphs(0, 0, morphForms); // won't match on LexEntry taSection1_1.SetMorphSense(0, 0, 0, lexEntry1_Sense2); // will match on LexGloss string gloss; tapara0.SetDefaultWordGloss(0, 0, out gloss); tapara1.SetDefaultWordGloss(0, 2, out gloss); tapara1.SetDefaultWordGloss(1, 0, out gloss); taSection1_1.SetDefaultWordGloss(0, 0, out gloss); StTxtPara.TwficInfo infoCba0_0_0 = new StTxtPara.TwficInfo(Cache, tapara0.GetSegmentForm(0, 0)); StTxtPara.TwficInfo infoCba1_0_2 = new StTxtPara.TwficInfo(Cache, tapara1.GetSegmentForm(0, 2)); StTxtPara.TwficInfo infoCbaScr_0_0 = new StTxtPara.TwficInfo(Cache, taSection1_1.GetSegmentForm(0, 0)); int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); int segDefn_note = Cache.GetIdFromGuid(LangProject.kguidAnnNote); BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache); ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_freeTranslation); freeTrans0.Comment.SetAlternative("Para0.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_literalTranslation); literalTrans0.Comment.SetAlternative("Para0.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation note0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_note); note0.Comment.SetAlternative("Para0.Segment0: XXXNote.", Cache.DefaultAnalWs); ICmIndirectAnnotation freeTrans1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_freeTranslation); freeTrans1.Comment.SetAlternative("Para1.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTrans1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_literalTranslation); literalTrans1.Comment.SetAlternative("Para1.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation note1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_note); note1.Comment.SetAlternative("Para1.Segment0: XXXNote.", Cache.DefaultAnalWs); // Scripture ICmIndirectAnnotation freeTransScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_freeTranslation); freeTransScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTransScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_literalTranslation); literalTransScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation noteScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_note); noteScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXNote.", Cache.DefaultAnalWs); } }