1

私たち英国の大学院生の多くは、ヴァージニア・ウルフの小説『The Waves』で会話を学んでおり、私はその小説を TEI でマークアップしようとしてきました。これを行うには、ダイアログをキャプチャする正規表現を作成すると便利です。ありがたいことに、The Waves は非常に規則的で、ほとんどすべてのダイアログは次の形式になっています。

「もうみんな行ってしまった」とルイスは言った。'私は一人だ。彼らは朝食のために家に入った」

しかし、いくつかの段落を続けることができます。特定のスピーカーのすべての段落に一致する正規表現を作成しようとしています。

これはChris Foster のブログ投稿で簡単に説明されており、彼は次のような提案をして/'([\^,]+,)' said Louis, '(*)'/いますが、これは単一の段落にしか一致しないと思います。これは私がそれを通して考えている方法です:

  • 段落の最初の行に「said Louis」(または他のキャラクターの名前) というテキストを含むすべての段落について、別のキャラクターのスピーチ、つまり「said Rhodha」に到達するまで、すべての行を一致させます。

私はおそらく厄介なpythonのトンでこれを行うことができますが、これが正規表現で可能かどうか知りたいです.

4

1 に答える 1

1

あなたのリンクから、テキストは次の規則に従っているようです。

  1. 各「行」は厳密な意味での行です。つまり、 で区切られてい\nます。
  2. 段落は、2 つ以上の連続する改行 (_i.e.) によって区切られます。\n\n+.
  3. 'スピーチを区別するために、無方向の一重引用符のみが使用されます。

ここに簡単な試みがあります (一番下までスクロールして、マッチ グループを表示します) — 間違っていると思います — しかし、正しい方向に導くのに十分な情報がここにはあります。$1慣用的に、$2、および$3、「言った」セパレータ間の句読点を含む各文字のスピーチを取得する方法に注意してくださいただし、言語の特定の癖がこの正規表現をどのように無効にするかに注意してください。たとえば、段落の終わりで引用符を閉じずに、スピーチが次の段落に続く場合に新しい引用符を開くという事実は、全体のバランスを崩します-戦略を引用し、アポストロフィも同様です。

\n\n.*?'([^^]+?[?]?),?' said (?:[A-Z][a-z]+)(?:([.])  |, )'([^^]+?)'(?=[^']*(?:'[^']')*[^']*\n\n.*'(?:[^^]+?[?]?),?' said (?:[A-Z][a-z]+)(?:[.]  |, ))
|   |  | <----><--> <>|<-------------------><------------>| <----> |<--------------------------------------------------------------------------------->
|   |  | |     |    | ||                    |             | |      ||
|   |  | |     |    | ||                    |             | |      |assert that this end-quote is followed by a string of non-quote characters, then
|   |  | |     |    | ||                    |             | |      |zero or more strings of quoted non-quote characters, then another string of non-
|   |  | |     |    | ||                    |             | |      |quote characters, a new paragraph, and the next "said Bernard"; otherwise fail.
|   |  | |     |    | ||                    |             | |      |
|   |  | |     |    | ||                    |             | |      match an (end-)quote
|   |  | |     |    | ||                    |             | |
|   |  | |     |    | ||                    |             | match any character as needed (but no more than needed)
|   |  | |     |    | ||                    |             |
|   |  | |     |    | ||                    |             match a (start-)quote
|   |  | |     |    | ||                    |
|   |  | |     |    | ||                    match either a period followed by two spaces, or a comma followed by one space
|   |  | |     |    | ||
|   |  | |     |    | |match the "said Bernard"
|   |  | |     |    | |
|   |  | |     |    | match an (end-)quote
|   |  | |     |    |
|   |  | |     |    match a comma, optionally
|   |  | |     |
|   |  | |     match a question mark, optionally
|   |  | |
|   |  | match any character as needed (but no more than needed)
|   |  |
|   |  match a (start-)quote
|   |
|   match as many non-newline characters as needed (but no more than needed)
|
new paragraph

Rubular マッチ (抜粋):

Match 3

1.  But when we sit together, close
2.   
3.  we melt into each
    other with phrases. We are edged with mist. We make an
    unsubstantial territory.

Match 4

1.  I see the beetle
2.  .
3.  It is black, I see; it is green,
    I see; I am tied down with single words. But you wander off; you
    slip away; you rise up higher, with words and words in phrases.
于 2013-03-27T19:26:01.910 に答える