Exemple #1
0
def process_page(page, index, parsed):
    pagetitle = unicode(page.title())

    def pagemsg(txt):
        msg("Page %s %s: %s" % (index, pagetitle, txt))

    notes = []

    pagemsg("Processing")

    head = None
    for t in parsed.filter_templates():
        origt = unicode(t)
        tn = tname(t)
        if tn == "be-adj":
            head = getparam(t, "1")
            if getparam(t, "head2"):
                pagemsg("WARNING: Can't handle head2= yet in {{rfinfl}}")
                head = None
        elif tn == "rfinfl" and getparam(t, "1") == "be" and getparam(
                t, "2") == "adjective":
            if not head:
                pagemsg("WARNING: Found {{rfinfl}} and don't have head: %s" %
                        origt)
            elif " " in head:
                pagemsg(
                    "Found {{rfinfl}} but head %s has space in it, skipping" %
                    head)
            else:
                rmparam(t, "2")
                t.add("1", head)
                blib.set_template_name(t, "be-adecl")
                notes.append("add Belarusian adjective declension for %s" %
                             head)
        elif tn == "be-decl-adj":
            word = getparam(t, "1") + getparam(t, "2")
            if belib.needs_accents(word):
                pagemsg("WARNING: Word %s needs accent: %s" % (word, origt))
                continue
            t.add("1", word)
            rmparam(t, "2")
            blib.set_template_name(t, "be-adecl")
            notes.append("convert {{be-decl-adj}} to {{be-adecl}}")
        elif tn == "be-adj-table":
            notesval = getparam(t, "notes")
            if notesval:
                notesval = re.sub("^: ", "", notesval)
                if not re.search(r"\.\s*$", notesval):
                    notesval = re.sub(r"(\s*)$", r".\1", notesval)
                t.add("footnote",
                      notesval,
                      before="notes",
                      preserve_spacing=False)
                rmparam(t, "notes")
            blib.set_template_name(t, "be-adecl-manual")
            notes.append("convert {{be-adj-table}} to {{be-adecl-manual}}")
        if origt != unicode(t):
            pagemsg("Replaced %s with %s" % (origt, unicode(t)))

    return unicode(parsed), notes
  def process_adj_headt(t):
    origt = unicode(t)
    def getp(param):
      return getparam(t, param)
    tr = getp("tr")
    head = getp("head")
    if getp("1"):
      pagemsg("WARNING: Has 1=%s: %s" % (getp("1"), origt))
      return
    must_continue = False
    for param in t.params:
      pn = pname(param)
      if pn not in ["head", "tr"]:
        pagemsg("WARNING: Unrecognized param %s=%s, skipping: %s" %
            (pn, unicode(param.value), origt))
        must_continue = True
        break
    if must_continue:
      return False
    del t.params[:]
    if not head:
      head = pagetitle
    if belib.needs_accents(head):
      pagemsg("WARNING: Head %s missing accents: %s" % (head, origt))
    t.add("1", head)
    if tr:
      t.add("tr", tr)

    if origt != unicode(t):
      notes.append("fix up {{be-adj}} to use new param convention")
      pagemsg("Replaced %s with %s" % (origt, unicode(t)))
    return True
Exemple #3
0
 def check_multi_stressed(maxparam):
     for i in xrange(1, maxparam + 1):
         val = getparam(t, str(i))
         vals = re.split(r",\s*", val)
         for v in vals:
             if be.is_multi_stressed(v):
                 pagemsg(
                     "WARNING: Param %s=%s has multiple stresses: %s" %
                     ((str(i), val, unicode(t))))
             if be.needs_accents(v):
                 pagemsg("WARNING: Param %s=%s has missing stress: %s" %
                         ((str(i), val, unicode(t))))
 def split_form(form):
   forms = re.split(r",\s*", form.strip())
   forms = [re.sub(r"^\[\[([^\[\]]*)\]\]$", r"\1", f) for f in forms]
   forms = [belib.add_accent_to_o(f) for f in forms]
   for f in forms:
     if "[[" in f:
       pagemsg("WARNING: Link in form %s: headword=%s, decl=%s" %
           (f, origt, origdeclt))
     if belib.needs_accents(f):
       pagemsg("WARNING: Form %s missing accents: headword=%s, decl=%s" %
           (f, origt, origdeclt))
   forms = [f for f in forms if f != "-"]
   return forms
  def process_verb_headt(t):
    origt = unicode(t)
    def getp(param):
      return getparam(t, param)
    tr = getp("tr")
    if getp("2"):
      head = getp("1")
      g = getp("2")
    else:
      head = getp("head")
      g = getp("1") or getp("a")
    pf = blib.fetch_param_chain(t, "pf", "pf")
    impf = blib.fetch_param_chain(t, "impf", "impf")
    must_continue = False
    for param in t.params:
      pn = pname(param)
      if pn not in ["head", "tr", "1", "a", "2", "pf", "pf2", "pf3",
          "impf", "impf2", "impf3"]:
        pagemsg("WARNING: Unrecognized param %s=%s, skipping: %s" %
            (pn, unicode(param.value), origt))
        must_continue = True
        break
    if must_continue:
      return False
    del t.params[:]
    if not head:
      head = pagetitle
    if belib.needs_accents(head):
      pagemsg("WARNING: Head %s missing accents: %s" % (head, origt))
    if not g:
      pagemsg("WARNING: No aspect in verb headword: %s" % origt)
      g = "?"
    t.add("1", head)
    if tr:
      t.add("tr", tr)
    t.add("2", g)
    blib.set_param_chain(t, pf, "pf", "pf")
    blib.set_param_chain(t, impf, "impf", "impf")

    if origt != unicode(t):
      notes.append("fix up {{be-verb}} to use new param convention")
      pagemsg("Replaced %s with %s" % (origt, unicode(t)))
    return True