40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
|
|
import json
|
|
|
|
def recommend(disease_query, cleaned_idx_path, exercise_idx_path):
|
|
with open(cleaned_idx_path, 'r', encoding='utf-8') as f:
|
|
idx = json.load(f)
|
|
with open(exercise_index_path, 'r', encoding='utf-8') as f:
|
|
ex_data = json.load(f)
|
|
|
|
results = {"food_remedy": [], "exercise_remedy": []}
|
|
|
|
# 1. Find Food Remedy
|
|
# Search in '药膳_flatten_mapping'
|
|
for mapping_key, ingredients in idx.get('药膳_mapping_cleaned', {}).items():
|
|
# Check if disease name is in the key
|
|
if disease_query in mapping_key:
|
|
results["food_remedy"].append(f"Use {', '.join(ingredients)} patterns found in {mapping_key}")
|
|
|
|
# 2. Find Exercise Remedy
|
|
for tech in ex_data['techniques']:
|
|
# Check benefits or parts
|
|
keywords = tech['benefits'] + tech['parts_involved']
|
|
for k in keywords:
|
|
if k in disease_query or disease_query in k:
|
|
results["exercise_remedy"].append(f"Practice {tech['name']} (Targeting: {k})")
|
|
|
|
return results
|
|
|
|
if __name__ == "__main__':
|
|
import sys
|
|
query = sys.argv[1] if len(sys.argv) > 1 else "肩"
|
|
c_path = "/home/songyi/Documents/ai_agent_scraper_study/data/大医网/索引_药膳疾病关联_cleaned.json"
|
|
e_path = "/home/songyi/Documents/ai_agent_scraper_study/data/大医网/索引_导引运动处_technique.json"
|
|
|
|
import sys
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
print(f"--- Recommendation for: {query} ---")
|
|
print(json.dumps(recommend(query, c_path, e_path), ensure_ascii=int(0), indent=2))
|
|
|