Ejemplo n.º 1
0
        private static Control MakeOptionCollectionWidget(PalasoDataObject target, Field field)
        {
            OptionsList         availableOptions = WeSayWordsProject.Project.GetOptionsList(field, false);
            OptionRefCollection refsOfChoices    =
                target.GetOrCreateProperty <OptionRefCollection>(field.FieldName);
            IList <IWritingSystemDefinition> writingSystems =
                BasilProject.Project.WritingSystemsFromIds(field.WritingSystemIds);
            IChoiceSystemAdaptor <Option, string, OptionRef> displayAdaptor;

            if (field.FieldName == LexSense.WellKnownProperties.SemanticDomainDdp4)
            {
                displayAdaptor = new DdpOptionDisplayAdaptor(availableOptions, field.WritingSystemIds[0]);
            }
            else
            {
                displayAdaptor = new OptionDisplayAdaptor(availableOptions, field.WritingSystemIds[0]);
            }


            ReferenceCollectionEditor <Option, string, OptionRef> control =
                new ReferenceCollectionEditor <Option, string, OptionRef>(refsOfChoices.Members,
                                                                          availableOptions.
                                                                          Options,
                                                                          writingSystems,
                                                                          field.Visibility,
                                                                          displayAdaptor,
                                                                          WeSayWordsProject.Project.ServiceLocator);

            control.AlternateEmptinessHelper = refsOfChoices;
            return(control);
        }
        public void Setup()
        {
            _ws.DefaultFontName = "Arial";
            _ws.DefaultFontSize = 30;
            _sourceChoices      = new OptionsList();
            AddSourceChoice("one", "1");
            AddSourceChoice("two", "2");
            AddSourceChoice("three", "3");
            AddSourceChoice("four", "4");
            AddSourceChoice("five", "5");

            _chosenItems = new OptionRefCollection(this);

            List <IWritingSystemDefinition> writingSystems = new List <IWritingSystemDefinition>();

            writingSystems.Add(_ws);

            _control = new ReferenceCollectionEditor <Option, string, OptionRef>(
                _chosenItems.Members,
                _sourceChoices.Options,
                writingSystems,
                CommonEnumerations.VisibilitySetting.Visible,
                new OptionDisplayAdaptor(_sourceChoices, _ws.Id),
                null);

            _control.Name = "refcontrol";
            _control.AlternateEmptinessHelper = _chosenItems;
        }
Ejemplo n.º 3
0
        /// <summary> Adds each sense of a word to be written out to lift </summary>
        private void AddSenses(LexEntry entry, Word wordEntry)
        {
            for (var i = 0; i < wordEntry.Senses.Count; i++)
            {
                // Merge in senses
                var dict = new Dictionary <string, string>();
                foreach (var gloss in wordEntry.Senses[i].Glosses)
                {
                    dict.Add(gloss.Language, gloss.Def);
                }

                var lexSense = new LexSense();
                lexSense.Gloss.MergeIn(MultiTextBase.Create(dict));
                entry.Senses.Add(lexSense);

                // Merge in semantic domains
                foreach (var semdom in wordEntry.Senses[i].SemanticDomains)
                {
                    var orc = new OptionRefCollection();
                    orc.Add(semdom.Id + " " + semdom.Name);

                    entry.Senses[i].Properties.Add(
                        new KeyValuePair <string, IPalasoDataObjectProperty>("semantic-domain-ddp4", orc));
                }
            }
        }
Ejemplo n.º 4
0
        public void CompareTo_OtherHasMoreEntries_ReturnsLess()
        {
            OptionRefCollection reference = new OptionRefCollection(this);
            OptionRefCollection other     = new OptionRefCollection(this);

            other.Add("key2");
            Assert.AreEqual(-1, reference.CompareTo(other));
        }
