edu.isi.nlp.strings.offsets.AnnotatedOffsetRange Maven / Gradle / Ivy
The newest version!
package edu.isi.nlp.strings.offsets;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import edu.isi.nlp.symbols.Symbol;
import java.util.Map;
public final class AnnotatedOffsetRange> {
private final OffsetRange range;
private final Symbol type;
private final ImmutableMap attributes;
public OffsetRange range() {
return range;
}
public Symbol type() {
return type;
}
public Map attributes() {
return attributes;
}
public static > AnnotatedOffsetRange create(
final Symbol spanType,
final OffsetRange range,
final Map otherAttributes) {
return new AnnotatedOffsetRange(spanType, range, otherAttributes);
}
public static > AnnotatedOffsetRange create(
final Symbol spanType, final OffsetRange range) {
return create(spanType, range, ImmutableMap.of());
}
private AnnotatedOffsetRange(
final Symbol spanType,
final OffsetRange range,
final Map otherAttributes) {
this.range = checkNotNull(range);
this.type = checkNotNull(spanType);
this.attributes = ImmutableMap.copyOf(otherAttributes);
}
public static >
Function, OffsetRange> toOffsetRangeFunction() {
return new Function, OffsetRange>() {
@Override
public OffsetRange apply(AnnotatedOffsetRange input) {
return input.range();
}
};
}
@Override
public String toString() {
final String attributesString = attributes().isEmpty() ? "" : (" " + attributes().toString());
return "[" + type.toString() + ": " + range().toString() + attributesString + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy