uk.gov.dstl.baleen.core.pipelines.YamlPipelineConfiguration类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中uk.gov.dstl.baleen.core.pipelines.YamlPipelineConfiguration类的一些代码示例,展示了YamlPipelineConfiguration类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlPipelineConfiguration类的具体详情如下:
包路径:uk.gov.dstl.baleen.core.pipelines.YamlPipelineConfiguration
类名称:YamlPipelineConfiguration

YamlPipelineConfiguration介绍

[英]A yaml based implementation of a pipeline config
[中]基于yaml的管道配置实现

代码示例

代码示例来源:origin: dstl/baleen

/**
 * Cosntruct a new BaleenJob
 *
 * @param name The name of the job
 * @param originalYaml The original YAML
 * @param scheduler The scheduler (i.e. collection reader)
 * @param tasks List of tasks (i.e. annotators)
 * @throws IOException if unable to construct
 */
public BaleenJob(
  String name, String originalYaml, CollectionReader scheduler, List<AnalysisEngine> tasks)
  throws IOException {
 this(name, new YamlPipelineConfiguration(originalYaml), scheduler, tasks);
}

代码示例来源:origin: dstl/baleen

@Override
public Map<String, Object> flatten(Collection<String> ignoreParams) {
 if (root instanceof Map<?, ?>) {
  return flatten(null, ignoreParams, (Map<String, Object>) root);
 } else {
  return new LinkedHashMap<>();
 }
}

代码示例来源:origin: dstl/baleen

/**
 * Construct a PipelineBuilder from the name and YAML
 *
 * @param name Pipeline name
 * @param yaml Pipeline YAML
 * @throws IOException
 * @deprecated Use {@link PipelineBuilder#PipelineBuilder(String, PipelineConfiguration)}
 */
@Deprecated
public PipelineBuilder(String name, String yaml) throws IOException {
 this(name, new YamlPipelineConfiguration(yaml));
}

代码示例来源:origin: dstl/baleen

private Map<String, Object> flatten(
   String key, Collection<String> ignoreParams, Map<String, Object> config) {
  Map<String, Object> flattened = new HashMap<>();

  String prefix = key;
  if (!Strings.isNullOrEmpty(prefix)) {
   prefix = prefix + ".";
  } else {
   prefix = "";
  }

  for (Entry<String, Object> e : config.entrySet()) {
   if (!ignoreParams.contains(e.getKey())) {
    if (e.getValue() instanceof Map) {
     flattened.putAll(
       flatten(prefix + e.getKey(), ignoreParams, (Map<String, Object>) e.getValue()));
    } else if (e.getValue() != null) {
     flattened.put(prefix + e.getKey(), e.getValue());
    }
   }
  }

  return flattened;
 }
}

代码示例来源:origin: dstl/baleen

/**
 * Construct a JobBuilder from the name and YAML
 *
 * @param name Pipeline name
 * @param yaml Pipeline YAML
 * @throws IOException if unable to read config
 * @deprecated Use {@link JobBuilder#JobBuilder(String, PipelineConfiguration)}
 */
@Deprecated
public JobBuilder(String name, String yaml) throws IOException {
 this(name, new YamlPipelineConfiguration(yaml));
}

代码示例来源:origin: dstl/baleen

/**
 * Constructor
 *
 * @param name Pipeline name
 * @param originalYaml The original YAML string that was used to build the pipeline
 * @param orderer The IPipelineOrderer to use to order the pipeline
 * @param collectionReader The collection reader
 * @param annotators The annotators to be ordered and used
 * @param consumers The consumers to be ordered and used
 * @throws IOException if error reading config
 * @deprecated Use {@link BaleenPipeline#BaleenPipeline(String, PipelineConfiguration,
 *     IPipelineOrderer, CollectionReader, List, List)}
 */
@Deprecated
public BaleenPipeline(
  String name,
  String originalYaml,
  IPipelineOrderer orderer,
  CollectionReader collectionReader,
  List<AnalysisEngine> annotators,
  List<AnalysisEngine> consumers)
  throws IOException {
 this(
   name,
   new YamlPipelineConfiguration(originalYaml),
   orderer,
   collectionReader,
   annotators,
   consumers);
}

代码示例来源:origin: dstl/baleen

/**
 * Create a new pipeline from the provided YAML, with the given name. If multiplicity is greater
 * than 1 names will be suffixed with '-n' for each multiple.
 */
public List<BaleenPipeline> create(String name, InputStream yaml, int multiplicity)
  throws BaleenException {
 try {
  return create(name, new YamlPipelineConfiguration(yaml), multiplicity);
 } catch (IOException e) {
  throw new BaleenException(e);
 }
}

代码示例来源:origin: dstl/baleen

/**
 * Create a new pipeline from the provided YAML file, with the given name. If multiplicity is
 * greater than 1 names will be suffixed with '-n' for each multiple.
 */
public List<BaleenPipeline> create(String name, File file, int multiplicity)
  throws BaleenException {
 try {
  return create(name, new YamlPipelineConfiguration(file), multiplicity);
 } catch (IOException e) {
  throw new BaleenException(e);
 }
}

代码示例来源:origin: dstl/baleen

