diff options
| author | 2025-03-13 01:01:20 +0800 | |
|---|---|---|
| committer | 2025-03-13 01:01:20 +0800 | |
| commit | 80b74f79dfbfa9afb845172a5ea84110d75f1bc8 (patch) | |
| tree | 361dcb055de78b50d82619646fde28fa618f9507 /src/conventionalrp | |
| parent | dd873e954a92d0e3209fe98b034570b47c859589 (diff) | |
| download | conventional_role_play-80b74f79dfbfa9afb845172a5ea84110d75f1bc8.tar.gz conventional_role_play-80b74f79dfbfa9afb845172a5ea84110d75f1bc8.zip | |
refactor(project)!: first implementation of the Conventional Role Play SDK with core components, renderers, extractors, and example usage.
Diffstat (limited to 'src/conventionalrp')
23 files changed, 178 insertions, 0 deletions
diff --git a/src/conventionalrp/__init__.py b/src/conventionalrp/__init__.py new file mode 100644 index 0000000..4522950 --- /dev/null +++ b/src/conventionalrp/__init__.py @@ -0,0 +1 @@ +from . import _core
\ No newline at end of file diff --git a/src/conventionalrp/__main__.py b/src/conventionalrp/__main__.py new file mode 100644 index 0000000..01b510d --- /dev/null +++ b/src/conventionalrp/__main__.py @@ -0,0 +1,7 @@ +from ._core import sum_as_string + +def main(): + print(sum_as_string(1, 2)) + +if __name__ == "__main__": + main() diff --git a/src/conventionalrp/_core.pyi b/src/conventionalrp/_core.pyi new file mode 100644 index 0000000..4945a82 --- /dev/null +++ b/src/conventionalrp/_core.pyi @@ -0,0 +1,3 @@ +def sum_as_string(self, a: int, b: int) -> str: ... + +class Base: ...
\ No newline at end of file diff --git a/src/conventionalrp/base.py b/src/conventionalrp/base.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/base.py 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 "<html><body>" + "".join(f"<p>{data}</p>" for data in processed_data) + "</body></html>" + + 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 diff --git a/src/conventionalrp/extractors/__init__.py b/src/conventionalrp/extractors/__init__.py new file mode 100644 index 0000000..d27a5eb --- /dev/null +++ b/src/conventionalrp/extractors/__init__.py @@ -0,0 +1,4 @@ +# FILE: /trpg-log-processor/trpg-log-processor/src/trpg_log_processor/extractors/__init__.py +""" +This file initializes the extractors module. +"""
\ No newline at end of file diff --git a/src/conventionalrp/extractors/base.py b/src/conventionalrp/extractors/base.py new file mode 100644 index 0000000..fc42f29 --- /dev/null +++ b/src/conventionalrp/extractors/base.py @@ -0,0 +1,9 @@ +class BaseExtractor: + def __init__(self): + self.rules = [] + + def extract(self, log_data): + raise NotImplementedError("Subclasses should implement this method.") + + def load_rules(self, rules_source): + raise NotImplementedError("Subclasses should implement this method.")
\ No newline at end of file diff --git a/src/conventionalrp/extractors/rule_extractor.py b/src/conventionalrp/extractors/rule_extractor.py new file mode 100644 index 0000000..78e8505 --- /dev/null +++ b/src/conventionalrp/extractors/rule_extractor.py @@ -0,0 +1,24 @@ +class BaseExtractor: + def extract(self): + raise NotImplementedError("This method should be overridden by subclasses.") + + def load_rules(self, rules): + raise NotImplementedError("This method should be overridden by subclasses.") + + +class RuleExtractor(BaseExtractor): + def __init__(self, config_file): + self.config_file = config_file + self.rules = self.load_rules_from_file() + + def load_rules_from_file(self): + import json + with open(self.config_file, 'r') as file: + return json.load(file) + + def extract(self): + # Implement rule extraction logic here + extracted_rules = [] + for rule in self.rules: + extracted_rules.append(rule) # Placeholder for actual extraction logic + return extracted_rules
\ No newline at end of file diff --git a/src/conventionalrp/html_renderer.py b/src/conventionalrp/html_renderer.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/html_renderer.py diff --git a/src/conventionalrp/json_renderer.py b/src/conventionalrp/json_renderer.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/json_renderer.py diff --git a/src/conventionalrp/markdown_renderer.py b/src/conventionalrp/markdown_renderer.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/markdown_renderer.py diff --git a/src/conventionalrp/plugins/__init__.py b/src/conventionalrp/plugins/__init__.py new file mode 100644 index 0000000..32fa8a0 --- /dev/null +++ b/src/conventionalrp/plugins/__init__.py @@ -0,0 +1,4 @@ +# FILE: /trpg-log-processor/trpg-log-processor/src/trpg_log_processor/plugins/__init__.py +""" +This file initializes the plugins module. +"""
\ No newline at end of file diff --git a/src/conventionalrp/plugins/plugin_manager.py b/src/conventionalrp/plugins/plugin_manager.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/plugins/plugin_manager.py diff --git a/src/conventionalrp/renderers/__init__.py b/src/conventionalrp/renderers/__init__.py new file mode 100644 index 0000000..ce04364 --- /dev/null +++ b/src/conventionalrp/renderers/__init__.py @@ -0,0 +1,4 @@ +# FILE: /trpg-log-processor/trpg-log-processor/src/trpg_log_processor/renderers/__init__.py +""" +This file initializes the renderers module. +"""
\ No newline at end of file diff --git a/src/conventionalrp/renderers/base.py b/src/conventionalrp/renderers/base.py new file mode 100644 index 0000000..498adec --- /dev/null +++ b/src/conventionalrp/renderers/base.py @@ -0,0 +1,6 @@ +class BaseRenderer: + def render(self, data): + raise NotImplementedError("Render method must be implemented by subclasses.") + + def set_style(self, style): + self.style = style
\ No newline at end of file diff --git a/src/conventionalrp/renderers/html_renderer.py b/src/conventionalrp/renderers/html_renderer.py new file mode 100644 index 0000000..3c30549 --- /dev/null +++ b/src/conventionalrp/renderers/html_renderer.py @@ -0,0 +1,21 @@ +from .base import BaseRenderer + +class HTMLRenderer(BaseRenderer): + def __init__(self): + super().__init__() + self.title = "TRPG Log Output" + + def render(self, data): + html_content = f"<html><head><title>{self.title}</title></head><body>" + html_content += "<h1>TRPG Log Output</h1>" + html_content += "<ul>" + + for entry in data: + html_content += f"<li>{entry}</li>" + + html_content += "</ul></body></html>" + return html_content + + def set_style(self, style): + # Implement style setting if needed + pass
\ No newline at end of file diff --git a/src/conventionalrp/renderers/json_renderer.py b/src/conventionalrp/renderers/json_renderer.py new file mode 100644 index 0000000..4313001 --- /dev/null +++ b/src/conventionalrp/renderers/json_renderer.py @@ -0,0 +1,9 @@ +from .base import BaseRenderer + +class JSONRenderer(BaseRenderer): + def render(self, data): + import json + return json.dumps(data, ensure_ascii=False, indent=4) + + def set_style(self, style): + self.style = style # Placeholder for potential styling options in the future
\ No newline at end of file diff --git a/src/conventionalrp/renderers/markdown_renderer.py b/src/conventionalrp/renderers/markdown_renderer.py new file mode 100644 index 0000000..396d6a4 --- /dev/null +++ b/src/conventionalrp/renderers/markdown_renderer.py @@ -0,0 +1,26 @@ +from .base import BaseRenderer + +class MarkdownRenderer(BaseRenderer): + def render(self, data): + """ + Renders the given data in Markdown format. + + Args: + data (dict): The data to render. + + Returns: + str: The rendered Markdown string. + """ + markdown_output = "" + for key, value in data.items(): + markdown_output += f"## {key}\n\n{value}\n\n" + return markdown_output + + def set_style(self, style): + """ + Sets the style for the Markdown renderer. + + Args: + style (dict): A dictionary of style options. + """ + self.style = style # Currently, Markdown does not support styling, but this can be extended.
\ No newline at end of file diff --git a/src/conventionalrp/tokenizer.py b/src/conventionalrp/tokenizer.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/tokenizer.py diff --git a/src/conventionalrp/utils/__init__.py b/src/conventionalrp/utils/__init__.py new file mode 100644 index 0000000..20153b2 --- /dev/null +++ b/src/conventionalrp/utils/__init__.py @@ -0,0 +1,2 @@ +# FILE: /trpg-log-processor/trpg-log-processor/src/trpg_log_processor/utils/__init__.py +"""This file initializes the utils module."""
\ No newline at end of file diff --git a/src/conventionalrp/utils/text_processing.py b/src/conventionalrp/utils/text_processing.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/conventionalrp/utils/text_processing.py |
