vesteinn commited on
Commit
86836ad
1 Parent(s): 9a8750d

Moved to B-I format

Browse files
Files changed (1) hide show
  1. swe-nerc.py +29 -9
swe-nerc.py CHANGED
@@ -19,15 +19,24 @@
19
 
20
 
21
  LABELS = [
22
- "EVN",
23
- "GRO",
24
- "LOC",
25
- "MNT",
26
  "O",
27
- "PRS",
28
- "SMP",
29
- "TME",
30
- "WRK"
 
 
 
 
 
 
 
 
 
31
  ]
32
 
33
 
@@ -108,6 +117,7 @@ class SweNERC(datasets.GeneratorBasedBuilder):
108
  guid = 0
109
  tokens = []
110
  ner_tags = []
 
111
  for line in f:
112
  if line.startswith("-DOCSTART-") or line == "" or line == "\n":
113
  if tokens:
@@ -119,15 +129,25 @@ class SweNERC(datasets.GeneratorBasedBuilder):
119
  guid += 1
120
  tokens = []
121
  ner_tags = []
 
122
  else:
123
  # tokens are tab separated
124
  splits = line.split("\t")
125
  tokens.append(splits[0])
126
  try:
127
- ner_tags.append(splits[1].rstrip())
 
 
 
 
 
 
 
 
128
  except:
129
  print(splits)
130
  raise
 
131
  # last example
132
  yield guid, {
133
  "id": str(guid),
 
19
 
20
 
21
  LABELS = [
22
+ "B-EVN",
23
+ "B-GRO",
24
+ "B-LOC",
25
+ "B-MNT",
26
  "O",
27
+ "B-PRS",
28
+ "B-SMP",
29
+ "B-TME",
30
+ "B-WRK",
31
+ "I-EVN",
32
+ "I-GRO",
33
+ "I-LOC",
34
+ "I-MNT",
35
+ "O",
36
+ "I-PRS",
37
+ "I-SMP",
38
+ "I-TME",
39
+ "I-WRK"
40
  ]
41
 
42
 
 
117
  guid = 0
118
  tokens = []
119
  ner_tags = []
120
+ last_tag = None
121
  for line in f:
122
  if line.startswith("-DOCSTART-") or line == "" or line == "\n":
123
  if tokens:
 
129
  guid += 1
130
  tokens = []
131
  ner_tags = []
132
+ last_tag = None
133
  else:
134
  # tokens are tab separated
135
  splits = line.split("\t")
136
  tokens.append(splits[0])
137
  try:
138
+ tag = splits[1].rstrip()
139
+ if tag == "O":
140
+ pass
141
+ elif tag == last_tag:
142
+ tag = "I-" + tag
143
+ else:
144
+ tag = "B-" + tag
145
+ ner_tags.append(tag)
146
+ last_tag = splits[1].rstrip()
147
  except:
148
  print(splits)
149
  raise
150
+
151
  # last example
152
  yield guid, {
153
  "id": str(guid),