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);
        }
Ejemplo n.º 2
0
        private void AddMapping()
        {
            var vm = new NewSegmentMappingViewModel(_projectService.Project.Segmenter);

            if (_dialogService.ShowModalDialog(this, vm) == true)
            {
                var mapping = new SegmentMappingViewModel(_projectService.Project.Segmenter, vm.Segment1, vm.Segment2);
                _mappings.Add(mapping);
                SelectedMapping = mapping;
                IsChanged       = true;
            }
        }
Ejemplo 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;
        }
Ejemplo n.º 4
0
        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;
        }
        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);
        }
Ejemplo n.º 6
0
        private void AddMapping()
        {
            NewSegmentMappingViewModel vm = _newMappingFactory();

            vm.Segment1        = _segment1;
            vm.Segment2        = _segment2;
            vm.SegmentsEnabled = _segment1 == null && _segment2 == null;
            if (_dialogService.ShowModalDialog(this, vm) == true)
            {
                SegmentMappingViewModel mapping = _mappingFactory(vm.LeftEnvironment1 + vm.Segment1 + vm.RightEnvironment1,
                                                                  vm.LeftEnvironment2 + vm.Segment2 + vm.RightEnvironment2);
                SegmentMappingViewModel existingMapping = _mappings.FirstOrDefault(m => (m.Segment1 == mapping.Segment1 && m.Segment2 == mapping.Segment2) ||
                                                                                   (m.Segment1 == mapping.Segment2 && m.Segment2 == mapping.Segment1));
                if (existingMapping == null)
                {
                    _mappings.Add(mapping);
                }
                else
                {
                    mapping = existingMapping;
                }
                SelectedMapping = mapping;
            }
        }
Ejemplo n.º 7
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.GetValue(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);
                }
            }
        }
Ejemplo n.º 8
0
 private void AddMapping()
 {
     NewSegmentMappingViewModel vm = _newMappingFactory();
     vm.Segment1 = _segment1;
     vm.Segment2 = _segment2;
     vm.SegmentsEnabled = _segment1 == null && _segment2 == null;
     if (_dialogService.ShowModalDialog(this, vm) == true)
     {
         SegmentMappingViewModel mapping = _mappingFactory(vm.LeftEnvironment1 + vm.Segment1 + vm.RightEnvironment1,
             vm.LeftEnvironment2 + vm.Segment2 + vm.RightEnvironment2);
         SegmentMappingViewModel existingMapping = _mappings.FirstOrDefault(m => (m.Segment1 == mapping.Segment1 && m.Segment2 == mapping.Segment2)
             || (m.Segment1 == mapping.Segment2 && m.Segment2 == mapping.Segment1));
         if (existingMapping == null)
             _mappings.Add(mapping);
         else
             mapping = existingMapping;
         SelectedMapping = mapping;
     }
 }