private static LexEntry CreateEmptyEntryWithOneSense()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			return entry;
		}
Exemple #2
0
		internal int AddWidgets(LexEntry entry, int insertAtRow)
		{
			DetailList.SuspendLayout();
			int rowCount = 0;
			Field field = ActiveViewTemplate.GetField(Field.FieldNames.EntryLexicalForm.ToString());
			if (field != null && field.GetDoShow(entry.LexicalForm, ShowNormallyHiddenFields))
			{
				Control formControl = MakeBoundControl(entry.LexicalForm, field);
				DetailList.AddWidgetRow(StringCatalog.Get(field.DisplayName),
										true,
										formControl,
										insertAtRow,
										false);
				insertAtRow = DetailList.GetRow(formControl);
				++rowCount;
			}
			rowCount += AddCustomFields(entry, insertAtRow + rowCount);

			LexSenseLayouter layouter = new LexSenseLayouter(DetailList,
															 ActiveViewTemplate,
															 RecordListManager);
			layouter.ShowNormallyHiddenFields = ShowNormallyHiddenFields;
			rowCount = AddChildrenWidgets(layouter, entry.Senses, insertAtRow, rowCount);
			//add a ghost
			rowCount += layouter.AddGhost(entry.Senses, true);

			DetailList.ResumeLayout();
			return rowCount;
		}
		public void LexicalFormHasAnalysisWritingSystem()
		{
			LexEntry entry = new LexEntry();
			entry.LexicalForm["vernacular"] = "filler";

			Assert.AreEqual(false, _missingLexicalFormFilter.FilteringPredicate(entry));
		}
		public void Setup()
		{
			WeSayWordsProject.InitializeForTests();

			_tempFolder = new TemporaryFolder();
			_filePath = _tempFolder.GetTemporaryFile();
			_lexEntryRepository = new LexEntryRepository(_filePath);

			_target = CreateEntry("one", "single item");
			_source = CreateEntry("single", "one item");

			CreateEntry("verde", "green");
			CreateEntry("amarelho", "yellow");
			CreateEntry("azul", "blue");

			_synonymsRelationField = new Field("synonyms",
											   "LexEntry",
											   new string[] {"vernacular"},
											   Field.MultiplicityType.ZeroOrMore,
											   "RelationToOneEntry");
			_synonymsRelationType = new LexRelationType("synonyms",
														LexRelationType.Multiplicities.Many,
														LexRelationType.TargetTypes.Sense);

			_singleSynonymRelationField = new Field("synonym",
											  "LexEntry",
											  new string[] {"vernacular"},
											  Field.MultiplicityType.ZeroOr1,
											  "RelationToOneEntry");
			_singleSynonymRelationType = new LexRelationType("synonym",
													   LexRelationType.Multiplicities.One,
													   LexRelationType.TargetTypes.Sense);
		}
		private static LexEntry CreateEmptyLexEntryWithOneEmptySentence()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.ExampleSentences.Add(new LexExampleSentence());
			return entry;
		}
		public void SenseExampleTranslationHasAnalysisWritingSystem()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			LexExampleSentence example = new LexExampleSentence();
			sense.ExampleSentences.Add(example);

			example.Translation["analysis"] = "filler";

			Assert.AreEqual(false, _missingExampleTranslationFilter.FilteringPredicate(entry));
		}
		public void SetUp()
		{
			WeSayWordsProject.InitializeForTests();

			_tempFolder = new TemporaryFolder();
			_filePath = _tempFolder.GetTemporaryFile();
			_lexEntryRepository = new LexEntryRepository(_filePath);

#if GlossMeaning
		   _primaryMeaningFieldName = Field.FieldNames.SenseGloss.ToString();
#else
			_primaryMeaningFieldName = LexSense.WellKnownProperties.Definition;
#endif

			string[] analysisWritingSystemIds = new string[]
													{
															BasilProject.Project.WritingSystems.
																	TestWritingSystemAnalId
													};
			string[] vernacularWritingSystemIds = new string[]
													  {
															  BasilProject.Project.WritingSystems.
																	  TestWritingSystemVernId
													  };
			RtfRenderer.HeadWordWritingSystemId = vernacularWritingSystemIds[0];

			_viewTemplate = new ViewTemplate();
			_viewTemplate.Add(new Field(Field.FieldNames.EntryLexicalForm.ToString(),
										"LexEntry",
										vernacularWritingSystemIds));
			_viewTemplate.Add(new Field(_primaryMeaningFieldName,
										"LexSense",
										analysisWritingSystemIds));
			_viewTemplate.Add(new Field(Field.FieldNames.ExampleSentence.ToString(),
										"LexExampleSentence",
										vernacularWritingSystemIds));
			_viewTemplate.Add(new Field(Field.FieldNames.ExampleTranslation.ToString(),
										"LexExampleSentence",
										analysisWritingSystemIds));

			empty = CreateTestEntry("", "", "");
			apple = CreateTestEntry("apple", "red thing", "An apple a day keeps the doctor away.");
			banana = CreateTestEntry("banana", "yellow food", "Monkeys like to eat bananas.");
			car = CreateTestEntry("car",
								  "small motorized vehicle",
								  "Watch out for cars when you cross the street.");
			bike = CreateTestEntry("bike", "vehicle with two wheels", "He rides his bike to school.");
		}
