Exemplo n.º 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"));
        }
Exemplo n.º 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;
                }
            };
        }
Exemplo n.º 3
0
		public void Notification()
		{
			_gotHandlerNotice = false;
			MultiText text = new MultiText();
			text.PropertyChanged += propertyChangedHandler;
			text.SetAlternative("zox", "");
			Assert.IsTrue(_gotHandlerNotice);
		}
Exemplo n.º 4
0
        public void Notification()
        {
            _gotHandlerNotice = false;
            MultiText text = new MultiText();

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

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

            LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);

            Assert.AreSame(_sense, sense);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
        }
Exemplo n.º 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);
        }
Exemplo n.º 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]);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
			}
		}
Exemplo n.º 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);
		}
Exemplo n.º 19
0
		public void GetOrCreateSenseWithMeaning_SenseDoesExists_ExistingSense()
		{
			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", "sense");

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreSame(_sense, sense);
		}
Exemplo n.º 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);
		}
Exemplo n.º 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
		}
Exemplo n.º 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>");
		}
Exemplo n.º 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());
			}
		}
Exemplo n.º 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());
			}
		}
Exemplo n.º 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());
			}
		}
Exemplo n.º 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());
			}
		}
Exemplo n.º 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];
		}