private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException {
 String name = req.getParameter(PARAM_NAME);
 String yaml = req.getParameter(PARAM_YAML);
 String multi = req.getParameter(PARAM_MULTIPLICITY);
 int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi);
 if (!parametersPresent(name, yaml) || manager.has(name)) {
  respondWithBadArguments(resp);
  return;
 }
 List<BaleenPipeline> t;
 try {
  t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity);
 } catch (BaleenException e) {
  LOGGER.error("Unable to create", e);
  respondWithError(
    resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed");
  return;
 }
 if (multiplicity == 1) {
  respondWithJson(resp, t.get(0));
 } else {
  respondWithJson(resp, t);
 }
}

代码示例来源:origin: dstl/baleen

logger.info("Attempting to create {} {}", getType(), name);
 logger.debug("Pipeline configuration: {}", yaml);
 create(name, new YamlPipelineConfiguration(yaml), multiplicity);
} catch (Exception e) {
 logger.warn(

代码示例来源:origin: dstl/baleen

protected BaleenJob wrapInJob(Class<? extends BaleenTask>... taskClasses)
  throws BaleenException, IOException {
 String yaml = getYaml(taskClasses);
 return (BaleenJob) jobManager.create("testjob", new YamlPipelineConfiguration(yaml));
}

代码示例来源:origin: dstl/baleen

protected BaleenJob wrapInJob(Class<? extends BaleenTask> taskClass, Map<String, String> params)
  throws BaleenException, IOException {
 String yaml = getYaml(taskClass, params);
 return (BaleenJob) jobManager.create("testjob", new YamlPipelineConfiguration(yaml));
}

代码示例来源:origin: dstl/baleen

@Test
public void testEmpty() throws Exception {
 BaleenJob job =
   new BaleenJob("name", new YamlPipelineConfiguration(), null, Collections.emptyList());
 doReturn(Optional.of(job)).when(manager).get(anyString());
 ServletCaller caller = new ServletCaller();
 caller.addParameter("name", "name");
 caller.doGet(new JobConfigServlet(manager));
 assertEquals("", caller.getResponseBody());
}

代码示例来源:origin: dstl/baleen

@Test
public void testNameAndYaml() throws IOException {
 BaleenPipeline bop =
   new BaleenPipeline(
     "Test Name",
     new YamlPipelineConfiguration("Test YAML"),
     new NoOpOrderer(),
     null,
     Collections.emptyList(),
     Collections.emptyList());
 assertEquals("Test Name", bop.getName());
 assertEquals("Test YAML", bop.originalConfig());
 // TODO: Test orderedYaml
}

代码示例来源:origin: dstl/baleen

@Test
public void testEmpty() throws Exception {
 BaleenPipeline pipeline =
   new BaleenPipeline(
     "name",
     new YamlPipelineConfiguration(),
     new NoOpOrderer(),
     null,
     Collections.emptyList(),
     Collections.emptyList());
 doReturn(Optional.of(pipeline)).when(manager).get(anyString());
 ServletCaller caller = new ServletCaller();
 caller.addParameter("name", "name");
 caller.doGet(new PipelineConfigServlet(manager));
 assertEquals("", caller.getResponseBody());
}

代码示例来源:origin: dstl/baleen

@Test
public void testErrorContentExtractorNotFound() throws Exception {
 String yaml =
   Files.asCharSource(getFile("errorNotFoundCEConfig.yaml"), StandardCharsets.UTF_8).read();
 PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml));
 try {
  pb.createNewPipeline();
  fail("Expected exception not thrown");
 } catch (BaleenException be) {
  // Expected exception, do nothing
 }
}

代码示例来源:origin: dstl/baleen

@Test
 public void testWithConfig() throws Exception {
  BaleenPipeline pipeline =
    new BaleenPipeline(
      "name",
      new YamlPipelineConfiguration("Config"),
      new NoOpOrderer(),
      null,
      Collections.emptyList(),
      Collections.emptyList());
  doReturn(Optional.of(pipeline)).when(manager).get(anyString());

  ServletCaller caller = new ServletCaller();
  caller.addParameter("name", "name");
  caller.doGet(new PipelineConfigServlet(manager));
  assertEquals("Config", caller.getResponseBody());
 }
}

代码示例来源:origin: dstl/baleen

@Test
public void testErrorNoCR() throws Exception {
 String yaml =
   Files.asCharSource(getFile("errorNoCRConfig.yaml"), StandardCharsets.UTF_8).read();
 PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml));
 try {
  pb.createNewPipeline();
  fail("Expected exception not thrown");
 } catch (BaleenException be) {
  // Expected exception, do nothing
 }
}

代码示例来源:origin: dstl/baleen

@Test
public void testErrorNotFoundCR() throws Exception {
 String yaml =
   Files.asCharSource(getFile("errorNotFoundCRConfig.yaml"), StandardCharsets.UTF_8).read();
 PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml));
 try {
  pb.createNewPipeline();
  fail("Expected exception not thrown");
 } catch (BaleenException be) {
  // Expected exception, do nothing
 }
}

代码示例来源:origin: dstl/baleen

@Test
public void testLegacy() throws Exception {
 String yaml = Files.asCharSource(getFile("legacyConfig.yaml"), StandardCharsets.UTF_8).read();
 PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml));
 BaleenPipeline pipeline = pb.createNewPipeline();
 assertEquals("Test Pipeline", pipeline.getName());
 assertEquals(yaml, pipeline.originalConfig());
 // Will throw an exception if the content extractor was not found resource wasn't initialized
}

相关文章

YamlPipelineConfiguration类方法