Inheritance: ObservableObject
コード例 #1
0
ファイル: EditRegionViewModel.cs プロジェクト: rmunn/cog
 public EditRegionViewModel(IEnumerable<Variety> varieties, Variety variety, GeographicRegion region)
 {
     _title = "Edit Region";
     _varieties = new ReadOnlyList<VarietyViewModel>(varieties.Select(v => new VarietyViewModel(v)).OrderBy(vm => vm.Name).ToArray());
     _selectedVariety = _varieties.First(vm => vm.DomainVariety == variety);
     _description = region.Description;
 }
コード例 #2
0
ファイル: EditVarietyViewModel.cs プロジェクト: rmunn/cog
 public EditVarietyViewModel(IKeyedCollection<string, Variety> varieties, Variety variety)
 {
     _title = "Rename Variety";
     _varieties = varieties;
     _variety = variety;
     _name = variety.Name;
 }
コード例 #3
0
ファイル: SegmentsVarietyViewModel.cs プロジェクト: rmunn/cog
 public SegmentsVarietyViewModel(SegmentsViewModel segmentsViewModel, Variety variety)
     : base(variety)
 {
     _segments = new MirroredBindableList<Segment, VarietySegmentViewModel>(segmentsViewModel.DomainSegments,
         segment => new VarietySegmentViewModel(this, segment, segmentsViewModel.DomainSyllablePosition), viewModel => viewModel.DomainSegment);
     _switchToVarietyCommand = new RelayCommand(() => Messenger.Default.Send(new SwitchViewMessage(typeof(VarietiesViewModel), DomainVariety)));
 }
コード例 #4
0
ファイル: CognacyDecision.cs プロジェクト: megahirt/cog
 public CognacyDecision(Variety variety1, Variety variety2, Meaning meaning, bool cognacy)
 {
     Variety1 = variety1;
     Variety2 = variety2;
     Meaning  = meaning;
     Cognacy  = cognacy;
 }
コード例 #5
0
 public SimilarityMatrixVarietyPairViewModel(SimilarityMetric similarityMetric, Variety thisVariety, VarietyPair varietyPair)
 {
     _varietyPair = varietyPair;
     _thisVariety = thisVariety;
     _otherVariety = _varietyPair.GetOtherVariety(_thisVariety);
     _switchToVarietyPairCommand = new RelayCommand(SwitchToVarietyPair);
     _similarityMetric = similarityMetric;
 }
コード例 #6
0
ファイル: WordPair.cs プロジェクト: megahirt/cog
 public Word GetWord(Variety v)
 {
     if (VarietyPair.Variety1 == v)
     {
         return(Word1);
     }
     return(Word2);
 }
コード例 #7
0
        internal void VarietyPairRemoved(VarietyPair varietyPair)
        {
            CheckReentrancy();
            Variety otherVariety = varietyPair.GetOtherVariety(_variety);

            _varietyPairs.Remove(otherVariety);
            OnPropertyChanged(new PropertyChangedEventArgs("Count"));
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, varietyPair));
        }
コード例 #8
0
 public WordListsVarietyViewModel(IProjectService projectService, WordListsVarietyMeaningViewModel.Factory varietyMeaningFactory, WordListsViewModel parent, Variety variety)
     : base(variety)
 {
     _parent = parent;
     _meanings = new VarietyMeaningViewModelCollection(projectService.Project.Meanings, DomainVariety.Words, meaning => varietyMeaningFactory(this, meaning));
     _switchToVarietyCommand = new RelayCommand(() => Messenger.Default.Send(new SwitchViewMessage(typeof(VarietiesViewModel), DomainVariety)));
     _goToNextInvalidWordCommand = new RelayCommand(GotoNextInvalidWord);
     CheckForErrors();
 }
コード例 #9
0
 public SimilarityMatrixVarietyViewModel(SimilarityMetric similarityMetric, IEnumerable<Variety> varieties, Variety variety)
     : base(variety)
 {
     var varietyPairs = new List<SimilarityMatrixVarietyPairViewModel>();
     foreach (Variety v in varieties)
     {
         VarietyPair vp;
         varietyPairs.Add(variety.VarietyPairs.TryGetValue(v, out vp) ? new SimilarityMatrixVarietyPairViewModel(similarityMetric, variety, vp) : new SimilarityMatrixVarietyPairViewModel(variety, v));
     }
     _varietyPairs = new ReadOnlyList<SimilarityMatrixVarietyPairViewModel>(varietyPairs);
 }