Ejemplo n.º 5
0
        public void Merge_BothEmpty_Empty()
        {
            OptionRefCollection a = new OptionRefCollection(this);
            OptionRefCollection b = new OptionRefCollection(this);

            a.MergeByKey(b);
            Assert.AreEqual(0, a.Count);
        }
Ejemplo n.º 6
0
        public void CompareTo_OtherHasFewerEntries_ReturnsGreater()
        {
            OptionRefCollection reference = new OptionRefCollection(this);

            reference.Add("key1");
            OptionRefCollection other = new OptionRefCollection(this);

            Assert.AreEqual(1, reference.CompareTo(other));
        }
Ejemplo n.º 7
0
        public void Merge_OtherEmpty_Unchanged()
        {
            OptionRefCollection a = new OptionRefCollection(this);

            a.Add("1");
            OptionRefCollection b = new OptionRefCollection(this);

            a.MergeByKey(b);
            Assert.AreEqual(1, a.Count);
        }
Ejemplo n.º 8
0
        public void CompareTo_OtherHasEntrythatIsAlphabeticallyLater_ReturnsLess()
        {
            OptionRefCollection reference = new OptionRefCollection(this);

            reference.Add("key1");
            OptionRefCollection other = new OptionRefCollection(this);

            other.Add("key2");
            Assert.AreEqual(-1, reference.CompareTo(other));
        }
Ejemplo n.º 9
0
        public void CompareTo_OtherHassameListEntries_ReturnsEqual()
        {
            OptionRefCollection reference = new OptionRefCollection(this);

            reference.Add("key1");
            OptionRefCollection other = new OptionRefCollection(this);

            other.Add("key1");
            Assert.AreEqual(0, reference.CompareTo(other));
        }
Ejemplo n.º 10
0
        public void WordCollected_LiftWithSemanticDomain_CopiedOver()
        {
            LexSense            firstSense = AddWordAndGetFirstSense();
            OptionRefCollection domains    =
                firstSense.GetProperty <OptionRefCollection>(
                    LexSense.WellKnownProperties.SemanticDomainDdp4);

            Assert.AreEqual(1, domains.Count);
            Assert.AreEqual("fruit", domains.KeyAtIndex(0));
        }
Ejemplo n.º 11
0
 public OptionCollectionControl(OptionRefCollection optionRefCollection,
                                OptionsList list,
                                string idOfPreferredWritingSystem)
 {
     _optionRefCollection = optionRefCollection;
     _list = list;
     _idOfPreferredWritingSystem = idOfPreferredWritingSystem;
     InitializeComponent();
     LoadDisplay();
 }
Ejemplo n.º 12
0
        public void UnexpectedAtomicTraitRetained()
        {
            LexEntry e = MakeSimpleEntry();

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

            Assert.IsTrue(option.Contains("dub"));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets a ResultSet containing entries that contain a semantic domain assigned to them
        /// sorted by semantic domain.
        /// Use "SemanticDomain" to access the semantic domain in a RecordToken.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public ResultSet <LexEntry> GetEntriesWithSemanticDomainSortedBySemanticDomain(
            string fieldName)
        {
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }

            string cachename = String.Format("Semanticdomains_{0}", fieldName);

            if (_caches[cachename] == null)
            {
                DelegateQuery <LexEntry> semanticDomainsQuery = new DelegateQuery <LexEntry>(
                    delegate(LexEntry entry)
                {
                    List <IDictionary <string, object> > fieldsandValuesForRecordTokens = new List <IDictionary <string, object> >();
                    foreach (LexSense sense in entry.Senses)
                    {
                        foreach (var pair in sense.Properties)
                        {
                            if (pair.Key == fieldName)
                            {
                                OptionRefCollection semanticDomains = (OptionRefCollection)pair.Value;
                                foreach (string semanticDomain in semanticDomains.Keys)
                                {
                                    IDictionary <string, object> tokenFieldsAndValues = new Dictionary <string, object>();
                                    string domain = semanticDomain;
                                    if (String.IsNullOrEmpty(semanticDomain))
                                    {
                                        domain = null;
                                    }
                                    if (CheckIfTokenHasAlreadyBeenReturnedForThisSemanticDomain(fieldsandValuesForRecordTokens, domain))
                                    {
                                        continue;                                                 //This is to avoid duplicates
                                    }
                                    tokenFieldsAndValues.Add("SemanticDomain", domain);
                                    fieldsandValuesForRecordTokens.Add(tokenFieldsAndValues);
                                }
                            }
                        }
                    }
                    return(fieldsandValuesForRecordTokens);
                }
                    );
                ResultSet <LexEntry> itemsMatchingQuery = GetItemsMatching(semanticDomainsQuery);
                SortDefinition[]     sortDefinition     = new SortDefinition[2];
                sortDefinition[0] = new SortDefinition("SemanticDomain", StringComparer.InvariantCulture);
                sortDefinition[1] = new SortDefinition("Sense", Comparer <int> .Default);
                ResultSetCache <LexEntry> cache =
                    new ResultSetCache <LexEntry>(this, sortDefinition, itemsMatchingQuery, semanticDomainsQuery);
                _caches.Add(cachename, cache);
            }
            return(_caches[cachename].GetResultSet());
        }
