示例#1
0
        public void GetHeadword_CitationFormHasAlternative_CorrectForm()
        {
            LexEntry entry = new LexEntry();

            entry.LexicalForm.SetAlternative("a", "apple");
            MultiText citation =
                entry.GetOrCreateProperty <MultiText>(LexEntry.WellKnownProperties.Citation);

            citation.SetAlternative("b", "barter");
            citation.SetAlternative("a", "applishus");
            Assert.AreEqual("applishus", entry.GetHeadWordForm("a"));
            Assert.AreEqual("barter", entry.GetHeadWordForm("b"));
            Assert.AreEqual(string.Empty, entry.GetHeadWordForm("donthave"));
        }
示例#2
0
        private void SetupComboControl(IValueHolder <string> selectedOptionRef)
        {
            _control.Font = (Font)StringCatalog.LabelFont.Clone();
            if (!_list.Options.Exists(delegate(Option o) { return(o.Key == string.Empty || o.Key == "unknown"); }))
            {
                MultiText unspecifiedMultiText = new MultiText();
                unspecifiedMultiText.SetAlternative(_preferredWritingSystem.Id,
                                                    StringCatalog.Get("~unknown",
                                                                      "This is shown in a combo-box (list of options, like Part Of Speech) when no option has been chosen, or the user just doesn't know what to put in this field."));
                Option unspecifiedOption = new Option("unknown", unspecifiedMultiText);
                _control.AddItem(new Option.OptionDisplayProxy(unspecifiedOption,
                                                               _preferredWritingSystem.Id));
            }
            _list.Options.Sort(CompareItems);
            foreach (Option o in _list.Options)
            {
                _control.AddItem(o.GetDisplayProxy(_preferredWritingSystem.Id));
            }
            _control.BackColor = Color.White;

            Value = selectedOptionRef.Value;
            _control.ListCompleted();

            _control.SelectedValueChanged += OnSelectedValueChanged;

            //don't let the mousewheel do the scrolling, as it's likely an accident (http://jira.palaso.org/issues/browse/WS-34670)
            ((Control)_control).MouseWheel += (sender, e) => {
                HandledMouseEventArgs he = e as HandledMouseEventArgs;
                if (he != null)
                {
                    he.Handled = true;
                }
            };
        }
示例#3
0
		public void Notification()
		{
			_gotHandlerNotice = false;
			MultiText text = new MultiText();
			text.PropertyChanged += propertyChangedHandler;
			text.SetAlternative("zox", "");
			Assert.IsTrue(_gotHandlerNotice);
		}
示例#4
0
        public void Notification()
        {
            _gotHandlerNotice = false;
            MultiText text = new MultiText();

            text.PropertyChanged += propertyChangedHandler;
            text.SetAlternative("zox", "");
            Assert.IsTrue(_gotHandlerNotice);
        }
示例#5
0
        public void GetOrCreateSenseWithMeaning_SenseDoesExists_ExistingSense()
        {
            MultiText meaning = new MultiText();

            meaning.SetAlternative("th", "sense");

            LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);

            Assert.AreSame(_sense, sense);
        }
示例#6
0
        private static void FillInMultiTextOfNewObject(object o,
                                                       string propertyName,
                                                       IWritingSystemDefinition writingSystem,
                                                       string value)
        {
            PropertyInfo info = o.GetType().GetProperty(propertyName);
            MultiText    text = (MultiText)info.GetValue(o, null);

            text.SetAlternative(writingSystem.Id, value);
        }
示例#7
0
        public void GetHeadword_CitationFormLacksAlternative_GetsFormFromLexemeForm()
        {
            LexEntry entry = new LexEntry();

            entry.LexicalForm.SetAlternative("a", "apple");
            MultiText citation =
                entry.GetOrCreateProperty <MultiText>(LexEntry.WellKnownProperties.Citation);

            citation.SetAlternative("b", "bater");
            Assert.AreEqual("apple", entry.GetHeadWordForm("a"));
        }
示例#8
0
        public MultiText GetMultiText()
        {
            //we don't have a binding that would keep an internal multitext up to date.
            //This seems cleaner and sufficient, at the moment.
            MultiText mt = new MultiText();

            foreach (IControlThatKnowsWritingSystem box in TextBoxes)
            {
                mt.SetAlternative(box.WritingSystem.Id, box.Text);
            }
            return(mt);
        }
