public int getLocalId(Language language) { if (isInLanguage(language)) { return localEntities.get(language).iterator().next().getId(); } else { return -1; } }
@Override public void run() { while (true) { LocalId id = localIds.get(random.nextInt(localIds.size())); try { Iterable<LocalLink> cursor = dao.getLinks(id.getLanguage(), id.getId(), random.nextBoolean()); if (numRows.incrementAndGet() > 10000000) { return; } numCells.addAndGet(IteratorUtils.toList(cursor.iterator()).size()); } catch (DaoException e) { e.printStackTrace(); } } } }
@Override public Integer getItemId(LocalId localId) throws DaoException { return upDao.getUnivPageId(localId.getLanguage(), localId.getId()); }
@Override public Integer getItemId(LocalId localId) throws DaoException { return upDao.getUnivPageId(localId.getLanguage(), localId.getId()); }
@Override public void run() { while (true) { LocalId id = localIds.get(random.nextInt(localIds.size())); try { Iterable<LocalLink> cursor = dao.getLinks(id.getLanguage(), id.getId(), random.nextBoolean()); if (numRows.incrementAndGet() > 10000000) { return; } numCells.addAndGet(IteratorUtils.toList(cursor.iterator()).size()); } catch (DaoException e) { e.printStackTrace(); } } } }
@Override public LocalPage getById(LocalId localId) throws DaoException { return getById(localId.getLanguage(), localId.getId()); }
@Override public SRResult similarity(String phrase1, String phrase2, boolean explanations) throws DaoException { Language language = getLanguage(); List<LocalString> phrases = Arrays.asList( new LocalString(language, phrase1), new LocalString(language, phrase2)); // debugSimilarityDisambiguator(phrases); List<LocalId> resolutions = disambiguator.disambiguateTop(phrases, null); if (resolutions.get(0) == null || resolutions.get(1) == null) { return new SRResult(); } // LocalPage lp1 = localPageDao.getById(language, resolutions.get(0).getId()); // LocalPage lp2 = localPageDao.getById(language, resolutions.get(1).getId()); // System.out.println("resolved " + phrase1 + ", " + phrase2 + " to " + lp1 + ", " + lp2); return similarity(resolutions.get(0).getId(), resolutions.get(1).getId(), explanations); }
@Override public LocalPage getById(LocalId localId) throws DaoException { return getById(localId.getLanguage(), localId.getId()); }
@Override public double[][] cosimilarity(String[] phrases) throws DaoException { int ids[] = new int[phrases.length]; List<LocalString> localStringList = new ArrayList<LocalString>(); for (String phrase : phrases){ localStringList.add(new LocalString(getLanguage(), phrase)); } List<LocalId> localIds = disambiguator.disambiguateTop(localStringList, null); for (int i=0; i<phrases.length; i++){ ids[i] = localIds.get(i).getId(); } return cosimilarity(ids); }
public void call(KnownSim ks) throws IOException, DaoException { ks.maybeSwap(); List<LocalString> localStrings = new ArrayList<LocalString>(); localStrings.add(new LocalString(ks.language, ks.phrase1)); localStrings.add(new LocalString(ks.language, ks.phrase2)); List<LocalId> ids = disambiguator.disambiguateTop(localStrings, null); if (ids != null && ids.size() == 2 && ids.get(0) != null && ids.get(1) != null) { LocalId lid1 = ids.get(0); LocalId lid2 = ids.get(1); SRResultList dsl = metric.mostSimilar(lid1.getId(), maxResults, validIds); if (dsl != null) { trainee.observe(dsl, dsl.getIndexForId(lid2.getId()), ks.similarity); } } } }, 100);
/** * Calculates the PageRank associated with a particular page. * Currently only implemented by the MatrixLocalLinkDao. * PageRank estimation is performed lazily, so the first time this method is called * will be very expensive, and future invocations will be cached. * * @param localId * @return An estimate of the pageRank. The sum of PageRank values for all pages will * approximately sum to 1.0. */ @Override public double getPageRank(LocalId localId) { return getPageRank(localId.getLanguage(), localId.getId()); }
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); } }
private String getTitle(LocalId id) throws DaoException { return metric.getLocalPageDao().getById(language, id.getId()).getTitle().toString(); }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = new EnvBuilder().build(); Configurator configurator = env.getConfigurator(); UniversalPageDao pdao = configurator.get(UniversalPageDao.class); UniversalLinkDao ldao = configurator.get(UniversalLinkDao.class); LocalPageDao lpDao = configurator.get(LocalPageDao.class); int i = 0; for (UniversalPage page : (Iterable<UniversalPage>)pdao.get(new DaoFilter().setNameSpaces(NameSpace.ARTICLE))) { for (LocalId lId : page.getLocalEntities()){ LocalPage lPage = lpDao.getById(lId.getLanguage(), lId.getId()); System.out.println(lPage); } System.out.println(); i++; } System.out.println("Concept count: " + i); } }
@Override public void save(PageView view) throws DaoException { insert( view.getPageId().getLanguage().getId(), view.getPageId().getId(), view.getHour(), view.getViews() ); }
@Override public SRResultList mostSimilar(String phrase, int maxResults, TIntSet validIds) throws DaoException{ LocalId similar = disambiguator.disambiguateTop(new LocalString(getLanguage(), phrase), null); if (similar==null){ SRResultList resultList = new SRResultList(1); resultList.set(0, new SRResult()); return resultList; } return mostSimilar(similar.getId(), maxResults,validIds); }
@Override public SRResultList mostSimilar(String phrase, int maxResults) throws DaoException { LocalId similar = disambiguator.disambiguateTop(new LocalString(getLanguage(), phrase), null); if (similar==null){ SRResultList resultList = new SRResultList(1); resultList.set(0, new SRResult()); return resultList; } return mostSimilar(similar.getId(), maxResults); }
@Override public void save(PageView view) throws DaoException { insert( view.getPageId().getLanguage().getId(), view.getPageId().getId(), view.getHour(), view.getViews() ); }
@Override public void save(UniversalPage page) throws DaoException { NameSpace nameSpace = page.getNameSpace(); for (Language language : page.getLanguageSet()) { for (LocalId localPage : page.getLocalEntities(language)) { insert( language.getId(), localPage.getId(), nameSpace.getArbitraryId(), page.getUnivId(), page.getAlgorithmId() ); } } }