示例#1
0
        /// <summary>
        /// it can happen that within a single entry, you can have mergable senses.
        /// </summary>
        private static void MergeSensesWithinEntries(LiftLexEntryRepository repo, string[] traitsWithMultiplicity, IProgress progress)
        {
            var ids = new List <RepositoryId>(repo.GetAllItems());

            foreach (var id in ids)
            {
                if (progress.CancelRequested)
                {
                    throw new OperationCanceledException("User cancelled");
                }
                var entry  = repo.GetItem(id);
                var senses = entry.Senses.ToArray();
                if (senses.Length < 2)
                {
                    continue;
                }
                var sensesToRemove = new List <LexSense>();
                foreach (var sense in entry.Senses)
                {
                    if (sensesToRemove.Any(s => ReferenceEquals(s, sense)))
                    {
                        continue;
                    }
                    foreach (var otherSense in entry.Senses)
                    {
                        if (ReferenceEquals(otherSense, sense))                         // Don't try and compare with ourself.
                        {
                            continue;
                        }
                        if (sensesToRemove.Any(s => ReferenceEquals(s, sense)))
                        {
                            continue;
                        }
                        if (!SenseMerger.TryMergeSenseWithSomeExistingSense(sense, otherSense, traitsWithMultiplicity, progress))
                        {
                            continue;
                        }
                        sensesToRemove.Add(otherSense);
                    }
                }
                foreach (var sense in sensesToRemove)
                {
                    entry.Senses.Remove(sense);
                    entry.IsDirty = true;
                }
                if (entry.IsDirty)
                {
                    repo.SaveItem(entry);
                }
            }
        }
示例#2
0
 private static void MergeOrAddSense(LexEntry targetEntry, LexSense incomingSense, string[] traitsWithMultiplicity, IProgress progress)
 {
     if (targetEntry.Senses.Count == 0)
     {
         targetEntry.Senses.Add(incomingSense);                //no problem!
     }
     else
     {
         if (targetEntry.Senses.Count == 1)
         {
             var targetSense = targetEntry.Senses[0];
             if (SenseMerger.TryMergeSenseWithSomeExistingSense(targetSense, incomingSense, traitsWithMultiplicity, progress))
             {
                 //it was merged in
                 return;
             }
         }
     }
     //it needs to be added
     targetEntry.Senses.Add(incomingSense);
 }