Add chunk store and chunk list helper

This commit is contained in:
liyaxing
2023-09-08 15:52:05 +08:00
parent 1e5b9afd0f
commit e8e3812d28
6 changed files with 164 additions and 28 deletions
+23 -3
View File
@@ -7,16 +7,27 @@ print(dir_path)
sys.path.append("{}/../src/".format(dir_path))
print(sys.path)
from knowledge import ChunkTracker, ChunkID, HashValue, PositionType
import logging
import sys
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
from knowledge import ChunkTracker, ChunkID, HashValue, PositionType, KnowledgeStore, ChunkListGenerator
import asyncio
import unittest
class TestChunk(unittest.TestCase):
def test_chunk_tracker(self):
tracker = ChunkTracker()
tracker = KnowledgeStore().get_chunk_tracker()
hash = HashValue.hash_data("1234567890".encode("utf-8"));
cid = ChunkID.new_chunk_id(hash)
@@ -29,8 +40,17 @@ class TestChunk(unittest.TestCase):
tracker.remove_position(cid)
ret = tracker.get_position(cid)
self.assertEqual(ret, None)
def test_chunk(self):
gen = ChunkListGenerator(KnowledgeStore().get_chunk_store(), KnowledgeStore().get_chunk_tracker())
gen.create_chunk_list_from_file("H:/test", 1024 * 1024, True)
# Read the file
text_file = "H:/test.txt"
with open(text_file, 'r', encoding = "utf-8") as file:
text = file.read()
gen.create_chunk_list_from_text(text, 1024)
if __name__ == "__main__":
unittest.main()