/// <summary>Register an Annotator that can be created by the pool.</summary> /// <remarks> /// Register an Annotator that can be created by the pool. /// Note that factories are used here so that many possible annotators can /// be defined within the AnnotatorPool, but an Annotator is only created /// when one is actually needed. /// </remarks> /// <param name="name">The name to be associated with the Annotator.</param> /// <param name="props">The properties we are using to create the annotator</param> /// <param name="annotator"> /// A factory that creates an instance of the desired Annotator. /// This should be an instance of /// <see cref="Edu.Stanford.Nlp.Util.Lazy{E}.Cache{E}(Java.Util.Function.ISupplier{T})"/> /// , if we want /// the annotator pool to behave as a cache (i.e., evict old annotators /// when the GC requires it). /// </param> /// <returns>true if a new annotator was created; false if we reuse an existing one</returns> public virtual bool Register(string name, Properties props, Lazy <IAnnotator> annotator) { bool newAnnotator = false; string newSig = PropertiesUtils.GetSignature(name, props); lock (this.cachedAnnotators) { AnnotatorPool.CachedAnnotator oldAnnotator = this.cachedAnnotators[name]; if (oldAnnotator == null || !Objects.Equals(oldAnnotator.signature, newSig)) { // the new annotator uses different properties so we need to update! if (oldAnnotator != null) { // Try to get it from the global cache log.Debug("Replacing old annotator \"" + name + "\" with signature [" + oldAnnotator.signature + "] with new annotator with signature [" + newSig + "]"); } // Add the new annotator this.cachedAnnotators[name] = new AnnotatorPool.CachedAnnotator(newSig, annotator); // Unmount the old annotator Optional.OfNullable(oldAnnotator).FlatMap(null).IfPresent(null); // Register that we added an annotator newAnnotator = true; } } // nothing to do if an annotator with same name and signature already exists return(newAnnotator); }
private void ResolveTimeExpression(ICoreMap annotation, TimeExpression te, SUTime.Time docDate) { SUTime.Temporal temporal = te.GetTemporal(); if (temporal != null) { // TODO: use correct time for anchor try { int flags = timexPatterns.DetermineRelFlags(annotation, te); //int flags = 0; SUTime.Temporal grounded = temporal.Resolve(docDate, flags); if (grounded == null) { logger.Debug("Error resolving " + temporal + ", using docDate=" + docDate); } if (grounded != temporal) { te.origTemporal = temporal; te.SetTemporal(grounded); } } catch (Exception ex) { if (options.verbose) { logger.Warn("Error resolving " + temporal, ex); logger.Warn(ex); } } } }
/// <summary>Add specified rules to this extractor.</summary> /// <param name="rules"/> public virtual void AppendRules(IList <SequenceMatchRules.IRule> rules) { if (verbose) { log.Info("Read " + rules.Count + " rules"); } // Put rules into stages if (collapseExtractionRules) { rules = Collapse(rules); if (verbose) { log.Info("Collapsing into " + rules.Count + " rules"); } } foreach (SequenceMatchRules.IRule r in rules) { if (r is SequenceMatchRules.AssignmentRule) { // Nothing to do // Assignments are added to environment as they are parsed ((SequenceMatchRules.AssignmentRule)r).Evaluate(env); } else { if (r is SequenceMatchRules.AnnotationExtractRule) { SequenceMatchRules.AnnotationExtractRule aer = (SequenceMatchRules.AnnotationExtractRule)r; CoreMapExpressionExtractor.Stage <T> stage = stages[aer.stage]; if (stage == null) { stages[aer.stage] = stage = new CoreMapExpressionExtractor.Stage <T>(); stage.stageId = aer.stage; bool clearMatched = (bool)env.GetDefaults()["stage.clearMatched"]; if (clearMatched != null) { stage.clearMatched = clearMatched; } int limitIters = (int)env.GetDefaults()["stage.limitIters"]; if (limitIters != null) { stage.limitIters = limitIters; } } if (aer.active) { if (SequenceMatchRules.FilterRuleType.Equals(aer.ruleType)) { stage.AddFilterRule(aer); } else { if (aer.isComposite) { // if (SequenceMatchRules.COMPOSITE_RULE_TYPE.equals(aer.ruleType)) { stage.AddCompositeRule(aer); } else { stage.AddBasicRule(aer); } } } else { log.Debug("Ignoring inactive rule: " + aer.name); } } } } }