Spaces:
Running
Running
File size: 7,159 Bytes
60d1d13 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
import pandas as pd
from typing import List
from langchain.schema import Document
from src.processor.text_utils import VietnameseTextProcessor
class CSVProcessor:
"""Process various CSV files from ViettelPay documentation"""
def __init__(self):
self.text_processor = VietnameseTextProcessor()
def process_definitions(self, file_path: str) -> List[Document]:
"""Process dinh_nghia.csv"""
df = pd.read_csv(file_path)
documents = []
for _, row in df.iterrows():
term = str(row["Định nghĩa"]).strip()
definition = str(row["Giải thích"]).strip()
# Create content
content = f"Định nghĩa - {term}: {definition}"
documents.append(
Document(
page_content=content,
metadata={
"doc_type": "definition",
"term": term,
"category": "terminology",
"source_file": "dinh_nghia.csv",
},
)
)
return documents
def process_error_handling(self, file_path: str) -> List[Document]:
"""Process huong_dan_xu_ly_loi.csv - Most critical for customer support"""
df = pd.read_csv(file_path)
documents = []
for _, row in df.iterrows():
error_code = str(row["Mã lỗi"]).strip()
error_msg = str(row["Câu báo lỗi/yêu cầu hỗ trợ"]).strip()
service = str(
row["Nghiệp vụ"]
).strip() # Fixed column name (no trailing space)
cause = str(row["Nguyên nhân"]).strip()
status = str(row["Trạng thái giao dịch"]).strip()
solution = str(row["Hướng khắc phục"]).strip()
# Create comprehensive content
content = f"""
Mã lỗi {error_code}: {error_msg}
Nghiệp vụ: {service}
Nguyên nhân: {cause}
Trạng thái: {status}
Cách khắc phục: {solution}
""".strip()
documents.append(
Document(
page_content=content,
metadata={
"doc_type": "error_resolution",
"error_code": error_code,
"service_type": service,
"status": status,
"source_file": "huong_dan_xu_ly_loi.csv",
},
)
)
return documents
def process_payment_guide(self, file_path: str) -> List[Document]:
"""Process huong_dan_thanh_toan.csv"""
df = pd.read_csv(file_path)
documents = []
for _, row in df.iterrows():
transaction_type = str(row["Loại giao dịch"]).strip()
scope = str(row["Phạm vi thanh toán"]).strip()
guide = str(row["Hướng dẫn thanh toán"]).strip()
content = f"""
Hướng dẫn thực hiện giao dịch
Loại giao dịch: {transaction_type}
Phạm vi: {scope}
Các bước thực hiện:
{guide}
""".strip()
documents.append(
Document(
page_content=content,
metadata={
"doc_type": "procedure",
"transaction_type": transaction_type,
"service_scope": scope,
"category": "payment_guide",
"source_file": "huong_dan_thanh_toan.csv",
},
)
)
return documents
def process_error_codes(self, file_path: str) -> List[Document]:
"""Process bang_ma_loi.csv"""
df = pd.read_csv(file_path)
documents = []
for _, row in df.iterrows():
error_code = str(row["Mã lỗi"]).strip()
description = str(row["Mô tả"]).strip()
content = f"Mã lỗi {error_code}: {description}"
documents.append(
Document(
page_content=content,
metadata={
"doc_type": "error_code",
"error_code": error_code,
"category": "error_reference",
"source_file": "bang_ma_loi.csv",
},
)
)
return documents
def process_cancellation_rules(self, file_path: str) -> List[Document]:
"""Process quy_dinh_huy_giao_dich.csv"""
df = pd.read_csv(file_path)
documents = []
# File summary for better semantic context
file_summary = """
Tài liệu quy định hủy giao dịch ViettelPay.
Bao gồm các quy định về điều kiện, hạn mức, nguyên tắc và hướng dẫn thực hiện hủy giao dịch thanh toán cước viễn thông Viettel.
""".strip()
for _, row in df.iterrows():
rule_type = str(row["Nội dung"]).strip()
rule_details = str(row["Quy định"]).strip()
# Create content with summary for better semantic understanding
content = f"""
{file_summary}
Nội dung: {rule_type}
Quy định: {rule_details}
""".strip()
documents.append(
Document(
page_content=content,
metadata={
"doc_type": "policy",
"rule_type": rule_type,
"category": "cancellation_rules",
"source_file": "quy_dinh_huy_giao_dich.csv",
},
)
)
return documents
def process_denominations(self, file_path: str) -> List[Document]:
"""Process menh_gia.csv - Concatenated approach for comparison queries"""
df = pd.read_csv(file_path)
# Create a summary chunk for denominations (concatenated approach)
content = "Bảng mệnh giá thẻ cào theo nhà mạng:\n\n"
for _, row in df.iterrows():
denomination = str(
row["Mệnh giá (Đơn vị tính VNĐ)"]
).strip() # Fixed column name
viettel = str(row["Nhà mạng Viettel"]).strip()
mobifone = str(row["Nhà mạng Mobifone"]).strip()
vinaphone = str(row["Nhà mạng Vinaphone"]).strip()
vietnammobile = str(row["Nhà mạng Vietnammobile"]).strip()
content += f"Mệnh giá {denomination}: Viettel({viettel}), Mobifone({mobifone}), Vinaphone({vinaphone}), Vietnammobile({vietnammobile})\n"
return [
Document(
page_content=content,
metadata={
"doc_type": "reference",
"category": "denominations",
"source_file": "menh_gia.csv",
},
)
]
|