Example usage for org.apache.commons.configuration BaseConfiguration setProperty

List of usage examples for org.apache.commons.configuration BaseConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration BaseConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Usage

From source file:com.feedzai.fos.impl.weka.WekaManagerTest.java

private WekaManagerConfig setupWekaConfig(String headerLocation) {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".minIdle", 10);
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".maxActive", 10);
    configuration.setProperty(FosConfig.HEADER_LOCATION, headerLocation);
    configuration.setProperty(FosConfig.FACTORY_NAME, WekaManagerFactory.class.getName());
    return new WekaManagerConfig(new FosConfig(configuration));
}

From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java

@Test
public void testCommonsConfigOverrideSetVsAdd() {
    BaseConfiguration bc = new BaseConfiguration();
    BaseConfiguration bc2 = new BaseConfiguration();

    bc2.addProperty("test.prop", 52);

    CompositeConfiguration cconfig = new CompositeConfiguration();
    cconfig.addConfiguration(bc);//from  w ww.ja  v  a 2s.c o  m
    cconfig.addConfiguration(bc2);

    bc.setProperty("test.prop", 112);

    Assert.assertEquals(112, cconfig.getInt("test.prop"));
}

From source file:com.feedzai.fos.impl.r.RIntegrationTest.java

@Test
public void trainandAdd() throws Exception {

    BaseConfiguration configuration = new BaseConfiguration();
    Map<String, String> properties = new HashMap<>();
    List<Attribute> attributes = getAttributes();

    ModelConfig modelConfig = new ModelConfig(attributes, properties);
    modelConfig.setProperty(RModelConfig.LIBRARIES, "e1071, foreign");
    modelConfig.setProperty(RModelConfig.MODEL_SAVE_PATH, getCwd());
    modelConfig.setProperty(RModelConfig.CLASS_INDEX, Integer.valueOf(attributes.size() - 1).toString());
    modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION, "naiveBayes");
    modelConfig.setProperty(RModelConfig.PREDICT_FUNCTION_ARGUMENTS, "type = 'raw'");

    configuration.setProperty(FosConfig.FACTORY_NAME, RManagerFactory.class.getName());

    FosConfig config = new FosConfig(configuration);

    RManagerConfig rManagerConfig = new RManagerConfig(config);

    RManager rManager = new RManager(rManagerConfig);

    UUID uuid = rManager.trainAndAdd(modelConfig, getTrainingInstances());

    Scorer scorer = rManager.getScorer();

    Object[] instance = { "b", 30.83, 0, "u", "g", "w", "v", 1.25, "t", "t", 1, "f", "g", 202, 0 };

    List<double[]> result = scorer.score(ImmutableList.of(uuid), instance);
    assertEquals("Only 1 score expected", 1, result.size());
    assertEquals("2 probabilities (not fraud, fraud)", 2, result.get(0).length);

}

From source file:com.runwaysdk.configuration.CommonsConfigurationResolver.java

private BaseConfiguration getRuntimeProperties() {
    BaseConfiguration properties = new BaseConfiguration();

    // Calculate the value of deploy.path. The reason we do this at runtime is
    // because the value of this property may vary depending on the application
    // context path.
    String webappContextPath = deployPath;
    if (deployPath == null) {
        webappContextPath = CommonsConfigurationResolver.class.getResource("/").getPath()
                .replace("WEB-INF/classes", "");
    }// ww w. ja va 2s . com

    if (webappContextPath.endsWith("/")) {
        webappContextPath = webappContextPath.substring(0, webappContextPath.length() - 1);
    }

    // getPath returns spaces as %20. The file constructor does not read this
    // properly.
    webappContextPath = webappContextPath.replace("%20", " ");

    // The reason we're using resource.toURI here is because if there's spaces
    // in the path then constructing a file with a string doesn't work...
    if (new File(webappContextPath).exists()) {
        properties.setProperty("deploy.path", webappContextPath);
        log.info("deploy.path resolved to [" + webappContextPath + "]");
    } else {
        throw new RunwayConfigurationException(
                "Unable to determine deploy.path, the location [" + webappContextPath + "] does not exist.");
    }

    return properties;
}

From source file:com.feedzai.fos.impl.r.RIntegrationTest.java

@Test
public void addModelFile() throws Exception {

    BaseConfiguration configuration = new BaseConfiguration();
    Map<String, String> properties = new HashMap<>();
    List<Attribute> attributes = getAttributes();

    ModelConfig modelConfig = new ModelConfig(attributes, properties);

    modelConfig.setProperty(RModelConfig.LIBRARIES, "e1071, foreign");
    modelConfig.setProperty(RModelConfig.MODEL_SAVE_PATH, getCwd());
    modelConfig.setProperty(RModelConfig.CLASS_INDEX, Integer.valueOf(attributes.size() - 1).toString());
    modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION, "svm");
    modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION_ARGUMENTS, "probability = TRUE");
    modelConfig.setProperty(RModelConfig.PREDICT_FUNCTION_ARGUMENTS, "probability = TRUE");
    modelConfig.setProperty(RModelConfig.PREDICT_RESULT_TRANSFORM, "r <- attr(r, 'probabilities')");

    configuration.setProperty(FosConfig.FACTORY_NAME, RManagerFactory.class.getName());

    FosConfig config = new FosConfig(configuration);

    RManagerConfig rManagerConfig = new RManagerConfig(config);

    RManager rManager = new RManager(rManagerConfig);
    UUID uuid = rManager.trainAndAddFile(modelConfig, getCwd() + "/credit-a.arff");

    Scorer scorer = rManager.getScorer();

    Object[] instance = { "b", 30.83, 0, "u", "g", "w", "v", 1.25, "t", "t", 1, "f", "g", 202, 0 };

    List<double[]> result = scorer.score(ImmutableList.of(uuid), instance);
    assertEquals("Only 1 score expected", 1, result.size());
    assertEquals("2 probabilities (not fraud, fraud)", 2, result.get(0).length);

}

