-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
26 lines (20 loc) · 822 Bytes
/
main.py
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
from markdown_parser import SemanticMarkdownParser
from pathlib import Path
import json
from token_encoder.encode import get_token_length
if __name__ == "__main__":
parser = SemanticMarkdownParser()
input_text = Path("input.md").read_text(encoding="utf-8")
# Parse to tree
root = parser.parse_markdown_to_tree(input_text)
# Process tree into chunks
chunks = parser.get_semantic_chunks(root, max_tokens=500)
# Print resulting chunks
with open("output.txt", "w") as file:
for i, chunk in enumerate(chunks, 1):
file.write(f"\nChunk {i}:\n")
file.write("-" * 80 + "\n")
file.write(chunk + "\n")
file.write("-" * 80 + "\n")
file.write(f"Token length: {get_token_length(chunk)}\n")
print("Output saved to output.txt")