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

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

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

Wikipedia.getDatabaseConfiguration介绍

暂无

代码示例

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

private SessionFactory initializeSessionFactory() {
  try {
    return WikiHibernateUtil.getSessionFactory(wiki.getDatabaseConfiguration());
  } catch (Exception e) {
    throw new IllegalStateException("Could not locate SessionFactory in JNDI", e);
  }
}

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

public WikipediaArticleResource(Wikipedia wiki) {
  this.wiki = wiki;
  initialSetup(wiki.getDatabaseConfiguration());
}

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

/**
 * The ID consists of the host, the database, and the language.
 * This should be unique in most cases.
 * @return Returns a unique ID for this Wikipedia object.
 */
public String getWikipediaId() {
  StringBuilder sb = new StringBuilder();
  sb.append(this.getDatabaseConfiguration().getHost());
  sb.append("_");
  sb.append(this.getDatabaseConfiguration().getDatabase());
  sb.append("_");
  sb.append(this.getDatabaseConfiguration().getLanguage());
  return sb.toString();
}

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

/**
 * Returns the ids of all pages that ever contained any template that started with any of the given template fragments
 *
 * @param templateFragments template-fragments to look for
 * @return list of page ids of the pages that once contained any template that started with any of the given template fragments
 * @throws WikiApiException If there was any error retrieving the page object (most
 *             likely if the template templates are corrupted)
 */
public List<Integer> getIdsOfPagesThatEverContainedTemplateFragments(List<String> templateFragments) throws WikiApiException{
  if(revApi==null){
    revApi = new RevisionApi(wiki.getDatabaseConfiguration());
  }
  Set<Integer> pageIdSet = new HashSet<Integer>();
  //TODO instead of getting rev ids and then getting page ids, do one query and make the join in the db directly
  List<Integer> revsWithTemplate = getRevisionIdsContainingTemplateFragments(templateFragments);
  for(int revId:revsWithTemplate){
    pageIdSet.add(revApi.getPageIdForRevisionId(revId));
  }
  List<Integer> pageIds = new LinkedList<Integer>();
  pageIds.addAll(pageIdSet);
  return pageIds;
}

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

/**
 * Returns the ids of all pages that ever contained any of the given template names in the history of their existence.
 *
 * @param templateNames template names to look for
 * @return list of page ids of the pages that once contained any of the given template names
 * @throws WikiApiException If there was any error retrieving the page object (most
 *             likely if the template templates are corrupted)
 */
public List<Integer> getIdsOfPagesThatEverContainedTemplateNames(List<String> templateNames) throws WikiApiException{
  if(revApi==null){
    revApi = new RevisionApi(wiki.getDatabaseConfiguration());
  }
  Set<Integer> pageIdSet = new HashSet<Integer>();
  //TODO instead of getting rev ids and then getting page ids, do one query and make the join in the db directly
  List<Integer> revsWithTemplate = getRevisionIdsContainingTemplateNames(templateNames);
  for(int revId:revsWithTemplate){
    pageIdSet.add(revApi.getPageIdForRevisionId(revId));
  }
  List<Integer> pageIds = new LinkedList<Integer>();
  pageIds.addAll(pageIdSet);
  return pageIds;
}

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

System.err.println("This methods has to parse each revision of the given page. If you have a revision-template index, please use getRevisionPairs().");
if(revApi==null){
  revApi = new RevisionApi(wiki.getDatabaseConfiguration());

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

revApi = new RevisionApi(wiki.getDatabaseConfiguration());

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

/**
 * Does the same as revisionContainsTemplateFragment() without using a template index
 *
 * @param revId
 * @param templateFragment
 * @return
 * @throws WikiApiException
 */
public boolean revisionContainsTemplateFragmentWithoutIndex(int revId, String templateFragment) throws WikiApiException{
  if(revApi==null){
    revApi = new RevisionApi(wiki.getDatabaseConfiguration());
  }
  if(parser==null){
    //TODO switch to SWEBLE
    MediaWikiParserFactory pf = new MediaWikiParserFactory(
        wiki.getDatabaseConfiguration().getLanguage());
    pf.setTemplateParserClass(ShowTemplateNamesAndParameters.class);
    parser = pf.createParser();
  }
  List<Template> tplList = parser.parse(revApi.getRevision(revId).getRevisionText()).getTemplates();
  for(Template tpl:tplList){
    if(tpl.getName().toLowerCase().startsWith(templateFragment.toLowerCase())){
      return true;
    }
  }
  return false;
}

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

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;
}

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

revApi = new RevisionApi(wiki.getDatabaseConfiguration());
    wiki.getDatabaseConfiguration().getLanguage());
pf.setTemplateParserClass(ShowTemplateNamesAndParameters.class);
parser = pf.createParser();

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

/**
 * Does the same as revisionContainsTemplateName() without using a template index
 *
 * @param revId
 * @param templateName
 * @return
 * @throws WikiApiException
 */
public boolean revisionContainsTemplateNameWithoutIndex(int revId, String templateName) throws WikiApiException{
  if(revApi==null){
    revApi = new RevisionApi(wiki.getDatabaseConfiguration());
  }
  if(parser==null){
    //TODO switch to SWEBLE
    MediaWikiParserFactory pf = new MediaWikiParserFactory(
        wiki.getDatabaseConfiguration().getLanguage());
    pf.setTemplateParserClass(ShowTemplateNamesAndParameters.class);
    parser = pf.createParser();
  }
  List<Template> tplList = parser.parse(revApi.getRevision(revId).getRevisionText()).getTemplates();
  for(Template tpl:tplList){
    if(tpl.getName().equalsIgnoreCase(templateName)){
      return true;
    }
  }
  return false;
}

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

revApi = new RevisionApi(wiki.getDatabaseConfiguration());

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

/**
 * @see de.tudarmstadt.ukp.wikipedia.api.Category#Category(Wikipedia, String)
 */
private void createCategory(Title title) throws WikiPageNotFoundException {
  String name = title.getWikiStyleTitle();
  Session session = this.wiki.__getHibernateSession();
  session.beginTransaction();
  Object returnValue;
  String query = "select cat.pageId from Category as cat where cat.name = :name";
  if(wiki.getDatabaseConfiguration().supportsCollation()) {
    query += Wikipedia.SQL_COLLATION;
  }
  returnValue = session.createNativeQuery(query)
      .setParameter("name", name, StringType.INSTANCE)
      .uniqueResult();
  session.getTransaction().commit();
  // if there is no category with this name, the hibernateCategory is null
  if (returnValue == null) {
    hibernateCategory = null;
    throw new WikiPageNotFoundException("No category with name " + name + " was found.");
  }
  else {
    // now cast it into an integer
    int pageID = (Integer) returnValue;
    createCategory( pageID);
  }
}

相关文章