/** * Returns true iff UniversalEntity has page in input language. * @param language * @return True if UniversalEntity has page in input language, false otherwise. */ public boolean isInLanguage(Language language){ return languages.containsLanguage(language); }
public LanguageSet getLanguageSet() { return new LanguageSet(searchers.keySet()); }
public QualitativeAnalyzer(Env env) { this.env = env; this.language = env.getLanguages().getDefaultLanguage(); }
@Override public void save(UniversalLink item) throws DaoException { try { int sourceId = item.getSourceId(); int destId = item.getDestId(); LanguageSet languages = item.getLanguageSet(); String key = sourceId + "_" + destId + "_" + item.getAlgorithmId(); byte[] temp = objectDb.get(key); if (temp != null) { languages = new LanguageSet(Sets.union(LanguageSet.getLanguageSet(temp).getLanguages(), languages.getLanguages())); } objectDb.put(key, languages.toByteArray()); } catch (IOException e) { throw new DaoException(e); } catch (ClassNotFoundException e) { throw new DaoException(e); } }
/** * Returns English if English is in the set, else returns Simple. If Simple is not in the * set, will return the default language or throws an exception, depending on the value of returnDefaultLangIfEnglishNotAvailable * @return * @throws WikiBrainException */ public Language getBestAvailableEnglishLang(boolean returnDefaultLangIfEnglishNotAvailable) throws WikiBrainException { if (this.containsLanguage(Language.getByLangCode("en"))){ return Language.getByLangCode("en"); }else if (this.containsLanguage(Language.getByLangCode("simple"))){ return Language.getByLangCode("simple"); }else{ if (returnDefaultLangIfEnglishNotAvailable){ return this.getDefaultLanguage(); } throw new WikiBrainException("No English language available"); } }
for(Language lang : langs.getLanguages()){ langIdEnsembleSRMetricMap.put(new Integer(lang.getId()), c.get(SRMetric.class, "ensemble", "language", lang.getLangCode())); langIdInlinkSRMetricMap.put(new Integer(lang.getId()), c.get(SRMetric.class, "inlink", "language", lang.getLangCode())); LOG.info(String.format("Finish building name mapping for %d items", counter1)); boolean containAllLanguage = true; for(Language language : langs.getLanguages()){ if(! lpDao.getLoadedLanguages().containsLanguage(language)){ throw new DaoException(String.format("Language %s not loaded", language.getEnLangName())); String name = wdDao.getItem(wdItem).getLabels().get(langs.getDefaultLanguage()); if(name == null) continue; int lang_counter = 0; List<Language> langList = new ArrayList<Language>(); for(Language language : langs.getLanguages()) langList.add(language); for(Language language : langList){
/** * Sets the language filter to the specified LanguageSet. * Used by LocalPage, RawPage, LocalLink, Redirect, and LocalCategoryMember. * @param languages * @return */ public DaoFilter setLanguages(LanguageSet languages) { return setLanguages(languages.getLanguages()); }
/** * Returns the number of languages in which this UniversalEntity exists. * @return */ public int getNumberOfLanguages(){ return languages.size(); }
public Title getBestEnglishTitle(LocalPageDao lpDao, boolean returnRandomLangIfEnglishNotAvailable) throws WikiBrainException { try { Language lang = getLanguageSet().getBestAvailableEnglishLang(returnRandomLangIfEnglishNotAvailable); LocalPage lp = lpDao.getById(lang, getLocalEntities(lang).iterator().next().getId()); return lp.getTitle(); }catch(DaoException e){ throw new WikiBrainException(e); } }
@Override public String toString(){ return "(" + getLangCodeString() + ")"; }
public EnvBuilder setLanguages(LanguageSet langs) { params.put("languages.default", "manual"); params.put("languages.manual.langCodes", langs.getLangCodes()); return this; }
for(Language lang : langs.getLanguages()){ langIdEnsembleSRMetricMap.put(new Integer(lang.getId()), c.get(SRMetric.class, "ensemble", "language", lang.getLangCode())); langIdInlinkSRMetricMap.put(new Integer(lang.getId()), c.get(SRMetric.class, "inlink", "language", lang.getLangCode())); LOG.info(String.format("Finish building name mapping for %d items", counter1)); boolean containAllLanguage = true; for(Language language : langs.getLanguages()){ if(! lpDao.getLoadedLanguages().containsLanguage(language)){ throw new DaoException(String.format("Language %s not loaded", language.getEnLangName())); String name = wdDao.getItem(wdItem).getLabels().get(langs.getDefaultLanguage()); if(name == null) continue; int lang_counter = 0; List<Language> langList = new ArrayList<Language>(); for(Language language : langs.getLanguages()) langList.add(language); for(Language language : langList){
public ToblersLawEvaluator(Env env, LanguageSet languages) throws ConfigurationException { this.env = env; //this.langs = new ArrayList<Language>(env.getLanguages().getLanguages()); langs = new ArrayList<Language>(); for(Language lang : languages.getLanguages()) langs.add(lang); // Get data access objects Configurator c = env.getConfigurator(); this.sdDao = c.get(SpatialDataDao.class); this.lpDao = c.get(LocalPageDao.class); this.upDao = c.get(UniversalPageDao.class); // build SR metrics this.metrics = new HashMap<Language, SRMetric>(); for(Language lang : langs){ SRMetric m = c.get(SRMetric.class, "ensemble", "language", lang.getLangCode()); metrics.put(lang, m); } }
public PipelineLoader(Env env, List<StageArgs> args) throws ConfigurationException, DaoException, ClassNotFoundException, InterruptedException { MetaInfoDao metaDao = env.getConfigurator().get(MetaInfoDao.class); this.langs = env.getLanguages(); this.state = metaDao.getAllCummulativeInfo(); // this.diagnosticDao = env.getConfigurator().get(DiagnosticDao.class); initConfig(env.getConfiguration()); if (args == null) { if (langs.size() == 0) { throw new IllegalArgumentException("No languages specified to pipeline loader"); } else if (langs.size() == 1) { args = Arrays.asList(new StageArgs(DEFAULT_GROUP, true, null)); } else { args = Arrays.asList(new StageArgs(MULTILINGUAL_GROUP, true, null)); } } setStageArguments(args); }
public WikidataValueScorer(Env env, Config conf) throws ConfigurationException { super(env, conf); try { wikidataDao = env.getConfigurator().get(WikidataDao.class); columnName = conf.getString("column"); Language lang = env.getLanguages().getBestAvailableEnglishLang(false); WikidataEntity prop = wikidataDao.getProperty(lang, conf.getString("property")); if (prop == null) { throw new IllegalArgumentException("Couldn't find property with name " + conf.getString("property")); } propertyId = prop.getId(); } catch (WikiBrainException e) { throw new ConfigurationException(e); } catch (DaoException e) { throw new ConfigurationException(e); } }
diagnostic.getStage(), diagnostic.getDate().toString(), diagnostic.getLangs().getLangCodeString(), diagnostic.getElapsedSeconds(), diagnostic.getSingleCoreSpeed(), object.put("stage", diagnostic.getStage()); object.put("date", diagnostic.getDate()); object.put("langs", diagnostic.getLangs().getLangCodeString()); object.put("elapsed", diagnostic.getElapsedSeconds()); object.put("singleCoreSpeed", diagnostic.getSingleCoreSpeed());
public WikiTextParser(LanguageInfo lang, LanguageSet allowedIllLangs, List<ParserVisitor> visitors) { this.lang = lang; subarticleParser = new SubarticleParser(lang); this.visitors = visitors; MediaWikiParserFactory pf = new MediaWikiParserFactory(); pf.setCalculateSrcSpans(true); pf.setCategoryIdentifers(lang.getCategoryNames()); if (allowedIllLangs != null) { pf.setLanguageIdentifers(allowedIllLangs.getLangCodes()); } jwpl = pf.createParser(); }
public AbstractUniversalEntity(int algorithmId, Multimap<Language, T> localEntities) { this.algorithmId = algorithmId; this.localEntities = localEntities; List<Language> langs = new ArrayList<Language>(localEntities.keySet()); Collections.sort(langs); this.languages = new LanguageSet(langs); }
private void pruneSet(Collection<Language> set, LanguageSet keepers) { Iterator<Language> iter = set.iterator(); while (iter.hasNext()) { Language l = iter.next(); if (!keepers.containsLanguage(l)) { iter.remove(); } } }
public Language getDefaultLanguage() { return getLanguages().getDefaultLanguage(); }