private static void AnnotateFactories(IAnnotator annotator) { annotator.Annotate <LogManager>(type => { type.Annotate(_ => LogManager.CreateNullLogger() == NotNull <ILogger>()); type.Annotate(_ => LogManager.GetCurrentClassLogger() == NotNull <ILogger>()); type.Annotate(_ => LogManager.GetCurrentClassLogger(CanBeNull <Type>()) == NotNull <ILogger>()); type.Annotate(_ => LogManager.GetLogger(NotNull <string>()) == NotNull <ILogger>()); type.Annotate(_ => LogManager.GetLogger(NotNull <string>(), CanBeNull <Type>()) == NotNull <ILogger>()); type.Annotate(_ => LogManager.DefaultCultureInfo == NotNull <LogManager.GetCultureInfo>()); type.Annotate(_ => LogManager.Configuration == CanBeNull <LoggingConfiguration>()); type.Annotate(_ => LogManager.DisableLogging() == NotNull <IDisposable>()); type.Annotate(_ => LogManager.AddHiddenAssembly(NotNull <Assembly>())); type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>())); type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>(), Some <TimeSpan>())); type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>(), Some <int>())); }); annotator.Annotate <LogFactory>(type => { type.Annotate(x => x.CreateNullLogger() == NotNull <ILogger>()); type.Annotate(x => x.GetCurrentClassLogger() == NotNull <ILogger>()); type.Annotate(x => x.GetCurrentClassLogger(CanBeNull <Type>()) == NotNull <ILogger>()); type.Annotate(x => x.GetLogger(NotNull <string>()) == NotNull <ILogger>()); type.Annotate(x => x.GetLogger(NotNull <string>(), CanBeNull <Type>()) == NotNull <ILogger>()); type.Annotate(x => x.DefaultCultureInfo == CanBeNull <CultureInfo>()); type.Annotate(x => x.Configuration == CanBeNull <LoggingConfiguration>()); type.Annotate(x => x.DisableLogging() == NotNull <IDisposable>()); type.Annotate(x => x.SuspendLogging() == NotNull <IDisposable>()); type.Annotate(x => x.Flush(NotNull <AsyncContinuation>())); type.Annotate(x => x.Flush(NotNull <AsyncContinuation>(), Some <TimeSpan>())); type.Annotate(x => x.Flush(NotNull <AsyncContinuation>(), Some <int>())); }); }
public virtual void TestExclamationPoint() { Annotation annotation = new Annotation("Foo!!"); ptb.Annotate(annotation); IList list = annotation.Get(typeof(CoreAnnotations.TokensAnnotation)); NUnit.Framework.Assert.AreEqual("Wrong double bang", "[Foo, !!]", list.ToString()); }
private static void AnnotateLogger(IAnnotator annotator) { annotator.Annotate <ILogger>(type => { AnnotateFatal(type); AnnotateError(type); AnnotateWarn(type); AnnotateInfo(type); AnnotateDebug(type); AnnotateTrace(type); }); }
public virtual Annotation Process(string sentence, string dateString, IAnnotator timeAnnotator) { log.Info("Processing text \"" + sentence + "\" with dateString = " + dateString); Annotation anno = new Annotation(sentence); if (dateString != null && !dateString.IsEmpty()) { anno.Set(typeof(CoreAnnotations.DocDateAnnotation), dateString); } pipeline.Annotate(anno); timeAnnotator.Annotate(anno); return(anno); }
public static Annotation Annotate(string text, IAnnotator tokenizer, IAnnotator xmlRemover, IAnnotator splitter) { Annotation annotation = new Annotation(text); tokenizer.Annotate(annotation); if (xmlRemover != null) { xmlRemover.Annotate(annotation); } if (splitter != null) { splitter.Annotate(annotation); } return(annotation); }
/// <summary> /// Does the actual work of splitting TextAnnotation into CoreLabels, /// which are then attached to the TokensAnnotation. /// </summary> public virtual void Annotate(Annotation annotation) { if (Verbose) { log.Info("Tokenizing ... "); } // for Arabic and Chinese use a segmenter instead if (useSegmenter) { segmenterAnnotator.Annotate(annotation); // set indexes into document wide tokens list SetTokenBeginTokenEnd(annotation.Get(typeof(CoreAnnotations.TokensAnnotation))); SetNewlineStatus(annotation.Get(typeof(CoreAnnotations.TokensAnnotation))); return; } if (annotation.ContainsKey(typeof(CoreAnnotations.TextAnnotation))) { string text = annotation.Get(typeof(CoreAnnotations.TextAnnotation)); Reader r = new StringReader(text); // don't wrap in BufferedReader. It gives you nothing for in-memory String unless you need the readLine() method! IList <CoreLabel> tokens = GetTokenizer(r).Tokenize(); // cdm 2010-05-15: This is now unnecessary, as it is done in CoreLabelTokenFactory // for (CoreLabel token: tokens) { // token.set(CoreAnnotations.TextAnnotation.class, token.get(CoreAnnotations.TextAnnotation.class)); // } // label newlines SetNewlineStatus(tokens); // set indexes into document wide token list SetTokenBeginTokenEnd(tokens); // add tokens list to annotation annotation.Set(typeof(CoreAnnotations.TokensAnnotation), tokens); if (Verbose) { log.Info("done."); log.Info("Tokens: " + annotation.Get(typeof(CoreAnnotations.TokensAnnotation))); } } else { throw new Exception("Tokenizer unable to find text in annotation: " + annotation); } }
private static void CheckResult(WordToSentenceProcessor <CoreLabel> wts, IAnnotator tokenizer, string testSentence, params string[] gold) { Annotation annotation = new Annotation(testSentence); ptbNL.Annotate(annotation); IList <CoreLabel> tokens = annotation.Get(typeof(CoreAnnotations.TokensAnnotation)); IList <IList <CoreLabel> > sentences = wts.Process(tokens); NUnit.Framework.Assert.AreEqual("Output number of sentences didn't match:\n" + Arrays.ToString(gold) + " vs. \n" + sentences + '\n', gold.Length, sentences.Count); Annotation[] goldAnnotations = new Annotation[gold.Length]; for (int i = 0; i < gold.Length; ++i) { goldAnnotations[i] = new Annotation(gold[i]); tokenizer.Annotate(goldAnnotations[i]); IList <CoreLabel> goldTokens = goldAnnotations[i].Get(typeof(CoreAnnotations.TokensAnnotation)); IList <CoreLabel> testTokens = sentences[i]; int goldTokensSize = goldTokens.Count; NUnit.Framework.Assert.AreEqual("Sentence lengths didn't match:\n" + goldTokens + " vs. \n" + testTokens + '\n', goldTokensSize, testTokens.Count); for (int j = 0; j < goldTokensSize; ++j) { NUnit.Framework.Assert.AreEqual(goldTokens[j].Word(), testTokens[j].Word()); } } }
private static void AnnotateFactories(IAnnotator annotator) { annotator.Annotate<LogManager>(type => { type.Annotate(_ => LogManager.CreateNullLogger() == NotNull<ILogger>()); type.Annotate(_ => LogManager.GetCurrentClassLogger() == NotNull<ILogger>()); type.Annotate(_ => LogManager.GetCurrentClassLogger(CanBeNull<Type>()) == NotNull<ILogger>()); type.Annotate(_ => LogManager.GetLogger(NotNull<string>()) == NotNull<ILogger>()); type.Annotate(_ => LogManager.GetLogger(NotNull<string>(), CanBeNull<Type>()) == NotNull<ILogger>()); type.Annotate(_ => LogManager.DefaultCultureInfo == NotNull<LogManager.GetCultureInfo>()); type.Annotate(_ => LogManager.Configuration == CanBeNull<LoggingConfiguration>()); type.Annotate(_ => LogManager.DisableLogging() == NotNull<IDisposable>()); type.Annotate(_ => LogManager.AddHiddenAssembly(NotNull<Assembly>())); type.Annotate(_ => LogManager.Flush(NotNull<AsyncContinuation>())); type.Annotate(_ => LogManager.Flush(NotNull<AsyncContinuation>(), Some<TimeSpan>())); type.Annotate(_ => LogManager.Flush(NotNull<AsyncContinuation>(), Some<int>())); }); annotator.Annotate<LogFactory>(type => { type.Annotate(x => x.CreateNullLogger() == NotNull<ILogger>()); type.Annotate(x => x.GetCurrentClassLogger() == NotNull<ILogger>()); type.Annotate(x => x.GetCurrentClassLogger(CanBeNull<Type>()) == NotNull<ILogger>()); type.Annotate(x => x.GetLogger(NotNull<string>()) == NotNull<ILogger>()); type.Annotate(x => x.GetLogger(NotNull<string>(), CanBeNull<Type>()) == NotNull<ILogger>()); type.Annotate(x => x.DefaultCultureInfo == CanBeNull<CultureInfo>()); type.Annotate(x => x.Configuration == CanBeNull<LoggingConfiguration>()); type.Annotate(x => x.DisableLogging() == NotNull<IDisposable>()); type.Annotate(x => x.SuspendLogging() == NotNull<IDisposable>()); type.Annotate(x => x.Flush(NotNull<AsyncContinuation>())); type.Annotate(x => x.Flush(NotNull<AsyncContinuation>(), Some<TimeSpan>())); type.Annotate(x => x.Flush(NotNull<AsyncContinuation>(), Some<int>())); }); }
private static void AnnotateLogger(IAnnotator annotator) { annotator.Annotate<ILogger>(type => { AnnotateFatal(type); AnnotateError(type); AnnotateWarn(type); AnnotateInfo(type); AnnotateDebug(type); AnnotateTrace(type); }); }