This commit is contained in:
init_mahdi
2026-11-28 16:36:19 +00:00
parent f7f9e85b02
commit 31a0647f77
111 changed files with 23944 additions and 3 deletions
+794
View File
@@ -0,0 +1,794 @@
import os, re
import orjson
from pathlib import Path
import json, traceback
import re
from typing import Any
from pydantic import BaseModel
from typing import List, Dict, Optional
from json_repair import repair_json
def load_orjson(path: str | Path):
path = Path(path)
with path.open("rb") as f: # باید باینری باز بشه برای orjson
return orjson.loads(f.read())
def save_orjson(path, data):
with open(path, "wb") as f:
f.write(
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
)
def preprocess_data(
j_path=Path("/home2/data/hadith-noor.json"),
output_path=Path("/home1/ava3/project/aiDataParser/task/0_hadis/input_data.json"),
system_prompt1="""تو یک مترجمِ متخصص در حوزه‌ی علوم اسلامی مانند، فقه و حقوق، تفسیر، اخلاق، عقاید، تاریخ اسلام و مخصوصا شیعه هستی.
متن زیر که یک حدیث از امامان معصوم شیعه هست را با دقتِ علمیِ و تحقیقی عمیق ترجمه کن.
در انجام این ترجمه، واژگان را دقیقاً مطابق با فرهنگِ اصطلاحاتِ همین حوزه تخصصی ترجمه کن.
از ترجمه‌های عمومی که معنای علمی را مخدوش می‌کنند، بپرهیز و هر اصطلاحِ کلیدی را در سراسر متن، با یک معادلِ واحد و ثابت ترجمه کن.
در مجموع مختصر و مفید و به صورت بسیار کوتاه ترجمه کن.
اگر اصطلاحی نیاز به تبیین دارد، فقط در داخل کروشه […] و به صورت ساده و مختصر واضح کن.
و در ترجمه کلمات مهم متن مثل افعال و ضمائر دقت داشته باش.
- نکته : به هیج عنوان اسم راوی یا نقل کننده یا اسم های داخل حدیث را تغییر ندهید! اگر اسم خاصی از شخصی بود باید در قسمت "dictionary" اسم عمومی تر را بیان کنید به عنوان مثال:
{
"word":"ابی عبدالله",
"translate":"امام حسین (علیه السلام)"
}
خروجی باید دقیقا مطابق با Schema زیر در قالب یک شیء Json باشد :
{
"pure_translation": "(فقط متن حدیث بدون هیچ گوینده و یا نقل شده ای) ترجمه کوتاه، دقیق، تخصصی و وفادار به متن حدیث",
"speaker_translation": "ترجمه کامل به همراه گوینده یا نقل کننده حدیث",
"dictionary":[
{
"word": "کلمات مهم داخل متن (مواردی مهم و یا مواردی که ممکن است با چند معنی تفسیر شوند)",
"translate": "ترجمه دقیق با توضیحات خلاصه ریشه و .. یا تفسیر کوتاه از معنی مشخص در این حدیث",
}
]
}
""",
system_prompt2="""تو یک متخصص موضوع‌زنی در حوزه‌ی علوم اسلامی و مخصوصا شیعه هستی.
مفاهیم موجود در متن زیر که یک حدیث از امامان معصوم شیعه هست را با دقتِ علمیِ و تحقیقی بررسی کن. و یک موضوع از موضوعات کلی زیر را برایش به عنوان موضوع اصلی انتخاب کن و یک یا چند موضوع دیگر را به ترتیب اولویت به عنوان موضوعات فرعی انتخاب کن.
## موضوعات کلی زیر را داریم:
### فقه
الأحاديث التي تتعلّق بالأحكام الشرعية العملية، كالواجب والحرام والمستحب والمعاملات والعبادات.
### اصول فقه
الأحاديث أو النصوص المرتبطة بقواعد استنباط الأحكام وفهم الأدلة، كالنسخ والتخصيص والتقييد والتعارض.
### اخلاق
الأحاديث التي تتناول الصفات والسلوكيات الحسنة أو السيئة، كالصدق والصبر والتواضع والرفق والحسد والكبر.
### عقاید و کلام
الأحاديث المتعلقة بأصول الاعتقاد، كالتوحيد وصفات الله والنبوة والإمامة والمعاد والإيمان والكفر.
### تربیت و سلوک
الأحاديث التي تتناول تربية الإنسان وإصلاح سلوكه وبناء شخصيته وتدرّجه في اكتساب العادات والفضائل.
### عرفان و معنویت
الأحاديث التي تتناول العلاقة الباطنية بين الإنسان وربّه، كالإخلاص والذكر والتوكل والقرب والمحبة الإلهية.
### فلسفه و حکمت
الأحاديث التي تتناول قضايا الوجود والإنسان والمعرفة والعلل والحِكَم العامة في الخلق والتشريع.
### تاریخ و سیره
الأحاديث التي تروي أحداثاً أو وقائع أو أخباراً تاريخية، أو تتناول حياة الأنبياء والأئمة والشخصيات والأحداث.
### تفسیر و علوم قرآن
الأحاديث المرتبطة بتفسير الآيات القرآنية وشأن النزول والقراءات ومفاهيم القرآن وعلومه.
### اجتماعی و سیاسی
الأحاديث التي تتناول المجتمع والسلطة والعدل والحكم والعلاقات بين الناس والمسؤوليات الاجتماعية والسياسية.
### خانواده و سبک زندگی
الأحاديث المتعلقة بالزواج والزوجين والوالدين والأولاد والأقارب وآداب الحياة اليومية.
### پزشکی و سلامت
الأحاديث التي تتناول الصحة والمرض والعلاج والوقاية والتغذية ونظافة البدن وسلامته.
### آخرت و معاد
الأحاديث المتعلقة بالموت والبرزخ والقيامة والحساب والجنة والنار والثواب والعقاب الأخروي.
### دعا و عبادات
الأحاديث التي تتناول الدعاء والذكر والعبادات وكيفيتها أو فضائلها وآدابها.
### حقوق و روابط انسانی
الأحاديث التي تتناول حقوق الناس والعدل والأمانة والمسؤولية والملكية والحقوق المتبادلة بين الأفراد.
- هیچ topic نباید خارج از موارد زیر باشد:
< "فقه" | "اصول فقه" | "اخلاق" | "عقاید و کلام" | "تربیت و سلوک" | "عرفان و معنویت" | "فلسفه و حکمت" | "تاریخ و سیره" | "تفسیر و علوم قرآن" | "اجتماعی و سیاسی" | "خانواده و سبک زندگی" | "پزشکی و سلامت" | "آخرت و معاد" | "دعا و عبادات" | "حقوق و روابط انسانی">,
خروجی باید دقیقا مطابق با Schema زیر یک شیء Json باشد :
{
"main_topic": "موضوع اصلی حدیث"
"main_topic_reason" : " توضیح دقیق و کوتاه (متن را با لحنی عمومی، علمی، رسمی و غیرمخاطب‌محور بنویس؛ به‌گونه‌ای که مطالب برای خواننده و به‌صورت مستقل بیان شوند و نه در قالب توضیح مستقیم به کاربر یا مخاطب.)",
"secondary_topics": [
{
"topic":"موضوعات فرعی حدیث به ترتیب اولویت",
"reason": ...
}, ...
]
}""",
):
in_data = load_orjson(j_path)
f_data = []
for item in in_data["RECORDS"]:
# print(f'item["PureHadithText"] {item["PureHadithText"]}')
# return
try:
text = re.sub(r"<Document>.+</Narrator>", "", item["PureHadithText"])
text = re.sub(r"</Document>", "", text)
text = re.sub(r"<Innocent>", "", text)
text = re.sub(r"</Innocent>", "", text)
# text = re.search(r"<Innocent>(.*)", item["PureHadithText"], re.DOTALL)
# text = re.sub(r"</Innocent>", "", text.group(1)).strip()
except:
print(f'item["PureHadithText"] {item["PureHadithText"]}')
return
# re.search(r"<Innocent>(.*)", item["PureHadithText"]).group(1).strip()
f_data.append(
{
"task": "translate",
"system_prompt": system_prompt1,
"user_prompt": text,
"id": item["NajafId"] + "_1",
"NajafId": item["NajafId"],
"HadithId": item["HadithId"],
}
)
f_data.append(
{
"task": "subject",
"system_prompt": system_prompt2,
"user_prompt": text,
"id": item["NajafId"] + "_2",
"NajafId": item["NajafId"],
"HadithId": item["HadithId"],
}
)
# print(f"text {text}")
# break
print(f"f_data {len(f_data)}")
save_orjson(path=output_path, data=f_data)
class SecData(BaseModel):
topic: str
reason: str
class SubData(BaseModel):
main_topic: str
main_topic_reason: str
secondary_topics: Optional[List[SecData]] = []
class DicData(BaseModel):
word: str
translate: str
class TrnData(BaseModel):
pure_translation: str
speaker_translation: str
dictionary: List
def repair_json_text(text: str) -> str:
text = text.strip()
# حذف code fence
text = re.sub(r"^\s*```(?:json)?\s*", "", text, flags=re.IGNORECASE)
text = re.sub(r"\s*```\s*$", "", text)
text = re.sub(r'(?m)^\s*"الغلام"\s*,\s*$', "", text)
# text = re.sub(r'(?m)^(\s*)"\s*(\{)', r"\1\2", text)
# اصلاح مقدارهایی که به شکل زیر هستند:
# "key": «مقدار»,
# "key": «مقدار».
#
# علامت‌های «...» داخل خود متن حفظ می‌شوند.
pattern = r'(?m)^(\s*"[^"]+"\s*:\s*)«(.*)»\.?"?(\s*[,}])\s*$'
text = re.sub(
pattern,
lambda match: (
match.group(1)
+ json.dumps(match.group(2), ensure_ascii=False)
+ match.group(3)
),
text,
)
return text
def convert_to_dict(input: str) -> dict[str, Any]:
repaired_text = repair_json_text(input)
try:
# result = json.loads(repaired_text)
result = repair_json(repaired_text, return_objects=True)
except json.JSONDecodeError as error:
raise ValueError(
f"JSON حتی پس از اصلاح قابل پردازش نیست:\n{error}\n\n"
f"متن اصلاح‌شده:\n{repaired_text}"
) from error
if not isinstance(result, dict):
raise ValueError("خروجی JSON باید یک دیکشنری باشد.")
return result
def postprocess_data(
in_path=Path(
"/home1/ava3/project/aiDataParser/task/0_hadis/output/final_data_haids.json"
),
out_path=Path(
"/home1/ava3/project/aiDataParser/task/0_hadis/finall_data/phase1.json"
),
failed_path=Path(
"/home1/ava3/project/aiDataParser/task/0_hadis/finall_data/phase1_failed.json"
),
):
data_sub = {i["NajafId"]: i for i in load_orjson(in_path) if i["task"] == "subject"}
data_translate = {
i["NajafId"]: i for i in load_orjson(in_path) if i["task"] != "subject"
}
print(f"data_sub {len(data_sub)} data_translate {len(data_translate)}")
f_data = []
failed_data = []
failed = {
"18281",
"38399",
"51245",
"17808",
"17617",
"37170",
"72667",
"57532",
"34687",
"36007",
"12509",
"17788",
"10322",
}
for _id, item in data_translate.items():
if _id in failed:
failed_data.append(
{
"id": _id,
"text": item["user_prompt"],
"subject_data": data_sub[_id]["llm_output"],
"translate_data": item["llm_output"],
}
)
else:
try:
s_data = SubData.model_validate(
convert_to_dict(data_sub[_id]["llm_output"])
)
t_data = TrnData.model_validate(convert_to_dict(item["llm_output"]))
except:
print(
f"_id {_id}",
)
continue
f_data.append(
{
"id": _id,
"text": item["user_prompt"],
"subject_data": s_data.model_dump(),
"translate_data": t_data.model_dump(),
}
)
print(f"f_data {len(f_data)}")
save_orjson(data=f_data, path=out_path)
save_orjson(data=failed_data, path=failed_path)
def preprocess2_data(
in_path=Path(
"/home1/ava3/project/aiDataParser/task/0_hadis/finall_data/phase1.json"
),
o_path=Path("/home1/ava3/project/aiDataParser/task/0_hadis/input_phase2.json"),
rule_prompt="""You are a deterministic Arabic proposition extraction engine.
## 1. TASK
Extract ALL distinct, explicit, and semantically meaningful propositions contained in the Arabic INPUT.
The goal is NOT:
* summarization
* interpretation
* commentary
* paraphrasing
* theological judgment
* legal judgment
* authentication of narration
* adding information from external knowledge
* reconstructing missing historical or situational information
The goal is to decompose the Arabic text into the smallest independently understandable propositions while preserving its original meaning and explicitly expressed communicative situation.
---
## 2. INPUT
You will receive ONLY ONE Arabic text, No other contextual information is provided.
Rules:
* Do not assume missing context.
* Do not use external knowledge to complete or reconstruct the text.
* Do not identify unnamed persons using outside knowledge.
* Do not infer an unstated speaker, audience, location, time, purpose, or intention.
* If contextual information is not explicitly recoverable from the Arabic text, mark it as unknown or not specified.
---
# 3. CORE PRINCIPLE: EXTRACT PROPOSITIONS, NOT SENTENCES
A single Arabic sentence may contain multiple independent propositions.
Extract independently meaningful semantic units, including:
* statements
* descriptions
* commands
* prohibitions
* permissions
* recommendations
* obligations
* questions containing explicit assertions
* conditions
* exceptions
* causes
* consequences
* temporal relations
* comparisons
* attributions
* speech acts
* relationships between entities
* explicitly expressed normative or evaluative claims
Each independently meaningful proposition must become a separate output item.
Preserve the semantic force of the Arabic expression.
---
# 4. ATOMICITY
Each proposition must express ONE independently understandable meaning.
Split propositions when the Arabic contains multiple independent semantic units connected by:
* و
* أو
* ثم
* فـ
* إن
* إذا
* من
* متى
* كلما
* إلا
* غير
* سوى
* لأن
* بسبب
* لذلك
* حتى
* or equivalent structures
Also split when there are:
* multiple independent actions
* multiple independent subjects
* multiple objects
* multiple attributes
* multiple consequences
* multiple explicitly stated relations
However:
DO NOT split a semantic unit when splitting it would destroy an essential logical, causal, conditional, temporal, or relational connection.
### Example
Input: العلم نور والعمل به نجاة
Output:
1. علم نور است.
2. عمل کردن به علم موجب نجات است.
---
# 5. FAITHFULNESS
The Persian proposition MUST preserve:
1. subject
2. predicate/action
3. modality
4. tense/aspect when semantically relevant
5. condition
6. exception
7. causal relation
8. temporal relation
9. comparison
10. attribution
11. degree or limitation
12. negation
13. communicative force
Never strengthen or weaken the Arabic meaning.
Examples:
* قد يفعل → ممکن است انجام دهد
* لا يفعل → انجام نمی‌دهد
* لا تفعل → انجام نده / نهی از انجام آن
* ينبغي → شایسته است / باید به معنای توصیه‌ای
* يمكن → می‌تواند / امکان دارد
* يجب → باید / ملزم است
* ليس → نیست
Do not convert a descriptive statement into a normative statement unless the Arabic explicitly does so.
---
# 6. NO EXTERNAL INTERPRETATION
Extract ONLY what is supported by the Arabic text itself.
Do NOT:
* identify unnamed people through external knowledge
* identify narrators through external knowledge
* authenticate narrations
* infer historical circumstances
* infer theological implications
* infer jurisprudential rulings
* infer unstated intentions
* infer an unstated audience
* infer an unstated location
* infer an unstated time
* infer an unstated purpose
* resolve genuine textual ambiguity using outside knowledge
If the Arabic explicitly provides the information, preserve it.
---
# 7. PRONOUNS AND REFERENCES
When a pronoun has an unambiguous antecedent within the INPUT, resolve it in the Persian proposition when necessary for independent understanding.
Example:
Input: دخل زيد المسجد ثم صلى فيه
Output:
1. زید وارد مسجد شد.
2. زید در مسجد نماز خواند.
If the antecedent cannot be reliably determined from the Arabic itself:
* do not guess
* preserve the ambiguity
* explain it briefly in `note`
---
# 8. COMMANDS, PROHIBITIONS AND NORMATIVE EXPRESSIONS
Distinguish semantic force carefully.
Examples:
* افعل → command
* لا تفعل → prohibition
* يجوز → permission
* لا يجوز → prohibition
* ينبغي → recommendation
* يجب → obligation
* يحرم → prohibition
Do NOT automatically interpret every imperative as a legal obligation.
Classify according to the semantic force explicitly expressed by the Arabic.
---
# 9. QUESTIONS
Do not automatically convert questions into factual propositions.
If the question itself contains an explicit assertion, extract that assertion only when semantically justified.
Otherwise preserve the interrogative character and classify it as:
`question`
---
# 10. CONDITIONS
Conditions must remain attached to the proposition whose validity or action depends on them.
Input: إن جاء زيد فأكرمه
Correct: اگر زید آمد، او را گرامی بدار.
Do NOT extract:
زید آمد.
او را گرامی بدار.
because this destroys the conditional relationship.
---
# 11. EXCEPTIONS
Always preserve explicitly stated exceptions:
* إلا
* غير
* سوى
* ما عدا
* إلا أن
* and equivalent structures
Example:
كل الناس إلا زيدا
must preserve:
همه مردم، به‌جز زید، ...
---
# 12. CAUSALITY AND CONSEQUENCE
Preserve explicit causal and consequential relationships.
Examples:
* لأن
* بسبب
* لذلك
* فإن
* فـ
* حتى
* نتيجةً لـ
* equivalent constructions
Do not convert an explicitly causal relationship into unrelated propositions.
---
# 13. ATTRIBUTION AND SPEAKER
When the Arabic attributes a statement or action to a speaker/entity, preserve the attribution.
Example:
قال رسول الله: ...
The output must distinguish:
1. WHO said it
2. WHAT was said
Do not present an attributed statement as though the extraction engine independently asserts it.
---
# 14. CONTEXT ≠ CONTEXT OF UTTERANCE
IMPORTANT:
Do NOT use the `note` field merely to describe general:
* linguistic context
* surrounding text
* topic
* textual background
* meaning of the sentence
The primary contextual concept required here is:
## Context of Utterance / مقام بیان
«مقام بیان» refers to the communicative situation in which the utterance occurs, as explicitly recoverable from the Arabic text.
The system should identify, when the text explicitly provides or unambiguously establishes them:
* Speaker / گوینده
* Addressee / مخاطب
* Time / زمان
* Place / مکان
* Situation / موقعیت بیان
* Topic / موضوع سخن
* Speaker's purpose or communicative goal / هدف یا قصد بیان
* Shared assumptions explicitly present in the text
* Speech act / کنش گفتاری
* Relation between speaker and addressee when explicitly expressed
IMPORTANT:
Context of Utterance is NOT equivalent to:
* linguistic context
* textual context
* general background
* dictionary meaning
* semantic context
The task is to reconstruct the communicative situation ONLY from evidence available in the Arabic INPUT.
---
# 15. CONTEXT OF UTTERANCE / مقام بیان
For every proposition, analyze whether the Arabic text provides information about its utterance situation.
The `note` MUST focus primarily on:
### «مقام بیان / Context of Utterance»
Use the following structure when information is available:
* گوینده:
* مخاطب:
* زمان:
* مکان:
* موقعیت بیان:
* موضوع:
* هدف/قصد گوینده:
* کنش گفتاری:
Only include information that is explicitly stated or unambiguously recoverable from the Arabic text.
If a field is not provided, write:
`مشخص نیست`
Do NOT invent missing information.
### Example
Arabic:
قال المعلم للطلاب: اجتهدوا في دروسكم
The note should identify that:
* گوینده: معلم
* مخاطب: دانش‌آموزان
* موقعیت: خطاب مستقیم معلم به دانش‌آموزان
* موضوع: تلاش در درس
* هدف/قصد: ترغیب یا دستور به تلاش
* کنش گفتاری: دستور/ترغیب
It should NOT merely say:
`این جمله درباره درس و تلاش است.`
because this describes the topic rather than the مقام بیان.
---
# 16. SPEAKER'S INTENTION
Do not automatically equate literal meaning with speaker intention.
Example:
هنا بارد جدا
Literal meaning:
اینجا خیلی سرد است.
Depending on the explicitly recoverable situation, the speaker may be indirectly requesting:
پنجره را ببند.
However:
DO NOT infer such an intention unless the Arabic text itself provides sufficient evidence for it.
If the communicative intention cannot be established from the INPUT:
`هدف/قصد گوینده: مشخص نیست`
---
# 17. SPEECH ACT
Identify the communicative act expressed by the utterance when supported by the text.
Possible speech acts include:
* statement / گزارش
* question / پرسش
* command / دستور
* prohibition / نهی
* request / درخواست
* recommendation / توصیه
* promise / وعده
* threat / تهدید
* declaration / اعلام
* warning / هشدار
* invitation / دعوت
* praise / ستایش
* blame / سرزنش
Do not assign a speech act that is not supported by the Arabic.
The speech act describes WHAT THE SPEAKER IS DOING BY UTTERING THE EXPRESSION, not merely WHAT THE SENTENCE IS ABOUT.
---
# 18. PROPOSITION TYPES
Assign exactly ONE `proposition_type` to every proposition.
Allowed values:
`fact`
`description`
`command`
`prohibition`
`permission`
`recommendation`
`obligation`
`conditional`
`causal`
`consequence`
`attribution`
`comparison`
`negation`
`question`
`ambiguous`
Use the most specific applicable type.
Guidance:
* fact: explicit assertion
* description: explicit characterization or attribute
* command: imperative instruction
* prohibition: explicit prohibition
* permission: explicit permission
* recommendation: explicit recommendation/exhortation
* obligation: explicit obligation/necessity
* conditional: proposition dependent on explicit condition
* causal: explicit cause/reason relation
* consequence: explicit result
* attribution: attribution of speech/action to an entity
* comparison: explicit comparison
* negation: negation as central semantic function
* question: genuine interrogative
* ambiguous: meaning cannot reliably be determined from the Arabic itself
---
# 19. AMBIGUITY
If a proposition has multiple plausible interpretations and the Arabic text alone does not permit reliable resolution:
* do not guess
* preserve the ambiguity
* use `ambiguous`
* explain the ambiguity briefly in `note`
The note should still distinguish between:
1. the semantic ambiguity
2. the available Context of Utterance
Do not use external knowledge to resolve the ambiguity.
---
# 20. PERSIAN OUTPUT
Every `proposition` MUST be written in fluent, natural Persian.
Every `note` MUST be written in fluent, natural Persian.
Rules:
* No English inside proposition content.
* Preserve proper names faithfully.
* Do not unnecessarily transliterate Arabic.
* Do not add commentary.
* Do not modernize or reinterpret meaning.
* Do not translate idioms into unrelated meanings.
* Prefer concise but independently understandable Persian.
The Persian output is a semantic translation, not a word-for-word translation.
---
# 21. NOTE FIELD — CRITICAL REQUIREMENT
The `note` field is primarily for recording:
## «مقام بیان / Context of Utterance»
NOT merely:
* context
* background
* surrounding text
* topic explanation
* general interpretation
The note should answer, as far as the Arabic permits:
**این گزاره در چه مقام بیانی مطرح شده است؟**
Specifically:
1. چه کسی می‌گوید؟
2. خطاب به چه کسی؟
3. در چه موقعیتی؟
4. در چه زمان یا مکانی، اگر ذکر شده؟
5. موضوع سخن چیست؟
6. گوینده با این بیان چه می‌کند یا چه هدف ارتباطی دارد؟
7. کنش گفتاری چیست؟
If information is absent, explicitly say:
`در متن مشخص نشده است.`
Never fabricate contextual information.
---
# 22. DISTINCTION BETWEEN CONTEXT AND CONTEXT OF UTTERANCE
Use this distinction strictly:
### Context / بافت یا سیاق
Primarily concerns the relationship of an expression to:
* surrounding words
* surrounding sentences
* preceding/following discourse
* linguistic environment
* textual situation
### Context of Utterance / مقام بیان
Concerns the communicative circumstances of the utterance:
* speaker
* addressee
* time
* place
* situation
* topic
* purpose/intention
* communicative act
* explicitly shared assumptions
When generating `note`, prioritize the second category.
---
# 23. COMPLETENESS CHECK
Before producing the output, verify:
1. Every explicit semantic proposition is represented.
2. No independent proposition is omitted.
3. No proposition contains multiple independent meanings.
4. Conditions are preserved.
5. Exceptions are preserved.
6. Negation is preserved.
7. Causal relations are preserved.
8. Consequences are preserved.
9. Attribution is preserved.
10. Modality is preserved.
11. No external information has been introduced.
12. No meaning has been strengthened or weakened.
13. Every proposition is independently understandable.
14. Every proposition has exactly one `proposition_type`.
15. The `note` describes the Context of Utterance rather than merely general context.
16. Missing contextual information is explicitly marked as unspecified.
17. Speaker intention is not invented.
18. Speech act is identified only when supported by the text.
19. Output is valid JSON.
---
# 24. OUTPUT FORMAT
Return ONLY valid JSON.
No Markdown.
No explanation.
No commentary before or after the JSON.
Use this exact structure:
{
"propositions": [
{
"proposition": "گزاره اتمیک و دقیق به فارسی.",
"text": "قسمت دقیق و کامل از متن اصلی که این گزاره بر اساس آن استخراج شده است.",
"proposition_type": "fact",
"note": "توصیف خلاصه بافتِ بیان",
"context_of_utterance": {
"speaker": "گوینده، در صورت مشخص بودن" | null,
"addressee": "مخاطب، در صورت مشخص بودن" | null,
"time": "زمان، در صورت مشخص بودن" | null,
"place": "مکان، در صورت مشخص بودن" | null,
"situation": "موقعیت بیان، در صورت مشخص بودن" | null,
"topic": "موضوع سخن" | null,
"purpose": "هدف یا قصد ارتباطی گوینده، فقط در صورت قابل استنباط بودن از متن" | null,
"speech_act": "کنش گفتاری" | null
}
}
]
}
If a context_of_utterance field is not available in the Arabic text, use:
`null`
Do NOT infer missing information.
If the Arabic text contains no extractable proposition, return:
{
"propositions": []
}
""",
):
in_data = load_orjson(in_path)
print(f"in_data {len(in_data)}")
f_data = []
for item in in_data:
f_data.append(
{
"id": item["id"],
"user_prompt": item["text"],
"system_prompt": rule_prompt,
}
)
# if len(f_data) >= 10:
# break
print(f"f_data {len(f_data)}")
save_orjson(path=o_path, data=f_data)
preprocess2_data()
# python3 -m aiDataParser.task.0_hadis.data_helper