ktagowski commited on
Commit
a9fd096
1 Parent(s): 5299df0

fix: Fix encoding and refactor nkjp-pos.py file

Browse files
Files changed (1) hide show
  1. nkjp-pos.py +43 -42
nkjp-pos.py CHANGED
@@ -31,41 +31,41 @@ _URLS = {
31
  _HOMEPAGE = "http://clip.ipipan.waw.pl/NationalCorpusOfPolish"
32
 
33
  _POS_TAGS = {
34
- 'adj',
35
- 'adja',
36
- 'adjc',
37
- 'adjp',
38
- 'adv',
39
- 'aglt',
40
- 'bedzie',
41
- 'brev',
42
- 'burk',
43
- 'comp',
44
- 'conj',
45
- 'depr',
46
- 'fin',
47
- 'ger',
48
- 'imps',
49
- 'impt',
50
- 'inf',
51
- 'interj',
52
- 'interp',
53
- 'num',
54
- 'numcol',
55
- 'pact',
56
- 'pant',
57
- 'pcon',
58
- 'ppas',
59
- 'ppron12',
60
- 'ppron3',
61
- 'praet',
62
- 'pred',
63
- 'prep',
64
- 'qub',
65
- 'siebie',
66
- 'subst',
67
- 'winien',
68
- 'xxx'
69
  }
70
 
71
 
@@ -79,10 +79,11 @@ class NKJPPOS(datasets.GeneratorBasedBuilder):
79
  {
80
  "id": datasets.Value("string"),
81
  "tokens": datasets.Sequence(datasets.Value("string")),
82
- "pos_tags": datasets.Sequence(datasets.features.ClassLabel(
83
- names=list(_POS_TAGS),
84
- num_classes=len(_POS_TAGS)
85
- )),
 
86
  }
87
  ),
88
  homepage=_HOMEPAGE,
@@ -90,7 +91,7 @@ class NKJPPOS(datasets.GeneratorBasedBuilder):
90
  )
91
 
92
  def _split_generators(
93
- self, dl_manager: datasets.DownloadManager
94
  ) -> List[datasets.SplitGenerator]:
95
  urls_to_download = _URLS
96
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
@@ -119,9 +120,9 @@ class NKJPPOS(datasets.GeneratorBasedBuilder):
119
  return data_line
120
 
121
  def _generate_examples(
122
- self, filepath: str
123
  ) -> Generator[Tuple[str, Dict[str, str]], None, None]:
124
- with open(filepath, 'r') as f:
125
  for line in f:
126
  data_line = self._clean_line(json.loads(line))
127
  yield data_line["id"], data_line
 
31
  _HOMEPAGE = "http://clip.ipipan.waw.pl/NationalCorpusOfPolish"
32
 
33
  _POS_TAGS = {
34
+ "adj",
35
+ "adja",
36
+ "adjc",
37
+ "adjp",
38
+ "adv",
39
+ "aglt",
40
+ "bedzie",
41
+ "brev",
42
+ "burk",
43
+ "comp",
44
+ "conj",
45
+ "depr",
46
+ "fin",
47
+ "ger",
48
+ "imps",
49
+ "impt",
50
+ "inf",
51
+ "interj",
52
+ "interp",
53
+ "num",
54
+ "numcol",
55
+ "pact",
56
+ "pant",
57
+ "pcon",
58
+ "ppas",
59
+ "ppron12",
60
+ "ppron3",
61
+ "praet",
62
+ "pred",
63
+ "prep",
64
+ "qub",
65
+ "siebie",
66
+ "subst",
67
+ "winien",
68
+ "xxx",
69
  }
70
 
71
 
 
79
  {
80
  "id": datasets.Value("string"),
81
  "tokens": datasets.Sequence(datasets.Value("string")),
82
+ "pos_tags": datasets.Sequence(
83
+ datasets.features.ClassLabel(
84
+ names=list(_POS_TAGS), num_classes=len(_POS_TAGS)
85
+ )
86
+ ),
87
  }
88
  ),
89
  homepage=_HOMEPAGE,
 
91
  )
92
 
93
  def _split_generators(
94
+ self, dl_manager: datasets.DownloadManager
95
  ) -> List[datasets.SplitGenerator]:
96
  urls_to_download = _URLS
97
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
 
120
  return data_line
121
 
122
  def _generate_examples(
123
+ self, filepath: str
124
  ) -> Generator[Tuple[str, Dict[str, str]], None, None]:
125
+ with open(filepath, "r", encoding="utf-8") as f:
126
  for line in f:
127
  data_line = self._clean_line(json.loads(line))
128
  yield data_line["id"], data_line