Tabnine Logo
Configurator
Code IndexAdd Tabnine to your IDE (free)

How to use
Configurator
in
org.wikibrain.conf

Best Java code snippets using org.wikibrain.conf.Configurator (Showing top 20 results out of 315)

origin: org.wikibrainapi/wikibrain-utils

/**
 * @see #get(Class, String, java.util.Map)
 * @param klass
 * @param name
 * @param <T>
 * @return
 * @throws ConfigurationException
 */
public <T> T get(Class<T> klass, String name) throws ConfigurationException {
  return get(klass, name, null);
}
origin: shilad/wikibrain

/**
 * Returns a default set of LuceneOptions.
 *
 * @return a default set of LuceneOptions
 */
public static LuceneOptions getDefaultOptions() {
  try {
    return new Configurator(new Configuration()).get(LuceneOptions.class, "plaintext");
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  }
}
origin: shilad/wikibrain

@Override
public String describeDisambiguator() {
  if (!config.hasPath("disambiguator")){
    return "none";
  }
  String disambigName = config.getString("disambiguator");
  try {
    Map dc = configurator.getConfig(Disambiguator.class, disambigName).root().unwrapped();
    String phraseName = null;
    if (dc.containsKey("phraseAnalyzer")) {
      phraseName = (String) dc.get("phraseAnalyzer");
    }
    if (phraseName == null || phraseName.equals("default")) {
      phraseName = configurator.getConf().get().getString("phrases.analyzer.default");
    }
    dc.put("phraseAnalyzer", phraseName);
    return disambigName + "=" + dc.toString();
  } catch (ConfigurationException e) {
    throw new IllegalStateException(e);
  }
}
origin: shilad/wikibrain

name = resolveComponentName(klass, name);
Config config = getConfig(klass, name);
Map<String, Object> cache = components.get(klass);
String key = makeCacheKey(name, runtimeParams);
synchronized (cache) {
  if (cache.containsKey(key)) {
    return (T) cache.get(key);
  } else {
    Pair<Provider, T> pair = constructInternal(klass, name, config, runtimeParams);
    if (pair.getLeft().getScope() == Provider.Scope.SINGLETON) {
      cache.put(key, pair.getRight());
origin: shilad/wikibrain

  @Override
  public PhraseAnalyzer get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException {
    if (!config.getString("type").equals("anchortext")) {
      return null;
    }
    PhraseAnalyzerDao paDao = getConfigurator().construct(
        PhraseAnalyzerDao.class, name, config.getConfig("dao"),
        new HashMap<String, String>());
    LocalPageDao lpDao = getConfigurator().get(LocalPageDao.class, config.getString("localPageDao"));
    LocalLinkDao llDao = getConfigurator().get(LocalLinkDao.class, config.getString("localLinkDao"));
    PrunedCounts.Pruner<String> phrasePruner = getConfigurator().construct(
        PrunedCounts.Pruner.class, null, config.getConfig("phrasePruner"), null);
    PrunedCounts.Pruner<Integer> pagePruner = getConfigurator().construct(
        PrunedCounts.Pruner.class, null, config.getConfig("pagePruner"), null);
    return new AnchorTextPhraseAnalyzer(paDao, lpDao, llDao, phrasePruner, pagePruner);
  }
}
origin: shilad/wikibrain

  protected static void configureBase(Configurator configurator, BaseSRMetric sr, Config config) throws ConfigurationException {
    Config rootConfig = configurator.getConf().get();

    File path = new File(rootConfig.getString("sr.metric.path"));
    sr.setDataDir(FileUtils.getFile(path, sr.getName(), sr.getLanguage().getLangCode()));

    // initialize normalizers
    sr.setSimilarityNormalizer(configurator.get(Normalizer.class, config.getString("similaritynormalizer")));
    sr.setMostSimilarNormalizer(configurator.get(Normalizer.class, config.getString("mostsimilarnormalizer")));

    boolean isTraining = rootConfig.getBoolean("sr.metric.training");
    if (isTraining) {
      sr.setReadNormalizers(false);
    }
    if (config.hasPath("buildMostSimilarCache")) {
      sr.setBuildMostSimilarCache(config.getBoolean("buildMostSimilarCache"));
    }

    try {
      sr.read();
    } catch (IOException e){
      throw new ConfigurationException(e);
    }
    LOG.info("finished base configuration of metric " + sr.getName());
  }
}
origin: org.wikibrainapi/wikibrain-loader

  @Override
  public boolean runDiagnostic(PrintWriter writer) {
    Config config = null;
    try {
      config = env.getConfigurator().getConfig(WpDataSource.class, null);
    } catch (ConfigurationException e) {
      throw new IllegalStateException(e);
    }
    boolean passed = true;
    try {
      WpDataSource ds = env.getConfigurator().get(WpDataSource.class);
      ds.getConnection().close();
      writer.write("Connection to database succeeded. Active configuration:\n");
    } catch (Exception e) {
      writer.write("Connection to database FAILED! Active configuration:\n");
      passed = false;
    }
    for (Map.Entry<String, ConfigValue > entry : config.entrySet()) {
      writer.write("\t" + entry.getKey() + ": " + entry.getValue().render() + "\n");
    }
    return passed;
  }
}
origin: shilad/wikibrain

