public static boolean isSymmetric(Measure measure) throws WikiRelatednessException { if (isSymmetricMap.containsKey(measure)) { return isSymmetricMap.get(measure); } else { throw new WikiRelatednessException("unknown measure " + measure); } }
/** * 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 Title getBufferElement() { String titleString = titleStringBuffer.get(bufferOffset); Title title = null; try { title = new Title(titleString); } catch (WikiTitleParsingException e) { e.printStackTrace(); } bufferOffset++; dataOffset++; return title; }
/** * @see de.tudarmstadt.ukp.wikipedia.api.Category#Category(Wikipedia, long) */ private void createCategory(long id) throws WikiPageNotFoundException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernateCategory = catDAO.findById(id); session.getTransaction().commit(); if (hibernateCategory == null) { throw new WikiPageNotFoundException("No category with id " + id + " was found."); } }
} catch (WikiInitializationException e1) { System.out.println("Could not initialize Wikipedia."); e1.printStackTrace(); System.exit(1); } catch (WikiApiException e) { System.out.println("Page " + title + " does not exist"); e.printStackTrace(); System.exit(1);
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); } }
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."); } }
private void fetchByPageId(int pageID) throws WikiApiException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernatePage = (de.tudarmstadt.ukp.wikipedia.api.hibernate.Page) session .createQuery("from Page where pageId = :id").setParameter("id", pageID, IntegerType.INSTANCE).uniqueResult(); session.getTransaction().commit(); if (hibernatePage == null) { throw new WikiPageNotFoundException("No page with page id " + pageID + " was found."); } }
public static boolean isSymmetric(Measure measure) throws WikiRelatednessException { if (isSymmetricMap.containsKey(measure)) { return isSymmetricMap.get(measure); } else { throw new WikiRelatednessException("unknown measure " + measure); } }
@Override public Entity next() { Category cat = wikiCatIterator.next(); String title = ""; try { title = cat.getTitle().getWikiStyleTitle(); } catch (WikiTitleParsingException e) { e.printStackTrace(); System.exit(1); } return new Entity(title); } }
/** * 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."); } }
/** * @throws WikiApiException Thrown if errors occurred. * @see de.tudarmstadt.ukp.wikipedia.api.Page */ private void fetchByHibernateId(long id) throws WikiApiException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernatePage = pageDAO.findById(id); session.getTransaction().commit(); if (hibernatePage == null) { throw new WikiPageNotFoundException("No page with id " + id + " was found."); } }
/** * Combines the relatedness values that have been computed between the categories of an article using a given combination strategy. * @param relatednessValues A list with the relatedness values. * @return The combined relatedness value. */ public double combineRelatedness(List<Double> relatednessValues) throws WikiRelatednessException { double combinedRelatedness = -1.0; if (strategy.equals(CombinationStrategy.Average) || strategy.equals(CombinationStrategy.SelectivityLinear) || strategy.equals(CombinationStrategy.SelectivityLog)) { combinedRelatedness = computeAverageRelatedness(relatednessValues); } // If CombinationStrategy is "none" then there is only a single result value and we do not have to combine anything. // But inheritence structure makes it necessary to have a combination of relatedness values computed. // So we use findSmallestRelatedness for "none" as this will select the smallest (that is the only value) in the list :) else if (strategy.equals(CombinationStrategy.Best) || strategy.equals(CombinationStrategy.None)) { combinedRelatedness = getBestRelatedness(relatednessValues); } else { throw new WikiRelatednessException("Unknown combination strategy " + strategy); } return combinedRelatedness; }
public int compare(Page o1, Page o2) { int retVal = 0; try { retVal = o1.getTitle().getPlainTitle().compareTo(o2.getTitle().getPlainTitle()); } catch (WikiTitleParsingException e) { e.printStackTrace(); } return retVal; } }
/** * 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); } }
/** * Creates a category object. * @param wiki The wikipedia object. * @param pName The name of the category. * @throws WikiPageNotFoundException If the category does not exist. */ public Category(Wikipedia wiki, String pName) throws WikiApiException { if (pName == null || pName.length() == 0) { throw new WikiPageNotFoundException(); } this.wiki = wiki; catDAO = new CategoryDAO(wiki); Title catTitle = new Title(pName); createCategory(catTitle); }
/** * Combines the relatedness values that have been computed between the categories of an article using a given combination strategy. * @param relatednessValues A list with the relatedness values. * @return The combined relatedness value. */ public double combineRelatedness(List<Double> relatednessValues) throws WikiRelatednessException { double combinedRelatedness = -1.0; if (strategy.equals(CombinationStrategy.Average) || strategy.equals(CombinationStrategy.SelectivityLinear) || strategy.equals(CombinationStrategy.SelectivityLog)) { combinedRelatedness = computeAverageRelatedness(relatednessValues); } // If CombinationStrategy is "none" then there is only a single result value and we do not have to combine anything. // But inheritence structure makes it necessary to have a combination of relatedness values computed. // So we use findSmallestRelatedness for "none" as this will select the smallest (that is the only value) in the list :) else if (strategy.equals(CombinationStrategy.Best) || strategy.equals(CombinationStrategy.None)) { combinedRelatedness = getBestRelatedness(relatednessValues); } else { throw new WikiRelatednessException("Unknown combination strategy " + strategy); } return combinedRelatedness; }
public int compare(Category o1, Category o2) { int retVal = 0; try { retVal = o1.getTitle().getPlainTitle().compareTo(o2.getTitle().getPlainTitle()); } catch (WikiTitleParsingException e) { e.printStackTrace(); } return retVal; } }
/** * (Constructor) Creates a new RevisionIterator object. * * @param config * Reference to the configuration object * * @throws WikiApiException * if an error occurs */ public RevisionIterator(final RevisionAPIConfiguration config) throws WikiApiException { this.config = config; try { this.primaryKey = -1; this.endPK = Integer.MAX_VALUE; this.statement = null; this.result = null; this.previousRevision = null; MAX_NUMBER_RESULTS = config.getBufferSize(); connect(); } catch (SQLException e) { throw new WikiApiException(e); } }
private static void saveCategoryGraph(CategoryGraph catGraph, String wikiId, String size) throws WikiApiException { String defaultSerializedGraphLocation = getCategoryGraphSerializationFileName(wikiId, size); try { logger.info("Saving category graph to " + defaultSerializedGraphLocation); GraphSerialization.saveGraph(catGraph.getGraph(), defaultSerializedGraphLocation); } catch (IOException e) { throw new WikiApiException(e); } }