tien_nemo

test load data

......@@ -104,7 +104,7 @@
<!-- Dropdown OCR -->
<select v-if="selectingIndex !== null"
<select v-if="selectingIndex !== null && ocrData[selectingIndex].isManual"
:style="getSelectStyle(ocrData[selectingIndex])"
v-model="ocrData[selectingIndex].field"
@change="applyMapping"
......@@ -440,54 +440,6 @@
},
// Tìm box OCR phù hợp nhất để map với field
findBestMatchingBox(fieldName, fieldValue) {
let bestMatchIndex = -1;
let bestScore = 0;
this.ocrData.forEach((item, index) => {
if (item.isDeleted) return;
// Nếu box này đã được map field khác, bỏ qua
if (item.field && item.field !== fieldName) return;
// Tính điểm phù hợp dựa trên text
const text = item.text || '';
const score = this.calculateTextSimilarity(text, fieldValue);
if (score > bestScore) {
bestScore = score;
bestMatchIndex = index;
}
});
// Chỉ map nếu điểm phù hợp đủ cao (ví dụ > 0.5)
return bestScore > 0.5 ? bestMatchIndex : -1;
},
// Tính điểm tương đồng giữa 2 text
calculateTextSimilarity(text1, text2) {
if (!text1 || !text2) return 0;
const t1 = text1.toLowerCase().trim();
const t2 = text2.toLowerCase().trim();
// Nếu text giống hệt nhau
if (t1 === t2) return 1.0;
// Nếu một text là subset của text kia
if (t1.includes(t2) || t2.includes(t1)) return 0.8;
// Tính điểm dựa trên số ký tự giống nhau
let commonChars = 0;
const minLength = Math.min(t1.length, t2.length);
for (let i = 0; i < minLength; i++) {
if (t1[i] === t2[i]) commonChars++;
}
return commonChars / Math.max(t1.length, t2.length);
},
onImageLoad() {
const img = this.$refs.pdfImage;
this.imageWidth = img.naturalWidth;
......@@ -529,32 +481,9 @@
zIndex: item.isManual ? 30 : 10
};
},
// highlightField(field) {
// let idx = -1;
// for (let i = this.ocrData.length - 1; i >= 0; i--) {
// const it = this.ocrData[i];
// if (!it.isDeleted && it.field === field) {
// idx = i;
// break;
// }
// }
//
// if (idx !== -1) {
// // Set active index (chuyển trạng thái active và màu xanh)
// this.activeIndex = idx;
// // Scroll đến box tương ứng
// this.scrollToBox(idx);
// // Focus vào box để người dùng thấy rõ
// this.focusOnBox(idx);
// } else {
// this.activeIndex = null;
// }
// },
highlightField(field) {
// Xóa tất cả manual box cũ trước khi tạo mới
// this.ocrData = this.ocrData.filter(b => !b.isManual);
//this.ocrData = this.ocrData.filter(b => !b.isManual);
let coords, text;
......