private static LexEntry CreateEmptyEntryWithOneSense()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			return entry;
		}
		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 OneSenseDefinitionWritingSystemWithOneWithoutAnalysis()
		{
			LexEntry entry = CreateEmptyEntryWithOneSense();
			LexSense sense = entry.Senses[0];

			sense.Definition["analysis"] = "filler";
			sense = new LexSense();
			entry.Senses.Add(sense);
			sense.Definition["vernacular"] = "filler";
			Assert.AreEqual(true, _missingMeaningFilter.FilteringPredicate(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 OneSenseExampleTranslationWithOneWithoutWritingSystems()
		{
			LexEntry entry = CreateEmptyEntryWithOneExampleSentence();
			LexExampleSentence example = entry.Senses[0].ExampleSentences[0];

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

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.ExampleSentences.Add(new LexExampleSentence());

			Assert.AreEqual(true, _missingExampleTranslationFilter.FilteringPredicate(entry));
		}
		public void OneSenseExampleCustomFieldWithOneWithoutWritingSystems()
		{
			LexEntry entry = CreateEmptyLexEntryWithOneEmptySentence();
			LexExampleSentence example = entry.Senses[0].ExampleSentences[0];

			MultiText custom = example.GetOrCreateProperty<MultiText>("customField");
			custom["vernacular"] = "filler";

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.ExampleSentences.Add(new LexExampleSentence());

			Assert.AreEqual(true, _missingCustomFieldFilter.FilteringPredicate(entry));
		}
示例#7
0
		private LexEntry CreateTestEntry(string lexicalForm, string meaning, string exampleSentence)
		{
			LexEntry entry = _lexEntryRepository.CreateItem();
			entry.LexicalForm[GetSomeValidWsIdForField("EntryLexicalForm")] = lexicalForm;
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
#if GlossMeaning
			sense.Gloss[GetSomeValidWsIdForField("SenseGloss")] = meaning;
#else
			sense.Definition[WeSayWordsProject.Project.WritingSystems.TestWritingSystemAnalId] =
					meaning;
#endif
			LexExampleSentence example = new LexExampleSentence();
			sense.ExampleSentences.Add(example);
			example.Sentence[GetSomeValidWsIdForField("ExampleSentence")] = exampleSentence;
			_lexEntryRepository.SaveItem(entry);
			return entry;
		}
		public void OneSenseExampleSentenceWithOneWithoutWritingSystems()
		{
			LexEntry entry = CreateEmptyEntryWithOneExampleSentence();
			LexExampleSentence example = entry.Senses[0].ExampleSentences[0];

			example.Sentence["vernacular"] = "filler";

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			example = new LexExampleSentence();
			sense.ExampleSentences.Add(example);

			Assert.AreEqual(true, _missingExampleSentenceFilter.FilteringPredicate(entry));
		}
		public void RemoveWord_HasAnotherSense_DisassociatesWordFromDomain()
		{
			LexEntry e = _lexEntryRepository.CreateItem();
			e.LexicalForm.SetAlternative("br", "peixe");
			LexSense s = AddNewSenseToEntry(e);
			s.Gloss.SetAlternative("en", "fish");
			s = new LexSense();
			e.Senses.Add(s);
			OptionRefCollection o =
					s.GetOrCreateProperty<OptionRefCollection>(
							LexSense.WellKnownProperties.SemanticDomainsDdp4);
			o.Add(Task.DomainKeys[0]);
			_lexEntryRepository.SaveItem(e);
			int originalCount = _lexEntryRepository.CountAllItems();

			Task.CurrentDomainIndex = 0;
			Task.DetachFromMatchingEntries("peixe");

			Assert.AreEqual(originalCount, _lexEntryRepository.CountAllItems());
		}
		public void SenseHasCustomField()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			OptionRef custom = sense.GetOrCreateProperty<OptionRef>("customField");
			custom.Value = "filler";

			Assert.AreEqual(false, _missingCustomFieldFilter.FilteringPredicate(entry));
		}
示例#11
0
		private Guid AddEntry(string lexemeForm,
							  string meaningWritingSystemId,
							  string meaning,
							  bool includeExample)
		{
			LexEntry entry = _lexEntryRepository.CreateItem();
			entry.LexicalForm.SetAlternative(_vernacularWritingSystem.Id, lexemeForm);

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
#if GlossMeaning
			sense.Gloss[
				WeSayWordsProject.Project.DefaultViewTemplate.GetField("SenseGloss").WritingSystemIds[0]] =
				meaning;
#else
			sense.Definition.SetAlternative(meaningWritingSystemId, meaning);
#endif
			if (includeExample)
			{
				LexExampleSentence ex = new LexExampleSentence();
				sense.ExampleSentences.Add(ex);
				ex.Sentence.SetAlternative("x", "hello");
			}
			_lexEntryRepository.SaveItem(entry);
			return entry.Guid;
		}
示例#12
0
		private static void AddExample(LexSense sense)
		{
			LexExampleSentence example = new LexExampleSentence();
			sense.ExampleSentences.Add(example);
			example.Sentence[BasilProject.Project.WritingSystems.TestWritingSystemVernId] =
					"sentence";
		}
示例#13
0
		public void WordCollected(MultiText newVernacularWord)
		{
			LexSense sense = new LexSense();
			sense.Definition.MergeIn(CurrentWordAsMultiText);
			sense.Gloss.MergeIn(CurrentWordAsMultiText);
			//we use this for matching up, and well, it probably is a good gloss

			AddSenseToLexicon(newVernacularWord, sense);
		}
示例#14
0
		public void RemovingAssociationWith_OnlyRemovesGloss()
		{
			RecordToken<LexEntry> token = PrepareEntryWithOneGloss();
			//now tweak the entry
			LexEntry entry = token.RealObject;
			LexSense leaveAloneSense = new LexSense();
			entry.Senses.Add(leaveAloneSense);
			leaveAloneSense.Gloss.SetAlternative(_glossingLanguageWSId, "single");
			Assert.AreEqual(2, entry.Senses.Count);

			//now simulate removing it, as when the user wants to correct spelling
			Task.TryToRemoveAssociationWithListWordFromEntry(token);
			Assert.AreEqual(1,
							_lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs).
									Count);
			Assert.AreEqual(1, entry.Senses.Count);
		}
示例#15
0
文件: LexEntry.cs 项目: bbriggs/wesay
		public LexSense GetOrCreateSenseWithMeaning(MultiText meaning) //Switch to meaning
		{
			foreach (LexSense sense in Senses)
			{
#if GlossMeaning
				if (meaning.HasFormWithSameContent(sense.Gloss))
#else
				if (meaning.HasFormWithSameContent(sense.Definition))
#endif
				{
					return sense;
				}
			}
			LexSense newSense = new LexSense();
			Senses.Add(newSense);
#if GlossMeaning
			newSense.Gloss.MergeIn(meaning);
#else
			newSense.Definition.MergeIn(meaning);
#endif
			return newSense;
		}
示例#16
0
		private void AddEntryAndSense(string gloss)
		{
			LexEntry e = _lexEntryRepository.CreateItem();
			LexSense sense = new LexSense();
			e.Senses.Add(sense);
			sense.Gloss[_glossingLanguageWSId] = gloss;
			_lexEntryRepository.SaveItem(e);
		}
示例#17
0
		private void WriteGrammi(LexSense sense)
		{
			if (!ShouldOutputProperty(LexSense.WellKnownProperties.PartOfSpeech))
			{
				return;
			}

			OptionRef pos = sense.GetProperty<OptionRef>(LexSense.WellKnownProperties.PartOfSpeech);

			if (pos != null && !pos.IsEmpty)
			{
				WritePosCore(pos);
			}
		}
示例#18
0
		public void Add(LexSense sense)
		{
			List<string> propertiesAlreadyOutput = new List<string>();

			Writer.WriteStartElement("sense");
			Writer.WriteAttributeString("id", sense.GetOrCreateId());

			if (ShouldOutputProperty(LexSense.WellKnownProperties.PartOfSpeech))
			{
				WriteGrammi(sense);
				propertiesAlreadyOutput.Add(LexSense.WellKnownProperties.PartOfSpeech);
			}
			if (ShouldOutputProperty(LexSense.WellKnownProperties.Gloss))
			{
				WriteOneElementPerFormIfNonEmpty(LexSense.WellKnownProperties.Gloss,
												 "gloss",
												 sense.Gloss,
												 ';');
				propertiesAlreadyOutput.Add(LexSense.WellKnownProperties.Gloss);
			}

			foreach (LexExampleSentence example in sense.ExampleSentences)
			{
				Add(example);
			}
			WriteWellKnownCustomMultiText(sense,
										  LexSense.WellKnownProperties.Definition,
										  propertiesAlreadyOutput);
			WriteWellKnownCustomMultiText(sense,
										  WeSayDataObject.WellKnownProperties.Note,
										  propertiesAlreadyOutput);
			//   WriteWellKnownUnimplementedProperty(sense, LexSense.WellKnownProperties.Note, propertiesAlreadyOutput);
			WriteCustomProperties(sense, propertiesAlreadyOutput);
			Writer.WriteEndElement();
		}
示例#19
0
		public string AddEntryCore(string lexemeFormWritingSystemId,
								   string lexemeForm,
								   string definitionWritingSystemId,
								   string definition,
								   string exampleWritingSystemId,
								   string example)
		{
			if (string.IsNullOrEmpty(lexemeForm))
			{
				Logger.WriteEvent("Dictionary Services AddEntry() called with Empty lexemeform");
				return null;
			}
			if (!CheckWritingSystemAndContentsPair(lexemeFormWritingSystemId, lexemeForm))
			{
				return null;
			}
			if (!CheckWritingSystemAndContentsPair(definitionWritingSystemId, definition))
			{
				return null;
			}
			if (!CheckWritingSystemAndContentsPair(exampleWritingSystemId, example))
			{
				return null;
			}

			Logger.WriteEvent("dictionary services.AddEntry()");

			LexEntry e = _lexEntryRepository.CreateItem();
			e.LexicalForm.SetAlternative(lexemeFormWritingSystemId, lexemeForm);

			LexSense sense = null;
			if (!string.IsNullOrEmpty(definition))
			{
				sense = new LexSense();
				e.Senses.Add(sense);
				sense.Definition.SetAlternative(definitionWritingSystemId, definition);
			}
			if (!string.IsNullOrEmpty(example))
			{
				if (sense == null)
				{
					sense = new LexSense();
					e.Senses.Add(sense);
				}
				LexExampleSentence ex = new LexExampleSentence();
				sense.ExampleSentences.Add(ex);
				ex.Sentence.SetAlternative(exampleWritingSystemId, example);
			}
			_lexEntryRepository.SaveItem(e);
			return e.Id;
		}
		public void RemoveWord_HasOnlyLexemeForm_DeletesWord()
		{
			LexEntry e = _lexEntryRepository.CreateItem();
			e.LexicalForm.SetAlternative("br", "peixe");
			LexSense s = new LexSense();
			e.Senses.Add(s);
			OptionRefCollection o =
					s.GetOrCreateProperty<OptionRefCollection>(
							LexSense.WellKnownProperties.SemanticDomainsDdp4);
			o.Add(Task.DomainKeys[0]);
			_lexEntryRepository.SaveItem(e);
			int originalCount = _lexEntryRepository.CountAllItems();

			Task.CurrentDomainIndex = 0;
			Task.DetachFromMatchingEntries("peixe");

			Assert.AreEqual(originalCount - 1, _lexEntryRepository.CountAllItems());
		}
示例#21
0
		private void CreateTestEntry(string lexicalForm, string Definition, string exampleSentence)
		{
			LexEntry entry = _lexEntryRepository.CreateItem();
			entry.LexicalForm[_writingSystem.Id] = lexicalForm;
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.Definition["analysis"] = Definition;
			LexExampleSentence example = new LexExampleSentence();
			sense.ExampleSentences.Add(example);
			example.Sentence[_writingSystem.Id] = exampleSentence;
			_lexEntryRepository.SaveItem(entry);
			return;
		}
		public void SenseCustomFieldHasNoValue()
		{
			LexEntry entry = new LexEntry();
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.Gloss["analysis"] = "filler";
			sense.GetOrCreateProperty<OptionRef>("customField");
			Assert.AreEqual(true, _missingCustomFieldFilter.FilteringPredicate(entry));
		}
示例#23
0
		private LexEntry CreateEntry(string lexemeForm, string meaning)
		{
			LexEntry entry = _lexEntryRepository.CreateItem();

			entry.LexicalForm.SetAlternative("vernacular", lexemeForm);

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			sense.Gloss[
					WeSayWordsProject.Project.DefaultViewTemplate.GetField(
							LexSense.WellKnownProperties.Definition).WritingSystemIds[0]] = meaning;
			_lexEntryRepository.SaveItem(entry);
			return entry;
		}
示例#24
0
		private static void AddSense(LexEntry entry)
		{
			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
#if GlossMeaning
			sense.Gloss[WeSayWordsProject.Project.DefaultViewTemplate.GetField("SenseGloss").WritingSystemIds[0]] = "GlossInAnalysis";
#else
			sense.Definition[
					WeSayWordsProject.Project.DefaultViewTemplate.GetField(
							LexSense.WellKnownProperties.Definition).WritingSystemIds[0]] =
					"MeaningInAnalysis";
#endif
			AddExample(sense);
			AddExample(sense);
		}
示例#25
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)
		{
			//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);
			if (entriesWithSameForm.Count == 0)
			{
				LexEntry entry = LexEntryRepository.CreateItem();
				entry.LexicalForm.MergeIn(lexemeForm);
				entry.Senses.Add(sense);
				LexEntryRepository.SaveItem(entry);
			}
			else
			{
				LexEntry entry = entriesWithSameForm[0].RealObject;

				foreach (LexSense s in entry.Senses)
				{
					if (sense.Gloss.Forms.Length > 0)
					{
						LanguageForm glossWeAreAdding = sense.Gloss.Forms[0];
						string glossInThisWritingSystem =
								s.Gloss.GetExactAlternative(glossWeAreAdding.WritingSystemId);
						if (glossInThisWritingSystem == glossWeAreAdding.Form)
						{
							return; //don't add it again
						}
					}
				}
				entry.Senses.Add(sense);
				LexEntryRepository.NotifyThatLexEntryHasBeenUpdated(entry);
			}
		}
		private static LexSense AddNewSenseToEntry(LexEntry e)
		{
			LexSense s = new LexSense();
			e.Senses.Add(s);
			return s;
		}