當前位置: 首頁>>代碼示例>>Java>>正文


Java CAS.getAnnotationIndex方法代碼示例

本文整理匯總了Java中org.apache.uima.cas.CAS.getAnnotationIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java CAS.getAnnotationIndex方法的具體用法?Java CAS.getAnnotationIndex怎麽用?Java CAS.getAnnotationIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.uima.cas.CAS的用法示例。


在下文中一共展示了CAS.getAnnotationIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import org.apache.uima.cas.CAS; //導入方法依賴的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: fromView

import org.apache.uima.cas.CAS; //導入方法依賴的package包/類
/**
 * Indexes all the symbols from an original document.
 *
 * @param originalDocumentView jCas original document view.
 * @return The newly created symbol indexed document.
 */
public static SymbolIndexedDocument fromView(CAS originalDocumentView) {
  Type viewIndexType = originalDocumentView.getTypeSystem()
      .getType("edu.umn.biomedicus.rtfuima.type.ViewIndex");

  Feature destinationNameFeature = viewIndexType
      .getFeatureByBaseName("destinationName");
  Feature destinationIndexFeature = viewIndexType
      .getFeatureByBaseName("destinationIndex");

  AnnotationIndex<AnnotationFS> viewIndexAI = originalDocumentView
      .getAnnotationIndex(viewIndexType);

  List<SymbolLocation> symbolLocations = new ArrayList<>();

  Map<String, Map<Integer, Integer>> destinationMap = new HashMap<>();

  int index = 0;
  int lastEnd = 0;
  for (AnnotationFS annotation : viewIndexAI) {
    int begin = annotation.getBegin();
    int end = annotation.getEnd();

    String destinationName
        = annotation.getStringValue(destinationNameFeature);

    SymbolLocation symbolLocation = new SymbolLocation(
        destinationName,
        begin - lastEnd,
        end - begin,
        index++
    );

    symbolLocations.add(symbolLocation);

    int destinationIndex
        = annotation.getIntValue(destinationIndexFeature);

    destinationMap.compute(destinationName,
        (String key, @Nullable Map<Integer, Integer> value) -> {
          if (value == null) {
            value = new HashMap<>();
          }
          value.put(destinationIndex, symbolLocations.size() - 1);

          return value;
        });
    lastEnd = end;
  }
  return new SymbolIndexedDocument(symbolLocations, destinationMap,
      originalDocumentView.getDocumentText());
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:58,代碼來源:SymbolIndexedDocument.java

示例3: process

import org.apache.uima.cas.CAS; //導入方法依賴的package包/類
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
  CAS originalDocumentView = aCAS.getView(Views.ORIGINAL_DOCUMENT_VIEW);
  SymbolIndexedDocument symbolIndexedDocument
      = SymbolIndexedDocument.fromView(originalDocumentView);

  CAS view = aCAS.getView(Views.SYSTEM_VIEW);

  TreeSet<Integer> covered = new TreeSet<>();
  for (String annotationType : Objects.requireNonNull(annotationTypes)) {
    Type type = view.getTypeSystem().getType(annotationType);

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

    for (Annotation annotation : annotationIndex) {
      IntStream.rangeClosed(annotation.getBegin(), annotation.getEnd()).forEach(covered::add);
    }
  }

  Iterator<Integer> iterator = covered.iterator();
  int next = iterator.next();
  int last = -1;
  while (iterator.hasNext()) {
    int first = next;
    while (iterator.hasNext()) {
      last = next;
      next = iterator.next();
      if (next - last > 1) {
        break;
      }
    }
    RegionTaggerBuilder.create()
        .withBeginTag("\\u2222221B ")
        .withEndTag("\\u2222221E ")
        .withSymbolIndexedDocument(symbolIndexedDocument)
        .withDestinationName(Views.SYSTEM_VIEW)
        .withBegin(first)
        .withEnd(last)
        .createRegionTagger()
        .tagRegion();
  }

  String rewrittenDocument = symbolIndexedDocument.getDocument();

  String fileName = FileNameProviders.fromCAS(view, ".rtf");
  Path file = outputDir.resolve(fileName);

  try (BufferedWriter bufferedWriter = Files
      .newBufferedWriter(file, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
    bufferedWriter.write(rewrittenDocument);
  } catch (IOException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
開發者ID:nlpie,項目名稱:biomedicus,代碼行數:55,代碼來源:AnnotationInsertingWriter.java


注:本文中的org.apache.uima.cas.CAS.getAnnotationIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。