/// <summary>
        /// Gets a ResultSet containing entries whose gloss match glossForm sorted by the lexical form
        /// in the given writingsystem.
        /// Use "Form" to access the lexical form and "Gloss/Form" to access the Gloss in a RecordToken.
        /// </summary>
        /// <param name="glossForm"></param>
        /// <param name="lexicalUnitWritingSystemDefinition"></param>
        /// <returns></returns>
        public ResultSet <LexEntry> GetEntriesWithMatchingGlossSortedByLexicalForm(
            LanguageForm glossForm, WritingSystemDefinition lexicalUnitWritingSystemDefinition)
        {
            if (null == glossForm || string.IsNullOrEmpty(glossForm.Form))
            {
                throw new ArgumentNullException("glossForm");
            }
            if (lexicalUnitWritingSystemDefinition == null)
            {
                throw new ArgumentNullException("lexicalUnitWritingSystemDefinition");
            }
            var allGlossesResultSet = GetAllEntriesWithGlossesSortedByLexicalForm(lexicalUnitWritingSystemDefinition);
            var filteredResultSet   = new List <RecordToken <LexEntry> >();

            foreach (RecordToken <LexEntry> recordToken in allGlossesResultSet)
            {
                if (((string)recordToken["Gloss"] == glossForm.Form) &&
                    ((string)recordToken["GlossWritingSystem"] == glossForm.WritingSystemId))
                {
                    filteredResultSet.Add(recordToken);
                }
            }

            return(new ResultSet <LexEntry>(this, filteredResultSet));
        }
Exemple #2
0
        /// <summary>
        /// Gets a ResultSet containing entries whose gloss match glossForm sorted by the lexical form
        /// in the given writingsystem.
        /// Use "Form" to access the lexical form and "Gloss/Form" to access the Gloss in a RecordToken.
        /// </summary>
        /// <param name="glossForm"></param>
        /// <param name="lexicalUnitWritingSystem"></param>
        /// <returns></returns>
        public ResultSet <LexEntry> GetEntriesWithMatchingMeaningSortedByLexicalForm(
            LanguageForm meaningForm, IWritingSystemDefinition lexicalUnitWritingSystem,
            bool glossMeaningField)
        {
            if (null == meaningForm || string.IsNullOrEmpty(meaningForm.Form))
            {
                throw new ArgumentNullException("meaningForm");
            }
            if (lexicalUnitWritingSystem == null)
            {
                throw new ArgumentNullException("lexicalUnitWritingSystem");
            }
            ResultSet <LexEntry>           allMeaningsResultSet = GetAllEntriesWithMeaningsSortedByLexicalForm(lexicalUnitWritingSystem, glossMeaningField);
            List <RecordToken <LexEntry> > filteredResultSet    = new List <RecordToken <LexEntry> >();

            foreach (RecordToken <LexEntry> recordToken in allMeaningsResultSet)
            {
                if (((string)recordToken["Meaning"] == meaningForm.Form) &&
                    ((string)recordToken["MeaningWritingSystem"] == meaningForm.WritingSystemId))
                {
                    filteredResultSet.Add(recordToken);
                }
            }

            return(new ResultSet <LexEntry>(this, filteredResultSet));
        }
Exemple #3
0
        private void LanguageFormAdded(object sender, EventArgs e)
        {
            LanguageForm fLang = sender as LanguageForm;

            if (fLang == null)
            {
                return;
            }
            ListView m_lvLanguages = Tools.GetControl("m_lvLanguages", fLang) as ListView;

            if (m_lvLanguages == null)
            {
                return;
            }
            m_lvLanguages.BeginUpdate();
            int[] aWidths = StrUtil.DeserializeIntArray(UIUtil.GetColumnWidths(m_lvLanguages) + " " + DpiUtil.ScaleIntX(60).ToString());
            int   iCol    = m_lvLanguages.Columns.Add("L-ID").Index;

            foreach (ListViewItem i in m_lvLanguages.Items)
            {
                try
                {
                    XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation));
                    KPTranslation   t  = KPTranslation.Load(i.Tag as string, xs);
                    i.SubItems.Add(t.Properties.Iso6391Code);
                }
                catch { if (string.IsNullOrEmpty(i.Tag as string))
                        {
                            i.SubItems.Add("en");
                        }
                }
            }
            UIUtil.ResizeColumns(m_lvLanguages, aWidths, true);
            m_lvLanguages.EndUpdate();
        }