コード例 #10
0
ファイル: VarietyPair.cs プロジェクト: FieldDB/cog
        public VarietyPair(Variety variety1, Variety variety2)
        {
            _variety1  = variety1;
            _variety2  = variety2;
            _wordPairs = new WordPairCollection(this);

            _soundCorrespondenceCollections = new ReadOnlyDictionary <FeatureSymbol, SoundCorrespondenceCollection>(new Dictionary <FeatureSymbol, SoundCorrespondenceCollection>
            {
                { CogFeatureSystem.Onset, new SoundCorrespondenceCollection() },
                { CogFeatureSystem.Nucleus, new SoundCorrespondenceCollection() },
                { CogFeatureSystem.Coda, new SoundCorrespondenceCollection() }
            });
        }
コード例 #11
0
ファイル: VarietyPair.cs プロジェクト: rmunn/cog
        public VarietyPair(Variety variety1, Variety variety2)
        {
            _variety1 = variety1;
            _variety2 = variety2;
            _wordPairs = new WordPairCollection(this);

            _soundCorrespondenceCollections = new ReadOnlyDictionary<FeatureSymbol, SoundCorrespondenceCollection>(new Dictionary<FeatureSymbol, SoundCorrespondenceCollection>
                {
                    {CogFeatureSystem.Onset, new SoundCorrespondenceCollection()},
                    {CogFeatureSystem.Nucleus, new SoundCorrespondenceCollection()},
                    {CogFeatureSystem.Coda, new SoundCorrespondenceCollection()}
                });
        }
コード例 #12
0
ファイル: VarietyPair.cs プロジェクト: megahirt/cog
        public Variety GetOtherVariety(Variety variety)
        {
            Variety otherVariety = null;

            if (Variety1 == variety)
            {
                otherVariety = Variety2;
            }
            else if (Variety2 == variety)
            {
                otherVariety = Variety1;
            }
            return(otherVariety);
        }
コード例 #13
0
        private CogProject CreateProject()
        {
            var project = new CogProject(_spanFactory);
            var variety1 = new Variety("variety1");
            project.Varieties.Add(variety1);
            var variety2 = new Variety("variety2");
            project.Varieties.Add(variety2);
            var variety3 = new Variety("variety3");
            project.Varieties.Add(variety3);
            var meaning1 = new Meaning("meaning1", null);
            project.Meanings.Add(meaning1);
            var meaning2 = new Meaning("meaning2", null);
            project.Meanings.Add(meaning2);
            var meaning3 = new Meaning("meaning3", null);
            project.Meanings.Add(meaning3);

            variety1.Words.Add(new Word("word1", meaning1));
            variety1.Words.Add(new Word("word2", meaning2));
            variety1.Words.Add(new Word("word3", meaning3));

            variety2.Words.Add(new Word("word4", meaning1));
            variety2.Words.Add(new Word("word5", meaning2));
            variety2.Words.Add(new Word("word6", meaning3));

            variety3.Words.Add(new Word("word7", meaning1));
            variety3.Words.Add(new Word("word8", meaning2));
            variety3.Words.Add(new Word("word9", meaning3));

            var vpGenerator = new VarietyPairGenerator();
            vpGenerator.Process(project);

            double score = 1.0;
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                foreach (Meaning meaning in project.Meanings)
                {
                    Word w1 = vp.Variety1.Words[meaning].First();
                    Word w2 = vp.Variety2.Words[meaning].First();
                    WordPair wp = vp.WordPairs.Add(w1, w2);
                    wp.PredictedCognacyScore = score;
                    wp.PredictedCognacy = true;
                    score -= 0.1;
                }
            }
            return project;
        }
