productannotator.java
来自「为了对数据进行处理」· Java 代码 · 共 47 行
JAVA
47 行
package com.backstopmedia.uima.tutorial;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.ibm.uima.analysis_engine.ResultSpecification;
import com.ibm.uima.analysis_engine.annotator.AnnotatorProcessException;
import com.ibm.uima.analysis_engine.annotator.JTextAnnotator_ImplBase;
import com.ibm.uima.jcas.impl.JCas;
public class ProductAnnotator extends JTextAnnotator_ImplBase {
public void process(JCas aJCas, ResultSpecification aResultSpec)
throws AnnotatorProcessException {
String txt = aJCas.getDocumentText();
Pattern UniverseProductNumbers = Pattern.compile("\\b[U][A-Z][A-Z]-\\d\\d\\d\\d\\d\\b");
Matcher matcher = UniverseProductNumbers.matcher(txt);
int pos = 0;
while (matcher.find(pos)) {
ProductNumber productNumberAnnotation = new ProductNumber(aJCas);
productNumberAnnotation.setProductLine("Universe");
productNumberAnnotation.setBegin(matcher.start());
productNumberAnnotation.setEnd(matcher.end());
productNumberAnnotation.addToIndexes();
pos = matcher.end();
}
Pattern BeyondProductNumbers = Pattern.compile("\\b[B][A-Z][A-Z]-\\d\\d\\d\\b");;
matcher = BeyondProductNumbers.matcher(txt);
pos = 0;
while (matcher.find(pos))
{
ProductNumber productNumberAnnotation = new ProductNumber(aJCas);
productNumberAnnotation.setProductLine("Beyond");
productNumberAnnotation.setBegin(matcher.start());
productNumberAnnotation.setEnd(matcher.end());
productNumberAnnotation.addToIndexes();
pos = matcher.end();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?