lvl2.1
This commit is contained in:
@@ -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
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+24
-12
@@ -1,24 +1,29 @@
|
|||||||
# --------------------------- modularity
|
# --------------------------- modularity
|
||||||
from app.common.elastic_helper import ElasticHelper
|
from app.common.elastic_helper import ElasticHelper
|
||||||
from pydantic import BaseModel
|
from base_model import MnTerm
|
||||||
|
|
||||||
# --------------------------- global-params
|
# --------------------------- global-params
|
||||||
|
input_es_index_name = ''
|
||||||
base_index_name = 'monir_test_term'
|
base_index_name = 'monir_test_term'
|
||||||
id_data = None
|
id_data = None
|
||||||
_data = None
|
_data = None
|
||||||
|
|
||||||
|
|
||||||
# --------------------------- function
|
# --------------------------- function
|
||||||
def generate_pydantic_model_from_mapping(model_name: str, mapping_es: dict) -> type[BaseModel]:
|
def conver_mn_term(old_data) -> MnTerm:
|
||||||
fields = {}
|
new_data = {
|
||||||
for field_name, field_def in mapping["properties"].items():
|
id: str
|
||||||
es_type = field_def["type"]
|
main_type: str
|
||||||
py_type = ES_TO_PYDANTIC.get(es_type, str)
|
sub_type: str
|
||||||
|
title: str
|
||||||
# اضافه کردن optional بودن؟ یا default؟ بسته به نیاز
|
content: str
|
||||||
fields[field_name] = (py_type, ...)
|
author: str
|
||||||
|
begin_date: datetime
|
||||||
return type(name, (BaseModel,), {"__annotations__": fields})
|
end_date: datetime
|
||||||
|
begin_year: int
|
||||||
|
tags: str
|
||||||
|
keywords: str
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# --------------------------- flow
|
# --------------------------- flow
|
||||||
@@ -35,4 +40,11 @@ es_helper.update_index_doc(
|
|||||||
index_name_o=base_index_name,
|
index_name_o=base_index_name,
|
||||||
eid=id_data,
|
eid=id_data,
|
||||||
data=_data
|
data=_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --------------------------- RUN
|
||||||
|
# ------ command
|
||||||
|
# --liunx
|
||||||
|
# python3 -m app.monir.sanad_stuff.py
|
||||||
|
# --windows
|
||||||
|
# python -m app.monir.sanad_stuff.py
|
||||||
|
|||||||
Reference in New Issue
Block a user