Inheritance: ViewModelBase
コード例 #1
0
ファイル: VarietyPairViewModel.cs プロジェクト: sillsdev/cog
        public VarietyPairViewModel(SegmentPool segmentPool, IProjectService projectService, WordPairsViewModel.Factory wordPairsFactory,
			WordPairViewModel.Factory wordPairFactory, VarietyPair varietyPair, bool areVarietiesInOrder)
            : base(varietyPair)
        {
            _segmentPool = segmentPool;
            _projectService = projectService;
            _varietyPair = varietyPair;
            _areVarietiesInOrder = areVarietiesInOrder;
            _wordPairsFactory = wordPairsFactory;
            _wordPairFactory = wordPairFactory;

            Messenger.Default.Register<ComparisonPerformedMessage>(this, HandleComparisonPerformed);

            UpdateVarietyPair();
        }
コード例 #2
0
        public GlobalCorrespondencesViewModel(IProjectService projectService, IBusyService busyService, IDialogService dialogService, IImageExportService imageExportService, IGraphService graphService,
			WordPairsViewModel.Factory wordPairsFactory, WordPairViewModel.Factory wordPairFactory)
            : base("Global Correspondences")
        {
            _projectService = projectService;
            _busyService = busyService;
            _dialogService = dialogService;
            _imageExportService = imageExportService;
            _graphService = graphService;
            _wordPairFactory = wordPairFactory;

            _selectedVarieties = new HashSet<Variety>();

            _projectService.ProjectOpened += _projectService_ProjectOpened;

            Messenger.Default.Register<ComparisonPerformedMessage>(this, msg => GenerateGraph());
            Messenger.Default.Register<DomainModelChangedMessage>(this, msg =>
            {
                if (msg.AffectsComparison)
                    ClearGraph();
            });
            Messenger.Default.Register<PerformingComparisonMessage>(this, msg => ClearGraph());

            _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))));
            _correspondenceFilter = new TaskAreaIntegerViewModel("Frequency threshold");
            _correspondenceFilter.PropertyChanging += _correspondenceFilter_PropertyChanging;
            _correspondenceFilter.PropertyChanged += _correspondenceFilter_PropertyChanged;
            TaskAreas.Add(_correspondenceFilter);
            TaskAreas.Add(new TaskAreaItemsViewModel("Common tasks",
                new TaskAreaCommandViewModel("Find words", _findCommand),
                new TaskAreaItemsViewModel("Sort word pairs by", new TaskAreaCommandGroupViewModel(
                    new TaskAreaCommandViewModel("Gloss", new RelayCommand(() => _observedWordPairs.UpdateSort("Meaning.Gloss", ListSortDirection.Ascending))),
                    new TaskAreaCommandViewModel("Similarity", new RelayCommand(() => _observedWordPairs.UpdateSort("PhoneticSimilarityScore", ListSortDirection.Descending))))),
                new TaskAreaCommandViewModel("Select varieties", new RelayCommand(SelectVarieties))
                ));
            TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks",
                new TaskAreaCommandViewModel("Export chart", new RelayCommand(ExportChart, CanExportChart))));
            _observedWordPairs = wordPairsFactory();
            _observedWordPairs.IncludeVarietyNamesInSelectedText = true;
            _observedWordPairs.UpdateSort("Meaning.Gloss", ListSortDirection.Ascending);
        }
コード例 #3
0
        internal bool FindNext(FindField field, string str, bool wrap, bool startAtBeginning)
        {
            if (_wordPairs.Count == 0)
            {
                if (wrap)
                {
                    ResetSearch();
                }
                return(false);
            }
            if (!startAtBeginning && _selectedWordPairs.Count == 0)
            {
                _startWordPair = _wordPairsView.Cast <WordPairViewModel>().Last();
            }
            else if (_startWordPair == null)
            {
                _startWordPair = _selectedWordPairs[0];
            }
            else if (!startAtBeginning && _selectedWordPairs.Contains(_startWordPair))
            {
                if (wrap)
                {
                    ResetSearch();
                }
                return(false);
            }

            List <WordPairViewModel> wordPairs = _wordPairsView.Cast <WordPairViewModel>().ToList();
            WordPairViewModel        curWordPair;

            if (startAtBeginning)
            {
                curWordPair = wordPairs[wordPairs.Count - 1];
                if (_startWordPair == curWordPair)
                {
                    ResetSearch();
                    return(false);
                }
            }
            else
            {
                curWordPair = _selectedWordPairs.Count == 0 ? _startWordPair : _selectedWordPairs[0];
            }
            int wordPairIndex = wordPairs.IndexOf(curWordPair);

            do
            {
                wordPairIndex++;
                if (wordPairIndex == wordPairs.Count)
                {
                    if (!wrap && !startAtBeginning && _startWordPair != curWordPair)
                    {
                        return(false);
                    }
                    wordPairIndex = 0;
                }
                curWordPair = wordPairs[wordPairIndex];
                bool match = false;
                switch (field)
                {
                case FindField.Form:
                    match = curWordPair.DomainWordPair.Word1.StrRep.Contains(str) ||
                            curWordPair.DomainWordPair.Word2.StrRep.Contains(str);
                    break;

                case FindField.Gloss:
                    match = curWordPair.Meaning.Gloss.Contains(str);
                    break;
                }
                if (match)
                {
                    using (_selectedWordPairsMonitor.Enter())
                    {
                        _selectedWordPairs.Clear();
                        _selectedWordPairs.Add(curWordPair);
                    }
                    return(true);
                }
            }while (_startWordPair != curWordPair);
            if (wrap)
            {
                ResetSearch();
            }
            return(false);
        }
