<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 XML Processing Example
Step1:  Step 1
Step2:  Step 2
Step3:  Step 3
Step4:  OK.  Now that everything is defined, it's time to run the code.  mwxml has a map() function that applied the process_dump function each of the XML dump file in paths -- in parallel -- using python's multiprocessing library and collects all of the yielded values in a generator.  As the code below demonstrates, it's easy to collect this output and write it to a new output file or print it out to the console (not recommended for large amounts of output).
<ASSISTANT_TASK:>
Python Code:
import mwxml
Explanation: XML Processing Example: Extract link count changes
This notebook details how to use the mwxml python library to efficiently process an entire Wikipedia-sized historical XML dump.  In this example, we'll extract image link-count change events from the history of Dutch Wikipedia.
End of explanation
import glob
paths = glob.glob('/public/dumps/public/nlwiki/20151202/nlwiki-20151202-pages-meta-history*.xml*.bz2')
paths
Explanation: Step 1: Gather the paths to all of the dump files
On tool labs, the XML dumps are available in /public/dumps/public/.  We're going to use python's glob library to get the paths of the Dutch Wikipedia dump (December 02, 2015) that contains the text of all revisions.
End of explanation
import re
EXTS = ["png", "gif", "jpg", "jpeg"]
# [[(file|image):<file>.<ext>]]
IMAGE_LINK_RE = re.compile(r"\[\[" + 
                           r"(file|image|afbeelding|bestand):" +  # Group 1
                           r"([^\]]+.(" + "|".join(EXTS) + r"))" +  # Group 2 & 3
                           r"(|[^\]]+)?" +  # Group 4
                           r"\]\]")
def extract_image_links(text):
  for m in IMAGE_LINK_RE.finditer(text):
    yield m.group(2)
Explanation: Step 2: Define the image link extractor.
Here we're using a regular expression to extract image links from the revision text of articles. Nothing fancy here.
End of explanation
def process_dump(dump, path):
  for page in dump:
    last_count = 0
    for revision in page:
      image_links = list(extract_image_links(revision.text or ""))
      delta = len(image_links) - last_count
      if delta != 0:
        yield revision.id, revision.timestamp, delta
      last_count = len(image_links)
Explanation: Step 3: Run the XML dump processor on the paths
This is the part that mwxml can help you do easily.  You need to define a process_dump function that takes two arguements: dump : mwxml.Dump and a path : str 
In the example, below, we iterate through the pages in the dump, and keep track of how many image links we saw in the last revision with last_count.  If the delta isn't 0, we yield some values.  It's very important that the process_dump function either yields something or returns an iterable.  We'll explain why in a moment.
End of explanation
count = 0
for rev_id, rev_timestamp, delta in mwxml.map(process_dump, paths):
    print("\t".join(str(v) for v in [rev_id, rev_timestamp, delta]))
    count += 1
    if count > 15:
        break
Explanation: OK.  Now that everything is defined, it's time to run the code.  mwxml has a map() function that applied the process_dump function each of the XML dump file in paths -- in parallel -- using python's multiprocessing library and collects all of the yielded values in a generator.  As the code below demonstrates, it's easy to collect this output and write it to a new output file or print it out to the console (not recommended for large amounts of output).
End of explanation
<END_TASK>