/** * Serializes the graph to the given destination. * @param destination The destination to which should be saved. * @throws WikiApiException Thrown if errors occurred. */ public void saveGraph(String destination) throws WikiApiException { try { GraphSerialization.saveGraph(graph, destination); } catch (IOException e) { throw new WikiApiException(e); } }
private void initializeCategoryGraph() throws LexicalSemanticResourceException { try { this.catGraph = CategoryGraphManager.getCategoryGraph(wiki); } catch (WikiApiException e) { e.printStackTrace(); throw new LexicalSemanticResourceException("Category graph could not be initialized.",e); } }
result = statement.executeQuery(query); } catch (WikiApiException wae) { logger.error(wae.getLocalizedMessage(), wae);
/** * Get infos only for a subset of articles. * @param pPages A set of pages. Only this subset of wiki pages is used in the info object. */ public WikipediaInfo(Iterable<Page> pPages) throws WikiApiException { if (pPages == null) { throw new WikiApiException("The page set has to be initialized."); } pages = pPages; averageFanOut = -1.0; // lazy initialization => it is computed and stored when it is accessed degreeDistribution = new HashMap<Integer,Integer>(); categorizedArticleSet = new HashSet<Integer>(); // get number of pages numberOfPages = 0; while (pages.iterator().hasNext()) { numberOfPages++; pages.iterator().next(); } }
public int getTaxonomicallyBoundPathLengthInNodes(Category cat1, Category cat2) throws WikiApiException { int retValue = getTaxonomicallyBoundPathLengthInEdges(cat1, cat2); if (retValue == 0) { return 0; } else if (retValue > 0) { return (--retValue); } else if (retValue == -1) { return -1; } else { throw new WikiApiException("Unknown return value."); } }
} catch (WikiApiException e) { logger.error("Page with hibernateID " + id + " not found."); e.printStackTrace();
/** * Creates an {@link CategoryGraph} using a serialized DirectedGraph object. * @param pWiki A {@link Wikipedia} object. * @param location The location of the serialized graph * @throws WikiApiException Thrown if errors occurred. */ public CategoryGraph(Wikipedia pWiki, File location) throws WikiApiException{ try { constructCategoryGraph(pWiki, GraphSerialization.loadGraph(location)); } catch (IOException e) { throw new WikiApiException(e); } catch (ClassNotFoundException e) { throw new WikiApiException(e); } }
} catch (WikiApiException e) { System.out.println("Page " + title + " does not exist"); e.printStackTrace(); System.exit(1);
/** * Gets the path length between two category nodes - measured in "nodes". * @param node1 The first node. * @param node2 The second node. * @return The number of nodes of the path between node1 and node2. 0, if the nodes are identical or neighbors. -1, if no path exists. */ public int getPathLengthInNodes(Category node1, Category node2) throws WikiApiException { int retValue = getPathLengthInEdges(node1, node2); if (retValue == 0) { return 0; } else if (retValue > 0) { return (--retValue); } else if (retValue == -1) { return -1; } else { throw new WikiApiException("Unknown return value."); } }
private static CategoryGraph tryToLoadCategoryGraph(Wikipedia wiki, String wikiId, String size) throws WikiApiException { String defaultSerializedGraphLocation = getCategoryGraphSerializationFileName(wikiId, size); File defaulSerializedGraphFile = new File(defaultSerializedGraphLocation); if (defaulSerializedGraphFile.exists()) { try { logger.info("Loading category graph from " + defaultSerializedGraphLocation); return new CategoryGraph(wiki, GraphSerialization.loadGraph(defaultSerializedGraphLocation)); } catch (IOException e) { throw new WikiApiException(e); } catch (ClassNotFoundException e) { throw new WikiApiException(e); } } else { return null; } }
private Connection getConnection(RevisionAPIConfiguration config) throws WikiApiException { Connection c; try { String driverDB = "com.mysql.jdbc.Driver"; Class.forName(driverDB); c = DriverManager.getConnection( "jdbc:mysql://" + config.getHost() + "/" + config.getDatabase(), config.getUser(), config.getPassword()); if (!c.isValid(5)) { throw new WikiApiException("Connection could not be established."); } } catch (SQLException e) { throw new WikiApiException(e); } catch (ClassNotFoundException e) { throw new WikiApiException(e); } return c; }
throw new WikiApiException(e);
throw new WikiApiException("Page ID must be > 0"); throw new WikiApiException(e);
throw new WikiApiException("Revision ID must be > 0"); throw new WikiApiException(e);
throw new WikiApiException("Article data is inconsistent"); throw new WikiApiException(e);
private Connection getConnection(Wikipedia wiki) throws WikiApiException { DatabaseConfiguration config = wiki.getDatabaseConfiguration(); Connection c; try { String driverDB = "com.mysql.jdbc.Driver"; Class.forName(driverDB); c = DriverManager.getConnection("jdbc:mysql://" + config.getHost() + "/" + config.getDatabase()+"?autoReconnect=true", config.getUser(), config.getPassword()); if (!c.isValid(5)) { throw new WikiApiException( "Connection could not be established."); } } catch (SQLException e) { throw new WikiApiException(e); } catch (ClassNotFoundException e) { throw new WikiApiException(e); } return c; }
throw new WikiApiException("Article data is inconsistent"); throw new WikiApiException(e);
/** * Helper method to obtain a connection via the given {@link RevisionAPIConfiguration} parameter. * @param config Must not be {@code null}. * @return A valid {@link Connection} to the database endpoint. * @throws WikiApiException Thrown if errors occurred while opening a connection. */ protected Connection getConnection(RevisionAPIConfiguration config) throws WikiApiException { Connection c; try { String driverDB = config.getDatabaseDriver(); Class.forName(driverDB); c = DriverManager.getConnection(config.getJdbcURL(), config.getUser(), config.getPassword()); if (!c.isValid(5)) { throw new WikiApiException("Connection could not be established."); } } catch (SQLException | ClassNotFoundException e) { throw new WikiApiException(e); } return c; }