1 MediaWiki Redirect Tools
2 =======================================================================
4 | **Author:** `Benjamin Mako Hill`__ <mako@atdot.cc>
5 | **Homepage:** http://networkcollectiv.es/wiki-redirects/
6 | **License:** `GNU GPLv3 or any later version`__ (see COPYING)
7 | **Description:** Tools to to generate a redirect spells dataset from "raw" MediaWiki XML dumps like those published by the Wikimedia foundation.
10 __ http://www.gnu.org/copyleft/gpl.html
12 If you use this software for research, please **cite the following
13 paper** in any resulting publication:
15 *Hill, Benjamin Mako and Aaron Shaw. "Consider the Redirect: A Missing
16 Dimension of Wikipedia Research." In Proceedings of the 10th International
17 Symposium on Open Collaboration (OpenSym 2014). ACM Press, 2014.*
21 To use these tools, you will need need to start with a MediaWiki dump
22 file. For Wikimedia Foundation projects, you can download them all from:
23 http://dumps.wikimedia.org/
25 Wikis from Wikia.com and other Wikimedia projects all use the same XML format
28 In the examples in this README, I will use a dump of `Simple English
29 Wikipedia`__ that I downloaded with the following command::
31 wget http://dumps.wikimedia.org/simplewiki/20140410/simplewiki-20140410-pages-meta-history.xml.7z
33 __ https://simple.wikipedia.org/
35 Before you start, you may also want to change the default directories
36 for writing intermediate output files. The default directories for
37 writing and reading files are at the top of the file `redirect_tools.R`
38 and can be changed by editing that file. By default, all files will be
39 written to the subdirectory "./output" in the local directory. If you
40 want to use the default directories, you will still need to create them
41 with a command like this::
43 mkdir output/redir output/spells
45 Step 2: Find Redirects in Revisions
46 =======================================================================
51 - Wikimedia Utilities (https://bitbucket.org/halfak/wikimedia-utilities)
55 - Wikimedia XML Dump files (compressed in some form)
59 - bzip2 compressed TSV files (one line per revision)
61 Run the file `01-extract_redirects.py` to build a dataset of revisions or edits
62 that marks every revisions as either containinig a revision, or not.
64 The script `01-extract_redirects.py` takes a MediaWiki dump file on STDIN and
65 outputs a TSV file on STDOUT of the following form.
67 +---------+-------------+--------------------------------+------------+---------+----------+--------------------+
68 | page.id | revision.id | page.title | timestamp | deleted | redirect | target |
69 +=========+=============+================================+============+=========+==========+====================+
70 | 1935456 | 17563584 | Mikhail Alekseevich Lavrentiev | 1116962833 | FALSE | FALSE | NA |
71 | 1935456 | 22034930 | Mikhail Alekseevich Lavrentiev | 1125245577 | FALSE | TRUE | Mikhail Lavrentyev |
72 +---------+-------------+--------------------------------+------------+---------+----------+--------------------+
75 In this case, the first revision of the article "Mikhail Alekseevich
76 Lavrentiev" was not a redirect but the second is a redirect to "Mikhail
79 If you were using the Simple English dump (which is a single file) I would
80 run the following command to send the output to the default ::
82 7za x -so simplewiki-20140410-pages-meta-history.xml.7z |
83 python2.7 01-extract_redirects.py | bzip2 -c - > output/redir/simple_redirs.tsz.bz2
85 Because our dumpfile is 7z compressed, I used 7za to uncompress it. If I had
86 used a gzip or bzip compressed file, I would use `zcat` or `bzcat` instead. I'm
87 also catting the output to `bzip2 -c` which will bzip the TSV output to
88 conserve space. The next step assumes a bzip2 compressed file. If you don't
89 want to bzip2 compress, you'll need to modify the code.
92 Step 2: Generate spells
93 =======================================================================
98 - data.table (http://cran.r-project.org/web/packages/data.table/)
99 - foriegn (http://cran.r-project.org/web/packages/foreign/)
103 - bzip compressed TSV files
107 - RData files containing data.frame of redirect spells named `redirect.spell`
108 (one file per input file)
109 - Stata DTA file (same data)
110 - TSV file (same data)
112 The file `redirect_tools.R` contains an R function `generate.spells()` that
113 takes a data frame of edit data as created in step 1 and a list of page title
114 and which will create a list of redirect spells for those pages. It also
115 contains a function `filename.to.spells()` which takes the filename of a bzip
116 compressed file of the form created in step 1 and outputs a full list of
119 You can run the command with::
121 R --no-save < 02-generate_spells.R
123 By default, output will be saved into `output/spells`.
127 Running Code in Parallel
128 =======================================================================
130 Because the full history dumps from the WMF foundation are split into many
131 files, it is can be appropriate to parse these dumps in parallel. Although the
132 specific ways you choose to do this will vary by the queuing system you use,
133 we've included examples of the scripts we used with Condor on the Harvard/MIT
134 Data Center (HMDC) in the "examples/" directory. They will not work without
135 modification for your computing environment because they have our environment
136 hardcoded in but they will give you an idea of where you might want to start.
138 Additionally, there is a third step `03-assemble_redirect_spells.R` that
139 contains R code that will read in all of the separate RData files, assmebles
140 the many smaller dataframes into a single data.frame, and then saves that
141 unified data.frame into a single RData file.