Exemple #4
0
        private static void RenderHeadword(LexEntry entry,
                                           StringBuilder html,
                                           LexEntryRepository lexEntryRepository)
        {
            if (StartNewSpan(html, HeadWordWritingSystemId, true, false, 0))
            {
                LanguageForm headword = entry.GetHeadWord(HeadWordWritingSystemId);
                if (null != headword)
                {
                    var str = MakeSafeForHtmlAndFormat(headword.Form);
                    html.Append(str);

                    int homographNumber = lexEntryRepository.GetHomographNumber(
                        entry,
                        WeSayWordsProject.Project.DefaultViewTemplate.HeadwordWritingSystem
                        );
                    if (homographNumber > 0)
                    {
                        html.Append("<sub>" + homographNumber.ToString() + "</sub>");
                    }
                }
                else
                {
                    html.Append("??? ");
                }
                html.Append(" </span>");
            }
        }
Exemple #5
0
        private static void RenderHeadword(LexEntry entry,
                                           StringBuilder rtf,
                                           LexEntryRepository lexEntryRepository)
        {
            rtf.Append(@"{\b ");
            LanguageForm headword = entry.GetHeadWord(HeadWordWritingSystemId);

            if (null != headword)
            {
                // rtf.Append(RenderField(headword, currentItem, 2, null));

                rtf.Append(SwitchToWritingSystem(headword.WritingSystemId, 2));
                rtf.Append(headword.Form);
                //   rtf.Append(" ");

                int homographNumber = lexEntryRepository.GetHomographNumber(
                    entry,
                    WeSayWordsProject.Project.DefaultViewTemplate.HeadwordWritingSystem
                    );
                if (homographNumber > 0)
                {
                    rtf.Append(@"{\sub " + homographNumber + "}");
                }
            }
            else
            {
                rtf.Append("??? ");
            }
            rtf.Append("}");
        }
Exemple #6
0
		public void ObjectEquals_OneStarredOtherIsNot_False()
		{
			var form1 = new LanguageForm();
			var form2 = new LanguageForm();
			form1.IsStarred = true;
			Assert.That(form1.Equals((object)form2), Is.False);
		}
 public EstablishmentNameForm(SelectListItem[] languageOptions)
 {
     TranslationToLanguage = new LanguageForm
     {
         Options = languageOptions,
     };
 }
Exemple #8
0
 /// <summary>
 /// called when the client changes our Control.Text... we need to them move that into the html
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnTextChanged(object sender, EventArgs e)
 {
     SetText(Text);
     AdjustHeight();
     LanguageForm.AdjustSpansForTextChange(_previousText, Text, Spans);
     _previousText = Text;
 }
Exemple #9
0
 string WriteSpanStartElementAndGetText(LanguageForm form, LanguageForm.FormatSpan span)
 {
     Writer.WriteStartElement("span");
     if (!String.IsNullOrEmpty(span.Lang))
     {
         Writer.WriteAttributeString("lang", span.Lang);
     }
     if (!String.IsNullOrEmpty(span.Class))
     {
         Writer.WriteAttributeString("class", span.Class);
     }
     if (!String.IsNullOrEmpty(span.LinkURL))
     {
         Writer.WriteAttributeString("href", span.LinkURL);
     }
     if (span.Index + span.Length <= form.Form.Length)
     {
         return(form.Form.Substring(span.Index, span.Length));
     }
     else if (span.Index < form.Form.Length)
     {
         return(form.Form.Substring(span.Index));
     }
     else
     {
         return(String.Empty);
     }
 }
Exemple #10
0
 public IWritingSystemDefinition GetWritingSystemOfLanguageForm(LanguageForm languageForm)
 {
     if (!_viewTemplate.WritingSystems.Contains(languageForm.WritingSystemId))
     {
         return(null);
     }
     return(_viewTemplate.WritingSystems.Get(languageForm.WritingSystemId));
 }
