de.tudarmstadt.ukp.wikipedia.api.Wikipedia.getCategory()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中de.tudarmstadt.ukp.wikipedia.api.Wikipedia.getCategory()方法的一些代码示例,展示了Wikipedia.getCategory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wikipedia.getCategory()方法的具体详情如下:
包路径:de.tudarmstadt.ukp.wikipedia.api.Wikipedia
类名称:Wikipedia
方法名:getCategory

Wikipedia.getCategory介绍

[英]Gets the category for a given pageId.
[中]获取给定pageId的类别。

代码示例

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.lexsemresource/de.tudarmstadt.ukp.dkpro.lexsemresource.wikipedia-asl

public boolean containsLexeme(String lexeme) throws LexicalSemanticResourceException {
  lexeme = WikipediaCategoryUtils.getCaseSensitiveLexeme(lexeme, isCaseSensitive);
  try {
    if(wiki.getCategory(lexeme) == null) {
      return false;
    }
  } catch (WikiApiException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Building a mapping from categories to article sets.
 * @param pWiki The wikipedia object.
 * @param pNodes The category nodes that should be used to build the map.
 * @return A mapping from categories to article sets.
 * @throws WikiPageNotFoundException
 */
private Map<Integer,Set<Integer>> getCategoryArticleMap(Wikipedia pWiki, Set<Integer> pNodes) throws WikiPageNotFoundException {
  Map<Integer,Set<Integer>> categoryArticleMap = new HashMap<Integer,Set<Integer>>();
  int progress = 0;
  for (int node : pNodes) {
    progress++;
    ApiUtilities.printProgressInfo(progress, pNodes.size(), 10, ApiUtilities.ProgressInfoMode.TEXT, "Getting category-article map.");
    Category cat = pWiki.getCategory(node);
    if (cat != null) {
      Set<Integer> pages = new HashSet<Integer>(cat.__getPages());
      categoryArticleMap.put(node, pages);
    }
    else {
      logger.info("{} is not a category.", node);
    }
  }
  return categoryArticleMap;
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Gets the lowest common subsumer (LCS) of two nodes.
 * The LCS of two nodes is first node on the path to the root, that has both nodes as sons.
 * Nodes that are not in the same connected component as the root node are defined to have no LCS.
 * @param categoryPageId1 The pageid of the first category node.
 * @param categoryPageId2 The pageid of the second category node.
 * @return The lowest common subsumer of the two nodes, or null if there is no LCS.
 */
public Category getLCS(int categoryPageId1, int categoryPageId2) throws WikiApiException {
  int lcsid = getLCSId(categoryPageId1, categoryPageId2);
  return lcsid>-1?wiki.getCategory(getLCSId(categoryPageId1, categoryPageId2)):null;
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * @return A set containing parents (supercategories) of this category.
 */
public Set<Category> getParents() {
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  session.lock(hibernateCategory, LockMode.NONE);
  Set<Integer> tmpSet = new HashSet<Integer>(hibernateCategory.getInLinks());
  session.getTransaction().commit();
  Set<Category> categories = new HashSet<Category>();
  for (int pageID : tmpSet) {
    categories.add(this.wiki.getCategory(pageID));
  }
  return categories;
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * @return A set containing the children (subcategories) of this category.
 */
public Set<Category> getChildren() {
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  session.lock(hibernateCategory, LockMode.NONE);
  Set<Integer> tmpSet = new HashSet<Integer>(hibernateCategory.getOutLinks());
  session.getTransaction().commit();
  Set<Category> categories = new HashSet<Category>();
  for (int pageID : tmpSet) {
    categories.add(this.wiki.getCategory(pageID));
  }
  return categories;
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * @return The disambiguation {@link Category}.
 * @throws WikiApiException Thrown if errors occurred fetching the information.
 */
public Category getDisambiguationCategory() throws WikiApiException
{
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  session.lock(hibernateMetaData, LockMode.NONE);
  String disambCategoryTitle = hibernateMetaData.getDisambiguationCategory();
  session.getTransaction().commit();
  return wiki.getCategory(disambCategoryTitle);
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * @return The name of the main/root {@link Category}.
 * @throws WikiApiException Thrown if errors occurred fetching the information.
 */
public Category getMainCategory() throws WikiApiException
{
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  session.lock(hibernateMetaData, LockMode.NONE);
  String mainCategoryTitle = hibernateMetaData.getMainCategory();
  session.getTransaction().commit();
  return wiki.getCategory(mainCategoryTitle);
}

代码示例来源:origin: dkpro/dkpro-jwpl

Category currentCat = wiki.getCategory(queue.get(0));
queue.remove(0);

代码示例来源:origin: dkpro/dkpro-jwpl

Category cat = pWiki.getCategory(node);
if (cat != null) {
  Set<Integer> pages = new HashSet<Integer>(cat.__getPages());

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * @return The a set of categories that this page belongs to.
 */
public Set<Category> getCategories()
{
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  session.buildLockRequest(LockOptions.NONE).lock(hibernatePage);
  Set<Integer> tmp = new UnmodifiableArraySet<Integer>(hibernatePage.getCategories());
  session.getTransaction().commit();
  Set<Category> categories = new HashSet<Category>();
  for (int pageID : tmp) {
    categories.add(wiki.getCategory(pageID));
  }
  return categories;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.lexsemresource/de.tudarmstadt.ukp.dkpro.lexsemresource.wikipedia-asl

public int getShortestPathLength(Entity firstEntity, Entity secondEntity) throws LexicalSemanticResourceException {
  String lexeme1 = WikipediaCategoryUtils.getCaseSensitiveLexeme(firstEntity.getFirstLexeme(), isCaseSensitive);
  String lexeme2 = WikipediaCategoryUtils.getCaseSensitiveLexeme(secondEntity.getFirstLexeme(), isCaseSensitive);
  if (lexeme1 == null || lexeme2 == null) {
    return -1;
  }
  if (this.catGraph == null) {
    initializeCategoryGraph();
  }
  Category c1;
  Category c2;
  try {
    c1 = wiki.getCategory(lexeme1);
    c2 = wiki.getCategory(lexeme2);
    return catGraph.getPathLengthInEdges(c1, c2);
  } catch (WikiApiException e) {
    return -1;
  }
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * The JGraphT cycle detection seems not to find all cycles. Thus, I wrote my own cycle detection.
 * It is a colored DFS and should find all (viscious :) cycles.
 * @return True, if the graph contains a cycle.
 * @throws WikiApiException Thrown if errors occurred.
 */
public boolean containsCycle() throws WikiApiException  {
  DefaultEdge edge = findCycle();
  if (edge != null) {
    Category sourceCat = wiki.getCategory(categoryGraph.getGraph().getEdgeSource(edge));
    Category targetCat = wiki.getCategory(categoryGraph.getGraph().getEdgeTarget(edge));
    logger.info("Cycle: " + sourceCat.getTitle() + " - " + targetCat.getTitle());
    return true;
  }
  else {
    return false;
  }
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Removes cycles from the graph that was used to construct the cycle handler.
 * @throws WikiApiException Thrown if errors occurred.
 */
public void removeCycles() throws WikiApiException {
  DefaultEdge edge = null;
  while ((edge = findCycle()) != null) {
    Category sourceCat = wiki.getCategory(categoryGraph.getGraph().getEdgeSource(edge));
    Category targetCat = wiki.getCategory(categoryGraph.getGraph().getEdgeTarget(edge));
    logger.info("Removing cycle: " + sourceCat.getTitle() + " - " + targetCat.getTitle());
    categoryGraph.getGraph().removeEdge(edge);
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.lexsemresource/de.tudarmstadt.ukp.dkpro.lexsemresource.wikipedia-asl

public Set<Entity> getParents(Entity entity) throws LexicalSemanticResourceException {
  Set<Entity> parents = new HashSet<Entity>();
  Category cat;
  String lexeme = WikipediaCategoryUtils.getCaseSensitiveLexeme(entity.getFirstLexeme(), isCaseSensitive);
  if (lexeme == null) {
    return parents;
  }
  try {
    cat = wiki.getCategory(lexeme);
    if (cat == null)  {
      return parents;
    }
    Set<Category> parentCategories = cat.getParents();
    for (Category parentCategory : parentCategories) {
      parents.add(new Entity(parentCategory.getTitle().getWikiStyleTitle()));
    }
  } catch (WikiApiException e) {
    throw new LexicalSemanticResourceException(e);
  }
  return parents;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.lexsemresource/de.tudarmstadt.ukp.dkpro.lexsemresource.wikipedia-asl

public Set<Entity> getChildren(Entity entity) throws LexicalSemanticResourceException {
  Set<Entity> children = new HashSet<Entity>();
  Category cat = null;
  String lexeme = WikipediaCategoryUtils.getCaseSensitiveLexeme(entity.getFirstLexeme(), isCaseSensitive);
  if (lexeme == null) {
    return children;
  }
  try {
    cat = wiki.getCategory(lexeme);
    if (cat == null) {
      return children;
    }
    Set<Category> childCategories = cat.getChildren();
    for (Category childCategory : childCategories) {
      children.add(new Entity(childCategory.getTitle().getWikiStyleTitle()));
    }
  } catch (WikiApiException e) {
    throw new LexicalSemanticResourceException(e);
  }
  return children;
}

代码示例来源:origin: dkpro/dkpro-jwpl

Category cat;
try {
  cat = wiki.getCategory(title);
} catch (WikiPageNotFoundException e) {
  throw new WikiApiException("Category " + title + " does not exist");

代码示例来源:origin: dkpro/dkpro-jwpl

Category topCat;
try {
  topCat = wiki.getCategory(title);
} catch (WikiPageNotFoundException e) {
  throw new WikiApiException("Category " + title + " does not exist");

代码示例来源:origin: de.tudarmstadt.ukp.uby/de.tudarmstadt.ukp.uby.integration.wikipedia-asl

/**
 * @param dbConfig
 * @param wiki
 * @param resourceVersion Version of the resource
 * @param dtd Version of the dtd
 * @param createEquivalents
 * @throws WikiApiException
 * @throws FileNotFoundException
 */
public WikipediaLMFTransformer(DBConfig dbConfig, Wikipedia wiki, String resourceVersion,
    String dtd, boolean createEquivalents) throws WikiApiException, FileNotFoundException {
  super(dbConfig);
  this.wiki = wiki;
  this.pageIterator = new PageIterator(wiki, true, 7000);
  this.categoryBlackList = wiki.getCategory(getHiddenCategoryName()).getChildrenIDs();
  this.currentEntryNr = 0;
  this.createEquivalents = createEquivalents;
  MediaWikiParserFactory pf = new MediaWikiParserFactory();		// Parse with MediaWikiParser
  pf.setCalculateSrcSpans(false);
  pf.setTemplateParserClass(FlushTemplates.class);
  mediaWikiParser = pf.createParser();
  dtd_version = dtd;
  this.resourceVersion = resourceVersion;
}

相关文章