Exemple #1
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
        }
Exemple #2
0
        private void AddCurrentSemanticDomainToEntry(LexEntry entry, string meaning)
        {
            LexSense sense = null;

            ////This can lead to wrongly assigned semantic domains in the case of multiple senses. Say I gather "shoot"  in the "weapons" domain (no idea if that even exists but bear with me)
            ////then I gather "shoot" in the "plants" domain. Both domains would be assigned to the same sense. That being said I assume this approach was taken because it will USUALLY be
            ////what the user intends as homographs/multiple senses are not as frequent as one sense belonging to multiple domains (i.e. "Rain" could be "Universe/Creation", "Agriculture",
            ////"Times of year" etc etc.) --TA Oct/3/2012
            //is the meaning empty? Then just grab the first sense
            if (ShowMeaningField && string.IsNullOrEmpty(meaning))
            {
                sense = entry.Senses.FirstOrDefault();
            }
            else
            {
                if ((_savedSensesDuringMoveToEditArea != null) && (_savedSensesDuringMoveToEditArea.Count > 0))                //we are editing a word we entered previously
                {
                    //in this case, we have this saved sense we want to put back,
                    //which could conceivably have example sentences and other stuff
                    //so update the meaning in case they edited that
                    if (ShowMeaningField)
                    {
                        _savedSensesDuringMoveToEditArea[0].Definition.SetAlternative(DefinitionWritingSystem.Id, meaning);
                    }

                    //are there senses with a matching glosses?
                    foreach (var lexSense in _savedSensesDuringMoveToEditArea)
                    {
                        sense = entry.Senses.FirstOrDefault(s => s.Definition.ContainsEqualForm(
                                                                lexSense.Definition[DefinitionWritingSystem.Id],
                                                                DefinitionWritingSystem.Id));
                        if (sense != null)
                        {
                            //now, can we merge this sense in?
                            if (!SenseMerger.TryMergeSenseWithSomeExistingSense(sense, lexSense, new string[] {}, new NullProgress()))
                            {
                                //ah well, they'll have to hand-merge at some point
                                //Enhance: add a chorus note
                                entry.Senses.Add(lexSense);
                            }
                        }
                        else                         //ok, no matching sense to try and merge with, so just add this
                        {
                            entry.Senses.Add(lexSense);
                            sense = lexSense;
                        }
                    }
                }
                else
                {
                    //is there a sense with a matching gloss?
                    sense = entry.Senses.FirstOrDefault(s => s.Definition.ContainsEqualForm(meaning, DefinitionWritingSystem.Id));
                }
            }
            if (sense == null)
            {
                sense = entry.GetOrCreateSenseWithMeaning(new MultiText());
                sense.Definition.SetAlternative(DefinitionWritingSystem.Id, meaning);
            }
            OptionRefCollection semanticDomains =
                sense.GetOrCreateProperty <OptionRefCollection>(_semanticDomainField.FieldName);

            if (!semanticDomains.Contains(CurrentDomainKey))
            {
                semanticDomains.Add(CurrentDomainKey);
            }
            LexEntryRepository.SaveItem(entry);
        }