@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); } }
@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); } }
@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); } }
@Override public SRMetric get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sparsevector")) { return null; } if (runtimeParams == null || !runtimeParams.containsKey("language")){ throw new IllegalArgumentException("Monolingual requires 'language' runtime parameter."); } Language language = Language.getByLangCode(runtimeParams.get("language")); Map<String, String> params = new HashMap<String, String>(); params.put("language", language.getLangCode()); SparseVectorGenerator generator = getConfigurator().construct( SparseVectorGenerator.class, null, config.getConfig("generator"), params); VectorSimilarity similarity = getConfigurator().construct( VectorSimilarity.class, null, config.getConfig("similarity"), params); SparseVectorSRMetric sr = new SparseVectorSRMetric( name, language, getConfigurator().get(LocalPageDao.class,config.getString("pageDao")), getConfigurator().get(Disambiguator.class,config.getString("disambiguator"),"language", language.getLangCode()), generator, similarity ); configureBase(getConfigurator(), sr, config); return sr; }
Map<String, String> params = new HashMap<String, String>(); params.put("language", language.getLangCode()); SparseVectorGenerator generator = getConfigurator().construct( SparseVectorGenerator.class, null, config.getConfig("generator"), params); VectorSimilarity similarity = getConfigurator().construct( VectorSimilarity.class, null, config.getConfig("similarity"), params); FancyPhraseVectorBasedSRMetric sr = new FancyPhraseVectorBasedSRMetric( generator, similarity, getConfigurator().construct( PhraseVectorCreator.class, null, config.getConfig("phrases"), null) );
@Override public Disambiguator get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException{ if (!config.getString("type").equals("similarity")){ return null; } if (runtimeParams == null || !runtimeParams.containsKey("language")){ throw new IllegalArgumentException("SimpleMilneWitten requires 'language' runtime parameter."); } Language lang = Language.getByLangCode(runtimeParams.get("language")); PhraseAnalyzer pa = getConfigurator().get(PhraseAnalyzer.class, config.getString("phraseAnalyzer")); // Create override config for sr metric and load it. String srName = config.getString("metric"); Config newConfig = getConfig().get().getConfig("sr.metric.local." + srName) .withValue("disambiguator", ConfigValueFactory.fromAnyRef("topResult")); Map<String, String> srRuntimeParams = new HashMap<String, String>(); srRuntimeParams.put("language", lang.getLangCode()); SRMetric sr = getConfigurator().construct(SRMetric.class, srName, newConfig, srRuntimeParams); SimilarityDisambiguator dab = new SimilarityDisambiguator(pa, sr); if (config.hasPath("criteria")) { dab.setCriteria(Criteria.valueOf(config.getString("criteria").toUpperCase())); } return dab; } }
@Override public SRMetric get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("densevector")) { return null; } if (runtimeParams == null || !runtimeParams.containsKey("language")){ throw new IllegalArgumentException("Monolingual requires 'language' runtime parameter."); } Language language = Language.getByLangCode(runtimeParams.get("language")); Map<String, String> params = new HashMap<String, String>(); params.put("language", language.getLangCode()); DenseVectorGenerator generator = getConfigurator().construct( DenseVectorGenerator.class, null, config.getConfig("generator"), params); DenseVectorSRMetric sr = new DenseVectorSRMetric( name, language, getConfigurator().get(LocalPageDao.class,config.getString("pageDao")), getConfigurator().get(Disambiguator.class,config.getString("disambiguator"),"language", language.getLangCode()), generator ); configureBase(getConfigurator(), sr, config); return sr; }
@Override public Disambiguator get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException{ if (!config.getString("type").equals("milnewitten")){ return null; } if (runtimeParams == null || !runtimeParams.containsKey("language")){ throw new IllegalArgumentException("SimpleMilneWitten requires 'language' runtime parameter."); } Language lang = Language.getByLangCode(runtimeParams.get("language")); PhraseAnalyzer pa = getConfigurator().get(PhraseAnalyzer.class, config.getString("phraseAnalyzer")); LocalPageDao pageDao = getConfigurator().get(LocalPageDao.class); // Create override config for sr metric and load it. String srName = config.getString("metric"); Config newConfig = getConfig().get().getConfig("sr.metric.local." + srName) .withValue("disambiguator", ConfigValueFactory.fromAnyRef("topResult")); Map<String, String> srRuntimeParams = new HashMap<String, String>(); srRuntimeParams.put("language", lang.getLangCode()); SRMetric sr = getConfigurator().construct(SRMetric.class, srName, newConfig, srRuntimeParams); try { return new MilneWittenDisambiguator(pageDao, pa, sr); } catch (DaoException e) { throw new ConfigurationException(e); } } }