本文整理了Java中de.tudarmstadt.ukp.wikipedia.api.Wikipedia.getPage()
方法的一些代码示例,展示了Wikipedia.getPage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wikipedia.getPage()
方法的具体详情如下:
包路径:de.tudarmstadt.ukp.wikipedia.api.Wikipedia
类名称:Wikipedia
方法名:getPage
[英]Gets the page for a given pageId.
[中]获取给定pageId的页面。
代码示例来源: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;
}
代码示例来源: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
/**
* Gets the discussion page for the page with the given title.
* The page retrieval works as defined in {@link #getPage(String title)}
*
* @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 Page getDiscussionPage(String title) throws WikiApiException {
return getDiscussionPage(getPage(title));
}
public boolean containsLexeme(String lexeme) throws LexicalSemanticResourceException {
lexeme = WikipediaArticleUtils.getCaseSensitiveLexeme(lexeme, isCaseSensitive);
try {
wiki.getPage(lexeme);
} catch (WikiApiException e) {
return false;
}
return true;
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* @return The set of articles that are categorized under this category.
* @throws WikiApiException
*/
public Set<Page> getArticles() throws WikiApiException {
Set<Integer> tmpSet = getArticleIds();
Set<Page> pages = new HashSet<Page>();
for (int pageID : tmpSet) {
pages.add(this.wiki.getPage(pageID));
}
return pages;
}
代码示例来源: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
/**
* 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(int)}. <br>
* The most recent discussion page is NOT included here!
* It can be obtained with {@link #getDiscussionPage(Page)}.
*
* @param articlePageId The id of the page for which to the the discussion archives
* @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(int articlePageId) throws WikiApiException {
//Retrieve discussion archive pages with page id
return getDiscussionArchives(getPage(articlePageId));
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Returns the names of all templates contained in the specified page.
*
* @param pageTitle
* the title of the page for which the templates should be
* retrieved
* @return A List with the names of the templates contained in the specified
* page
* @throws WikiApiException
* If there was any error retrieving the page object (most
* likely if the templates are corrupted)
*/
public List<String> getTemplateNamesFromPage(String pageTitle) throws WikiApiException{
Page p=null;
try{
p = wiki.getPage(pageTitle);
}catch (WikiApiException e) {
return new ArrayList<String>();
}
return getTemplateNamesFromPage(p);
}
代码示例来源:origin: dkpro/dkpro-jwpl
/**
* Returns the article page for a given discussion page.
*
* @param discussionPage
* the discussion page object
* @return The page object of the article associated with the discussion. If
* the parameter already was an article, it is returned directly.
* @throws WikiApiException Thrown if errors occurred.
*/
public Page getArticleForDiscussionPage(Page discussionPage) throws WikiApiException {
if(discussionPage.isDiscussion()){
String title = discussionPage.getTitle().getPlainTitle().replaceAll(WikiConstants.DISCUSSION_PREFIX, "");
if(title.contains("/")){
//If we have a discussion archive
//TODO This does not support articles that contain slashes-
//However, the rest of the API cannot cope with that as well, so this should not be any extra trouble
title = title.split("/")[0];
}
return getPage(title);
}else{
return discussionPage;
}
}
/**
* Resolves disambiguation pages into candidate pages and returns the best relatedness value out of all candidate pairs.
* @param token1 The first token.
* @param token2 The second token.
* @return The relatedness value between the two pages that belong to the given tokens.
* @throws WikiException
*/
protected double getRelatednessValue(String token1, String token2) throws WikiException {
// Get the pages that belong to the tokens.
// Encode the search string as a wikipedia title before searching.
Page page1;
Page page2;
try {
page1 = wiki.getPage(token1);
page2 = wiki.getPage(token2);
} catch (WikiPageNotFoundException e) {
return NOT_IN_WIKIPEDIA;
}
// resolve disambiguation pages
Set<Page> pageSet1 = getDisambiguationPageSet(page1);
Set<Page> pageSet2 = getDisambiguationPageSet(page2);
List<Double> relatednessValues = this.getRelatednessValues(pageSet1, pageSet2);
return getBestRelatedness(relatednessValues);
}
代码示例来源:origin: dkpro/dkpro-similarity
/**
* Resolves disambiguation pages into candidate pages and returns the best relatedness value out of all candidate pairs.
* @param token1 The first token.
* @param token2 The second token.
* @return The relatedness value between the two pages that belong to the given tokens.
* @throws WikiException
*/
protected double getRelatednessValue(String token1, String token2) throws WikiException {
// Get the pages that belong to the tokens.
// Encode the search string as a wikipedia title before searching.
Page page1;
Page page2;
try {
page1 = wiki.getPage(token1);
page2 = wiki.getPage(token2);
} catch (WikiPageNotFoundException e) {
return NOT_IN_WIKIPEDIA;
}
// resolve disambiguation pages
Set<Page> pageSet1 = getDisambiguationPageSet(page1);
Set<Page> pageSet2 = getDisambiguationPageSet(page2);
List<Double> relatednessValues = this.getRelatednessValues(pageSet1, pageSet2);
return getBestRelatedness(relatednessValues);
}
public static Page entityToPage(Wikipedia wiki, Entity entity, boolean isCaseSensitive) throws LexicalSemanticResourceException {
String lexeme = getCaseSensitiveLexeme(entity.getFirstLexeme(), isCaseSensitive);
try {
return wiki.getPage(lexeme);
} catch (WikiApiException e) {
throw new LexicalSemanticResourceException(e);
}
}
代码示例来源:origin: dkpro/dkpro-core
protected void addDocumentMetaData(JCas jcas, int pageId, int revisionId)
throws WikiTitleParsingException, WikiApiException
{
// fix for issue http://code.google.com/p/dkpro-core-asl/issues/detail?id=209
String language = WikiUtils.jwplLanguage2dkproLanguage(dbconfig.getLanguage());
DocumentMetaData metaData = DocumentMetaData.create(jcas);
metaData.setDocumentTitle(wiki.getPage(pageId).getTitle().getWikiStyleTitle());
metaData.setCollectionId(Integer.valueOf(pageId).toString());
metaData.setDocumentId(Integer.valueOf(revisionId).toString());
metaData.setLanguage(language);
}
代码示例来源:origin: dkpro/dkpro-jwpl
Page page = wiki.getPage(title);
System.out.println(page.getText());
} catch (WikiApiException e) {
代码示例来源: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
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
/**
* @param args
*/
public static void main(String[] args)
{
DatabaseConfiguration dbconf = new DatabaseConfiguration();
dbconf.setDatabase("wiki_en_20120104_rev");
dbconf.setUser("root");
dbconf.setPassword("");
dbconf.setHost("127.0.0.1:3307");
dbconf.setLanguage(WikiConstants.Language.english);
try {
Wikipedia wiki = new Wikipedia(dbconf);
Page p = wiki.getPage("Ari Sitas");
List<ExtractedSection> sects = ParseUtils.getSections(p.getText(),p.getTitle().toString(), -1);
for(ExtractedSection sect:sects){
System.out.println(sect.getBody());
}
}
catch (Exception e) {
// TODO handle exception
e.printStackTrace();
}
}
代码示例来源:origin: dkpro/dkpro-jwpl
Page p = wiki.getPage("Dog");
代码示例来源:origin: dkpro/dkpro-jwpl
public static void main(String[] args) throws WikiApiException {
//db connection settings
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setDatabase("DATABASE");
dbConfig.setHost("HOST");
dbConfig.setUser("USER");
dbConfig.setPassword("PASSWORD");
dbConfig.setLanguage(Language.english);
//initialize a wiki
Wikipedia wiki = new Wikipedia(dbConfig);
MediaWikiParserFactory pf = new MediaWikiParserFactory(Language.english);
MediaWikiParser parser = pf.createParser();
//get the page 'House_(disambiguation)'
ParsedPage pp = parser.parse(wiki.getPage("House_(disambiguation)").getText());
int i = 1;
// print out all nested lists of the page
for(NestedList nl : pp.getNestedLists()){
System.out.println(i + ": \n" + outputNestedList(nl,0));
i++;
}
}
代码示例来源:origin: dkpro/dkpro-jwpl
public static void main(String[] args) throws WikiApiException {
//db connection settings
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setDatabase("DATABASE");
dbConfig.setHost("HOST");
dbConfig.setUser("USER");
dbConfig.setPassword("PASSWORD");
dbConfig.setLanguage(Language.english);
//initialize a wiki
Wikipedia wiki = new Wikipedia(dbConfig);
//get the page 'Dog'
Page p = wiki.getPage("Dog");
//get a ParsedPage object
MediaWikiParserFactory pf = new MediaWikiParserFactory();
MediaWikiParser parser = pf.createParser();
ParsedPage pp = parser.parse(p.getText());
//get the sections of the page
List<Section> sections = pp.getSections();
for(Section section : sections) {
System.out.println(section.getTitle());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!