3
いくつかの記事から負傷した人々に関する情報を抽出しようとしています。問題は、ジャーナリス言語で情報を伝えるさまざまな方法があることです。数字または単語で書くことができるからです。例えば正規表現を単語として書かれた数字のリストと組み合わせた
:1-10から行く回数番号のほとんどは言葉ではなく数字で書かれているように私は気づいた
`Security forces had *wounded two* gunmen inside the museum but that two or three accomplices might still be at large.`
`The suicide bomber has wounded *four men* last night.`
`*Dozens* were wounded in a terrorist attack.`
。そして、私はどのような複雑なコードでも起こらずにそれらを抽出する方法を疑問に思っていました。
リストを使用しますか?どのようにそれが含まれるだろうか?
これは私が数字で負傷した人の数を抽出するため、これまでに使用されるパターンです:
two
four
Dozens
\w+\s(?=were)
:?=
text_open = open("News")
text_read = text_open.read()
pattern= ("wounded (\d+)|(\d+) were wounded|(\d+) injured|(\d+) people were wounded|wounding (\d+)|wounding at least (\d+)")
result = re.findall(pattern,text_read)
print(result)