現在、ステートメントを反映できる基本的な「AI」を作成しようとしています。たとえば、ユーザーが「私の猫は茶色です」と入力したとします。AI は「あなたの猫は茶色ですか?」と返します。
翻訳に使用する変数データのテーブルを作成しました。
reflections = \
[["I", "you"],
["i", "you"],
["We", "you"],
["we", "you"],
["We're", "you're"],
["we're", "you're"],
["I'm", "you're"],
["i'm", "you're"],
["im", "you're"],
["this", "that"],
["This", "that"],
["am", "are"],
["Am", "are"],
["My", "your"],
["my", "your"],
["you", "I"], # Grammar: Sometimes "me" is better
["You", "I"],
["u", "me"],
["I'd", "you'd"],
["I'll", "you'll"],
["We'd", "you'd"],
["we'd", "you'd"],
["We'll", "you'll"],
["we'll", "you'll"],
["You're", "I'm"],
["you're", "I'm"],
["ur", "I'm"],
["c", "see"],
["I've", "you've"],
["We've", "you've"],
["we've", "you've"],
["Our", "your"],
["our", "your"],
["was", "were"],
["Was", "were"],
["were", "was"],
["Were", "was"],
["me", "you"],
["your", "my"],
["Your", "my"]]
ただし、データの実装に問題があります。
文字列反射の私の現在の定義は次のとおりです。
from string import maketrans
intab = ".!"
outtab = "??"
translate_message = maketrans(intab, outtab) #used to replace punctuation
def reflect_statement(message):
if ' ' not in message:
if len(message) == 0:
return elicitations[0]
if len(message) == 1:
return elicitations[1]
if len(message) == 2:
return elicitations[2]
if len(message) == 3:
return elicitations[3]
if len(message) == 4:
return elicitations[4]
if len(message) == 5:
return elicitations[5]
if len(message) == 6:
return elicitations[6]
if len(message) == 7:
return elicitations[7]
if len(message) == 8:
return elicitations[8]
if len(message) == 9:
return elicitations[9]
if len(message) == 10:
return elicitations[10]
if len(message) > 10:
return elicitations[11]
if ' ' in message:
message = message.translate(translate_message)
return message
これは、私が完了したプログラムの別の部分です。
誰かが私に提供できる助けを本当に感謝します。
乾杯!