【问题标题】:Python to detect dipthongs in English [closed]Python检测英语双元音[关闭]
【发布时间】:2021-12-17 14:02:35
【问题描述】:

是否有 Python 库可以检测/突出显示给定英文文本中的所有双元音(正常拼写而不是国际音标)?

【问题讨论】:

  • 我不知道,但编码起来并不难,因为它们的数量有限。

标签: python nlp


【解决方案1】:

如果您将“双元音”定义为通常表示双元音的字母对/组合(“ee”、“ou”等),那么类似以下的内容将有助于搜索字母组合来自预定义的集合:

while len(text) > 0:
    # Iterate over dipthongs
    for d in DIPTHONGS:
        # If dipthong is in remaining text
        if d in text:
            # Partition remaining text
            before, dip, after = text.partition(d)
            # Append the part before and the highlighted dipthong to highlighted_text
            highlighted_text = highlighted_text + before
            highlighted_text = highlighted_text + f'*{d}*'
            # Update text to the remaining text
            text = after
    else:
        # No dipthongs found, so append remainder of text to highlighted_text
        highlighted_text = highlighted_text + text
        text = ''

print(highlighted_text)

输出:

我使用星号作为高亮显示,因为它既快速又简单,但您可以轻松调整此使用颜色,或者您的用例所需的任何颜色。

我想不出任何例子,但我怀疑在某些情况下拼写类似于双元音但发音不是双元音,反之亦然(因为英语就是这样)。要真正考虑发音,您可以使用 NLTK CMUdict 语料库之类的东西 - 请参阅https://www.nltk.org/book/ch02.html 的第 4.2 节开始。

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2010-10-03
    相关资源
    最近更新 更多