diff --git a/app/monir/base_model.py b/app/monir/base_model.py new file mode 100644 index 0000000..4263e23 --- /dev/null +++ b/app/monir/base_model.py @@ -0,0 +1,164 @@ +from pydantic import BaseModel, Field +from typing import Optional, List, Dict +from datetime import datetime + + +# فیلد اجباری: +# str = Field(..., description="") +# فیلد اختیاری: +# Optional[str] = Field(None, description="") + +class Properties(BaseModel): + """ + Standard Form Of Foreign Key To Other Index + """ + id: str = Field(..., description="شناسه یکتا") + title: str = Field(..., description="عنوان") + author: str = Field(..., description="سازنده") + sub_type: str = Field(..., description="نوع دوم") + + +class TreeInfo(BaseModel): + title: str + parent_id: str = Field(..., description="") + child_order: int + level: int + full_path: Optional[str] = Field(None, description="") + path_headings: str + + +class NlpParses(BaseModel): + main_type: str + nlp_type: str + begin: int + end: int + text: str + referes: str + dependency_infos:str # nested + + +class Embeddings(BaseModel): + type: Optional[str] = Field(None, description=""), + dims: Optional[int] = Field(1024, description=""), + index: Optional[bool] = Field(True, description=""), + similarity: Optional[str] = Field(None, description="") + + +class FileLinks(BaseModel): + title: str + link: str + type: str + description: str + + +class UserLogs(BaseModel): + id: str + user_id: int + username: str + time_edit: datetime + property: str + + +class MnSection(BaseModel): + id: str + main_type: str + html: str + content: str + meet_info: Properties + term_info: Properties + tree_info: TreeInfo + content_len: int + word_len: int + tags: str + keywords: str + sort_date_timestamp: int + nlp_parses: NlpParses + embeddings: Embeddings + file_links: FileLinks + time_edit: datetime + user_edit: int + user_logs: UserLogs + + +class MnTerm(BaseModel): + id: str + main_type: str + sub_type: str + title: str + content: str + author: str + begin_date: datetime + end_date: datetime + begin_year: int + tags: str + keywords: str + + +class MnMeetEntity(BaseModel): + id: str + main_type: str + sub_type: str + title: str + content: str + permit_tags: str + search_state: str + user_create: str + time_create: datetime + time_edit: datetime + file_links: FileLinks + meet_info: Properties + term_info: Properties + +class Subjects(BaseModel): + id: int + title: str + +class ReportInfo(BaseModel): + film_count: int + sound_count: int + photo_count: int + file_count: int + is_address: int + is_mindex: int + is_mintro: int + is_sanad_data1: int + is_sanad_data2: int + +class MnMeet(BaseModel): + """ + Monir Meet Standard fields foramt + """ + id: str + main_type: str + sub_type: str + person_code: str + research_code: str + meet_code: str + old_meet_id: int + title: str + meet_no: int + author: str + term_info: Properties + subtitle: str + subjects: Subjects + allwords: str + tags: str + keywords: str + verb: str + sanad_year: int + sanad_date: datetime + amplify: str + ralation: str + city: str + place: str + address: str + audience: str + attendees: str + report_info: ReportInfo + mindex: str + mintro: str + content: str + completion: Optional[str] = Field(None, description="type: completion") + sort_date_timestamp: int + permit_tags: str + resource_info: str \ No newline at end of file diff --git a/app/monir/new_schema/mn_term.py b/app/monir/new_schema/mn_term.py deleted file mode 100644 index a4b33d4..0000000 --- a/app/monir/new_schema/mn_term.py +++ /dev/null @@ -1,46 +0,0 @@ -from pydantic import BaseModel - -class MnTerm(BaseModel): - id: str - main_type : str - "sub_type": str - "title": str - "content": str - "author": str - { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "begin_date": { - "type": "date" - }, - "end_date": { - "type": "date" - }, - "begin_year": { - "type": "integer" - }, - "tags": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "keywords": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - } -} \ No newline at end of file diff --git a/app/monir/sanad_stuff.py b/app/monir/sanad_stuff.py index 3c1a257..881bdc1 100644 --- a/app/monir/sanad_stuff.py +++ b/app/monir/sanad_stuff.py @@ -1,24 +1,29 @@ # --------------------------- modularity from app.common.elastic_helper import ElasticHelper -from pydantic import BaseModel +from base_model import MnTerm # --------------------------- global-params +input_es_index_name = '' base_index_name = 'monir_test_term' id_data = None _data = None # --------------------------- function -def generate_pydantic_model_from_mapping(model_name: str, mapping_es: dict) -> type[BaseModel]: - fields = {} - for field_name, field_def in mapping["properties"].items(): - es_type = field_def["type"] - py_type = ES_TO_PYDANTIC.get(es_type, str) - - # اضافه کردن optional بودن؟ یا default؟ بسته به نیاز - fields[field_name] = (py_type, ...) - - return type(name, (BaseModel,), {"__annotations__": fields}) +def conver_mn_term(old_data) -> MnTerm: + new_data = { + id: str + main_type: str + sub_type: str + title: str + content: str + author: str + begin_date: datetime + end_date: datetime + begin_year: int + tags: str + keywords: str + } # --------------------------- flow @@ -35,4 +40,11 @@ es_helper.update_index_doc( index_name_o=base_index_name, eid=id_data, data=_data -) \ No newline at end of file +) + +# --------------------------- RUN +# ------ command +# --liunx +# python3 -m app.monir.sanad_stuff.py +# --windows +# python -m app.monir.sanad_stuff.py