sergey-tihon / Stanford.NLP.NET

Stanford NLP for .NET
http://sergey-tihon.github.io/Stanford.NLP.NET/
MIT License
598 stars 123 forks source link

Timex not converting to actual time #48

Closed SeanSobey closed 8 years ago

SeanSobey commented 8 years ago

I have the following code:

// Path to the folder with models extracted from `stanford-corenlp-3.6.0-models.jar`
var folderPath = HttpContext.Current.Server.MapPath("~/App_Data/stanford-corenlp-full-2015-12-09");
var modelsFolderPath = Path.Combine(folderPath, "models");

// SUTime configuration
var suTimeFolderPath = Path.Combine(folderPath, "sutime");
var suTimeRules = new[] { "defs.sutime.txt""english.holidays.sutime.txt""english.sutime.txt" }.Select(suTimeRule => Path.Combine(suTimeFolderPath, suTimeRule));

var coreProperties = new Properties();
coreProperties.setProperty("annotators", requestProperties.Annotators);
coreProperties.setProperty("date"DateTime.Parse(requestProperties.Date).ToShortDateString());
// http://stanfordnlp.github.io/CoreNLP/ner.html
coreProperties.setProperty("ner.useSUTime""true");
//http://nlp.stanford.edu/software/sutime.shtml
coreProperties.setProperty("sutime.rules"string.Join(",", suTimeRules));
coreProperties.setProperty("sutime.binders""0");
//coreProperties.setProperty("sutime.markTimeRanges", "true");

// We should change current directory, so StanfordCoreNLP could find all the model files automatically
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(modelsFolderPath);
var pipeline = new StanfordCoreNLP(coreProperties);
Directory.SetCurrentDirectory(curDir);

var props = new Properties();
props.setProperty("sutime.rules"string.Join(",", suTimeRules));
props.setProperty("sutime.binders""0");

pipeline.addAnnotator(new TimeAnnotator("sutime", props));

var decodedValue = HttpUtility.UrlDecode(value);
var annotation = new Annotation(decodedValue);
annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), DateTime.Parse(requestProperties.Date).ToShortDateString());
pipeline.annotate(annotation);

using (var stream = new ByteArrayOutputStream())
{
    using (var printWriter = new PrintWriter(stream))
    {
        pipeline.jsonPrint(annotation, printWriter);
        return Ok(JsonConvert.DeserializeObject(stream.toString()));
    }
}

Call with the following properies: { "annotators": "tokenize,ssplit,pos,parse,depparse,lemma,ner", "date": "2016-07-30T20:13:22.157Z" }

And tokens like so: "tokens": [ { "index": 1, "word": "now", "originalText": "now", "lemma": "now", "characterOffsetBegin": 0, "characterOffsetEnd": 3, "pos": "RB", "ner": "DATE", "normalizedNER": "PRESENT_REF", "before": "", "after": "", "timex": { "tid": "t1", "type": "DATE", "value": "PRESENT_REF" } } ]

With text: Now

Why is 'PRESENT_REF' not converted to the actual time?

Thanks to anyone for any assistance!

sergey-tihon commented 8 years ago

@R2dical I really recommend to repeat the question on SO - http://stackoverflow.com/questions/tagged/stanford-nlp

This project is for recompiling *.jars to *.dlls, and all questions like "How to write in C# the following Java code".

Sorry, I do not know answers on all Stanford.NLP question like "Why it works so".