public ParallelTextCorpus(ITextCorpus sourceCorpus, ITextCorpus targetCorpus, ITextAlignmentCorpus textAlignmentCorpus = null, IComparer <object> segmentRefComparer = null) { SourceCorpus = sourceCorpus; TargetCorpus = targetCorpus; TextAlignmentCorpus = textAlignmentCorpus; _segmentRefComparer = segmentRefComparer; }
private void CloseProject() { CurrentText = null; _texts.Clear(); CurrentText = new TextViewModel(_tokenizer); _sourceCorpus = null; _targetCorpus = null; if (_hybridEngine != null) { _hybridEngine.Dispose(); _hybridEngine = null; } if (_smtModel != null) { _smtModel.Dispose(); _smtModel = null; } _saveProjectCommand.UpdateCanExecute(); RebuildTask.UpdateCanExecute(); }
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); }
public FilteredTextCorpus(ITextCorpus corpus, Func <IText, bool> filter) { _corpus = corpus; _filter = filter; }
public ISmtBatchTrainer CreateBatchTrainer(Func <string, string> sourcePreprocessor, ITextCorpus sourceCorpus, Func <string, string> targetPreprocessor, ITextCorpus targetCorpus, ITextAlignmentCorpus alignmentCorpus = null) { CheckDisposed(); var corpus = new ParallelTextCorpus(sourceCorpus, targetCorpus, alignmentCorpus); return(string.IsNullOrEmpty(ConfigFileName) ? new BatchTrainer(this, Parameters, sourcePreprocessor, targetPreprocessor, corpus) : new BatchTrainer(this, ConfigFileName, sourcePreprocessor, targetPreprocessor, corpus)); }