示例#9
0
        private void WriteHeadWordField(LexEntry entry, string outputFieldName)
        {
            //                headword.SetAlternative(HeadWordWritingSystemId, entry.GetHeadWordForm(HeadWordWritingSystemId));

            var headword = new MultiText();

            foreach (string writingSystemId in _headwordWritingSystemIds)
            {
                headword.SetAlternative(writingSystemId, entry.GetHeadWordForm(writingSystemId));
            }
            WriteMultiTextAsArtificialField(outputFieldName, headword);
        }
示例#10
0
        public void GetOrCreateSenseWithMeaning_SenseWithEmptyStringExists_ExistingSense()
        {
            ClearSenseMeaning();

            MultiText meaning = new MultiText();

            meaning.SetAlternative("th", string.Empty);

            LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);

            Assert.AreSame(_sense, sense);
        }
示例#11
0
        private void AppendSearchKey(string ws, string searchKeys)
        {
            string s = searchKeys.Trim().Replace('\n', ' ').Replace("  ", " ");

            s = s.TrimEnd(new char[] { ',', ' ' });            //fieldworks has extra commas
            string existing = _searchKeys.GetExactAlternative(ws);

            if (existing != string.Empty)
            {
                existing += ", ";
            }
            _searchKeys.SetAlternative(ws, existing + s);
        }
示例#12
0
        public void GetOrCreateSenseWithMeaning_SenseDoesNotExist_NewSenseWithMeaning()
        {
            MultiText meaning = new MultiText();

            meaning.SetAlternative("th", "new");

            LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);

            Assert.AreNotSame(_sense, sense);
#if GlossMeaning
            Assert.AreEqual("new", sense.Gloss.GetExactAlternative("th"));
#else
            Assert.AreEqual("new", sense.Definition.GetExactAlternative("th"));
#endif
        }
示例#13
0
        private void WriteHeadWordFieldForRelation(LexEntry entry, string outputFieldName)
        {
            //                headword.SetAlternative(HeadWordWritingSystemId, entry.GetHeadWordForm(HeadWordWritingSystemId));

            var headword = new MultiText();

            foreach (string writingSystemId in _headwordWritingSystemIds)
            {
                var headWordForm = entry.GetHeadWordForm(writingSystemId);
                if (!string.IsNullOrEmpty(headWordForm))
                {
                    headword.SetAlternative(writingSystemId, headWordForm);
                    break;                    //we only want the first non-empty one
                }
            }
            WriteMultiTextAsArtificialField(outputFieldName, headword);
        }
示例#14
0
        private RecordToken <LexEntry> PrepareEntryWithOneMeaning()
        {
            Task.NavigateAbsoluteFirst();
            MultiText word = new MultiText();

            word.SetAlternative(_vernacularLanguageWSId, "uno");
            Task.WordCollected(word);
            Assert.AreEqual(1,
                            _lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs).
                            Count);

            ResultSet <LexEntry> entries =
                _lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs);

            Task.Deactivate();
            return(entries[0]);
        }
示例#15
0
        private MultiText ParseDescriptions(XmlReader reader)
        {
            var description = new MultiText();

            reader.ReadToFollowing("AStr");
            while (reader.IsStartElement("AStr"))
            {
                reader.ReadToFollowing("Run");
                string ws = reader["ws"];
                // Next Read reads text
                string tempString = reader.ReadElementString("Run").Trim();
                if (!String.IsNullOrEmpty(tempString))
                {
                    // Only add non empty strings to the multitext
                    description.SetAlternative(ws, tempString);
                }
                reader.ReadToNextSibling("AStr");
                reader.ReadToNextSibling("AStr");
            }
            return(description);
        }
示例#16
0
        private MultiText ParseMultiStringElement(XmlReader reader, bool exampleWords)
        {
            var entry = new MultiText();

            reader.ReadToFollowing("AUni");
            while (reader.IsStartElement("AUni"))
            {
                string ws = reader["ws"];
                // Next Read reads text
                string tempString = reader.ReadElementString("AUni").Trim();
                if (!String.IsNullOrEmpty(tempString))
                {
                    // Only add non empty strings to the multitext
                    entry.SetAlternative(ws, tempString);
                    if (exampleWords)
                    {
                        AppendSearchKey(ws, tempString);
                    }
                }
            }
            return(entry);
        }
