当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationIndex类代码示例

本文整理汇总了Java中org.apache.uima.cas.text.AnnotationIndex的典型用法代码示例。如果您正苦于以下问题:Java AnnotationIndex类的具体用法?Java AnnotationIndex怎么用?Java AnnotationIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnnotationIndex类属于org.apache.uima.cas.text包,在下文中一共展示了AnnotationIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
  LOGGER.debug("Annotating rtf paragraphs.");
  CAS systemView = aCAS.getView(Views.SYSTEM_VIEW);

  Type newParagraphType = systemView.getTypeSystem()
      .getType("edu.umn.biomedicus.rtfuima.type.NewParagraph");

  Type paragraphType = systemView.getTypeSystem()
      .getType("edu.umn.biomedicus.type.ParagraphAnnotation");

  AnnotationIndex<AnnotationFS> newParagraphIndex = systemView
      .getAnnotationIndex(newParagraphType);
  int start = 0;

  for (AnnotationFS newParagraph : newParagraphIndex) {
    int end = newParagraph.getEnd();
    systemView.addFsToIndexes(
        systemView.createAnnotation(paragraphType, start, end));

    start = end;
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:24,代码来源:ParagraphAnnotator.java

示例2: process

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
private void process(JCas cas) throws AnalysisEngineProcessException {
    AnnotationIndex<Annotation> tokenIdx = cas.getAnnotationIndex(tokenType);
    for (Annotation token : tokenIdx) {
        String tokenStr = token.getCoveredText();
        if (proceed(tokenStr)) {
            // TODO configuration point
            // tokenizer should care about normalization
            tokenStr = WordUtils.normalizeToDictionaryForm(tokenStr);
            List<Wordform> wfDictEntries = dict.getEntries(tokenStr);
            if (wfDictEntries != null && !wfDictEntries.isEmpty()) {
                // invoke adapter
                annoAdapter.apply(cas, token, wfDictEntries);
            }
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:17,代码来源:MorphologyAnnotator.java

示例3: 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);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:17,代码来源:InitialTokenizer.java

示例4: 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);
	}
}
 
开发者ID:termsuite,项目名称:termsuite-core,代码行数:17,代码来源:ChineseNormalizer.java

示例5: 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;
	}
}
 
开发者ID:termsuite,项目名称:termsuite-core,代码行数:18,代码来源:CasExporter.java

示例6: 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;
	}
}
 
开发者ID:termsuite,项目名称:termsuite-core,代码行数:18,代码来源:XmiCasExporter.java

示例7: 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();
	//}

}
 
开发者ID:EUMSSI,项目名称:EUMSSI-tools,代码行数:38,代码来源:AnnotationCollectionUtils.java