コード例 #14
0
        public void Import(object importSettingsViewModel, Stream stream, CogProject project)
        {
            var reader = new CsvReader(new StreamReader(stream), ',');
            if (!SkipRows(reader, 5))
            {
                project.Meanings.Clear();
                project.Varieties.Clear();
                return;
            }

            var varieties = new List<Variety>();
            var meanings = new Dictionary<string, Meaning>();
            IList<string> varietyRow;
            while (reader.ReadRow(out varietyRow))
            {
                if (string.IsNullOrEmpty(varietyRow[0]))
                    break;

                var variety = new Variety(varietyRow[0].Trim());
                if (!SkipRows(reader, 2))
                    throw new ImportException("Metadata for a variety is incomplete.");

                Meaning curMeaning = null;
                IList<string> glossRow;
                while (reader.ReadRow(out glossRow) && glossRow.Any(s => !string.IsNullOrEmpty(s)))
                {
                    if (!string.IsNullOrEmpty(glossRow[0]))
                    {
                        string gloss = glossRow[0].Trim();
                        curMeaning = meanings.GetValue(gloss, () => new Meaning(gloss, null));
                    }
                    if (curMeaning == null)
                        throw new ImportException("A gloss is missing.");

                    string wordStr = glossRow[1].Trim();
                    if (!string.IsNullOrEmpty(wordStr))
                        variety.Words.Add(new Word(wordStr, curMeaning));
                }
                varieties.Add(variety);
            }

            project.Meanings.ReplaceAll(meanings.Values);
            project.Varieties.ReplaceAll(varieties);
        }
コード例 #15
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);
        }
コード例 #16
0
 public GeographicalVarietyViewModel(GeographicalRegionViewModel.Factory regionFactory, Variety variety)
     : base(variety)
 {
     _regions = new MirroredBindableList<GeographicRegion, GeographicalRegionViewModel>(variety.Regions, region => regionFactory(this, region), vm => vm.DomainRegion);
     _clusterIndex = -1;
 }
コード例 #17
0
 bool IKeyedCollection <Variety, VarietyPair> .Remove(Variety key)
 {
     throw new NotSupportedException();
 }
コード例 #18
0
        private void LoadVarietyFolder(Dictionary<Variety, List<GeographicRegion>> regions, Variety variety, XElement elem)
        {
            foreach (XElement placemark in elem.Elements(Kml + "Placemark"))
            {
                XElement polygon = placemark.Element(Kml + "Polygon");
                if (polygon != null)
                    regions.GetValue(variety, () => new List<GeographicRegion>()).Add(LoadRegion(polygon, (string) placemark.Element(Kml + "name")));
            }

            foreach (XElement folder in elem.Elements(Kml + "Folder"))
                LoadVarietyFolder(regions, variety, folder);
        }
コード例 #19
0
        public void Import(object importSettingsViewModel, Stream stream, CogProject project)
        {
            XDocument doc = XDocument.Load(stream, LoadOptions.SetLineInfo);
            XElement root = doc.Element("survey");
            if (root == null)
                throw new ImportException("No survey element.");

            var varietyNames = new HashSet<string>();
            var varieties = new Dictionary<string, Tuple<Variety, List<Word>>>();
            foreach (XElement wordListElem in root.Elements("word_lists").Elements("word_list"))
            {
                var id = (string) wordListElem.Attribute("id");
                if (id == null)
                    throw new ImportException(string.Format("A \"word_list\" element is missing an \"id\" attribute. Line: {0}", ((IXmlLineInfo) wordListElem).LineNumber));
                if (varieties.ContainsKey(id))
                    throw new ImportException(string.Format("The ID of a \"word_list\" element is not unique. Line: {0}", ((IXmlLineInfo) wordListElem).LineNumber));
                XElement nameElem = wordListElem.Element("name");
                if (nameElem == null)
                    throw new ImportException(string.Format("A \"word_list\" element is missing a \"name\" element. Line: {0}", ((IXmlLineInfo) wordListElem).LineNumber));
                var name = ((string) nameElem).Trim();
                if (string.IsNullOrEmpty(name))
                    throw new ImportException(string.Format("A blank variety name is not allowed. Line: {0}", ((IXmlLineInfo) nameElem).LineNumber));
                if (varietyNames.Contains(name))
                    throw new ImportException(string.Format("The variety name, \"{0}\", is not unique. Line: {1}", name, ((IXmlLineInfo) wordListElem).LineNumber));
                varietyNames.Add(name);
                var variety = new Variety(name);

                varieties[id] = Tuple.Create(variety, new List<Word>());
            }

            var meanings = new Dictionary<string, Meaning>();
            foreach (XElement glossElem in root.Elements("glosses").Elements("gloss"))
            {
                XElement nameElem = glossElem.Element("name");
                if (nameElem == null)
                    throw new ImportException(string.Format("A \"gloss\" element is missing a \"name\" element. Line: {0}", ((IXmlLineInfo) glossElem).LineNumber));
                var gloss = ((string) nameElem).Trim();
                if (string.IsNullOrEmpty(gloss))
                    throw new ImportException(string.Format("A blank gloss is not allowed. Line: {0}", ((IXmlLineInfo) nameElem).LineNumber));
                var pos = (string) glossElem.Element("part_of_speech");
                if (meanings.ContainsKey(gloss))
                    throw new ImportException(string.Format("The gloss, \"{0}\", is not unique. Line: {1}", gloss, ((IXmlLineInfo) nameElem).LineNumber));
                var meaning = new Meaning(gloss, pos);
                meanings[gloss] = meaning;
                foreach (XElement transElem in glossElem.Elements("transcriptions").Elements("transcription"))
                {
                    XElement wordListIdElem = transElem.Element("word_list_id");
                    if (wordListIdElem == null)
                        throw new ImportException(string.Format("A \"transcription\" element is missing a \"word_list_id\" element. Line: {0}", ((IXmlLineInfo) transElem).LineNumber));
                    var varietyID = (string) wordListIdElem;
                    var wordform = (string) transElem.Element("name");
                    if (wordform != null)
                    {
                        wordform = wordform.Trim();
                        if (!string.IsNullOrEmpty(wordform))
                        {
                            Tuple<Variety, List<Word>> variety;
                            if (varieties.TryGetValue(varietyID, out variety))
                            {
                                foreach (string w in wordform.Split(','))
                                {
                                    string str = w.Trim();
                                    variety.Item2.Add(new Word(str, meaning));
                                }
                            }
                        }
                    }
                }
            }

            project.Meanings.ReplaceAll(meanings.Values);
            using (project.Varieties.BulkUpdate())
            {
                project.Varieties.Clear();
                foreach (Tuple<Variety, List<Word>> variety in varieties.Values)
                {
                    variety.Item1.Words.AddRange(variety.Item2);
                    project.Varieties.Add(variety.Item1);
                }
            }
        }