Exemple #11
0
        private void barButtonLanguage_ItemClick(object sender, ItemClickEventArgs e)
        {
            LanguageForm xform1 = new LanguageForm(_FlexSys)
            {
                MdiParent = this
            };

            xform1.Show();
        }
        public void ObjectEquals_Null_False()
        {
            var form1 = new LanguageForm {
                IsStarred = true, WritingSystemId = "en", Form = "form1"
            };
            LanguageForm form2 = null;

            Assert.That(form1.Equals((object)form2), Is.False);
        }
        public void AdjustSpans_Delete()
        {
            // In these tests, we're testing (deleting) edits to the formatted string
            // "This is a <span class='Strong'>test</span> of <span class='Weak'>something</span> or other."
            // See http://jira.palaso.org/issues/browse/WS-34799 for a discussion of what we want to achieve.
            List <LanguageForm.FormatSpan> spans = new List <LanguageForm.FormatSpan>();
            string oldString = "This is a test of something or other.";

            // before any spans (remove 3 characters)
            var expected = CreateSpans(spans, -3, 0, -3, 0);

            LanguageForm.AdjustSpansForTextChange(oldString, "This a test of something or other.", spans);
            VerifySpans(expected, spans);

            // before any spans, but next to first span (remove 2 characters)
            expected = CreateSpans(spans, -2, 0, -2, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is test of something or other.", spans);
            VerifySpans(expected, spans);

            // start before any spans, but including part of first span (remove 2 before and 2 inside span)
            expected = CreateSpans(spans, -2, -2, -4, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is st of something or other.", spans);
            VerifySpans(expected, spans);

            // start before any spans, but extending past first span (remove 2 before, 4 inside, and 4 after/between)
            // The span length going negative is okay, and the same as going to zero: the span is ignored thereafter.
            expected = CreateSpans(spans, -2, -8, -10, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is something or other.", spans);
            VerifySpans(expected, spans);

            // delete exactly the first span (remove 4 inside)
            expected = CreateSpans(spans, 0, -4, -4, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a  of something or other.", spans);
            VerifySpans(expected, spans);

            // after any spans (effectively no change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of something or other", spans);
            VerifySpans(expected, spans);

            // after any spans, but adjacent to last span (effectively no change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of somethingther.", spans);
            VerifySpans(expected, spans);

            // delete from middle of first span to middle of second span
            expected = CreateSpans(spans, 0, -2, -6, -7);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a teng or other.", spans);
            VerifySpans(expected, spans);

            // change text without changing length of string
            // (alas, we can't handle this kind of wholesale change, so effectively no change to the spans)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "That is a joke of some other topic!!!", spans);
            VerifySpans(expected, spans);
        }
Exemple #14
0
        /// <summary>
        /// this is safer
        /// </summary>
        /// <param name="writingSystemId"></param>
        /// <returns>string.emtpy if no headword</returns>
        public string GetHeadWordForm(string writingSystemId)
        {
            LanguageForm form = GetHeadWord(writingSystemId);

            if (form == null)
            {
                return(string.Empty);
            }
            return(form.Form);
        }
Exemple #15
0
 private static bool IsCurrentField(MultiText text,
                                    LanguageForm l,
                                    CurrentItemEventArgs currentItem)
 {
     if (currentItem == null)
     {
         return(false);
     }
     return(currentItem.DataTarget == text &&
            currentItem.WritingSystemId == l.WritingSystemId);
 }
        public void ContainsEqualForm_DifferentValue_False()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws"] = "test";
            LanguageForm form = new LanguageForm();

            form.WritingSystemId = "ws";
            form.Form            = "tests";
            Assert.IsFalse(x.ContainsEqualForm(form));
        }
        public void ObjectEquals_StarredWritingSystemAndFormAreIdentical_True()
        {
            var form1 = new LanguageForm {
                IsStarred = true, WritingSystemId = "en", Form = "form1"
            };
            var form2 = new LanguageForm {
                IsStarred = true, WritingSystemId = "en", Form = "form1"
            };

            Assert.That(form1.Equals((object)form2), Is.True);
        }
        public void ObjectEquals_OneContainsFormInWritingSystemOtherDoesNot_False()
        {
            var form1 = new LanguageForm {
                WritingSystemId = "en", Form = "form1"
            };
            var form2 = new LanguageForm {
                WritingSystemId = "en", Form = "form2"
            };

            Assert.That(form1.Equals((object)form2), Is.False);
        }
        public void Equals_OneContainsWritingSystemOtherDoesNot_False()
        {
            var form1 = new LanguageForm {
                WritingSystemId = "en"
            };
            var form2 = new LanguageForm {
                WritingSystemId = "de"
            };

            Assert.That(form1.Equals(form2), Is.False);
        }
        public void ContainsEqualForm_SameContent_True()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws1"] = "testing";
            x["ws"]  = "test";
            x["ws2"] = "testing";
            LanguageForm form = new LanguageForm();

            form.WritingSystemId = "ws";
            form.Form            = "test";
            Assert.IsTrue(x.ContainsEqualForm(form));
        }
Exemple #21
0
 private void OnTextChanged(object sender, EventArgs e)
 {
     //only first change per focus session will be logged
     if (!_haveAlreadyLoggedTextChanged && Focused
         /*try not to report when code is changing us*/)
     {
         _haveAlreadyLoggedTextChanged = true;
         Logger.WriteMinorEvent("First_TextChange (could be paste via mouse) {0}:{1}",
                                _nameForLogging,
                                _writingSystem.Id);
     }
     LanguageForm.AdjustSpansForTextChange(_previousText, Text, Spans);
     _previousText = Text;
 }
        /// <summary>
        /// In some cases, we're better off copying from another national language than leaving the field empty.
        /// </summary>
        /// <remarks>
        ///	This is a tough decision. Without this, if we have, say, an English Contributors list but English isn't the N1 (L2), then the
        /// book won't show it at all. An ideal solution would just order them and then "display the first non-empty one", but that would require some java script... not
        /// something could be readily done in CSS, far as I can think.
        /// For now, I *think* this won't do any harm, and if it does, it's adding data, not losing it. Users had complained about "losing" the contributor data before.
        ///</remarks>
        private string PossiblyCopyFromAnotherLanguage(XmlElement element, string languageCodeOfTargetField, DataSet data, string key)
        {
            string classes = element.GetAttribute("class");

            if (!string.IsNullOrEmpty(classes))
            {
                // if this field is normally read-only, make it readable so they can do any translation that might be needed
                element.SetAttribute("class", classes.Replace("bloom-readOnlyInTranslationMode", ""));
            }

            if (!classes.Contains("bloom-copyFromOtherLanguageIfNecessary"))
            {
                return("");
            }

            LanguageForm formToCopyFromSinceOursIsMissing = null;
            string       s = "";

            if ((languageCodeOfTargetField == _collectionSettings.Language2Iso639Code ||             //is it a national language?
                 languageCodeOfTargetField == _collectionSettings.Language3Iso639Code))
            {
                formToCopyFromSinceOursIsMissing =
                    data.TextVariables[key].TextAlternatives.GetBestAlternative(new[] { languageCodeOfTargetField, "*", "en", "fr", "es", "pt" });
                if (formToCopyFromSinceOursIsMissing != null)
                {
                    s = formToCopyFromSinceOursIsMissing.Form;
                }

                if (string.IsNullOrEmpty(s))
                {
                    //OK, well even on a non-global language is better than none
                    //s = data.TextVariables[key].TextAlternatives.GetFirstAlternative();
                    formToCopyFromSinceOursIsMissing = GetFirstAlternativeForm(data.TextVariables[key].TextAlternatives);
                    if (formToCopyFromSinceOursIsMissing != null)
                    {
                        s = formToCopyFromSinceOursIsMissing.Form;
                    }
                }
            }

            /* this was a fine idea, execpt that if the user then edits it, well, it's not borrowed anymore but we'll still have this sitting there misleading us
             *                                      //record our dubious deed for posterity
             *                                      if (formToCopyFromSinceOursIsMissing != null)
             *                                      {
             *                                              node.SetAttribute("bloom-languageBloomHadToCopyFrom",
             *                                                                                formToCopyFromSinceOursIsMissing.WritingSystemId);
             *                                      }
             */
            return(s);
        }
Exemple #23
0
        private static void RenderForm(MultiText text,
                                       CurrentItemEventArgs currentItem,
                                       StringBuilder htmlBuilder,
                                       LanguageForm form,
                                       int sizeBoost)
        {
            bool underLineOn = IsCurrentField(text, form, currentItem);

            if (StartNewSpan(htmlBuilder, form.WritingSystemId, false, underLineOn, sizeBoost))
            {
                var str = MakeSafeForHtmlAndFormat(form.Form);
                htmlBuilder.Append(str);
                htmlBuilder.Append(" </span>");
            }
        }
Exemple #24
0
 void CopySpans(Dictionary <string, List <LiftSpan> > spans)
 {
     foreach (var key in spans.Keys)
     {
         LanguageForm form = Find(key);
         if (form == null)
         {
             continue;
         }
         foreach (var span in spans[key])
         {
             form.AddSpan(span.Index, span.Length, span.Lang, span.Class, span.LinkURL);
         }
     }
 }
        public void UpdateSpans_Insert()
        {
            // In these tests, we're testing (inserting) edits to the formatted string
            // "This is a <span class='Strong'>test</span> of <span class='Weak'>something</span> or other."
            // See http://jira.palaso.org/issues/browse/WS-34799 for a discussion of what we want to achieve.
            List <LanguageForm.FormatSpan> spans = new List <LanguageForm.FormatSpan>();
            string oldString = "This is a test of something or other.";

            // before any spans (add 3 characters)
            var expected = CreateSpans(spans, 3, 0, 3, 0);

            LanguageForm.AdjustSpansForTextChange(oldString, "This isn't a test of something or other.", spans);
            VerifySpans(expected, spans);

            // before any spans, but right next to the first span (add 5 characters)
            expected = CreateSpans(spans, 5, 0, 5, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a good test of something or other.", spans);
            VerifySpans(expected, spans);

            // after any spans (add 5 characters, but spans don't change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of something else or other.", spans);
            VerifySpans(expected, spans);

            // inside the first span (increase its length by 2)
            expected = CreateSpans(spans, 0, 2, 2, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a tessst of something or other.", spans);
            VerifySpans(expected, spans);

            // after the first span, but right next to it (increase its length by 3)
            expected = CreateSpans(spans, 0, 3, 3, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a testing of something or other.", spans);
            VerifySpans(expected, spans);

            // inside the second span (increase its length by 9)
            expected = CreateSpans(spans, 0, 0, 0, 9);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of some kind of thing or other.", spans);
            VerifySpans(expected, spans);

            // between the two spans (effectively add 1 character)
            expected = CreateSpans(spans, 0, 0, 1, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test for something or other.", spans);
            VerifySpans(expected, spans);
        }
Exemple #26
0
        //public static IList<LanguageForm> GetActualTextForms(MultiText text, IWritingSystemRepository writingSytems)
        //{
        //    var x = text.Forms.Where(f => !writingSytems.Get(f.WritingSystemId).IsVoice);
        //    return new List<LanguageForm>(x);
        //}

        private static void RenderForm(MultiText text,
                                       CurrentItemEventArgs currentItem,
                                       StringBuilder rtfBuilder,
                                       LanguageForm form,
                                       int sizeBoost)
        {
            if (IsCurrentField(text, form, currentItem))
            {
                rtfBuilder.Append(@"\ul");
            }
            rtfBuilder.Append(SwitchToWritingSystem(form.WritingSystemId, sizeBoost));
            rtfBuilder.Append(form.Form);             // + " ");
            if (IsCurrentField(text, form, currentItem))
            {
                //rtfBuilder.Append(" ");
                //rtfBuilder.Append(Convert.ToChar(160));
                rtfBuilder.Append(@"\ulnone ");
                //rtfBuilder.Append(Convert.ToChar(160));
            }
            rtfBuilder.Append(" ");
        }
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_EntryHasIdenticalSenses_ReturnsBoth()
		{
			LanguageForm identicalGloss = new LanguageForm("de", "de Gloss", new MultiText());

			LexEntry entryWithGlossAndLexicalForm = _repository.CreateItem();
			entryWithGlossAndLexicalForm.LexicalForm.SetAlternative("en", "en Word1");
			entryWithGlossAndLexicalForm.Senses.Add(new LexSense());
			entryWithGlossAndLexicalForm.Senses[0].Gloss.SetAlternative(identicalGloss.WritingSystemId, identicalGloss.Form);
			entryWithGlossAndLexicalForm.Senses.Add(new LexSense());
			entryWithGlossAndLexicalForm.Senses[1].Gloss.SetAlternative(identicalGloss.WritingSystemId, identicalGloss.Form);

			var lexicalFormWritingSystem = WritingSystemDefinitionForTest("en");
			var matches = _repository.GetEntriesWithMatchingGlossSortedByLexicalForm(identicalGloss, lexicalFormWritingSystem);
			Assert.AreEqual(2, matches.Count);
			Assert.AreEqual("en Word1", matches[0]["Form"]);
			Assert.AreEqual("en Word1", matches[1]["Form"]);
		}
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_TwoEntriesWithSameGlossButDifferentLexicalForms_ReturnsListSortedByLexicalForm()
		{
			LanguageForm glossToMatch = new LanguageForm("de", "de Gloss", new MultiText());
			CreateEntryWithLexicalFormAndGloss(glossToMatch, "en", "en LexicalForm2");
			CreateEntryWithLexicalFormAndGloss(glossToMatch, "en", "en LexicalForm1");
			var lexicalFormWritingSystem = WritingSystemDefinitionForTest("en");
			var matches = _repository.GetEntriesWithMatchingGlossSortedByLexicalForm(glossToMatch, lexicalFormWritingSystem);
			Assert.AreEqual("en LexicalForm1", matches[0]["Form"]);
			Assert.AreEqual("en LexicalForm2", matches[1]["Form"]);
		}
Exemple #29
0
		private static IObjectContainer MakeFlatStringDatabase(bool doIndex)
		{
			string path = Path.GetTempFileName();
			_db4oConfiguration = Db4oFactory.Configure();
			if (doIndex)
			{
				IObjectClass objectClass = _db4oConfiguration.ObjectClass(typeof (LanguageForm));
				objectClass.ObjectField("_form").Indexed(true);
			}

			DiagnosticToConsole listener = new DiagnosticToConsole();
			_db4oConfiguration.Diagnostic().AddListener(listener);

			IObjectContainer db = Db4oFactory.OpenFile(path);
			((YapStream) db).GetNativeQueryHandler().QueryOptimizationFailure +=
					OnQueryOptimizationFailure;

			for (int i = 0;i < 10000;i++)
			{
				LanguageForm f = new LanguageForm("en", i.ToString());
				db.Set(f);
			}
			db.Commit();
			return db;
		}
Exemple #30
0
		private static bool IsCurrentField(MultiText text,
										   LanguageForm l,
										   CurrentItemEventArgs currentItem)
		{
			if (currentItem == null)
			{
				return false;
			}
			return (currentItem.DataTarget == text &&
					currentItem.WritingSystemId == l.WritingSystemId);
		}
Exemple #31
0
		private static void RenderForm(MultiText text,
									   CurrentItemEventArgs currentItem,
									   StringBuilder rtfBuilder,
									   LanguageForm form,
									   int sizeBoost)
		{
			if (IsCurrentField(text, form, currentItem))
			{
				rtfBuilder.Append(@"\ul");
			}
			rtfBuilder.Append(SwitchToWritingSystem(form.WritingSystemId, sizeBoost));
			rtfBuilder.Append(form.Form); // + " ");
			if (IsCurrentField(text, form, currentItem))
			{
				//rtfBuilder.Append(" ");
				//rtfBuilder.Append(Convert.ToChar(160));
				rtfBuilder.Append(@"\ulnone ");
				//rtfBuilder.Append(Convert.ToChar(160));
			}
			rtfBuilder.Append(" ");
		}
Exemple #32
0
		public void CompareTo_Null_ReturnsGreater()
		{
			_languageFormToCompare = null;
			Assert.AreEqual(1, _languageForm.CompareTo(_languageFormToCompare));
		}
Exemple #33
0
		public void Setup()
		{
			_languageFormToCompare = new LanguageForm();
			_languageForm = new LanguageForm();
		}
		private void CreateEntryWithLexicalFormAndGloss(
			LanguageForm glossToMatch, string lexicalFormWritingSystem, string lexicalForm
		)
		{
			LexEntry entryWithGlossAndLexicalForm = _repository.CreateItem();
			entryWithGlossAndLexicalForm.Senses.Add(new LexSense());
			entryWithGlossAndLexicalForm.Senses[0].Gloss.SetAlternative(glossToMatch.WritingSystemId, glossToMatch.Form);
			entryWithGlossAndLexicalForm.LexicalForm.SetAlternative(lexicalFormWritingSystem, lexicalForm);
		}
Exemple #35
0
		public void ObjectEquals_SameObject_True()
		{
			var form = new LanguageForm();
			Assert.That(form.Equals((object) form), Is.True);
		}
 public void RemoveLanguageForm(LanguageForm languageForm)
 {
     Debug.Assert(Forms.Length > 0);
     LanguageForm[] forms = new LanguageForm[Forms.Length - 1];
     for (int i = 0, j = 0; i < forms.Length; i++,j++)
     {
         if (Forms[j] == languageForm)
         {
             j++;
         }
         forms[i] = Forms[j];
     }
     _forms = forms;
 }
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_EntryHasNoLexicalFormInWritingSystem_ReturnsNullForThatEntry()
		{
			LanguageForm glossToMatch = new LanguageForm("de", "de Gloss", new MultiText());
			CreateEntryWithLexicalFormAndGloss(glossToMatch, "en", "en LexicalForm2");
			var lexicalFormWritingSystem = WritingSystemDefinitionForTest("fr");
			var matches = _repository.GetEntriesWithMatchingGlossSortedByLexicalForm(glossToMatch, lexicalFormWritingSystem);
			Assert.AreEqual(null, matches[0]["Form"]);
		}
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_GlossDoesNotExist_ReturnsEmpty()
		{
			var ws = WritingSystemDefinitionForTest("en");
			LanguageForm glossThatDoesNotExist = new LanguageForm("en", "I don't exist!", new MultiText());
			var matches = _repository.GetEntriesWithMatchingGlossSortedByLexicalForm(glossThatDoesNotExist, ws);
			Assert.AreEqual(0, matches.Count);
		}
		public void ContainsEqualForm_DifferentStarred_False()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws"] = "test";
			LanguageForm form = new LanguageForm();
			form.WritingSystemId = "ws";
			form.Form = "test";
			form.IsStarred = true;
			Assert.IsFalse(x.ContainsEqualForm(form));
		}
 public bool ContainsEqualForm(LanguageForm other)
 {
     foreach (LanguageForm form in Forms)
     {
         if (other.Equals(form))
         {
             return true;
         }
     }
     return false;
 }
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_LanguageFormNull_Throws()
		{
			var glossLanguageForm = new LanguageForm("en", "en Gloss", new MultiText());
			Assert.Throws<ArgumentNullException>(() =>
				_repository.GetEntriesWithMatchingGlossSortedByLexicalForm(
				glossLanguageForm, null
			));
		}
        protected void AddLanguageForm(LanguageForm languageForm)
        {
            LanguageForm[] forms = new LanguageForm[Forms.Length + 1];
            for (int i = 0; i < Forms.Length; i++)
            {
                forms[i] = Forms[i];
            }

            //actually copy the contents, as we must now be the parent
            forms[Forms.Length] = new LanguageForm(languageForm.WritingSystemId, languageForm.Form, this);
            Array.Sort(forms);
            _forms = forms;
        }
		public void GetEntriesWithMatchingGlossSortedByLexicalForm_TwoEntriesWithDifferingGlosses_OnlyEntryWithmatchingGlossIsFound()
		{
			const string glossToFind = "Gloss To Find.";
			AddEntryWithGloss(glossToFind);
			AddEntryWithGloss("Gloss Not To Find.");
			LanguageForm glossLanguageForm = new LanguageForm("en", glossToFind, new MultiText());
			var writingSystem = WritingSystemDefinitionForTest("en");
			var list = _repository.GetEntriesWithMatchingGlossSortedByLexicalForm(
				glossLanguageForm, writingSystem
			);
			Assert.AreEqual(1, list.Count);
			Assert.AreSame(glossToFind, list[0].RealObject.Senses[0].Gloss["en"]);
		}
Exemple #44
0
        /// <summary>
        /// Try to add the sense to a matching entry. If none found, make a new entry with the sense
        /// </summary>
        private void AddSenseToLexicon(MultiTextBase lexemeForm, LexSense sense)
        {
            //remove from the gloss and def any forms we don't want in our project for those fields
            foreach (var form in sense.Gloss.Forms)
            {
                //why are we checking definition writing system here? Well, the whole gloss/def thing continues to be murky. When gathering, we're just
                //trying to populate both.  And if you have your 1st def be, say, french, and don't have that in your glosses, well
                // in the WordList task, you won't see the words you gathered, because that's based on glosses!
                if (!_glossWritingSystemIds.Contains(form.WritingSystemId) && !_definitionWritingSystemIds.Contains(form.WritingSystemId))
                {
                    sense.Gloss.SetAlternative(form.WritingSystemId, null);
                }
            }
            foreach (var form in sense.Definition.Forms)
            {
                if (!_definitionWritingSystemIds.Contains(form.WritingSystemId) && !_glossWritingSystemIds.Contains(form.WritingSystemId))
                {
                    sense.Definition.SetAlternative(form.WritingSystemId, null);
                }
            }

            //I don't recall why we did this, but what it is doing is populating def from gloss and vice-versa, where there are blanks

            /* var definition = sense.Definition;
             * if(definition.Empty)
             * {
             *      foreach (var form in sense.Gloss.Forms)
             *      {
             *              //this check makes sure we don't introduce a form form a lang we allow for gloss, but not def
             *              if (_definitionWritingSystemIds.Contains(form.WritingSystemId))
             *                      definition.SetAlternative(form.WritingSystemId, form.Form);
             *      }
             * }
             *
             * var gloss = sense.Gloss;
             * if (gloss.Empty)
             * {
             *      foreach (var form in sense.Definition.Forms)
             *      {
             *              //this check makes sure we don't introduce a form form a lang we allow for def, but not gloss
             *              if (_glossWritingSystemIds.Contains(form.WritingSystemId))
             *                      gloss.SetAlternative(form.WritingSystemId, form.Form);
             *      }
             * } */

            //review: the desired semantics of this find are unclear, if we have more than one ws
            ResultSet <LexEntry> entriesWithSameForm =
                LexEntryRepository.GetEntriesWithMatchingLexicalForm(
                    lexemeForm[_lexicalUnitWritingSystem.Id], _lexicalUnitWritingSystem);
            var          meaningField = _glossMeaningField ? sense.Gloss : sense.Definition;
            LanguageForm firstMeaning = new LanguageForm("en", "-none-", null);

            if (meaningField.Forms.Length > 0)
            {
                firstMeaning = meaningField.Forms[0];
            }

            if (entriesWithSameForm.Count == 0)
            {
                LexEntry entry = LexEntryRepository.CreateItem();
                entry.LexicalForm.MergeIn(lexemeForm);
                entry.Senses.Add(sense.Clone());
                LexEntryRepository.SaveItem(entry);
                Logger.WriteEvent("WordList-Adding new word '{0}'and giving the sense '{1}'", entry.GetSimpleFormForLogging(), firstMeaning);
            }
            else
            {
                LexEntry entry = entriesWithSameForm[0].RealObject;

                foreach (LexSense s in entry.Senses)
                {
                    if (meaningField.Forms.Length > 0)
                    {
                        LanguageForm meaningWeAreAdding         = firstMeaning;
                        string       meaningInThisWritingSystem = _glossMeaningField ?
                                                                  s.Gloss.GetExactAlternative(meaningWeAreAdding.WritingSystemId) :
                                                                  s.Definition.GetExactAlternative(meaningWeAreAdding.WritingSystemId);
                        if (meaningInThisWritingSystem == meaningWeAreAdding.Form)
                        {
                            Logger.WriteEvent("WordList '{0}' already exists in '{1}'", firstMeaning, entry.GetSimpleFormForLogging());
                            return;                             //don't add it again
                        }
                    }
                }
                if (sense.Gloss.Forms.Length == 0 && sense.Definition.Forms.Length == 0 && sense.ExampleSentences.Count == 0)
                {
                    return;                    //nothing worth adding (may happen in unit test)
                }
                entry.Senses.Add(sense);

                //REVIEW: June 2011, Hatton added this, because of WS-34024: if a new *meaning* was added to an existing entry,
                //and then the user quit, this change was unsaved.
                LexEntryRepository.SaveItem(entry);
                Logger.WriteEvent("WordList-Added '{0}' to preexisting '{1}'", firstMeaning, entry.GetSimpleFormForLogging());
            }
        }
		public void ContainsEqualForm_SameContent_True()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws1"] = "testing";
			x["ws"] = "test";
			x["ws2"] = "testing";
			LanguageForm form = new LanguageForm();
			form.WritingSystemId = "ws";
			form.Form = "test";
			Assert.IsTrue(x.ContainsEqualForm(form));
		}