wordbank/base_model.py
2025-12-03 15:22:54 +03:30

300 lines
8.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from pydantic import BaseModel
from typing import List, Optional, Union
# برچسب های گرامری
word_class_dict = {
"noun": "اسم",
"proper_noun": "اسم خاص",
"plural_noun": "اسم جمع",
"verb": "فعل",
"auxiliary_verb": "فعل کمکی",
"adjective": "صفت",
"adverb": "قید",
"pronoun": "ضمیر",
"conjunction": "حرف ربط",
"particle": "حروف ربط کوچک",
"preposition": "حرف اضافه",
"interjection": "صوت/حرف ندا",
"numeral": "عدد",
"determiner": "تعیین کننده",
"classifier": "شمارنده",
"modal_verb": "فعل وجهی",
"brand": "نام تجاری",
"trademark": "علامت تجاری",
"rare": "نادر",
"nonce": "واژه ساخته شده برای یک موقعیت خاص",
"constructed": "ساخته شده توسط هوش مصنوعی",
"neologism": "واژه تازه ابداع شده",
"unknown": "ناشناخته",
"other": "غیره",
}
# برچسب های غیر گرامری کلمه
tags_dict = {
"loanword": "واژه وام گرفته شده",
"foreign": "واژه خارجی گردان شده",
"formal": "رسمی",
"informal": "غیررسمی",
"colloquial": "محاوره ای/گفتاری",
"slang": "عامیانه",
"vulgar": "رکیک",
"offensive": "توهین آمیز",
"derogatory": "تحقیرآمیز",
"euphemistic": "مؤدبانه",
"archaic": "منسوخ",
"archaism": "کلمه ای قدیمی که گاهی برای اثر هنری استفاده می شود",
"obsolete": "کاملاً منسوخ شده",
"dated": "قدیمی ولی هنوز کمی استفاده می شود",
"historical": "تاریخی",
"poetic": "کاربرد شعری",
"literary": "ادبی",
"modern": "مدرن",
"literal": "",
"figurative": "",
"idiomatic": "اصطلاحی",
"metaphorical": "اصطلاحی",
"hyperbolic": "اغراق آمیز",
"regional": "منطقه ای",
"dialect": "لهجه ای",
"united-state": "آمریکایی",
"united-kingdom": "بریتانیایی",
"per-iranian": "فارسی ایران",
"per-afghanian": "فارسی افغانستان",
"per-tajiks": "فارسی تاجیکستان",
"persian-gulf-arabic": "عربی خلیج فارس",
"egyptian-arabic": "عربی مصری",
"yemenian-arabic": "عربی یمنی",
"tehrani": "لهجه تهرانی",
"qomi": "لهجه قمی",
"colloquial-ersian": "فارسی محاوره ای",
"humorous": "طنزآمیز",
"sarcastic": "کنایه ای",
"ironic": "طعنه آمیز",
"pejorative": "تحقیرآمیز",
"affectionate": "محبت آمیز",
"neutral": "خنثی",
"elevated": "فاخر",
"polite": "مؤدبانه",
"rude": "بی ادبانه",
"gendered": "(مذکر/مونث) جنسیتی",
"inclusive": "خنثی جنسیتی",
"racist": "نژادپرستانه",
"classist": "طبقاتی",
}
# زبان کلمه
lang_dict = {
"persian": "فارسی",
"old_persian": "فارسی کهن",
"arabic": "عربی",
"english": "انگلیسی",
"turkish": "ترکی",
"kurdish": "کوردی",
"azeri": "آذری",
"etc": "سایر زبان ها",
}
# حوزه کلمه
scope_dict = {
"medical": "پزشکی",
"legal": "حقوقی",
"scientific": "علمی",
"technical": "فنی",
"religious": "مذهبی",
"mythological": "اساطیری",
"military": "نظامی",
"internet": "اینترنت",
"unknown": "ناشناخته",
"other": "سایر حوزه ها",
"public": "روزمره",
"economic ": "اقتصادی",
"financial": "مالی",
"business": "تجارت",
"tax": "مالیات",
"budget": "بودجه",
"industry": "صنعت",
"agricultural": "کشاورزی",
"transportation": "حمل و نقل",
"estate": "املاک",
"insurance": "بیمه",
"social": "اجتماعی",
"culture": "فرهنگ",
"literature": "ادبیات",
"art": "هنر",
"ُsport": "ورزش",
"family": "خانواده",
"education": "آموزش",
"media": "رسانه",
"environment": "محیط زیست",
"administrative": "اداری",
"security": "امنیت",
"police": "انتظامی",
"elections": "انتخابات",
"development": "توسعه",
"documents": "اسناد",
"civil": "مدنی",
"political": "سیاسی",
"historical": "تاریخی",
"philosophical": "فلسفی",
"technology": "فناوری",
}
# Base-Model
class WordCorrector(BaseModel):
id:str # شناسه یکتا داخل دیتابیس
word: str # کلمه
is_correct: bool = False # آیا املای کلمه درست است؟
nearest_correct_word: str # کلمه اصلاح‌شده
origin: str = "" # مصدر
stem: str = "" # ریشه
is_proper_noun: Optional[bool] = False # اگر اسم است: True = خاص، False = عام
word_class: Optional[Union[List[str], str]]
# = [
# "noun",
# "proper_noun",
# "plural_noun",
# "verb",
# "auxiliary_verb",
# "adjective",
# "adverb",
# "pronoun",
# "conjunction",
# "particle",
# "preposition",
# "interjection",
# "numeral",
# "determiner",
# "classifier",
# "modal_verb",
# "brand",
# "trademark",
# "rare",
# "nonce",
# "constructed",
# "neologism",
# "unknown",
# "other",
# ]
tags: Optional[Union[List[str], str]]
# = [
# "loanword",
# "foreign",
# "formal",
# "informal",
# "colloquial",
# "slang",
# "vulgar",
# "offensive",
# "derogatory",
# "euphemistic",
# "archaic",
# "archaism",
# "obsolete",
# "dated",
# "historical",
# "poetic",
# "literary",
# "modern",
# "literal",
# "figurative",
# "idiomatic",
# "metaphorical",
# "hyperbolic",
# "regional",
# "dialect",
# "united-state",
# "united-kingdom",
# "per-iranian",
# "per-afghanian",
# "per-tajiks",
# "persian-gulf-arabic",
# "egyptian-arabic",
# "yemenian-arabic",
# "tehrani",
# "qomi",
# "colloquial-ersian",
# "humorous",
# "sarcastic",
# "ironic",
# "pejorative",
# "affectionate",
# "neutral",
# "elevated",
# "polite",
# "rude",
# "gendered",
# "inclusive",
# "racist",
# "classist",
# ]
ner_description: Optional[str] = "" # تشریح کلمه
llm_description: Optional[str] = "" # توضیحات مدل درباره کلمه
user_description: Optional[str] = "" # توضیحات شخص درباره کلمه
admin_description: Optional[str] = "" # توضیحات متخصص درباره کلمه
confidence: Optional[float] = None # اطمینان مدل
lang: Optional[Union[List[str], str]]
# = [
# "persian",
# "old_persian",
# "arabic",
# "english",
# "turkish",
# "kurdish",
# "azeri",
# "etc",
# ]
scope: Optional[Union[List[str], str]]
# = [
# "medical",
# "legal",
# "scientific",
# "technical",
# "religious",
# "mythological",
# "military",
# "internet",
# "unknown",
# "other",
# "public",
# "economic ",
# "financial",
# "business",
# "tax",
# "budget",
# "industry",
# "agricultural",
# "transportation",
# "estate",
# "insurance",
# "social",
# "culture",
# "literature",
# "art",
# "ُsport",
# "family",
# "education",
# "media",
# "environment",
# "administrative",
# "security",
# "police",
# "elections",
# "development",
# "documents",
# "civil",
# "political",
# "historical",
# "philosophical",
# "technology",
# ]
# مدل برای POST درخواست‌ها
class IDRequest(BaseModel):
id: int = None
name: Optional[str] = None # فیلد اختیاری برای تست