예제 #1
0
        public void TestStringCase()
        {
            CaseFunctions cf = new CaseFunctions("en");

            Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase("abc"));
            Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(""));
            Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(null));
            Assert.AreEqual(StringCaseStatus.title, cf.StringCase("Abc"));
            Assert.AreEqual(StringCaseStatus.title, cf.StringCase("A"));
            Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("AbC"));
            Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("ABC"));
            Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("aBC"));
            int    surrogateUc    = 0x10400;       // DESERET CAPITAL LETTER LONG I
            int    surrogateLc    = 0x10428;       // DESERET SMALL LETTER LONG I
            string strUcSurrogate = Surrogates.StringFromCodePoint(surrogateUc);
            string strLcSurrogate = Surrogates.StringFromCodePoint(surrogateLc);

            // A single upper case surrogate is treated as title.
            Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate));
            Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate + "bc"));
            Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase(strUcSurrogate + "bC"));
            Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(strLcSurrogate + "bc"));
        }
예제 #2
0
		/// <summary>
		/// If hvoWordform is the hvo of a capitalized wordform which has no useful information,
		/// delete it. It is considered useless if
		/// - it has no occurrences
		/// - it has no anlyses
		/// - it doesn't have known incorrect spelling status.
		/// Note that the argument may be some other kind of object (typically a WfiAnalysis or WfiGloss).
		/// If so do nothing.
		/// </summary>
		public static void DeleteRedundantCapitalizedWordform(FdoCache cache, int hvoWordform)
		{
			if (cache.GetClassOfObject(hvoWordform) != WfiWordform.kclsidWfiWordform)
				return;
			if (cache.GetVectorProperty(hvoWordform, OccurrencesFlid(cache), true).Length != 0)
				return;
			if (cache.IsValidObject(hvoWordform))
			{
				// If it's real it might have analyses etc.
				WfiWordform wf = (WfiWordform) CmObject.CreateFromDBObject(cache, hvoWordform);
				if (wf.AnalysesOC.Count > 0)
					return;
				// Arguably we should keep it for known correct spelling status. However, if it's ever been
				// confirmed as an analysis, even temporarily, it will have that.
				if (wf.SpellingStatus == (int)SpellingStatusStates.incorrect)
					return;
			}
			foreach (int ws in cache.LangProject.CurVernWssRS.HvoArray)
			{
				CaseFunctions cf = new CaseFunctions(cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws).IcuLocale);
				string text = cache.GetMultiStringAlt(hvoWordform, (int) WfiWordformTags.kflidForm, ws).Text;
				if (!String.IsNullOrEmpty(text) && cf.StringCase(text) == StringCaseStatus.allLower)
					return;
			}
		   cache.DeleteObject(hvoWordform);
		}
예제 #3
0
		/// <summary>
		/// Lookup the form, and try to match on the specified writing system.
		/// </summary>
		/// <param name="form"></param>
		/// <param name="ws"></param>
		/// <param name="fIncludeLowerCaseForm">match on lower case form, if other case was not found.</param>
		/// <returns></returns>
		public int GetWordformId(string form, int ws, bool fIncludeLowerCaseForm)
		{
			int wfHvo = GetWordformId(form, ws);
			if (fIncludeLowerCaseForm && wfHvo == 0)
			{
				// try finding a lowercase version.
				IWritingSystem wsEngine = m_cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws);
				if (wsEngine == null)
					return 0;
				string locale = wsEngine.IcuLocale;
				CaseFunctions cf = new CaseFunctions(locale);
				string lcForm = cf.ToLower(form);
				// we only want to look up the lower case form, if the given form was not already lowercased.
				if (lcForm != form)
					wfHvo = GetWordformId(lcForm, ws);
			}
			return wfHvo;
		}
예제 #4
0
        public void TestToLower()
        {
            CaseFunctions cf = new CaseFunctions("en");

            Assert.AreEqual("abc", cf.ToLower("ABC"));
        }
예제 #5
0
			virtual internal int SetAlternateCase(int iSegment, int iSegForm, StringCaseStatus targetState, out string alternateCaseForm)
			{
				// Get actual segment form.
				int hvoCbaActual = GetSegmentForm(iSegment, iSegForm);
				int hvoActualInstanceOf;
				IWfiWordform actualCbaWordform;
				GetRealWordformInfo(hvoCbaActual, out hvoActualInstanceOf, out actualCbaWordform);
				ITsString tssWordformBaseline = GetBaselineText(hvoCbaActual);
				// Add any relevant 'other case' forms.
				int nvar;
				int ws = tssWordformBaseline.get_Properties(0).GetIntPropValues((int)FwTextPropType.ktptWs, out nvar); ;
				string locale = m_cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws).IcuLocale;
				CaseFunctions cf = new CaseFunctions(locale);
				switch (targetState)
				{
					case StringCaseStatus.allLower:
						alternateCaseForm = cf.ToLower(actualCbaWordform.Form.GetAlternative(ws));
						break;
					default:
						throw new ArgumentException("target StringCaseStatus(" + targetState.ToString() + ") not yet supported.");
				}

				// Find or create the new wordform.
				IWfiWordform wfAlternateCase = WfiWordform.FindOrCreateWordform(m_cache, alternateCaseForm, ws);

				// Set the annotation to this wordform.
				int hvoCbaReal = SetInstanceOf(hvoCbaActual, wfAlternateCase.Hvo, true);

				if (!tssWordformBaseline.Equals(wfAlternateCase.Form.BestVernacularAlternative))
				{
					// Cache the real form.
					m_cache.VwCacheDaAccessor.CacheStringProp(hvoCbaReal, InterlinVc.TwficRealFormTag(m_cache), tssWordformBaseline);
				}
				return wfAlternateCase.Hvo;
			}
