Inheritance: IAnalysisService
Beispiel #1
0
        public void FindCommand()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService = Substitute.For<IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            WordsViewModel observedWords = segments.ObservedWords;
            observedWords.WordsView = new ListCollectionView(observedWords.Words);

            FindViewModel findViewModel = null;
            Action closeCallback = null;
            dialogService.ShowModelessDialog(segments, Arg.Do<FindViewModel>(vm => findViewModel = vm), Arg.Do<Action>(callback => closeCallback = callback));
            segments.FindCommand.Execute(null);
            Assert.That(findViewModel, Is.Not.Null);
            Assert.That(closeCallback, Is.Not.Null);

            // already open, shouldn't get opened twice
            dialogService.ClearReceivedCalls();
            segments.FindCommand.Execute(null);
            dialogService.DidNotReceive().ShowModelessDialog(segments, Arg.Any<FindViewModel>(), Arg.Any<Action>());

            // nothing selected, no match
            findViewModel.Field = FindField.Form;
            findViewModel.String = "nothing";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.Empty);

            // nothing selected, matches
            segments.SelectedSegment = segments.Varieties[1].Segments[3];
            WordViewModel[] wordsViewArray = observedWords.WordsView.Cast<WordViewModel>().ToArray();
            findViewModel.String = "fi";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
        }
