opentology 0.1.0

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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +609 -0
  3. package/dist/commands/context.d.ts +29 -0
  4. package/dist/commands/context.js +369 -0
  5. package/dist/commands/delete.d.ts +2 -0
  6. package/dist/commands/delete.js +46 -0
  7. package/dist/commands/diff.d.ts +2 -0
  8. package/dist/commands/diff.js +43 -0
  9. package/dist/commands/drop.d.ts +2 -0
  10. package/dist/commands/drop.js +41 -0
  11. package/dist/commands/graph.d.ts +2 -0
  12. package/dist/commands/graph.js +130 -0
  13. package/dist/commands/infer.d.ts +2 -0
  14. package/dist/commands/infer.js +47 -0
  15. package/dist/commands/init.d.ts +2 -0
  16. package/dist/commands/init.js +53 -0
  17. package/dist/commands/mcp.d.ts +2 -0
  18. package/dist/commands/mcp.js +9 -0
  19. package/dist/commands/prefix.d.ts +2 -0
  20. package/dist/commands/prefix.js +73 -0
  21. package/dist/commands/pull.d.ts +2 -0
  22. package/dist/commands/pull.js +43 -0
  23. package/dist/commands/push.d.ts +2 -0
  24. package/dist/commands/push.js +79 -0
  25. package/dist/commands/query.d.ts +2 -0
  26. package/dist/commands/query.js +119 -0
  27. package/dist/commands/shapes.d.ts +2 -0
  28. package/dist/commands/shapes.js +67 -0
  29. package/dist/commands/status.d.ts +2 -0
  30. package/dist/commands/status.js +47 -0
  31. package/dist/commands/validate.d.ts +2 -0
  32. package/dist/commands/validate.js +46 -0
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.js +38 -0
  35. package/dist/lib/codebase-scanner.d.ts +41 -0
  36. package/dist/lib/codebase-scanner.js +360 -0
  37. package/dist/lib/config.d.ts +16 -0
  38. package/dist/lib/config.js +70 -0
  39. package/dist/lib/embedded-adapter.d.ts +45 -0
  40. package/dist/lib/embedded-adapter.js +202 -0
  41. package/dist/lib/http-adapter.d.ts +41 -0
  42. package/dist/lib/http-adapter.js +169 -0
  43. package/dist/lib/oxigraph.d.ts +62 -0
  44. package/dist/lib/oxigraph.js +323 -0
  45. package/dist/lib/reasoner.d.ts +19 -0
  46. package/dist/lib/reasoner.js +310 -0
  47. package/dist/lib/shacl.d.ts +22 -0
  48. package/dist/lib/shacl.js +105 -0
  49. package/dist/lib/sparql-utils.d.ts +28 -0
  50. package/dist/lib/sparql-utils.js +217 -0
  51. package/dist/lib/store-adapter.d.ts +50 -0
  52. package/dist/lib/store-adapter.js +1 -0
  53. package/dist/lib/store-factory.d.ts +9 -0
  54. package/dist/lib/store-factory.js +71 -0
  55. package/dist/lib/validator.d.ts +10 -0
  56. package/dist/lib/validator.js +40 -0
  57. package/dist/mcp/server.d.ts +3 -0
  58. package/dist/mcp/server.js +1020 -0
  59. package/dist/templates/claude-md-context.d.ts +4 -0
  60. package/dist/templates/claude-md-context.js +104 -0
  61. package/dist/templates/otx-ontology.d.ts +2 -0
  62. package/dist/templates/otx-ontology.js +31 -0
  63. package/dist/templates/session-start-hook.d.ts +1 -0
  64. package/dist/templates/session-start-hook.js +94 -0
  65. package/dist/templates/slash-commands.d.ts +5 -0
  66. package/dist/templates/slash-commands.js +108 -0
  67. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Younkyum Jin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,609 @@