コード例 #20
0
 public MultipleWordAlignmentVarietyViewModel(Variety variety, int wordIndex)
     : base(variety)
 {
     _wordIndex = wordIndex;
 }
コード例 #21
0
ファイル: HierarchicalGraphVertex.cs プロジェクト: rmunn/cog
 public HierarchicalGraphVertex(Variety variety, double depth)
     : base(variety)
 {
     _variety = variety;
     _depth = depth;
 }
コード例 #22
0
 public SelectableVarietyViewModel(Variety variety)
     : base(variety)
 {
 }
コード例 #23
0
ファイル: VarietyViewModel.cs プロジェクト: rmunn/cog
 public VarietyViewModel(Variety variety)
     : base(variety)
 {
     _variety = variety;
 }
コード例 #24
0
ファイル: WordListsViewModel.cs プロジェクト: sillsdev/cog
 private void AddNewVariety()
 {
     var vm = new EditVarietyViewModel(_projectService.Project.Varieties);
     if (_dialogService.ShowModalDialog(this, vm) == true)
     {
         var variety = new Variety(vm.Name);
         _projectService.Project.Varieties.Add(variety);
         _analysisService.Segment(variety);
         Messenger.Default.Send(new DomainModelChangedMessage(true));
     }
 }
コード例 #25
0
ファイル: VarietyPair.cs プロジェクト: rmunn/cog
 public Variety GetOtherVariety(Variety variety)
 {
     Variety otherVariety = null;
     if (_variety1 == variety)
         otherVariety = _variety2;
     else if (_variety2 == variety)
         otherVariety = _variety1;
     return otherVariety;
 }
コード例 #26
0
ファイル: NetworkGraphVertex.cs プロジェクト: rmunn/cog
 public NetworkGraphVertex(Variety variety)
     : base(variety)
 {
     _variety = variety;
 }
コード例 #27
0
 private CogProject CreateProject()
 {
     var project = new CogProject(_spanFactory);
     var variety1 = new Variety("variety1");
     project.Varieties.Add(variety1);
     var variety2 = new Variety("variety2");
     project.Varieties.Add(variety2);
     var variety3 = new Variety("variety3");
     project.Varieties.Add(variety3);
     var generator = new VarietyPairGenerator();
     generator.Process(project);
     variety1.VarietyPairs[variety2].LexicalSimilarityScore = 0.9;
     variety1.VarietyPairs[variety2].PhoneticSimilarityScore = 0.95;
     variety1.VarietyPairs[variety3].LexicalSimilarityScore = 0.8;
     variety1.VarietyPairs[variety3].PhoneticSimilarityScore = 0.85;
     variety2.VarietyPairs[variety3].LexicalSimilarityScore = 0.7;
     variety2.VarietyPairs[variety3].PhoneticSimilarityScore = 0.75;
     return project;
 }
