sayou-wrapper 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: sayou-wrapper
3
+ Version: 0.0.1
4
+ Summary: Wrapper components for the Sayou Data Fabric
5
+ Project-URL: Homepage, https://github.com/sayouzone/sayou-fabric
6
+ Project-URL: Documentation, https://sayouzone.github.io/sayou-fabric/
7
+ Project-URL: Repository, https://github.com/sayouzone/sayou-fabric
8
+ Project-URL: Changelog, https://github.com/sayouzone/sayou-fabric/releases
9
+ Author-email: Sayouzone <contact@sayouzone.com>
10
+ License: Apache License
11
+ Version 2.0, January 2004
12
+ http://www.apache.org/licenses/
13
+
14
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
15
+
16
+ 1. Definitions.
17
+
18
+ "License" shall mean the terms and conditions for use, reproduction,
19
+ and distribution as defined by Sections 1 through 9 of this document.
20
+
21
+ "Licensor" shall mean the copyright owner or entity authorized by
22
+ the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all
25
+ other entities that control, are controlled by, or are under common
26
+ control with that entity. For the purposes of this definition,
27
+ "control" means (i) the power, direct or indirect, to cause the
28
+ direction or management of such entity, whether by contract or
29
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
30
+ outstanding shares, or (iii) beneficial ownership of such entity.
31
+
32
+ "You" (or "Your") shall mean an individual or Legal Entity
33
+ exercising permissions granted by this License.
34
+
35
+ "Source" form shall mean the preferred form for making modifications,
36
+ including but not limited to software source code, documentation
37
+ source, and configuration files.
38
+
39
+ "Object" form shall mean any form resulting from mechanical
40
+ transformation or translation of a Source form, including but
41
+ not limited to compiled object code, generated documentation,
42
+ and conversions to other media types.
43
+
44
+ "Work" shall mean the work of authorship, whether in Source or
45
+ Object form, made available under the License, as indicated by a
46
+ copyright notice that is included in or attached to the work
47
+ (an example is provided in the Appendix below).
48
+
49
+ "Derivative Works" shall mean any work, whether in Source or Object
50
+ form, that is based on (or derived from) the Work and for which the
51
+ editorial revisions, annotations, elaborations, or other modifications
52
+ represent, as a whole, an original work of authorship. For the purposes
53
+ of this License, Derivative Works shall not include works that remain
54
+ separable from, or merely link (or bind by name) to the interfaces of,
55
+ the Work and Derivative Works thereof.
56
+
57
+ "Contribution" shall mean any work of authorship, including
58
+ the original version of the Work and any modifications or additions
59
+ to that Work or Derivative Works thereof, that is intentionally
60
+ submitted to Licensor for inclusion in the Work by the copyright owner
61
+ or by an individual or Legal Entity authorized to submit on behalf of
62
+ the copyright owner. For the purposes of this definition, "submitted"
63
+ means any form of electronic, verbal, or written communication sent
64
+ to the Licensor or its representatives, including but not limited to
65
+ communication on electronic mailing lists, source code control systems,
66
+ and issue tracking systems that are managed by, or on behalf of, the
67
+ Licensor for the purpose of discussing and improving the Work, but
68
+ excluding communication that is conspicuously marked or otherwise
69
+ designated in writing by the copyright owner as "Not a Contribution."
70
+
71
+ "Contributor" shall mean Licensor and any individual or Legal Entity
72
+ on behalf of whom a Contribution has been received by Licensor and
73
+ subsequently incorporated within the Work.
74
+
75
+ 2. Grant of Copyright License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ copyright license to reproduce, prepare Derivative Works of,
79
+ publicly display, publicly perform, sublicense, and distribute the
80
+ Work and such Derivative Works in Source or Object form.
81
+
82
+ 3. Grant of Patent License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ (except as stated in this section) patent license to make, have made,
86
+ use, offer to sell, sell, import, and otherwise transfer the Work,
87
+ where such license applies only to those patent claims licensable
88
+ by such Contributor that are necessarily infringed by their
89
+ Contribution(s) alone or by combination of their Contribution(s)
90
+ with the Work to which such Contribution(s) was submitted. If You
91
+ institute patent litigation against any entity (including a
92
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
93
+ or a Contribution incorporated within the Work constitutes direct
94
+ or contributory patent infringement, then any patent licenses
95
+ granted to You under this License for that Work shall terminate
96
+ as of the date such litigation is filed.
97
+
98
+ 4. Redistribution. You may reproduce and distribute copies of the
99
+ Work or Derivative Works thereof in any medium, with or without
100
+ modifications, and in Source or Object form, provided that You
101
+ meet the following conditions:
102
+
103
+ (a) You must give any other recipients of the Work or
104
+ Derivative Works a copy of this License; and
105
+
106
+ (b) You must cause any modified files to carry prominent notices
107
+ stating that You changed the files; and
108
+
109
+ (c) You must retain, in the Source form of any Derivative Works
110
+ that You distribute, all copyright, patent, trademark, and
111
+ attribution notices from the Source form of the Work,
112
+ excluding those notices that do not pertain to any part of
113
+ the Derivative Works; and
114
+
115
+ (d) If the Work includes a "NOTICE" text file as part of its
116
+ distribution, then any Derivative Works that You distribute must
117
+ include a readable copy of the attribution notices contained
118
+ within such NOTICE file, excluding those notices that do not
119
+ pertain to any part of the Derivative Works, in at least one
120
+ of the following places: within a NOTICE text file distributed
121
+ as part of the Derivative Works; within the Source form or
122
+ documentation, if provided along with the Derivative Works; or,
123
+ within a display generated by the Derivative Works, if and
124
+ wherever such third-party notices normally appear. The contents
125
+ of the NOTICE file are for informational purposes only and
126
+ do not modify the License. You may add Your own attribution
127
+ notices within Derivative Works that You distribute, alongside
128
+ or as an addendum to the NOTICE text from the Work, provided
129
+ that such additional attribution notices cannot be construed
130
+ as modifying the License.
131
+
132
+ You may add Your own copyright statement to Your modifications and
133
+ may provide additional or different license terms and conditions
134
+ for use, reproduction, or distribution of Your modifications, or
135
+ for any such Derivative Works as a whole, provided Your use,
136
+ reproduction, and distribution of the Work otherwise complies with
137
+ the conditions stated in this License.
138
+
139
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
140
+ any Contribution intentionally submitted for inclusion in the Work
141
+ by You to the Licensor shall be under the terms and conditions of
142
+ this License, without any additional terms or conditions.
143
+ Notwithstanding the above, nothing herein shall supersede or modify
144
+ the terms of any separate license agreement you may have executed
145
+ with Licensor regarding such Contributions.
146
+
147
+ 6. Trademarks. This License does not grant permission to use the trade
148
+ names, trademarks, service marks, or product names of the Licensor,
149
+ except as required for reasonable and customary use in describing the
150
+ origin of the Work and reproducing the content of the NOTICE file.
151
+
152
+ 7. Disclaimer of Warranty. Unless required by applicable law or
153
+ agreed to in writing, Licensor provides the Work (and each
154
+ Contributor provides its Contributions) on an "AS IS" BASIS,
155
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156
+ implied, including, without limitation, any warranties or conditions
157
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
158
+ PARTICULAR PURPOSE. You are solely responsible for determining the
159
+ appropriateness of using or redistributing the Work and assume any
160
+ risks associated with Your exercise of permissions under this License.
161
+
162
+ 8. Limitation of Liability. In no event and under no legal theory,
163
+ whether in tort (including negligence), contract, or otherwise,
164
+ unless required by applicable law (such as deliberate and grossly
165
+ negligent acts) or agreed to in writing, shall any Contributor be
166
+ liable to You for damages, including any direct, indirect, special,
167
+ incidental, or consequential damages of any character arising as a
168
+ result of this License or out of the use or inability to use the
169
+ Work (including but not limited to damages for loss of goodwill,
170
+ work stoppage, computer failure or malfunction, or any and all
171
+ other commercial damages or losses), even if such Contributor
172
+ has been advised of the possibility of such damages.
173
+
174
+ 9. Accepting Warranty or Additional Liability. While redistributing
175
+ the Work or Derivative Works thereof, You may choose to offer,
176
+ and charge a fee for, acceptance of support, warranty, indemnity,
177
+ or other liability obligations and/or rights consistent with this
178
+ License. However, in accepting such obligations, You may act only
179
+ on Your own behalf and on Your sole responsibility, not on behalf
180
+ of any other Contributor, and only if You agree to indemnify,
181
+ defend, and hold each Contributor harmless for any liability
182
+ incurred by, or claims asserted against, such Contributor by reason
183
+ of your accepting any such warranty or additional liability.
184
+
185
+ END OF TERMS AND CONDITIONS
186
+
187
+ APPENDIX: How to apply the Apache License to your work.
188
+
189
+ To apply the Apache License to your work, attach the following
190
+ boilerplate notice, with the fields enclosed by brackets "[]"
191
+ replaced with your own identifying information. (Don't include
192
+ the brackets!) The text should be enclosed in the appropriate
193
+ comment syntax for the file format. We also recommend that a
194
+ file or class name and description of purpose be included on the
195
+ same "printed page" as the copyright notice for easier
196
+ identification within third-party archives.
197
+
198
+ Copyright [yyyy] [name of copyright owner]
199
+
200
+ Licensed under the Apache License, Version 2.0 (the "License");
201
+ you may not use this file except in compliance with the License.
202
+ You may obtain a copy of the License at
203
+
204
+ http://www.apache.org/licenses/LICENSE-2.0
205
+
206
+ Unless required by applicable law or agreed to in writing, software
207
+ distributed under the License is distributed on an "AS IS" BASIS,
208
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209
+ See the License for the specific language governing permissions and
210
+ limitations under the License.
211
+ Classifier: License :: OSI Approved :: Apache Software License
212
+ Classifier: Operating System :: OS Independent
213
+ Classifier: Programming Language :: Python :: 3.9
214
+ Classifier: Programming Language :: Python :: 3.10
215
+ Classifier: Programming Language :: Python :: 3.11
216
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
217
+ Requires-Python: >=3.9
218
+ Requires-Dist: sayou-core~=0.0.2
219
+ Description-Content-Type: text/markdown
220
+
221
+ # Sayou Refinery (sayou_refinery)
222
+
223
+
224
+
225
+ **A pluggable framework for refining raw Data Atoms into a coherent Knowledge Graph (KG) for advanced LLM applications.**
226
+
227
+ ---
228
+
229
+ ## 💡 Why Sayou Refinery?
230
+
231
+ `sayou_refinery` solves the core problem of organizing messy, disconnected data into a structured KG. This KG acts as a "map" for RAG pipelines, allowing LLMs to retrieve accurate, context-aware data, minimizing hallucinations and costs.
232
+
233
+ - **Pluggable Architecture:** Bring your own data store (Neo4j, JSON) or refinement logic.
234
+ - **Ontology-Driven:** Ensures all data conforms to your central schema.
235
+ - **Focused Responsibility:** Does one job well: **Refine & Link**. No connectors, no embedding logic.
236
+
237
+ ## 🚀 Quick Start (v.0.0.1)
238
+
239
+ ### 1. Installation
240
+
241
+ ```bash
242
+ pip install sayou-refinery
243
+ ```
244
+
245
+ ### 2. Usage (Example)
246
+ sayou_refinery is a library. You import it into your own project. See the full code in examples/subway_refinery/run.py.
247
+
248
+ ``` Python
249
+ # your_project/run.py
250
+ from sayou.refinery.pipeline import Pipeline
251
+ from sayou.refinery.schema.manager import OntologyManager
252
+ from sayou.refinery.schema.validator import SchemaValidator
253
+ from sayou.refinery.graph.builder import KnowledgeGraphBuilder
254
+ from sayou.refinery.linker.default_linker import DefaultLinker
255
+ from sayou.refinery.store.json_store import JsonStore
256
+
257
+ # 1. Import your custom domain logic
258
+ from your_project.my_refiner import MyDomainRefiner
259
+
260
+ # 2. Prepare components (Explicit Injection)
261
+ schema_manager = OntologyManager()
262
+ validator = SchemaValidator()
263
+ refiner = MyDomainRefiner() # Your logic
264
+ builder = KnowledgeGraphBuilder()
265
+ linker = DefaultLinker()
266
+ store = JsonStore()
267
+
268
+ # 3. Create and configure the pipeline
269
+ pipeline = Pipeline(
270
+ schema_manager=schema_manager,
271
+ validator=validator,
272
+ refiner=refiner,
273
+ builder=builder,
274
+ linker=linker,
275
+ store=store
276
+ )
277
+
278
+ pipeline.initialize(
279
+ ontology_path="path/to/your_schema.json",
280
+ filepath="output/my_kg.json" # Config for JsonStore
281
+ )
282
+
283
+ # 4. Load your data atoms
284
+ my_atoms = [...] # Load your DataAtom objects
285
+
286
+ # 5. Run
287
+ pipeline.run(my_atoms)
288
+ ```
289
+
290
+ ## 🏗️ Core Concepts
291
+ - Data Atom: The standard input unit. (Schema/structure explanation)
292
+
293
+ - Refiner (BaseRefiner): Cleans, aggregates, or transforms atoms. (e.g., averaging subway data)
294
+
295
+ - Linker (BaseLinker): Establishes relationships between nodes.
296
+
297
+ - Store (BaseStore): The output driver (JSON, Neo4j, etc.).
298
+
299
+ ## 🤝 Contributing
300
+ We welcome contributions! Please read our CONTRIBUTING.md (추후 추가) file for details on how to submit pull requests.
301
+
302
+ ## 📜 License
303
+ This project is licensed under the MIT License.
@@ -0,0 +1,83 @@
1
+ # Sayou Refinery (sayou_refinery)
2
+
3
+
4
+
5
+ **A pluggable framework for refining raw Data Atoms into a coherent Knowledge Graph (KG) for advanced LLM applications.**
6
+
7
+ ---
8
+
9
+ ## 💡 Why Sayou Refinery?
10
+
11
+ `sayou_refinery` solves the core problem of organizing messy, disconnected data into a structured KG. This KG acts as a "map" for RAG pipelines, allowing LLMs to retrieve accurate, context-aware data, minimizing hallucinations and costs.
12
+
13
+ - **Pluggable Architecture:** Bring your own data store (Neo4j, JSON) or refinement logic.
14
+ - **Ontology-Driven:** Ensures all data conforms to your central schema.
15
+ - **Focused Responsibility:** Does one job well: **Refine & Link**. No connectors, no embedding logic.
16
+
17
+ ## 🚀 Quick Start (v.0.0.1)
18
+
19
+ ### 1. Installation
20
+
21
+ ```bash
22
+ pip install sayou-refinery
23
+ ```
24
+
25
+ ### 2. Usage (Example)
26
+ sayou_refinery is a library. You import it into your own project. See the full code in examples/subway_refinery/run.py.
27
+
28
+ ``` Python
29
+ # your_project/run.py
30
+ from sayou.refinery.pipeline import Pipeline
31
+ from sayou.refinery.schema.manager import OntologyManager
32
+ from sayou.refinery.schema.validator import SchemaValidator
33
+ from sayou.refinery.graph.builder import KnowledgeGraphBuilder
34
+ from sayou.refinery.linker.default_linker import DefaultLinker
35
+ from sayou.refinery.store.json_store import JsonStore
36
+
37
+ # 1. Import your custom domain logic
38
+ from your_project.my_refiner import MyDomainRefiner
39
+
40
+ # 2. Prepare components (Explicit Injection)
41
+ schema_manager = OntologyManager()
42
+ validator = SchemaValidator()
43
+ refiner = MyDomainRefiner() # Your logic
44
+ builder = KnowledgeGraphBuilder()
45
+ linker = DefaultLinker()
46
+ store = JsonStore()
47
+
48
+ # 3. Create and configure the pipeline
49
+ pipeline = Pipeline(
50
+ schema_manager=schema_manager,
51
+ validator=validator,
52
+ refiner=refiner,
53
+ builder=builder,
54
+ linker=linker,
55
+ store=store
56
+ )
57
+
58
+ pipeline.initialize(
59
+ ontology_path="path/to/your_schema.json",
60
+ filepath="output/my_kg.json" # Config for JsonStore
61
+ )
62
+
63
+ # 4. Load your data atoms
64
+ my_atoms = [...] # Load your DataAtom objects
65
+
66
+ # 5. Run
67
+ pipeline.run(my_atoms)
68
+ ```
69
+
70
+ ## 🏗️ Core Concepts
71
+ - Data Atom: The standard input unit. (Schema/structure explanation)
72
+
73
+ - Refiner (BaseRefiner): Cleans, aggregates, or transforms atoms. (e.g., averaging subway data)
74
+
75
+ - Linker (BaseLinker): Establishes relationships between nodes.
76
+
77
+ - Store (BaseStore): The output driver (JSON, Neo4j, etc.).
78
+
79
+ ## 🤝 Contributing
80
+ We welcome contributions! Please read our CONTRIBUTING.md (추후 추가) file for details on how to submit pull requests.
81
+
82
+ ## 📜 License
83
+ This project is licensed under the MIT License.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ # -----------------
6
+ # 1. 패키지 기본 정보
7
+ # -----------------
8
+ [project]
9
+ name = "sayou-wrapper"
10
+ version = "0.0.1"
11
+ authors = [
12
+ { name = "Sayouzone", email = "contact@sayouzone.com" },
13
+ ]
14
+ description = "Wrapper components for the Sayou Data Fabric"
15
+ readme = "README.md"
16
+ license = { file = "../../LICENSE" }
17
+ requires-python = ">=3.9"
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "License :: OSI Approved :: Apache Software License",
23
+ "Operating System :: OS Independent",
24
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
25
+ ]
26
+ dependencies = [
27
+ "sayou-core ~= 0.0.2"
28
+ ]
29
+
30
+ # -----------------
31
+ # 2. 프로젝트 링크 (PyPI 사이드바)
32
+ # -----------------
33
+ [project.urls]
34
+ "Homepage" = "https://github.com/sayouzone/sayou-fabric"
35
+ "Documentation" = "https://sayouzone.github.io/sayou-fabric/"
36
+ "Repository" = "https://github.com/sayouzone/sayou-fabric"
37
+ "Changelog" = "https://github.com/sayouzone/sayou-fabric/releases"
38
+
39
+ # -----------------
40
+ # 3. 소스 코드 위치
41
+ # -----------------
42
+ [tool.hatch.build.targets.wheel]
43
+ packages = ["src/sayou"]
@@ -0,0 +1,14 @@
1
+ # src/sayou/wrapper/core/exceptions.py
2
+ from sayou.core.exceptions import SayouCoreError
3
+
4
+ class WrapperError(SayouCoreError):
5
+ """'sayou-wrapper' 툴킷의 모든 오류가 상속받는 베이스 예외"""
6
+ pass
7
+
8
+ class MappingError(WrapperError):
9
+ """'Mapper' (Tier 1/2/3) 실행 중 발생하는 오류"""
10
+ pass
11
+
12
+ class ValidationError(WrapperError):
13
+ """'Validator' (Tier 1/2/3) 실행 중 발생하는 오류 (e.g., 스키마 위반)"""
14
+ pass
@@ -0,0 +1,44 @@
1
+ # src/sayou/wrapper/interfaces/base_mapper.py
2
+ from abc import abstractmethod
3
+ from typing import List, Any, Dict
4
+ from sayou.core.base_component import BaseComponent
5
+ from sayou.wrapper.core.exceptions import MappingError
6
+
7
+ class BaseMapper(BaseComponent):
8
+ """
9
+ (Tier 1) 'Raw Data' 리스트를 '구조화된 dict' 리스트로 '매핑'하는
10
+ 모든 Mapper의 인터페이스. (Template Method)
11
+ """
12
+ component_name = "BaseMapper"
13
+
14
+ def map_list(self, raw_data_list: List[Any]) -> List[Dict[str, Any]]:
15
+ """
16
+ [공통 골격] Raw Data 리스트를 순회하며 매핑을 실행합니다.
17
+ Tier 2/3는 이 메서드를 오버라이드하지 않습니다.
18
+ """
19
+ self._log(f"Mapping {len(raw_data_list)} raw items...")
20
+ mapped_dicts = []
21
+ for raw_data in raw_data_list:
22
+ try:
23
+ # Tier 2/3가 '알맹이'를 구현
24
+ mapped_dict = self._do_map_item(raw_data)
25
+ if mapped_dict:
26
+ mapped_dicts.append(mapped_dict)
27
+ except Exception as e:
28
+ self._log(f"Mapping failed for item {raw_data}: {e}")
29
+ # (정책에 따라 실패 시 중단하거나, None을 반환)
30
+
31
+ self._log(f"Mapping complete. {len(mapped_dicts)} items mapped.")
32
+ return mapped_dicts
33
+
34
+ @abstractmethod
35
+ def _do_map_item(self, raw_data_item: Any) -> Dict[str, Any]:
36
+ """
37
+ [구현 필수] 단일 원본 데이터 조각을 받아
38
+ 'DataAtom'의 기반이 될 딕셔너리로 매핑합니다.
39
+
40
+ :param raw_data_item: e.g., CSV의 1행 (list)
41
+ :return: DataAtom 구조를 가진 딕셔너리
42
+ (e.g., {"source": "...", "type": "...", "payload": {...}})
43
+ """
44
+ raise NotImplementedError
@@ -0,0 +1,42 @@
1
+ # src/sayou/wrapper/interfaces/base_validator.py
2
+ from abc import abstractmethod
3
+ from typing import List, Dict, Any
4
+ from sayou.core.base_component import BaseComponent
5
+
6
+ class BaseValidator(BaseComponent):
7
+ """
8
+ (Tier 1) '매핑된 dict' 리스트가 스키마에 부합하는지 '검증'하는
9
+ 모든 Validator의 인터페이스. (Template Method)
10
+ """
11
+ component_name = "BaseValidator"
12
+
13
+ def validate_list(self, mapped_dicts: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
14
+ """
15
+ [공통 골격] 매핑된 dict 리스트를 순회하며 검증합니다.
16
+ Tier 2/3는 이 메서드를 오버라이드하지 않습니다.
17
+ """
18
+ self._log(f"Validating {len(mapped_dicts)} mapped items...")
19
+ validated_dicts = []
20
+ for mapped_dict in mapped_dicts:
21
+ try:
22
+ # Tier 2/3가 '알맹이'를 구현
23
+ if self._do_validate_item(mapped_dict):
24
+ validated_dicts.append(mapped_dict)
25
+ else:
26
+ # (실패 시 로그만 남기고 필터링)
27
+ self._log(f"Validation failed, item dropped: {mapped_dict.get('payload', {}).get('entity_id', 'N/A')}")
28
+ except Exception as e:
29
+ self._log(f"Validation error: {e}")
30
+
31
+ self._log(f"Validation complete. {len(validated_dicts)} items passed.")
32
+ return validated_dicts
33
+
34
+ @abstractmethod
35
+ def _do_validate_item(self, mapped_dict: Dict[str, Any]) -> bool:
36
+ """
37
+ [구현 필수] 단일 매핑 딕셔너리를 검증합니다.
38
+
39
+ :param mapped_dict: Mapper가 생성한 딕셔너리
40
+ :return: (True/False) 검증 통과 여부
41
+ """
42
+ raise NotImplementedError
@@ -0,0 +1,69 @@
1
+ # src/sayou/wrapper/templates/mapper/list_mapper.py
2
+ from typing import Dict, Any, List
3
+ from sayou.wrapper.interfaces.base_mapper import BaseMapper
4
+ from sayou.wrapper.core.exceptions import MappingError
5
+
6
+ class ListMapper(BaseMapper):
7
+ """
8
+ (Tier 2) 'List' (e.g., CSV row)를 'Dict'로 매핑하는 일반 엔진.
9
+ 사용자가 'main.py'에서 이 클래스에 '매핑 규칙'을 주입합니다.
10
+ """
11
+ component_name = "ListMapper"
12
+
13
+ def initialize(self, **kwargs):
14
+ """
15
+ 'main.py'에서 '매핑 규칙'을 주입받습니다.
16
+ e.g.,
17
+ field_mappings = {
18
+ 0: "payload.entity_id", # 0번 인덱스 -> entity_id
19
+ 1: "payload.attributes.schema:name" # 1번 인덱스 -> name
20
+ }
21
+ static_fields = {
22
+ "source": "csv_connector",
23
+ "type": "entity"
24
+ }
25
+ headers = ["id", "name"] (CSV 헤더가 있을 경우)
26
+ """
27
+ self.mappings = kwargs.get("field_mappings", {})
28
+ self.static_fields = kwargs.get("static_fields", {})
29
+ self.headers = kwargs.get("headers") # (선택적) 헤더 사용 시
30
+
31
+ if not self.mappings:
32
+ raise MappingError("ListMapper requires 'field_mappings'.")
33
+
34
+ def _do_map_item(self, raw_data_item: List[Any]) -> Dict[str, Any]:
35
+ """
36
+ [Tier 1 구현] '매핑 규칙'에 따라 List를 Dict로 변환합니다.
37
+ (e.g., ["222", "강남"] -> {"source": ..., "type": ..., "payload": {...}})
38
+ """
39
+ # 1. 고정 값(e.g., source, type)으로 뼈대 생성
40
+ mapped_dict = self.static_fields.copy()
41
+
42
+ # DataAtom의 'payload' 뼈대(attributes, relationships)를 '먼저' 생성합니다.
43
+ # 이렇게 하면 매핑 규칙에 'relationships'가 없더라도
44
+ # 'payload.relationships: {}'가 항상 존재하게 됩니다.
45
+ mapped_dict.setdefault("payload", {})
46
+ mapped_dict["payload"].setdefault("attributes", {})
47
+ mapped_dict["payload"].setdefault("relationships", {})
48
+
49
+ # 2. 매핑 규칙에 따라 값 삽입
50
+ for index, value in enumerate(raw_data_item):
51
+ key_path = None
52
+ if self.headers:
53
+ header_name = self.headers[index]
54
+ key_path = self.mappings.get(header_name) # 헤더명 기준
55
+ else:
56
+ key_path = self.mappings.get(index) # 인덱스 기준
57
+
58
+ if key_path:
59
+ # e.g., "payload.attributes.schema:name" 같은 중첩 키 설정
60
+ self._set_nested_value(mapped_dict, key_path.split('.'), value)
61
+
62
+ return mapped_dict
63
+
64
+ def _set_nested_value(self, d: Dict, keys: List[str], value: Any):
65
+ """d[keys[0]][keys[1]]... = value를 안전하게 설정"""
66
+ current = d
67
+ for key in keys[:-1]:
68
+ current = current.setdefault(key, {})
69
+ current[keys[-1]] = value
@@ -0,0 +1,68 @@
1
+ # src/sayou/wrapper/pipeline.py
2
+ from typing import List, Any
3
+ from sayou.core.base_component import BaseComponent
4
+ from sayou.core.atom import DataAtom
5
+ from sayou.core.exceptions import InitializationError
6
+ from sayou.wrapper.interfaces.base_mapper import BaseMapper
7
+ from sayou.wrapper.interfaces.base_validator import BaseValidator
8
+
9
+ class Pipeline(BaseComponent):
10
+ """
11
+ (Orchestrator) 'Mapper'와 'Validator'를
12
+ '조립'하여 'Wrapping' 파이프라인을 실행합니다.
13
+ """
14
+ component_name = "WrapperPipeline"
15
+
16
+ def __init__(self,
17
+ mapper: BaseMapper,
18
+ validator: BaseValidator):
19
+
20
+ self.mapper = mapper
21
+ self.validator = validator
22
+ self._log("Pipeline initialized with Mapper and Validator.")
23
+
24
+ def initialize(self, **kwargs):
25
+ """
26
+ 내부 컴포넌트(Mapper, Validator)에 설정을 주입합니다.
27
+
28
+ e.g., kwargs = {
29
+ "field_mappings": {0: "payload.entity_id"},
30
+ "static_fields": {"source": "csv_source"},
31
+ "ontology_path": "path/to/schema.json"
32
+ }
33
+ """
34
+ self.mapper.initialize(**kwargs)
35
+ self.validator.initialize(**kwargs)
36
+
37
+ def run(self, raw_data_list: List[Any]) -> List[DataAtom]:
38
+ """
39
+ [Mapper -> Validator -> DataAtom] 파이프라인을 실행합니다.
40
+
41
+ :param raw_data_list: e.g., CSV row 리스트
42
+ :return: 생성된 DataAtom 리스트
43
+ """
44
+ self._log(f"Wrapper pipeline run started with {len(raw_data_list)} items.")
45
+
46
+ # 1. (Mapper) Raw -> Dict 리스트로 매핑
47
+ mapped_dicts = self.mapper.map_list(raw_data_list)
48
+
49
+ # 2. (Validator) 스키마 검증 및 필터링
50
+ validated_dicts = self.validator.validate_list(mapped_dicts)
51
+
52
+ # 3. (공통) DataAtom 객체 생성
53
+ final_atoms: List[DataAtom] = []
54
+ for v_dict in validated_dicts:
55
+ try:
56
+ # ⭐️ DataAtom.from_dict()가 아닌, 키를 직접 매핑
57
+ # (BaseWrapper.wrap()의 로직을 파이프라인이 수행)
58
+ atom = DataAtom(
59
+ source=v_dict.get("source"),
60
+ type=v_dict.get("type"),
61
+ payload=v_dict.get("payload", {})
62
+ )
63
+ final_atoms.append(atom)
64
+ except Exception as e:
65
+ self._log(f"DataAtom creation failed: {e}")
66
+
67
+ self._log(f"Wrapper run finished. {len(final_atoms)} atoms created.")
68
+ return final_atoms
@@ -0,0 +1,34 @@
1
+ # src/sayou/wrapper/templates/validator/default_validator.py
2
+ from sayou.wrapper.interfaces.base_validator import BaseValidator
3
+ from sayou.wrapper.core.exceptions import ValidationError
4
+ from typing import Dict, Any
5
+
6
+ # (v.0.0.1 에서는 가벼운 '필수 키' 검증기)
7
+ # (v.0.1.0 에서는 'pip install jsonschema' 의존성을 추가하고
8
+ # '사유존 온톨로지'를 JSON Schema로 변환하여 실제 검증 수행)
9
+
10
+ class DefaultValidator(BaseValidator):
11
+ """
12
+ (Tier 2) '매핑된 dict'를 검증하는 일반 엔진.
13
+ v.0.0.1 에서는 'source', 'type', 'payload.entity_id' 존재만 검사.
14
+ """
15
+ component_name = "DefaultValidator"
16
+
17
+ def initialize(self, **kwargs):
18
+ self.ontology_path = kwargs.get("ontology_path")
19
+ # (v.0.1.0: 여기서 온톨로지를 로드하고 JSON Schema로 컴파일)
20
+ self._log(f"Initialized (v.0.0.1 - Basic Key Check mode).")
21
+
22
+ def _do_validate_item(self, mapped_dict: Dict[str, Any]) -> bool:
23
+ """[Tier 1 구현] 필수 키 존재 여부 검사"""
24
+
25
+ if not mapped_dict.get("source") or not mapped_dict.get("type"):
26
+ self._log(f"Validation failed: Missing 'source' or 'type'.")
27
+ return False
28
+
29
+ if not mapped_dict.get("payload", {}).get("entity_id"):
30
+ self._log(f"Validation failed: Missing 'payload.entity_id'.")
31
+ return False
32
+
33
+ # (v.0.1.0: jsonschema.validate(mapped_dict, self.compiled_schema))
34
+ return True