Java Code Examples for play.inject.Injector#instanceOf()

The following examples show how to use play.inject.Injector#instanceOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinearUCBPredictorConfig.java    From samantha with MIT License 6 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    double alpha = 0.1;
    if (predictorConfig.asMap().containsKey("alpha")) {
        alpha = predictorConfig.getDouble("alpha");
    }
    double lambda = 1.0;
    if (predictorConfig.asMap().containsKey("lambda")) {
        lambda = predictorConfig.getDouble("lambda");
    }
    return new LinearUCBPredictorConfig(predictorConfig.getString("modelName"),
            feaExtConfigs, predictorConfig.getStringList("features"),
            predictorConfig.getInt("numMainFeatures"),
            predictorConfig.getString("labelName"),
            predictorConfig.getString("weightName"), daoConfigs, expanders, injector,
            predictorConfig.getConfig("onlineOptimizationMethod"),
            predictorConfig.getString("modelFile"),
            predictorConfig.getString("daoConfigKey"), lambda, alpha,
            predictorConfig.getStringList("evaluatorNames"), predictorConfig);
}
 
Example 2
Source File: ESBasedIndexerConfig.java    From samantha with MIT License 6 votes vote down vote up
static public IndexerConfig getIndexerConfig(Configuration indexerConfig,
                                             Injector injector) {
    ElasticSearchService elasticSearchService = injector
            .instanceOf(ElasticSearchService.class);
    String elasticSearchIndex = indexerConfig.getString("elasticSearchIndex");
    Configuration settingConfig = indexerConfig.getConfig("elasticSearchSetting");
    if (!elasticSearchService.existsIndex(elasticSearchIndex).isExists()) {
        elasticSearchService.createIndex(elasticSearchIndex, settingConfig);
    }
    Configuration mappingConfig = indexerConfig.getConfig("elasticSearchMapping");
    for (String typeName : mappingConfig.subKeys()) {
        if (!elasticSearchService.existsType(elasticSearchIndex, typeName)
                .isExists()) {
            elasticSearchService.putMapping(elasticSearchIndex, typeName,
                    mappingConfig.getConfig(typeName));
        }
    }
    return new ESBasedIndexerConfig(indexerConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get()),
            elasticSearchIndex, indexerConfig.getString("indexTypeKey"),
            indexerConfig.getString("indexType"),
            indexerConfig.getStringList("uniqueFields"),
            injector, indexerConfig.getString("daoConfigKey"),
            indexerConfig);
}
 
Example 3
Source File: ServerGlobal.java    From samantha with MIT License 6 votes vote down vote up
public void beforeStart(Application application) {
    Injector injector = application.injector();
    Configuration configuration = application.configuration();
    SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class);
    List<String> enabledEngines = configuration.getStringList(ConfigKey.ENGINES_ENABLED.get());
    Configuration samanthaConfig = configuration.getConfig(ConfigKey.SAMANTHA_BASE.get());
    for (String engine : enabledEngines) {
        Configuration engineConfig = samanthaConfig.getConfig(engine);
        List<String> schedulerNames = engineConfig.getStringList(ConfigKey.ENGINE_BEFORE_START_SCHEDULERS.get());
        if (schedulerNames != null) {
            for (String scheduler : schedulerNames) {
                RequestContext peudoReq = new RequestContext(Json.newObject(), engine);
                configService.getSchedulerConfig(scheduler, peudoReq).runJobs();
            }
        }
    }
}
 
Example 4
Source File: RegressionTreePredictorConfig.java    From samantha with MIT License 6 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    return new RegressionTreePredictorConfig(predictorConfig.getString("modelName"),
            feaExtConfigs, predictorConfig.getStringList("features"),
            predictorConfig.getString("labelName"),
            predictorConfig.getString("weightName"), daoConfigs, expanders, injector,
            injector.instanceOf(TreeLearningMethod.class),
            predictorConfig.getString("modelFile"),
            predictorConfig.getString("daoConfigKey"), predictorConfig);
}
 
