Dump a representation of this rule as a .RULE file stored in ``rules_data_dir`` as a UTF-8 file having: - the rule data as YAML frontmatter - the rule text And this is a ``rule_file``. Also writes any kwargs as extra data in the rule metadata.
(self, rules_data_dir, **kwargs)
| 2396 | self.is_tiny = self.length < tiny_rule |
| 2397 | |
| 2398 | def dump(self, rules_data_dir, **kwargs): |
| 2399 | """ |
| 2400 | Dump a representation of this rule as a .RULE file stored in ``rules_data_dir`` as a UTF-8 |
| 2401 | file having: |
| 2402 | - the rule data as YAML frontmatter |
| 2403 | - the rule text |
| 2404 | And this is a ``rule_file``. |
| 2405 | |
| 2406 | Also writes any kwargs as extra data in the rule metadata. |
| 2407 | |
| 2408 | Does nothing if this rule was created from a License (e.g., `is_from_license` is True) |
| 2409 | """ |
| 2410 | if self.is_from_license or self.is_synthetic: |
| 2411 | return |
| 2412 | |
| 2413 | rule_file = self.rule_file(rules_data_dir=rules_data_dir) |
| 2414 | |
| 2415 | metadata = self.to_dict() |
| 2416 | # This can be used to pass objects to dump on the rule file with |
| 2417 | # other rule metadata, like debugging collection of required phrases |
| 2418 | if kwargs: |
| 2419 | metadata.update(kwargs) |
| 2420 | content = self.text |
| 2421 | output = dumps_frontmatter(content=content, metadata=metadata) |
| 2422 | with open(rule_file, 'w') as of: |
| 2423 | of.write(output) |
| 2424 | |
| 2425 | def load(self, rule_file, with_checks=True): |
| 2426 | """ |