위키페디어 덤프 파일 mongoDB 임포트 및 php에서 사용

Step by Step to access wikipedia dump using MongoDB and PHP for data analytics

In an effort to evaluate how to handle unstructured data using mongodb I write this post to extract data from WikiDump and importing to Mongodb and accessing the same using PHP MongoDB Client libraries. Subsequently to do behavior analytics on the data.

Objective: Retrieve the wikidump import it into mongodb and retrieve the data using mongoclient.

Pre-Requisites: We would need the following softwares are pre-requisites for going step by step as per the post.

Step by Step Procedure: Importing the Tamil Wikipedia Dump to MongoDb.

Step 1: First you can download the wikipedia dump from the website dumps.wikipedia.org. In this case I downloaded the Tamil wiki dump from the following location http://dumps.wikimedia.org/tawiki/20131204/

Step 2: Then I would like to analyze the articles in the Tamil wikipedia so downloaded the file tawiki-20131204-pages-articles.xml.bz2 which is of 68.5 MB size

Step 3: You would also need the appropriate library for handling mongoclient and bzopen libraries. Please download those and use it accordingly.

Step 3a: MongoClient Library installation: http://www.php.net/manual/en/mongo.installation.php and look at the s3 amazon link location I downloaded php_mongo-1.4.5.zip.

Note: Extract that zip file and download appropriate version dll to the ext folder of php location. Make sure to add extension=php_mongo-1.4.5-5.4-vc9-x86_64.dll to php.ini ( I was running this in 64-bit os, choose appropariately)

Step 3b: BZip Installation: http://www.bzip.org/ and refer this link http://www.php.net/manual/en/bzip2.setup.php for setting up of the BZip library in PHP.

Note:

a. BZip2.dll has to be copied from the BZip installation folder to php folder, refer the picture given below).

b. Make sure to add extension=php_bz2.dll to php.ini or uncomment the same if it exists.

Step 4: Make sure you are running mongodb using the command line interface as shown in the picture below:

Step 5: Enough of setup, now it’s time to import the data from the wikidump to the mongodb. Please follow the instructions on executing the PHP file for importing from the command line. We will use the PHP code from James Linden from the URL provided here http://jameslinden.com/dataset/wikipedia.org/xml-dump-import-mongodb/.

Download the PHP script and place it under WAMP/XAMPP folder accordingly. Make sure you change the $dsname = ‘mongodb://localhost/wp20130708’;
$file = ‘enwiki-20130708-pages-articles.xml.bz2’;
$log = ‘./’;

aspects in the PHP Script. Then go to the command prompt and give the command PHP wikipedia.org-xmldump-mongodb.php.

I’m running the file from PHPScript folder but executing the PHP bin folder. This will also create a log file while the execution is complete.

Step 6: We will verify the imported data using the client mongo

Step 7: The following PHP Code helps to connect to the mongodb which has the wikidump

The following is the code which has modified:

<code>

<meta http-equiv=”content-type” content=”text/html;charset=utf-8″ />

<?php

// PHP code to look at the Wikipedia data which are imported from Wikipedia Dump to MongoDB

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

$dbhost = ‘mongodb://localhost/tawiki’;

$dbname = “tawiki”;

//Connect to the localhost

$m = new mongoclient($dbhost);

//Retrive the collections exists in the database “tawiki”

$db = $m->selectDB(“tawiki”);

$collections=$db->getCollectionNames();

//Display the Collections

echo (“<b>Collections in </b>” . $dbname . “<br/><hr/>”);

var_dump($collections);

//Lets retrive the data in the collection “Page”

$collection=new MongoCollection($db, ‘page’);

//$Query =array();//(“username” => “Seesiva”);

$Query =array(“revision.contributor.username”=>”Seesiva”);

$cursor = $collection->find($Query);

$mycount=0;

$mycount=$cursor->count(true);

echo (“<b>Titles Contribution for the Query: </b>” . array_shift($Query) . ” and total results found:” . strval($mycount) .”<br/><hr/>”);

//Retrieve the titles contributed by the User

foreach ($cursor as $doc) {

//var_dump($doc[‘title’]);

    var_dump($doc);

//echo($doc[‘title’]);

    }

?>

</code>

Step 8: Find the results

 

 

[출처] https://sivaanalytics.wordpress.com/2013/12/22/wikipedia-content-access-to-mongodb-and-php-for-data-analytics-step-by-step/

 

 
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
778 인텔 x86 어셈블리 메뉴얼 The Intel Assembly Manual file 졸리운_곰 2019.01.24 158
777 Machine Learning in Excel file 졸리운_곰 2019.01.23 180
776 올한해 React.js 개발을 접다 - 충동적인 프레임워크 변경에서 오는 후회 file 졸리운_곰 2019.01.19 106
775 ◈ 금강경(金剛經) 전문(全文) 및 풀이 글 졸리운_곰 2019.01.16 469
774 금강경 한글 전문 졸리운_곰 2019.01.16 272
773 금강경 전문 졸리운_곰 2019.01.16 390
772 How to Call SWI-Prolog from PHP 5 졸리운_곰 2019.01.09 430
» 위키페디어 덤프 파일 mongoDB 임포트 및 php에서 사용 file 졸리운_곰 2019.01.08 204
770 Windows 10에서 VisualStudio 6 설치 file 졸리운_곰 2019.01.07 357
769 [WPF] MVC, MVP, MVVM 차이점 file 졸리운_곰 2019.01.06 131
768 MVC, MVP, MVVM 비교 file 졸리운_곰 2019.01.06 114
767 텍스트 마이닝 무엇을 할 수 있을까? 졸리운_곰 2019.01.03 107
766 SD(System Dynamics, 시스템타이내믹스)의 개요 졸리운_곰 2019.01.03 85
765 100 Best GitHub: Expert System 100 깃허브의 전문가 시스템 오픈소스 file 졸리운_곰 2019.01.01 163
764 윈도우10에서 배드섹터복구하는 3가지 방법 : Bad Sector Repair in Windows 10 (3 Ways Included) file 졸리운_곰 2018.12.29 406
763 경제금융용어 700선-게시용.pdf file 졸리운_곰 2018.12.28 712
762 [경제] 경제 영어 (용어) 20000 졸리운_곰 2018.12.28 2458
761 영어 경영용어정리했으니 확인하세요 ^^ file 졸리운_곰 2018.12.28 504
760 경제경영 용어 정리(인사, 노무, 재무, 회계) 졸리운_곰 2018.12.28 496
759 주식관련 용어 정리 졸리운_곰 2018.12.27 673
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED