protected override void AnnotateCorpus( Corpus corpus, System.Threading.CancellationToken token) { token.ThrowIfCancellationRequested(); Guid taskId = Guid.NewGuid(); DirectoryInfo dir = new DirectoryInfo( AppDomain.CurrentDomain.BaseDirectory); dir = dir.CreateSubdirectory("Tasks"); dir = dir.CreateSubdirectory(taskId.ToString()); string dataFile = dir.FullName + "\\Corpus.crfppdata"; string outputFile = dir.FullName + "\\Output.crfppdata"; try { AnnotationProgressChangedEventArgs ePrepared = new AnnotationProgressChangedEventArgs( 1, 3, MessagePreparing); OnAnnotationProgressChanged(ePrepared); CRFPPHelper.EncodeCorpusToCRFPPData(corpus, dataFile); token.ThrowIfCancellationRequested(); AnnotationProgressChangedEventArgs eAnnotating = new AnnotationProgressChangedEventArgs( 2, 3, MessageAnnotating); OnAnnotationProgressChanged(eAnnotating); CRFPPHelper.Annotate( Model.RootPath, dataFile, outputFile, 1, 0); token.ThrowIfCancellationRequested(); AnnotationProgressChangedEventArgs eFinishing = new AnnotationProgressChangedEventArgs( 3, 3, MessageFinishing); OnAnnotationProgressChanged(eFinishing); CRFPPHelper.DecodeCorpusFromCRFPPData(corpus, outputFile); token.ThrowIfCancellationRequested(); } catch { throw; } finally { File.Delete(dataFile); File.Delete(outputFile); try { dir.Delete(); } catch { } } }
/// <summary> /// 在异步标注操作进度更新时调用该方法以引发AnnotationProgressChanged事件。 /// </summary> /// <param name="e">事件数据</param> protected virtual void OnAnnotationProgressChanged( AnnotationProgressChangedEventArgs e) { e.Raise(this, ref AnnotationProgressChanged); }