Full Understanding of Mutual Inconsistencies in Administrative Markup Items - Contradiction detection system for regulation documents using HTML GraphRAG
npm install fumiamiFull Understanding of Mutual Inconsistencies in Administrative Markup Items
大学規定集等のHTML文書をHTML GraphRAGを用いて解析し、規定間の矛盾・不整合を自動検出するシステム。



1. 矛盾検出 - 規定文書内の矛盾を自動検出
2. 影響分析 - 規定変更時に影響を受ける条項を特定
```
fumiami/
├── packages/
│ ├── esperanto-ts/ # LLM/Embedding統合インターフェース
│ ├── graphrag/ # HTML GraphRAG (パーサー, チャンカー, グラフ)
│ └── detector/ # 矛盾検出 + 影響分析
└── samples/
└── u-tokyo/ # 東京大学規則集サンプル
| パッケージ | 説明 |
|-----------|------|
| @fumiami/esperanto-ts | Azure AI Foundry / Ollama 統一インターフェース |@fumiami/graphrag
| | HTML文書のGraphRAG処理 |@fumiami/detector
| | 矛盾検出・影響分析エンジン |
`bashnpm からインストール
npm install fumiami
$3
`bash
リポジトリをクローン
git clone https://github.com/nahisaho/FUMIAMI.git
cd FUMIAMI/fumiami依存関係をインストール
pnpm installビルド
pnpm build
`$3
#### 1. グラフ構築
`typescript
import { GraphBuilder, AIFactory } from 'fumiami';// Ollama使用(ローカル)
const factory = AIFactory.ollama('http://localhost:11434');
const embedding = factory.createEmbeddingModel({ model: 'nomic-embed-text' });
// グラフ構築
const builder = new GraphBuilder();
builder.setEmbeddingModel(embedding);
const result = await builder.buildFromHTML(html, 'regulation.html');
const graph = builder.getGraph();
`#### 2. 矛盾検出
`typescript
import { ContradictionDetector } from 'fumiami';const detector = new ContradictionDetector();
const detection = await detector.detect(graph);
console.log('矛盾:', detection.contradictions);
`#### 3. 影響分析
`typescript
import { ImpactAnalyzer } from 'fumiami';const analyzer = new ImpactAnalyzer();
const impact = await analyzer.analyze(graph, 'chunk-id-of-article-3');
console.log('影響を受ける条項:', impact.impactedArticles);
`$3
`bash
グラフ構築
npx fumiami build ./path/to/regulation.html -o ./graph.json矛盾検出
npx fumiami detect ./graph.json影響分析
npx fumiami impact ./graph.json 第3条
`🔧 開発
$3
- Node.js 20+
- pnpm 8+
- Ollama(ローカルLLM使用時)
$3
`bash
全パッケージのテスト
pnpm -r test:run個別パッケージ
cd packages/esperanto-ts && pnpm test:run
cd packages/graphrag && pnpm test:run
cd packages/detector && pnpm test:run
`$3
FUMIAMIは Ollama(ローカルLLM)と Azure AI Foundry(クラウド)の2つのAIプロバイダーをサポートしています。
---
#### Ollama(ローカル)
ローカル環境でLLMを実行する場合に使用します。
##### 1. Ollamaのインストール
`bash
Linux/WSL
curl -fsSL https://ollama.com/install.sh | shmacOS
brew install ollama起動
ollama serve
`##### 2. 必要なモデルをダウンロード
`bash
Embeddingモデル(必須)
ollama pull nomic-embed-text言語モデル(オプション - 将来のLLM連携用)
ollama pull qwen2.5:7b
`##### 3. TypeScriptでの使用
`typescript
import { AIFactory } from '@fumiami/esperanto-ts';// 方法1: 静的ファクトリーメソッド(推奨)
const factory = AIFactory.ollama('http://localhost:11434');
// 方法2: モデルを指定して初期化
const factory = AIFactory.ollama('http://localhost:11434', {
embeddingModel: 'nomic-embed-text',
languageModel: 'qwen2.5:7b',
systemPrompt: 'あなたは規定文書の専門家です。',
});
// Embeddingモデルを作成
const embedding = factory.createEmbeddingModel({ model: 'nomic-embed-text' });
// ベクトル生成
const result = await embedding.embed('第1条 この規則は...');
console.log(result.embedding); // number[]
`##### 4. CLI使用時の設定
`bash
graphragでOllamaを使用
npx graphrag build ./regulation.html -o ./graph.json \
--ollama-url http://localhost:11434 \
--embedding-model nomic-embed-text
`---
#### Azure AI Foundry(クラウド)
Azure AI Foundryのモデルを使用する場合に設定します。
##### 1. 環境変数の設定
プロジェクトルートに
.env ファイルを作成:`bash
fumiami/.env
AZURE_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_API_KEY=your-api-key-here
AZURE_API_VERSION=2024-02-15-preview
`##### 2. TypeScriptでの使用
`typescript
import { AIFactory } from '@fumiami/esperanto-ts';
import dotenv from 'dotenv';// 環境変数を読み込み
dotenv.config();
// 方法1: 静的ファクトリーメソッド(推奨)
const factory = AIFactory.azure(
process.env.AZURE_ENDPOINT!,
process.env.AZURE_API_KEY!
);
// 方法2: オプション付きで初期化
const factory = AIFactory.azure(
process.env.AZURE_ENDPOINT!,
process.env.AZURE_API_KEY!,
{
embeddingModel: 'text-embedding-ada-002',
languageModel: 'gpt-4',
apiVersion: '2024-02-15-preview',
}
);
// Embeddingモデルを作成
const embedding = factory.createEmbeddingModel({
model: 'text-embedding-ada-002'
});
// ベクトル生成
const result = await embedding.embed('第1条 この規則は...');
`##### 3. Azure AI Foundryの設定型
`typescript
interface AzureConfig {
provider: 'azure';
endpoint: string; // Azure OpenAIのエンドポイントURL
apiKey: string; // APIキー
apiVersion?: string; // APIバージョン(省略時はデフォルト値)
}
`---
#### 設定の優先順位
1. メソッド引数 -
createEmbeddingModel({ model: '...' }) で直接指定
2. ファクトリー初期化時 - AIFactory.ollama(url, { embeddingModel: '...' })
3. デフォルト値 - 設定がない場合はエラー`typescript
// ファクトリー初期化時にデフォルトモデルを設定
const factory = AIFactory.ollama('http://localhost:11434', {
embeddingModel: 'nomic-embed-text',
});// デフォルトモデルを使用
const embedding1 = factory.createEmbeddingModel();
// 別のモデルを指定して上書き
const embedding2 = factory.createEmbeddingModel({ model: 'mxbai-embed-large' });
`---
#### 推奨モデル
| プロバイダー | 用途 | 推奨モデル |
|-------------|------|-----------|
| Ollama | Embedding |
nomic-embed-text, mxbai-embed-large |
| Ollama | 言語モデル | qwen2.5:7b, llama3.1:8b |
| Azure | Embedding | text-embedding-ada-002, text-embedding-3-small |
| Azure | 言語モデル | gpt-4, gpt-4o, gpt-35-turbo |📊 検出可能な矛盾タイプ
| タイプ | 説明 | 例 |
|--------|------|-----|
|
definition | 同一用語の定義矛盾 | 「学生」の定義が複数存在 |
| numeric | 数値の矛盾 | 期限が「14日」と「20日」で異なる |
| condition | 条件の論理矛盾 | 条件が相互に矛盾 |
| temporal | 時期・期限の矛盾 | 締切日が複数存在 |
| reference | 参照矛盾 | 存在しない条項への参照 |📊 影響タイプ
| タイプ | 説明 | 深刻度 |
|--------|------|--------|
|
direct-reference | 直接参照している条項 | high |
| definition-usage | 定義された用語を使用 | medium |
| condition-chain | 条件の前提として参照 | critical |
| structural-child | 構造的な子要素 | critical |
| structural-sibling | 同一章・節内の条項 | low |
| semantic-similar | 意味的に類似した条項 | low-high |📁 サンプルデータ
samples/u-tokyo/ に東京大学規則集のサンプルデータがあります。`bash
サンプルで矛盾検出を試す
cd packages/graphrag
npx graphrag build ../samples/u-tokyo/html/学部通則.html -o ./cache/gakubu.jsoncd ../detector
npx detector detect ../graphrag/cache/gakubu.json
``MIT License
Issue・PRを歓迎します。
---
Project: FUMIAMI
Version: 0.1.0
Date: 2026-01-14