Exemple #8
0
/*
		/// <summary>
		/// Import a single entry selected out of a Lift file. For test use.
		/// </summary>
		/// <param name="path"></param>
		/// <param name="xpath"></param>
		/// <returns>either the entry which was created were merged into</returns>
		public LexEntry ImportOneWeSayEntry(string path, string xpath)
		{
			XmlDocument doc = new XmlDocument();
			doc.Load(path);
			return ImportOneEntry(doc.SelectSingleNode(xpath));
		}
*/

		internal ILexEntry MergeInOneEntry(LexEntry wsEntry)
		{
			ILexEntry flexEntry=null;
			Guid guid = wsEntry.Guid;
			int hvo = _cache.GetIdFromGuid(guid);
			if (hvo > 0)
			{
				flexEntry = FlexEntry.CreateFromDBObject(_cache, hvo);
			   // if (((LexSense)flexEntry.SensesOS[0]).Gloss.AnalysisDefaultWritingSystem != weSayEntry.Gloss)
//                MergeAnalysisString((flexEntry.SensesOS[0]).Gloss,weSayEntry.Gloss);
//                MergeVernacularString(flexEntry.LexemeFormOA.Form,weSayEntry.LexicalForm);
//                MergeVernacularString(((ILexExampleSentence)((LexSense)flexEntry.SensesOS[0]).ExamplesOS[0]).Example,weSayEntry.Example);
			}
			else
			{
				flexEntry = MakeFwEntryFromWeSayEntry(wsEntry);
			}
			return flexEntry;
		}
Exemple #9
0
/*
 *              /// <summary>
 *              /// Import a single entry selected out of a Lift file. For test use.
 *              /// </summary>
 *              /// <param name="path"></param>
 *              /// <param name="xpath"></param>
 *              /// <returns>either the entry which was created were merged into</returns>
 *              public LexEntry ImportOneWeSayEntry(string path, string xpath)
 *              {
 *                      XmlDocument doc = new XmlDocument();
 *                      doc.Load(path);
 *                      return ImportOneEntry(doc.SelectSingleNode(xpath));
 *              }
 */

        internal ILexEntry MergeInOneEntry(LexEntry wsEntry)
        {
            ILexEntry flexEntry = null;
            Guid      guid      = wsEntry.Guid;
            int       hvo       = _cache.GetIdFromGuid(guid);

            if (hvo > 0)
            {
                flexEntry = FlexEntry.CreateFromDBObject(_cache, hvo);
                // if (((LexSense)flexEntry.SensesOS[0]).Gloss.AnalysisDefaultWritingSystem != weSayEntry.Gloss)
//                MergeAnalysisString((flexEntry.SensesOS[0]).Gloss,weSayEntry.Gloss);
//                MergeVernacularString(flexEntry.LexemeFormOA.Form,weSayEntry.LexicalForm);
//                MergeVernacularString(((ILexExampleSentence)((LexSense)flexEntry.SensesOS[0]).ExamplesOS[0]).Example,weSayEntry.Example);
            }
            else
            {
                flexEntry = MakeFwEntryFromWeSayEntry(wsEntry);
            }
            return(flexEntry);
        }
		private static bool IsMissingTranslation(LexEntry entry)
		{
			if (entry == null)
			{
				return false;
			}
			bool hasSense = false;
			bool hasExample = false;
			foreach (LexSense sense in entry.Senses)
			{
				hasSense = true;
				foreach (LexExampleSentence exampleSentence in sense.ExampleSentences)
				{
					hasExample = true;
					if (exampleSentence.Translation["analysis"].Length == 0)
					{
						return true;
					}
				}
			}
			return !(hasSense && hasExample);
		}
		public void LexicalFormWritingSystemNoVernacular()
		{
			LexEntry entry = new LexEntry();
			entry.LexicalForm["analysis"] = "filler";
			Assert.AreEqual(true, _missingLexicalFormFilter.FilteringPredicate(entry));
		}
		private static void AddTranslationToEntry(LexEntry entry, string translation)
		{
			LexSense sense = entry.Senses[0];
			LexExampleSentence example = sense.ExampleSentences[0];
			example.Translation["analysis"] = translation;
		}
Exemple #13
0
		public static string ToRtf(LexEntry entry,
								   CurrentItemEventArgs currentItem,
								   LexEntryRepository lexEntryRepository)
		{
			if (lexEntryRepository == null)
			{
				throw new ArgumentNullException("lexEntryRepository");
			}
			if (entry == null)
			{
				return string.Empty;
			}

			StringBuilder rtf = new StringBuilder();
			rtf.Append(@"{\rtf1\ansi\uc0\fs28 ");
			rtf.Append(MakeFontTable());
			RenderHeadword(entry, rtf, lexEntryRepository);

			int senseNumber = 1;
			foreach (LexSense sense in entry.Senses)
			{
				//rtf.Append(SwitchToWritingSystem(BasilProject.Project.WritingSystems.AnalysisWritingSystemDefault.Id));
#if GlossMeaning
				if (entry.Senses.Count > 1 || (currentItem != null && currentItem.PropertyName == "Gloss"))
#else
				if (entry.Senses.Count > 1 ||
					(currentItem != null &&
					 currentItem.PropertyName == LexSense.WellKnownProperties.Definition))
#endif
				{
					rtf.Append(" " + senseNumber);
				}

				OptionRef posRef =
						sense.GetProperty<OptionRef>(LexSense.WellKnownProperties.PartOfSpeech);
				if (posRef != null)
				{
					OptionsList list =
							WeSayWordsProject.Project.GetOptionsList(
									LexSense.WellKnownProperties.PartOfSpeech);
					if (list != null)
					{
						Option posOption = list.GetOptionFromKey(posRef.Value);

						if (posOption != null)
						{
							Field posField =
									WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(
											LexSense.WellKnownProperties.PartOfSpeech);
							if (posField != null)
							{
								rtf.Append(@" \i ");
								rtf.Append(RenderField(posOption.Name, currentItem, 0, posField));
								rtf.Append(@"\i0 ");
							}
						}
					}
				}
#if GlossMeaning
				rtf.Append(" " + RenderField(sense.Gloss, currentItem));
#else
				rtf.Append(" " + RenderField(sense.Definition, currentItem));
#endif
				//                rtf.Append(@"\i0 ");

				foreach (LexExampleSentence exampleSentence in sense.ExampleSentences)
				{
					rtf.Append(@" \i ");
					rtf.Append(RenderField(exampleSentence.Sentence, currentItem));
					rtf.Append(@"\i0 ");
					rtf.Append(RenderField(exampleSentence.Translation, currentItem));
				}

				rtf.Append(RenderGhostedField("Sentence", currentItem, null));
				rtf.Append(RenderGhostedField("Translation", currentItem, null));

				++senseNumber;
			}
#if GlossMeaning
			rtf.Append(RenderGhostedField("Gloss", currentItem, entry.Senses.Count + 1));
#else
			rtf.Append(RenderGhostedField(LexSense.WellKnownProperties.Definition,
										  currentItem,
										  entry.Senses.Count + 1));
#endif

			rtf.Append(@"\par}");
			return Utf16ToRtfAnsi(rtf.ToString());
		}
		public void LexicalFormNoWritingSystems()
		{
			LexEntry entry = new LexEntry();
			Assert.AreEqual(true, _missingLexicalFormFilter.FilteringPredicate(entry));
		}
		public void NoSenses()
		{
			LexEntry entry = new LexEntry();
			Assert.AreEqual(false, _missingExampleSentenceFilter.FilteringPredicate(entry));
		}
		public void NoExamples()
		{
			LexEntry entry = new LexEntry();
			entry.Senses.Add(new LexSense());
			Assert.AreEqual(true, _missingExampleSentenceFilter.FilteringPredicate(entry));
		}