public Config getMetricConfig(String name) throws ConfigurationException {
  return env.getConfigurator().getConfig(SRMetric.class, name);
}
origin: shilad/wikibrain

Configurator conf = env.getConfigurator();
List argList = Arrays.asList(conf.getConf().get().getString("download.listFile"));
String filePath = cmd.getOptionValue('o', conf.getConf().get().getString("download.path"));
if (cmd.hasOption("i")) {
  argList = Arrays.asList(cmd.getOptionValues("i"));
origin: shilad/wikibrain

configurator = new Configurator(configuration);
origin: shilad/wikibrain

public SRBuilder(Env env, String metricName, Language language) throws ConfigurationException {
  this.env = env;
  this.language = language;
  this.config = env.getConfiguration();
  this.srDir = new File(config.get().getString("sr.metric.path"));
  datasetNames = config.get().getStringList("sr.dataset.defaultsets");
  // Properly resolve the default metric name.
  this.metricName = env.getConfigurator().resolveComponentName(SRMetric.class, metricName);
  if (!srDir.isDirectory()) {
    srDir.mkdirs();
  }
}
origin: shilad/wikibrain

@Override
public SRMetric create() {
  try {
    Map<String, String> runtimeParams = new HashMap<String, String>();
    runtimeParams.put("language", language.getLangCode());
    return configurator.construct(SRMetric.class, name, config, runtimeParams);
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  }
}
origin: shilad/wikibrain

  @Override
  public PhraseAnalyzer get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException {
    if (!config.getString("type").equals("stanford")) {
      return null;
    }
    PhraseAnalyzerDao paDao = getConfigurator().construct(
        PhraseAnalyzerDao.class, name, config.getConfig("dao"),
        new HashMap<String, String>());
    LocalPageDao lpDao = getConfigurator().get(LocalPageDao.class, config.getString("localPageDao"));
    File path = new File(config.getString("path"));
    PrunedCounts.Pruner<String> phrasePruner = getConfigurator().construct(
        PrunedCounts.Pruner.class, null, config.getConfig("phrasePruner"), null);
    PrunedCounts.Pruner<Integer> pagePruner = getConfigurator().construct(
        PrunedCounts.Pruner.class, null, config.getConfig("pagePruner"), null);
    return new StanfordPhraseAnalyzer(paDao, lpDao, phrasePruner, pagePruner, path);
  }
}
origin: org.wikibrainapi/wikibrain-wikidata

File path = new File(conf.getConf().getFile("download.path"), "wikidata.json.bz2");
if (!path.isFile()) {
  File tf = File.createTempFile("wikidata.json", null);
WikidataDao wdDao = conf.get(WikidataDao.class);
UniversalPageDao upDao = conf.get(UniversalPageDao.class);
MetaInfoDao metaDao = conf.get(MetaInfoDao.class);
LanguageSet langs = conf.get(LanguageSet.class);
origin: shilad/wikibrain

  @Override
  public boolean runDiagnostic(PrintWriter writer) {
    Config config = null;
    try {
      config = env.getConfigurator().getConfig(WpDataSource.class, null);
    } catch (ConfigurationException e) {
      throw new IllegalStateException(e);
    }
    boolean passed = true;
    try {
      WpDataSource ds = env.getConfigurator().get(WpDataSource.class);
      ds.getConnection().close();
      writer.write("Connection to database succeeded. Active configuration:\n");
    } catch (Exception e) {
      writer.write("Connection to database FAILED! Active configuration:\n");
      passed = false;
    }
    for (Map.Entry<String, ConfigValue > entry : config.entrySet()) {
      writer.write("\t" + entry.getKey() + ": " + entry.getValue().render() + "\n");
    }
    return passed;
  }
}
origin: org.wikibrainapi/wikibrain-utils

