-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightParser.py
29 lines (23 loc) · 871 Bytes
/
LightParser.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
import re
from typing import Literal
LightType = Literal["moderate", "shade", "half shade", "direct sun", "diffuse", "any"]
class LightParser:
def __init__(self, light_description: str) -> None:
match = re.search(r'.*[Ll]ikes? ([\w\s]+)(,|$)', light_description)
desc_to_light_type = {
"moderate sunshine": "moderate",
"light": "direct sun",
"sunshine": "direct sun",
"half shade": "half shade",
"half shade environment": "half shade",
"half shade environments": "half shade",
"scattered": "diffuse",
}
if not match:
self.__light = desc_to_light_type["light"]
else:
desc, _ = match.groups()
self.__light = desc_to_light_type[desc]
@property
def light(self) -> str:
return self.__light