UTS_WTK / check.py
rain1024's picture
HF-1: Add rules for punctuations (#3)
0fea388
class PunctuationRule:
def __init__(self, punctuation_marks=[":", ",", "\"", "%", "."]):
self.name = "Punctuation Rule"
self.punctuation_marks = punctuation_marks
def check(self, token, tag) -> bool:
if token in self.punctuation_marks and tag != "B-W":
return False
return True
if __name__ == "__main__":
Rules = [PunctuationRule()]
with open('data/large/train.txt', 'r', encoding='utf-8') as file:
data = file.read()
lines = [line.split() for line in data.strip().split('\n')]
# Lists to capture inconsistencies
inconsistencies = []
violations = []
# Iterate through tokens and tags
for line_index, line in enumerate(lines):
if len(line) != 2:
continue
token, tag = line
for rule in Rules:
if not rule.check(token, tag):
violations.append((token, tag, line_index+1))
# Print violations
if violations:
print("Các dấu không tuân thủ rule:")
for token, tag, line_number in violations:
print(f"data/large/train.txt:{line_number}: Dấu {token} | Nhãn {tag}")
print(f"\nTổng số lần sai: {len(violations)}")
else:
print("Tất cả các dấu tuân thủ rule.")