/// <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()); } }
/// <summary> /// Adds this word and gloss, potentially adding the current semantic domain to multiple entriew with that word and gloss. /// </summary> /// <param name="lexicalForm"></param> /// <param name="gloss"></param> /// <returns>the entries that were modified </returns> public IList <LexEntry> AddWord(string lexicalForm, string gloss) { VerifyTaskActivated(); if (string.IsNullOrEmpty(lexicalForm)) { throw new ArgumentNullException(); } var modifiedEntries = new List <LexEntry>(); if (lexicalForm != string.Empty) { ResultSet <LexEntry> recordTokens = LexEntryRepository.GetEntriesWithMatchingLexicalForm(lexicalForm, FormWritingSystem); if (recordTokens.Count == 0) //no entries with a matching form { LexEntry entry = LexEntryRepository.CreateItem(); entry.LexicalForm.SetAlternative(WordWritingSystemId, lexicalForm); AddCurrentSemanticDomainToEntry(entry, gloss); LexEntryRepository.SaveItem(entry); modifiedEntries.Add(entry); _logger.WriteConciseHistoricalEvent("SD-Added '{0}' with Domain to '{1}'", entry.GetSimpleFormForLogging(), CurrentDomainName); } else // one or more matching entries { var entriesMatchingWord = new List <LexEntry>(from RecordToken <LexEntry> x in recordTokens select x.RealObject); foreach (var entry in entriesMatchingWord) { if (HasMatchingSense(entry, gloss)) { modifiedEntries.Add(entry); AddCurrentSemanticDomainToEntry(entry, gloss); _logger.WriteConciseHistoricalEvent("SD-Added Domain to '{0}'", entry.GetSimpleFormForLogging()); break; } } if (modifiedEntries.Count == 0) //didn't find any matching glosses { //NB: what to do IS NOT CLEAR. This just adds to the first entry, // but it's just rolling the dice! What to do??? var first = entriesMatchingWord.First(); modifiedEntries.Add(first); AddCurrentSemanticDomainToEntry(first, gloss); _logger.WriteConciseHistoricalEvent("SD-Added Domain {0} to '{1}' REVIEW", CurrentDomainName, first.GetSimpleFormForLogging()); } } } _savedSensesDuringMoveToEditArea = null; UpdateCurrentWords(); return(modifiedEntries); }