Download modifier.py from lilingxi01/temporal-wiki-links-sample: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/lilingxi01/temporal-wiki-links-sample/resolve/main/modifier.py
- Command line
-
hf download hf://datasets/lilingxi01/temporal-wiki-links-sample/modifier.py
-
curl -L -o modifier.py https://huggingface.co/datasets/lilingxi01/temporal-wiki-links-sample/resolve/main/modifier.py
1.34 kB
| import logging | |
| import bloark | |
| from grimm import clean_syntax # Need to install separately. | |
| # Define a modifier profile. | |
| class MyModifier(bloark.ModifierProfile): | |
| def block(self, content: dict, metadata: dict): | |
| text_content = content['text']['#text'] | |
| text, external_links, internal_links, images = clean_syntax(text_content) | |
| new_content = { | |
| "article_id": content["article_id"], | |
| "revision_id": content["revision_id"], | |
| "timestamp": content["timestamp"], | |
| "clean_text": text, | |
| "external_links": external_links, | |
| "internal_links": internal_links, | |
| "images": images, | |
| } | |
| return new_content, metadata | |
| if __name__ == '__main__': | |
| # Create a modifier instance with 8 processes (CPUs) and INFO-level logging. | |
| modifier = bloark.Modifier( | |
| output_dir='./output', | |
| num_proc=8, # TODO: Adjust accordingly! | |
| log_level=logging.INFO | |
| ) | |
| # Preload all files from the input directory (original warehouses). | |
| modifier.preload('./input') | |
| # Add the modifier profile to the modifier instance. | |
| # You can even add multiple profiles to the same modifier. | |
| modifier.add_profile(MyModifier()) | |
| # Start modifying the warehouses (this command will take a long time). | |
| modifier.start() | |