edsnlp.pipelines.misc.measures
patterns
CompositeSize
Bases: CompositeMeasure
Composite size measure. Supports the following units: - mm - cm - dm - m
Source code in edsnlp/pipelines/misc/measures/patterns.py
11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
mm = property(make_multi_getter('mm'))
class-attribute
cm = property(make_multi_getter('cm'))
class-attribute
dm = property(make_multi_getter('dm'))
class-attribute
m = property(make_multi_getter('m'))
class-attribute
Size
Bases: SimpleMeasure
Size measure. Supports the following units: - mm - cm - dm - m
Source code in edsnlp/pipelines/misc/measures/patterns.py
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 |
|
COMPOSITE = CompositeSize
class-attribute
UNITS = {'mm': {'prefix': 'mill?im', 'abbr': 'mm', 'value': 1}, 'cm': {'prefix': 'centim', 'abbr': 'cm', 'value': 10}, 'dm': {'prefix': 'decim', 'abbr': 'dm', 'value': 100}, 'm': {'prefix': 'metre', 'abbr': 'm', 'value': 1000}}
class-attribute
mm = property(make_simple_getter('mm'))
class-attribute
cm = property(make_simple_getter('cm'))
class-attribute
dm = property(make_simple_getter('dm'))
class-attribute
m = property(make_simple_getter('m'))
class-attribute
parse(int_part, dec_part, unit, infix=False)
Source code in edsnlp/pipelines/misc/measures/patterns.py
44 45 46 47 |
|
Weight
Bases: SimpleMeasure
Weight measure. Supports the following units: - mg - cg - dg - g - kg
Source code in edsnlp/pipelines/misc/measures/patterns.py
55 56 57 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 |
|
COMPOSITE = None
class-attribute
UNITS = {'mg': {'prefix': 'mill?ig', 'abbr': 'mg', 'value': 1}, 'cg': {'prefix': 'centig', 'abbr': 'cg', 'value': 10}, 'dg': {'prefix': 'decig', 'abbr': 'dg', 'value': 100}, 'g': {'prefix': 'gram', 'abbr': 'g', 'value': 1000}, 'kg': {'prefix': 'kilo', 'abbr': 'kg', 'value': 1000000}}
class-attribute
mg = property(make_simple_getter('mg'))
class-attribute
cg = property(make_simple_getter('cg'))
class-attribute
dg = property(make_simple_getter('dg'))
class-attribute
g = property(make_simple_getter('g'))
class-attribute
kg = property(make_simple_getter('kg'))
class-attribute
parse(int_part, dec_part, unit, infix=False)
Source code in edsnlp/pipelines/misc/measures/patterns.py
75 76 77 78 |
|
Angle
Bases: SimpleMeasure
Angle measure. Supports the following units: - h
Source code in edsnlp/pipelines/misc/measures/patterns.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
COMPOSITE = None
class-attribute
UNITS = {'h': {'prefix': 'heur', 'abbr': 'h', 'value': 1}}
class-attribute
h = property(make_simple_getter('h'))
class-attribute
parse(int_part, dec_part, unit, infix=False)
Source code in edsnlp/pipelines/misc/measures/patterns.py
99 100 101 102 103 104 105 |
|
factory
DEFAULT_CONFIG = dict(attr='NORM', ignore_excluded=False, measures=['eds.measures.size', 'eds.measures.weight', 'eds.measures.angle'])
module-attribute
create_component(nlp, name, measures, attr, ignore_excluded)
Source code in edsnlp/pipelines/misc/measures/factory.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
measures
Measure
Bases: abc.ABC
Source code in edsnlp/pipelines/misc/measures/measures.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
INTEGER = '(?:[0-9]+)'
class-attribute
CONJUNCTIONS = 'et|ou'
class-attribute
COMPOSERS = '[x*]|par'
class-attribute
UNITS = {}
class-attribute
COMPOSITE = None
class-attribute
__iter__()
Iter over items of the measure (only one for SimpleMeasure)
RETURNS | DESCRIPTION |
---|---|
iterable
|
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
131 132 133 134 135 136 137 138 139 |
|
__getitem__(item)
Access items of the measure (only one for SimpleMeasure)
PARAMETER | DESCRIPTION |
---|---|
item |
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
measure
|
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
SimpleMeasure
Bases: Measure
Source code in edsnlp/pipelines/misc/measures/measures.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
value = value
instance-attribute
unit = unit
instance-attribute
__init__(value, unit)
The SimpleMeasure class contains the value and unit for a single non-composite measure
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE:
|
unit |
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
parse(int_part, dec_part, unit, infix)
Class method to create an instance from the match groups
int_part : str The integer part of the match (eg 12 in 12 metres 50 or 12.50metres) dec_part : str The decimal part of the match (eg 50 in 12 metres 50 or 12.50metres) unit : str The normalized variant of the unit (eg "m" for 12 metre 50) infix : bool Whether the unit was in the before (True) or after (False) the decimal part
Source code in edsnlp/pipelines/misc/measures/measures.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
_get_scale_to(unit)
Source code in edsnlp/pipelines/misc/measures/measures.py
189 190 |
|
__iter__()
Source code in edsnlp/pipelines/misc/measures/measures.py
192 193 |
|
__getitem__(item)
Source code in edsnlp/pipelines/misc/measures/measures.py
195 196 197 |
|
__str__()
Source code in edsnlp/pipelines/misc/measures/measures.py
199 200 |
|
__repr__()
Source code in edsnlp/pipelines/misc/measures/measures.py
202 203 |
|
__eq__(other)
Source code in edsnlp/pipelines/misc/measures/measures.py
205 206 |
|
__lt__(other)
Source code in edsnlp/pipelines/misc/measures/measures.py
208 209 |
|
__le__(other)
Source code in edsnlp/pipelines/misc/measures/measures.py
211 212 |
|
CompositeMeasure
Bases: Measure
The CompositeMeasure class contains a sequence of multiple SimpleMeasure instances
PARAMETER | DESCRIPTION |
---|---|
measures |
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
measures = list(measures)
instance-attribute
__init__(measures)
Source code in edsnlp/pipelines/misc/measures/measures.py
225 226 227 |
|
__iter__()
Source code in edsnlp/pipelines/misc/measures/measures.py
229 230 |
|
__getitem__(item)
Source code in edsnlp/pipelines/misc/measures/measures.py
232 233 234 235 |
|
__str__()
Source code in edsnlp/pipelines/misc/measures/measures.py
237 238 |
|
__repr__()
Source code in edsnlp/pipelines/misc/measures/measures.py
240 241 |
|
Measures
Bases: BaseComponent
Matcher component to extract measures. A measures is most often composed of a number and a unit like
1,26 cm The unit can also be positioned in place of the decimal dot/comma 1 cm 26 Some measures can be composite 1,26 cm x 2,34 mm And sometimes they are factorized Les trois kystes mesurent 1, 2 et 3cm.
The recognized measures are stored in the "measures" SpanGroup.
Each span has a Measure
object stored in the "value" extension attribute.
PARAMETER | DESCRIPTION |
---|---|
nlp |
The SpaCy object.
TYPE:
|
measures |
The registry names of the measures to extract
TYPE:
|
attr |
Whether to match on the text ('TEXT') or on the normalized text ('NORM')
TYPE:
|
ignore_excluded |
Whether to exclude pollution patterns when matching in the text
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
regex_matcher = RegexMatcher(attr=attr, ignore_excluded=ignore_excluded)
instance-attribute
extraction_regexes = {}
instance-attribute
measures: Dict[str, Measure] = {}
instance-attribute
__init__(nlp, measures, attr, ignore_excluded)
Source code in edsnlp/pipelines/misc/measures/measures.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
set_extensions()
Source code in edsnlp/pipelines/misc/measures/measures.py
295 296 297 298 299 |
|
__call__(doc)
Adds measures to document's "measures" SpanGroup.
PARAMETER | DESCRIPTION |
---|---|
doc |
spaCy Doc object
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
doc
|
spaCy Doc object, annotated for extracted terms. |
Source code in edsnlp/pipelines/misc/measures/measures.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
disj_capture(regexes, capture=True)
Source code in edsnlp/pipelines/misc/measures/measures.py
14 15 16 17 18 19 20 |
|
rightmost_largest_sort_key(span)
Source code in edsnlp/pipelines/misc/measures/measures.py
23 24 |
|
make_patterns(measure)
Build recognition and extraction patterns for a given Measure class
PARAMETER | DESCRIPTION |
---|---|
measure |
The measure to build recognition and extraction patterns for
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
trigger
|
TYPE:
|
extraction
|
TYPE:
|
Source code in edsnlp/pipelines/misc/measures/measures.py
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
make_simple_getter(name)
Source code in edsnlp/pipelines/misc/measures/measures.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
make_multi_getter(name)
Source code in edsnlp/pipelines/misc/measures/measures.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|