medspacy.context
ConText
The ConText for spaCy processing.
This component matches modifiers in a Doc, defines their scope, and identifies edges between targets and modifiers. Sets two spaCy extensions: - Span..modifiers: a list of ConTextModifier objects which modify a target Span - Doc..context_graph: a ConText graph object which contains the targets, modifiers, and edges between them.
Source code in medspacy/context/context.py
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 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 140 141 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 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 213 214 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 242 243 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 | |
categories
property
Returns list of categories available that Context might produce.
input_span_type
property
writable
The input source of entities for the component. Must be either "ents" corresponding to doc.ents or "group" for a spaCy span group.
Returns:
| Type | Description |
|---|---|
|
The input type, "ents" or "group". |
rules
property
Returns list of ConTextRules available to context.
span_group_name
property
writable
The name of the span group used by this component. If input_type is "group", calling this component will
use spans in the span group with this name.
Returns:
| Type | Description |
|---|---|
str
|
The span group name. |
__call__(doc, targets=None)
Applies the ConText algorithm to a Doc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
The spaCy Doc to process. |
required | |
targets
|
str
|
The optional custom attribute extension on doc to run over. Must contain an iterable of Span objects |
None
|
Returns:
| Type | Description |
|---|---|
Doc
|
The processed spaCy Doc. |
Source code in medspacy/context/context.py
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 | |
__init__(nlp, name='medspacy_context', rules='default', language_code='en', phrase_matcher_attr='LOWER', allowed_types=None, excluded_types=None, terminating_types=None, max_scope=None, max_targets=None, prune_on_modifier_overlap=True, prune_on_target_overlap=False, span_attrs='default', input_span_type='ents', span_group_name='medspacy_spans')
Creates a new ConText object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nlp
|
Language
|
A SpaCy Language object. |
required |
name
|
str
|
The name of the component. |
'medspacy_context'
|
rules
|
Optional[str]
|
The rules to load. Default is "default", loads rules packaged with medspaCy that are derived from
original ConText rules and years of practical applications at the US Department of Veterans Affairs. If
None, no rules are loaded. Otherwise, must be a path to a json file containing rules. Add ConTextRules
directly through |
'default'
|
language_code
|
str
|
Language code to use (ISO code) as a default for loading resources. See documentation and also the /resources directory to see which resources might be available in each language. Default is "en" for English. |
'en'
|
phrase_matcher_attr
|
str
|
The token attribute to use for PhraseMatcher for rules where |
'LOWER'
|
allowed_types
|
Optional[Set[str]]
|
A global list of types included by context. Rules will operate on only spans with these labels. |
None
|
excluded_types
|
Optional[Set[str]]
|
A global list of types excluded by context. Rules will not operate on spans with these labels. |
None
|
terminating_types
|
Optional[Dict[str, Iterable[str]]]
|
A global map of types to the types that can terminate them. This can be used to apply terminations to all rules of a particular type rather than adding to every rule individually in the ContextRule object. |
None
|
max_scope
|
Optional[int]
|
The number of tokens around a modifier in a target can be modified. Default value is None, Context will use the sentence boundaries. If a value greater than zero, applies the window globally. Both options will be overridden by a more specific value in a ContextRule. |
None
|
max_targets
|
Optional[int]
|
The maximum number of targets a modifier can modify. Default value is None, context will modify all targets in its scope. If a value greater than zero, applies this value globally. Both options will be overridden by a more specific value in a ContextRule. |
None
|
prune_on_modifier_overlap
|
bool
|
Whether to prune modifiers which are substrings of another modifier. If True, will drop substrings completely. For example, if "no history of" and "history of" are both ConTextRules,both will match the text "no history of afib", but only "no history of" should modify afib. Default True. |
True
|
prune_on_target_overlap
|
bool
|
Whether to remove any matched modifiers which overlap with target entities. If False, any overlapping modifiers will not modify the overlapping entity but will still modify any other targets in its scope. Default False. |
False
|
span_attrs
|
Union[Literal['default'], Dict[str, Dict[str, Any]], None]
|
The optional span attributes to modify. Default option "default" uses attributes in
|
'default'
|
input_span_type
|
Union[Literal['ents', 'group']]
|
"ents" or "group". Where to look for targets. "ents" will modify attributes of spans
in doc.ents. "group" will modify attributes of spans in the span group specified by |
'ents'
|
span_group_name
|
str
|
The name of the span group used when |
'medspacy_spans'
|
Source code in medspacy/context/context.py
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
add(rules)
Adds ConTextRules to Context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rules
|
A single ConTextRule or a collection of ConTextRules to add to the Sectionizer. |
required |
Source code in medspacy/context/context.py
209 210 211 212 213 214 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 242 243 | |
register_default_attributes()
classmethod
Registers the default values for the Span attributes defined in DEFAULT_ATTRIBUTES.
Source code in medspacy/context/context.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
register_graph_attributes()
classmethod
Registers spaCy attribute extensions: Span..modifiers and Doc..context_graph.
Source code in medspacy/context/context.py
245 246 247 248 249 250 251 252 253 254 | |
set_context_attributes(edges)
Adds Span-level attributes to targets with modifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
The edges of the ContextGraph to modify. |
required |
Source code in medspacy/context/context.py
273 274 275 276 277 278 279 280 281 282 283 284 | |
ConTextGraph
The ConTextGraph class defines the internal structure of the ConText algorithm. It stores a collection of modifiers, matched with ConTextRules, and targets from some other source such as the TargetMatcher or a spaCy NER model.
Each modifier can have some number of associated targets that it modifies. This relationship is stored as edges of of the graph.
Source code in medspacy/context/context_graph.py
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 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__init__(targets=None, modifiers=None, edges=None, prune_on_modifier_overlap=False)
Creates a new ConTextGraph object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
Optional[List[Span]]
|
A spans that context might modify. |
None
|
modifiers
|
Optional[List[ConTextModifier]]
|
A list of ConTextModifiers that might modify the targets. |
None
|
edges
|
Optional[List]
|
A list of edges between targets and modifiers representing the modification relationship. |
None
|
prune_on_modifier_overlap
|
bool
|
Whether to prune modifiers when one modifier completely covers another. |
False
|
Source code in medspacy/context/context_graph.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
apply_modifiers()
Checks each target/modifier pair. If modifier modifies target, create an edge between them.
Source code in medspacy/context/context_graph.py
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 | |
from_serialized_representation(serialized_representation)
classmethod
Creates the ConTextGraph from the serialized representation
Source code in medspacy/context/context_graph.py
98 99 100 101 102 103 104 105 | |
serialized_representation()
Returns the serialized representation of the ConTextGraph
Source code in medspacy/context/context_graph.py
92 93 94 95 96 | |
update_scopes()
Update the scope of all ConTextModifier.
For each modifier in a list of ConTextModifiers, check against each other modifier to see if one of the modifiers should update the other. This allows neighboring similar modifiers to extend each other's scope and allows "terminate" modifiers to end a modifier's scope.
Source code in medspacy/context/context_graph.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
ConTextModifier
Represents a concept found by ConText in a document. An instance of this class is the result of ConTextRule matching text in a Doc.
Source code in medspacy/context/context_modifier.py
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 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 140 141 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 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 213 214 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 242 243 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
allowed_types
property
Returns the associated allowed types.
category
property
Returns the associated category.
direction
property
Returns the associated direction.
excluded_types
property
Returns the associated excluded types.
max_scope
property
Returns the associated maximum scope.
max_targets
property
Returns the associated maximum number of targets.
modifier_span
property
The spaCy Span object, which is a view of self.doc, covered by this match.
num_targets
property
Returns the associated number of targets.
rule
property
Returns the associated context rule.
scope_span
property
Returns the associated scope.
__init__(context_rule, start, end, doc, scope_start=None, scope_end=None, max_scope=None)
Create a new ConTextModifier from a document span. Each modifier represents a span in the text and a surrounding window. Spans such as entities or other members of span groups that occur within this window can be modified by this ConTextModifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_rule
|
ConTextRule
|
The ConTextRule object which defines the modifier. |
required |
start
|
int
|
The start token index. |
required |
end
|
int
|
The end token index (non-inclusive). |
required |
doc
|
Doc
|
The spaCy Doc which contains this span. This is needed to initialize the modifier but is not maintained. |
required |
scope_start
|
Optional[int]
|
The start token index of the scope. |
None
|
scope_end
|
Optional[int]
|
The end index of the scope. |
None
|
max_scope
|
Optional[int]
|
Whether to use scope values rather than sentence boundaries for modifications. |
None
|
Source code in medspacy/context/context_modifier.py
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 | |
__set_scope(doc)
Applies the direction of the ConTextRule which generated this ConTextModifier to define a scope. If self._max_scope is None, then the default scope is the sentence which it occurs in whichever direction defined by self.direction. For example, if the direction is "forward", the scope will be [self.end: sentence.end]. If the direction is "backward", it will be [self.start: sentence.start].
If self.max_scope is not None and the length of the default scope is longer than self.max_scope, it will be reduced to self.max_scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Doc
|
The spaCy doc to use to set scope. |
required |
Source code in medspacy/context/context_modifier.py
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 154 155 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 | |
allows(target_label)
Returns whether if a modifier is able to modify a target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_label
|
str
|
The target type to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the modifier is allowed to modify a target of the specified type. True if |
bool
|
|
Source code in medspacy/context/context_modifier.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
from_serialized_representation(serialized_representation)
classmethod
Instantiates the class from the serialized representation
Source code in medspacy/context/context_modifier.py
379 380 381 382 383 384 385 386 387 388 389 390 391 | |
limit_scope(other)
If self and other have the same category or if other has a directionality of 'terminate', use the span of other to update the scope of self. Limiting the scope of two modifiers of the same category reduces the number of modifiers. For example, in 'no evidence of CHF, no pneumonia', 'pneumonia' will only be modified by 'no', not 'no evidence of'. 'terminate' modifiers limit the scope of a modifier like 'no evidence of' in 'no evidence of CHF, but there is pneumonia'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
ConTextModifier
|
The modifier to check against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the other modifier modified the scope of self. |
Source code in medspacy/context/context_modifier.py
203 204 205 206 207 208 209 210 211 212 213 214 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 242 243 244 245 | |
modifies(target)
Checks whether the target is within the modifier scope and if self is allowed to modify target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Span
|
a spaCy span representing a target concept. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the target is within |
Source code in medspacy/context/context_modifier.py
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 | |
modify(target)
Add target to the list of self._targets and increment self._num_targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Span
|
The spaCy span to add. |
required |
Source code in medspacy/context/context_modifier.py
321 322 323 324 325 326 327 328 329 | |
on_modifies(target)
If the ConTextRule used to define a ConTextModifier has an on_modifies callback function, evaluate and return
either True or False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Span
|
The spaCy span to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The result of the |
Source code in medspacy/context/context_modifier.py
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 | |
reduce_targets()
Reduces the number of targets to the n-closest targets based on the value of self.max_targets. If
self.max_targets is None, no pruning is done.
Source code in medspacy/context/context_modifier.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
serialized_representation()
Serialized Representation of the modifier
Source code in medspacy/context/context_modifier.py
365 366 367 368 369 370 371 372 373 374 375 376 377 | |
update_scope(span)
Changes the scope of self to be the given spaCy span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
a spaCy Span which contains the scope which a modifier should cover. |
required |
Source code in medspacy/context/context_modifier.py
193 194 195 196 197 198 199 200 201 | |
ConTextRule
Bases: BaseRule
A ConTextRule defines a ConText modifier. ConTextRules are rules which define which spans are extracted as modifiers and how they behave, such as the phrase to be matched, the category/semantic class, the direction of the modifier in the text, and what types of target spans can be modified.
Source code in medspacy/context/context_rule.py
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 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 140 141 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 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 213 214 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 242 | |
__init__(literal, category, pattern=None, direction='BIDIRECTIONAL', on_match=None, on_modifies=None, allowed_types=None, excluded_types=None, max_scope=None, max_targets=None, terminated_by=None, metadata=None)
Creates a ConTextRule object.
The primary arguments of literal category, and direction define the span of text to be matched, the
semantic category, and the direction within the sentence in which the modifier operates.
Other arguments specify additional custom logic such as:
- Additional control over what text can be matched as a modifier (pattern and on_match)
- Which types of targets can be modified (allowed_types, excluded_types)
- The scope size and number of targets that a modifier can modify (max_targets, max_scope)
- Other logic for terminating a span or for allowing a modifier to modify a target (on_modifies,
terminated_by)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
literal
|
str
|
The string representation of a concept. If |
required |
category
|
str
|
The semantic class of the matched span. This corresponds to the |
required |
pattern
|
Optional[Union[str, List[Dict[str, str]]]]
|
A list or string to use as a spaCy pattern rather than |
None
|
direction
|
str
|
The directionality or action of a modifier. This defines which part of a sentence a modifier will include as its scope. Entities within the scope will be considered to be modified. Valid values are: - "FORWARD": Scope will begin after the end of a modifier and move to the right - "BACKWARD": Scope will begin before the beginning of a modifier and move to the left - "BIDIRECTIONAL": Scope will expand on either side of a modifier - "TERMINATE": A special direction to limit any other modifiers if this phrase is in its scope. Example: "no evidence of chf but there is pneumonia": "but" will prevent "no evidence of" from modifying "pneumonia" - "PSEUDO": A special direction which will not modify any targets. This can be used for differentiating superstrings of modifiers. Example: A modifier with literal="negative attitude" will prevent the phrase "negative" in "She has a negative attitude about her treatment" from being extracted as a modifier. |
'BIDIRECTIONAL'
|
on_match
|
Optional[Callable[[Matcher, Doc, int, List[Tuple[int, int, int]]], Any]]
|
An optional callback function or other callable which takes 4 arguments: |
None
|
on_modifies
|
Optional[Callable[[Span, Span, Span], bool]]
|
Callback function to run when building an edge between a target and a modifier. This allows specifying custom logic for allowing or preventing certain modifiers from modifying certain targets. The callable should take 3 arguments: target: The spaCy Span from doc.ents (ie., 'Evidence of pneumonia') modifier: The spaCy Span covered in a resulting modifier (ie., 'no evidence of') span_between: The Span between the target and modifier in question. Should return either True or False. If returns False, then the modifier will not modify the target. |
None
|
allowed_types
|
Optional[Set[str]]
|
A collection of target labels to allow a modifier to modify. If None, will apply to any type not specifically excluded in excluded_types. Only one of allowed_types and excluded_types can be used. An error will be thrown if both are not None. |
None
|
excluded_types
|
Optional[Set[str]]
|
A collection of target labels which this modifier cannot modify. If None, will apply to all target types unless allowed_types is not None. |
None
|
max_scope
|
Optional[int]
|
A number of tokens to explicitly limit the size of the modifier's scope. If None, the scope will
include the entire sentence in the direction of |
None
|
max_targets
|
Optional[int]
|
The maximum number of targets which a modifier can modify. If None, will modify all targets in its scope. |
None
|
terminated_by
|
Optional[Set[str]]
|
An optional collection of other modifier categories which will terminate the scope of this modifier. If None, only "TERMINATE" will do this. Example: if a ConTextRule defining "positive for" has terminated_by={"NEGATED_EXISTENCE"}, then in the sentence "positive for flu, negative for RSV", the positive modifier will modify "flu" but will be terminated by "negative for" and will not modify "RSV". This helps prevent multiple conflicting modifiers from distributing too far across a sentence. |
None
|
metadata
|
Optional[Dict[Any, Any]]
|
Optional dictionary of any extra metadata. |
None
|
Source code in medspacy/context/context_rule.py
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
from_dict(rule_dict)
classmethod
Reads a dictionary into a ConTextRule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_dict
|
The dictionary to convert. |
required |
Returns:
| Type | Description |
|---|---|
ConTextRule
|
The ConTextRule created from the dictionary. |
Source code in medspacy/context/context_rule.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
from_json(filepath)
classmethod
Reads in a lexicon of modifiers from a JSON file under the key context_rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
The .json file containing modifier rules. Must contain |
required |
Returns:
| Type | Description |
|---|---|
List[ConTextRule]
|
A list of ConTextRules objects read from the JSON. |
Source code in medspacy/context/context_rule.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
to_dict()
Converts ConTextItems to a python dictionary. Used when writing context rules to a json file.
Returns:
| Type | Description |
|---|---|
|
The dictionary containing the ConTextRule info. |
Source code in medspacy/context/context_rule.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
to_json(context_rules, filepath)
classmethod
Writes ConTextItems to a json file.
Args: context_rules: a list of ContextRules that will be written to a file. filepath: the .json file to contain modifier rules
Source code in medspacy/context/context_rule.py
224 225 226 227 228 229 230 231 232 233 234 235 236 | |