olski.morph¶
Morphology, over Morfeusz 2.
Morfeusz answers two questions olski needs and a regular expression cannot: what are this form's possible readings, and what are the features of each. It also segments, and it segments into a graph rather than a list, because Polish does not always agree with itself about where one word ends.
What matters about the output, more than the API:
A form usually has several readings. ustawienia is the genitive singular
or nominative plural of the noun ustawienie, and also two forms of the
gerund of ustawić. Nothing here picks between them. Choosing is the parser's
job, and where the parser cannot choose either, the ambiguity is the answer.
A tag is a set of feature values, not a string. subst:sg:nom.acc:m3 says
singular, nominative or accusative, inanimate masculine. The dot is a
disjunction, so a feature holds a set and agreement is set intersection. That is
what makes unification the right operation later.
VALUES = {}
module-attribute
¶
UNKNOWN = 'ign'
module-attribute
¶
Tag
dataclass
¶
A part of speech and its features, each feature holding a set of values.
Source code in olski/morph.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
pos
instance-attribute
¶
features = frozenset()
class-attribute
instance-attribute
¶
raw = ''
class-attribute
instance-attribute
¶
cechy
cached
property
¶
Te same cechy w postaci, o którą pyta unifikacja.
Zbiorem są dlatego, że tag ma się haszować,
a bierze w olski/grammar.py czyta je słownikiem.
Przeliczenie jednego na drugie jest zapamiętane,
bo nad jedną formą pyta o nie każdy sprawdzany terminal.
known
property
¶
__init__(pos, features=frozenset(), raw='')
¶
get(feature)
¶
Return the values of a feature, or the empty set if it has none.
Source code in olski/morph.py
81 82 83 | |
has(feature, value)
¶
Source code in olski/morph.py
85 86 | |
__str__()
¶
Source code in olski/morph.py
88 89 | |
Reading
dataclass
¶
One way of reading a form: its lemma and its tag.
Source code in olski/morph.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
form
instance-attribute
¶
lemma
instance-attribute
¶
tag
instance-attribute
¶
kwalifikatory = ()
class-attribute
instance-attribute
¶
__init__(form, lemma, tag, kwalifikatory=())
¶
__str__()
¶
Source code in olski/morph.py
105 106 | |
Segment
dataclass
¶
An edge of the segmentation graph, with every reading of its form.
start and end are node numbers in that graph. A text whose
segmentation is unambiguous — most of them — produces edges where each
end is the next start, and then the graph is a chain.
They are positions in the graph and not offsets into the text, so nothing
here can say where in a file a form was found. Morfeusz emits the gaps as
sp edges under KEEP_WHITESPACES, which is what walking a path and
summing form lengths would need; this asks for SKIP_WHITESPACES because
the parser wants words.
Source code in olski/morph.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
start
instance-attribute
¶
end
instance-attribute
¶
form
instance-attribute
¶
readings
instance-attribute
¶
lematy
property
¶
Słowa, którymi ta forma bywa; pyta o nie bez_lematu_formy.
known
property
¶
__init__(start, end, form, readings)
¶
with_pos(pos)
¶
Source code in olski/morph.py
138 139 | |
tag(raw)
cached
¶
Parse a Morfeusz tag string into a part of speech and its features.
Memoized on the raw string: the question is asked once per reading of every
form, and the tagset has a few hundred distinct tags. A Tag is immutable,
so one answer serves every caller.
Source code in olski/morph.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
generuj(lemat)
¶
Wszystko, co słownik odmienia pod tym lematem, tak jak on to wydaje.
Krotka niesie formę, identyfikator leksemu, tag surowy, nazwy i kwalifikatory, a pytający czytają z niej różne pola — kwalifikator czyta sama synteza — więc nie wychodzi stąd ani jedno pole odjęte. Leksemów wychodzi tyle, ile słownik trzyma pod tym napisem, bo wybór między nimi jest wyborem autora, a nie tego modułu.
Source code in olski/morph.py
194 195 196 197 198 199 200 201 202 203 | |
analyse(text)
¶
Segment and analyse text, returning the edges of its segmentation graph.
Source code in olski/morph.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
unknown(segments)
¶
Return the segments Morfeusz could not recognize at all.
Source code in olski/morph.py
226 227 228 | |