本文整理了Java中org.apache.uima.jcas.tcas.Annotation
类的一些代码示例,展示了Annotation
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation
类的具体详情如下:
包路径:org.apache.uima.jcas.tcas.Annotation
类名称:Annotation
[英]the JCas class model for the CAS type uima.cas.Annotation. It defines two integer valued features indicating the begin and end of the span being annotated. There is also a method to retrieve the spanned text as a string.
[中]CAS类型uima的JCas类模型。中科院。注释。它定义了两个整数值特征,指示要注释的范围的开始和结束。还有一种方法可以将跨距文本作为字符串检索。
代码示例来源:origin: org.apache.ctakes/ctakes-dependency-parser
/** Equality expressions to aid in converting between DepNodes and CAS objects */
public static boolean equalCoverage(Annotation annot1,Annotation annot2) {
return annot1.getBegin()==annot2.getBegin() &&
annot1.getEnd()==annot2.getEnd() &&
annot1.getCoveredText()==annot2.getCoveredText();
}
// public static boolean equalCoverage(Annotation annot,UimaDepNode udNode) {
代码示例来源:origin: ClearTK/cleartk
@Override
public Annotation convert(JCas view, TopTreebankNode topNode) {
Annotation annotation = new Annotation(view);
List<Annotation> subAnnotations = new ArrayList<Annotation>();
for (PropbankRelation rel : this.relations) {
subAnnotations.add(rel.convert(view, topNode));
}
// annotation.setAnnotations(UIMAUtil.toFSArray(view, subAnnotations));
int[] span = AnnotationUtil.getAnnotationsExtent(subAnnotations);
annotation.setBegin(span[0]);
annotation.setEnd(span[1]);
annotation.addToIndexes();
return annotation;
}
代码示例来源:origin: apache/ctakes
static private String getDebugText( final Annotation a ) {
return a.getType().getShortName() + "(" + a.getBegin() + "-" + a.getEnd() + "): " + a.getCoveredText();
}
代码示例来源:origin: org.cleartk/cleartk-util
public static int[] getAnnotationsExtent(List<? extends Annotation> annotations) {
int start = Integer.MAX_VALUE;
int end = 0;
for (Annotation annotation : annotations) {
if (annotation.getBegin() < start)
start = annotation.getBegin();
if (annotation.getEnd() > end)
end = annotation.getEnd();
}
return new int[] { start, end };
}
}
代码示例来源:origin: CLLKazan/UIMA-Ext
private static void postprocess(int spanBegin, Annotation anno, int begin, int end) {
anno.setBegin(spanBegin + begin);
anno.setEnd(spanBegin + end);
anno.addToIndexes();
}
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
int e = 0;
for (final Annotation anno : JCasUtil.select(jcas, segmentAnnotationType)) {
final int b = anno.getBegin();
AnnotationFactory.createAnnotation(jcas, b, b, boundaryAnnotationType);
e = anno.getEnd();
}
AnnotationFactory.createAnnotation(jcas, e, e, boundaryAnnotationType);
}
代码示例来源:origin: org.cleartk/cleartk-util
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
if (windowClass != null) {
for (Annotation window : JCasUtil.select(jCas, windowClass)) {
String text = window.getCoveredText();
createParentheticals(jCas, text, window.getBegin());
}
} else {
String text = jCas.getDocumentText();
createParentheticals(jCas, text, 0);
}
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
if (segmentAnnotationClass != null) {
for (final Annotation segAnno : JCasUtil.select(jcas, segmentAnnotationClass)) {
doAnnotations(jcas, JCasUtil.selectCovered(jcas, baseAnnotation, segAnno), segAnno.getEnd());
}
} else {
doAnnotations(jcas, JCasUtil.select(jcas, baseAnnotation), jcas.getDocumentText().length());
}
}
代码示例来源:origin: de.tudarmstadt.ukp.teaching.uima/de.tudarmstadt.ukp.teaching.uima.lesson1
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
DocumentMetaData meta = iterate(aJCas, DocumentMetaData.class).iterator().next();
System.out.println("=== METADATA ========================================");
System.out.println("URI : "+meta.getDocumentUri());
System.out.println("Language: "+aJCas.getDocumentLanguage());
System.out.println("=== TEXT ============================================");
System.out.println(aJCas.getDocumentText());
System.out.println("=== ANNOTATIONS =====================================");
for (Annotation a : iterate(aJCas, Annotation.class)) {
System.out.println(a.getType().getName() + "(" + a.getBegin() + ","
+ a.getEnd() + ") [" + a.getCoveredText() + "]");
}
}
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
int i = 0;
int index = 0;
for (final Annotation anno : JCasUtil.select(jcas, boundaryAnnotationType)) {
if ((index > 0) || beginAndSegment)
AnnotationFactory.createAnnotation(jcas, i, anno.getBegin(), segmentAnnotationType);
i = anno.getBegin();
index++;
}
if (beginAndSegment)
AnnotationFactory.createAnnotation(jcas, i, jcas.getDocumentText().length(), segmentAnnotationType);
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
JCas srcView, tgtView;
try {
srcView = aJCas.getView(sourceViewName);
tgtView = aJCas.getView(targetViewName);
for (Annotation a : JCasUtil.select(srcView, clazz)) {
AnnotationFactory.createAnnotation(tgtView, a.getBegin(), a.getEnd(), clazz);
}
} catch (CASException e) {
throw new AnalysisEngineProcessException(e);
}
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Set<Annotation> toDelete = null;
if (deleteSource) {
toDelete = new HashSet<Annotation>();
}
for (Annotation anno : JCasUtil.select(jcas, sourceClass)) {
Annotation newAnnotation = AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(),
targetClass);
if (deleteSource)
toDelete.add(anno);
if (!(targetFeatureName.isEmpty() || targetFeatureValue.isEmpty())) {
Feature feature = newAnnotation.getType().getFeatureByBaseName(targetFeatureName);
if (feature != null)
newAnnotation.setFeatureValueFromString(feature, targetFeatureValue);
}
}
if (deleteSource) {
for (Annotation a : toDelete) {
a.removeFromIndexes();
}
}
}
代码示例来源:origin: ClearTK/cleartk
public static <T extends Annotation> List<T> selectMatching(
JCas jCas,
Class<T> selectedType,
Annotation annotation) {
List<T> result = new ArrayList<T>();
for (T selected : JCasUtil.selectCovered(jCas, selectedType, annotation)) {
if (selected.getBegin() == annotation.getBegin() && selected.getEnd() == annotation.getEnd()) {
result.add(selected);
}
}
return result;
}
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.api.segmentation-asl
/**
* Trim the offsets of the given annotation to remove leading/trailing whitespace.
* <p>
* <b>Note:</b> use this method if the document text of the CAS has not been set yet but you
* have it available in a buffer.
* <p>
* <b>Note:</b> best use this method before adding the annotation to the indexes.
*
* @param aText
* the document text (available so far).
* @param aAnnotation
* the annotation to trim. Offsets are updated.
*/
public static void trim(CharSequence aText, Annotation aAnnotation)
{
int[] offsets = { aAnnotation.getBegin(), aAnnotation.getEnd() };
trim(aText, offsets);
aAnnotation.setBegin(offsets[0]);
aAnnotation.setEnd(offsets[1]);
}
代码示例来源:origin: de.cit-ec.scie/scie-classifiers
public static double getRelativeDist(Annotation a, Annotation b, JCas jcas) {
final double dist;
if (a.getEnd() < b.getBegin()) {
dist = b.getBegin() - a.getEnd();
} else if (b.getEnd() < a.getBegin()) {
dist = a.getBegin() - b.getEnd();
} else {
dist = 0;
}
return dist / (double) jcas.getDocumentText().length();
}
代码示例来源:origin: org.apache.ctakes/ctakes-coreference
public boolean calcNPHead () {
Annotation a = m1.getContent();
// return (a.getEnd()==m1.getEnd() && a.getBegin()>m1.getBegin()) ? "yes" : "no";
FSIterator iter = jcas.getJFSIndexRepository().getAnnotationIndex(LookupWindowAnnotation.type).iterator();
while (iter.hasNext()) {
LookupWindowAnnotation lwa = (LookupWindowAnnotation) iter.next();
if (lwa.getBegin()<=a.getBegin() && lwa.getEnd()==a.getEnd())
return true;
}
return false;
}
代码示例来源:origin: de.unistuttgart.ims/uimautil
protected <T extends TOP> T getFeatureStructure(JCas jcas, XMLElement hAnno, Element elm, Rule<T> mapping) {
T annotation = null;
if (mapping.isUnique()) {
annotation = getOrCreate(jcas, mapping.getTargetClass());
} else {
annotation = (T) jcas.getCas().createFS(JCasUtil.getType(jcas, mapping.getTargetClass()));
jcas.getCas().addFsToIndexes(annotation);
if (Annotation.class.isAssignableFrom(mapping.getTargetClass())) {
((Annotation) annotation).setBegin(hAnno.getBegin());
((Annotation) annotation).setEnd(hAnno.getEnd());
}
if (elm.hasAttr("xml:id") && !exists(elm.attr("xml:id"))) {
String id = elm.attr("xml:id");
idRegistry.put(id, new AbstractMap.SimpleEntry<Element, FeatureStructure>(elm, annotation));
}
}
return annotation;
}
代码示例来源:origin: CLLKazan/UIMA-Ext
private boolean isWhitespaceBefore(JCas cas, Annotation anno) {
if (anno.getBegin() == 0) {
return true;
}
char charBefore = cas.getDocumentText().charAt(anno.getBegin() - 1);
return Character.isWhitespace(charBefore);
}
代码示例来源:origin: edu.utah.bmi.nlp/nlp-core
private void indexAnnotations(JCas jCas) {
for (Class conceptType : evidenceAnnotationTree.keySet()) {
FSIndex annoIndex = jCas.getAnnotationIndex(conceptType);
Iterator annoIter = annoIndex.iterator();
IntervalST<Annotation> intervalST = new IntervalST<>();
while (annoIter.hasNext()) {
Annotation anno = (Annotation) annoIter.next();
intervalST.put(new Interval1D(anno.getBegin(), anno.getEnd()), anno);
}
evidenceAnnotationTree.put(conceptType, intervalST);
}
}
代码示例来源:origin: apache/ctakes
/**
* Given an annotation, retrieve its last word.
*/
public static String getLastWord(JCas systemView, Annotation annotation) {
List<WordToken> tokens = JCasUtil.selectCovered(systemView, WordToken.class, annotation);
if(tokens.size() == 0) {
return annotation.getCoveredText();
}
WordToken lastToken = tokens.get(tokens.size() - 1);
return lastToken.getCoveredText();
}
内容来源于网络,如有侵权,请联系作者删除!