public SimilarSegmentMappingsViewModel(IProjectService projectService, IDialogService dialogService, SegmentMappingsTableViewModel.Factory segmentMappingsTableFactory,
			SegmentMappingsViewModel mappings, SegmentMappingViewModel.Factory mappingFactory, SoundType soundType)
        {
            _projectService = projectService;
            _mappings = mappings;
            _mappings.PropertyChanged += ChildPropertyChanged;
            _soundType = soundType;
            _dialogService = dialogService;
            _segmentMappingsTableFactory = segmentMappingsTableFactory;
            _mappingFactory = mappingFactory;
            _editSegmentMappingsTableCommand = new RelayCommand(EditSegmentMappingsTable);
        }
Esempio n. 2
0
 public SimilarSegmentMappingsViewModel(IProjectService projectService, IDialogService dialogService, SegmentMappingsTableViewModel.Factory segmentMappingsTableFactory,
                                        SegmentMappingsViewModel mappings, SegmentMappingViewModel.Factory mappingFactory, SoundType soundType)
 {
     _projectService                  = projectService;
     _mappings                        = mappings;
     _mappings.PropertyChanged       += ChildPropertyChanged;
     _soundType                       = soundType;
     _dialogService                   = dialogService;
     _segmentMappingsTableFactory     = segmentMappingsTableFactory;
     _mappingFactory                  = mappingFactory;
     _editSegmentMappingsTableCommand = new RelayCommand(EditSegmentMappingsTable);
 }
Esempio n. 3
0
        public SegmentMappingsViewModel(IDialogService dialogService, IImportService importService, SegmentMappingViewModel.Factory mappingFactory,
			NewSegmentMappingViewModel.Factory newMappingFactory)
        {
            _dialogService = dialogService;
            _importService = importService;
            _mappingFactory = mappingFactory;
            _newMappingFactory = newMappingFactory;
            _mappings = new BindableList<SegmentMappingViewModel>();
            _newCommand = new RelayCommand(AddMapping);
            _removeCommand = new RelayCommand(RemoveMapping, CanRemoveMapping);
            _importCommand = new RelayCommand(Import);
            _mappings.CollectionChanged += MappingsChanged;
        }
Esempio n. 4
0
 public SegmentMappingsViewModel(IDialogService dialogService, IImportService importService, SegmentMappingViewModel.Factory mappingFactory,
                                 NewSegmentMappingViewModel.Factory newMappingFactory)
 {
     _dialogService               = dialogService;
     _importService               = importService;
     _mappingFactory              = mappingFactory;
     _newMappingFactory           = newMappingFactory;
     _mappings                    = new BindableList <SegmentMappingViewModel>();
     _newCommand                  = new RelayCommand(AddMapping);
     _removeCommand               = new RelayCommand(RemoveMapping, CanRemoveMapping);
     _importCommand               = new RelayCommand(Import);
     _mappings.CollectionChanged += MappingsChanged;
 }
        public BlairCognateIdentifierViewModel(SegmentPool segmentPool, IProjectService projectService, SegmentMappingsViewModel ignoredMappings,
			SimilarSegmentMappingsViewModel.Factory similarSegmentMappingsFactory, SegmentMappingViewModel.Factory mappingFactory)
            : base("Blair")
        {
            _segmentPool = segmentPool;
            _projectService = projectService;
            _mappingFactory = mappingFactory;
            _ignoredMappings = ignoredMappings;
            _ignoredMappings.PropertyChanged += ChildPropertyChanged;
            _similarVowels = similarSegmentMappingsFactory(SoundType.Vowel);
            _similarVowels.PropertyChanged += ChildPropertyChanged;
            _similarConsonants = similarSegmentMappingsFactory(SoundType.Consonant);
            _similarConsonants.PropertyChanged += ChildPropertyChanged;
        }
Esempio n. 6
0
 public SegmentMappingsTableSegmentPairViewModel(SegmentMappingsViewModel mappings, SegmentMappingViewModel.Factory mappingFactory,
                                                 SegmentMappingsTableSegmentViewModel segment1, SegmentMappingsTableSegmentViewModel segment2, int delta, bool enabled)
 {
     _mappingFactory = mappingFactory;
     _segment1       = segment1;
     _segment2       = segment2;
     _enabled        = enabled;
     _delta          = delta;
     _mappings       = mappings;
     _mappings.ConstrainToSegmentPair(_segment1.StrRep, _segment2.StrRep);
     _mappings.ImportEnabled = false;
     _mappings.Mappings.CollectionChanged += MappingsChanged;
     _toggleMappingCommand = new RelayCommand(ToggleMapping);
 }
 public BlairCognateIdentifierViewModel(SegmentPool segmentPool, IProjectService projectService, SegmentMappingsViewModel ignoredMappings,
                                        SimilarSegmentMappingsViewModel.Factory similarSegmentMappingsFactory, SegmentMappingViewModel.Factory mappingFactory)
     : base("Blair", "Blair-Method-Settings")
 {
     _segmentPool     = segmentPool;
     _projectService  = projectService;
     _mappingFactory  = mappingFactory;
     _ignoredMappings = ignoredMappings;
     _ignoredMappings.PropertyChanged += ChildPropertyChanged;
     _similarVowels = similarSegmentMappingsFactory(SoundType.Vowel);
     _similarVowels.PropertyChanged     += ChildPropertyChanged;
     _similarConsonants                  = similarSegmentMappingsFactory(SoundType.Consonant);
     _similarConsonants.PropertyChanged += ChildPropertyChanged;
 }
        public SegmentMappingsTableSegmentPairViewModel(SegmentMappingsViewModel mappings, SegmentMappingViewModel.Factory mappingFactory,
			SegmentMappingsTableSegmentViewModel segment1, SegmentMappingsTableSegmentViewModel segment2, int delta, bool enabled)
        {
            _mappingFactory = mappingFactory;
            _segment1 = segment1;
            _segment2 = segment2;
            _enabled = enabled;
            _delta = delta;
            _mappings = mappings;
            _mappings.ConstrainToSegmentPair(_segment1.StrRep, _segment2.StrRep);
            _mappings.ImportEnabled = false;
            _mappings.Mappings.CollectionChanged += MappingsChanged;
            _toggleMappingCommand = new RelayCommand(ToggleMapping);
        }
            public TestEnvironment()
            {
                DispatcherHelper.Initialize();
                _projectService = Substitute.For <IProjectService>();
                var dialogService = Substitute.For <IDialogService>();
                var importService = Substitute.For <IImportService>();

                SegmentMappingViewModel.Factory    mappingFactory    = (segment1, segment2) => new SegmentMappingViewModel(_projectService, segment1, segment2);
                NewSegmentMappingViewModel.Factory newMappingFactory = () => new NewSegmentMappingViewModel(_projectService);

                var segmentMappings = new SegmentMappingsViewModel(dialogService, importService, mappingFactory, newMappingFactory);

                _segmentPair = new SegmentMappingsTableSegmentPairViewModel(segmentMappings, mappingFactory,
                                                                            new SegmentMappingsTableSegmentViewModel(new Segment(FeatureStruct.New().Symbol(CogFeatureSystem.ConsonantType).Feature(CogFeatureSystem.StrRep).EqualTo("b").Value), SoundType.Consonant),
                                                                            new SegmentMappingsTableSegmentViewModel(new Segment(FeatureStruct.New().Symbol(CogFeatureSystem.ConsonantType).Feature(CogFeatureSystem.StrRep).EqualTo("c").Value), SoundType.Consonant),
                                                                            100, true);

                var project = new CogProject();

                _projectService.Project.Returns(project);
            }