Exemple #17
0
		public override void Add(LexEntry entry)
		{
			WritingSystem headWordWritingSystem = _viewTemplate.HeadwordWritingSystems[0];
			int h = _lexEntryRepository.GetHomographNumber(entry, headWordWritingSystem);
			Add(entry, h);
		}
		private void AddCurrentSemanticDomainToEntry(LexEntry entry)
		{
			LexSense sense = entry.GetOrCreateSenseWithMeaning(new MultiText());
			OptionRefCollection semanticDomains =
				sense.GetOrCreateProperty<OptionRefCollection>(_semanticDomainField.FieldName);
			if (!semanticDomains.Contains(CurrentDomainKey))
			{
				semanticDomains.Add(CurrentDomainKey);
			}
			LexEntryRepository.SaveItem(entry);
		}
		private EntryViewControl CreateForm(LexEntry entry, bool requiresVisibleForm)
		{
			EntryViewControl entryViewControl = new EntryViewControl();
			entryViewControl.LexEntryRepository = _lexEntryRepository;
			entryViewControl.ViewTemplate = _viewTemplate;
			entryViewControl.DataSource = entry;

			if(requiresVisibleForm)
			{
				Form window = new Form();
				window.Controls.Add(entryViewControl);
				window.Show();
			}
			return entryViewControl;
		}
		private static void DebugShowState(MissingInfoControl missingInfoControl,
										   LexEntry currentRecord)
		{
			Console.WriteLine("Current:");
			Console.WriteLine(currentRecord);

			Console.WriteLine("ToDo:");
			foreach (LexEntry item in missingInfoControl._recordsListBox.Items)
			{
				Console.WriteLine(item);
			}

			Console.WriteLine("Completed:");
			foreach (LexEntry item in missingInfoControl._completedRecordsListBox.Items)
			{
				Console.WriteLine(item);
			}
		}
Exemple #21
0
		private void SetRecordToBeEdited(LexEntry record)
		{
			SaveAndCleanUpPreviousEntry();
			Control_EntryDetailPanel.DataSource = record;
			if (record != null)
			{
				record.PropertyChanged += OnEntryChanged;
			}
		}
		private void EnsureField_Change_UpdatesSenseMeaning(LexEntry entry)
		{
			using (
					EntryViewControl entryViewControl = CreateFilteredForm(entry,
																		   _primaryMeaningFieldName,
																		   "LexSense",
																		   BasilProject.Project.
																				   WritingSystems.
																				   TestWritingSystemAnalId)
					)
			{
				DetailList entryDetailControl = entryViewControl.ControlEntryDetail;
				Label labelControl = entryDetailControl.GetLabelControlFromRow(0);
				Assert.AreEqual("Meaning 1", labelControl.Text);
				MultiTextControl editControl =
						(MultiTextControl) entryDetailControl.GetEditControlFromRow(0);
				editControl.TextBoxes[0].Focus();
				editControl.TextBoxes[0].Text = "test";
				entryDetailControl.GetEditControlFromRow(1).Focus();
				Assert.IsTrue(editControl.TextBoxes[0].Text.Contains(GetMeaning(entry)));
			}
		}
		private void TestEntryShows(LexEntry entry)
		{
			using (EntryViewControl entryViewControl = CreateForm(entry, false))
			{
				Assert.IsTrue(
						entryViewControl.ControlFormattedView.Text.Contains(GetLexicalForm(entry)));
				Assert.IsTrue(entryViewControl.ControlFormattedView.Text.Contains(GetMeaning(entry)));
				Assert.IsTrue(
						entryViewControl.ControlFormattedView.Text.Contains(GetExampleSentence(entry)));
			}
		}
		public void NoSenses()
		{
			LexEntry entry = new LexEntry();
			Assert.AreEqual(true, _missingMeaningFilter.FilteringPredicate(entry));
		}
Exemple #25
0
		public int AddWidgets(LexEntry entry)
		{
			return AddWidgets(entry, -1);
		}
Exemple #26
0
		protected override void WriteHeadword(LexEntry entry)
		{
			if (0 != (_options & Options.DetermineHeadword))
			{
				WriteHeadWordField(entry, "headword");
			}
		}
		private static string GetLexicalForm(LexEntry entry)
		{
			return entry.LexicalForm.GetFirstAlternative();
		}
Exemple #28
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);
		}
		private static string GetMeaning(LexEntry entry)
		{
#if GlossMeaning
			return entry.Senses[0].Gloss.GetFirstAlternative();
#else
			return entry.Senses[0].Definition.GetFirstAlternative();
#endif
		}
		private EntryViewControl CreateFilteredForm(LexEntry entry,
													string field,
													string className,
													params string[] writingSystems)
		{
			ViewTemplate viewTemplate = new ViewTemplate();
			viewTemplate.Add(new Field(field, className, writingSystems));
			EntryViewControl entryViewControl = new EntryViewControl();
			entryViewControl.LexEntryRepository = _lexEntryRepository;
			entryViewControl.ViewTemplate = viewTemplate;
			entryViewControl.DataSource = entry;


			Form window = new Form();
			window.Controls.Add(entryViewControl);
			window.Show();

			return entryViewControl;
		}
		private static string GetExampleSentence(LexEntry entry)
		{
			return entry.Senses[0].ExampleSentences[0].Sentence.GetFirstAlternative();
		}