Example 5
Source File: GBDTPredictorConfig.java    From samantha with MIT License 6 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    int maxIter = predictorConfig.getInt("maxNumTrees");
    StandardBoostingMethod boostingMethod = new StandardBoostingMethod(maxIter);
    return new GBDTPredictorConfig(predictorConfig.getString("modelName"),
            feaExtConfigs, predictorConfig.getStringList("features"),
            predictorConfig.getString("labelName"),
            predictorConfig.getString("weightName"), daoConfigs, expanders, injector,
            injector.instanceOf(TreeLearningMethod.class),
            predictorConfig.getStringList("groupKeys"),
            predictorConfig.getString("modelFile"),
            predictorConfig.getConfig("objectiveConfig"), boostingMethod,
            predictorConfig.getString("daoConfigKey"),
            predictorConfig);
}
 
Example 6
Source File: XGBoostPredictorConfig.java    From samantha with MIT License 6 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    int round = predictorConfig.getInt("numTrees");
    return new XGBoostPredictorConfig(predictorConfig.getString("modelName"),
            feaExtConfigs, predictorConfig.getStringList("features"),
            predictorConfig.getString("labelName"),
            predictorConfig.getString("weightName"), daoConfigs, expanders, injector,
            new XGBoostMethod(predictorConfig.getConfig("methodConfig").asMap(), round),
            predictorConfig.getString("modelFile"),
            predictorConfig.getString("daoConfigKey"), predictorConfig);
}
 
Example 7
Source File: NegativeSamplingExpander.java    From samantha with MIT License 6 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                         Injector injector, RequestContext requestContext) {
    ModelService modelService = injector.instanceOf(ModelService.class);
    SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class);
    configService.getPredictor(expanderConfig.getString("predictorName"), requestContext);
    AbstractLearningModel model = (AbstractLearningModel) modelService.getModel(
            requestContext.getEngineName(), expanderConfig.getString("modelName"));
    String keyPrefix = expanderConfig.getString("keyPrefix");
    if (keyPrefix == null) {
        keyPrefix = expanderConfig.getString("itemAttr");
    }
    return new NegativeSamplingExpander(
            expanderConfig.getString("itemAttr"),
            expanderConfig.getString("itemIndex"), keyPrefix,
            expanderConfig.getString("labelAttr"),
            expanderConfig.getStringList("fillInAttrs"),
            expanderConfig.getString("separator"),
            expanderConfig.getString("joiner"),
            expanderConfig.getInt("maxIdx"),
            expanderConfig.getInt("maxNumSample"), model);
}
 
Example 8
Source File: XGBoostGBCentPredictorConfig.java    From samantha with MIT License 5 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daosConfig = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    return new XGBoostGBCentPredictorConfig(predictorConfig.getString("modelName"),
            predictorConfig.getString("svdfeaModelName"), predictorConfig.getString("svdfeaPredictorName"),
            predictorConfig.getStringList("treeFeatures"), feaExtConfigs, daosConfig, expanders,
            predictorConfig.getConfig("methodConfig"), injector, predictorConfig.getString("modelFile"),
            predictorConfig.getString("daoConfigKey"), predictorConfig);
}
 
Example 9
Source File: PredictorBasedExpander.java    From samantha with MIT License 5 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                  Injector injector, RequestContext requestContext) {
    String predictorName = expanderConfig.getString("predictorName");
    SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class);
    Predictor predictor = configService.getPredictor(predictorName, requestContext);
    String joiner = expanderConfig.getString("joiner");
    if (joiner == null) {
        joiner = ",";
    }
    return new PredictorBasedExpander(predictor, expanderConfig.getString("scoreAttr"),
            expanderConfig.getString("scoresAttr"), joiner);
}
 
