本文整理汇总了C#中Annotation.set方法的典型用法代码示例。如果您正苦于以下问题:C# Annotation.set方法的具体用法?C# Annotation.set怎么用?C# Annotation.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Annotation
的用法示例。
在下文中一共展示了Annotation.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
// Path to the folder with models extracted from `stanford-corenlp-3.6.0-models.jar`
var jarRoot = @"..\..\..\..\paket-files\nlp.stanford.edu\stanford-corenlp-full-2015-12-09\models";
var modelsDirectory = jarRoot + @"\edu\stanford\nlp\models";
// Annotation pipeline configuration
var pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new TokenizerAnnotator(false));
pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
// Loading POS Tagger and including them into pipeline
var tagger = new MaxentTagger(modelsDirectory +
@"\pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger");
pipeline.addAnnotator(new POSTaggerAnnotator(tagger));
// SUTime configuration
var sutimeRules = modelsDirectory + @"\sutime\defs.sutime.txt,"
+ modelsDirectory + @"\sutime\english.holidays.sutime.txt,"
+ modelsDirectory + @"\sutime\english.sutime.txt";
var props = new Properties();
props.setProperty("sutime.rules", sutimeRules);
props.setProperty("sutime.binders", "0");
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
// Sample text for time expression extraction
var text = "Three interesting dates are 18 Feb 1997, the 20th of july and 4 days from today.";
var annotation = new Annotation(text);
annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), "2013-07-14");
pipeline.annotate(annotation);
Console.WriteLine("{0}\n", annotation.get(new CoreAnnotations.TextAnnotation().getClass()));
var timexAnnsAll = annotation.get(new TimeAnnotations.TimexAnnotations().getClass()) as ArrayList;
foreach (CoreMap cm in timexAnnsAll)
{
var tokens = cm.get(new CoreAnnotations.TokensAnnotation().getClass()) as List;
var first = tokens.get(0);
var last = tokens.get(tokens.size() - 1);
var time = cm.get(new TimeExpression.Annotation().getClass()) as TimeExpression;
Console.WriteLine("{0} [from char offset {1} to {2}] --> {3}", cm, first, last, time.getTemporal());
}
}
示例2: PrepareAnnotation
private Annotation PrepareAnnotation(string text, DateTime currentDate)
{
var pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new TokenizerAnnotator(false));
pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
var tagger = new MaxentTagger(modelsDir + @"pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger");
pipeline.addAnnotator(new POSTaggerAnnotator(tagger));
var sutimeRules = modelsDir + @"\sutime\defs.sutime.txt,"
+ modelsDir + @"\sutime\english.holidays.sutime.txt,"
+ modelsDir + @"\sutime\english.sutime.txt";
var props = new Properties();
props.setProperty("sutime.rules", sutimeRules);
props.setProperty("sutime.binders", "0");
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
var annotation = new Annotation(text);
annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), currentDate.ToString("yyyy-MM-dd"));
pipeline.annotate(annotation);
return annotation;
}
示例3: SUTimeDefautTest
public void SUTimeDefautTest()
{
var pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new PTBTokenizerAnnotator(false));
pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
var tagger =
new MaxentTagger(
Config.GetModel(@"pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger"));
pipeline.addAnnotator(new POSTaggerAnnotator(tagger));
var sutimeRules = new[] {
Config.GetModel(@"sutime\defs.sutime.txt"),
Config.GetModel(@"sutime\english.holidays.sutime.txt"),
Config.GetModel(@"sutime\english.sutime.txt")
};
var props = new Properties();
props.setProperty("sutime.rules", String.Join(",", sutimeRules));
props.setProperty("sutime.binders", "0");
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
const string text = "Three interesting dates are 18 Feb 1997, the 20th of july and 4 days from today.";
var annotation = new Annotation(text);
annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), "2013-07-14");
pipeline.annotate(annotation);
Console.WriteLine(annotation.get(new CoreAnnotations.TextAnnotation().getClass())+"\n");
var timexAnnsAll = (ArrayList)annotation.get(new TimeAnnotations.TimexAnnotations().getClass());
foreach (CoreMap cm in timexAnnsAll)
{
var tokens = (java.util.List)cm.get(new CoreAnnotations.TokensAnnotation().getClass());
var first = tokens.get(0);
var last = tokens.get(tokens.size() - 1);
var time = (TimeExpression)cm.get(new TimeExpression.Annotation().getClass());
Console.WriteLine("{0} [from char offset '{1}' to '{2}'] --> {3}",
cm, first, last, (time.getTemporal()));
}
}
示例4: extractTime
public void extractTime(string text)
{
sentenceInput = text;
string presentDate = "2015-10-10";
string curr = Environment.CurrentDirectory;
var jarRoot = curr + @"\stanford-corenlp-3.5.2-models";
var modelsDirectory = jarRoot + @"\edu\stanford\nlp\models";
// Annotation pipeline configuration
var pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new TokenizerAnnotator(false));
pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
// SUTime configuration
var sutimeRules = modelsDirectory + @"\sutime\defs.sutime.txt,"
+ modelsDirectory + @"\sutime\english.holidays.sutime.txt,"
+ modelsDirectory + @"\sutime\english.sutime.txt";
var props = new Properties();
props.setProperty("sutime.rules", sutimeRules);
props.setProperty("sutime.binders", "0");
props.setProperty("sutime.markTimeRanges", "true");
props.setProperty("sutime.includeRange", "true");
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
// Sample text for time expression extraction
var annotation = new Annotation(text);
annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), presentDate);
pipeline.annotate(annotation);
// Console.WriteLine("{0}\n", annotation.get(new CoreAnnotations.TextAnnotation().getClass()));
var timexAnnsAll = annotation.get(new TimeAnnotations.TimexAnnotations().getClass()) as ArrayList;
foreach (CoreMap cm in timexAnnsAll)
{
var time = cm.get(new TimeExpression.Annotation().getClass()) as TimeExpression;
string typeTimex = time.getTemporal().getTimexType().toString();
if (typeTimex.ToLower() == "duration")
{
typeTime = "tPeriod";
valueTime = time.getTemporal().toISOString();
Console.WriteLine(valueTime);
}
if (typeTimex.ToLower() == "time" || typeTimex.ToLower() == "date")
{
string textOftime = time.getText().ToString();
char[] delimiterChars = { ' ' };
string[] words = textOftime.Split(delimiterChars);
string mainword = words[0];
var tagger = new MaxentTagger(modelsDirectory + @"\pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger");
var sentences = MaxentTagger.tokenizeText(new StringReader(text));
var first = sentences.get(0) as ArrayList;
int size = first.size();
int i = 0;
int index = -3;
while (i < size)
{
if (first.get(i).ToString() == mainword)
index = i;
i++;
}
var taggedSentence = tagger.tagSentence(first);
string checker = taggedSentence.get(index - 1).ToString();
if (checker.ToLower() == "after/in" || checker.ToLower() == "since/in")
{
typeTime = "tTrigger";
valueTime = "Start : " + time.getTemporal().toISOString();
Console.WriteLine(valueTime);
}
else if (checker.ToLower() == "before/in")
{
if (typeTimex == "TIME")
{
typeTime = "tTrigger";
valueTime = "End : " + time.getTemporal().toISOString();
Console.WriteLine(valueTime);
}
else
{
DateTime result = new DateTime();
DateTime current = DateTime.ParseExact(presentDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
string dt = time.getTemporal().toString();
char[] delimiter = { '-', '-', '-' };
string[] partsOfDate = time.getTemporal().toISOString().Split(delimiter);
//.........这里部分代码省略.........