private Properties GetTimeAnnotatorProperties(IHttpServletRequest request) { // Parses request and set up properties for time annotators bool markTimeRanges = ParseBoolean(request.GetParameter("markTimeRanges")); bool includeNested = ParseBoolean(request.GetParameter("includeNested")); bool includeRange = ParseBoolean(request.GetParameter("includeRange")); bool readRules = true; string heuristicLevel = request.GetParameter("relativeHeuristicLevel"); Options.RelativeHeuristicLevel relativeHeuristicLevel = Options.RelativeHeuristicLevel.None; if (!StringUtils.IsNullOrEmpty(heuristicLevel)) { relativeHeuristicLevel = Options.RelativeHeuristicLevel.ValueOf(heuristicLevel); } string ruleFile = null; if (readRules) { string rules = request.GetParameter("rules"); if (Sharpen.Runtime.EqualsIgnoreCase("English", rules)) { ruleFile = GetRuleFilepaths("defs.sutime.txt", "english.sutime.txt", "english.holidays.sutime.txt"); } } // Create properties Properties props = new Properties(); if (markTimeRanges) { props.SetProperty("sutime.markTimeRanges", "true"); } if (includeNested) { props.SetProperty("sutime.includeNested", "true"); } if (includeRange) { props.SetProperty("sutime.includeRange", "true"); } if (ruleFile != null) { props.SetProperty("sutime.rules", ruleFile); props.SetProperty("sutime.binders", "1"); props.SetProperty("sutime.binder.1", "edu.stanford.nlp.time.JollyDayHolidays"); props.SetProperty("sutime.binder.1.xml", GetServletContext().GetRealPath("/WEB-INF/data/holidays/Holidays_sutime.xml")); props.SetProperty("sutime.binder.1.pathtype", "file"); } props.SetProperty("sutime.teRelHeurLevel", relativeHeuristicLevel.ToString()); // props.setProperty("sutime.verbose", "true"); // props.setProperty("heideltime.path", getServletContext().getRealPath("/packages/heideltime")); // props.setProperty("gutime.path", getServletContext().getRealPath("/packages/gutime")); return(props); }
public Options(string name, Properties props) { includeRange = PropertiesUtils.GetBool(props, name + ".includeRange", includeRange); markTimeRanges = PropertiesUtils.GetBool(props, name + ".markTimeRanges", markTimeRanges); includeNested = PropertiesUtils.GetBool(props, name + ".includeNested", includeNested); restrictToTimex3 = PropertiesUtils.GetBool(props, name + ".restrictToTimex3", restrictToTimex3); teRelHeurLevel = Options.RelativeHeuristicLevel.ValueOf(props.GetProperty(name + ".teRelHeurLevel", teRelHeurLevel.ToString())); verbose = PropertiesUtils.GetBool(props, name + ".verbose", verbose); // set default rules by SUTime language language = props.GetProperty(name + ".language", language); if (!languageToRulesFiles.Keys.Contains(language)) { language = "english"; } grammarFilename = languageToRulesFiles[language]; // override if rules are set by properties grammarFilename = props.GetProperty(name + ".rules", grammarFilename); searchForDocDate = PropertiesUtils.GetBool(props, name + ".searchForDocDate", searchForDocDate); string binderProperty = props.GetProperty(name + ".binders"); int nBinders; string[] binderClasses; if (binderProperty == null) { nBinders = DefaultBinders.Length; binderClasses = DefaultBinders; } else { nBinders = PropertiesUtils.GetInt(props, name + ".binders", 0); binderClasses = new string[nBinders]; for (int i = 0; i < nBinders; ++i) { string binderPrefix = name + ".binder." + (i + 1); binderClasses[i] = props.GetProperty(binderPrefix); } } if (nBinders > 0 && Runtime.GetProperty("STS") == null) { binders = new Env.IBinder[nBinders]; for (int i = 0; i < nBinders; i++) { int bi = i + 1; string binderPrefix = name + ".binder." + bi; try { Type binderClass = Sharpen.Runtime.GetType(binderClasses[i]); binderPrefix = binderPrefix + "."; binders[i] = (Env.IBinder)System.Activator.CreateInstance(binderClass); binders[i].Init(binderPrefix, props); } catch (Exception ex) { throw new Exception("Error initializing binder " + bi, ex); } } } }