update
Browse files- HISTORY.md +5 -0
- data_inconsistent_check.py +41 -0
HISTORY.md
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# HISTORY
|
2 |
+
|
3 |
+
## 1.0.0 (2023-02-24)
|
4 |
+
|
5 |
+
* Initial Commit
|
data_inconsistent_check.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
class PunctuationRule:
|
3 |
+
def __init__(self, punctuation_marks=[":", ",", "\"", "%", "."]):
|
4 |
+
self.name = "Punctuation Rule"
|
5 |
+
self.punctuation_marks = punctuation_marks
|
6 |
+
|
7 |
+
def check(self, token, tag) -> bool:
|
8 |
+
if token in self.punctuation_marks and tag != "B-W":
|
9 |
+
return False
|
10 |
+
return True
|
11 |
+
|
12 |
+
|
13 |
+
if __name__ == "__main__":
|
14 |
+
Rules = [PunctuationRule()]
|
15 |
+
|
16 |
+
with open('data/large/train.txt', 'r', encoding='utf-8') as file:
|
17 |
+
data = file.read()
|
18 |
+
lines = [line.split() for line in data.strip().split('\n')]
|
19 |
+
print(len(lines))
|
20 |
+
# Lists to capture inconsistencies
|
21 |
+
inconsistencies = []
|
22 |
+
violations = []
|
23 |
+
|
24 |
+
|
25 |
+
# Iterate through tokens and tags
|
26 |
+
for line_index, line in enumerate(lines):
|
27 |
+
if len(line) != 2:
|
28 |
+
continue
|
29 |
+
|
30 |
+
token, tag = line
|
31 |
+
for rule in Rules:
|
32 |
+
if not rule.check(token, tag):
|
33 |
+
violations.append((token, tag, line_index+1))
|
34 |
+
# Print violations
|
35 |
+
if violations:
|
36 |
+
print("Các dấu không tuân thủ rule:")
|
37 |
+
for token, tag, line_number in violations:
|
38 |
+
print(f"Line {line_number}: Dấu {token} | Nhãn {tag}")
|
39 |
+
print(f"\nTổng số lần sai: {len(violations)}")
|
40 |
+
else:
|
41 |
+
print("Tất cả các dấu tuân thủ rule.")
|