gpt4 book ai didi

javascript - 有没有办法找出文本/ Markdown 文件中文本的诗歌风格?

转载 作者:行者123 更新时间:2023-11-30 19:23:59 27 4
gpt4 key购买 nike

有一个 Markdown /文本文件,在正常段落之间有诗意的短语,像这样:

Mr. Lewes reaches this conclusion: "If, therefore, we reflect what a poem _Faust_ is, and that it contains almost every variety of style and metre, it will be tolerably evident that no one unacquainted with the original can form an adequate idea of it from translation,"  which is certainly correct of any translation wherein something of the rhythmical variety and beauty of the original is not retained. That very much of the rhythmical character may be retained in English, was long ago shown by Mr. Carlyle,  in the passages which he translated, both literally and rhythmically, from the _Helena_ (Part Second). In fact, we have so many instances of the possibility of reciprocally transferring the finest qualities of English and German poetry, that there is no sufficient excuse for an unmetrical translation of _Faust_. I refer especially to such subtile and melodious lyrics as "The Castle by the Sea," of Uhland, and the "Silent Land" of Salis, translated by Mr. Longfellow; Goethe's "Minstrel" and "Coptic Song," by Dr. Hedge; Heine's "Two Grenadiers," by Dr. Furness and many of Heine's songs by Mr Leland; and also to the German translations of English lyrics, by Freiligrath and Strodtmann. 

> Life of Goethe (Book VI.).

> Mr. Lewes gives the following advice: "The English reader would perhaps best succeed who should first read Dr. Anster's brilliant paraphrase, and then carefully go through Hayward's prose translation." This is singularly at variance with the view he has just expressed. Dr. Anster's version is an almost incredible dilution of the original, written in _other_ metres; while Hayward's entirely omits the element of poetry.

> Foreign Review, 1828.

> When Freiligrath can thus give us Walter Scott:—


"Kommt, wie der Wind kommt,
Wenn Wälder erzittern
Kommt, wie die Brandung
Wenn Flotten zersplittern!
Schnell heran, schnell herab,
Schneller kommt Al'e!—
Häuptling und Bub' und Knapp,
Herr und Vasalle!"

我想在 markdown 的所有此类诗意结构的上方和下方放置三个```,以便 HTML 的输出在 <pre> 中包含诗歌。标签。像这样:

```
"Kommt, wie der Wind kommt,
Wenn Wälder erzittern
Kommt, wie die Brandung
Wenn Flotten zersplittern!
Schnell heran, schnell herab,
Schneller kommt Al'e!—
Häuptling und Bub' und Knapp,
Herr und Vasalle!"
```

想知道是否有正则表达式可以可靠地匹配文本文件中的此类模式?


另一种情况:

有时我会使用以下格式来识别诗歌散文:

abra ca dabra op
lorem ipsum holy this
line doesn't have
an indent but it's in
continuity of the
structure that sits together.

最佳答案

在大多数情况下,我同意有关此问题最好由 AI 解决的评论。话虽这么说,你的脑子里有一个 AI(减去 A),如果你可以查看格式良好的文档并定义构成“诗歌”的模式,你可以编写一个正则表达式来选择它。


^((?:.+\n)+.+)$ 此正则表达式选择内容行之间只有一个换行符的行。只要您的 Markdown /文本文件在普通段落之间放置至少两个换行符,并且诗歌的长度超过一行(如您的示例),它就会捕获它们。

Try it here!


^((?:.+\n .+\n)+)$ 如果您更喜欢“诗歌”的更严格定义,此正则表达式会查找一行内容,后面跟着一行缩进的内容(也像你的例子)。正则表达式不会匹配不以缩进行结尾的“格式错误”的诗歌。

Try it here!

关于javascript - 有没有办法找出文本/ Markdown 文件中文本的诗歌风格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57121573/

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