예제 #6
0
		internal string Replacement(ITsString oldTss)
		{
			string replacement = m_newSpelling;
			if (PreserveCase)
			{
				int var;
				int ws = oldTss.get_Properties(0).GetIntPropValues((int)FwTextPropType.ktptWs, out var);
				if (m_cf == null || m_wsCf != ws)
				{
					string icuLocale = m_cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws).IcuLocale;
					m_cf = new CaseFunctions(icuLocale);
					m_wsCf = ws;
				}
				if (m_cf.StringCase(oldTss.Text) == StringCaseStatus.title)
					replacement = m_cf.ToTitle(replacement);
			}
			return replacement;
		}
예제 #7
0
			public override void SetupCombo()
			{
				CheckDisposed();

				base.SetupCombo();
				// Any time we pop this up, the text in the box is the text form of the current
				// analysis, as a starting point.
				ITsStrBldr builder = TsStrBldrClass.Create();
				int cmorphs = MorphCount;
				Debug.Assert(cmorphs != 0); // we're supposed to be building on one of them!

				int hvoWordform = m_sandbox.GetWordformHvoOfAnalysis();
				int hvoAnalysis = m_sandbox.GetWfiAnalysisHvoInUse();

				// Find the actual original form of the current wordform
				ITsString tssForm = m_sandbox.FindAFullWordForm(hvoWordform);
				string form = StrFromTss(tssForm);
				bool fBaseWordIsPhrase = SandboxBase.IsPhrase(form);

				// First, store the current morph breakdown if we have one,
				// Otherwise, if the user has deleted all the morphemes on the morpheme line
				// (per LT-1621) simply use the original wordform.
				// NOTE: Normally we would use Sandbox.IsMorphFormLineEmpty for this condition
				// but since we're already using the variable(s) needed for this check,
				// here we'll use those variables for economy/performance instead.
				string currentBreakdown = m_sandbox.MorphManager.BuildCurrentMorphsString();
				if (currentBreakdown != string.Empty)
				{
					m_comboList.Text = currentBreakdown;
					// The above and every other distinct morpheme breakdown from owned
					// WfiAnalyses are possible choices.
					ITsString tssText = TsStrFactoryClass.Create().
						MakeString(currentBreakdown, m_wsVern);
					m_comboList.Items.Add(tssText);
				}
				else
				{
					m_comboList.Text = form;
					m_comboList.Items.Add(tssForm);
				}
				// if we added the fullWordform (or the current breakdown is somehow empty although we may have an analysis), then add the
				// wordform HVO; otherwise, add the analysis HVO.
				if (currentBreakdown == string.Empty || (hvoAnalysis == 0 && tssForm != null && tssForm.Equals(m_comboList.Items[0] as ITsString)))
					m_items.Add(hvoWordform);
				else
					m_items.Add(hvoAnalysis);	// [wfi] hvoAnalysis may equal '0' (for annotations that are instances of Wordform).
				Debug.Assert(m_items.Count == m_comboList.Items.Count,
					"combo list (m_comboList) should contain the same count as the m_items list (hvos)");
				AddAnalysesOf(hvoWordform, fBaseWordIsPhrase);
				// Add the original wordform, if not already present.
				AddIfNotPresent(tssForm, hvoWordform);
				m_comboList.SelectedIndex = this.IndexOfCurrentItem;

				// Add any relevant 'other case' forms.
				int wsVern = m_sandbox.RawWordformWs;
				string locale = m_caches.MainCache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsVern).IcuLocale;
				CaseFunctions cf = new CaseFunctions(locale);
				switch (m_sandbox.CaseStatus)
				{
					case StringCaseStatus.allLower:
						break; // no more to add
					case StringCaseStatus.title:
						AddOtherCase(cf.SwitchTitleAndLower(form));
						break;
					case StringCaseStatus.mixed:
						switch (cf.StringCase(form))
						{
							case StringCaseStatus.allLower:
								AddOtherCase(cf.ToTitle(form));
								AddOtherCase(m_sandbox.RawWordform.Text);
								break;
							case StringCaseStatus.title:
								AddOtherCase(cf.ToLower(form));
								AddOtherCase(m_sandbox.RawWordform.Text);
								break;
							case StringCaseStatus.mixed:
								AddOtherCase(cf.ToLower(form));
								AddOtherCase(cf.ToTitle(form));
								break;
						}
						break;
				}
				Debug.Assert(m_items.Count == m_comboList.Items.Count,
					"combo list (m_comboList) should contain the same count as the m_items list (hvos)");
				m_comboList.Items.Add(ITextStrings.ksEditMorphBreaks_);
			}