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


Java Files.asCharSource方法代码示例

本文整理汇总了Java中com.google.common.io.Files.asCharSource方法的典型用法代码示例。如果您正苦于以下问题:Java Files.asCharSource方法的具体用法?Java Files.asCharSource怎么用?Java Files.asCharSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Files的用法示例。


在下文中一共展示了Files.asCharSource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uncachedRead

import com.google.common.io.Files; //导入方法依赖的package包/类
private synchronized AnswerKey uncachedRead(final Symbol docid) throws IOException {
  final ImmutableList.Builder<AssessedResponse> annotated = ImmutableList.builder();
  final ImmutableList.Builder<Response> unannotated = ImmutableList.builder();
  final CorefAnnotation.Builder corefBuilder = assessmentCreator.corefBuilder(docid);

  final File f = bareOrWithSuffix(directory, docid.asString(), ACCEPTABLE_SUFFIXES);

  final CharSource source = Files.asCharSource(f, UTF_8);
  for (final String line : source.readLines()) {
    try {
      if (line.isEmpty() || line.startsWith("#")) {
        continue;
      }
      final String[] parts = line.split("\t");
      final List<String> argumentParts = Arrays.asList(parts).subList(1, 11);
      final List<String> annotationParts = Arrays.asList(parts).subList(11, parts.length);

      if (annotationParts.isEmpty()) {
        throw new IOException(String.format(
            "The assessment store file for document ID %s appears to be a system " +
                "output file with no assessment columns.", docid));
      }

      final Response response = parseArgumentFields(argumentParts);
      final AssessmentCreator.AssessmentParseResult annotation =
          parseAnnotation(annotationParts);

      if (annotation.assessment().isPresent()) {
        annotated.add(AssessedResponse.of(response, annotation.assessment().get()));
      } else {
        unannotated.add(response);
      }

      if (annotation.corefId().isPresent()) {
        corefBuilder.corefCAS(response.canonicalArgument(), annotation.corefId().get());
      } else {
        corefBuilder.addUnannotatedCAS(response.canonicalArgument());
      }
    } catch (Exception e) {
      throw new IOException(String.format(
          "While reading answer key for document %s, error on line %s", docid, line), e);
    }
  }

  return assessmentCreator.createAnswerKey(docid, annotated.build(), unannotated.build(),
      corefBuilder.build());
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:48,代码来源:AssessmentSpecFormats.java


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