Beispiel #2
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));
        }
        public void FindCommand()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var graphService = new GraphService(projectService);
            var imageExportService = Substitute.For<IImageExportService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);

            WordPairsViewModel.Factory wordPairsFactory = () => new WordPairsViewModel(busyService);

            var globalCorrespondences = new GlobalCorrespondencesViewModel(projectService, busyService, dialogService, imageExportService, graphService, wordPairsFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2"), new Variety("variety3")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("kæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            project.Varieties[2].Words.AddRange(new[] {new Word("wɜrd", project.Meanings[0]), new Word("kɑr", project.Meanings[1]), new Word("fʊt.bɔl", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();

            var varietyPairGenerator = new VarietyPairGenerator();
            varietyPairGenerator.Process(project);
            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, ComponentIdentifiers.PrimaryWordAligner);
            var globalCorrIdentifier = new SoundCorrespondenceIdentifier(segmentPool, project, ComponentIdentifiers.PrimaryWordAligner);
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                    wp.AreCognatePredicted = true;
                vp.SoundChangeFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.SoundChangeProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.SoundChangeFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
                globalCorrIdentifier.Process(vp);
            }
            projectService.AreAllVarietiesCompared.Returns(true);
            projectService.ProjectOpened += Raise.Event();

            WordPairsViewModel observedWordPairs = globalCorrespondences.ObservedWordPairs;
            observedWordPairs.WordPairsView = new ListCollectionView(observedWordPairs.WordPairs);

            FindViewModel findViewModel = null;
            Action closeCallback = null;
            dialogService.ShowModelessDialog(globalCorrespondences, Arg.Do<FindViewModel>(vm => findViewModel = vm), Arg.Do<Action>(callback => closeCallback = callback));
            globalCorrespondences.FindCommand.Execute(null);
            Assert.That(findViewModel, Is.Not.Null);
            Assert.That(closeCallback, Is.Not.Null);

            // already open, shouldn't get opened twice
            dialogService.ClearReceivedCalls();
            globalCorrespondences.FindCommand.Execute(null);
            dialogService.DidNotReceive().ShowModelessDialog(globalCorrespondences, Arg.Any<FindViewModel>(), Arg.Any<Action>());

            // form searches
            findViewModel.Field = FindField.Form;

            // no word pairs, no match
            findViewModel.String = "nothing";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.Empty);

            globalCorrespondences.SelectedCorrespondence = globalCorrespondences.Graph.Edges.First(e => e.Source.StrRep == "k" && e.Target.StrRep == "g");
            WordPairViewModel[] wordPairsArray = observedWordPairs.WordPairsView.Cast<WordPairViewModel>().ToArray();

            // nothing selected, no match
            findViewModel.String = "nothing";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.Empty);

            // nothing selected, matches
            findViewModel.String = "d";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));

            // first word selected, matches
            observedWordPairs.SelectedWordPairs.Clear();
            observedWordPairs.SelectedWordPairs.Add(wordPairsArray[0]);
            findViewModel.String = "g";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            // start search over
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[1].ToEnumerable()));

            // last word selected, matches
            observedWordPairs.SelectedWordPairs.Clear();
            observedWordPairs.SelectedWordPairs.Add(wordPairsArray[2]);
            findViewModel.String = "u";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));

            // nothing selected, matches, change selected word
            observedWordPairs.SelectedWordPairs.Clear();
            findViewModel.String = ".";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));
            observedWordPairs.SelectedWordPairs.Clear();
            observedWordPairs.SelectedWordPairs.Add(wordPairsArray[1]);
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));

            // gloss searches
            findViewModel.Field = FindField.Gloss;
            findViewModel.String = "gloss2";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWordPairs.SelectedWordPairs, Is.EquivalentTo(wordPairsArray[0].ToEnumerable()));
        }
        public void ObservedWordPairs()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var graphService = new GraphService(projectService);
            var imageExportService = Substitute.For<IImageExportService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);

            WordPairsViewModel.Factory wordPairsFactory = () => new WordPairsViewModel(busyService);

            var globalCorrespondences = new GlobalCorrespondencesViewModel(projectService, busyService, dialogService, imageExportService, graphService, wordPairsFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2"), new Variety("variety3")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            project.Varieties[2].Words.AddRange(new[] {new Word("wɜrd", project.Meanings[0]), new Word("kɑr", project.Meanings[1]), new Word("fʊt.bɔl", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();

            var varietyPairGenerator = new VarietyPairGenerator();
            varietyPairGenerator.Process(project);
            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, ComponentIdentifiers.PrimaryWordAligner);
            var globalCorrIdentifier = new SoundCorrespondenceIdentifier(segmentPool, project, ComponentIdentifiers.PrimaryWordAligner);
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                    wp.AreCognatePredicted = true;
                vp.SoundChangeFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.SoundChangeProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.SoundChangeFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
                globalCorrIdentifier.Process(vp);
            }
            projectService.AreAllVarietiesCompared.Returns(true);
            projectService.ProjectOpened += Raise.Event();

            var observedWordPairs = globalCorrespondences.ObservedWordPairs;
            observedWordPairs.WordPairsView = new ListCollectionView(observedWordPairs.WordPairs);

            Assert.That(observedWordPairs.WordPairsView, Is.Empty);

            globalCorrespondences.SelectedCorrespondence = globalCorrespondences.Graph.Edges.First(e => e.Source.StrRep == "g" && e.Target.StrRep == "k");
            WordPairViewModel[] wordPairsArray = observedWordPairs.WordPairsView.Cast<WordPairViewModel>().ToArray();
            Assert.That(wordPairsArray.Length, Is.EqualTo(2));
            Assert.That(wordPairsArray[0].Meaning.Gloss, Is.EqualTo("gloss2"));
            Assert.That(wordPairsArray[0].AlignedNodes[2].IsSelected, Is.True);
            Assert.That(wordPairsArray[1].Meaning.Gloss, Is.EqualTo("gloss2"));
            Assert.That(wordPairsArray[1].AlignedNodes[0].IsSelected, Is.True);

            globalCorrespondences.SyllablePosition = SyllablePosition.Nucleus;
            globalCorrespondences.SelectedCorrespondence = globalCorrespondences.Graph.Edges.First(e => e.Source.StrRep == "ʊ" && e.Target.StrRep == "u");
            wordPairsArray = observedWordPairs.WordPairsView.Cast<WordPairViewModel>().ToArray();
            Assert.That(wordPairsArray.Length, Is.EqualTo(2));
            Assert.That(wordPairsArray[0].Meaning.Gloss, Is.EqualTo("gloss2"));
            Assert.That(wordPairsArray[0].AlignedNodes[1].IsSelected, Is.True);
            Assert.That(wordPairsArray[1].Meaning.Gloss, Is.EqualTo("gloss3"));
            Assert.That(wordPairsArray[1].AlignedNodes[1].IsSelected, Is.True);

            globalCorrespondences.SelectedCorrespondence = null;
            Assert.That(observedWordPairs.WordPairsView, Is.Empty);
        }
        public void Graph()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var graphService = new GraphService(projectService);
            var imageExportService = Substitute.For<IImageExportService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);

            WordPairsViewModel.Factory wordPairsFactory = () => new WordPairsViewModel(busyService);

            var globalCorrespondences = new GlobalCorrespondencesViewModel(projectService, busyService, dialogService, imageExportService, graphService, wordPairsFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2"), new Variety("variety3")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            project.Varieties[2].Words.AddRange(new[] {new Word("wɜrd", project.Meanings[0]), new Word("kɑr", project.Meanings[1]), new Word("fʊt.bɔl", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            Assert.That(globalCorrespondences.Graph, Is.Null);

            Messenger.Default.Send(new PerformingComparisonMessage());
            var varietyPairGenerator = new VarietyPairGenerator();
            varietyPairGenerator.Process(project);
            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, ComponentIdentifiers.PrimaryWordAligner);
            var globalCorrIdentifier = new SoundCorrespondenceIdentifier(segmentPool, project, ComponentIdentifiers.PrimaryWordAligner);
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                    wp.AreCognatePredicted = true;
                vp.SoundChangeFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.SoundChangeProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.SoundChangeFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
                globalCorrIdentifier.Process(vp);
            }

            Messenger.Default.Send(new ComparisonPerformedMessage());

            Assert.That(globalCorrespondences.Graph, Is.Not.Null);

            globalCorrespondences.SyllablePosition = SyllablePosition.Nucleus;
            Assert.That(globalCorrespondences.Graph, Is.Not.Null);

            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(globalCorrespondences.Graph, Is.Null);

            globalCorrespondences.SyllablePosition = SyllablePosition.Coda;
            Assert.That(globalCorrespondences.Graph, Is.Null);
        }
