UTS_WTK / data_inconsistent_check.py
rain1024's picture
update
af0870b
raw
history blame
1.31 kB
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')]
print(len(lines))
# 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"Line {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.")