示例8: testChunkUnambiguousStrictSubiterator

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
private void testChunkUnambiguousStrictSubiterator(JCas testJcas,
		AnnotationIndex<Annotation> annotationIndex) {
	System.out.println("Debug: ---------------------------------------------------------------");

	System.out.println("Debug: unambiguous and strict subiterating all the chunk annotations");
	AnnotationIndex<Annotation> chunkAnnotationIndex = (AnnotationIndex<Annotation>) testJcas.getAnnotationIndex(Chunk.type);
	for (Annotation aChunk : chunkAnnotationIndex) {
		FSIterator<Annotation> chunkSubIterator = annotationIndex.subiterator(aChunk,false,true);
		System.out.println("annotation to subiterate type>"+aChunk.getClass().getName()+"< coveredText>"+aChunk.getCoveredText()+"<");

		while(chunkSubIterator.isValid()) {
			Annotation subAnnotation = chunkSubIterator.get();

			System.out.println("moveToNext subAnnotation type>"+subAnnotation.getClass().getName()+"< coveredText>"+subAnnotation.getCoveredText()+"<");
			chunkSubIterator.moveToNext();
		}
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:19,代码来源:TestLocatedAnnotationAE.java

示例9: 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();
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:21,代码来源:TestLocatedAnnotationAE.java

示例10: 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();
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:25,代码来源:TestLocatedAnnotationAE.java

示例11: 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("======<<<");
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:16,代码来源:UIMA_Util.java

示例12: process

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
  try {
    Iterator<JCas> viewIterator = aJCas.getViewIterator();

    while (viewIterator.hasNext()) {
      JCas view = viewIterator.next();

      String sofaDataString = view.getSofaDataString();
      int length = sofaDataString != null ? sofaDataString.length() : -1;

      AnnotationIndex<Annotation> annotationIndex = view.getAnnotationIndex();

      for (Annotation annotation : annotationIndex) {
        int begin = annotation.getBegin();
        int end = annotation.getEnd();

        if (begin > end) {
          LOGGER
              .error("Annotation {} begin {} after end {}", annotation.getType().getName(), begin,
                  end);
        }

        if (begin < 0) {
          LOGGER.error("Annotation {} begin {} before 0", annotation.getType().getName(), begin);
        }

        if (end > length) {
          LOGGER.error("Annotation {} end {} after length of sofa {}",
              annotation.getType().getName(),
              end, length);
        }

      }
    }

  } catch (CASException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:41,代码来源:AnnotationVerifier.java

示例13: getStringValue

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
/**
 * @param cas
 * @param type
 * @param feature
 * @return feature value of the first annotation of given type from given
 * CAS. E.g., it is useful to get document metadata values. If there
 * is no such annotation method will return null.
 */
public static String getStringValue(CAS cas, Type type, Feature feature) {
    AnnotationIndex<AnnotationFS> metaIdx = cas.getAnnotationIndex(type);
    if (metaIdx.size() > 0) {
        AnnotationFS meta = metaIdx.iterator().next();
        return meta.getFeatureValueAsString(feature);
    } else {
        return null;
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:18,代码来源:AnnotationUtils.java

示例14: getSingleAnnotation

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <A extends AnnotationFS> A getSingleAnnotation(JCas cas, Class<A> typeJCasClass) {
    Type annoType = CasUtil.getAnnotationType(cas.getCas(), typeJCasClass);
    AnnotationIndex<Annotation> annoIdx = cas.getAnnotationIndex(annoType);
    if (annoIdx.size() == 0) {
        return null;
    } else if (annoIdx.size() == 1) {
        return (A) annoIdx.iterator().next();
    } else {
        throw new IllegalStateException(String.format(
                "Too much (>1) annotations of type %s", annoType));
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:14,代码来源:AnnotationUtils.java

示例15: process

import org.apache.uima.cas.text.AnnotationIndex; //导入依赖的package包/类
private void process(CAS cas, PrintWriter out) {
    AnnotationIndex<AnnotationFS> tokenIdx = cas.getAnnotationIndex(tokenType);
    Multimap<AnnotationFS, String> tokLabelsMap = HashMultimap.create(tokenIdx.size(), 1);
    // phase 1 - initialize map <token => label>
    for (Type et : encodeTypesMap.keySet()) {
        String typeLabel = encodeTypesMap.get(et);
        for (AnnotationFS encAnno : cas.getAnnotationIndex(et)) {
            Iterator<AnnotationFS> encAnnoTokens =
                    CasUtil.selectCovered(tokenType, encAnno).iterator();
            if (!encAnnoTokens.hasNext()) {
                getLogger().warn(format("%s: %s does not cover any tokens",
                        docURI, toPrettyString(encAnno)));
                continue;
            }
            // handle first token of encAnno
            tokLabelsMap.put(encAnnoTokens.next(), BEGIN_PREFIX + typeLabel);
            // handle other tokens
            while (encAnnoTokens.hasNext()) {
                tokLabelsMap.put(encAnnoTokens.next(), INSIDE_PREFIX + typeLabel);
            }
        }
    }
    // phase 2 - write token records into output stream
    for (AnnotationFS tok : tokenIdx) {
        List<String> recordFields = Lists.newLinkedList();
        recordFields.add(tok.getCoveredText());
        //
        Collection<String> tokLabels = tokLabelsMap.get(tok);
        if (tokLabels.isEmpty()) {
            recordFields.add(OUTSIDE_LABEL);
        } else {
            recordFields.addAll(tokLabels);
        }
        //
        out.println(tabJoiner.join(recordFields));
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:38,代码来源:IobWriter.java


注:本文中的org.apache.uima.cas.text.AnnotationIndex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。