public SRBuilder(Env env, String metricName) throws ConfigurationException { this(env, metricName, env.getDefaultLanguage()); }
public static void main(String args[]) throws ConfigurationException, DaoException, IOException { Env env = new EnvBuilder().build(); Configurator c = env.getConfigurator(); Language lang = env.getDefaultLanguage(); // simple english PhraseAnalyzer pa = c.get(PhraseAnalyzer.class, "anchortext"); LocalPageDao pageDao = c.get(LocalPageDao.class); LocalPage page = pageDao.getByTitle(new Title("Obama", lang), NameSpace.ARTICLE); System.out.println("description of " + page + ":"); // should resolve redirect to Barack Obama LinkedHashMap<String, Float> description = pa.describe(lang, page, 100); if (description == null) { System.out.println("\tno description!"); } else { for (String phrase : description.keySet()) { System.out.println("\t" + phrase + ": " + description.get(phrase)); } } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); // Get page Title title = new Title("Berlin", env.getDefaultLanguage()); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); System.out.println("Properties for " + title); // Show statements Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } } }
public static void main(String args[]) throws ConfigurationException, DaoException, IOException { Env env = new EnvBuilder().build(); Configurator c = env.getConfigurator(); Language lang = env.getDefaultLanguage(); // simple english PhraseAnalyzer pa = c.get(PhraseAnalyzer.class, "anchortext"); LocalPageDao pageDao = c.get(LocalPageDao.class); LocalPage page = pageDao.getByTitle(new Title("Obama", lang), NameSpace.ARTICLE); System.out.println("description of " + page + ":"); // should resolve redirect to Barack Obama LinkedHashMap<String, Float> description = pa.describe(lang, page, 100); if (description == null) { System.out.println("\tno description!"); } else { for (String phrase : description.keySet()) { System.out.println("\t" + phrase + ": " + description.get(phrase)); } } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); // Get page Title title = new Title("Berlin", env.getDefaultLanguage()); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); System.out.println("Properties for " + title); // Show statements Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Language lang = env.getDefaultLanguage(); SpatialDataDao spatialDao = env.getConfigurator().get(SpatialDataDao.class); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); UniversalPageDao conceptDao = env.getConfigurator().get(UniversalPageDao.class); SphericalDistanceMetric metric1 = new SphericalDistanceMetric(spatialDao); metric1.enableCache(true); GraphDistanceMetric metric2 = new GraphDistanceMetric(spatialDao, metric1); metric2.enableCache(true); Map<Integer, Geometry> points = spatialDao.getAllGeometriesInLayer("wikidata", Precision.LatLonPrecision.HIGH); List<Integer> ids = new ArrayList<Integer>(points.keySet()); Random random = new Random(); for (int i = 0; i < 1000; i++) { int univId1 = ids.get(random.nextInt(ids.size())); int univId2 = ids.get(random.nextInt(ids.size())); LocalPage page1 = pageDao.getById(lang, conceptDao.getLocalId(lang, univId1)); LocalPage page2 = pageDao.getById(lang, conceptDao.getLocalId(lang, univId2)); double distance = metric2.distance(points.get(univId1), points.get(univId2)); System.out.println("distance between " + page1 + " and " + page2 + " is " + distance); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Language lang = env.getDefaultLanguage(); SpatialDataDao spatialDao = env.getConfigurator().get(SpatialDataDao.class); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); UniversalPageDao conceptDao = env.getConfigurator().get(UniversalPageDao.class); SphericalDistanceMetric metric1 = new SphericalDistanceMetric(spatialDao); metric1.enableCache(true); GraphDistanceMetric metric2 = new GraphDistanceMetric(spatialDao, metric1); metric2.enableCache(true); Map<Integer, Geometry> points = spatialDao.getAllGeometriesInLayer("wikidata", Precision.LatLonPrecision.HIGH); List<Integer> ids = new ArrayList<Integer>(points.keySet()); Random random = new Random(); for (int i = 0; i < 1000; i++) { int univId1 = ids.get(random.nextInt(ids.size())); int univId2 = ids.get(random.nextInt(ids.size())); LocalPage page1 = pageDao.getById(lang, conceptDao.getLocalId(lang, univId1)); LocalPage page2 = pageDao.getById(lang, conceptDao.getLocalId(lang, univId2)); double distance = metric2.distance(points.get(univId1), points.get(univId2)); System.out.println("distance between " + page1 + " and " + page2 + " is " + distance); } } }
public static void main(String[] args) throws Exception{ // Initialize the WikiBrain environment and get the local page dao Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); Language simple = env.getDefaultLanguage(); // Retrieve the "milnewitten" sr metric for simple english SRMetric sr = conf.get( SRMetric.class, "prebuiltword2vec", "language", simple.getLangCode()); //Similarity between strings for (String phrase : Arrays.asList("Barack Obama", "US", "Canada", "vim")) { SRResultList similar = sr.mostSimilar(phrase, 3); List<String> pages = new ArrayList<String>(); for (int i = 0; i < similar.numDocs(); i++) { LocalPage page = lpDao.getById(simple, similar.getId(i)); pages.add((i+1) + ") " + page.getTitle()); } System.out.println("'" + phrase + "' is similar to " + StringUtils.join(pages, ", ")); } } }
public static void main(String[] args) throws Exception{ // Initialize the WikiBrain environment and get the local page dao Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); Language simple = env.getDefaultLanguage(); // Retrieve the "milnewitten" sr metric for simple english SRMetric sr = conf.get( SRMetric.class, "prebuiltword2vec", "language", simple.getLangCode()); //Similarity between strings for (String phrase : Arrays.asList("Barack Obama", "US", "Canada", "vim")) { SRResultList similar = sr.mostSimilar(phrase, 3); List<String> pages = new ArrayList<String>(); for (int i = 0; i < similar.numDocs(); i++) { LocalPage page = lpDao.getById(simple, similar.getId(i)); pages.add((i+1) + ") " + page.getTitle()); } System.out.println("'" + phrase + "' is similar to " + StringUtils.join(pages, ", ")); } } }
public static void main(String args[]) throws Exception { Language lang = env.getDefaultLanguage();
public static void main(String args[]) throws ConfigurationException, DaoException { // Get the pageview dao Env env = EnvBuilder.envFromArgs(args); PageViewDao viewDao = env.getConfigurator().get(PageViewDao.class); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); Language lang = env.getDefaultLanguage(); // Download and import pageview stats if necessary. DateTime start = new DateTime(2014, 8, 14, 11, 0, 0); DateTime end = new DateTime(2014, 8, 14, 23, 0, 0); viewDao.ensureLoaded(start, end, env.getLanguages()); // Retrieve counts for all pageviews TIntIntMap allViews = viewDao.getAllViews(lang, start, end); int pageIds[] = WpCollectionUtils.sortMapKeys(allViews, true); System.out.println("Top pageviews in " + lang); for (int i = 0; i < 10; i++) { LocalPage page = pageDao.getById(lang, pageIds[i]); int n = allViews.get(pageIds[i]); System.out.format("%d. %s (nviews=%d)\n", (i+1), page.getTitle(), n); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { // Get the pageview dao Env env = EnvBuilder.envFromArgs(args); PageViewDao viewDao = env.getConfigurator().get(PageViewDao.class); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); Language lang = env.getDefaultLanguage(); // Download and import pageview stats if necessary. DateTime start = new DateTime(2014, 8, 14, 11, 0, 0); DateTime end = new DateTime(2014, 8, 14, 23, 0, 0); viewDao.ensureLoaded(start, end, env.getLanguages()); // Retrieve counts for all pageviews TIntIntMap allViews = viewDao.getAllViews(lang, start, end); int pageIds[] = WpCollectionUtils.sortMapKeys(allViews, true); System.out.println("Top pageviews in " + lang); for (int i = 0; i < 10; i++) { LocalPage page = pageDao.getById(lang, pageIds[i]); int n = allViews.get(pageIds[i]); System.out.format("%d. %s (nviews=%d)\n", (i+1), page.getTitle(), n); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); UniversalPageDao univDao = conf.get(UniversalPageDao.class); Language lang = env.getDefaultLanguage(); // Show statements for berlin Title title = new Title("Berlin", lang); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); System.out.println("Properties for " + title); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } // Print out who was born in Berlin WikidataValue berlinEntity = WikidataValue.forItem(univDao.getUnivPageId(page)); for (WikidataStatement st : wdDao.getByValue("place of birth", berlinEntity)) { System.out.println(wdDao.getLocalStatement(lang, st).getFullStatement()); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); UniversalPageDao univDao = conf.get(UniversalPageDao.class); Language lang = env.getDefaultLanguage(); // Show statements for berlin Title title = new Title("Berlin", lang); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); System.out.println("Properties for " + title); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } // Print out who was born in Berlin WikidataValue berlinEntity = WikidataValue.forItem(univDao.getUnivPageId(page)); for (WikidataStatement st : wdDao.getByValue("place of birth", berlinEntity)) { System.out.println(wdDao.getLocalStatement(lang, st).getFullStatement()); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); // Get the default wikifier in the default language. Wikifier wikifier = env.getConfigurator().get( Wikifier.class, "websail", "language", env.getDefaultLanguage().getLangCode()); for (LocalLink link : wikifier.wikify(CORPUS)) { System.out.println("link is " + link.getAnchorText() + " is for " + pageDao.getById(link.getLanguage(), link.getDestId())); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); LocalPageDao pageDao = env.getConfigurator().get(LocalPageDao.class); // Get the default wikifier in the default language. Wikifier wikifier = env.getConfigurator().get( Wikifier.class, "websail", "language", env.getDefaultLanguage().getLangCode()); for (LocalLink link : wikifier.wikify(CORPUS)) { System.out.println("link is " + link.getAnchorText() + " is for " + pageDao.getById(link.getLanguage(), link.getDestId())); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { // Initialize the WikiBrain environment and get the local page dao Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); // Retrieve the "ensemble" sr metric for simple english SRMetric sr = conf.get( SRMetric.class, "milnewitten", "language", env.getDefaultLanguage().getLangCode()); //Similarity between strings String pairs[][] = new String[][] { { "cat", "kitty" }, { "Obama", "president" }, { "tires", "car" }, { "java", "computer" }, { "dog", "computer" }, }; ExplanationFormatter formatter= new ExplanationFormatter(lpDao); for (String pair[] : pairs) { SRResult s = sr.similarity(pair[0], pair[1], true); System.out.println(s.getScore() + ": '" + pair[0] + "', '" + pair[1] + "'"); for (Explanation e:s.getExplanations()) { // System.out.println(formatter.formatExplanation(e)); } } } }
public static void main(String args[]) throws ConfigurationException, DaoException { // Initialize the WikiBrain environment and get the local page dao Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); // Retrieve the "ensemble" sr metric for simple english SRMetric sr = conf.get( SRMetric.class, "milnewitten", "language", env.getDefaultLanguage().getLangCode()); //Similarity between strings String pairs[][] = new String[][] { { "cat", "kitty" }, { "Obama", "president" }, { "tires", "car" }, { "java", "computer" }, { "dog", "computer" }, }; ExplanationFormatter formatter= new ExplanationFormatter(lpDao); for (String pair[] : pairs) { SRResult s = sr.similarity(pair[0], pair[1], true); System.out.println(s.getScore() + ": '" + pair[0] + "', '" + pair[1] + "'"); for (Explanation e:s.getExplanations()) { // System.out.println(formatter.formatExplanation(e)); } } } }
Language lang = env.getDefaultLanguage(); WikidataDao wdd = env.getConfigurator().get(WikidataDao.class); LocalPageDao lpd = env.getConfigurator().get(LocalPageDao.class);
Language lang = env.getDefaultLanguage(); WikidataDao wdd = env.getConfigurator().get(WikidataDao.class); LocalPageDao lpd = env.getConfigurator().get(LocalPageDao.class);