Esempio n. 10
0
        public SegmentMappingsTableViewModel(IProjectService projectService, SegmentMappingsTableSegmentPairViewModel.Factory segmentPairFactory, SegmentMappingViewModel.Factory mappingFactory,
                                             IEnumerable <SegmentMappingViewModel> mappings, SoundType soundType, int threshold)
        {
            _threshold = threshold;

            _soundType = soundType;
            FeatureSymbol segmentType;

            switch (_soundType)
            {
            case SoundType.Consonant:
                segmentType = CogFeatureSystem.ConsonantType;
                break;

            case SoundType.Vowel:
                segmentType = CogFeatureSystem.VowelType;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            var segmentComparer  = new SegmentComparer();
            var categoryComparer = new SegmentCategoryComparer();

            _segments = new ReadOnlyList <SegmentMappingsTableSegmentViewModel>(projectService.Project.Varieties.SelectMany(v => v.SegmentFrequencyDistribution.ObservedSamples)
                                                                                .Where(s => s.Type == segmentType).Distinct().OrderBy(s => s.Category(), categoryComparer).ThenBy(s => s, segmentComparer)
                                                                                .Select(s => new SegmentMappingsTableSegmentViewModel(s, _soundType)).Concat(new SegmentMappingsTableSegmentViewModel(null, _soundType)).ToArray());
            _categories = new ReadOnlyList <SegmentCategoryViewModel>(_segments.GroupBy(s => s.DomainSegment == null ? string.Empty : s.DomainSegment.Category())
                                                                      .OrderBy(g => g.Key, categoryComparer).Select(g => new SegmentCategoryViewModel(g.Key, g)).ToArray());

            var mappingLookup = new Dictionary <UnorderedTuple <string, string>, HashSet <UnorderedTuple <string, string> > >();

            foreach (SegmentMappingViewModel mapping in mappings)
            {
                string        seg1, seg2;
                FeatureSymbol leftEnv1, rightEnv1, leftEnv2, rightEnv2;
                if (ListSegmentMappings.Normalize(projectService.Project.Segmenter, mapping.Segment1, out seg1, out leftEnv1, out rightEnv1) &&
                    ListSegmentMappings.Normalize(projectService.Project.Segmenter, mapping.Segment2, out seg2, out leftEnv2, out rightEnv2))
                {
                    UnorderedTuple <string, string>            key = UnorderedTuple.Create(seg1, seg2);
                    HashSet <UnorderedTuple <string, string> > m   = mappingLookup.GetOrCreate(key, () => new HashSet <UnorderedTuple <string, string> >());
                    m.Add(UnorderedTuple.Create(mapping.Segment1, mapping.Segment2));
                }
            }

            IWordAligner aligner = projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];

            foreach (SegmentMappingsTableSegmentViewModel segment1 in _segments)
            {
                bool isEnabled = true;
                foreach (SegmentMappingsTableSegmentViewModel segment2 in _segments)
                {
                    if (EqualityComparer <Segment> .Default.Equals(segment1.DomainSegment, segment2.DomainSegment))
                    {
                        isEnabled = false;
                    }

                    int delta = segment1.DomainSegment == null || segment2.DomainSegment == null ? -1
                                                : aligner.Delta(segment1.DomainSegment.FeatureStruct, segment2.DomainSegment.FeatureStruct);
                    SegmentMappingsTableSegmentPairViewModel segmentPair = segmentPairFactory(segment1, segment2, delta, isEnabled);
                    segmentPair.MeetsThreshold = delta != -1 && delta <= _threshold;
                    HashSet <UnorderedTuple <string, string> > pairMappings;
                    if (mappingLookup.TryGetValue(UnorderedTuple.Create(segment1.StrRep, segment2.StrRep), out pairMappings))
                    {
                        segmentPair.Mappings.Mappings.AddRange(pairMappings.Select(m => mappingFactory(m.Item1, m.Item2)));
                    }
                    segment1.SegmentPairs.Add(segmentPair);
                }
            }
        }