HF-1: Add rules for punctuations
#3
by
rain1024
- opened
- HISTORY.md +10 -0
- check.py +41 -0
- data/large/train.txt +2 -2
HISTORY.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HISTORY
|
| 2 |
+
|
| 3 |
+
## 1.1.0 (2023-07-25)
|
| 4 |
+
|
| 5 |
+
* Add script check.py
|
| 6 |
+
* Fix some punctuation errors
|
| 7 |
+
|
| 8 |
+
## 1.0 (2023-02-23)
|
| 9 |
+
|
| 10 |
+
* Initial commit
|
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 |
+
|
| 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"data/large/train.txt:{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.")
|
data/large/train.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c4082b8e42bec83df17f6ac27892c0848468c442e84a4b8d47833daa7f0d6209
|
| 3 |
+
size 20883616
|