そのため、NumPy と Pandas と NLTK を使用して、CHILDES データベースのプロビデンス コーパスから発話を取得する Python スクリプトに取り組んでいます。
参考までに、私のスクリプトのアイデアは、コーパス内の各子供のデータフレームに、名前、探している言語的特徴 (否定タイプ) を含む発話、子供がそれを言ったときの年齢、子供が言ったときの MLU を入力することです。そう言った。
偉大な。
これで、ユーザーはデータフレームがこの情報で満たされ、各発話が特定のカテゴリのものとしてタグ付けされた後に入ることができるようになり、コンソールは、どちらかの側にコンテキストの行でタグ付けされた発話を出力します (子供が「いいえ」と言ったのを見るだけで、母親がその直前に何を言ったか、または誰かがその後に何を言ったかを見ずに、それが何を意味するのかを伝えるのは難しい.
だから私のトリックは、文脈の行を取得することです。これをすべて実現するために、プログラム内の他のメソッドを使用してセットアップしましたが、最初にデータフレームにデータを入力するメソッドの 1 つのセグメントを見ていただきたいと思います。 line_context:" は、約 91 の誤検知を提供しています!
各ファイルの行ごとに一時的なコピーを作成しているため、最終的に否定を持つ各発話に対して、子のデータフレーム内のその発話のインデックスが HashMap (または dict in Python) を 3 つの文字列のリスト (CHILDESCorpusReader が文を与える方法なので、文字列のリストです)、発話、その前の発話、およびその後の発話...
そのため、「if line == line_context」というバグのある行があり、文字列のリストのリスト(ファイルの発話の行ごとのコピー、または「line_context」)を反復処理しているため、「line」と一致していることを確認します、または反復されている子供の発話の行であるため、後でインデックスを一致させることができます。
問題は、同じ一連の文字であるこれらの「文」の多くがあることです (['no'] 自体が多く表示されます!)。したがって、私のプログラムはそれを同じものとして認識し、否定があることを確認します。 、それをデータフレームに保存しますが、ファイルの発話のコピーで ['no'] のインスタンスが見つかるたびに保存します。これは、そのファイル内の子供のスピーチのみの行の 1 つと同じです。だから私は同じものの約91の余分なインスタンスを取得しています!
ふぅ!とにかく、「if line == line_context」のようなものを取得して、ファイル内の['no']の単一のインスタンスを選択して、ファイル内の同じポイントにいることを知る方法はありますか?両側???私は NLTK CHILDESCorpusReader を使用していますが、これはこの種のもののためのリソースを持っていないようです (そうでなければ、コンテキストの行を取得するためにこの途方もなく回りくどい方法を使用する必要はありません!)
おそらく、各ファイルに対して作成している utterance_list を反復処理するときに、発話が反復処理している子供の発話と一致した後、utterance_list 内のその項目を変更および/または削除できる方法があるので、それが私に偽陽性を与えるのを防ぐために c. あと91回!?
ありがとう。
これがコードです (各行が何をすべきかを正確に理解するのに役立つことを願って、いくつかのコメントを追加しました):
for file in value_corpus.fileids(): #iterates through the .xml files in the corpus_map
for line_total in value_corpus.sents(fileids=file, speaker='ALL'): #creates a copy of the utterances by all speakers
utterance_list.append(line_total) #adds each line from the file to the list
for line_context in utterance_list: #iterates through the newly created list
for line in value_corpus.sents(fileids=file, speaker='CHI'): #checks through the original file's list of children's utterances
if line == line_context: #tries to make sure that for each child's utterance, I'm at the point in the embedded for loop where the utterance in my utterance_list and the utterance in the file of child's sentences is the same exact sentence BUGGY(many lines are the same --> false positives)
for type in syntax_types: #iterates through the negation syntactic types
if type in line: #if the line contains a negation
value_df.iat[i,5] = type #populates the "Syntactic Type" column
value_df.iat[i,3] = line #populates the "Utterance" column
MLU = str(value_corpus.MLU(fileids=file, speaker='CHI'))
MLU = "".join(MLU)
value_df.iat[i,2] = MLU #populates the "MLU" column
value_df.iat[i,1] = value_corpus.age(fileids=file, speaker='CHI',month=True) #populates the "Ages" column
utterance_index = utterance_list.index(line_context)
try:
before_line = utterance_list[utterance_index - 1]
except IndexError: #if no line before, doesn't look for context
before_line = utterance_list[utterance_index]
try:
after_line = utterance_list[utterance_index + 1]
except IndexError: #if no line after, doesn't look for context
after_line = utterance_list[utterance_index]
value_dict[i] = [before_line, line, after_line]
i = i + 1 #iterates to next row in "Utterance" column of df