Last active
August 29, 2015 13:57
-
-
Save xecutioner/9596695 to your computer and use it in GitHub Desktop.
Wikimedia article extractions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #STEP 1: Use media labs tool to generate doc based xml from the wikipedia dump. | |
| ---------------------------- | |
| # Use medialab's extractor tool http://medialab.di.unipi.it/wiki/Wikipedia_Extractor | |
| > wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2 | |
| > bzcat enwiki-latest-pages-articles.xml.bz2 | | |
| WikiExtractor.py -cb 250K -o extracted | |
| In order to combine the whole extracted text into a single file one can issue: | |
| > find extracted -name '*bz2' -exec bunzip2 -c {} \; > wiki_parsed.xml | |
| > rm -rf extracted | |
| STEP 2 | |
| -------------------------------- | |
| # Remove any untouched incomplete tags | |
| sed -i.bak -e 's/<[^doc>/!][^ >][^>]*>//g;s/<\/[^doc>][^>]*>//g' wiki_parsed.xml | |
| STEP 3 : Generate a valid xml to be parsed. | |
| ----------------------------------------- | |
| # Prepend a head tag to validate a proper xml to be parsed by xml parsers | |
| echo "<head>"|cat - yourfile > /tmp/out && mv /tmp/out yourfile | |
| OR | |
| sed -i '1s/^/<head> /' file | |
| check if the last doc tag is closed or not if not close it. | |
| #Close the head tag | |
| echo "</head>" >> file | |
| STEP 4 : Split the large xml into different files with each file being an article. | |
| ------------------------------------------------------------------------------------------- | |
| # Incase we want to go with spliting the big xml into the smaller files one for each article. | |
| awk '/<doc/{x="F"++i;}{print > x;}' wiki_parsed.xml | |
| OR https://github.com/seamusabshere/xml_split | |
| xml_split wiki_parsed.xml doc splitted/mon | |
| --- more http://www.theunixschool.com/2012/06/awk-10-examples-to-split-file-into.html | |
| STEP 5: Run the rake task to get the data out and dump into the database. | |
| ------------------------------------------------------------------------------------------- | |
| Considering the splitted docs are in the splitted directory | |
| bundle exec rake 'wiki_extractor:extract_to_db[splitted]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment