From 80b74f79dfbfa9afb845172a5ea84110d75f1bc8 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Thu, 13 Mar 2025 01:01:20 +0800 Subject: refactor(project)!: first implementation of the Conventional Role Play SDK with core components, renderers, extractors, and example usage. --- src/conventionalrp/core/__init__.py | 4 ++++ src/conventionalrp/core/parser.py | 15 ++++++++++++++ src/conventionalrp/core/processor.py | 39 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/conventionalrp/core/__init__.py create mode 100644 src/conventionalrp/core/parser.py create mode 100644 src/conventionalrp/core/processor.py (limited to 'src/conventionalrp/core') diff --git a/src/conventionalrp/core/__init__.py b/src/conventionalrp/core/__init__.py new file mode 100644 index 0000000..7097e41 --- /dev/null +++ b/src/conventionalrp/core/__init__.py @@ -0,0 +1,4 @@ +# FILE: /trpg-log-processor/trpg-log-processor/src/trpg_log_processor/core/__init__.py +""" +This file initializes the core module of the trpg_log_processor SDK. +""" \ No newline at end of file diff --git a/src/conventionalrp/core/parser.py b/src/conventionalrp/core/parser.py new file mode 100644 index 0000000..32b1b9f --- /dev/null +++ b/src/conventionalrp/core/parser.py @@ -0,0 +1,15 @@ +class Parser: + def __init__(self): + self.rules = [] + + def load_rules(self, rules): + """Load parsing rules.""" + self.rules = rules + + def parse_log(self, log): + """Parse the TRPG log based on loaded rules.""" + parsed_data = [] + for rule in self.rules: + # Implement rule-based parsing logic here + pass + return parsed_data \ No newline at end of file diff --git a/src/conventionalrp/core/processor.py b/src/conventionalrp/core/processor.py new file mode 100644 index 0000000..40033cf --- /dev/null +++ b/src/conventionalrp/core/processor.py @@ -0,0 +1,39 @@ +class Processor: + def __init__(self, rules): + self.rules = rules + + def process_tokens(self, tokens): + processed_data = [] + for token in tokens: + processed_data.append(self.apply_rules(token)) + return processed_data + + def apply_rules(self, token): + # Implement rule application logic here + for rule in self.rules: + if rule.matches(token): + return rule.apply(token) + return token + + def generate_output(self, processed_data, format_type): + # Implement output generation logic based on format_type + if format_type == 'json': + return self.generate_json_output(processed_data) + elif format_type == 'html': + return self.generate_html_output(processed_data) + elif format_type == 'markdown': + return self.generate_markdown_output(processed_data) + else: + raise ValueError("Unsupported format type") + + def generate_json_output(self, processed_data): + import json + return json.dumps(processed_data) + + def generate_html_output(self, processed_data): + # Implement HTML output generation + return "" + "".join(f"
{data}
" for data in processed_data) + "" + + def generate_markdown_output(self, processed_data): + # Implement Markdown output generation + return "\n".join(f"- {data}" for data in processed_data) \ No newline at end of file -- cgit v1.2.3-70-g09d2