Skip to main content

MAGATAMA Core - Knowledge Graph Engine for Code Analysis

Project description

magatama-core - Knowledge Graph Engine

PyPI version Python 3.11+ License: MIT

MAGATAMAYATA のフォーク)の コアライブラリパッケージです(パッケージ名 magatama-core / import 名 magatama_core)。

独立したライブラリとして、コード解析と知識グラフ構築機能を提供します。

特徴

  • 🔍 マルチ言語解析: Python, TypeScript, Rust, Go, Java, C# ほか 24 言語
  • 🕸️ 知識グラフ: NetworkX によるエンティティ・関係性グラフ
  • 🔗 関係性検出: CALLS, IMPORTS, CONTAINS, INHERITS
  • 💾 永続化: JSON / SQLite ストレージ

インストール

pip install magatama-core

オプション言語サポート

# Rust サポート
pip install magatama-core[rust]

# Go サポート
pip install magatama-core[go]

# 全言語サポート
pip install magatama-core[all-languages]

使用方法

基本的な使い方

from magatama_core.infrastructure.parsers import PythonParser
from magatama_core.infrastructure.storage import NetworkXKnowledgeGraph
from magatama_core.application.usecases import ParseFileUseCase

# パーサーとグラフを作成
parser = PythonParser()
graph = NetworkXKnowledgeGraph()

# ユースケースを設定
parse_file = ParseFileUseCase(
    parsers={".py": parser},
    knowledge_graph=graph,
)

# ファイルを解析
from pathlib import Path
result = parse_file.execute(Path("your_file.py"))

print(f"Entities: {result.entity_count}")
print(f"Relationships: {result.relationship_count}")

エンティティの検索

from magatama_core.domain.entities import EntityType

# 関数をすべて取得
functions = list(graph.entities.get_by_type(EntityType.FUNCTION))

# 名前で検索
all_entities = list(graph.entities.all())
matches = [e for e in all_entities if "process" in e.name.lower()]

グラフの永続化

from magatama_core.infrastructure.storage import JSONGraphSerializer

serializer = JSONGraphSerializer()

# 保存
serializer.save(graph, Path("graph.json"))

# 読み込み
loaded_graph = serializer.load(Path("graph.json"))

アーキテクチャ

magatama-core は Clean Architecture に基づいて設計されています:

magatama_core/
├── domain/          # ドメイン層
│   ├── entities/    # FunctionEntity, ClassEntity, etc.
│   ├── value_objects/ # EntityId, Location
│   └── repositories/ # インターフェース
├── application/     # アプリケーション層
│   ├── usecases/    # ParseFileUseCase, etc.
│   └── services/    # Benchmark, etc.
└── infrastructure/  # インフラ層
    ├── parsers/     # PythonParser, TypeScriptParser, etc.
    └── storage/     # NetworkXKnowledgeGraph, SQLiteKnowledgeGraph

対応言語

合計 24 言語に対応しています(主要なものを抜粋)。全一覧は ルート README を参照。

言語 拡張子 パーサー
Python .py PythonParser
TypeScript .ts, .tsx TypeScriptParser
JavaScript .js, .jsx JavaScriptParser
Rust .rs RustParser
Go .go GoParser
Java / C# / C / C++ / Ruby / PHP ほか (計 24 言語)

ライセンス

MIT License - 詳細は LICENSE を参照してください。

関連プロジェクト

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magatama_core-0.5.2.tar.gz (152.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magatama_core-0.5.2-py3-none-any.whl (135.9 kB view details)

Uploaded Python 3

File details

Details for the file magatama_core-0.5.2.tar.gz.

File metadata

  • Download URL: magatama_core-0.5.2.tar.gz
  • Upload date:
  • Size: 152.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for magatama_core-0.5.2.tar.gz
Algorithm Hash digest
SHA256 0621c9a9b9b07e28d10aa262138161e9190f02ed7cb0eb65cd2e79582bb9cb3f
MD5 07212d802d3146d4be2f03f949c974a8
BLAKE2b-256 485bf418890965c7c42ebbd43317c2aa838db41f0169f61982e35ec8506bc410

See more details on using hashes here.

File details

Details for the file magatama_core-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: magatama_core-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 135.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for magatama_core-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 44557920012a19a6675849279c83c0ecb35feb0096326230aeceb7ac24cb8408
MD5 5bfcde4424243ee5de21ff9999dd04a8
BLAKE2b-256 098a48b5518d8bc6dc1e9686602d6d378860a6fd30af75e2767bd9fe7d279b5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page