Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,20 +132,55 @@ PHYSICS_KEYWORDS = [
|
|
| 132 |
# テキストが物理学に関連しているかチェック
|
| 133 |
def is_physics_related(text):
|
| 134 |
lower_text = text.lower()
|
| 135 |
-
# キーワードの一致
|
| 136 |
-
keyword_match = any(keyword.lower() in lower_text for keyword in PHYSICS_KEYWORDS)
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
r"(衝突|反発)[を|の](計算|予測|予想)",
|
| 144 |
-
r"(物理|力学)[的|的な|法則|モデル]"
|
| 145 |
]
|
| 146 |
-
phrase_match = any(re.search(pattern, lower_text) for pattern in phrase_patterns)
|
| 147 |
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
# 過去のメッセージを表示
|
| 151 |
for message in st.session_state.messages:
|
|
|
|
| 132 |
# テキストが物理学に関連しているかチェック
|
| 133 |
def is_physics_related(text):
|
| 134 |
lower_text = text.lower()
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
# 明確な物理関連キーワード(より具体的で誤検出が少ないもの)
|
| 137 |
+
explicit_physics_keywords = [
|
| 138 |
+
"物理法則", "物理シミュレーション", "ニュートン力学", "電磁気学", "熱力学", "量子力学", "相対性理論",
|
| 139 |
+
"physics simulation", "newton's laws", "electromagnetism", "thermodynamics",
|
| 140 |
+
"quantum mechanics", "relativity theory"
|
|
|
|
|
|
|
| 141 |
]
|
|
|
|
| 142 |
|
| 143 |
+
# 単語境界を考慮すべきキーワード(一般的な単語だが、単独で使われた場合は物理関連の可能性が高い)
|
| 144 |
+
word_boundary_keywords = [
|
| 145 |
+
r"\b力学\b", r"\b重力\b", r"\b摩擦\b", r"\b衝突\b", r"\b運動方程式\b", r"\b加速度\b", r"\b速度\b", r"\b質量\b",
|
| 146 |
+
r"\bgravity\b", r"\bfriction\b", r"\bcollision\b", r"\bvelocity\b", r"\bacceleration\b", r"\bmass\b"
|
| 147 |
+
]
|
| 148 |
+
|
| 149 |
+
# 明確な物理用語が含まれているか
|
| 150 |
+
explicit_match = any(keyword.lower() in lower_text for keyword in explicit_physics_keywords)
|
| 151 |
+
|
| 152 |
+
# 境界を考慮すべき単語が含まれているか(単語として独立して存在する場合のみ)
|
| 153 |
+
boundary_match = any(re.search(pattern, lower_text) for pattern in word_boundary_keywords)
|
| 154 |
+
|
| 155 |
+
# 物理シミュレーション関連の特定のフレーズパターン
|
| 156 |
+
physics_phrases = [
|
| 157 |
+
r"物理.*シミュレ(ーション|ート)",
|
| 158 |
+
r"physics.*simulation",
|
| 159 |
+
r"ボールの.*衝突",
|
| 160 |
+
r"ball.*collision",
|
| 161 |
+
r"重力.*計算",
|
| 162 |
+
r"gravity.*calculation",
|
| 163 |
+
r"運動方程式",
|
| 164 |
+
r"equation.*motion",
|
| 165 |
+
r"力学.*モデル",
|
| 166 |
+
r"mechanics.*model"
|
| 167 |
+
]
|
| 168 |
+
phrase_match = any(re.search(pattern, lower_text) for pattern in physics_phrases)
|
| 169 |
+
|
| 170 |
+
# 誤検出しやすいコンテキストのチェック(これらが含まれる場合は物理関連ではない可能性が高い)
|
| 171 |
+
non_physics_contexts = [
|
| 172 |
+
"アプリの動作", "システムの動作", "プログラムの動作", "ソフトウェアの動作",
|
| 173 |
+
"app behavior", "system behavior", "program behavior", "software behavior",
|
| 174 |
+
"UIの動き", "インターフェースの動き", "ボタンの動き",
|
| 175 |
+
"UI movement", "interface movement", "button movement"
|
| 176 |
+
]
|
| 177 |
+
negative_context = any(context.lower() in lower_text for context in non_physics_contexts)
|
| 178 |
+
|
| 179 |
+
# 物理関連であると判断するロジック:
|
| 180 |
+
# 1. 明確な物理用語が含まれている、または
|
| 181 |
+
# 2. 境界を考慮すべき単語が含まれていて、かつ誤検出コンテキストが含まれていない、または
|
| 182 |
+
# 3. 物理シミュレーション関連の特定のフレーズが含まれている
|
| 183 |
+
return explicit_match or (boundary_match and not negative_context) or phrase_match
|
| 184 |
|
| 185 |
# 過去のメッセージを表示
|
| 186 |
for message in st.session_state.messages:
|