Ejemplo n.º 1
0
        private void WordsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                AddWords(e.NewItems.Cast <WordViewModel>());
                break;

            case NotifyCollectionChangedAction.Remove:
                RemoveWords(e.OldItems.Cast <WordViewModel>());
                break;

            case NotifyCollectionChangedAction.Replace:
                RemoveWords(e.OldItems.Cast <WordViewModel>());
                AddWords(e.NewItems.Cast <WordViewModel>());
                break;

            case NotifyCollectionChangedAction.Reset:
                _selectedWords.Clear();
                using (_selectedSegmentWords.BulkUpdate())
                {
                    _selectedSegmentWords.Clear();
                    AddWords(_words);
                }
                break;
            }
            ResetSearch();
            UpdateWordCounts();
        }
Ejemplo n.º 2
0
        private void AlignWords()
        {
            if (_selectedMeaning == null)
            {
                return;
            }

            _busyService.ShowBusyIndicatorUntilFinishDrawing();

            var words = new HashSet <Word>();

            foreach (VarietyPair vp in _projectService.Project.VarietyPairs)
            {
                WordPair wp;
                if (vp.WordPairs.TryGetValue(_selectedMeaning.DomainMeaning, out wp))
                {
                    words.Add(wp.Word1);
                    words.Add(wp.Word2);
                }
            }
            if (words.Count == 0)
            {
                _words.Clear();
                return;
            }

            IWordAligner aligner = _projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];
            Alignment <Word, ShapeNode> alignment;

            if (words.Count == 1)
            {
                Word word = words.First();
                Annotation <ShapeNode> prefixAnn = word.Prefix;
                var prefix = new AlignmentCell <ShapeNode>(prefixAnn != null ? word.Shape.GetNodes(prefixAnn.Span).Where(NodeFilter) : Enumerable.Empty <ShapeNode>());
                IEnumerable <AlignmentCell <ShapeNode> > columns = word.Shape.GetNodes(word.Stem.Span).Where(NodeFilter).Select(n => new AlignmentCell <ShapeNode>(n));
                Annotation <ShapeNode> suffixAnn = word.Suffix;
                var suffix = new AlignmentCell <ShapeNode>(suffixAnn != null ? word.Shape.GetNodes(suffixAnn.Span).Where(NodeFilter) : Enumerable.Empty <ShapeNode>());
                alignment = new Alignment <Word, ShapeNode>(0, 0, Tuple.Create(word, prefix, columns, suffix));
            }
            else
            {
                IWordAlignerResult result = aligner.Compute(words);
                alignment = result.GetAlignments().First();
            }

            List <Cluster <Word> > cognateSets = _projectService.Project.GenerateCognateSets(_selectedMeaning.DomainMeaning).OrderBy(c => c.Noise).ThenByDescending(c => c.DataObjects.Count).ToList();

            ColumnCount = alignment.ColumnCount;
            using (_words.BulkUpdate())
            {
                _words.Clear();
                for (int i = 0; i < alignment.SequenceCount; i++)
                {
                    AlignmentCell <ShapeNode> prefix = alignment.Prefixes[i];
                    Word word = alignment.Sequences[i];
                    IEnumerable <AlignmentCell <ShapeNode> > columns = Enumerable.Range(0, alignment.ColumnCount).Select(col => alignment[i, col]);
                    AlignmentCell <ShapeNode> suffix = alignment.Suffixes[i];
                    int cognateSetIndex = cognateSets.FindIndex(set => set.DataObjects.Contains(word));
                    _words.Add(new MultipleWordAlignmentWordViewModel(word, prefix, columns, suffix, cognateSetIndex == cognateSets.Count - 1 ? int.MaxValue : cognateSetIndex + 1));
                }
            }
        }