Exemple #1
0
  public static void main(String[] args) throws Exception {
    String filePath = "../examples/father.conf";
    byte[] buffer = new byte[(int) new File(filePath).length()];
    BufferedInputStream f = null;
    try {
      f = new BufferedInputStream(new FileInputStream(filePath));
      f.read(buffer);
    } finally {
      if (f != null)
        try {
          f.close();
        } catch (IOException ignored) {
        }
    }
    String confString = new String(buffer);

    Resource confFile = new InputStreamResource(new ByteArrayInputStream(confString.getBytes()));

    IConfiguration configuration = new ConfParserConfiguration(confFile);

    ApplicationContextBuilder builder = new DefaultApplicationContextBuilder();
    ApplicationContext context =
        builder.buildApplicationContext(configuration, new ArrayList<Resource>());

    LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class);
    algorithm.start();
  }
Exemple #2
0
  /**
   * TODO This function takes the config string as in a conf file and the returns an
   * EvaluatedDescription
   *
   * @param conf the content of a conf file
   * @return
   */
  public EvaluatedDescriptionPosNeg learn(String conf) throws Exception {
    Resource confFile = new InputStreamResource(new ByteArrayInputStream(conf.getBytes()));

    IConfiguration configuration = new ConfParserConfiguration(confFile);

    ApplicationContextBuilder builder = new DefaultApplicationContextBuilder();
    ApplicationContext context =
        builder.buildApplicationContext(configuration, new ArrayList<Resource>());

    LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class);
    algorithm.start();
    if (algorithm instanceof ClassExpressionLearningAlgorithm) {
      return (EvaluatedDescriptionPosNeg)
          ((ClassExpressionLearningAlgorithm) algorithm)
              .getCurrentlyBestEvaluatedDescriptions(1)
              .iterator()
              .next();
    }
    throw new Exception("only ClassExpressionLearningAlgorithm implemented currently");
  }