Kevin99z commited on
Commit
01fea5b
·
1 Parent(s): 0b33a10
Files changed (2) hide show
  1. inspired_unicrs.py +17 -2
  2. utils.py +0 -16
inspired_unicrs.py CHANGED
@@ -1,8 +1,23 @@
1
  import json
2
  from typing import List
3
  import datasets
4
- from .utils import markup_entity
5
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  logger = datasets.logging.get_logger(__name__)
8
 
 
1
  import json
2
  from typing import List
3
  import datasets
4
+ import re
5
+
6
+ ENTITY = 'entity'
7
+ ENTITY_PATTERN = r'<entity> {} </entity>'
8
+
9
+
10
+ def markup_entity(utt: str, entities: List[str]):
11
+ # If entities like "action movie" and "action" appear at the same time, we only mark the longer one
12
+ entities = sorted(list(set(entities)), key=lambda x: len(x), reverse=True)
13
+ for i, entity in enumerate(entities):
14
+ valid = entity not in ENTITY
15
+ for prev in entities[:i]:
16
+ if entity in prev:
17
+ valid = False
18
+ if valid:
19
+ utt = re.sub(entity, ENTITY_PATTERN.format(entity), utt)
20
+ return utt
21
 
22
  logger = datasets.logging.get_logger(__name__)
23
 
utils.py CHANGED
@@ -5,22 +5,6 @@ from typing import List
5
  from datasets import load_dataset, Value, Sequence
6
  import json
7
 
8
- ENTITY = 'entity'
9
- ENTITY_PATTERN = r'<entity> (.*?) </entity>'
10
-
11
-
12
- def markup_entity(utt: str, entities: List[str]):
13
- # If entities like "action movie" and "action" appear at the same time, we only mark the longer one
14
- entities = sorted(list(set(entities)), key=lambda x: len(x), reverse=True)
15
- for i, entity in enumerate(entities):
16
- valid = entity not in ENTITY
17
- for prev in entities[:i]:
18
- if entity in prev:
19
- valid = False
20
- if valid:
21
- utt = re.sub(entity, ENTITY_PATTERN.format(entity), utt)
22
- return utt
23
-
24
  def print_dataset_info(dataset):
25
  # Print the features
26
  print("features:")
 
5
  from datasets import load_dataset, Value, Sequence
6
  import json
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def print_dataset_info(dataset):
9
  # Print the features
10
  print("features:")