示例#17
0
		public void Add_MultiTextWithMalFormedXML_IsExportedText()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well formed&lt;span&gt; XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
示例#18
0
		/// <summary>
		/// nb: this is used both for the headword of an article, but also for the target of a relation.
		/// </summary>
		private void WriteHeadWordField(LexEntry entry, string outputFieldName)
		{
			if (Template == null)
			{
				throw new InvalidOperationException("Expected a non-null Template");
			}
			MultiText headword = new MultiText();
			Field fieldControllingHeadwordOutput =
					Template.GetField(LexEntry.WellKnownProperties.Citation);
			if (fieldControllingHeadwordOutput == null || !fieldControllingHeadwordOutput.Enabled)
			{
				fieldControllingHeadwordOutput =
						Template.GetField(LexEntry.WellKnownProperties.LexicalUnit);
				if (fieldControllingHeadwordOutput == null)
				{
					throw new ArgumentException("Expected to find LexicalUnit in the view Template");
				}
			}
			//                headword.SetAlternative(HeadWordWritingSystemId, entry.GetHeadWordForm(HeadWordWritingSystemId));

			foreach (string writingSystemId in fieldControllingHeadwordOutput.WritingSystemIds)
			{
				headword.SetAlternative(writingSystemId, entry.GetHeadWordForm(writingSystemId));
			}
			WriteMultiTextAsArtificialField(outputFieldName, headword);
		}
示例#19
0
		public void GetOrCreateSenseWithMeaning_SenseDoesExists_ExistingSense()
		{
			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", "sense");

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreSame(_sense, sense);
		}
示例#20
0
		public void GetOrCreateSenseWithMeaning_SenseWithEmptyStringExists_ExistingSense()
		{
			ClearSenseMeaning();

			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", string.Empty);

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreSame(_sense, sense);
		}
示例#21
0
		public void GetOrCreateSenseWithMeaning_SenseDoesNotExist_NewSenseWithMeaning()
		{
			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", "new");

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreNotSame(_sense, sense);
#if GlossMeaning
			Assert.AreEqual("new", sense.Gloss.GetExactAlternative("th"));
#else
			Assert.AreEqual("new", sense.Definition.GetExactAlternative("th"));
#endif
		}
示例#22
0
		public void Add_MultiTextWithMalFormedXML_IsExportedText()
		{
			MultiText multiText = new MultiText();
			multiText.SetAlternative("de", "This <span href=\"reference\">is not well formed<span> XML!");
			_exporter.Add(null, multiText);
			CheckAnswer("<form lang=\"de\"><text>This &lt;span href=\"reference\"&gt;is not well formed&lt;span&gt; XML!</text></form>");
		}
示例#23
0
		public void Add_MultiTextWithWellFormedXMLAndScaryCharacter_IsExportedAsXML()
		{
			const string expected =
			"<form\r\n\tlang=\"de\">\r\n\t<text>This <span href=\"reference\">is well &#x1F; formed</span> XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is well \u001F formed</span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
示例#24
0
		public void Add_MultiTextWithScaryUnicodeChar_IsExported()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This has a segment separator character at the end&#x1F;</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This has a segment separator character at the end\u001F");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
示例#25
0
		public void Add_TextWithSpanAndMeaningfulWhiteSpace_FormattingAndWhitespaceIsUntouched()
		{
			const string formattedText = "\rThis's <span href=\"reference\">\n is a\t\t\n\r\t span</span> with annoying whitespace!\r\n";
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>" + formattedText + "</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", formattedText);
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
示例#26
0
		public void Add_MalformedXmlWithWithScaryUnicodeChar_IsExportedAsText()
		{
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well &#x1F; formed&lt;span&gt; XML!</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well \u001F formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
示例#27
0
		private RecordToken<LexEntry> PrepareEntryWithOneGloss()
		{
			Task.NavigateAbsoluteFirst();
			MultiText word = new MultiText();

			word.SetAlternative(_vernacularLanguageWSId, "uno");
			Task.WordCollected(word);
			Assert.AreEqual(1,
							_lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs).
									Count);

			ResultSet<LexEntry> entries =
					_lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs);

			return entries[0];
		}