こんにちは、私は現在、クエリソルバーコードに取り組んでおり、ユーザーが入力したクエリの単語を検索するために正規表現を使用しています。正規表現を使用してクエリ内の単語を検索するにはどうすればよいですか?
しかし、私が使用しているコードが私の元のアイデアのコンセプトを穏やかにしていないというジレンマを思いつきました。コードは次のとおりです。
def query():
print ('Enter a query\n\nThe query must not have more than 30 characters.\n')
while True:
query = raw_input ('Query: ')
if 30> len(query):
break
print ('The query must have less than 30 chracters.\n')
def querysolver():
query_words = dict.fromkeys(['screen_repair','Phone_virus','Water_damage', False])
if re.search (r'[wet]', query):
query_words['Water_damage'] = True
if re.search (r'[water]', query):
query_words['Water_damage'] = True
if re.search (r'[wet]', query):
query_words['Water_damage'] = True
if re.search (r'[screen]', query):
query_words['screen_repair'] = True
if re.search (r'[smashed]', query):
query_words['screen_repair'] = True
if re.search (r'[hacked]', query):
query_words['Phone_virus'] = True
if re.search (r'[virus]', query):
query_words['Phone_virus'] = True
どのようにこれらの値を使用してユーザークエリの解決策を見つけることができますか?
あなたがそれそう 'break'後' print'を持っています – depperm
@depperm imこれは私が質問していた質問ではありません – LordZiggy
"ユーザーのクエリにソリューションを見つける"ソリューションを見つける?あなたの質問は全く明確ではありません。ところで、あなたの正規表現はあなたが思うことをしません。 '[wet]'は、単語ではなく文字列中の 'w'、' e'または 't'文字を探します。あなたは正規表現を必要としなくても、単純にクエリーで ''濡れた ''をします。 – DeepSpace