public void OwnedObjects() { m_dtree.Initialize(Cache, false, m_layouts, m_parts); m_dtree.ShowObject(m_entry, "OptSensesEty", null, m_entry, false); // With no etymology or senses, this view contains nothing at all. Assert.AreEqual(0, m_dtree.Controls.Count); m_parent.Close(); m_parent.Dispose(); m_parent = null; ILexSense sense1 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); m_entry.SensesOS.Add(sense1); ILexSense sense2 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); m_entry.SensesOS.Add(sense2); Cache.MainCacheAccessor.SetString(sense2.Hvo, LexSenseTags.kflidScientificName, TsStringUtils.MakeTss("blah blah", Cache.DefaultAnalWs)); m_parent = new Form(); m_dtree = new DataTree(); m_parent.Controls.Add(m_dtree); m_dtree.Initialize(Cache, false, m_layouts, m_parts); m_dtree.ShowObject(m_entry, "OptSensesEty", null, m_entry, false); // With two senses, we get a header slice, a gloss slice for // sense 1 (not optional), and both gloss and Scientific name // slices for sense 2. Assert.AreEqual(3, m_dtree.Controls.Count); //Assert.AreEqual("Senses", (m_dtree.Controls[0] as Slice).Label); Assert.AreEqual("Gloss", (m_dtree.Controls[0] as Slice).Label); Assert.AreEqual("Gloss", (m_dtree.Controls[1] as Slice).Label); Assert.AreEqual("ScientificName", (m_dtree.Controls[2] as Slice).Label); m_parent.Close(); m_parent.Dispose(); m_parent = null; ILexEtymology lm = Cache.ServiceLocator.GetInstance <ILexEtymologyFactory>().Create(); m_entry.EtymologyOA = lm; m_parent = new Form(); m_dtree = new DataTree(); m_parent.Controls.Add(m_dtree); m_dtree.Initialize(Cache, false, m_layouts, m_parts); m_dtree.ShowObject(m_entry, "OptSensesEty", null, m_entry, false); // Adding an etymology gets us just no more slices so far, // because it doesn't have a form or source Assert.AreEqual(3, m_dtree.Controls.Count); //Assert.AreEqual("Etymology", (m_dtree.Controls[3] as Slice).Label); m_parent.Close(); m_parent.Dispose(); m_parent = null; lm.Source = "source"; // Again set both because I'm not sure which it really // should be. lm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeTss("rubbish", Cache.DefaultVernWs); lm.Form.AnalysisDefaultWritingSystem = TsStringUtils.MakeTss("rubbish", Cache.DefaultAnalWs); m_parent = new Form(); m_dtree = new DataTree(); m_parent.Controls.Add(m_dtree); m_dtree.Initialize(Cache, false, m_layouts, m_parts); m_dtree.ShowObject(m_entry, "OptSensesEty", null, m_entry, false); // When the etymology has something we get two more. Assert.AreEqual(5, m_dtree.Controls.Count); Assert.AreEqual("Form", (m_dtree.Controls[3] as Slice).Label); Assert.AreEqual("Source", (m_dtree.Controls[4] as Slice).Label); }
/// <summary> /// Convert FDO lex entry to LF lex entry. /// </summary> /// <returns>LF entry /// <param name="fdoEntry">Fdo entry.</param> private LfLexEntry FdoLexEntryToLfLexEntry(ILexEntry fdoEntry) { if (fdoEntry == null) { return(null); } ILgWritingSystem AnalysisWritingSystem = ServiceLocator.LanguageProject.DefaultAnalysisWritingSystem; ILgWritingSystem VernacularWritingSystem = ServiceLocator.LanguageProject.DefaultVernacularWritingSystem; var lfEntry = new LfLexEntry(); IMoForm fdoLexeme = fdoEntry.LexemeFormOA; if (fdoLexeme == null) { lfEntry.Lexeme = null; } else { lfEntry.Lexeme = ToMultiText(fdoLexeme.Form); } // Other fields of fdoLexeme (AllomorphEnvironments, LiftResidue, MorphTypeRA, etc.) not mapped // Fields below in alphabetical order by ILexSense property, except for Lexeme foreach (IMoForm allomorph in fdoEntry.AlternateFormsOS) { // Do nothing; LanguageForge doesn't currently handle allomorphs, so we don't convert them } lfEntry.EntryBibliography = ToMultiText(fdoEntry.Bibliography); // TODO: Consider whether to use fdoEntry.CitationFormWithAffixType instead // (which would produce "-s" instead of "s" for the English plural suffix, for instance) lfEntry.CitationForm = ToMultiText(fdoEntry.CitationForm); lfEntry.Note = ToMultiText(fdoEntry.Comment); // DateModified and DateCreated can be confusing, because LF and FDO are doing two different // things with them. In FDO, there is just one DateModified and one DateCreated; simple. But // in LF, there is an AuthorInfo record as well, which contains its own ModifiedDate and CreatedDate // fields. (Note the word order: there's LfEntry.DateCreated, and LfEntry.AuthorInfo.CreatedDate). // The conversion we have chosen to use is: AuthorInfo will correspond to FDO. So FDO.DateCreated // becomes AuthorInfo.CreatedDate, and FDO.DateModified becomes AuthorInfo.ModifiedDate. The two // fields on the LF entry will instead refer to when the *Mongo record* was created or modified, // and the LfEntry.DateCreated and LfEntry.DateModified fields will never be put into FDO. var now = DateTime.UtcNow; if (LfProject.IsInitialClone) { lfEntry.DateCreated = now; } // LanguageForge needs this modified to know there is changed data lfEntry.DateModified = now; if (lfEntry.AuthorInfo == null) { lfEntry.AuthorInfo = new LfAuthorInfo(); } lfEntry.AuthorInfo.CreatedByUserRef = null; lfEntry.AuthorInfo.CreatedDate = fdoEntry.DateCreated.ToUniversalTime(); lfEntry.AuthorInfo.ModifiedByUserRef = null; lfEntry.AuthorInfo.ModifiedDate = fdoEntry.DateModified.ToUniversalTime(); #if DBVERSION_7000068 ILexEtymology fdoEtymology = fdoEntry.EtymologyOA; #else // TODO: Once LF's data model is updated from a single etymology to an array, // convert all of them instead of just the first. E.g., // foreach (ILexEtymology fdoEtymology in fdoEntry.EtymologyOS) { ... } ILexEtymology fdoEtymology = null; if (fdoEntry.EtymologyOS.Count > 0) { fdoEtymology = fdoEntry.EtymologyOS.First(); } #endif if (fdoEtymology != null) { lfEntry.Etymology = ToMultiText(fdoEtymology.Form); lfEntry.EtymologyComment = ToMultiText(fdoEtymology.Comment); lfEntry.EtymologyGloss = ToMultiText(fdoEtymology.Gloss); #if DBVERSION_7000068 lfEntry.EtymologySource = LfMultiText.FromSingleStringMapping(AnalysisWritingSystem.Id, fdoEtymology.Source); #else lfEntry.EtymologySource = ToMultiText(fdoEtymology.LanguageNotes); #endif // fdoEtymology.LiftResidue not mapped } lfEntry.Guid = fdoEntry.Guid; if (fdoEntry.LIFTid == null) { lfEntry.LiftId = null; } else { lfEntry.LiftId = fdoEntry.LIFTid.Normalize(System.Text.NormalizationForm.FormC); // Because LIFT files on disk are NFC and we need to make sure LiftIDs match those on disk } lfEntry.LiteralMeaning = ToMultiText(fdoEntry.LiteralMeaning); if (fdoEntry.PrimaryMorphType != null) { lfEntry.MorphologyType = fdoEntry.PrimaryMorphType.NameHierarchyString; } // TODO: Once LF's data model is updated from a single pronunciation to an array of pronunciations, convert all of them instead of just the first. E.g., //foreach (ILexPronunciation fdoPronunciation in fdoEntry.PronunciationsOS) { ... } if (fdoEntry.PronunciationsOS.Count > 0) { ILexPronunciation fdoPronunciation = fdoEntry.PronunciationsOS.First(); lfEntry.Pronunciation = ToMultiText(fdoPronunciation.Form); lfEntry.CvPattern = LfMultiText.FromSingleITsString(fdoPronunciation.CVPattern, ServiceLocator.WritingSystemFactory); lfEntry.Tone = LfMultiText.FromSingleITsString(fdoPronunciation.Tone, ServiceLocator.WritingSystemFactory); // TODO: Map fdoPronunciation.MediaFilesOS properly (converting video to sound files if necessary) lfEntry.Location = ToStringField(LocationListCode, fdoPronunciation.LocationRA); } lfEntry.EntryRestrictions = ToMultiText(fdoEntry.Restrictions); if (lfEntry.Senses == null) // Shouldn't happen, but let's be careful { lfEntry.Senses = new List <LfSense>(); } lfEntry.Senses.AddRange(fdoEntry.SensesOS.Select(FdoSenseToLfSense)); lfEntry.SummaryDefinition = ToMultiText(fdoEntry.SummaryDefinition); BsonDocument customFieldsAndGuids = _convertCustomField.GetCustomFieldsForThisCmObject(fdoEntry, "entry", ListConverters); BsonDocument customFieldsBson = customFieldsAndGuids["customFields"].AsBsonDocument; BsonDocument customFieldGuids = customFieldsAndGuids["customFieldGuids"].AsBsonDocument; lfEntry.CustomFields = customFieldsBson; lfEntry.CustomFieldGuids = customFieldGuids; return(lfEntry); /* Fields not mapped because it doesn't make sense to map them (e.g., Hvo, backreferences, etc): * fdoEntry.ComplexFormEntries; * fdoEntry.ComplexFormEntryRefs; * fdoEntry.ComplexFormsNotSubentries; * fdoEntry.EntryRefsOS; * fdoEntry.HasMoreThanOneSense; * fdoEntry.HeadWord; // Read-only virtual property * fdoEntry.IsMorphTypesMixed; // Read-only property * fdoEntry.LexEntryReferences; * fdoEntry.MainEntriesOrSensesRS; * fdoEntry.MinimalLexReferences; * fdoEntry.MorphoSyntaxAnalysesOC; * fdoEntry.MorphTypes; * fdoEntry.NumberOfSensesForEntry; * fdoEntry.PicturesOfSenses; * */ /* Fields that would make sense to map, but that we don't because LF doesn't handle them (e.g., allomorphs): * fdoEntry.AllAllomorphs; // LF doesn't handle allomorphs, so skip all allomorph-related fields * fdoEntry.AlternateFormsOS; * fdoEntry.CitationFormWithAffixType; // Citation form already mapped * fdoEntry.DoNotPublishInRC; * fdoEntry.DoNotShowMainEntryInRC; * fdoEntry.DoNotUseForParsing; * fdoEntry.HomographForm; * fdoEntry.HomographFormKey; * fdoEntry.HomographNumber; * fdoEntry.ImportResidue; * fdoEntry.LiftResidue; * fdoEntry.PronunciationsOS * fdoEntry.PublishAsMinorEntry; * fdoEntry.PublishIn; * fdoEntry.ShowMainEntryIn; * fdoEntry.Subentries; * fdoEntry.VariantEntryRefs; * fdoEntry.VariantFormEntries; * fdoEntry.VisibleComplexFormBackRefs; * fdoEntry.VisibleComplexFormEntries; * fdoEntry.VisibleVariantEntryRefs; * */ }
private void WriteEtymology(TextWriter w, ILexEtymology ety) { w.Write("<etymology"); WriteLiftDates(w, ety); w.Write(" type=\"{0}\"", MakeSafeAndNormalizedAttribute(GetProperty(ety, "LiftType").ToString())); w.Write(" source=\"{0}\"", MakeSafeAndNormalizedAttribute(GetProperty(ety, "LiftSource").ToString())); w.WriteLine(">"); WriteAllForms(w, null, null, "form", ety.Form); WriteAllForms(w, null, null, "gloss", ety.Gloss); WriteAllForms(w, "field", "type=\"comment\"", "form", ety.Comment); WriteLiftResidue(w, ety); w.WriteLine("</etymology>"); }