Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        public void FindText_EnterWordInDictionaryThenPressCtrlN_AddsWordInFindTextSoTwoEntries()
        {
            AddInitialEntries();
            TextBoxTester t = new TextBoxTester("_textToSearchForBox", _window);

            t.Enter("Secondary");
            Application.DoEvents();
            PressCtrlN(t, true);
            VerifySelectedWordIs("Secondary");
            Assert.AreEqual(2,
                            _lexEntryRepository.GetEntriesWithMatchingLexicalForm("Secondary",
                                                                                  _vernacularWritingSystem)
                            .Count);
        }
Exemplo n.º 3
0
        public void RemovingGlossFromEmptyEntry_RemovesEntry()
        {
            RecordToken <LexEntry> token = PrepareEntryWithOneMeaning();

            //now simulate removing it, as when the user wants to correct spelling
            Task.TryToRemoveAssociationWithListWordFromEntry(token);
            Assert.AreEqual(0,
                            _lexEntryRepository.GetEntriesWithMatchingLexicalForm("uno", VernWs).
                            Count);
            Task.Deactivate();
        }
Exemplo n.º 4
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)
        {
            //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());
            }
        }
Exemplo n.º 5
0
        public void PrepareToMoveWordToEditArea(WordDisplay wordDisplay)
        {
            VerifyTaskActivated();
            _savedSensesDuringMoveToEditArea = null;

            if (wordDisplay == null)
            {
                throw new ArgumentNullException();
            }
            // this task was coded to have a list of word-forms, not actual entries.
            //so we have to go searching for possible matches at this point.
            ResultSet <LexEntry> matchingEntries =
                LexEntryRepository.GetEntriesWithMatchingLexicalForm(wordDisplay.Vernacular.Form, FormWritingSystem);

            foreach (RecordToken <LexEntry> recordToken in matchingEntries)
            {
                if (_savedSensesDuringMoveToEditArea == null)
                {
                    _savedSensesDuringMoveToEditArea = new List <LexSense>();
                }
                // have to iterate through these in reverse order since they might get modified
                LexEntry entry = recordToken.RealObject;
                //If we aren't showing the meaning field then we are going let any edits effect all matching Senses
                if (!ShowMeaningField)
                {
                    for (int i = entry.Senses.Count - 1; i >= 0; i--)
                    {
                        LexSense sense           = entry.Senses[i];
                        var      semanticDomains = sense.GetProperty <OptionRefCollection>(_semanticDomainField.FieldName);
                        if (semanticDomains != null)
                        {
                            if (semanticDomains.Contains(CurrentDomainKey))
                            {
                                RememberMeaningOfDissociatedWord(sense);
                                entry.Senses.Remove(sense);
                                //if we don't do this and it has a meaning, we'll fail to delete the word when the user is trying to correct the spelling. (WS-34245)
                            }
                        }
                    }
                }
                //If we are showing the meaning field then we only let edits effect the sense that matches the shown meaning (definition)
                else
                {
                    var firstSenseMatchingSemDomAndMeaning =
                        entry.Senses.
                        Where(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4) != null).
                        FirstOrDefault(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4).Contains(CurrentDomainKey) &&
                                       s.Definition.GetBestAlternative(new[] { DefinitionWritingSystem.Id }) == wordDisplay.Meaning);
                    if (firstSenseMatchingSemDomAndMeaning != null)
                    {
                        RememberMeaningOfDissociatedWord(firstSenseMatchingSemDomAndMeaning);
                        entry.Senses.Remove(firstSenseMatchingSemDomAndMeaning);
                    }
                }
                entry.CleanUpAfterEditting();
                if (entry.IsEmptyExceptForLexemeFormForPurposesOfDeletion)
                {
                    LexEntryRepository.DeleteItem(entry);                     // if there are no senses left, get rid of it
                }
                else
                {
                    LexEntryRepository.SaveItem(entry);
                }
            }

            UpdateCurrentWords();
        }