コード例 #28
0
 public SimilarityMatrixVarietyPairViewModel(Variety thisVariety, Variety otherVariety)
 {
     _thisVariety = thisVariety;
     _otherVariety = otherVariety;
 }
コード例 #29
0
 public VarietyPair this[Variety key]
 {
     get { return(_varietyPairs[key]); }
 }
コード例 #30
0
ファイル: WordPair.cs プロジェクト: sillsdev/cog
 public Word GetWord(Variety v)
 {
     if (VarietyPair.Variety1 == v)
         return _word1;
     return _word2;
 }
コード例 #31
0
 public bool TryGetValue(Variety key, out VarietyPair item)
 {
     return(_varietyPairs.TryGetValue(key, out item));
 }
コード例 #32
0
ファイル: VerbBase.cs プロジェクト: rmunn/cog
 // Should this be protected? But the unit test needs to call it.
 public void SetUpProject()
 {
     if (ConfigData != null && ConfigFilename != null)
     {
         Warnings.Add("WARNING: options --config-data and --config-file were both specified. Ignoring --config-file.");
         ConfigFilename = null;
     }
     if (ConfigData == null && ConfigFilename == null)
     {
         ConfigFilename = FindConfigFilename();
         // If ConfigFilename is STILL null at this point, it's because no config files were found at all, so we'll use the default one from the resource.
     }
     SpanFactory = new ShapeSpanFactory();
     SegmentPool = new SegmentPool();
     Variety1 = new Variety("variety1");
     Variety2 = new Variety("variety2");
     Meaning = new Meaning("gloss1", "cat1");
     if (ConfigData == null && ConfigFilename == null)
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     else if (ConfigData != null)
         Project = GetProjectFromXmlString(SpanFactory, SegmentPool, ConfigData);
     else if (ConfigFilename != null)
         Project = GetProjectFromFilename(SpanFactory, SegmentPool, ConfigFilename);
     else // Should never get here given checks above, but let's be safe and write the check anyway
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     Project.Meanings.Add(Meaning);
     Project.Varieties.Add(Variety1);
     Project.Varieties.Add(Variety2);
     Project.VarietyPairs.Add(new VarietyPair(Variety1, Variety2));
 }
コード例 #33
0
 public bool Contains(Variety key)
 {
     return(_varietyPairs.ContainsKey(key));
 }
コード例 #34
0
ファイル: AnalysisService.cs プロジェクト: StephenEhmann/cog
        public void Stem(StemmingMethod method, Variety variety)
        {
            _busyService.ShowBusyIndicatorUntilFinishDrawing();
            if (method == StemmingMethod.Automatic)
                variety.Affixes.Clear();

            var pipeline = new Pipeline<Variety>(GetStemProcessors(method));
            pipeline.Process(variety.ToEnumerable());
            Messenger.Default.Send(new DomainModelChangedMessage(true));
        }
コード例 #35
0
 internal VarietyVarietyPairCollection(Variety variety)
 {
     _variety      = variety;
     _varietyPairs = new Dictionary <Variety, VarietyPair>();
 }
コード例 #36
0
ファイル: AnalysisService.cs プロジェクト: StephenEhmann/cog
 public void Segment(Variety variety)
 {
     _busyService.ShowBusyIndicatorUntilFinishDrawing();
     var pipeline = new Pipeline<Variety>(GetSegmentProcessors());
     pipeline.Process(variety.ToEnumerable());
 }
コード例 #37
0
 internal WordCollection(Variety variety)
 {
     _variety    = variety;
     _words      = new Dictionary <Meaning, HashSet <Word> >();
     _emptyWords = new ReadOnlyCollection <Word>(new Word[0]);
 }
コード例 #38
0
ファイル: CognatesVerb.cs プロジェクト: rmunn/cog
 public void Segment(Variety variety)
 {
     var pipeline = new Pipeline<Variety>(GetSegmentProcessors());
     pipeline.Process(variety.ToEnumerable());
 }