-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy path3_parse.py
More file actions
75 lines (55 loc) · 1.74 KB
/
Copy path3_parse.py
File metadata and controls
75 lines (55 loc) · 1.74 KB
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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Part 3: crawl and parse unstructured content, initializing the vector
store and generating a lexical graph.
see copyright/license https://github.com/DerwenAI/strwythura/README.md
"""
import json
import pathlib
from strwythura import Profiler, Workflow
if __name__ == "__main__":
# instantiate and configure our workflow manager
work: Workflow = Workflow(
config_path = pathlib.Path("config.toml"),
)
# start the performance profiling
profiling: bool = work.config["prof"]["use_pyinst"]
if profiling:
prof: Profiler = Profiler()
# de-serialize assets from previous steps
work.thesaurus.load_source(
pathlib.Path(work.config["sz"]["thesaurus_path"]),
format = "turtle",
)
work.ctx.ent_store.load_json(
pathlib.Path(work.config["ent"]["store_path"]),
)
work.ctx.erkg.load_graph(
pathlib.Path(work.config["erkg"]["erkg_path"]),
)
work.ctx.open_vector_tables()
work.load_parser()
domain: dict = json.load(
pathlib.Path("domain.json").open("r", encoding = "utf-8")
)
# crawl, chunk, parse -- across all the documents
work.crawl_chunk_parse(
domain["sources"]["content"],
)
# serialize the intermediate results
work.ctx.ent_store.save_json(
pathlib.Path(work.config["ent"]["store_path"]),
)
work.ctx.ent_store.save_vec(
pathlib.Path(work.config["ent"]["vec_path"]),
)
work.ctx.lex.save_graph(
pathlib.Path(work.config["nlp"]["lex_path"]),
)
work.ctx.erkg.save_graph(
pathlib.Path(work.config["erkg"]["erkg_path"]),
)
# finally, report the performance profiler stats
if profiling:
prof.analyze()