From source file:com.feedzai.fos.impl.r.RIntegrationTest.java

@Test
public void addModel() throws Exception {

    BaseConfiguration configuration = new BaseConfiguration();
    Map<String, String> properties = new HashMap<>();
    List<Attribute> attributes = getAttributes();

    String suuid = "d9556c14-97f1-40f6-9514-f6fb339474af";
    UUID uuid = UUID.fromString(suuid);

    ModelConfig modelConfig = new ModelConfig(attributes, properties);
    modelConfig.setProperty("UUID", suuid);

    modelConfig.setProperty(RModelConfig.LIBRARIES, "e1071, foreign");
    modelConfig.setProperty(RModelConfig.MODEL_SAVE_PATH, getCwd());
    modelConfig.setProperty(RModelConfig.CLASS_INDEX, Integer.valueOf(attributes.size() - 1).toString());
    modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION, "svm");
    modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION_ARGUMENTS, "probability = TRUE");
    modelConfig.setProperty(RModelConfig.PREDICT_FUNCTION_ARGUMENTS, "probability = TRUE");
    modelConfig.setProperty(RModelConfig.PREDICT_RESULT_TRANSFORM, "r <- attr(r, 'probabilities')");
    configuration.setProperty(FosConfig.FACTORY_NAME, RManagerFactory.class.getName());

    FosConfig config = new FosConfig(configuration);

    RManagerConfig rManagerConfig = new RManagerConfig(config);

    RManager rManager = new RManager(rManagerConfig);
    rManager.trainFile(modelConfig, getCwd() + "/credit-a.arff");
    rManager.addModel(modelConfig,// w w  w  .  ja va 2  s . c  o m
            new ModelDescriptor(ModelDescriptor.Format.BINARY, getCwd() + "/credit-a.arff.model"));

    Scorer scorer = rManager.getScorer();

    Object[] instance = { "b", 30.83, 0, "u", "g", "w", "v", 1.25, "t", "t", 1, "f", "g", 202, 0 };

    List<double[]> result = scorer.score(ImmutableList.of(uuid), instance);
    assertEquals("Only 1 score expected", 1, result.size());
    assertEquals("2 probabilities (not fraud, fraud)", 2, result.get(0).length);

}

From source file:org.apache.tinkerpop.gremlin.hadoop.structure.io.InputOutputHelper.java

public static HadoopGraph getOutputGraph(final Configuration configuration,
        final GraphComputer.ResultGraph resultGraph, final GraphComputer.Persist persist) {
    final HadoopConfiguration hadoopConfiguration = new HadoopConfiguration(configuration);
    final BaseConfiguration newConfiguration = new BaseConfiguration();
    newConfiguration.copy(hadoopConfiguration);
    if (resultGraph.equals(GraphComputer.ResultGraph.NEW)) {
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION,
                hadoopConfiguration.getOutputLocation());
        if (hadoopConfiguration.containsKey(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT))
            newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT, InputOutputHelper
                    .getInputFormat(hadoopConfiguration.getGraphOutputFormat()).getCanonicalName());
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT_HAS_EDGES,
                persist.equals(GraphComputer.Persist.EDGES));
    }/*www.  jav a  2  s  .  c om*/
    newConfiguration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION,
            hadoopConfiguration.getOutputLocation() + "_");
    return HadoopGraph.open(newConfiguration);
}

From source file:org.apache.tinkerpop.gremlin.hadoop.structure.util.ConfUtil.java

public static org.apache.commons.configuration.Configuration makeApacheConfiguration(
        final Configuration hadoopConfiguration) {
    final BaseConfiguration apacheConfiguration = new BaseConfiguration();
    apacheConfiguration.setDelimiterParsingDisabled(true);
    hadoopConfiguration.iterator()/*from  w ww. ja  va  2s.c  o m*/
            .forEachRemaining(e -> apacheConfiguration.setProperty(e.getKey(), e.getValue()));
    return apacheConfiguration;
}

From source file:org.apache.tinkerpop.gremlin.hadoop.structure.util.HadoopHelper.java

public static HadoopGraph getOutputGraph(final HadoopGraph hadoopGraph,
        final GraphComputer.ResultGraph resultGraph, final GraphComputer.Persist persist) {
    final BaseConfiguration newConfiguration = new BaseConfiguration();
    newConfiguration.copy(hadoopGraph.configuration());
    if (resultGraph.equals(GraphComputer.ResultGraph.NEW)) {
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION,
                hadoopGraph.configuration().getOutputLocation() + "/" + Constants.HIDDEN_G);
        if (hadoopGraph.configuration().containsKey(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT))
            newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT, InputOutputHelper
                    .getInputFormat(hadoopGraph.configuration().getGraphOutputFormat()).getCanonicalName());
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION,
                hadoopGraph.configuration().getOutputLocation() + "_");
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT_HAS_EDGES,
                persist.equals(GraphComputer.Persist.EDGES));
    } else {/*from  w  w w.java 2s.  c  o m*/
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION,
                hadoopGraph.configuration().getOutputLocation() + "_");
    }
    return HadoopGraph.open(newConfiguration);
}

From source file:org.apache.tinkerpop.gremlin.spark.AbstractSparkTest.java

protected Configuration getBaseConfiguration() {
    final BaseConfiguration configuration = new BaseConfiguration();
    configuration.setDelimiterParsingDisabled(true);
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty(Constants.SPARK_SERIALIZER, GryoSerializer.class.getCanonicalName());
    configuration.setProperty("spark.kryo.registrationRequired", true);
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    return configuration;
}