TCM Templates¶
Traditional Chinese Medicine text analysis.
Overview¶
TCM (Traditional Chinese Medicine) templates are designed for extracting knowledge from TCM texts, including herbal medicine, formulas, and syndrome differentiation.
Templates¶
herb_property¶
Type: model
Purpose: Extract herb properties and characteristics
Best for: - Materia medica texts - Herb databases - Prescription references
Fields:
| Field | Type | Description |
|---|---|---|
name |
str | Herb name (Chinese/pinyin) |
properties |
list[str] | Nature (hot, warm, cool, cold, neutral) |
flavors |
list[str] | Five flavors (sour, bitter, sweet, pungent, salty) |
meridians |
list[str] | Entered meridians |
functions |
list[str] | Main functions |
indications |
list[str] | Clinical indications |
formula_composition¶
Type: graph
Purpose: Extract herbal formula compositions
Best for: - Formula collections (方剂学) - Prescription texts - Classic texts (伤寒论, 金匮要略)
Entities:
- Herbs (药物)
- Formulas (方剂)
- Conditions (病症)
Relations:
contains— Formula contains herbtreats— Formula treats conditionmodifies— Modified formula relationship
herb_relation¶
Type: graph
Purpose: Extract herb-to-herb relationships
Best for: - Herb pairing references (药对) - Compatibility texts (十八反, 十九畏) - Combination guides
Relations:
pairs_with— Common pairingsynergizes_with— Synergistic effectincompatible_with— Contraindicated combination
meridian_graph¶
Type: graph
Purpose: Extract meridian pathway information
Best for: - Acupuncture texts - Meridian studies - Point location references
Entities:
- Meridians (经脉)
- Acupoints (穴位)
- Organs (脏腑)
Relations:
connects_to— Meridian connectionsbelongs_to— Point to meridianinfluences— Meridian-organ relationship
syndrome_reasoning¶
Type: graph
Purpose: Extract syndrome differentiation logic
Best for: - Diagnostics texts (中医诊断学) - Case studies - Syndrome differentiation guides
Entities:
- Symptoms (症状)
- Syndromes (证型)
- Patterns (病机)
Relations:
indicates— Symptom indicates syndromedifferentiates_from— Differential diagnosisleads_to— Pattern progression
Use Cases¶
Herb Database Building¶
from hyperextract import Template
ka = Template.create("tcm/herb_property", "zh")
herb_db = {}
for herb_file in herb_files:
herb = ka.parse(herb_file.read_text())
herb_db[herb.data.name] = herb.data
# Query by function
for name, data in herb_db.items():
if "补气" in data.functions:
print(f"{name}: Qi tonic herb")
Formula Analysis¶
ka = Template.create("tcm/formula_composition", "zh")
formula = ka.parse(si_jun_zi_tang_text)
# List herbs
print("Formula composition:")
for relation in formula.data.relations:
if relation.type == "contains":
print(f" - {relation.target}")
Syndrome Study¶
ka = Template.create("tcm/syndrome_reasoning", "zh")
syndromes = ka.parse(diagnostics_text)
# Find what symptom indicates what syndrome
symptom = "舌淡苔白"
related = [
r for r in syndromes.data.relations
if r.source == symptom and r.type == "indicates"
]
for r in related:
print(f"{symptom} indicates {r.target}")
Tips¶
- Use Chinese language (
-l zh) — Better extraction from TCM texts - herb_property for materia medica — Build herb databases
- formula_composition for方剂学 — Study classic formulas
- meridian_graph for acupuncture — Map meridian pathways