Beispiel #6
0
        public void ObservedWords()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService = Substitute.For<IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            var observedWords = segments.ObservedWords;
            observedWords.WordsView = new ListCollectionView(segments.ObservedWords.Words);

            Assert.That(observedWords.WordsView, Is.Empty);

            segments.SelectedSegment = segments.Varieties[1].Segments[3];
            WordViewModel[] wordsViewArray = observedWords.WordsView.Cast<WordViewModel>().ToArray();
            Assert.That(wordsViewArray.Select(w => w.StrRep), Is.EqualTo(new[] {"gu.gəl", "gu.fi"}));
            Assert.That(wordsViewArray[0].Segments[1].IsSelected, Is.True);
            Assert.That(wordsViewArray[0].Segments[2].IsSelected, Is.False);
            Assert.That(wordsViewArray[0].Segments[4].IsSelected, Is.True);

            segments.SelectedSegment = segments.Varieties[0].Segments[1];
            Assert.That(observedWords.WordsView, Is.Empty);

            segments.SelectedSegment = null;
            Assert.That(observedWords.WordsView, Is.Empty);
        }
Beispiel #7
0
        public void Segments()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService = Substitute.For<IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"b", "f", "l", "g", "h"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Labial", "Coronal", "Dorsal", "Guttural"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[2]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[3]}));
            Assert.That(segments.Categories[3].Segments, Is.EquivalentTo(new[] {segments.Segments[4]}));

            project.Varieties[0].Words.RemoveAll(project.Meanings[0]);
            analysisService.Segment(project.Varieties[0]);
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"b", "f", "g", "h"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Labial", "Dorsal", "Guttural"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[2]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[3]}));

            segments.SyllablePosition = SyllablePosition.Nucleus;
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"i", "u", "ʊ", "ɛ", "ə", "æ"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Close", "Mid", "Open"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1], segments.Segments[2]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[3], segments.Segments[4]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[5]}));

            foreach (Variety variety in project.Varieties)
                variety.Words.Clear();
            analysisService.SegmentAll();
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.False);
            Assert.That(segments.Segments, Is.Empty);
            Assert.That(segments.Categories, Is.Empty);
        }
        public void Words()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var busyService = Substitute.For<IBusyService>();
            var exportService = Substitute.For<IExportService>();
            var dialogService = Substitute.For<IDialogService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);

            var alignment = new MultipleWordAlignmentViewModel(projectService, busyService, exportService, analysisService);

            var project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2"), new Variety("variety3")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            project.Varieties[2].Words.AddRange(new[] {new Word("wɜrd", project.Meanings[0]), new Word("kɑr", project.Meanings[1]), new Word("fʊt.bɔl", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();

            var varietyPairGenerator = new VarietyPairGenerator();
            varietyPairGenerator.Process(project);
            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, ComponentIdentifiers.PrimaryWordAligner);
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                {
                    wp.PredictedCognacy = true;
                    wp.PredictedCognacyScore = 1.0;
                }
                vp.CognateSoundCorrespondenceFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.CognateSoundCorrespondenceProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.CognateSoundCorrespondenceFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
            }
            projectService.AreAllVarietiesCompared.Returns(true);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(alignment.SelectedMeaning, Is.Null);
            Assert.That(alignment.Words, Is.Empty);

            alignment.MeaningsView = new ListCollectionView(alignment.Meanings);
            alignment.WordsView = new ListCollectionView(alignment.Words);

            Assert.That(alignment.WordsView.Cast<MultipleWordAlignmentWordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] {"hɛ.loʊ", "hɛlp", "wɜrd"}));
            Assert.That(alignment.ColumnCount, Is.EqualTo(4));

            alignment.SelectedMeaning = alignment.Meanings[1];

            Assert.That(alignment.WordsView.Cast<MultipleWordAlignmentWordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] {"gu.gəl", "gʊd", "kɑr"}));
            Assert.That(alignment.ColumnCount, Is.EqualTo(5));

            project.Varieties.RemoveAt(project.Varieties.Count - 1);
            Messenger.Default.Send(new DomainModelChangedMessage(true));

            Messenger.Default.Send(new PerformingComparisonMessage());
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                {
                    wp.PredictedCognacy = true;
                    wp.PredictedCognacyScore = 1.0;
                }
                vp.CognateSoundCorrespondenceFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.CognateSoundCorrespondenceProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.CognateSoundCorrespondenceFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
            }
            Messenger.Default.Send(new ComparisonPerformedMessage());

            Assert.That(alignment.WordsView.Cast<MultipleWordAlignmentWordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] {"gu.gəl", "gʊd"}));
            Assert.That(alignment.ColumnCount, Is.EqualTo(5));

            project.Varieties.RemoveAt(project.Varieties.Count - 1);

            Messenger.Default.Send(new PerformingComparisonMessage());
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                wordPairGenerator.Process(vp);
                foreach (WordPair wp in vp.WordPairs)
                    wp.PredictedCognacy = true;
                vp.CognateSoundCorrespondenceFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();
                vp.CognateSoundCorrespondenceProbabilityDistribution = new ConditionalProbabilityDistribution<SoundContext, Ngram<Segment>>(vp.CognateSoundCorrespondenceFrequencyDistribution, (sc, fd) => new MaxLikelihoodProbabilityDistribution<Ngram<Segment>>(fd));
            }
            Messenger.Default.Send(new ComparisonPerformedMessage());

            Assert.That(alignment.WordsView, Is.Empty);
        }