1
+ # OpenTology
2
+
3
+ > CLI-managed RDF/SPARQL infrastructure with RDFS reasoning and SHACL validation -- Supabase for knowledge graphs
4
+
5
+ [English](#english) | [한국어](#한국어)
6
+
7
+ ---
8
+
9
+ ## English
10
+
11
+ ### Architecture
12
+
13
+ ```mermaid
14
+ graph TB
15
+ subgraph CLI["opentology CLI"]
16
+ Init[init]
17
+ Push[push]
18
+ Query[query]
19
+ Validate[validate]
20
+ Infer[infer]
21
+ More[...]
22
+ end
23
+
24
+ subgraph MCP["MCP Server"]
25
+ Tools[11 Tools]
26
+ Resource["opentology://schema"]
27
+ end
28
+
29
+ subgraph Adapter["StoreAdapter"]
30
+ HTTP["HTTP Mode\nOxigraph Server"]
31
+ Embedded["Embedded Mode\nWASM In-Process"]
32
+ end
33
+
34
+ subgraph Pipeline["Processing Pipeline"]
35
+ SHACL["SHACL Validation"]
36
+ RDFS["RDFS Reasoning"]
37
+ end
38
+
39
+ CLI --> Adapter
40
+ MCP --> Adapter
41
+ CLI --> Pipeline
42
+ Pipeline --> Adapter
43
+ ```
44
+
45
+ Existing ontology tools have terrible developer experience. OpenTology gives you managed RDF with a simple CLI -- initialize a project, write Turtle, validate with SHACL, push with automatic RDFS inference, and query, all from your terminal. It ships an MCP server so AI assistants can manage your knowledge graph directly. It runs in embedded mode with zero Docker dependency, or connects to an Oxigraph server over HTTP.
46
+
47
+ ### System Requirements
48
+
49
+ - **Node.js** >= 20.0.0
50
+ - **oxigraph** uses WebAssembly (WASM) — platform-independent, runs everywhere Node.js runs. No C++ compiler, Python, or native build tools needed.
51
+
52
+ ### Quick Demo
53
+
54
+ ```bash
55
+ # Zero-install embedded mode (no Docker!)
56
+ opentology init --embedded my-project
57
+
58
+ # Define ontology with class hierarchy
59
+ cat > ontology.ttl << 'EOF'
60
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
61
+ @prefix ex: <http://example.org/> .
62
+ ex:Person a rdfs:Class .
63
+ ex:Doctor rdfs:subClassOf ex:Person .
64
+ ex:Kim a ex:Doctor ; ex:name "Dr. Kim" .
65
+ ex:Lee a ex:Person ; ex:name "Lee" .
66
+ EOF
67
+
68
+ # Push with automatic RDFS inference
69
+ opentology push ontology.ttl
70
+ # -> Pushed 6 triples
71
+ # -> Inferred 1 additional triples
72
+
73
+ # Query: Doctor instances found as Person (inference!)
74
+ opentology query 'SELECT ?name WHERE { ?p a ex:Person . ?p ex:name ?name }'
75
+ # -> Kim, Lee (Kim is a Doctor, but inferred as Person)
76
+ ```
77
+
78
+ ### Push Pipeline
79
+
80
+ ```mermaid
81
+ graph LR
82
+ A["Write .ttl"] --> B["validate"]
83
+ B --> C{"SHACL shapes?"}
84
+ C -->|Yes| D["SHACL Check"]
85
+ C -->|No| E["push"]
86
+ D -->|Pass| E
87
+ D -->|Fail| F["Error"]
88
+ E --> G["RDFS Inference"]
89
+ G --> H["query"]
90
+ ```
91
+
92
+ ### Why OpenTology?
93
+
94
+ | | OpenTology | Raw Oxigraph | Neo4j |
95
+ |---|---|---|---|
96
+ | Setup | `npm install -g opentology` | Manual binary/Docker config | Server install + license |
97
+ | Docker required | No (embedded mode) | Yes | Yes |
98
+ | RDFS reasoning | Automatic on push | Manual SPARQL CONSTRUCT | Not native |
99
+ | SHACL validation | Built-in | Manual tooling | N/A |
100
+ | AI integration | MCP server with 11 tools | None | Plugin ecosystem |
101
+ | Query language | SPARQL (auto-prefixed) | SPARQL (raw) | Cypher |
102
+ | Data format | Turtle files | Turtle/N-Triples | Property graph |
103
+ | Project scoping | Automatic named graphs | Manual | Database-level |
104
+
105
+ ### Features
106
+
107
+ **Core**
108
+
109
+ - 14 CLI commands covering the full RDF lifecycle
110
+ - Project-level configuration with `.opentology.json`
111
+ - Named graph scoping -- queries are automatically scoped to your project
112
+ - Two modes: HTTP (Oxigraph server) and embedded (WASM, zero Docker)
113
+ - Prefix registry with auto-injection into SPARQL queries
114
+
115
+ **Reasoning**
116
+
117
+ - RDFS inference: subClassOf, subPropertyOf, domain, range
118
+ - Query `Person` and get `Doctor` instances automatically
119
+ - Auto-materialization on push, manual control with `infer`
120
+
121
+ **Validation**
122
+
123
+ - Turtle syntax validation before every push
124
+ - SHACL shape constraint validation
125
+ - `shapes/` directory convention for organizing shape files
126
+
127
+ **AI Integration**
128
+
129
+ - MCP server with 11 tools and 1 resource
130
+ - `opentology://schema` resource auto-loads ontology overview
131
+ - Works with Claude Code, Cursor, and any MCP-compatible client
132
+
133
+ ### Two Modes
134
+
135
+ | | HTTP Mode | Embedded Mode |
136
+ |---|---|---|
137
+ | Backend | Oxigraph server (Docker or binary) | In-process WASM store |
138
+ | Docker | Required | Not required |
139
+ | Init | `opentology init my-project` | `opentology init --embedded my-project` |
140
+ | Source of truth | Oxigraph server | Local `.ttl` files |
141
+ | Best for | Production, shared access | Local dev, quick experiments |
142
+ | Performance | Server-grade | Single-user |
143
+
144
+ ### Installation
145
+
146
+ ```bash
147
+ npm install -g opentology
148
+ ```
149
+
150
+ **Prerequisites:** Node.js 20+
151
+
152
+ For HTTP mode, you also need Oxigraph running:
153
+
154
+ ```bash
155
+ docker run -p 7878:7878 ghcr.io/oxigraph/oxigraph \
156
+ serve --location /data --bind 0.0.0.0:7878
157
+ ```
158
+
159
+ For embedded mode, no additional setup is needed.
160
+
161
+ ### CLI Commands
162
+
163
+ | Command | Description |
164
+ |---------|-------------|
165
+ | `opentology init [project-id]` | Initialize project (`--embedded` for Docker-free mode) |
166
+ | `opentology validate <file>` | Validate Turtle syntax (`--shacl` for SHACL validation) |
167
+ | `opentology push <file>` | Push triples with auto SHACL validation and RDFS inference (`--replace`, `--no-shacl`, `--no-infer`) |
168
+ | `opentology query <sparql>` | Run SPARQL with auto prefix injection (`--format table\|json\|csv`, `--raw`) |
169
+ | `opentology status` | Show asserted/inferred/total triple counts (file count in embedded mode) |
170
+ | `opentology pull` | Export project graph as Turtle |
171
+ | `opentology drop` | Drop the entire project graph (`--force` to skip confirmation) |
172
+ | `opentology delete <file>` | Delete triples from a file or by pattern (`--where`) |
173
+ | `opentology diff <file>` | Compare local Turtle file against the graph |
174
+ | `opentology shapes` | List or show SHACL shapes |
175
+ | `opentology infer` | Run RDFS materialization (`--clear` to remove inferred triples) |
176
+ | `opentology graph` | List, create, or drop named graphs |
177
+ | `opentology prefix` | List, add, or remove project prefixes |
178
+ | `opentology mcp` | Start the MCP server |
179
+
180
+ ### MCP Integration
181
+
182
+ Add to your MCP client configuration (`.mcp.json`):
183
+
184
+ ```json
185
+ {
186
+ "mcpServers": {
187
+ "opentology": {
188
+ "command": "npx",
189
+ "args": ["opentology", "mcp"]
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ **11 Tools:**
196
+
197
+ | Tool | Description |
198
+ |------|-------------|
199
+ | `opentology_init` | Initialize a project |
200
+ | `opentology_validate` | Validate Turtle content |
201
+ | `opentology_push` | Validate and push triples |
202
+ | `opentology_query` | Execute SPARQL queries |
203
+ | `opentology_status` | Get project status |
204
+ | `opentology_pull` | Export graph as Turtle |
205
+ | `opentology_drop` | Drop project graph |
206
+ | `opentology_delete` | Delete triples |
207
+ | `opentology_diff` | Compare local vs graph |
208
+ | `opentology_schema` | Introspect ontology schema |
209
+ | `opentology_infer` | Run RDFS inference |
210
+
211
+ **1 Resource:**
212
+
213
+ | Resource | Description |
214
+ |----------|-------------|
215
+ | `opentology://schema` | Auto-loaded ontology overview (classes, properties, instances) |
216
+
217
+ ### RDFS Reasoning
218
+
219
+ OpenTology automatically materializes RDFS inferences when you push data. If your ontology defines a class hierarchy, queries against a parent class return instances of all subclasses.
220
+
221
+ ```mermaid
222
+ graph TD
223
+ Kim["ex:Kim"] -->|a| Doctor["ex:Doctor"]
224
+ Doctor -->|rdfs:subClassOf| MedProf["ex:MedicalProfessional"]
225
+ MedProf -->|rdfs:subClassOf| Person["ex:Person"]
226
+ Kim -.->|inferred: a| MedProf
227
+ Kim -.->|inferred: a| Person
228
+
229
+ style Kim fill:#4CAF50,color:white
230
+ style Doctor fill:#2196F3,color:white
231
+ style MedProf fill:#2196F3,color:white
232
+ style Person fill:#2196F3,color:white
233
+ ```
234
+
235
+ Supported inference rules:
236
+
237
+ - **rdfs:subClassOf** -- instances of subclass are instances of superclass
238
+ - **rdfs:subPropertyOf** -- triples with subproperty imply triples with superproperty
239
+ - **rdfs:domain** -- using a property implies the subject is of the domain class
240
+ - **rdfs:range** -- using a property implies the object is of the range class
241
+
242
+ Use `opentology infer` to manually trigger materialization, or `opentology infer --clear` to remove inferred triples.
243
+
244
+ ### SHACL Validation
245
+
246
+ Place shape files in the `shapes/` directory. They are automatically validated on push.
247
+
248
+ ```turtle
249
+ # shapes/person-shape.ttl
250
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
251
+ @prefix ex: <http://example.org/> .
252
+
253
+ ex:PersonShape a sh:NodeShape ;
254
+ sh:targetClass ex:Person ;
255
+ sh:property [
256
+ sh:path ex:name ;
257
+ sh:minCount 1 ;
258
+ sh:datatype xsd:string ;
259
+ ] .
260
+ ```
261
+
262
+ ```bash
263
+ # Validate explicitly
264
+ opentology validate --shacl data.ttl
265
+
266
+ # Push auto-validates (skip with --no-shacl)
267
+ opentology push data.ttl
268
+
269
+ # List available shapes
270
+ opentology shapes
271
+ ```
272
+
273
+ ### Tech Stack
274
+
275
+ - TypeScript, commander.js, n3.js
276
+ - Oxigraph WASM (embedded mode) / Oxigraph server (HTTP mode)
277
+ - @modelcontextprotocol/sdk for MCP server
278
+ - shacl-engine for SHACL validation
279
+ - picocolors for terminal output
280
+
281
+ ### Roadmap
282
+
283
+ - [x] CLI with 14 commands
284
+ - [x] MCP server with 11 tools and 1 resource
285
+ - [x] Schema introspection (MCP resource + tool)
286
+ - [x] Complete CRUD (push --replace, drop, delete)
287
+ - [x] SHACL validation (shape constraints on push)
288
+ - [x] DX polish (diff, colors, better errors)
289
+ - [x] Multi-graph support
290
+ - [x] Prefix management
291
+ - [x] Embedded mode (no Docker required)
292
+ - [x] RDFS reasoning (auto-materialization on push)
293
+ - [ ] OWL reasoning (owl:sameAs, owl:inverseOf)
294
+ - [ ] Remote ontology import
295
+ - [ ] Version control for ontology snapshots
296
+ - [ ] Web UI for graph exploration
297
+
298
+ ### Contributing
299
+
300
+ 1. Fork the repository
301
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
302
+ 3. Commit your changes
303
+ 4. Open a Pull Request
304
+
305
+ ### License
306
+
307
+ MIT
308
+
309
+ ---
310
+
311
+ ## 한국어
312
+
313
+ ### 아키텍처
314
+
315
+ ```mermaid
316
+ graph TB
317
+ subgraph CLI["opentology CLI"]
318
+ Init[init]
319
+ Push[push]
320
+ Query[query]
321
+ Validate[validate]
322
+ Infer[infer]
323
+ More[...]
324
+ end
325
+
326
+ subgraph MCP["MCP Server"]
327
+ Tools[11 Tools]
328
+ Resource["opentology://schema"]
329
+ end
330
+
331
+ subgraph Adapter["StoreAdapter"]
332
+ HTTP["HTTP Mode\nOxigraph Server"]
333
+ Embedded["Embedded Mode\nWASM In-Process"]
334
+ end
335
+
336
+ subgraph Pipeline["Processing Pipeline"]
337
+ SHACL["SHACL Validation"]
338
+ RDFS["RDFS Reasoning"]
339
+ end
340
+
341
+ CLI --> Adapter
342
+ MCP --> Adapter
343
+ CLI --> Pipeline
344
+ Pipeline --> Adapter
345
+ ```
346
+
347
+ 온톨로지 도구들은 개발자 경험이 열악합니다. OpenTology는 터미널에서 RDF의 전체 생애주기를 관리합니다. 프로젝트 초기화, Turtle 작성, SHACL 검증, RDFS 추론이 포함된 푸시, SPARQL 쿼리까지 CLI 하나로 처리합니다. MCP 서버를 내장하고 있어 AI 어시스턴트가 지식 그래프를 직접 다룰 수 있고, Docker 없이 임베디드 모드로 바로 시작할 수 있습니다.
348
+
349
+ ### 시스템 요구사항
350
+
351
+ - **Node.js** >= 20.0.0
352
+ - **oxigraph**는 WebAssembly(WASM)를 사용하므로 플랫폼 독립적입니다. Node.js가 실행되는 모든 환경에서 동작하며, C++ 컴파일러, Python, 또는 네이티브 빌드 도구가 필요하지 않습니다.
353
+
354
+ ### 빠른 시작
355
+
356
+ ```bash
357
+ # Docker 없이 바로 시작 (임베디드 모드)
358
+ opentology init --embedded my-project
359
+
360
+ # 클래스 계층 구조가 포함된 온톨로지 작성
361
+ cat > ontology.ttl << 'EOF'
362
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
363
+ @prefix ex: <http://example.org/> .
364
+ ex:Person a rdfs:Class .
365
+ ex:Doctor rdfs:subClassOf ex:Person .
366
+ ex:Kim a ex:Doctor ; ex:name "Dr. Kim" .
367
+ ex:Lee a ex:Person ; ex:name "Lee" .
368
+ EOF
369
+
370
+ # RDFS 추론 포함 자동 푸시
371
+ opentology push ontology.ttl
372
+ # -> Pushed 6 triples
373
+ # -> Inferred 1 additional triples
374
+
375
+ # Doctor를 Person으로 자동 추론하여 결과에 포함
376
+ opentology query 'SELECT ?name WHERE { ?p a ex:Person . ?p ex:name ?name }'
377
+ # -> Kim, Lee (Kim은 Doctor이지만 Person으로 추론됨)
378
+ ```
379
+
380
+ ### 푸시 파이프라인
381
+
382
+ ```mermaid
383
+ graph LR
384
+ A["Write .ttl"] --> B["validate"]
385
+ B --> C{"SHACL shapes?"}
386
+ C -->|Yes| D["SHACL Check"]
387
+ C -->|No| E["push"]
388
+ D -->|Pass| E
389
+ D -->|Fail| F["Error"]
390
+ E --> G["RDFS Inference"]
391
+ G --> H["query"]
392
+ ```
393
+
394
+ ### OpenTology를 쓰는 이유
395
+
396
+ | | OpenTology | Oxigraph 직접 사용 | Neo4j |
397
+ |---|---|---|---|
398
+ | 설치 | `npm install -g opentology` | 바이너리/Docker 직접 구성 | 서버 설치 + 라이선스 |
399
+ | Docker 필수 | 아니오 (임베디드 모드) | 예 | 예 |
400
+ | RDFS 추론 | 푸시 시 자동 | SPARQL CONSTRUCT 수동 작성 | 네이티브 미지원 |
401
+ | SHACL 검증 | 내장 | 별도 도구 필요 | 해당 없음 |
402
+ | AI 연동 | MCP 서버 11개 도구 | 없음 | 플러그인 생태계 |
403
+ | 쿼리 언어 | SPARQL (접두사 자동 삽입) | SPARQL (수동) | Cypher |
404
+ | 데이터 형식 | Turtle 파일 | Turtle/N-Triples | 속성 그래프 |
405
+ | 프로젝트 구분 | Named Graph 자동 | 수동 관리 | 데이터베이스 단위 |
406
+
407
+ ### 주요 기능
408
+
409
+ **핵심**
410
+
411
+ - RDF 전체 생애주기를 다루는 14개 CLI 명령어
412
+ - `.opentology.json` 기반 프로젝트 설정
413
+ - Named Graph 자동 스코핑 -- 쿼리가 프로젝트 그래프에 자동 한정
414
+ - HTTP 모드(Oxigraph 서버)와 임베디드 모드(WASM, Docker 불필요) 지원
415
+ - 프로젝트 수준 접두사 레지스트리, SPARQL 쿼리에 자동 삽입
416
+
417
+ **추론**
418
+
419
+ - RDFS 추론: subClassOf, subPropertyOf, domain, range
420
+ - `Person`을 쿼리하면 `Doctor` 인스턴스도 자동 포함
421
+ - 푸시 시 자동 물질화, `infer` 명령어로 수동 제어
422
+
423
+ **검증**
424
+
425
+ - 푸시 전 Turtle 문법 자동 검증
426
+ - SHACL 형상 제약 조건 검증
427
+ - `shapes/` 디렉토리 규칙으로 형상 파일 관리
428
+
429
+ **AI 연동**
430
+
431
+ - 11개 도구와 1개 리소스를 제공하는 MCP 서버
432
+ - `opentology://schema` 리소스로 온톨로지 개요 자동 로드
433
+ - Claude Code, Cursor 등 MCP 호환 클라이언트와 연동
434
+
435
+ ### 두 가지 모드
436
+
437
+ | | HTTP 모드 | 임베디드 모드 |
438
+ |---|---|---|
439
+ | 백엔드 | Oxigraph 서버 (Docker 또는 바이너리) | 인프로세스 WASM 스토어 |
440
+ | Docker | 필요 | 불필요 |
441
+ | 초기화 | `opentology init my-project` | `opentology init --embedded my-project` |
442
+ | 원본 데이터 | Oxigraph 서버 | 로컬 `.ttl` 파일 |
443
+ | 적합한 용도 | 프로덕션, 공유 환경 | 로컬 개발, 빠른 실험 |
444
+ | 성능 | 서버급 | 단일 사용자 |
445
+
446
+ ### 설치
447
+
448
+ ```bash
449
+ npm install -g opentology
450
+ ```
451
+
452
+ **필수 조건:** Node.js 20+
453
+
454
+ HTTP 모드를 사용하려면 Oxigraph 서버가 필요합니다:
455
+
456
+ ```bash
457
+ docker run -p 7878:7878 ghcr.io/oxigraph/oxigraph \
458
+ serve --location /data --bind 0.0.0.0:7878
459
+ ```
460
+
461
+ 임베디드 모드는 추가 설치가 필요 없습니다.
462
+
463
+ ### CLI 명령어
464
+
465
+ | 명령어 | 설명 |
466
+ |--------|------|
467
+ | `opentology init [project-id]` | 프로젝트 초기화 (`--embedded`로 Docker 불필요 모드) |
468
+ | `opentology validate <file>` | Turtle 문법 검증 (`--shacl`로 SHACL 검증) |
469
+ | `opentology push <file>` | SHACL 자동 검증 + RDFS 추론 포함 푸시 (`--replace`, `--no-shacl`, `--no-infer`) |
470
+ | `opentology query <sparql>` | 접두사 자동 삽입 SPARQL 실행 (`--format table\|json\|csv`, `--raw`) |
471
+ | `opentology status` | asserted/inferred/total 트리플 수 표시 (임베디드 모드에서 파일 수 포함) |
472
+ | `opentology pull` | 프로젝트 그래프를 Turtle로 내보내기 |
473
+ | `opentology drop` | 프로젝트 그래프 전체 삭제 (`--force`로 확인 생략) |
474
+ | `opentology delete <file>` | 파일 또는 패턴(`--where`)으로 트리플 삭제 |
475
+ | `opentology diff <file>` | 로컬 Turtle 파일과 그래프 비교 |
476
+ | `opentology shapes` | SHACL 형상 목록 조회/상세 보기 |
477
+ | `opentology infer` | RDFS 물질화 실행 (`--clear`로 추론 트리플 제거) |
478
+ | `opentology graph` | Named Graph 목록/생성/삭제 |
479
+ | `opentology prefix` | 프로젝트 접두사 목록/추가/제거 |
480
+ | `opentology mcp` | MCP 서버 시작 |
481
+
482
+ ### MCP 연동
483
+
484
+ MCP 클라이언트 설정 파일(`.mcp.json`)에 추가:
485
+
486
+ ```json
487
+ {
488
+ "mcpServers": {
489
+ "opentology": {
490
+ "command": "npx",
491
+ "args": ["opentology", "mcp"]
492
+ }
493
+ }
494
+ }
495
+ ```
496
+
497
+ **11개 도구:**
498
+
499
+ | 도구 | 설명 |
500
+ |------|------|
501
+ | `opentology_init` | 프로젝트 초기화 |
502
+ | `opentology_validate` | Turtle 내용 검증 |
503
+ | `opentology_push` | 트리플 검증 및 푸시 |
504
+ | `opentology_query` | SPARQL 쿼리 실행 |
505
+ | `opentology_status` | 프로젝트 상태 조회 |
506
+ | `opentology_pull` | 그래프를 Turtle로 내보내기 |
507
+ | `opentology_drop` | 프로젝트 그래프 삭제 |
508
+ | `opentology_delete` | 트리플 삭제 |
509
+ | `opentology_diff` | 로컬 파일과 그래프 비교 |
510
+ | `opentology_schema` | 온톨로지 스키마 조회 |
511
+ | `opentology_infer` | RDFS 추론 실행 |
512
+
513
+ **1개 리소스:**
514
+
515
+ | 리소스 | 설명 |
516
+ |--------|------|
517
+ | `opentology://schema` | 온톨로지 개요 자동 로드 (클래스, 속성, 인스턴스) |
518
+
519
+ ### RDFS 추론
520
+
521
+ 데이터를 푸시하면 RDFS 추론이 자동으로 물질화됩니다. 온톨로지에 클래스 계층이 정의되어 있으면, 상위 클래스를 쿼리할 때 하위 클래스의 인스턴스도 함께 반환됩니다.
522
+
523
+ ```mermaid
524
+ graph TD
525
+ Kim["ex:Kim"] -->|a| Doctor["ex:Doctor"]
526
+ Doctor -->|rdfs:subClassOf| MedProf["ex:MedicalProfessional"]
527
+ MedProf -->|rdfs:subClassOf| Person["ex:Person"]
528
+ Kim -.->|inferred: a| MedProf
529
+ Kim -.->|inferred: a| Person
530
+
531
+ style Kim fill:#4CAF50,color:white
532
+ style Doctor fill:#2196F3,color:white
533
+ style MedProf fill:#2196F3,color:white
534
+ style Person fill:#2196F3,color:white
535
+ ```
536
+
537
+ 지원하는 추론 규칙:
538
+
539
+ - **rdfs:subClassOf** -- 하위 클래스의 인스턴스는 상위 클래스의 인스턴스
540
+ - **rdfs:subPropertyOf** -- 하위 속성의 트리플은 상위 속성의 트리플을 함의
541
+ - **rdfs:domain** -- 속성 사용 시 주어가 도메인 클래스의 인스턴스임을 함의
542
+ - **rdfs:range** -- 속성 사용 시 목적어가 범위 클래스의 인스턴스임을 함의
543
+
544
+ `opentology infer`로 수동 물질화, `opentology infer --clear`로 추론 트리플 제거가 가능합니다.
545
+
546
+ ### SHACL 검증
547
+
548
+ `shapes/` 디렉토리에 형상 파일을 배치하면 푸시 시 자동으로 검증됩니다.
549
+
550
+ ```turtle
551
+ # shapes/person-shape.ttl
552
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
553
+ @prefix ex: <http://example.org/> .
554
+
555
+ ex:PersonShape a sh:NodeShape ;
556
+ sh:targetClass ex:Person ;
557
+ sh:property [
558
+ sh:path ex:name ;
559
+ sh:minCount 1 ;
560
+ sh:datatype xsd:string ;
561
+ ] .
562
+ ```
563
+
564
+ ```bash
565
+ # 명시적 검증
566
+ opentology validate --shacl data.ttl
567
+
568
+ # 푸시 시 자동 검증 (--no-shacl로 생략 가능)
569
+ opentology push data.ttl
570
+
571
+ # 등록된 형상 목록 조회
572
+ opentology shapes
573
+ ```
574
+
575
+ ### 기술 스택
576
+
577
+ - TypeScript, commander.js, n3.js
578
+ - Oxigraph WASM (임베디드 모드) / Oxigraph 서버 (HTTP 모드)
579
+ - @modelcontextprotocol/sdk (MCP 서버)
580
+ - shacl-engine (SHACL 검증)
581
+ - picocolors (터미널 출력)
582
+
583
+ ### 로드맵
584
+
585
+ - [x] 14개 CLI 명령어
586
+ - [x] 11개 도구와 1개 리소스를 갖춘 MCP 서버
587
+ - [x] 스키마 조회 (MCP 리소스 + 도구)
588
+ - [x] 완전한 CRUD (push --replace, drop, delete)
589
+ - [x] SHACL 검증 (푸시 시 형상 제약 자동 검증)
590
+ - [x] DX 개선 (diff, 컬러 출력, 에러 메시지)
591
+ - [x] 멀티 그래프 지원
592
+ - [x] 접두사 관리
593
+ - [x] 임베디드 모드 (Docker 불필요)
594
+ - [x] RDFS 추론 (푸시 시 자동 물질화)
595
+ - [ ] OWL 추론 (owl:sameAs, owl:inverseOf)
596
+ - [ ] 원격 온톨로지 임포트
597
+ - [ ] 온톨로지 스냅샷 버전 관리
598
+ - [ ] 그래프 탐색 웹 UI
599
+
600
+ ### 기여 방법
601
+
602
+ 1. 저장소를 포크합니다
603
+ 2. 기능 브랜치를 만듭니다 (`git checkout -b feature/my-feature`)
604
+ 3. 변경사항을 커밋합니다
605
+ 4. Pull Request를 열어주세요
606
+
607
+ ### 라이선스
608
+
609
+ MIT
@@ -0,0 +1,29 @@
1
+ import { Command } from 'commander';
2
+ export interface ContextLoadOutput {
3
+ projectId: string;
4
+ graphUri: string;
5
+ sessions: Array<{
6
+ uri: string;
7
+ title: string;
8
+ date: string;
9
+ nextTodo?: string;
10
+ }>;
11
+ openIssues: Array<{
12
+ uri: string;
13
+ title: string;
14
+ date: string;
15
+ }>;
16
+ recentDecisions: Array<{
17
+ uri: string;
18
+ title: string;
19
+ date: string;
20
+ reason?: string;
21
+ }>;
22
+ meta: {
23
+ contextTripleCount: number;
24
+ sessionsTripleCount: number;
25
+ loadedAt: string;
26
+ };
27
+ warnings?: string[];
28
+ }
29
+ export declare function registerContext(program: Command): void;