Exemplo n.º 1
0
        public void UnexpectedAtomicCollectionRetained()
        {
            LexEntry e = MakeSimpleEntry();

            _builder.MergeInTrait(e, new Trait("flub", "dub"));
            _builder.MergeInTrait(e, new Trait("flub", "stub"));
            Assert.AreEqual(1, e.Properties.Count);
            Assert.AreEqual("flub", e.Properties[0].Key);
            OptionRefCollection option = e.GetProperty <OptionRefCollection>("flub");

            Assert.IsTrue(option.Contains("dub"));
            Assert.IsTrue(option.Contains("stub"));
        }
Exemplo n.º 2
0
        public void ExpectedCollectionTrait()
        {
            _builder.ExpectedOptionCollectionTraits.Add("flub");
            LexEntry e = MakeSimpleEntry();

            _builder.MergeInTrait(e, new Trait("flub", "dub"));
            _builder.MergeInTrait(e, new Trait("flub", "stub"));
            Assert.AreEqual(1, e.Properties.Count);
            Assert.AreEqual("flub", e.Properties[0].Key);
            OptionRefCollection options = e.GetProperty <OptionRefCollection>("flub");

            Assert.AreEqual(2, options.Count);
            Assert.IsTrue(options.Contains("dub"));
            Assert.IsTrue(options.Contains("stub"));
        }
Exemplo n.º 3
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);
        }