-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
59 lines (51 loc) · 1.89 KB
/
models.py
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
50
51
52
53
54
55
56
57
58
59
import re
from enum import Enum, unique
from typing import List
@unique
class Intent(Enum):
O = "/O"
Person = "PER"
Room = "ROOM"
Building = "BUILD"
Floor = "FLOOR"
Ordinal = "ORD"
Cardinal = "CAR"
Date = "DATE"
Time = "TIME"
Money = "MONEY"
Event = "EVE"
Announcement = "ANN"
CountryCity = "GPE"
Location = "LOC"
Organization = "ORG"
def convert(words: List[str], intent: Intent = None, segment: bool = True):
match intent:
case Intent.O:
if segment:
return [x.replace(" ", intent.value + " ").replace("?", "?" + intent.value) for x in words]
return [x.replace(" ", "") for x in words]
case _:
if segment:
# # Long version
# rose = []
# rise = []
# for i in words:
# rose = i.strip()
# rose += " "
# rise.append(rose)
# print("|" + rose + "|")
# for j in rise:
# ree = j.replace(" ", "/B-PER ")
# if ree.count(" ")>2:
# roo = re.sub(r"/B-PER $", "/I-PER ", ree)
# list.append(roo)
# Short Version
intent = intent.value
ree = [x.strip() + " " for x in words]
row = [re.sub(r"/B-{} $".format(intent), "/I-{} ".format(intent),
x.replace(" ", "/B-{} ".format(intent))) if x.count(" ") >= 2 else x.replace(" ",
"/B-{} ".format(
intent))
for x in ree]
return row
return words