json-wikipedia travis-ci-badge

Json Wikipedia contains code to convert the Wikipedia XML dump into a JSON or avro dump.

Setup

compile the project running

mvn assembly:assembly

the command will produce a JAR file containing all the dependencies the target folder.

Convert the Wikipedia XML

You can convert the Wikipedia dump to JSON format by running the commands:

java -cp target/json-wikipedia-1.0.0-jar-with-dependencies.jar it.cnr.isti.hpc.wikipedia.cli.MediawikiToJsonCLI -input wikipedia-dump.xml.bz -output wikipedia-dump.json[.gz] -lang [en|it]

or

./scripts/convert-xml-dump-to-json.sh [en|it] wikipedia-dump.xml.bz wikipedia-dump.json[.gz]

Or to Apache Avro:

java -cp target/json-wikipedia-1.0.0-jar-with-dependencies.jar it.cnr.isti.hpc.wikipedia.cli.MediawikiToJsonCLI -input wikipedia-dump.xml.bz -output wikipedia-dump.avro -lang [en|it]

or

./scripts/convert-xml-dump-to-json.sh [en|it] wikipedia-dump.xml.bz wikipedia-dump.avro

Content of the output

Both the commands will produce a file contain a file containing a record for each article. In the JSON format each line of the file contains an article of dump encoded in JSON. Each record can be deserialized in an Article object, which represents an enriched version of the wikitext page. The Article object contains:

Usage

Once you have created (or downloaded) the JSON dump (say wikipedia.json), you can iterate over the articles of the collection easily using this snippet:

RecordReader<Article> reader = new RecordReader<Article>(
        "wikipedia.json",new JsonRecordParser<Article>(Article.class)
)

for (Article a : reader) {
// do what you want with your articles
}

In order to use these classes, you will have to install json-wikipedia in your maven repository:

mvn install

and import the project in your new maven project adding the dependency:

<dependency>
    <groupId>it.cnr.isti.hpc</groupId>
    <artifactId>json-wikipedia</artifactId>
    <version>2.0.0-SNAPSHOT</version>
</dependency>

Schema

The full schema of a record is encoded in avro