name = resolveComponentName(klass, name);
Config config = getConfig(klass, name);
Map<String, Object> cache = components.get(klass);
String key = makeCacheKey(name, runtimeParams);
synchronized (cache) {
  if (cache.containsKey(key)) {
    return (T) cache.get(key);
  } else {
    Pair<Provider, T> pair = constructInternal(klass, name, config, runtimeParams);
    if (pair.getLeft().getScope() == Provider.Scope.SINGLETON) {
      cache.put(key, pair.getRight());
origin: shilad/wikibrain

/**
 * Constructs a new factory that creates an sr metric with a particular name from the config
 * file. The overrides take precedence over any configuration parameters, and are relative to
 * the innermost configuration block for an SR metric (i.e. the nested dictionary with key
 * the name of the metric).
 *
 * @param language
 * @param configurator
 * @param name Name of metric from configuration file
 * @param configOverrides Optional configuration overrides, or null.
 * @throws ConfigurationException
 */
public ConfigMonolingualSRFactory(Language language, Configurator configurator, String name, Map<String, Object> configOverrides) throws ConfigurationException {
  this.config = ConfigFactory.empty();
  if (configOverrides != null) {
    config = config.withFallback(ConfigFactory.parseMap(configOverrides));
  }
  config = config.withFallback(configurator.getConfig(SRMetric.class, name));
  this.configurator = configurator;
  this.name = name;
  this.language = language;
}
origin: shilad/wikibrain

  linkMatchers = FileMatcher.getListByNames(conf.getConf().get().getStringList("download.matcher"));
String filePath = conf.getConf().get().getString("download.listFile");
if (cmd.hasOption('o')) {
  filePath = cmd.getOptionValue('o');
origin: org.wikibrainapi/wikibrain-utils

/**
 * Returns the config object associated with the given class and name.
 * @param klass The generic interface or superclass, not the specific implementation.
 * @param name The name of the class as it appears in the config file. If name is null,
 *             the configurator tries to guess by looking for a "default" entry in
 *             the config that provides the name for a default implementation or, if
 *             there is exactly one implementation returning it. Otherwise, if name is
 *             null it throws an error.
 * @return The requested config object.
 * @throws ConfigurationException
 */
public Config getConfig(Class klass, String name) throws ConfigurationException {
  if (!providers.containsKey(klass)) {
    throw new ConfigurationException("No registered providers for components with class " + klass);
  }
  ProviderSet pset = providers.get(klass);
  name = resolveComponentName(klass, name);
  String path = pset.path + "." + name;
  if (!conf.get().hasPath(path)) {
    throw new ConfigurationException("Configuration path " + path + " does not exist");
  }
  return conf.get().getConfig(path);
}
origin: org.wikibrainapi/wikibrain-utils

/**
 * Get a specific named instance of the component with the specified class.
 * This method can only be used when there is exactly one instance of the component.
 *
 * @param klass The generic interface or superclass, not the specific implementation.
 * @return The requested component.
 */
public <T> T get(Class<T> klass) throws ConfigurationException {
  return get(klass, null);
}
org.wikibrain.confConfigurator

Javadoc

Binds together providers for a collection of components. A component is uniquely identified by two elements: 1. A superclass or interface (e.g. DataSource). 2. A name (e.g. 'foo'). So there can be multiple instances of the same component type as long as they are uniquely named. The configurator scans the class path for all classes that extend org.wikibrain.conf.Provider. This configurator will instantiate the provider and ask it what class it provides (Provider.getType) and what path of the configuration it handles along (Provider.getPath()). For example, let's say that there are two different providers for DataSource: MySqlDataSourceProvider and H2DataSourceProvider. Both their Provider.getType() methods must return javax.sql.DataSource and both their Provider.getPath() methods must return "dao.dataSource". Given the following config: ... some top-level elements... 'dao' : 'dataSource' : { 'foo' : { ... config params for foo impl ... }, 'bar' : { ... config params for bar impl ... }, } If a client requests the local page dao named 'foo', the configurator iterates through the two providers passing '{ ... config params for foo .. }' until a provider accepts and generates the requested DataSource. A special optional key named 'default' has a value corresponding to the name of implementation that should be used for the version of get() that does not take a name. For example, if the dataSource hashtable above had entry 'default' : 'bar', the 'bar' entry would be used by default if no name was supplied to the get() method. All generated components are considered singletons. Once a named component is generated once, it is cached and reused for future requests.

Most used methods

  • get
    Get a specific named instance of the component with the specified class.
  • <init>
    Constructs a new configuration object with the specified configuration.
  • getConf
  • getConfig
    Returns the config object associated with the given class and name.
  • construct
    Constructs an instance of the specified class with the passed in config. This bypasses the cache and
  • resolveComponentName
    If the component name is "default" or null, return the name of the default implementation of the com
  • close
    Tries to close all open components, clears the components map.
  • constructInternal
  • makeCacheKey
    Returns a unique string for the name and params
  • registerProvider
    Instantiates providers for the component.
  • registerProviders
    Registers all class that extend Providers
  • registerProviders

Popular in Java

  • Creating JSON documents from java classes using gson
  • putExtra (Intent)
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now