当前位置: 首页>>代码示例>>Java>>正文


Java RevisionApi类代码示例

本文整理汇总了Java中de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi的典型用法代码示例。如果您正苦于以下问题:Java RevisionApi类的具体用法?Java RevisionApi怎么用?Java RevisionApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RevisionApi类属于de.tudarmstadt.ukp.wikipedia.revisionmachine.api包,在下文中一共展示了RevisionApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RevisionBasedTalkPageExtractor

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Creates a new TalkPageExtractor that segments a collection of discussion pages into threads and turns
 * 
 * @param wiki the JWPL Wikipedia object with an active database connection
 * @param revApi the JWPL RevisionApi object with an active database connection
 * @param pageTitles a collection of page or talk page ttiles
 * @param includeArchives true, if the extractor should attempt to extract discussions from discussion archives (still buggy)
 * @param aggregateParagraphsToTurns true, whether paragraphs should heuristically be aggregated to turns
 * @throws WikiInitializationException in case the database connection could not be established
 * @throws WikiApiException in case the database could not be accessed
 */
public RevisionBasedTalkPageExtractor(Wikipedia wiki, RevisionApi revApi, Collection<String> pageTitles, boolean includeArchives, boolean aggregateParagraphsToTurns) throws WikiInitializationException, WikiApiException{
	this.wiki =wiki;
	this.includeArchives=includeArchives;
	this.aggregateParagraphsToTurns = aggregateParagraphsToTurns;
	this.revApi = revApi;

	sourcePages = new ArrayList<>();
	talkPages=new ArrayList<>();
	logger.trace("Loading "+pageTitles.size()+" pages....");
	for(String title:pageTitles){
		try{
			sourcePages.add(wiki.getPage(title));
		}catch(WikiPageNotFoundException e){
			logger.warn("Could not find article "+title);
		}
	}
	logger.trace("done.");
	loadTalkPages();
	
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:32,代码来源:RevisionBasedTalkPageExtractor.java

示例2: getRevisionForTimestamp

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Returns the revision of an article at a particular age
 * 
 * @param articleId id of the article
 * @param tagetTS we are looking for a revision created at or right after the provided timestamp
 * @param revApi revisionApi object
 * @return the revision object, if it exists. null, else
 */
public static Revision getRevisionForTimestamp(int articleId, Timestamp targetTS, RevisionApi revApi) throws WikiApiException{
	DateTime targetDT = new DateTime(targetTS);
	Timestamp prevTS=null;
	for(Timestamp curTS:revApi.getRevisionTimestamps(articleId)){
		DateTime curDT = new DateTime(curTS);
		if(curDT.isEqual(targetDT)){
			return revApi.getRevision(articleId, curTS);
		}
		if(curDT.isAfter(targetDT)&&prevTS!=null){
			return revApi.getRevision(articleId, prevTS);
		}
		prevTS=curTS;
	}
	return null;		
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:24,代码来源:RevisionUtils.java

示例3: getRevisionByTimestampTest

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
@Test
public void getRevisionByTimestampTest()
{
	Calendar calendar = Calendar.getInstance();
	calendar.set(2008, 10, 10, 10, 10, 10);

	String pageName = "Car";
	try {
		RevisionApi revisionApi = new RevisionApi(
				wiki.getDatabaseConfiguration());
		int pageId = wiki.getPage(pageName).getPageId();

		Timestamp timestamp = new Timestamp(calendar.getTimeInMillis());

		Revision revision = revisionApi.getRevision(pageId, timestamp);

		assertEquals(1142935, revision.getRevisionID());
		assertEquals(0, revision.getFullRevisionID());
		assertEquals(349, revision.getRevisionCounter());
		assertEquals(pageId, revision.getArticleID());
	}
	catch (WikiApiException e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:27,代码来源:RevisionApiTest.java

示例4: lastRevisionTest

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
public void lastRevisionTest()
{
	Calendar calendar = Calendar.getInstance();
	calendar.set(2008, 10, 10, 10, 10, 10);

	String pageName = "Car";
	try {
		RevisionApi revisionApi = new RevisionApi(
				wiki.getDatabaseConfiguration());
		int pageId = wiki.getPage(pageName).getPageId();

		Timestamp lastRevisionTimestamp = revisionApi
				.getLastDateOfAppearance(pageId);
		Revision revision = revisionApi.getRevision(pageId,
				lastRevisionTimestamp);
		assertEquals(wiki.getPage(pageId).getText(),
				revision.getRevisionText());

	}
	catch (WikiApiException e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:25,代码来源:RevisionApiTest.java

示例5: ParagraphForwardChecker

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Creates a new ParagraphForwardChecker for the given Talk page revision using the JWPL Revision Iterator.
 * It builds a TreeMap that maps paragraphs to the revision in which the paragraph first appeared.
 * 
 * @param revApi a connection to the revision database used to initialize the RevisionIterator
 * @param searchToRevId the search limit for the revision
 * @throws WikiInitializationException in case the database cannot be accessed
 * @throws WikiApiException in case the database cannot be accessed
 */
public ParagraphForwardChecker(RevisionApi revApi, Revision searchToRevId) throws WikiInitializationException, WikiApiException{
	parToRevMap = new TreeMap<String,Revision>();
	TopicExtractor topicExtractor = new TopicExtractor();
	
	int firstRevPK = revApi.getFirstRevisionPK(searchToRevId.getArticleID());
	int lastRevPK = searchToRevId.getPrimaryKey();
	this.revIt = new RevisionIterator(revApi.getRevisionApiConfiguration(), firstRevPK, lastRevPK, revApi.getConnection());
	double revisionsToProcess = searchToRevId.getRevisionCounter();
	double curRevNumber = 1;
	int logPercent = 0; 
      	logger.debug("Processing "+revisionsToProcess+"");
	while(revIt.hasNext()){						
		Revision curRev = revIt.next();		
		if(curRev.getContributorId()==null||(curRev.getContributorId()!=null&&curRev.getContributorId()>0&&!revApi.getUserGroups(curRev.getContributorId()).contains("bot"))){
			for(Topic t:topicExtractor.getTopics(curRev.getRevisionText())){
				for(TalkPageParagraph tpp:t.getParagraphs()){					
					if(!parToRevMap.containsKey(reduceToChars(tpp.getText()))) 
					{ 
						parToRevMap.put(reduceToChars(tpp.getText()),curRev);							
					}
				}			
			}						
		}
  	        int curPercent=(int)Math.round(((curRevNumber++)/revisionsToProcess)*100);   	        
  	        if(curPercent%10==0&&curPercent!=logPercent){
  	        	System.out.println(curPercent+ "% of "+revisionsToProcess+" revisions processed");
  	        	logPercent=curPercent;
  	        }
	}	
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:40,代码来源:ParagraphForwardChecker.java

示例6: TalkPage

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * @param revApi
 *            RevisionApi instance
 * @param revId
 *            talk page revision to process
 * @param aggregateParagraphs
 *            whether to aggregate paragraphs to turns (true) or to consider
 *            paragraphs as turns on their own (false)
 */
public TalkPage(RevisionApi revApi, int revId, boolean aggregateParagraphs) {
	this.aggregateParagraphs = aggregateParagraphs;
	this.revApi=revApi;
	try {
		tpBaseRevision = revApi.getRevision(revId);
	} catch (WikiApiException e) {
		logger.error("Error checking revisions of origin for paragraphs. Could not process revision. Error accessing Wikipedia database with revision API",e);
	}
	_revisionSegmentParagraphs();
	_buildTurnsFromParagraphs();
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:21,代码来源:TalkPage.java

示例7: getRevisionForAge

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Returns the revision of an article at a particular age
 * 
 * @param articleId id of the article
 * @param creationTS explicitly defines the creation TimeStamp from where to count (e.g. if we want to retrieve the revision of the TalkPage based on the age of the article Page)
 * @param ageInDays age in days
 * @param revApi revisionApi object
 * @return the revision object, if it exists. null, else
 */
public static Revision getRevisionForAge(int articleId, Timestamp creationTS, int ageInDays, RevisionApi revApi) throws WikiApiException{
	DateTime creation = new DateTime(creationTS);
	DateTime version = creation.withFieldAdded(DurationFieldType.days(), ageInDays);
	for(Timestamp curTS:revApi.getRevisionTimestamps(articleId)){
		DateTime curDT = new DateTime(curTS);
		if(curDT.isEqual(version)||curDT.isAfter(version)){
			return revApi.getRevision(articleId, curTS);
		}
	}
	return null;		
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:21,代码来源:RevisionUtils.java

示例8: getRevisionBeforeTimestamp

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Returns the revision of an article at a particular age
 * 
 * @param articleId id of the article
 * @param tagetTS we are looking for a revision created at or right after the provided timestamp
 * @param revApi revisionApi object
 * @return the revision object, if it exists. null, else
 */
public static Revision getRevisionBeforeTimestamp(int articleId, Timestamp targetTS, RevisionApi revApi) throws WikiApiException{
	DateTime targetDT = new DateTime(targetTS);
	Timestamp prevTS=null;
	for(Timestamp curTS:revApi.getRevisionTimestamps(articleId)){
		DateTime curDT = new DateTime(curTS);
		if((curDT.isEqual(targetDT)||curDT.isAfter(targetDT))&&prevTS!=null){
			return revApi.getRevision(articleId, prevTS);
		}
		prevTS=curTS;
	}
	return null;		
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:21,代码来源:RevisionUtils.java

示例9: getRevisionByRevisionId

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
@Test
public void getRevisionByRevisionId()
{
	Calendar calendar = Calendar.getInstance();
	calendar.set(2008, 10, 10, 10, 10, 10);

	try {
		RevisionApi revisionApi = new RevisionApi(
				wiki.getDatabaseConfiguration());
		int pageId = wiki.getPage("Car").getPageId();

		Timestamp timestamp = new Timestamp(calendar.getTimeInMillis());

		Revision revision1 = revisionApi.getRevision(1142935);
		Revision revision2 = revisionApi.getRevision(pageId, timestamp);

		assertEquals(1142935, revision1.getRevisionID());
		assertEquals(0, revision1.getFullRevisionID());
		assertEquals(349, revision1.getRevisionCounter());

		assertEquals(revision1.getRevisionID(), revision2.getRevisionID());
		assertEquals(revision1.getFullRevisionID(),
				revision2.getFullRevisionID());
		assertEquals(revision1.getRevisionCounter(),
				revision2.getRevisionCounter());
		assertEquals(revision1.getArticleID(), revision2.getArticleID());

	}
	catch (WikiApiException e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:34,代码来源:RevisionApiTest.java

示例10: getRevisionByRevisionCounter

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
@Test
public void getRevisionByRevisionCounter()
{
	Calendar calendar = Calendar.getInstance();
	calendar.set(2008, 10, 10, 10, 10, 10);

	try {
		RevisionApi revisionApi = new RevisionApi(
				wiki.getDatabaseConfiguration());
		int pageId = wiki.getPage("Car").getPageId();

		Timestamp timestamp = new Timestamp(calendar.getTimeInMillis());

		Revision revision1 = revisionApi.getRevision(pageId, 349);
		Revision revision2 = revisionApi.getRevision(pageId, timestamp);

		assertEquals(1142935, revision1.getRevisionID());
		assertEquals(0, revision1.getFullRevisionID());
		assertEquals(349, revision1.getRevisionCounter());

		assertEquals(revision1.getRevisionID(), revision2.getRevisionID());
		assertEquals(revision1.getFullRevisionID(),
				revision2.getFullRevisionID());
		assertEquals(revision1.getRevisionCounter(),
				revision2.getRevisionCounter());
		assertEquals(revision1.getArticleID(), revision2.getArticleID());

	}
	catch (WikiApiException e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:34,代码来源:RevisionApiTest.java

示例11: articleIDTests

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
@Test
public void articleIDTests()
{
	Calendar calendar = Calendar.getInstance();
	calendar.set(2008, 10, 10, 10, 10, 10);

	try {
		RevisionApi revisionApi = new RevisionApi(
				wiki.getDatabaseConfiguration());
		int pageId = wiki.getPage("Car").getPageId();

		Timestamp firstDayOfAppearance = revisionApi
				.getFirstDateOfAppearance(pageId);
		Timestamp lastDayOfAppearance = revisionApi
				.getLastDateOfAppearance(pageId);
		int nrOfRevisions = revisionApi.getNumberOfRevisions(pageId);

		assertEquals("2004-04-07 02:31:34.0",
				firstDayOfAppearance.toString());
		assertEquals("2009-01-19 04:58:09.0",
				lastDayOfAppearance.toString());
		assertEquals(382, nrOfRevisions);

	}
	catch (WikiApiException e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:30,代码来源:RevisionApiTest.java

示例12: run

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {
	if(args.length!=8){			
		throw new RuntimeException("Incorrect number of launch parameters.");
	}
	final String discourseName=args[0];		

	final String dataSetName=args[1];		
	if(dataSourceService.dataSourceExists(dataSetName)){
		logger.warn("Dataset "+dataSetName+" has already been imported into DiscourseDB. Existing pages will be skipped.");			
	}
	
	final String titleListFilename=args[2];
	File titleListFile = new File(titleListFilename);
	if(!titleListFile.exists()||!titleListFile.isFile()){
		logger.error("Title list file "+titleListFilename+" cannot be read. Aborting ... ");			
		return;			
	}
	List<String> titles = FileUtils.readLines(titleListFile);

	logger.trace("Establishing connection to Wikipedia db...");
	DatabaseConfiguration dbconf = new DatabaseConfiguration();
	dbconf.setHost(args[3]);
	dbconf.setDatabase(args[4]);
	dbconf.setUser(args[5]);
	dbconf.setPassword(args[6]);
	dbconf.setLanguage(Language.valueOf(args[7]));
	Wikipedia wiki = new Wikipedia(dbconf);
	RevisionApi revApi = new RevisionApi(dbconf);
	
	RevisionBasedTalkPageExtractor extractor = null;
	logger.info("Start mapping Talk pages for "+titles.size()+" articles to DiscourseDB...");		
	int tpNum = 1;
	for(String title:titles){
		//first check if we alrady have the discussions from this article from a previous import
		if(discoursePartService.exists(discourseService.createOrGetDiscourse(discourseName), title, DiscoursePartTypes.TALK_PAGE)){
			logger.warn("Discussions for article "+title+ "have already been imported. Skipping ...");
			continue;			
		}			

		logger.info("Segmenting Talk Pages for article "+title);
		extractor = new RevisionBasedTalkPageExtractor(wiki, revApi, title, false, true);
		List<TalkPage> talkPages = extractor.getTalkPages();
		for(TalkPage tp:talkPages){
			if(tp!=null){
				logger.info("Mapping Talk Page #"+tpNum++);
				converterService.mapTalkPage(discourseName, dataSetName, title, tp);									
			}
		}
	}
	logger.info("Finished mapping Talk pages.");

	//manually close the hibernate session for the Wikipedia connection which is not managed by Spring
	WikiHibernateUtil.getSessionFactory(dbconf).close();
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:56,代码来源:WikipediaTalkPageConverter.java

示例13: RevisionUtils

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
public RevisionUtils(DatabaseConfiguration conf) throws WikiApiException{
	wiki = new Wikipedia(conf);
	revApi = new RevisionApi(conf);
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:5,代码来源:RevisionUtils.java

示例14: extractTemplates

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
/**
 * Extracts templates from pages and revisions
 */
private void extractTemplates() throws WikiApiException
{
	PageIterator pageIter = new PageIterator(getWiki(), true, pageBuffer);
	RevisionApi revApi = new RevisionApi(dbConf);

	int pageCounter = 0;
	long revisionCounter =0L;

	while (pageIter.hasNext()) {
		pageCounter++;

		if (pageCounter % VERBOSITY == 0) {
			logger.info(pageCounter + " pages processed ...");
		}

		Page curPage = pageIter.next();
		int curPageId = curPage.getPageId();


		//PROCESS PAGES
		if (mode.active_for_pages) {
			fillMapWithTemplateData(curPage.getText(), pageFilter, curPageId,
					TPLNAME_TO_PAGEIDS);
		}

		//PROCESS REVISIONS
		if (mode.active_for_revisions) {
			List<Timestamp> tsList = revApi.getRevisionTimestamps(curPageId);
			for(Timestamp ts:tsList){

				revisionCounter++;
				if (revisionCounter % (VERBOSITY*10) == 0) {
					logger.info(revisionCounter + " revisions processed ...");
				}

				Revision curRevision = revApi.getRevision(curPageId, ts);
				int curRevisionId = curRevision.getRevisionID();

				fillMapWithTemplateData(curRevision.getRevisionText(),
						revisionFilter, curRevisionId, TPLNAME_TO_REVISIONIDS);
			}
		}
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:48,代码来源:WikipediaTemplateInfoGenerator.java

示例15: RevisionUtils

import de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi; //导入依赖的package包/类
public RevisionUtils(DatabaseConfiguration conf) throws WikiApiException{
	wiki = new Wikipedia(conf);
	revApi = new RevisionApi(conf);	
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:5,代码来源:RevisionUtils.java


注:本文中的de.tudarmstadt.ukp.wikipedia.revisionmachine.api.RevisionApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。