本文整理了Java中de.tudarmstadt.ukp.wikipedia.api.Wikipedia.<init>()
方法的一些代码示例,展示了Wikipedia.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wikipedia.<init>()
方法的具体详情如下:
包路径:de.tudarmstadt.ukp.wikipedia.api.Wikipedia
类名称:Wikipedia
方法名:<init>
[英]Creates a new Wikipedia object accessing the database indicated by the dbConfig parameter.
[中]创建一个新的Wikipedia对象,访问dbConfig参数指示的数据库。
代码示例来源: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 RevisionUtils(DatabaseConfiguration conf) throws WikiApiException{
wiki = new Wikipedia(conf);
revApi = new RevisionApi(conf);
}
public WikipediaCategoryResource(DatabaseConfiguration dbConfig) throws LexicalSemanticResourceException {
try {
this.wiki = new Wikipedia(dbConfig);
} catch (WikiInitializationException e) {
throw new LexicalSemanticResourceException("Wikipedia could not be initialized.",e);
}
initialSetup();
}
public WikipediaArticleResource(DatabaseConfiguration dbConfig) throws LexicalSemanticResourceException {
try {
wiki = new Wikipedia(dbConfig);
} catch (WikiInitializationException e) {
throw new LexicalSemanticResourceException("Wikipedia could not be initialized.",e);
}
initialSetup(dbConfig);
}
代码示例来源:origin: dkpro/dkpro-core
@Override
public void initialize(UimaContext context)
throws ResourceInitializationException
{
super.initialize(context);
dbconfig = new DatabaseConfiguration(
host,
db,
user,
password,
language
);
try {
this.wiki = new Wikipedia(dbconfig);
}
catch (WikiInitializationException e) {
throw new ResourceInitializationException(e);
}
}
代码示例来源:origin: edu.illinois.cs.cogcomp/DatalessClassification
private IndexDocumentsByLucene(final String outputLuceneDir) {
// read DB config
InputStream is = IndexDocumentsByLucene.class.getResourceAsStream("conf/db.conf");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
String serverName = br.readLine();
String mydatabase = br.readLine();
String username = br.readLine();
String password = br.readLine();
br.close();
dbConfig.setHost(serverName);
dbConfig.setDatabase(mydatabase);
dbConfig.setUser(username);
dbConfig.setPassword(password);
dbConfig.setLanguage(Language.chinese);
System.out.println("Register to database...");
wiki = new Wikipedia(dbConfig);
System.out.println("Done.");
System.out.println("Register to lucene...");
Directory indexDir = FSDirectory.open(new File(outputLuceneDir));
writer = new IndexWriter(indexDir, new StandardAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.LIMITED);
System.out.println("Done...");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
代码示例来源:origin: dkpro/dkpro-similarity
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
throws ResourceInitializationException
{
if (!super.initialize(aSpecifier, aAdditionalParams)) {
return false;
}
DatabaseConfiguration dbconfig =
new DatabaseConfiguration(host,database,user, password,
Language.english);
Wikipedia wiki;
try {
wiki = new Wikipedia(dbconfig);
}
catch (WikiInitializationException e) {
throw new ResourceInitializationException();
}
TextSimilarityMeasureBase measure = new WLMComparator(wiki, false, useOutboundLinks);
this.measure = measure;
mode = TextSimilarityResourceMode.text;
return true;
}
代码示例来源: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;
}
代码示例来源:origin: dkpro/dkpro-jwpl
Wikipedia wiki = new Wikipedia(dbConfig);
代码示例来源:origin: dkpro/dkpro-jwpl
Wikipedia wiki = new Wikipedia(dbConfig);
代码示例来源:origin: dkpro/dkpro-jwpl
wiki = new Wikipedia(dbConfig);
} catch (WikiInitializationException e1) {
System.out.println("Could not initialize Wikipedia.");
代码示例来源:origin: dkpro/dkpro-jwpl
Wikipedia wiki = new Wikipedia(dbConfig);
代码示例来源: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
Wikipedia wiki = new Wikipedia(dbConfig);
代码示例来源: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
Wikipedia wiki = new Wikipedia(dbConfig);
代码示例来源: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());
}
}
}
代码示例来源:origin: dkpro/dkpro-core
/**
* Creates a Wikipedia object from a DBConfig annotation without the need to
* manually create the intermediary DatabaseConfiguration.
*
* @param confAnnotation
* annotation containing the db credentials
* @return a Wikipedia object
* @throws WikiApiException
* if the Wikipedia object could not be created
*/
public static Wikipedia getWikipedia(DBConfig confAnnotation)
throws WikiApiException
{
DatabaseConfiguration config = new DatabaseConfiguration();
config.setHost(confAnnotation.getHost());
config.setDatabase(confAnnotation.getDB());
config.setUser(confAnnotation.getUser());
config.setPassword(confAnnotation.getPassword());
config.setLanguage(Language.valueOf(confAnnotation.getLanguage()));
return new Wikipedia(config);
}
内容来源于网络,如有侵权,请联系作者删除!