Example 10
Source File: RegressionTreeGBCentPredictorConfig.java    From samantha with MIT License 5 votes vote down vote up
public static PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector) {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daosConfig = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    return new RegressionTreeGBCentPredictorConfig(predictorConfig.getString("modelName"),
            predictorConfig.getString("svdfeaModelName"), predictorConfig.getString("svdfeaPredictorName"),
            predictorConfig.getStringList("treeFeatures"), predictorConfig.getStringList("groupKeys"),
            feaExtConfigs, daosConfig, expanders,
            predictorConfig.getConfig("methodConfig"), injector, predictorConfig.getString("modelFile"),
            predictorConfig.getString("daoConfigKey"), predictorConfig);
}
 
Example 11
Source File: RetrieverBasedExpander.java    From samantha with MIT License 5 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                         Injector injector, RequestContext requestContext) {
    String retrieverName = expanderConfig.getString("retrieverName");
    SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class);
    Retriever retriever = configService.getRetriever(retrieverName, requestContext);
    return new RetrieverBasedExpander(retriever);
}
 
Example 12
Source File: SVDFeaturePredictorConfig.java    From samantha with MIT License 5 votes vote down vote up
static public PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector)
        throws ConfigurationException {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    String dependPredictorName = null, dependPredictorModelName = null;
    if (predictorConfig.asMap().containsKey("dependPredictorName")) {
        dependPredictorName = predictorConfig.getString("dependPredictorName");
        dependPredictorModelName = predictorConfig.getString("dependPredictorModelName");
    }
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    List<String> evaluatorNames = new ArrayList<>();
    if (predictorConfig.asMap().containsKey("evaluatorNames")) {
        evaluatorNames = predictorConfig.getStringList("evaluatorNames");
    }
    return new SVDFeaturePredictorConfig(
            predictorConfig.getStringList("biasFeas"),
            predictorConfig.getStringList("ufactFeas"),
            predictorConfig.getStringList("ifactFeas"),
            predictorConfig.getStringList("groupKeys"),
            evaluatorNames,
            predictorConfig.getString("modelFile"),
            predictorConfig.getString("modelName"),
            predictorConfig.getString("labelName"),
            predictorConfig.getString("weightName"),
            predictorConfig.getInt("factDim"),
            predictorConfig.getConfig("onlineOptimizationMethod"),
            predictorConfig.getConfig("optimizationMethod"),
            predictorConfig.getConfig("objectiveConfig"),
            feaExtConfigs, daoConfigs,
            dependPredictorName,
            dependPredictorModelName, injector, expanders,
            predictorConfig.getString("daoConfigKey"),
            predictorConfig);
}
 
Example 13
Source File: ESQueryBasedRetrieverConfig.java    From samantha with MIT License 5 votes vote down vote up
static public RetrieverConfig getRetrieverConfig(Configuration retrieverConfig,
                                                 Injector injector)
        throws ConfigurationException {
    ElasticSearchService elasticSearchService = injector
            .instanceOf(ElasticSearchService.class);
    String elasticSearchIndex = retrieverConfig.getString("elasticSearchIndex");
    Configuration settingConfig = retrieverConfig.getConfig("elasticSearchSetting");
    if (!elasticSearchService.existsIndex(elasticSearchIndex).isExists()) {
        elasticSearchService.createIndex(elasticSearchIndex, settingConfig);
    }
    String elasticSearchScoreName = retrieverConfig.getString("elasticSearchScoreName");
    List<String> retrieveFields = retrieverConfig.getStringList("retrieveFields");
    Configuration mappingConfig = retrieverConfig.getConfig("elasticSearchMapping");
    for (String typeName : mappingConfig.subKeys()) {
        if (!elasticSearchService.existsType(elasticSearchIndex, typeName)
                .isExists()) {
            elasticSearchService.putMapping(elasticSearchIndex, typeName,
                    mappingConfig.getConfig(typeName));
        }
    }
    Boolean defaultMatchAll = retrieverConfig.getBoolean("defaultMatchAll", false);
    return new ESQueryBasedRetrieverConfig(retrieverConfig.getString("elasticSearchIndex"),
            elasticSearchScoreName, retrieverConfig.getString("retrieveType"),
            retrieveFields, retrieverConfig.getString("elasticSearchReqKey"),
            retrieverConfig.getString("setScrollKey"), defaultMatchAll,
            injector, retrieverConfig, retrieverConfig.getString("queryKey"),
            retrieverConfig.getStringList("matchFields"));
}
 
Example 14
Source File: RetrieverBasedItemFilterExpander.java    From samantha with MIT License 5 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                         Injector injector, RequestContext requestContext) {
    String retrieverName = expanderConfig.getString("retrieverName");
    SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class);
    Retriever retriever = configService.getRetriever(retrieverName, requestContext);
    boolean exclude = true;
    if (expanderConfig.asMap().containsKey("exclude")) {
        exclude = expanderConfig.getBoolean("exclude");
    }
    return new RetrieverBasedItemFilterExpander(retriever, expanderConfig.getStringList("itemAttrs"),
            exclude);
}
 
Example 15
Source File: RedisBasedJoinExpander.java    From samantha with MIT License 4 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                         Injector injector,
                                         RequestContext requestContext) {
    return new RedisBasedJoinExpander(expanderConfig.getConfigList("expandFields"),
            injector.instanceOf(RedisService.class));
}
 
Example 16
Source File: TensorFlowPredictorConfig.java    From samantha with MIT License 4 votes vote down vote up
static public PredictorConfig getPredictorConfig(Configuration predictorConfig,
                                                 Injector injector)
        throws ConfigurationException {
    FeaturizerConfigParser parser = injector.instanceOf(
            FeatureExtractorListConfigParser.class);
    Configuration daoConfigs = predictorConfig.getConfig(ConfigKey.ENTITY_DAOS_CONFIG.get());
    List<FeatureExtractorConfig> feaExtConfigs = parser.parse(predictorConfig
            .getConfig(ConfigKey.PREDICTOR_FEATURIZER_CONFIG.get()));
    List<Configuration> expanders = ExpanderUtilities.getEntityExpandersConfig(predictorConfig);
    List<String> evaluatorNames = new ArrayList<>();
    if (predictorConfig.asMap().containsKey("evaluatorNames")) {
        evaluatorNames = predictorConfig.getStringList("evaluatorNames");
    }
    List<Configuration> checkConfigs = predictorConfig.getConfigList("equalSizeChecks");
    List<List<String>> equalSizeChecks = new ArrayList<>();
    if (checkConfigs != null) {
        for (Configuration check : checkConfigs) {
            equalSizeChecks.add(check.getStringList("featuresWithEqualSizes"));
        }
    }
    return new TensorFlowPredictorConfig(
            predictorConfig.getStringList("groupKeys"),
            predictorConfig.getStringList("indexKeys"),
            equalSizeChecks, evaluatorNames,
            predictorConfig.getString("modelFile"),
            predictorConfig.getString("modelName"),
            feaExtConfigs, daoConfigs,
            predictorConfig.getConfig("methodConfig"),
            predictorConfig.getConfig("onlineMethodConfig"),
            injector, expanders,
            predictorConfig.getString("daoConfigKey"),
            predictorConfig.getString("predItemFea"),
            predictorConfig.getString("outputOper"),
            predictorConfig.getString("updateOper"),
            predictorConfig.getString("lossOper"),
            predictorConfig.getString("initOper"),
            predictorConfig.getString("topKOper"),
            predictorConfig.getString("topKId"),
            predictorConfig.getString("topKValue"),
            predictorConfig.getString("itemIndex"),
            predictorConfig.getString("graphDefFilePath"),
            predictorConfig.getString("modelExportDir"),
            predictorConfig);
}
 
Example 17
Source File: ESBasedJoinExpander.java    From samantha with MIT License 4 votes vote down vote up
public static EntityExpander getExpander(Configuration expanderConfig,
                                         Injector injector, RequestContext requestContext) {
    return new ESBasedJoinExpander(injector.instanceOf(ElasticSearchService.class),
            expanderConfig.getString("elasticSearchIndex"),
            expanderConfig.getConfigList("expandFields"));
}