code: def extract_pages(f, filter_namespaces=False, filter_articles=None):
      """Extract pages from a MediaWiki database dump.
  
      Parameters
      ----------
      f : file
          File-like object.
      filter_namespaces : list of str or bool
           Namespaces that will be extracted.
  
      Yields
      ------
      tuple of (str or None, str, str)
          Title, text and page id.
  
      """
      elems = (elem for _, elem in iterparse(f, events=("end",)))
  
      # We can't rely on the namespace for database dumps, since it's changed
      # it every time a small modification to the format is made. So, determine
      # those from the first element we find, which will be part of the metadata,
      # and construct element paths.
      elem = next(elems)
      namespace = get_namespace(elem.tag)
      ns_mapping = {"ns": namespace}
      page_tag = "{%(ns)s}page" % ns_mapping
      text_path = "./{%(ns)s}revision/{%(ns)s}text" % ns_mapping
      title_path = "./{%(ns)s}title" % ns_mapping
      ns_path = "./{%(ns)s}ns" % ns_mapping
      pageid_path = "./{%(ns)s}id" % ns_mapping
  
      for elem in elems:
          if elem.tag == page_tag:
              title = elem.find(title_path).text
              text = elem.find(text_path).text
  
              if filter_namespaces:
                  ns = elem.find(ns_path).text
                  if ns not in filter_namespaces:
                      text = None
  
              if filter_articles is not None:
                  if not filter_articles(
                      elem,
                      namespace=namespace,
                      title=title,
                      text=text,
                      page_tag=page_tag,
                      text_path=text_path,
                      title_path=title_path,
                      ns_path=ns_path,
                      pageid_path=pageid_path,
                  ):
                      text = None
  
              pageid = elem.find(pageid_path).text
              yield title, text or "", pageid  # empty page will yield None
  
              # Prune the element tree, as per
              # http://www.ibm.com/developerworks/xml/library/x-hiperfparse/
              # except that we don't need to prune backlinks from the parent
              # because we don't use LXML.
              # We do this only for <page>s, since we need to inspect the
              # ./revision/text element. The pages comprise the bulk of the
              # file, so in practice we prune away enough.
              elem.clear()
  
imports: import bz2
  import logging
  import multiprocessing
  import re
  import signal
  from pickle import PicklingError
  from xml.etree.ElementTree import iterparse
  from gensim import utils
  from gensim.corpora.dictionary import Dictionary
  from gensim.corpora.textcorpus import TextCorpus
label_desc: Use image node_id 9 for calling a global function with example usage: extract_pages(f, filter_namespaces, filter_articles) without return types