コード例 #1
0
		/// ------------------------------------------------------------------------------------
		internal PaLexPronunciation(ILexPronunciation lxPro)
		{
			xForm = PaMultiString.Create(lxPro.Form, lxPro.Cache.ServiceLocator);
			xLocation = PaCmPossibility.Create(lxPro.LocationRA);
			CVPattern = lxPro.CVPattern.Text;
			Tone = lxPro.Tone.Text;
			xGuid = lxPro.Guid;

			xMediaFiles = (from x in lxPro.MediaFilesOS
						   where x != null && x.MediaFileRA != null
						   select new PaMediaFile(x)).ToList();
		}
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        internal PaLexPronunciation(ILexPronunciation lxPro)
        {
            xForm     = PaMultiString.Create(lxPro.Form, lxPro.Cache.ServiceLocator);
            xLocation = PaCmPossibility.Create(lxPro.LocationRA);
            CVPattern = lxPro.CVPattern.Text;
            Tone      = lxPro.Tone.Text;
            xGuid     = lxPro.Guid;

            xMediaFiles = (from x in lxPro.MediaFilesOS
                           where x != null && x.MediaFileRA != null
                           select new PaMediaFile(x)).ToList();
        }
コード例 #3
0
        /// <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;
             *
             */
        }
コード例 #4
0
ファイル: LiftExporter.cs プロジェクト: bbriggs/FieldWorks
		private void WritePronunciation(TextWriter w, ILexPronunciation pron)
		{
			w.Write("<pronunciation");
			WriteLiftDates(w, pron);
			w.WriteLine(">");
			WriteAllForms(w, null, null, "form", pron.Form);
			foreach (var file in pron.MediaFilesOS)
				WriteMediaFile(w, file);
			WriteString(w, "field", "type=\"cv-pattern\"", "form", pron.CVPattern);
			WriteString(w, "field", "type=\"tone\"", "form", pron.Tone);
			if (pron.LocationRA != null)
				w.WriteLine("<trait name=\"{0}\" value=\"{1}\"/>",
					RangeNames.sLocationsOA, MakeSafeAndNormalizedAttribute(pron.LocationRA.Name.BestAnalysisVernacularAlternative.Text));
			WriteLiftResidue(w, pron);
			w.WriteLine("</pronunciation>");
		}
コード例 #5
0
		private void SetupPronunciationData(out ILexPronunciation firstPronunciation, out ILexEntry firstEntryWithPronunciation, out ILexEntry firstEntryWithoutPronunciation, out List<ILexEntry> entriesWithoutPronunciations, out List<ILexPronunciation> pronunciations)
		{
			firstPronunciation = null;
			firstEntryWithPronunciation = null;
			firstEntryWithoutPronunciation = null;
			entriesWithoutPronunciations = new List<ILexEntry>();
			pronunciations = new List<ILexPronunciation>();
			// find an entry with pronunciations.
			foreach (ILexEntry entry in Cache.LangProject.LexDbOA.Entries)
			{
				if (entry.PronunciationsOS.Count > 0)
				{
					pronunciations.AddRange(entry.PronunciationsOS);
					if (firstPronunciation == null)
					{
						firstEntryWithPronunciation = entry;
						firstPronunciation = entry.PronunciationsOS[0];
						var newPronunciation = Cache.ServiceLocator.GetInstance<ILexPronunciationFactory>().Create();
						pronunciations.Add(newPronunciation);
						NonUndoableUnitOfWorkHelper.Do(
							Cache.ActionHandlerAccessor, () =>
								entry.PronunciationsOS.Add(newPronunciation));
					}
				}
				else
				{
					entriesWithoutPronunciations.Add(entry);
					if (firstEntryWithoutPronunciation == null)
						firstEntryWithoutPronunciation = entry;
				}
			}
		}
コード例 #6
0
		private ILexEntry CreateZZZparentEntryWithMultipleSensesAndPronunciation(out ILexPronunciation pronunciation)
		{
			string formLexEntry = "ZZZparentEntry";
			ILexEntry parentEntry = null;
			ILexPronunciation pronunc;
			NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
			{
				int clsidForm = 0;
				parentEntry = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(
					MorphServices.FindMorphType(Cache, ref formLexEntry, out clsidForm),
					TsStringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs), "ZZZparentEntry.sense1", null);
				var parentEntry_Sense1 = parentEntry.SensesOS[0];
				var parentEntry_Sense2 = Cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(
					parentEntry, null, "ZZZparentEntry.sense2");
				pronunc = Cache.ServiceLocator.GetInstance<ILexPronunciationFactory>().Create();
				parentEntry.PronunciationsOS.Add(pronunc);
				pronunc.Form.set_String(Cache.DefaultVernWs, "samplePronunciation");
			});
			pronunciation = parentEntry.PronunciationsOS.Last();
			return parentEntry;
		}
コード例 #7
0
ファイル: BulkEditBarTests.cs プロジェクト: sillsdev/WorldPad
		private void SetupPronunciationData(out ILexPronunciation firstPronunciation, out ILexEntry firstEntryWithPronunciation, out ILexEntry firstEntryWithoutPronunciation, out List<ILexEntry> entriesWithoutPronunciations, out List<ILexPronunciation> pronunciations)
		{
			firstPronunciation = null;
			firstEntryWithPronunciation = null;
			firstEntryWithoutPronunciation = null;
			entriesWithoutPronunciations = new List<ILexEntry>();
			pronunciations = new List<ILexPronunciation>();
			// find an entry with pronunciations.
			foreach (ILexEntry entry in Cache.LangProject.LexDbOA.EntriesOC)
			{
				if (entry.PronunciationsOS.Count > 0)
				{
					pronunciations.AddRange(entry.PronunciationsOS);
					if (firstPronunciation == null)
					{
						firstEntryWithPronunciation = entry;
						firstPronunciation = entry.PronunciationsOS[0];
						pronunciations.Add(entry.PronunciationsOS.Append(new LexPronunciation()));
					}
				}
				else
				{
					entriesWithoutPronunciations.Add(entry);
					if (firstEntryWithoutPronunciation == null)
						firstEntryWithoutPronunciation = entry;
				}
			}
		}
コード例 #8
0
ファイル: BulkEditBarTests.cs プロジェクト: sillsdev/WorldPad
		private ILexEntry CreateZZZparentEntryWithMultipleSensesAndPronunciation(out ILexPronunciation pronunciation)
		{
			string formLexEntry = "ZZZparentEntry";
			int clsidForm = 0;
			ILexEntry parentEntry = LexEntry.CreateEntry(Cache,
														 MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm),
														 StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs), "ZZZparentEntry.sense1", null);
			ILexSense parentEntry_Sense1 = parentEntry.SensesOS[0];
			ILexSense parentEntry_Sense2 = LexSense.CreateSense(parentEntry, null, "ZZZparentEntry.sense2");
			pronunciation = parentEntry.PronunciationsOS.Append(new LexPronunciation());
			pronunciation.Form.SetAlternative("samplePronunciation", Cache.DefaultVernWs);
			return parentEntry;
		}