1

たとえば、次のようなテキストがあります。80% of $300,000 Each Human Resource/IT Department.

$300,000単語と一緒に抽出する必要がありますEach Human Resource/IT Department

トークン化後に単語にタグを付けるために pos タグ付けを使用しました。300,000 を抽出できましたが、$ 記号を一緒に抽出できませんでした。

私がこれまでに持っているもの:

text = '80% of $300,000 Each Human Resource/IT Department'
train_text = text
sample_text = text
custom_sent_tokenizer = PunktSentenseTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)

for i in tokenized:
    words = nltk.word_tokenize(i)
    tagged = nltk.pos_tag(words)

chunkGram = r"""chunk: {<DT>+<NN.*>+<NN.*>?|<NNP>?|<CD>+<NN>?|<NNP>?}"""


chunkParser = nltk.RegexpParser(chunkGram)
chunked = chunkParser.parse(tagged)

リストに変換されたときのチャンク出力 -['80 %', '300,000', 'Each Human Resource/IT Department']

私が欲しかったもの:['80 %', '**$**300,000', 'Each Human Resource/IT Department']

私は試した

chunkGram = r"""chunk: {**</$CD>|**<DT>+<NN.*>+<NN.*>?|<NNP>?|<CD>+<NN>?|?}"""

それでもうまくいきません。だから、私が必要なのはCDと一緒に$だけです

4

1 に答える 1

1

<\$> を追加する必要がありますか? あなたの文法で。

chunkGram = r"""chunk: {<DT>+<NN.*>+<NN.*>?|<\$>?<CD>+<NN>?|<NNP>?}"""

コード :

import nltk
from nltk.tokenize import PunktSentenceTokenizer

text = '80% of $300,000 Each Human Resource/IT Department'
train_text = text
sample_text = text
custom_sent_tokenizer = PunktSentenceTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)

for i in tokenized:
    words = nltk.word_tokenize(i)
    tagged = nltk.pos_tag(words)

chunkGram = r"""chunk: {<DT>+<NN.*>+<NN.*>?|<\$>?<CD>+<NN>?|<NNP>?}"""

chunkParser = nltk.RegexpParser(chunkGram)
chunked = chunkParser.parse(tagged)

print(chunked)

出力:

(S
  (chunk 80/CD %/NN)
  of/IN
  (chunk $/$ 300,000/CD)
  (chunk Each/DT Human/NNP Resource/IT/NNP Department/NNP))
于 2016-07-10T13:26:16.070 に答える