public LocalId toLocalId() { return new LocalId(language, localId); }
@Override public Set<LocalId> getFromSource(Language sourceLang, int sourceId) throws DaoException { LocalId localId = new LocalId(sourceLang, sourceId); return getFromSource(localId); }
@Override public Map<Integer, Integer> getNumViews(Language lang, Iterable<Integer> ids, DateTime startTime, DateTime endTime) throws ConfigurationException, DaoException{ Map<Integer, Integer> result = new HashMap<Integer, Integer>(); for(Integer id: ids){ result.put(id, getNumViews(new LocalId(lang, id), startTime, endTime)); } return result; } @Override
public static LocalId fromInt(int packed) { int languageId = packed >>> 26; if (languageId < 0 || languageId > MAX_PACKED_ID) throw new IllegalArgumentException("illegal languageId: " + languageId + " in " + packed); int id = packed & MAX_PACKED_ID; return new LocalId(Language.getById(languageId), id); }
@Override public Map<Integer, Integer> getNumViews(Language lang, Iterable<Integer> ids, DateTime startTime, DateTime endTime) throws ConfigurationException, DaoException{ Map<Integer, Integer> result = new HashMap<Integer, Integer>(); for(Integer id: ids){ result.put(id, getNumViews(new LocalId(lang, id), startTime, endTime)); } return result; } @Override
public static LocalId fromLong(long packed) { long languageId = packed >>> 32; long id = packed & MAX_PACKED_ID; return new LocalId(Language.getById((int)languageId), (int)id); }
@Override public int getNumViews(Language lang, int pageId, DateTime startDate, DateTime endDate) throws DaoException { return getNumViews(new LocalId(lang, pageId), startDate, endDate); }
@Override public Set<LocalId> getToDest(Language destLang, int destId) throws DaoException { return getToDest(new LocalId(destLang, destId)); }
@Override public Set<LocalId> getFromSource(Language sourceLang, int sourceId) throws DaoException { return getFromSource(new LocalId(sourceLang, sourceId)); }
@Override public Set<LocalId> getToDest(Language destLang, int destId) throws DaoException { return getToDest(new LocalId(destLang, destId)); }
@Override public int getNumViews(Language lang, int pageId, DateTime startDate, DateTime endDate) throws DaoException { return getNumViews(new LocalId(lang, pageId), startDate, endDate); }
@Override public LinkedHashMap<LocalId, Float> resolve(Language language, String phrase, int maxPages) throws DaoException { LinkedHashMap<LocalId, Float> result = new LinkedHashMap<LocalId, Float>(); if (maxPages < 1) return result; int pageId = lpDao.getIdByTitle(new Title(phrase, language)); if (pageId >= 0) { result.put(new LocalId(language, pageId), 1.0f); } return result; }
@Override public int getNumViews(Language lang, int pageId, DateTime startDate, int numberOfHours) throws DaoException { return getNumViews(new LocalId(lang, pageId), startDate, startDate.plusHours(numberOfHours)); }
@Override public int getNumViews(Language lang, int pageId, DateTime startDate, int numberOfHours) throws DaoException { return getNumViews(new LocalId(lang, pageId), startDate, startDate.plusHours(numberOfHours)); }
@Override public Set<LocalId> pagesWithValue(String propertyName, WikidataValue value, Language language) throws DaoException { Set<LocalId> ids = new HashSet<LocalId>(); for (int conceptId : conceptsWithValue(propertyName, value)) { UniversalPage up = upDao.getById(conceptId); if (up != null && up.isInLanguage(language)) { ids.add(new LocalId(language, up.getLocalId(language))); } } return ids; } @Override
@Override public Set<LocalId> pagesWithValue(String propertyName, WikidataValue value, Language language) throws DaoException { Set<LocalId> ids = new HashSet<LocalId>(); for (int conceptId : conceptsWithValue(propertyName, value)) { UniversalPage up = upDao.getById(conceptId); if (up != null && up.isInLanguage(language)) { ids.add(new LocalId(language, up.getLocalId(language))); } } return ids; } @Override
private LinkedHashMap<LocalId, Float> resolveTextual(String phrase, int n) { if (n == 0) { return new LinkedHashMap<LocalId, Float>(); } WikiBrainScoreDoc results[] = searcher.getQueryBuilderByLanguage(language) .setPhraseQuery(new TextFieldElements().addPlainText(), phrase) .setNumHits(n*2) .search(); double total = 0.0; for (WikiBrainScoreDoc doc : results) { total += doc.score; } LinkedHashMap<LocalId, Float> expanded = new LinkedHashMap<LocalId, Float>(); for (int i = 0; i < n && i < results.length; i++) { expanded.put(new LocalId(language, results[i].wpId), (float)(results[i].score / total)); } return expanded; }
protected PageView buildPageView(Record record) throws DaoException { if (record == null) { return null; } LocalId id = new LocalId( Language.getById(record.getValue(Tables.PAGEVIEW.LANG_ID)), record.getValue(Tables.PAGEVIEW.PAGE_ID) ); return new PageView( id, record.getValue(Tables.PAGEVIEW.TSTAMP), record.getValue(Tables.PAGEVIEW.NUM_VIEWS) ); }
protected PageView buildPageView(Record record) throws DaoException { if (record == null) { return null; } LocalId id = new LocalId( Language.getById(record.getValue(Tables.PAGEVIEW.LANG_ID)), record.getValue(Tables.PAGEVIEW.PAGE_ID) ); return new PageView( id, record.getValue(Tables.PAGEVIEW.TSTAMP), record.getValue(Tables.PAGEVIEW.NUM_VIEWS) ); }