gpt4 book ai didi

python - 用 Python 解析莎士比亚文本

转载 作者:行者123 更新时间:2023-12-01 06:03:56 24 4
gpt4 key购买 nike

这是我要解析的源文本:

                       1      From fairest creatures we desire increase,      That thereby beauty's rose might never die,      But as the riper should by time decease,      His tender heir might bear his memory:      But thou contracted to thine own bright eyes,      Feed'st thy light's flame with self-substantial fuel,      Making a famine where abundance lies,      Thy self thy foe, to thy sweet self too cruel:      Thou that art now the world's fresh ornament,      And only herald to the gaudy spring,      Within thine own bud buriest thy content,      And tender churl mak'st waste in niggarding:        Pity the world, or else this glutton be,        To eat the world's due, by the grave and thee.                         2      When forty winters shall besiege thy brow,      And dig deep trenches in thy beauty's field,      Thy youth's proud livery so gazed on now,      Will be a tattered weed of small worth held:        Then being asked, where all thy beauty lies,      Where all the treasure of thy lusty days;      To say within thine own deep sunken eyes,      Were an all-eating shame, and thriftless praise.      How much more praise deserved thy beauty's use,      If thou couldst answer 'This fair child of mine      Shall sum my count, and make my old excuse'      Proving his beauty by succession thine.        This were to be new made when thou art old,        And see thy blood warm when thou feel'st it cold.                         3      Look in thy glass and tell the face thou viewest,      Now is the time that face should form another,      Whose fresh repair if now thou not renewest,      Thou dost beguile the world, unbless some mother.      For where is she so fair whose uneared womb      Disdains the tillage of thy husbandry?      Or who is he so fond will be the tomb,      Of his self-love to stop posterity?        Thou art thy mother's glass and she in thee      Calls back the lovely April of her prime,      So thou through windows of thine age shalt see,      Despite of wrinkles this thy golden time.        But if thou live remembered not to be,        Die single and thine image dies with thee.

我想将它解析成这样的 block :

第一个 block 应该是:

From fairest creatures we desire increase, That thereby beauty's rose might never die, But as the riper should by time decease, His tender heir might bear his memory: But thou contracted to thine own bright eyes, Feed'st thy light's flame with self-substantial fuel, Making a famine where abundance lies, Thy self thy foe, to thy sweet self too cruel: Thou that art now the world's fresh ornament, And only herald to the gaudy spring, Within thine own bud buriest thy content, And tender churl mak'st waste in niggarding: Pity the world, or else this glutton be, To eat the world's due, by the grave and thee.

第二个:

When forty winters shall besiege thy brow, And dig deep trenches in thy beauty's field, Thy youth's proud livery so gazed on now, Will be a tattered weed of small worth held:
Then being asked, where all thy beauty lies, Where all the treasure of thy lusty days; To say within thine own deep sunken eyes, Were an all-eating shame, and thriftless praise.

第三个:

How much more praise deserved thy beauty's use, If thou couldst answer 'This fair child of mine Shall sum my count, and make my old excuse' Proving his beauty by succession thine. This were to be new made when thou art old, And see thy blood warm when thou feel'st it cold.

...等等。每次句子以 . 结尾时,我都希望该部分成为一个新 block 。

如何解析这样的内容?我想要一些指导方针,以明确有效的方式来做到这一点。我不想一个字符一个字符地进行一些检查……

谢谢

最佳答案

您可能可以将其拆分为:

re.split(r"(?:^|(?:[^\S\n]*\n){2}(?m)^)[ \t]+\d+[ \t]+[\r\n]+", text)

关于python - 用 Python 解析莎士比亚文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com