25 lines
844 B
Python
25 lines
844 B
Python
# sensory_system/eyes.py
|
||
|
||
import os
|
||
from typing import List
|
||
|
||
|
||
class Eyes:
|
||
"""The ‘eyes’ read both live input and, on startup, your book corpus."""
|
||
def __init__(self, books_path: str = None) -> None:
|
||
self.corpus: List[str] = []
|
||
if books_path:
|
||
self.load_books(books_path)
|
||
|
||
def load_books(self, folder_path: str) -> None:
|
||
"""Load all .txt files from folder_path into self.corpus."""
|
||
for fn in os.listdir(folder_path):
|
||
if fn.lower().endswith(".txt"):
|
||
full = os.path.join(folder_path, fn)
|
||
with open(full, encoding="utf-8") as f:
|
||
self.corpus.append(f.read())
|
||
|
||
def preprocess(self, text: str) -> List[int]:
|
||
"""Turn an input string into a list of char codes (0–255)."""
|
||
return [ord(c) % 256 for c in text]
|