本文整理汇总了Java中org.apache.uima.cas.text.AnnotationIndex.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationIndex.iterator方法的具体用法?Java AnnotationIndex.iterator怎么用?Java AnnotationIndex.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.cas.text.AnnotationIndex
的用法示例。
在下文中一共展示了AnnotationIndex.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
@Override
public void process(CAS _cas) throws AnalysisEngineProcessException {
JCas cas;
try {
cas = _cas.getJCas();
} catch (CASException e) {
throw new AnalysisEngineProcessException(e);
}
AnnotationIndex<Annotation> spanIndex = cas.getAnnotationIndex(spanType);
FSIterator<Annotation> spanIterator = spanIndex.iterator();
Annotation span = null;
while (spanIterator.hasNext()) {
span = spanIterator.next();
tokenizeSpan(cas, span);
}
}
示例2: process
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
@Override
public void process(JCas cas) throws AnalysisEngineProcessException {
try {
AnnotationIndex<Annotation> index = cas.getAnnotationIndex(WordAnnotation.type);
FSIterator<Annotation> iterator = index.iterator();
while (iterator.hasNext()) {
WordAnnotation annotation = (WordAnnotation) iterator.next();
String norm = annotation.getCoveredText();
annotation.setLemma(norm);
annotation.setStem(norm);
}
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
示例3: getExportFilePath
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
protected String getExportFilePath(JCas cas, String extension) {
AnnotationIndex<Annotation> index = cas.getAnnotationIndex(SourceDocumentInformation.type);
FSIterator<Annotation> iterator = index.iterator();
if (iterator.hasNext()) {
SourceDocumentInformation annotation = (SourceDocumentInformation) iterator.next();
File file = new File(annotation.getUri());
String name = file.getName();
int i = name.lastIndexOf('.');
if (i == -1) {
return name + "." + extension;
} else {
return name.substring(0, i) + "." + extension;
}
} else {
return null;
}
}
示例4: getExportFilePath
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
protected String getExportFilePath(JCas cas) {
AnnotationIndex<Annotation> index = cas.getAnnotationIndex(SourceDocumentInformation.type);
FSIterator<Annotation> iterator = index.iterator();
if (iterator.hasNext()) {
SourceDocumentInformation annotation = (SourceDocumentInformation) iterator.next();
File file = new File(annotation.getUri());
String name = file.getName();
int i = name.lastIndexOf('.');
if (i == -1) {
return name + ".xmi";
} else {
return name.substring(0, i) + ".xmi";
}
} else {
return null;
}
}
示例5: removeDuplicateAnnotations
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* Remove duplicate annotations at the same offsets
* from the index
*
* Only based on testing the offset, may have distinct features values !
* In case of duplicate, no guarantee about which one will be removed
*
* @param aJCas the CAS which contains the FSindex
* @author hernandez
* @throws AnalysisEngineProcessException
*
*/
public static void removeDuplicateAnnotations(JCas aJCas) {
AnnotationIndex<Annotation> anAnnotationIndex = aJCas.getAnnotationIndex();
FSIterator<Annotation> anAnnotationIterator = anAnnotationIndex.iterator();
while (anAnnotationIterator.hasNext()) {
Annotation anAnnotation = anAnnotationIterator.next();
removeSubsumedAnnotation(aJCas,anAnnotation.getClass().getName(),anAnnotation.getClass().getName(),true);
}
//HashMap<String, String> alreadySeenFS = new HashMap<String, String>();
//
// parse the FSIndex
// compute an hash of the current Annotation from Class.name alphabetcally ordered list of features with their value.toString()
// if alreadySeenFS this hash them remove from FS
// else add to alreadSeenFS
//
//byte[] hash = null;
//try {
// hash= MessageDigest.getInstance("MD5").digest(aJCas.getSofaDataString().getBytes());
//} catch (NoSuchAlgorithmException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
//}
}
示例6: testNonAmbiguousIterator
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* @param annotationIndex
*/
private void testNonAmbiguousIterator(
AnnotationIndex<Annotation> annotationIndex) {
FSIterator<Annotation> annotationIndexIterator;
Annotation annotation;
System.out.println("Debug: ---------------------------------------------------------------");
System.out.println("Debug: non-ambiguous iteration over an annotation index");
annotationIndexIterator = annotationIndex.iterator(false);
annotationIndexIterator.moveToFirst();
annotation = annotationIndexIterator.get();
System.out.println("first annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"< ");
annotationIndexIterator.moveToNext();
while(annotationIndexIterator.isValid()) {
annotation = annotationIndexIterator.get();
System.out.println("moveToNext annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"<");
annotationIndexIterator.moveToNext();
}
}
示例7: testNonAmbiguousIteratorOverAnIndexOfAGivenType
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* @param inputViewJCas
* @param firstChunk
*/
private void testNonAmbiguousIteratorOverAnIndexOfAGivenType(JCas inputViewJCas,
Annotation firstChunk) {
AnnotationIndex<Annotation> annotationIndex;
FSIterator<Annotation> annotationIndexIterator;
Annotation annotation;
System.out.println("Debug: ---------------------------------------------------------------");
System.out.println("Debug: moveTo+ non-ambiguous iteration over an annotation index (of Chunk.type)");
annotationIndex = (AnnotationIndex<Annotation>) inputViewJCas.getAnnotationIndex(Chunk.type);
annotationIndexIterator = annotationIndex.iterator(false);
annotationIndexIterator.moveTo(firstChunk);
annotation = annotationIndexIterator.get();
System.out.println("moveTo annotation (first chunk firstly met) coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"< ");
annotationIndexIterator.moveToNext();
while(annotationIndexIterator.isValid()) {
annotation = annotationIndexIterator.get();
System.out.println("moveToNext annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"<");
annotationIndexIterator.moveToNext();
}
}
示例8: showCasDebugInfo
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
public static void showCasDebugInfo(JCas jcas, String s) throws CASException {
System.out.println(">>>====== " + s + " " + jcas.getViewName());
Iterator i = jcas.getViewIterator();
while (i.hasNext()) {
JCas aCas = (JCas) i.next();
System.out.println(">>-----" + aCas.getViewName() + " : " + aCas.size());
AnnotationIndex ai = aCas.getAnnotationIndex();
Iterator annotationIterator = ai.iterator();
while (annotationIterator.hasNext()) {
System.out.println(" " + annotationIterator.next());
}
System.out.println("------<<");
}
System.out.println("======<<<");
}
示例9: process
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
String txt = jCas.getDocumentText();
if (txt == null || txt.isEmpty()) {
return;
}
int txtLength = txt.length();
AnnotationIndex<Annotation> tokenIndex = jCas
.getAnnotationIndex(TokenBase.typeIndexID);
FSIterator<Annotation> tokenIter = tokenIndex.iterator();
if (!tokenIter.isValid()) {
makeNTSpan(jCas, 0, txtLength);
} else {
int lastTokenEnd = 0;
while (tokenIter.isValid()) {
Annotation token = tokenIter.get();
if (token.getBegin() > lastTokenEnd) {
makeNTSpan(jCas, lastTokenEnd, token.getBegin());
}
lastTokenEnd = token.getEnd();
//
tokenIter.moveToNext();
}
// check the span after the last token
if (txtLength > lastTokenEnd) {
makeNTSpan(jCas, lastTokenEnd, txtLength);
}
}
}
示例10: clean
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* remove word annotations covered by compound word ones.
*
* @param cas the common analysis structure
*/
private void clean(JCas cas) {
List<Annotation> remAnnotations = new ArrayList<Annotation>();
Type type = this.getType(cas);
AnnotationIndex<Annotation> index = cas.getAnnotationIndex(type);
FSIterator<Annotation> iterator = index.iterator();
Queue<Annotation> lastAnnotationBuffer = new LinkedList<>();
int lastEnd = -1;
Annotation annotation;
while (iterator.hasNext()) {
annotation = iterator.next();
if(annotation.getBegin()>lastEnd) {
/*
* Fast, easy and most frequent case: the annotation does
* not overlap with the ones in the buffer
*/
lastAnnotationBuffer.clear();
} else {
/*
* Does not mean that is is contained in another annotation.
*/
for(Annotation candidateContainer:lastAnnotationBuffer)
if(candidateContainer.getBegin() <= annotation.getBegin()
&& candidateContainer.getEnd() >= annotation.getEnd())
// annotation is contained in candidateContainer
remAnnotations.add(annotation);
}
lastEnd = Integer.max(lastEnd, annotation.getEnd());
lastAnnotationBuffer.add(annotation);
}
for (Annotation a : remAnnotations) {
a.removeFromIndexes();
}
}
示例11: doTreeTag
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* based on tokens from the jcas object, adds part of speech (POS) and sentence
* tags to the jcas object using the treetagger program.
* @param jcas JCas object supplied by the pipeline
*/
private void doTreeTag(JCas jcas) {
try {
if(ttProc == null) {
ttProc = new TreeTaggerProcess(ttprops.getTreeTaggingProcess());
}
Logger.printDetail(component, "TreeTagger (pos tagging) with: " + ttprops.parFileName);
AnnotationIndex ai = jcas.getAnnotationIndex(Token.type);
List<String> tokenStrings = new ArrayList<>();
List<Token> tokens = new ArrayList<>();
for(FSIterator fsi = ai.iterator(); fsi.hasNext();) {
Token token = (Token) fsi.next();
tokenStrings.add(token.getCoveredText());
tokens.add(token);
}
ttreader = new TreeTaggerReader(tokens, ttProc.getStdout(), jcas, annotate_sentences);
ttwriter = new TreeTaggerWriter(tokenStrings, ttProc.getStdin());
Thread rThread = new Thread(ttreader);
Thread wThread = new Thread(ttwriter);
rThread.start();
wThread.start();
rThread.join();
wThread.join();
} catch(IOException | InterruptedException e) {
e.printStackTrace();
}
}
示例12: process
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
@Override
public void process(JCas cas) throws AnalysisEngineProcessException {
try {
AnnotationIndex<Annotation> index = cas.getAnnotationIndex(WordAnnotation.type);
FSIterator<Annotation> iterator = index.iterator();
while (iterator.hasNext()) {
WordAnnotation annotation = (WordAnnotation) iterator.next();
String tag = annotation.getTag().toLowerCase();
this.setCategory(annotation, tag);
}
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
示例13: removeSubsumedAnnotation
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* Remove some subsumed annotations from a given type of subsuming annotation
* Somehow based on
* http://permalink.gmane.org/gmane.comp.apache.uima.general/3501
* http://www.mail-archive.com/[email protected]/msg01645.html
* http://uima.apache.org/downloads/releaseDocs/2.3.0-incubating/docs/api/org/apache/uima/jcas/JCas.html#removeFsFromIndexes(org.apache.uima.cas.FeatureStructure)
* @param aJCas
* @param subsumingAnnotation
* @param subsumedAnnotation
* @param strictOffset
*/
public static void removeSubsumedAnnotation(JCas aJCas, String subsumingAnnotation, String subsumedAnnotation, boolean strictOffset) {
List<Annotation> annotationToRemoveList = new ArrayList<Annotation>();
Type subsumingAnnotationType = aJCas.getTypeSystem().getType(subsumingAnnotation);
AnnotationIndex<Annotation> subsumingAnnotationIndex = aJCas.getAnnotationIndex(subsumingAnnotationType);
Type subsumedAnnotationType = aJCas.getTypeSystem().getType(subsumedAnnotation);
AnnotationIndex<Annotation> subsumedAnnotationIndex = aJCas.getAnnotationIndex(subsumedAnnotationType);
FSIterator<Annotation> subsumingAnnotationIterator = subsumingAnnotationIndex.iterator();
while (subsumingAnnotationIterator.hasNext()) {
Annotation aSubsumingAnnotation = subsumingAnnotationIterator.next();
FSIterator<Annotation> subsumedAnnotationIterator = subsumedAnnotationIndex.subiterator(aSubsumingAnnotation);
while (subsumedAnnotationIterator.hasNext()) {
Annotation aSubsumedAnnotation = subsumedAnnotationIterator.next();
if (strictOffset) {
if ((aSubsumingAnnotation.getBegin() == aSubsumedAnnotation.getBegin()) && (aSubsumingAnnotation.getEnd() == aSubsumedAnnotation.getEnd()) ) {
annotationToRemoveList.add(aSubsumedAnnotation);
} }
else annotationToRemoveList.add(aSubsumedAnnotation);
}
}
for (Annotation remove : annotationToRemoveList) {
remove.removeFromIndexes();
}
}
示例14: getAnnotationArray
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* This method get an FeatureStructure Array of selected annotation types
* Leave empty if all annotations should be considered
*
* @param aJCas
* the CAS over which the process is performed
* @param annotationHashMap
* Map of annotations to filter in the JCas
* @return ArrayList<FeatureStructure>
* Filtered JCas with the selected annotation
* @throws AnalysisEngineProcessException
*/
public static ArrayList<FeatureStructure> getAnnotationArray(JCas aJCas, HashMap<String, Integer> annotationHashMap) throws AnalysisEngineProcessException {
//System.out.println("Debug: getAnnotationArray HashMap.size>"+annotationHashMap.size()+"<");
ArrayList<FeatureStructure> result = new ArrayList<FeatureStructure>();
//FSIndex<Annotation> result = null;
AnnotationIndex annotationIndex = (AnnotationIndex)
aJCas.getAnnotationIndex();
FSIterator annotationIndexIterator = annotationIndex.iterator();
//Iterator keyIter = annotationHashMap.keySet().iterator();
//while (keyIter.hasNext()){
// String key = (String) keyIter.next();
// System.out.println("Debug: key>"+key+"<");
//}
while (annotationIndexIterator.hasNext()) {
// On peut le manipuler comme on veut ...
Object annotationObject = annotationIndexIterator.next();
Class annotationClass = annotationObject.getClass();
String className = "null";
if (annotationClass != null ) {
className = annotationClass.getName(); //.toString();
//System.out.println("Debug: class>"+className+"<");
if ((annotationHashMap.size() == 0) || (annotationHashMap.containsKey(className))) {
result.add((FeatureStructure) annotationObject);
Annotation annotation = (Annotation) annotationObject;
//System.out.println("Debug: "+className + "\t" + annotation.getCoveredText()+ "\t" + annotation.getBegin() + "\t" +annotation.getEnd());
}
}
}
return result;
}
示例15: loadAnswerType
import org.apache.uima.cas.text.AnnotationIndex; //导入方法依赖的package包/类
/**
* Convert UIMA data model
*
* @param questionView
* @return answerType
*/
public static String loadAnswerType(JCas questionView) {
String result = null;
AnnotationIndex<?> index = questionView.getAnnotationIndex(AnswerType.type);
Iterator<?> it = index.iterator();
if (it.hasNext()) {
AnswerType atype = (AnswerType) it.next();
result = atype.getLabel();
}
return result;
}