本文整理了Java中de.tudarmstadt.ukp.wikipedia.api.Wikipedia
类的一些代码示例,展示了Wikipedia
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wikipedia
类的具体详情如下:
包路径:de.tudarmstadt.ukp.wikipedia.api.Wikipedia
类名称:Wikipedia
[英]Provides access to Wikipedia articles and categories.
[中]提供对维基百科文章和类别的访问。
代码示例来源:origin: dkpro/dkpro-jwpl
private Wikipedia getWiki()
{
if (this.wiki == null) {
Wikipedia nWiki = null;
try {
nWiki = new Wikipedia(dbConf);
}
catch (WikiInitializationException e) {
logger.error("Error initializing Wiki connection!", e);
}
return nWiki;
}
else {
return this.wiki;
}
}
代码示例来源:origin: dkpro/dkpro-jwpl
public Page next() {
Page page = null;
try {
page = this.wiki.getPage(pageIDs.get(iterPosition));
} catch (WikiApiException e) {
logger.error("Could not load page with id {}", pageIDs.get(iterPosition), e);
}
iterPosition++;
return page;
}
public int getNumberOfEntities() {
long numberOfEntities = wiki.getMetaData().getNumberOfPages() - wiki.getMetaData().getNumberOfRedirectPages();
return new Long(numberOfEntities).intValue();
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Gets the discussion page for an article page with the given pageId.
*
* @param articlePageId The id of the page.
* @return The page object for a given pageId.
* @throws WikiApiException Thrown if errors occurred.
*/
public Page getDiscussionPage(int articlePageId) throws WikiApiException {
//Retrieve discussion page with article title
//TODO not the prettiest solution, but currently discussions are only marked in the title
return getDiscussionPage(getPage(articlePageId));
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Returns an iterable containing all archived discussion pages for
* the page with the given title String. <br>
* The page retrieval works as defined in {@link #getPage(String title)}.<br>
* The most recent discussion page is NOT included here!
* It can be obtained with {@link #getDiscussionPage(Page)}.
*
* @param title The title of the page for which the discussions should be retrieved.
* @return The page object for the discussion page.
* @throws WikiApiException If no page or redirect with this title exists or title could not be properly parsed.
*/
public Iterable<Page> getDiscussionArchives(String title) throws WikiApiException {
//Retrieve discussion archive pages with page title
return getDiscussionArchives(getPage(title));
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Deleted the root path map file.
* @throws WikiApiException Thrown if errors occurred.
*/
public void deleteRootPathMap() throws WikiApiException {
File rootPathFile = new File(this.rootPathMapFilename + "_" + wiki.getLanguage() + "_" + wiki.getMetaData().getVersion());
rootPathFile.delete();
}
代码示例来源:origin: dkpro/dkpro-jwpl
public static void main(String[] args) throws WikiApiException {
// configure the database connection parameters
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setHost("SERVER_URL");
dbConfig.setDatabase("DATABASE");
dbConfig.setUser("USER");
dbConfig.setPassword("PASSWORD");
dbConfig.setLanguage(Language.german);
// Create a new German wikipedia.
Wikipedia wiki = new Wikipedia(dbConfig);
// Get the page with title "Hello world".
// May throw an exception, if the page does not exist.
Page page = wiki.getPage("Hello world");
System.out.println(page.getText());
}
}
代码示例来源:origin: dkpro/dkpro-jwpl
dbConfig.setLanguage(Language.english);
Wikipedia wiki = new Wikipedia(dbConfig);
Iterator<Page> pageIt = wiki.getArticles().iterator();
nrOfPages = wiki.getMetaData().getNumberOfPages();
nrOfTables = 0;
nrOfTemplates = 0;
代码示例来源:origin: dkpro/dkpro-jwpl
public static void main(String[] args) throws WikiApiException {
// configure the database connection parameters
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setHost("SERVER_URL");
dbConfig.setDatabase("DATABASE");
dbConfig.setUser("USER");
dbConfig.setPassword("PASSWORD");
dbConfig.setLanguage(Language.german);
// Create a new German wikipedia.
Wikipedia wiki = new Wikipedia(dbConfig);
String title = "Hello world";
if (wiki.existsPage(title)) {
Page page = wiki.getPage(title);
System.out.println(page.getText());
}
else {
System.out.println("Page " + title + " does not exist");
}
}
}
代码示例来源:origin: dkpro/dkpro-jwpl
Wikipedia wiki = new Wikipedia(dbConfig);
Category cat;
try {
cat = wiki.getCategory(title);
} catch (WikiPageNotFoundException e) {
throw new WikiApiException("Category " + title + " does not exist");
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Return an iterable containing all archived discussion pages for
* the given article page. The most recent discussion page is not included.
* The most recent discussion page can be obtained with {@link #getDiscussionPage(Page)}.
* <br>
* The provided page Object must not be a discussion page itself! If it is
* a discussion page, is returned unchanged.
*
* @param articlePage the article page for which a discussion archives should be retrieved
* @return An iterable with the discussion archive page objects for the given article page object
* @throws WikiApiException If no page or redirect with this title exists or title could not be properly parsed.
*/
public Iterable<Page> getDiscussionArchives(Page articlePage) throws WikiApiException{
String articleTitle = articlePage.getTitle().getWikiStyleTitle();
if(!articleTitle.startsWith(WikiConstants.DISCUSSION_PREFIX)){
articleTitle=WikiConstants.DISCUSSION_PREFIX+articleTitle;
}
Session session = this.__getHibernateSession();
session.beginTransaction();
List<Page> discussionArchives = new LinkedList<Page>();
Query query = session.createQuery("SELECT pageID FROM PageMapLine where name like :name");
query.setParameter("name", articleTitle+"/%", StringType.INSTANCE);
Iterator results = query.list().iterator();
session.getTransaction().commit();
while (results.hasNext()) {
int pageID = (Integer) results.next();
discussionArchives.add(getPage(pageID));
}
return discussionArchives;
}
代码示例来源:origin: dkpro/dkpro-jwpl
dbConfig.setLanguage(Language.german);
Wikipedia wiki = new Wikipedia(dbConfig);
Iterator<Page> pageIt = wiki.getArticles().iterator();
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
revApi = new RevisionApi(wiki.getDatabaseConfiguration());
if(!wiki.getPage(current.getArticleID()).isDiscussion()){
int currentCounter = current.getRevisionCounter();
代码示例来源: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
public static Set<String> getUniqueArticleTitles() throws WikiInitializationException {
// configure the database connection parameters
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setHost("SERVER_URL");
dbConfig.setDatabase("DATABASE");
dbConfig.setUser("USER");
dbConfig.setPassword("PASSWORD");
dbConfig.setLanguage(Language.german);
// Create a new German wikipedia.
Wikipedia wiki = new Wikipedia(dbConfig);
Set<String> uniqueArticleTitles = new TreeSet<String>();
for (Title title : wiki.getTitles()) {
uniqueArticleTitles.add(title.getPlainTitle());
}
return uniqueArticleTitles;
}
public WikipediaArticleEntityIterable(Wikipedia wiki, boolean isCaseSensitive) {
this.wikiPageIterable = wiki.getArticles();
this.wiki = wiki;
this.isCaseSensitive = isCaseSensitive;
}
代码示例来源: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: dkpro/dkpro-core
@Override
public void initialize(UimaContext context)
throws ResourceInitializationException {
super.initialize(context);
MetaData md = wiki.getMetaData();
this.nrOfArticles = md.getNumberOfPages() - md.getNumberOfDisambiguationPages()
- md.getNumberOfRedirectPages();
this.currentArticleIndex = 0;
RevisionAPIConfiguration revConfig = new RevisionAPIConfiguration(dbconfig);
try {
revApi = new RevisionApi(revConfig);
}
catch (WikiApiException e) {
throw new ResourceInitializationException(e);
}
idIter = wiki.getPageIds().iterator();
}
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!