File size: 1,340 Bytes
25eab98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
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
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()