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)
8 If you use this software for research, please cite the following paper in any
11 Hill, Benjamin Mako and Aaron Shaw. "Consider the Redirect: A Missing
12 Dimension of Wikipedia Research." In Proceedings of the 10th International
13 Symposium on Open Collaboration (OpenSym 2014). ACM Press, 2014.
17 These tools help you generate a redirect spells dataset from "raw" MediaWiki
18 XML dumps like those published by the Wikimedia foundation.
20 To uese these tools, you will need to a MediaWiki dump file. For Wikimedia
21 Foundation projects, you can download them all from:
22 http://dumps.wikimedia.org/
24 Wikis from Wikia.com and other Wikimedia projects all use the same XML format
27 In the examples in this README, I will use a dump of `Simple English
28 Wikipedia`__ that I downloaded with the following command::
30 wget http://dumps.wikimedia.org/simplewiki/20140410/simplewiki-20140410-pages-meta-history.xml.7z
32 __ https://simple.wikipedia.org/
34 Before you start, you may also want to change the default directories for
35 writing intermediate output files.
37 The default directories for writing and reading files are at the top of the
38 file `redirect_tools.R` and can be changed by editing that file. By default,
39 all files will be written to the subdirectory "./output" in the local
40 directory. If you want to use the default directories, you will still need to
41 create them 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 > page.id revision.id page.title timestamp deleted redirect target
68 > 1935456 17563584 Mikhail Alekseevich Lavrentiev 1116962833 FALSE FALSE NA
69 > 1935456 22034930 Mikhail Alekseevich Lavrentiev 1125245577 FALSE TRUE Mikhail Lavrentyev
71 In this case, the first revision of the article "Mikhail Alekseevich
72 Lavrentiev" was not a redirect but the second is a redirect to "Mikhail
75 If you were using the Simple English dump (which is a single file) I would
76 run the following command to send the output to the default ::
78 7za x -so simplewiki-20140410-pages-meta-history.xml.7z |
79 python2.7 01-extract_redirects.py | bzip2 -c - > output/redir/simple_redirs.tsz.bz2
81 Because our dumpfile is 7z compressed, I used 7za to uncompress it. If I had
82 used a gzip or bzip compressed file, I would use `zcat` or `bzcat` instead. I'm
83 also catting the output to `bzip2 -c` which will bzip the TSV output to
84 conserve space. The next step assumes a bzip2 compressed file. If you don't
85 want to bzip2 compress, you'll need to modify the code.
88 Step 2: Generate spells
89 =======================================================================
94 - data.table (http://cran.r-project.org/web/packages/data.table/)
95 - foriegn (http://cran.r-project.org/web/packages/foreign/)
99 - bzip compressed TSV files
103 - RData files containing data.frame of redirect spells named `redirect.spell`
104 (one file per input file)
105 - Stata DTA file (same data)
106 - TSV file (same data)
108 The file `redirect_tools.R` contains an R function `generate.spells()` that
109 takes a data frame of edit data as created in step 1 and a list of page title
110 and which will create a list of redirect spells for those pages. It also
111 contains a function `filename.to.spells()` which takes the filename of a bzip
112 compressed file of the form created in step 1 and outputs a full list of
115 You can run the command with::
117 R --no-save < 02-generate_spells.R
119 By default, output will be saved into `output/spells`.
123 Running Code in Parallel
124 =======================================================================
126 Because the full history dumps from the WMF foundation are split into many
127 files, it is can be appropriate to parse these dumps in parallel. Although the
128 specific ways you choose to do this will vary by the queuing system you use,
129 we've included examples of the scripts we used with Condor on the Harvard/MIT
130 Data Center (HMDC) in the "examples/" directory. They will not work without
131 modification for your computing environment because they have our environment
132 hardcoded in but they will give you an idea of where you might want to start.
134 Additionally, there is a third step `03-assemble_redirect_spells.R` that
135 contains R code that will read in all of the separate RData files, assmebles
136 the many smaller dataframes into a single data.frame, and then saves that
137 unified data.frame into a single RData file.