-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
60 lines (43 loc) · 1.45 KB
/
Copy pathtest.py
File metadata and controls
60 lines (43 loc) · 1.45 KB
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
60
from dataclasses import dataclass
from typing import Dict, Sequence, Type, TypeVar, cast
Properties=Dict[str,str]
#@define(frozen=True)
@dataclass
class LingUnit(): #ABC
properties: Properties
#@property
def get_properties(self) -> Properties:
return self.properties
#@define(frozen=True)
@dataclass
class NonTerminalLingUnit(LingUnit):
sub_units: Sequence[LingUnit]
#@property
#@abstractmethod
def get_sub_units(self) -> Sequence[LingUnit]:
return self.sub_units
#@define(frozen=True)
@dataclass
class Morph(LingUnit):
pass
#@define(frozen=True)
@dataclass
class Word(NonTerminalLingUnit):
pass
#def __init__(cls, properties: Properties, sub_units: Sequence[Morph]):
# super().__init__(properties, sub_units)
#sub_units: Sequence[Morph]
@dataclass
class UnitFactory():
def createMorph(self, properties: Properties) -> Morph:
return Morph(properties)
def createNonTerminalUnit(self, level: Type[NonTerminalLingUnit], properties: Properties, sub_units: Sequence[LingUnit]) -> NonTerminalLingUnit:
return level(properties, sub_units)
def createWord(self, properties: Properties, morphs: Sequence[Morph]) -> NonTerminalLingUnit:
w = self.createNonTerminalUnit(Word, properties, morphs)
return cast(Word, w)
f = UnitFactory()
w = f.createWord({'foo': 'bar'}, [Morph({'x':'1'}), Morph({'y': '2'})])
print(type(w))
print(w.get_properties()['foo'])
print(w.get_sub_units())