(w)
return w
Uses the Porter stemming algorithm to remove suffixes from English
    words.

    >>> stem("fundamentally")
    "fundament"
Uses the Porter stemming algorithm to remove suffixes from English
    words.
Uses the Porter stemming algorithm to remove suffixes from English words .
def stem(w):
    """Uses the Porter stemming algorithm to remove suffixes from English
    words.

    >>> stem("fundamentally")
    "fundament"
    """

    if len(w) < 3:
        return w

    first_is_y = w[0] == "y"
    if first_is_y:
        w = "Y" + w[1:]

    # Step 1a
    if w.endswith("s"):
        if w.endswith("sses"):
            w = w[:-2]
        elif w.endswith("ies"):
            w = w[:-2]
        elif w[-2] != "s":
            w = w[:-1]

    # Step 1b

    if w.endswith("eed"):
        s = w[:-3]
        if _mgr0.match(s):
            w = w[:-1]
    else:
        m = _ed_ing.match(w)
        if m:
            stem = m.group(1)
            if _s_v.match(stem):
                w = stem
                if _at_bl_iz.match(w):
                    w += "e"
                elif _step1b.match(w):
                    w = w[:-1]
                elif _c_v.match(w):
                    w += "e"

    # Step 1c

    if w.endswith("y"):
        stem = w[:-1]
        if _s_v.match(stem):
            w = stem + "i"

    # Step 2

    m = _step2.match(w)
    if m:
        stem = m.group(1)
        suffix = m.group(2)
        if _mgr0.match(stem):
            w = stem + _step2list[suffix]

    # Step 3

    m = _step3.match(w)
    if m:
        stem = m.group(1)
        suffix = m.group(2)
        if _mgr0.match(stem):
            w = stem + _step3list[suffix]

    # Step 4

    m = _step4_1.match(w)
    if m:
        stem = m.group(1)
        if _mgr1.match(stem):
            w = stem
    else:
        m = _step4_2.match(w)
        if m:
            stem = m.group(1) + m.group(2)
            if _mgr1.match(stem):
                w = stem

    # Step 5

    m = _step5.match(w)
    if m:
        stem = m.group(1)
        if _mgr1.match(stem) or (_meq1.match(stem) and not _c_v.match(stem)):
            w = stem

    if w.endswith("ll") and _mgr1.match(w):
        w = w[:-1]

    if first_is_y:
        w = "y" + w[1:]

    return w
def stem ( w ) : if len ( w ) < 3 : return w first_is_y = w [ 0 ] == "y" if first_is_y : w = "Y" + w [ 1 : ] # Step 1a if w . endswith ( "s" ) : if w . endswith ( "sses" ) : w = w [ : - 2 ] elif w . endswith ( "ies" ) : w = w [ : - 2 ] elif w [ - 2 ] != "s" : w = w [ : - 1 ] # Step 1b if w . endswith ( "eed" ) : s = w [ : - 3 ] if _mgr0 . match ( s ) : w = w [ : - 1 ] else : m = _ed_ing . match ( w ) if m : stem = m . group ( 1 ) if _s_v . match ( stem ) : w = stem if _at_bl_iz . match ( w ) : w += "e" elif _step1b . match ( w ) : w = w [ : - 1 ] elif _c_v . match ( w ) : w += "e" # Step 1c if w . endswith ( "y" ) : stem = w [ : - 1 ] if _s_v . match ( stem ) : w = stem + "i" # Step 2 m = _step2 . match ( w ) if m : stem = m . group ( 1 ) suffix = m . group ( 2 ) if _mgr0 . match ( stem ) : w = stem + _step2list [ suffix ] # Step 3 m = _step3 . match ( w ) if m : stem = m . group ( 1 ) suffix = m . group ( 2 ) if _mgr0 . match ( stem ) : w = stem + _step3list [ suffix ] # Step 4 m = _step4_1 . match ( w ) if m : stem = m . group ( 1 ) if _mgr1 . match ( stem ) : w = stem else : m = _step4_2 . match ( w ) if m : stem = m . group ( 1 ) + m . group ( 2 ) if _mgr1 . match ( stem ) : w = stem # Step 5 m = _step5 . match ( w ) if m : stem = m . group ( 1 ) if _mgr1 . match ( stem ) or ( _meq1 . match ( stem ) and not _c_v . match ( stem ) ) : w = stem if w . endswith ( "ll" ) and _mgr1 . match ( w ) : w = w [ : - 1 ] if first_is_y : w = "y" + w [ 1 : ] return w