|
2 | 2 | Structures and operations for quantifier scope in DELPH-IN semantics. |
3 | 3 | """ |
4 | 4 |
|
5 | | -from typing import Dict, Iterable, List, Mapping, Optional, Tuple |
| 5 | +from typing import Iterable, Mapping, Optional |
6 | 6 |
|
7 | 7 | # Default modules need to import the PyDelphin version |
8 | 8 | from delphin.__about__ import __version__ # noqa: F401 |
|
29 | 29 | ScopeLabel = str |
30 | 30 | ScopeRelation = str |
31 | 31 | ScopeMap = Mapping[ScopeLabel, Predications] |
32 | | -DescendantMap = Mapping[Identifier, List[Predication]] |
33 | | -ScopalRoleArgument = Tuple[Role, ScopeRelation, Identifier] |
34 | | -ScopalArgumentStructure = Mapping[Identifier, List[ScopalRoleArgument]] |
| 32 | +DescendantMap = Mapping[Identifier, list[Predication]] |
| 33 | +ScopalRoleArgument = tuple[Role, ScopeRelation, Identifier] |
| 34 | +ScopalArgumentStructure = Mapping[Identifier, list[ScopalRoleArgument]] |
35 | 35 | # Regarding literal types, see: https://www.python.org/dev/peps/pep-0563/ |
36 | | -ScopeEqualities = Iterable[Tuple[ScopeLabel, ScopeLabel]] |
| 36 | +ScopeEqualities = Iterable[tuple[ScopeLabel, ScopeLabel]] |
37 | 37 |
|
38 | 38 |
|
39 | 39 | # Exceptions |
@@ -87,7 +87,7 @@ def scopal_arguments(self, scopes=None) -> ScopalArgumentStructure: |
87 | 87 | """ |
88 | 88 | raise NotImplementedError() |
89 | 89 |
|
90 | | - def scopes(self) -> Tuple[ScopeLabel, ScopeMap]: |
| 90 | + def scopes(self) -> tuple[ScopeLabel, ScopeMap]: |
91 | 91 | """ |
92 | 92 | Return a tuple containing the top label and the scope map. |
93 | 93 |
|
@@ -117,7 +117,7 @@ def conjoin(scopes: ScopeMap, leqs: ScopeEqualities) -> ScopeMap: |
117 | 117 | >>> {lbl: [p.id for p in ps] for lbl, ps in conjoined.items()} |
118 | 118 | {'h1': ['e2'], 'h2': ['x4', 'e6']} |
119 | 119 | """ |
120 | | - scopemap: Dict[ScopeLabel, List[Predication]] = {} |
| 120 | + scopemap: dict[ScopeLabel, list[Predication]] = {} |
121 | 121 | for component in _connected_components(list(scopes), leqs): |
122 | 122 | chosen_label = next(iter(component)) |
123 | 123 | scopemap[chosen_label] = [] |
@@ -155,13 +155,13 @@ def descendants(x: ScopingSemanticStructure, |
155 | 155 | if scopes is None: |
156 | 156 | _, scopes = x.scopes() |
157 | 157 | scargs = x.scopal_arguments(scopes=scopes) |
158 | | - descs: Dict[Identifier, List[Predication]] = {} |
| 158 | + descs: dict[Identifier, list[Predication]] = {} |
159 | 159 | for p in x.predications: |
160 | 160 | _descendants(descs, p.id, scargs, scopes) |
161 | 161 | return descs |
162 | 162 |
|
163 | 163 |
|
164 | | -def _descendants(descs: Dict[Identifier, List[Predication]], |
| 164 | +def _descendants(descs: dict[Identifier, list[Predication]], |
165 | 165 | id: Identifier, |
166 | 166 | scargs: ScopalArgumentStructure, |
167 | 167 | scopes: ScopeMap) -> None: |
@@ -203,7 +203,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap: |
203 | 203 |
|
204 | 204 | 3. Prefer tensed over untensed eventualities |
205 | 205 |
|
206 | | - 4. Finally, prefer prefer those appearing first in *x* |
| 206 | + 4. Finally, prefer those appearing first in *x* |
207 | 207 |
|
208 | 208 | The definition of "tensed" vs "untensed" eventualities is |
209 | 209 | grammar-specific, but it is used by several large grammars. If a |
@@ -233,7 +233,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap: |
233 | 233 | descs = {id: set(d.id for d in ds) |
234 | 234 | for id, ds in descendants(x, scopes).items()} |
235 | 235 |
|
236 | | - reps: Dict[ScopeLabel, List[Predication]] = { |
| 236 | + reps: dict[ScopeLabel, list[Predication]] = { |
237 | 237 | label: [] for label in scopes |
238 | 238 | } |
239 | 239 | for label, scope in scopes.items(): |
|
0 commit comments