Ejemplo n.º 14
0
        public void Merge_TargetEmptyOtherNot_GetsOther()
        {
            OptionRefCollection a = new OptionRefCollection(this);
            OptionRefCollection b = new OptionRefCollection(this);

            b.Add("1");
            b.Add("2");
            a.MergeByKey(b);
            Assert.AreEqual(2, a.Count);
            Assert.AreEqual(2, b.Count);
        }
Ejemplo n.º 15
0
 private void WriteOptionRefCollection(string traitName, OptionRefCollection collection)
 {
     if (!ShouldOutputProperty(traitName))
     {
         return;
     }
     foreach (string key in collection.Keys)
     {
         Writer.WriteStartElement("trait");
         Writer.WriteAttributeString("name", traitName);
         Writer.WriteAttributeString("value", key);                 //yes, the 'value' here is an option key
         Writer.WriteEndElement();
     }
 }
Ejemplo n.º 16
0
        public void Merge_SourceHasEmbeddedXml_Copied()
        {
            OptionRefCollection a = new OptionRefCollection(this);

            a.Add("1");
            OptionRefCollection b = new OptionRefCollection(this);

            b.Add("1");
            ((OptionRef)(b.Members[0])).EmbeddedXmlElements.Add("line1");
            ((OptionRef)(b.Members[0])).EmbeddedXmlElements.Add("line2");
            a.MergeByKey(b);
            Assert.AreEqual(1, a.Count);
            Assert.AreEqual(2, ((OptionRef)(a.Members[0])).EmbeddedXmlElements.Count);
        }
Ejemplo n.º 17
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"));
        }
Ejemplo n.º 18
0
        public void Merge_OneOverlap_NoDuplicates()
        {
            OptionRefCollection a = new OptionRefCollection(this);

            a.Add("1");
            a.Add("2");
            OptionRefCollection b = new OptionRefCollection(this);

            b.Add("1");
            b.Add("3");
            a.MergeByKey(b);
            Assert.AreEqual(3, a.Count);
            Assert.Contains("1", a.Keys.ToArray());
            Assert.Contains("2", a.Keys.ToArray());
            Assert.Contains("3", a.Keys.ToArray());
        }
