حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال
تضمين المصطلحات والمعارف الخاصة بالمجال في مطالبات النظام
حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال درس مجاني في AI Prompt Engineering على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Prompt Engineering، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Prompt Engineering 4 دروس في المجموع.
مشكلة إزالة الالتباس
تزخر لغة المجالات بالغموض. تعني «Yield» عائد السندات في المجال المالي، بينما تعني محصول الزراعة. وتعني «Resolution» دقة الشاشة في واجهات المستخدم، وحل المشكلة في الدعم. ومن دون سياق المجال، تختار النماذج المعنى العام الأكثر شيوعًا، وهو معنى خاطئ في المجالات المتخصصة.
نمط إدراج المسرد
أدرج مسرد المجال مباشرةً في موجّه النظام. فهذا يتجاوز مفردات النموذج الافتراضية ويضمن تفسير المصطلحات الخاصة بالمجال تفسيرًا صحيحًا طوال الجلسة.
FINANCE_GLOSSARY = '''
DOMAIN GLOSSARY (these definitions override general language meaning):
- yield: bond yield (annual return as percentage of bond price), NOT crop or harvest
- duration: interest rate sensitivity measure (modified duration), NOT time length
- spread: yield spread between two bonds, NOT physical spreading
- convexity: second-order price sensitivity to interest rate changes, NOT geometry
- tenor: remaining time to maturity of a financial instrument, NOT musical pitch
- floor: minimum interest rate in a rate agreement, NOT building floor
- cap: maximum interest rate, NOT a hat or market capitalization
- swap: exchange of cash flows between counterparties, NOT physical exchange
- basis: difference between spot and futures price, NOT foundation
'''
FINANCE_SYSTEM_PROMPT = (
'You are a fixed income analyst.\n\n'
+ FINANCE_GLOSSARY +
'\nAlways use these domain definitions when answering questions.'
)
import anthropic
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
response = client.messages.create(
model='claude-opus-4-5', max_tokens=500,
system=FINANCE_SYSTEM_PROMPT,
messages=[{'role': 'user', 'content': 'What is the yield of a 10-year bond?'}]
)
print(response.content[0].text)إنشاء ملف مسرد المجال
خزّن المسارد في ملفات YAML منظّمة حتى يمكن إدارة إصداراتها ومشاركتها بين الموجّهات وتحديثها بواسطة خبراء المجال من دون تعديل شيفرة الموجّه.
# glossaries/fixed_income.yaml
glossary:
yield:
domain_meaning: Annual return on a bond as a percentage of its current market price
general_meaning: Crop or harvest output
use_domain: true
examples:
- 'The 10-year Treasury yield rose to 4.5%'
- 'Current yield = annual coupon / market price'
duration:
domain_meaning: |
Measure of a bond's price sensitivity to interest rate changes.
Modified duration = -dP/P / dr
general_meaning: Length of time
use_domain: true
basis:
domain_meaning: Difference between spot price and futures price of the same instrument
general_meaning: Foundation or base
use_domain: true
# glossaries/load.py
import yaml
def load_glossary(domain):
with open(f'glossaries/{domain}.yaml') as f:
data = yaml.safe_load(f)
lines = ['DOMAIN GLOSSARY:']
for term, info in data['glossary'].items():
lines.append(f'- {term}: {info["domain_meaning"].strip()}')
return '\n'.join(lines)إدراج الأنطولوجيا للمجالات المعقدة
تتجاوز الأنطولوجيا المسرد، إذ تعرّف العلاقات بين المفاهيم، مثل التراتبيات والقيود والقواعد. ويساعد إدراج الأنطولوجيا النموذج على فهم المفاهيم التي تنتمي إلى كل فئة وكيفية ترابطها.
MEDICAL_ONTOLOGY_SNIPPET = '''
CLINICAL ONTOLOGY (use these relationships in all analysis):
Diagnosis Hierarchy:
- Condition > Category > Specific Diagnosis
- "Hypertension" is a specific diagnosis under "Cardiovascular Conditions"
- "Type 2 Diabetes" is under "Endocrine / Metabolic Conditions"
Medication Classes:
- ACE inhibitors (e.g., lisinopril) -> used for: hypertension, heart failure, CKD
- Beta-blockers (e.g., metoprolol) -> used for: hypertension, angina, heart failure
- Statins (e.g., atorvastatin) -> used for: hyperlipidemia, cardiovascular risk
Measurement Rules:
- "BP" means Blood Pressure, format: systolic/diastolic (e.g., 130/85 mmHg)
- "A1c" means glycated hemoglobin; > 6.5% is diagnostic for Type 2 Diabetes
- "eGFR" means estimated Glomerular Filtration Rate; < 60 mL/min/1.73m2 = CKD
Always use ICD-10 categories when classifying diagnoses.
'''
print(MEDICAL_ONTOLOGY_SNIPPET[:300])إنشاء المسرد ديناميكيًا
بالنسبة إلى قواعد المعرفة الكبيرة، أنشئ مسردًا مركزًا ديناميكيًا، وذلك باستخراج المصطلحات الأكثر صلة بالمهمة الحالية فقط من مسرد رئيسي، مع إبقاء نافذة السياق مقتصدة.
import json
# master_glossary.json — full domain glossary
MASTER_GLOSSARY = {
'yield': 'Bond yield: annual return as percentage of current market price',
'duration': 'Modified duration: bond price sensitivity to rate changes',
'convexity': 'Second-order rate sensitivity measure',
'swap': 'Exchange of fixed and floating cash flows',
'option': 'Contract giving right (not obligation) to buy/sell an asset',
'beta': 'Stock volatility relative to market index',
'alpha': 'Excess return over benchmark after adjusting for risk',
# ... hundreds more
}
def focused_glossary(user_query, master_glossary, max_terms=10):
'''Select glossary terms most relevant to the user query.'''
query_lower = user_query.lower()
relevant = {}
for term, definition in master_glossary.items():
if term.lower() in query_lower or any(
word in query_lower for word in definition.lower().split()[:5]
):
relevant[term] = definition
if len(relevant) >= max_terms:
break
lines = ['RELEVANT DOMAIN TERMS:']
for t, d in relevant.items():
lines.append(f'- {t}: {d}')
return '\n'.join(lines)
query = 'What is the duration and convexity of this bond portfolio?'
print(focused_glossary(query, MASTER_GLOSSARY))إزالة الالتباس متعدد المجالات
تمتد بعض الاستعلامات عبر مجالات متعددة. أدرج سياق جميع المجالات ذات الصلة، ووجّه النموذج إلى إزالة الالتباس استنادًا إلى سياق المحادثة.
MULTI_DOMAIN_SYSTEM = '''
This system serves both agricultural and financial users.
The domain is determined by context cues in the user message.
Domain disambiguation rules:
- If the user mentions "crops", "harvest", "acres", "soil", "planting":
Use AGRICULTURAL definitions: yield = crop output, spread = physical spreading
- If the user mentions "bonds", "portfolio", "maturity", "coupon", "treasuries":
Use FINANCIAL definitions: yield = bond yield, spread = yield spread
- If the domain is ambiguous:
Ask the user to clarify: "Are you asking about agricultural or financial yields?"
AGRICULTURAL GLOSSARY:
- yield: crop output per unit area (e.g., bushels per acre)
- basis: difference between local cash price and futures price for a commodity
FINANCIAL GLOSSARY:
- yield: annual bond return as percentage of current price
- basis: yield spread between two financial instruments
'''
print('Multi-domain system prompt loaded.')
print('The model will ask for clarification when domain is ambiguous.')مخرجات مقيّدة بالأنطولوجيا
يمكن لإدراج الأنطولوجيا تقييد مخرجات النموذج بحيث تستخدم الفئات المحددة مسبقًا فقط، مما يمنع التصنيف الحر الذي يعطّل المعالجة اللاحقة.
SUPPORT_ONTOLOGY_SYSTEM = '''
You are a support ticket classifier for a B2B SaaS company.
TICKET CATEGORY ONTOLOGY (use ONLY these exact category names):
Level 1 Categories:
- Billing > Sub-categories: Invoice Error, Subscription Change, Refund Request, Payment Failure
- Technical > Sub-categories: Bug Report, Performance Issue, Integration Error, Feature Not Working
- Account > Sub-categories: Access Request, User Management, Security Concern, Password Reset
- Feature Request > Sub-categories: New Feature, Enhancement, UI/UX Improvement
CLASSIFICATION RULES:
1. Always return exactly one Level 1 category and one Sub-category.
2. If ticket spans multiple categories, choose the PRIMARY issue.
3. If uncertain, use the category that would route to the most qualified team.
4. Return format: {"category": "Technical", "subcategory": "Bug Report", "confidence": "HIGH"}
Confidence: HIGH (clear), MEDIUM (likely), LOW (ambiguous)
'''
def classify_ticket(ticket_text):
import json
response = client.messages.create(
model='claude-opus-4-5', max_tokens=100,
system=SUPPORT_ONTOLOGY_SYSTEM,
messages=[{'role': 'user', 'content': f'Classify: {ticket_text}'}]
)
return json.loads(response.content[0].text)إدراج الأنطولوجيا القانونية
تعرّف أنطولوجيات المجال القانوني تراتبيات بنود العقود، والعلاقات بين الأطراف، وأنواع الالتزامات. ويضمن إدراجها تصنيفًا متسقًا في جميع مهام تحليل العقود.
LEGAL_ONTOLOGY = '''
CONTRACT CLAUSE ONTOLOGY:
Obligation Types:
- SHALL: mandatory obligation (enforceable duty)
- MAY: permissive right (optional action)
- SHALL NOT: mandatory prohibition
- WILL: future intention (weaker than SHALL)
Clause Risk Hierarchy:
- CRITICAL: financial exposure > $1M or termination rights
- HIGH: material business impact, IP rights, indemnification
- MEDIUM: operational restrictions, notice requirements
- LOW: administrative provisions, definitions
Party References (standardize to these canonical forms):
- "the Company", "we", "us" -> VENDOR
- "Customer", "Client", "you" -> CUSTOMER
- "third party", "subcontractor" -> THIRD_PARTY
Always use these canonical party names in your analysis.
Do not use the actual company names — replace with canonical form.
'''
print('Legal ontology loaded. Party names will be canonicalized in all analysis.')مدقق اتساق المصطلحات
بعد استلام مخرجات النموذج، تحقّق من استخدام مصطلحات المجال باتساق ومن عدم عودتها إلى معاني اللغة العامة. إذ يكشف فحص المعالجة اللاحقة انحراف المصطلحات.
PROHIBITED_GENERAL_MEANINGS = {
# In fixed income context: these general meanings should not appear
'yield': ['harvest', 'crop', 'produce', 'give way', 'surrender'],
'duration': ['how long', 'length of time', 'period of time'],
'floor': ['ground floor', 'building floor', 'floor plan'],
'cap': ['hat', 'market cap', 'bottle cap'],
}
def check_terminology_consistency(text, domain_term):
text_lower = text.lower()
prohibited = PROHIBITED_GENERAL_MEANINGS.get(domain_term, [])
violations = []
for general_phrase in prohibited:
if general_phrase in text_lower:
# Find context window around the violation
idx = text_lower.index(general_phrase)
context = text[max(0, idx-50):idx+80]
violations.append({'phrase': general_phrase, 'context': context})
return violations
# Usage after LLM call
output = 'The yield of the bond is 4.5% per annum based on current market price.'
violations = check_terminology_consistency(output, 'yield')
if violations:
print('Terminology violation detected:', violations)
else:
print('Terminology consistency: PASS')إدارة إصدارات المسرد
يجب إدارة إصدارات مسارد المجالات بالتزامن مع الموجّهات. فأي تغيير في المصطلحات، مثل تعريف تنظيمي جديد أو معيار سريري محدّث، يتطلب إعادة تقييم جميع الموجّهات التي تستخدم المصطلحات المتأثرة.
# Glossary versioning with impact tracking
GLOSSARY_VERSIONS = {
'1.0.0': {
'yield': 'Bond yield: annual coupon / face value (current yield)',
'duration': 'Macaulay duration'
},
'2.0.0': {
'yield': 'Bond yield: annual return as % of current market price (yield to maturity)',
'duration': 'Modified duration (more precise for risk management)',
'convexity': 'Second-order rate sensitivity (new in v2)' # new term
}
}
def get_affected_prompts(old_version, new_version, prompt_registry):
'''Find prompts that use terms changed between glossary versions.'''
old_terms = set(GLOSSARY_VERSIONS[old_version].keys())
new_terms = set(GLOSSARY_VERSIONS[new_version].keys())
changed_terms = old_terms ^ new_terms # symmetric difference
affected = []
for prompt_id, artifact in prompt_registry.items():
if any(term in artifact['template'] for term in changed_terms):
affected.append(prompt_id)
return affected
print('Prompts affected by glossary v1.0.0 -> v2.0.0 update:', ['rate-analysis-v1', 'bond-report'])أنطولوجيا هرمية بعلاقات الأصل والفرع
تعرّف الأنطولوجيات الكاملة تراتبيات المفاهيم من الأصل إلى الفرع. ويتيح التوجيه باستخدام تراتبية للنموذج الاستدلال على مستوى التحديد المناسب، فلا يكون واسعًا جدًا ولا ضيقًا جدًا.
PRODUCT_ONTOLOGY = '''
PRODUCT CATEGORY ONTOLOGY (use for all product classification tasks):
Electronics
Computing
Laptops
Gaming Laptops
Ultrabooks
Workstations
Desktops
Tablets
Consumer Electronics
Smartphones
Smart Speakers
Wearables
Smartwatches
Fitness Trackers
CLASSIFICATION RULES:
1. Always classify to the most specific level where evidence exists.
2. If a product matches multiple branches, use the primary use case.
3. Use exact taxonomy names from above — do not invent new categories.
4. If a product does not fit, use the nearest parent category and
add "[NON-STANDARD: <reason>]" after the category name.
'''
print('Product ontology ready. 4-level hierarchy loaded.')تحقق سريع
نُشر نموذج لتحليل محافظ السندات. ومن دون إدراج مسرد، يفسّر النموذج السؤال «What is the yield on this instrument?» على أنه يطلب وصف إنتاج المحاصيل. ما السبب الجذري وما الحل؟
ملخص إدراج المسرد والأنطولوجيا
يعالج إدراج مسرد المجال والأنطولوجيا الغموض الاصطلاحي على مستوى النظام:
- إدراج المسرد: عرّف معاني المصطلحات الخاصة بالمجال في موجّه النظام عند وجود مصطلحات ملتبسة
- إدراج الأنطولوجيا: قدّم تراتبيات المفاهيم وقواعد العلاقات وقيود التصنيف
- المسرد الديناميكي: اختر المصطلحات ذات الصلة فقط من مسرد رئيسي لإبقاء نوافذ السياق مقتصدة
- إزالة الالتباس متعدد المجالات: أدرج قواعد لاكتشاف المجال استنادًا إلى السياق
- إدارة الإصدارات: يجب إدارة إصدارات المسارد وإعادة تقييم الموجّهات عند تغيّر المصطلحات
- فحص الاتساق: عالج المخرجات لاحقًا لاكتشاف انحراف المصطلحات
الأسئلة الشائعة
هل درس «حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال» مجاني؟
نعم — نص درس «حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Prompt Engineering، انتقل إلى CoddyKit PRO. تتضمن دورة AI Prompt Engineering 4 دروس في المجموع.
ماذا ستتعلم في «حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال»؟
تضمين المصطلحات والمعارف الخاصة بالمجال في مطالبات النظام تتمرن على AI Prompt Engineering مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ AI Prompt Engineering؟
لا تُشترط خبرة سابقة. AI Prompt Engineering على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس AI Prompt Engineering هذا؟
نعم. كل درس في AI Prompt Engineering يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- أنماط المطالبات في المجال القانوني
- صياغة المطالبات الطبية والسريرية
- المطالبات المالية والكمية
- حقن مسرد المصطلحات والأنطولوجيا الخاصة بالمجال