25 lines
844 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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 (0255)."""
return [ord(c) % 256 for c in text]