protected internal virtual bool ExtractAnnotation <_T0>(IList <_T0> source, CoreMapAggregator aggregator) where _T0 : ICoreMap { annotation = aggregator.Merge(source, chunkOffsets.GetBegin(), chunkOffsets.GetEnd()); charOffsets = Interval.ToInterval(annotation.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)), annotation.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation)), Interval.IntervalOpenEnd); tokenOffsets = Interval.ToInterval(annotation.Get(typeof(CoreAnnotations.TokenBeginAnnotation)), annotation.Get(typeof(CoreAnnotations.TokenEndAnnotation)), Interval.IntervalOpenEnd); text = annotation.Get(typeof(CoreAnnotations.TextAnnotation)); extractFunc.Annotate(this, source.SubList(chunkOffsets.GetBegin(), chunkOffsets.GetEnd())); return(true); }
public static CoreMapAggregator GetDefaultTokensAggregator(Env env) { if (env != null) { CoreMapAggregator obj = env.GetDefaultTokensAggregator(); if (obj != null) { return(obj); } } return(CoreMapAggregator.DefaultNumericTokensAggregator); }
public virtual CoreMapAggregator GetDefaultTokensAggregator() { if (defaultTokensAggregator == null && (defaultTokensAggregators != null || aggregateToTokens)) { CoreLabelTokenFactory tokenFactory = (aggregateToTokens) ? new CoreLabelTokenFactory() : null; IDictionary <Type, CoreMapAttributeAggregator> aggregators = defaultTokensAggregators; if (aggregators == null) { aggregators = CoreMapAttributeAggregator.DefaultNumericTokensAggregators; } defaultTokensAggregator = CoreMapAggregator.GetAggregator(aggregators, null, tokenFactory); } return(defaultTokensAggregator); }
private ICoreMap CreateMergedChunk(int groupStart, int groupEnd) { ICoreMap merged = null; /* if (annotation != null) { * // Take start and end * merged = ChunkAnnotationUtils.getMergedChunk(elements, annotation.get(CoreAnnotations.TextAnnotation.class), groupStart, groupEnd); * } */ if (merged == null) { // Okay, have to go through these one by one and merge them merged = CoreMapAggregator.GetDefaultAggregator().Merge(elements, groupStart, groupEnd); } return(merged); }
private bool ExtractAnnotation(ICoreMap sourceAnnotation, CoreMapAggregator aggregator) { Type tokensAnnotationKey = extractFunc.tokensAnnotationField; if (chunkOffsets != null) { annotation = aggregator.Merge((IList <ICoreMap>)sourceAnnotation.Get(tokensAnnotationKey), chunkOffsets.GetBegin(), chunkOffsets.GetEnd()); if (sourceAnnotation.ContainsKey(typeof(CoreAnnotations.TextAnnotation))) { ChunkAnnotationUtils.AnnotateChunkText(annotation, sourceAnnotation); } if (tokenOffsets != null) { if (annotation.Get(typeof(CoreAnnotations.TokenBeginAnnotation)) == null) { annotation.Set(typeof(CoreAnnotations.TokenBeginAnnotation), tokenOffsets.GetBegin()); } if (annotation.Get(typeof(CoreAnnotations.TokenEndAnnotation)) == null) { annotation.Set(typeof(CoreAnnotations.TokenEndAnnotation), tokenOffsets.GetEnd()); } } charOffsets = Interval.ToInterval(annotation.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)), annotation.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation))); tokenOffsets = Interval.ToInterval(annotation.Get(typeof(CoreAnnotations.TokenBeginAnnotation)), annotation.Get(typeof(CoreAnnotations.TokenEndAnnotation)), Interval.IntervalOpenEnd); } else { int baseCharOffset = sourceAnnotation.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)); if (baseCharOffset == null) { baseCharOffset = 0; } chunkOffsets = ChunkAnnotationUtils.GetChunkOffsetsUsingCharOffsets((IList <ICoreMap>)sourceAnnotation.Get(tokensAnnotationKey), charOffsets.GetBegin() + baseCharOffset, charOffsets.GetEnd() + baseCharOffset); ICoreMap annotation2 = aggregator.Merge((IList <ICoreMap>)sourceAnnotation.Get(tokensAnnotationKey), chunkOffsets.GetBegin(), chunkOffsets.GetEnd()); annotation = ChunkAnnotationUtils.GetAnnotatedChunkUsingCharOffsets(sourceAnnotation, charOffsets.GetBegin(), charOffsets.GetEnd()); tokenOffsets = Interval.ToInterval(annotation.Get(typeof(CoreAnnotations.TokenBeginAnnotation)), annotation.Get(typeof(CoreAnnotations.TokenEndAnnotation)), Interval.IntervalOpenEnd); annotation.Set(tokensAnnotationKey, annotation2.Get(tokensAnnotationKey)); } text = annotation.Get(typeof(CoreAnnotations.TextAnnotation)); extractFunc.Annotate(this, (IList <ICoreMap>)annotation.Get(tokensAnnotationKey)); return(true); }
public virtual bool ExtractAnnotation <_T0>(Env env, IList <_T0> source) where _T0 : ICoreMap { return(ExtractAnnotation(source, CoreMapAggregator.GetDefaultAggregator())); }
public MergeAction(CoreMapAggregator aggregator) { this.aggregator = aggregator; }