private void PopulateSegments() { var segmentComparer = new SegmentComparer(); var categoryComparer = new SegmentCategoryComparer(); _busyService.ShowBusyIndicatorUntilFinishDrawing(); using (_domainSegments.BulkUpdate()) using (_segments.BulkUpdate()) { _domainSegments.Clear(); _segments.Clear(); foreach (Segment segment in _projectService.Project.Varieties .SelectMany(v => v.SyllablePositionSegmentFrequencyDistributions[DomainSyllablePosition].ObservedSamples) .Distinct().OrderBy(s => s.Category(), categoryComparer).ThenBy(s => s, segmentComparer)) { _domainSegments.Add(segment); _segments.Add(new SegmentViewModel(segment)); } } _categories.ReplaceAll(_segments.GroupBy(s => s.DomainSegment.Category()).OrderBy(g => g.Key, categoryComparer).Select(g => new SegmentCategoryViewModel(g.Key, g))); HasSegments = _segments.Count > 0; }
private bool LoadProject(string fileName) { XElement projectElem; try { projectElem = XElement.Load(fileName); } catch (Exception) { return(false); } XElement engineElem = projectElem.Element("TranslationEngine"); if (engineElem == null) { return(false); } var smtConfig = (string)engineElem.Element("SmtConfig"); if (smtConfig == null) { return(false); } var hcSrcConfig = (string)engineElem.Element("SourceAnalyzerConfig"); var hcTrgConfig = (string)engineElem.Element("TargetGeneratorConfig"); string configDir = Path.GetDirectoryName(fileName); Debug.Assert(configDir != null); ITranslationEngine transferEngine = null; if (hcSrcConfig != null && hcTrgConfig != null) { Language srcLang = XmlLanguageLoader.Load(Path.Combine(configDir, hcSrcConfig)); var srcMorpher = new Morpher(_hcTraceManager, srcLang); Language trgLang = XmlLanguageLoader.Load(Path.Combine(configDir, hcTrgConfig)); var trgMorpher = new Morpher(_hcTraceManager, trgLang); transferEngine = new TransferEngine(srcMorpher, new SimpleTransferer(new GlossMorphemeMapper(trgMorpher)), trgMorpher); } _smtModel = new ThotSmtModel(Path.Combine(configDir, smtConfig)); IInteractiveSmtEngine smtEngine = _smtModel.CreateInteractiveEngine(); _hybridEngine = new HybridTranslationEngine(smtEngine, transferEngine); var sourceTexts = new List <IText>(); var targetTexts = new List <IText>(); var alignmentCollections = new List <ITextAlignmentCollection>(); using (_texts.BulkUpdate()) { foreach (XElement textElem in projectElem.Elements("Texts").Elements("Text")) { var name = (string)textElem.Attribute("name"); var metadataFileName = (string)textElem.Element("MetadataFile"); if (metadataFileName == null) { return(false); } metadataFileName = Path.Combine(configDir, metadataFileName); var srcTextFileName = (string)textElem.Element("SourceFile"); if (srcTextFileName == null) { return(false); } srcTextFileName = Path.Combine(configDir, srcTextFileName); var trgTextFileName = (string)textElem.Element("TargetFile"); if (trgTextFileName == null) { return(false); } trgTextFileName = Path.Combine(configDir, trgTextFileName); var alignmentsFileName = (string)textElem.Element("AlignmentsFile"); if (alignmentsFileName != null) { alignmentsFileName = Path.Combine(configDir, alignmentsFileName); } var text = new TextViewModel(_tokenizer, name, metadataFileName, srcTextFileName, trgTextFileName, alignmentsFileName) { Engine = _hybridEngine }; text.PropertyChanged += TextPropertyChanged; _texts.Add(text); Func <TextSegment, bool> segmentFilter = s => text.IsApproved((TextSegmentRef)s.SegmentRef); sourceTexts.Add(new FilteredText(new TextFileText(_tokenizer, name, srcTextFileName), segmentFilter)); targetTexts.Add(new FilteredText(new TextFileText(_tokenizer, name, trgTextFileName), segmentFilter)); if (alignmentsFileName != null) { alignmentCollections.Add(new TextFileTextAlignmentCollection(name, alignmentsFileName)); } } } if (_texts.Count == 0) { return(false); } _sourceCorpus = new DictionaryTextCorpus(sourceTexts); _targetCorpus = new DictionaryTextCorpus(targetTexts); _alignmentCorpus = new DictionaryTextAlignmentCorpus(alignmentCollections); CurrentText = _texts[0]; AcceptChanges(); RebuildTask.UpdateCanExecute(); return(true); }