Exemple #1
0
 private void ClearWordSelection(WordViewModel word)
 {
     var item = (ListBoxItem) WordsListBox.ItemContainerGenerator.ContainerFromItem(word);
     if (item != null)
     {
         ListBox wordListBox = item.FindVisualDescendants<ListBox>().FirstOrDefault();
         if (wordListBox != null)
             wordListBox.UnselectAll();
     }
 }
Exemple #2
0
        internal bool FindNext(FindField field, string str)
        {
            if (_words.Count == 0)
            {
                ResetSearch();
                return(false);
            }
            if (_selectedWords.Count == 0)
            {
                _startWord = _wordsView.Cast <WordViewModel>().Last();
            }
            else if (_startWord == null)
            {
                _startWord = _selectedWords[0];
            }
            else if (_selectedWords.Contains(_startWord))
            {
                ResetSearch();
                return(false);
            }

            List <WordViewModel> words   = _wordsView.Cast <WordViewModel>().ToList();
            WordViewModel        curWord = _selectedWords.Count == 0 ? _startWord : _selectedWords[0];
            int wordIndex = words.IndexOf(curWord);

            do
            {
                wordIndex = (wordIndex + 1) % words.Count;
                curWord   = words[wordIndex];
                bool match = false;
                switch (field)
                {
                case FindField.Form:
                    match = curWord.StrRep.Contains(str);
                    break;

                case FindField.Gloss:
                    match = curWord.Meaning.Gloss.Contains(str);
                    break;
                }
                if (match)
                {
                    using (_selectedWordsMonitor.Enter())
                    {
                        _selectedWords.Clear();
                        _selectedWords.Add(curWord);
                    }
                    return(true);
                }
            }while (_startWord != curWord);
            ResetSearch();
            return(false);
        }
        public WordListsVarietyMeaningViewModel(IBusyService busyService, IAnalysisService analysisService, WordViewModel.Factory wordFactory, WordListsVarietyViewModel variety, Meaning meaning)
            : base(meaning)
        {
            _busyService = busyService;
            _analysisService = analysisService;
            _variety = variety;

            _domainWords = new ObservableList<Word>(variety.DomainVariety.Words[meaning]);
            _words = new MirroredBindableList<Word, WordViewModel>(_domainWords, word => wordFactory(word), vm => vm.DomainWord);
            _domainWords.CollectionChanged += DomainWordsChanged;
            _strRep = string.Join(",", _domainWords.Select(word => word.StrRep));
            _showInVarietiesCommand = new RelayCommand(ShowInVarieties, () => _domainWords.Count > 0);
        }
Exemple #4
0
        public void Segments()
        {
            var segmentPool = new SegmentPool();
            var busyService = Substitute.For<IBusyService>();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.Add(new Meaning("gloss1", "cat1"));
            project.Varieties.Add(new Variety("variety1"));
            var w = new Word("gugəl", project.Meanings[0]);
            project.Varieties[0].Words.Add(w);
            projectService.Project.Returns(project);

            var word = new WordViewModel(busyService, analysisService, w);

            Assert.That(word.Segments, Is.Empty);
            Assert.That(word.IsValid, Is.False);

            project.Segmenter.Segment(w);

            Assert.That(word.IsValid, Is.True);
            Assert.That(word.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"|", "g", "u", "g", "ə", "l", "|"}));

            word.Segments.Move(0, 2);

            Assert.That(word.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"g", "u", "|", "g", "ə", "l", "|"}));
            Annotation<ShapeNode> prefixAnn = w.Prefix;
            Assert.That(prefixAnn, Is.Not.Null);
            Assert.That(w.Shape.GetNodes(prefixAnn.Span).Select(n => n.OriginalStrRep()), Is.EqualTo(new[] {"g", "u"}));
            Assert.That(w.Shape.GetNodes(w.Stem.Span).Select(n => n.OriginalStrRep()), Is.EqualTo(new[] {"g", "ə", "l"}));
            Assert.That(w.Suffix, Is.Null);
            Assert.That(w.StemIndex, Is.EqualTo(2));
            Assert.That(w.StemLength, Is.EqualTo(3));

            WordSegmentViewModel seg = word.Segments[6];
            word.Segments.RemoveAt(6);
            word.Segments.Insert(5, seg);

            Assert.That(word.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"g", "u", "|", "g", "ə", "|", "l"}));
            prefixAnn = w.Prefix;
            Assert.That(prefixAnn, Is.Not.Null);
            Assert.That(w.Shape.GetNodes(prefixAnn.Span).Select(n => n.OriginalStrRep()), Is.EqualTo(new[] {"g", "u"}));
            Assert.That(w.Shape.GetNodes(w.Stem.Span).Select(n => n.OriginalStrRep()), Is.EqualTo(new[] {"g", "ə"}));
            Annotation<ShapeNode> suffixAnn = w.Suffix;
            Assert.That(suffixAnn, Is.Not.Null);
            Assert.That(w.Shape.GetNodes(suffixAnn.Span).Select(n => n.OriginalStrRep()), Is.EqualTo(new[] {"l"}));
            Assert.That(w.StemIndex, Is.EqualTo(2));
            Assert.That(w.StemLength, Is.EqualTo(2));
        }
Exemple #5
0
        private bool SelectWordSegments(WordViewModel word)
        {
            bool selected = false;

            foreach (WordSegmentViewModel segment in word.Segments.Where(s => !s.IsBoundary && !s.IsNotInOriginal))
            {
                segment.IsSelected = _selectedSegment != null && segment.DomainNode.StrRep() == _selectedSegment.StrRep;
                if (segment.IsSelected)
                {
                    selected = true;
                }
            }
            return(selected);
        }
Exemple #6
0
        public SegmentsViewModel(IProjectService projectService, IDialogService dialogService, IBusyService busyService, IExportService exportService, WordsViewModel.Factory wordsFactory,
			WordViewModel.Factory wordFactory)
            : base("Segments")
        {
            _projectService = projectService;
            _busyService = busyService;
            _dialogService = dialogService;
            _exportService = exportService;
            _wordFactory = wordFactory;

            _findCommand = new RelayCommand(Find);

            TaskAreas.Add(new TaskAreaCommandGroupViewModel("Syllable position",
                new TaskAreaCommandViewModel("Onset", new RelayCommand(() => SyllablePosition = SyllablePosition.Onset)),
                new TaskAreaCommandViewModel("Nucleus", new RelayCommand(() => SyllablePosition = SyllablePosition.Nucleus)),
                new TaskAreaCommandViewModel("Coda", new RelayCommand(() => SyllablePosition = SyllablePosition.Coda))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Common tasks",
                new TaskAreaCommandViewModel("Find words", _findCommand),
                new TaskAreaItemsViewModel("Sort words by", new TaskAreaCommandGroupViewModel(
                    new TaskAreaCommandViewModel("Meaning", new RelayCommand(() => SortWordsBy("Meaning.Gloss", ListSortDirection.Ascending))),
                    new TaskAreaCommandViewModel("Form", new RelayCommand(() => SortWordsBy("StrRep", ListSortDirection.Ascending)))))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks",
                new TaskAreaCommandViewModel("Export segment frequencies", new RelayCommand(ExportSegmentFrequencies, CanExportSegmentFrequencies))));

            _projectService.ProjectOpened += _projectService_ProjectOpened;

            Messenger.Default.Register<DomainModelChangedMessage>(this, msg =>
                {
                    if (msg.AffectsComparison)
                        PopulateSegments();
                });

            _currentWords = new BulkObservableList<WordViewModel>();
            _observedWords = wordsFactory(new ReadOnlyBindableList<WordViewModel>(_currentWords));
            _domainSegments = new BulkObservableList<Segment>();
            _segments = new BulkObservableList<SegmentViewModel>();
            _readonlySegments = new ReadOnlyBindableList<SegmentViewModel>(_segments);
            _categories = new BulkObservableList<SegmentCategoryViewModel>();
            _readonlyCategories = new ReadOnlyBindableList<SegmentCategoryViewModel>(_categories);
        }
        public VarietiesVarietyViewModel(IProjectService projectService, IDialogService dialogService, WordsViewModel.Factory wordsFactory, WordViewModel.Factory wordFactory, Variety variety)
            : base(variety)
        {
            _projectService = projectService;
            _dialogService = dialogService;

            IEnumerable<Segment> segments = variety.SegmentFrequencyDistribution == null ? Enumerable.Empty<Segment>() : variety.SegmentFrequencyDistribution.ObservedSamples;

            _segments = new BulkObservableList<VarietySegmentViewModel>(segments.Select(seg => new VarietySegmentViewModel(this, seg)));
            _maxSegProb = _segments.Select(seg => seg.Probability).Concat(0).Max();
            _readOnlySegments = new ReadOnlyBindableList<VarietySegmentViewModel>(_segments);
            variety.PropertyChanged += variety_PropertyChanged;
            _affixes = new MirroredBindableList<Affix, AffixViewModel>(DomainVariety.Affixes, affix => new AffixViewModel(affix), vm => vm.DomainAffix);
            _words = new MirroredBindableCollection<Word, WordViewModel>(variety.Words, word =>
                {
                    WordViewModel vm = wordFactory(word);
                    SelectWordSegments(vm);
                    return vm;
                }, vm => vm.DomainWord);
            _wordsViewModel = wordsFactory(_words);
            _newAffixCommand = new RelayCommand(NewAffix);
            _editAffixCommand = new RelayCommand(EditAffix, CanEditAffix);
            _removeAffixCommand = new RelayCommand(RemoveAffix, CanRemoveAffix);
        }
Exemple #8
0
        public VarietiesVarietyViewModel(IProjectService projectService, IDialogService dialogService, WordsViewModel.Factory wordsFactory, WordViewModel.Factory wordFactory, Variety variety)
            : base(variety)
        {
            _projectService = projectService;
            _dialogService  = dialogService;

            IEnumerable <Segment> segments = variety.SegmentFrequencyDistribution == null?Enumerable.Empty <Segment>() : variety.SegmentFrequencyDistribution.ObservedSamples;

            _segments                = new BulkObservableList <VarietySegmentViewModel>(segments.Select(seg => new VarietySegmentViewModel(this, seg)));
            _maxSegProb              = _segments.Select(seg => seg.Probability).Concat(0).Max();
            _readOnlySegments        = new ReadOnlyBindableList <VarietySegmentViewModel>(_segments);
            variety.PropertyChanged += variety_PropertyChanged;
            _affixes = new MirroredBindableList <Affix, AffixViewModel>(DomainVariety.Affixes, affix => new AffixViewModel(affix), vm => vm.DomainAffix);
            _words   = new MirroredBindableCollection <Word, WordViewModel>(variety.Words, word =>
            {
                WordViewModel vm = wordFactory(word);
                SelectWordSegments(vm);
                return(vm);
            }, vm => vm.DomainWord);
            _wordsViewModel     = wordsFactory(_words);
            _newAffixCommand    = new RelayCommand(NewAffix);
            _editAffixCommand   = new RelayCommand(EditAffix, CanEditAffix);
            _removeAffixCommand = new RelayCommand(RemoveAffix, CanRemoveAffix);
        }
 private bool SelectWordSegments(WordViewModel word)
 {
     bool selected = false;
     foreach (WordSegmentViewModel segment in word.Segments.Where(s => !s.IsBoundary && !s.IsNotInOriginal))
     {
         segment.IsSelected = _selectedSegment != null && segment.DomainNode.StrRep() == _selectedSegment.StrRep;
         if (segment.IsSelected)
             selected = true;
     }
     return selected;
 }
Exemple #10
0
 internal void ResetSearch()
 {
     _startWord = null;
 }
Exemple #11
0
        internal bool FindNext(FindField field, string str)
        {
            if (_words.Count == 0)
            {
                ResetSearch();
                return false;
            }
            if (_selectedWords.Count == 0)
            {
                _startWord = _wordsView.Cast<WordViewModel>().Last();
            }
            else if (_startWord == null)
            {
                _startWord = _selectedWords[0];
            }
            else if (_selectedWords.Contains(_startWord))
            {
                ResetSearch();
                return false;
            }

            List<WordViewModel> words = _wordsView.Cast<WordViewModel>().ToList();
            WordViewModel curWord = _selectedWords.Count == 0 ? _startWord : _selectedWords[0];
            int wordIndex = words.IndexOf(curWord);
            do
            {
                wordIndex = (wordIndex + 1) % words.Count;
                curWord = words[wordIndex];
                bool match = false;
                switch (field)
                {
                    case FindField.Form:
                        match = curWord.StrRep.Contains(str);
                        break;

                    case FindField.Gloss:
                        match = curWord.Meaning.Gloss.Contains(str);
                        break;
                }
                if (match)
                {
                    using (_selectedWordsMonitor.Enter())
                    {
                        _selectedWords.Clear();
                        _selectedWords.Add(curWord);
                    }
                    return true;
                }
            }
            while (_startWord != curWord);
            ResetSearch();
            return false;
        }
Exemple #12
0
 internal void ResetSearch()
 {
     _startWord = null;
 }