Skip to main content

mwparallelparser

mwparallelparser (the MediaWiki Parallel Parser) is a Python package that provides a parallel parser for MediaWiki wikicode

The name parallel parser refers to the idea of parallel markup proposed by Ted Nelson. In the parallel markup approach, the raw text data and the formatting information are kept separately. Each formatting tag contains information about its position in the document. This format has many advantages over traditional embedded markup. Among others, it is much more natural for many machine learning-related topics.

There are several key assumptions for the parser, that should be kept in mind:

  • The raw text data should be as clean as possible. The parser should remove any formatting syntax, even when corresponding parallel markup isn’t produced.

  • The white spaces should be removed if they don’t provide any additional information. That means that several following spaces in the wikicode should be rendered as one space character if it is a part of a normal paragraph. Also, the empty lines are removed.

Installation

The mwparallelparser is avaliable through Python Package Index; you can install the latest release with pip install mwparallelparser

Usage

Normal usage is rather straightforward (where wikicode is the syntax to parse):

>>> from mwparallelparser import Parser
>>> parser = Parser()
>>> parallel_wikicode = parser.parse(wikicode)
>>> print(wikicode['lines'])
>>> print(wikicode['tags'])

The wikicode['lines'] contains the raw text lines, generated from the given wikicode. The lines are kept in a List (without a newline character at the end). Unless specified otherwise by some tag, each line represents a paragraph. Just like in the original MediaWiki parser, the paragraphs are joined to a single output line if they are separated only by one new line character in a source file.

The wikicode['tags'] contains a List of parallel tags in the document. Each tag is represented by a Dict with the following structure:

{
    'type': string,  # tag type, in mwparallelparser usually the same as HTML tag name
    'spans': [       # a List of tags positions in the document
        {'line': int,
         'start': int,
         'length': int},
        {'line': int}
    ],
    'attributes': {} # dictionary of tag attributes. Individual for each tag type.
}

Each span must be a continuous fragment of the document, but no longer than one line of the output. If the tag is longer than one line, many spans are defined. There are two types of spans. The first is line spans, which selects the entire line: {'line': int}. The second is inline spans, which selects only part of a line: {'line': int, 'start': int, 'length': int}. In the inline spans, the 'start' defines the index of a first character inside the span, the 'length' defines a number of characters that are included in the span.

Supported tags

Development

The project contains unit tests that checks if the parser works as expected. To execute all the tests run the following command in the project root dictionary:

python -m unittest

To execute a specific test suite:

python -m unittest tests/test_wikilink.py

Release files for mwparallelparser 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mwparallelparser 0.1.7
File Size Uploaded
mwparallelparser-0.1.7.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mwparallelparser 0.1.7
File Interpreter ABI Platform
mwparallelparser-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size:20.4 kB

Release files / mwparallelparser-0.1.7.tar.gz

Download URL mwparallelparser-0.1.7.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e88be601e06da03718af443d5720d26bcc09f627e00d11b6cfbe547714859424
BLAKE2b-256 checksum
How to use checksums
2689be65f558fd162718170964a6cb428dea7af69e87152da8dac206cc14855f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / mwparallelparser-0.1.7-py3-none-any.whl

Download URL mwparallelparser-0.1.7-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6c4ed6d7b89926ee3f822b670c83836ab91fe9c0240e0230da7ee81b155a567
BLAKE2b-256 checksum
How to use checksums
f017a23afc2064bd77b40af08308eb5fd7fa3bb8335f6278f9dbf75e93d98adc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page