コード例 #4
0
 internal void ResetSearch()
 {
     _startWordPair = null;
 }
コード例 #5
0
ファイル: WordPairsViewModel.cs プロジェクト: rmunn/cog
 internal void ResetSearch()
 {
     _startWordPair = null;
 }
コード例 #6
0
ファイル: WordPairsViewModel.cs プロジェクト: rmunn/cog
        internal bool FindNext(FindField field, string str, bool wrap, bool startAtBeginning)
        {
            if (_wordPairs.Count == 0)
            {
                if (wrap)
                    ResetSearch();
                return false;
            }
            if (!startAtBeginning && _selectedWordPairs.Count == 0)
            {
                _startWordPair = _wordPairsView.Cast<WordPairViewModel>().Last();
            }
            else if (_startWordPair == null)
            {
                _startWordPair = _selectedWordPairs[0];
            }
            else if (!startAtBeginning && _selectedWordPairs.Contains(_startWordPair))
            {
                if (wrap)
                    ResetSearch();
                return false;
            }

            List<WordPairViewModel> wordPairs = _wordPairsView.Cast<WordPairViewModel>().ToList();
            WordPairViewModel curWordPair;
            if (startAtBeginning)
            {
                curWordPair = wordPairs[wordPairs.Count - 1];
                if (_startWordPair == curWordPair)
                {
                    ResetSearch();
                    return false;
                }
            }
            else
            {
                curWordPair = _selectedWordPairs.Count == 0 ? _startWordPair : _selectedWordPairs[0];
            }
            int wordPairIndex = wordPairs.IndexOf(curWordPair);
            do
            {
                wordPairIndex++;
                if (wordPairIndex == wordPairs.Count)
                {
                    if (!wrap && !startAtBeginning && _startWordPair != curWordPair)
                        return false;
                    wordPairIndex = 0;
                }
                curWordPair = wordPairs[wordPairIndex];
                bool match = false;
                switch (field)
                {
                    case FindField.Form:
                        match = curWordPair.DomainWordPair.Word1.StrRep.Contains(str)
                            || curWordPair.DomainWordPair.Word2.StrRep.Contains(str);
                        break;

                    case FindField.Gloss:
                        match = curWordPair.Meaning.Gloss.Contains(str);
                        break;
                }
                if (match)
                {
                    using (_selectedWordPairsMonitor.Enter())
                    {
                        _selectedWordPairs.Clear();
                        _selectedWordPairs.Add(curWordPair);
                    }
                    return true;
                }
            }
            while (_startWordPair != curWordPair);
            if (wrap)
                ResetSearch();
            return false;
        }
コード例 #7
0
            public TestEnvironment(bool? actualCognacy, bool predictedCognacy)
            {
                DispatcherHelper.Initialize();

                var segmentPool = new SegmentPool();
                var spanFactory = new ShapeSpanFactory();
                var projectService = Substitute.For<IProjectService>();
                var analysisService = Substitute.For<IAnalysisService>();
                _project = TestHelpers.GetTestProject(spanFactory, segmentPool);
                _project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
                _project.Meanings.Add(new Meaning("meaning1", null));
                var word1 = new Word("wɜrd", _project.Meanings[0]);
                _project.Varieties[0].Words.Add(word1);
                _project.Segmenter.Segment(word1);
                var word2 = new Word("kɑr", _project.Meanings[0]);
                _project.Varieties[1].Words.Add(word2);
                _project.Segmenter.Segment(word2);

                var vp = new VarietyPair(_project.Varieties[0], _project.Varieties[1]);
                if (actualCognacy != null)
                    _project.CognacyDecisions.Add(new CognacyDecision(vp.Variety1, vp.Variety2, _project.Meanings[0], (bool) actualCognacy));

                _project.VarietyPairs.Add(vp);
                var wp = new WordPair(word1, word2) {PredictedCognacy = predictedCognacy, ActualCognacy = actualCognacy};
                _project.VarietyPairs[0].WordPairs.Add(wp);

                projectService.Project.Returns(_project);
                _wordPairViewModel = new WordPairViewModel(projectService, analysisService, wp, true);
            }