File size: 1,301 Bytes
0fea388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

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.")