Ejemplo n.º 19
0
        public void Merge_SourceAndTargetBothEmbeddedXml_ReturnsFalseWithTargetUnchanged()
        {
            OptionRefCollection a = new OptionRefCollection(this);

            a.Add("1");
            ((OptionRef)(a.Members[0])).EmbeddedXmlElements.Add("line1");
            OptionRefCollection b = new OptionRefCollection(this);

            b.Add("1");
            b.Add("2");
            ((OptionRef)(b.Members[0])).EmbeddedXmlElements.Add("line1");
            var result = a.MergeByKey(b);

            Assert.IsFalse(result);
            Assert.AreEqual(1, a.Members.Count);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Handle LIFT's "trait" entity,
 /// which can be found on any subclass of "extensible", on any "field", and as
 /// a subclass of "annotation".
 /// </summary>
 public void MergeInTrait(PalasoDataObject extensible, Trait trait)
 {
     if (String.IsNullOrEmpty(trait.Name))
     {
         //"log skipping..."
         return;
     }
     if (ExpectedOptionTraits.Contains(trait.Name))
     {
         OptionRef o = extensible.GetOrCreateProperty <OptionRef>(trait.Name);
         o.Value = trait.Value.Trim();
     }
     else if (trait.Name.StartsWith("flag-"))
     {
         extensible.SetFlag(trait.Name);
     }
     // if it is unknown assume it is a collection.
     else             //if (ExpectedOptionCollectionTraits.Contains(trait.Name))
     {
         var key = trait.Value.Trim();
         OptionRefCollection refs =
             extensible.GetOrCreateProperty <OptionRefCollection>(trait.Name);
         if (trait.Name == LexSense.WellKnownProperties.SemanticDomainDdp4)
         {
             if (_semanticDomainsList != null && _semanticDomainsList.GetOptionFromKey(key) == null)
             {
                 var match = _semanticDomainsList.Options.FirstOrDefault(option => option.Key.StartsWith(key));
                 if (match != null)
                 {
                     refs.Add(match.Key);
                     return;
                 }
             }
         }
         refs.Add(key);
     }
     //else
     //{
     //    //"log skipping..."
     //}
 }
Ejemplo n.º 21
0
        public IEnumerable <string> GetDisplayStrings(LexEntry item)
        {
            List <string> keys = new List <string>();

            foreach (LexSense sense in item.Senses)
            {
                OptionRefCollection semanticDomains = sense.GetProperty <OptionRefCollection>(_semanticDomainFieldName);

                if (semanticDomains != null)
                {
                    foreach (string s in semanticDomains.Keys)
                    {
                        if (!keys.Contains(s))
                        {
                            keys.Add(s);
                        }
                    }
                }
            }
            return(keys);
        }
Ejemplo n.º 22
0
        /// <summary> Adds each <see cref="Sense"/> of a word to be written out to lift </summary>
        private static void AddSenses(LexEntry entry, Word wordEntry)
        {
            var activeSenses = wordEntry.Senses.Where(s => s.Accessibility == State.Active).ToList();

            foreach (var currentSense in activeSenses)
            {
                // Merge in senses
                var dict = new Dictionary <string, string>();
                foreach (var gloss in currentSense.Glosses)
                {
                    if (dict.ContainsKey(gloss.Language))
                    {
                        // This is an unexpected situation but rather than crashing or losing data we
                        // will just append extra definitions for the language with a semicolon separator
                        dict[gloss.Language] = $"{dict[gloss.Language]};{gloss.Def}";
                    }
                    else
                    {
                        dict.Add(gloss.Language, gloss.Def);
                    }
                }

                var lexSense = new LexSense();
                lexSense.Gloss.MergeIn(MultiTextBase.Create(dict));
                lexSense.Id = currentSense.Guid.ToString();
                entry.Senses.Add(lexSense);

                // Merge in semantic domains
                foreach (var semDom in currentSense.SemanticDomains)
                {
                    var orc = new OptionRefCollection();
                    orc.Add(semDom.Id + " " + semDom.Name);

                    lexSense.Properties.Add(
                        new KeyValuePair <string, IPalasoDataObjectProperty>("semantic-domain-ddp4", orc));
                }
            }
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
        public void CompareTo_Null_ReturnsGreater()
        {
            OptionRefCollection reference = new OptionRefCollection(this);

            Assert.AreEqual(1, reference.CompareTo(null));
        }