Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 1,356 Bytes
8db6109
a361ef5
 
8db6109
 
a361ef5
8db6109
 
 
a361ef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8db6109
a361ef5
8db6109
 
a361ef5
8db6109
 
 
 
 
 
a361ef5
8db6109
a361ef5
8db6109
 
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
42
43
44
45
46
47
48
49
import json
import string
import re

stopwords = ["he", "she", "they", "it"]
list_alnum = string.ascii_lowercase + '0123456789 '


def filtering(entry):

    def _subfilter(token):
        if len(re.findall(rf'[^{list_alnum}]+', token)) != 0:
            return False
        if token in stopwords:
            return False
        if token.startswith("www"):
            return False
        if token.startswith("."):
            return False
        if token.startswith(","):
            return False
        if token.startswith("$"):
            return False
        if token.startswith("+"):
            return False
        if token.startswith("#"):
            return False
        return True

    if not _subfilter(entry["object"].lower()):
        return False
    if not _subfilter(entry["subject"].lower()):
        return False

    if entry['object'].islower() and entry['subject'].islower():
        return False

    return True


for s in ['train', 'validation', 'test']:
    with open(f"data/t_rex.raw.{s}.jsonl") as f:
        data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
    print(f"[{s}] (before): {len(data)}")
    data = [i for i in data if filtering(i)]
    print(f"[{s}] (after) : {len(data)}")
    with open(f"data/t_rex.filter.{s}.jsonl", 'w') as f:
        f.write('\n'.join([json.dumps(i) for i in data]))