← 返回 Skills 市场
fisa712

Knowledge Graph - Transitive Closure Generator

作者 Muhammad Asif · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
30
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install transitive-closure-generator
功能描述
Compute transitive closure on graphs to infer implicit relationships and expand graphs with logically implied connections. Supports multiple algorithms and c...
使用说明 (SKILL.md)

Transitive Closure Generator

Compute transitive closure on graphs to automatically infer implicit relationships and expand knowledge graphs.

This skill computes the transitive closure of relations, deriving all logically implied connections from existing relationships and materializing them as explicit edges.

Quick Start

Use When

  • Computing ancestor relationships from parent chains
  • Inferring dependency chains in software
  • Expanding hierarchical relationships
  • Finding reachability in networks
  • Materializing transitive relations
  • Analyzing organizational hierarchies
  • Building complete dependency graphs
  • Expanding knowledge graph completeness

Inputs

  • Graph edges (relationship pairs)
  • Relation type to compute closure for
  • Optional: Maximum depth/hops
  • Optional: Cycle detection and handling

Outputs

  • Transitive closure edges (all reachable pairs)
  • Path information (distances, intermediates)
  • Reachability analysis
  • Cycle detection results
  • Statistics and metrics

Transitive Closure Concepts

Transitive Relation

A relation where if A→B and B→C then A→C.

Examples:

ancestor_of:      A ancestor_of B ∧ B ancestor_of C ⇒ A ancestor_of C
depends_on:       A depends B ∧ B depends C ⇒ A depends C
located_in:       Paris located_in France ∧ France located_in Europe ⇒ Paris located_in Europe
subclass_of:      Dog subclass_of Mammal ∧ Mammal subclass_of Animal ⇒ Dog subclass_of Animal

Non-Transitive Relations

Relations where transitivity doesn't apply:

friend_of:        A friend B ∧ B friend C ⇏ A friend C (not necessarily)
married_to:       A married B ∧ B married C ⇏ A married C (false)
knows:            A knows B ∧ B knows C ⇏ A knows C (uncertain)

Transitive Closure Set

The complete set of all pairs (a,b) where a can reach b.

Example:

Original edges:
  A → B
  B → C
  C → D

Transitive closure:
  Direct:   A→B, B→C, C→D (3 edges)
  Inferred: A→C, A→D, B→D (3 additional edges)
  Total:    6 edges

Path Materialization

Converting implicit paths into explicit edges.

Implicit chain: A ---> B ---> C ---> D
Materialized:   A → C (2 hops), A → D (3 hops), etc.

Reachability

Set of all nodes reachable from a given node.

From A: {B, C, D}
From B: {C, D}
From C: {D}

Closure Computation Algorithms

Algorithm 1: Depth-First Search (DFS)

Find all reachable nodes from each source node.

Complexity: O(V * (V + E))
Space: O(V)
Best For: Small to medium graphs

For each node N:
  Visited = {}
  DFS(N, Visited)
  Add all visited nodes as reachable

Algorithm 2: Breadth-First Search (BFS)

Level-by-level traversal to find all reachable nodes.

Complexity: O(V * (V + E))
Space: O(V)
Best For: Finding shortest paths, layered structures

For each node N:
  Queue = {N}
  While Queue not empty:
    Current = Queue.pop()
    For each neighbor of Current:
      If not visited:
        Mark visited
        Add to closure
        Queue.push(neighbor)

Algorithm 3: Floyd-Warshall

Compute all-pairs shortest paths and closure simultaneously.

Complexity: O(V³)
Space: O(V²)
Best For: Dense graphs, need all distances

D[i][j] = direct edge weight or ∞
For each intermediate k:
  For each pair (i,j):
    D[i][j] = min(D[i][j], D[i][k] + D[k][j])
    If D[i][j] \x3C ∞, add to closure

Algorithm 4: Warshall's Algorithm

Specialized for transitive closure computation.

Complexity: O(V³)
Space: O(V²)
Best For: Dense graphs, pure closure (no distances)

TC[i][j] = 1 if edge exists, 0 otherwise
For each k in 0..V:
  For each i in 0..V:
    For each j in 0..V:
      TC[i][j] = TC[i][j] OR (TC[i][k] AND TC[k][j])

Algorithm 5: Incremental Closure

Update closure incrementally when edges are added.

Complexity: O(added_edges * V)
Space: O(V²)
Best For: Dynamic graphs, continuous updates

On add edge (u, v):
  Mark TC[u][v] = 1
  For all (i,u) and (v,j) in TC:
    Mark TC[i][j] = 1
  Propagate transitively

Cycle Detection

DAG Assumption

Most transitive closure algorithms assume acyclic graphs (DAGs).

Cycles cause:

  • Infinite expansion
  • Incorrect closure results
  • Performance issues

Detection Methods

Method 1: Color-Based DFS

Colors: White (unvisited), Gray (visiting), Black (done)
If reach Gray node: cycle detected

Method 2: Topological Sort

If can't perform complete topological sort: contains cycle

Method 3: Negative Weight Cycles (Bellman-Ford)

If shortest path becomes negative: cycle in weight sense

Materialization Strategies

Full Materialization

Store all closure edges explicitly.

Pros: O(1) query, no computation needed
Cons: Storage overhead O(V²), update cost

Lazy Computation

Compute paths on-demand.

Pros: No storage overhead
Cons: Query time O(V+E), repeated computation

Hybrid Approach

Materialize high-value closures, compute others on-demand.

Pros: Balanced cost/benefit
Cons: Complexity

Performance Optimization

Optimization 1: Memoization

Cache computed reachability sets.

reachable_cache = {}
def get_reachable(node):
    if node in reachable_cache:
        return reachable_cache[node]
    result = compute_reachable_bfs(node)
    reachable_cache[node] = result
    return result

Optimization 2: Incremental Updates

Update only affected paths when new edges added.

New edge (u, v):
  - Find all nodes that can reach u
  - Find all nodes reachable from v
  - Add edges from reaching→v reachable

Optimization 3: Bidirectional Search

Search from both source and target.

Forward reach from source
Backward reach to target
Intersection = connected pairs

Error Handling

Common Issues

Issue Cause Solution
Infinite loop Cycles in graph Detect and handle cycles
Memory overflow Too many inferred edges Lazy materialization, sampling
Performance timeout O(V³) on large graph Use faster algorithm, incremental
Incorrect results Assuming non-transitive as transitive Validate relation type
Duplicate edges Not deduplicating Track seen edges

Best Practices

Verify transitivity - Ensure relation is truly transitive
Detect cycles early - Prevent infinite loops
Choose right algorithm - Match to graph size and density
Use memoization - Cache frequently computed paths
Handle large graphs - Consider lazy evaluation
Monitor performance - Track closure computation time
Validate results - Check for correctness
Consider updates - Plan for incremental changes
Document assumptions - Clarify which relations are transitive
Test with sample data - Verify on small graphs first

Advanced Features

Weighted Transitive Closure

Compute closure with edge weights (e.g., confidence, cost).

Probabilistic Closure

Handle uncertain relationships with confidence scores.

Temporal Closure

Time-aware transitive closure considering timestamps.

Approximate Closure

Fast approximation for large graphs.

Cross-Graph Closure

Compute closure across multiple interconnected graphs.

Integration Points

This skill integrates with:

  • Graph Rule Engine Builder - Define transitive rules
  • Ontology-Based Inference - Compute ontology closure
  • Causal Chain Analyzer - Analyze causal chains
  • Graph Path Reasoning Analyzer - Find reachable paths
  • Multi-Hop Reasoning Query Builder - Build queries

Recommended Libraries

Graph Algorithms

  • networkx - DFS, BFS, topological sort
  • scipy.sparse - Sparse matrix operations
  • numpy - Matrix operations for Warshall

Optimization

  • functools.lru_cache - Memoization
  • collections.deque - Queue for BFS

Analysis

  • igraph - Fast graph algorithms
  • graph-tool - High-performance analysis

Related Skills

  • Graph Rule Engine Builder - Define transitive rules
  • Ontology-Based Inference - Class hierarchy closure
  • Causal Chain Analyzer - Analyze causal paths
  • Graph Path Reasoning Analyzer - Find all paths
  • Multi-Hop Reasoning Query Builder - Complex queries

Version: 1.0.0

安全使用建议
Install only if you are comfortable treating it as a basic local transitive-closure helper. Do not rely on its advertised cycle-detection result or unsupported algorithms until those gaps are fixed and tested.
能力评估
Purpose & Capability
The files coherently describe and implement transitive-closure graph analysis, but the capability is overstated: cycle detection is advertised and configured while the code never sets has_cycle, and some named algorithms fall back to BFS.
Instruction Scope
The runtime instructions are educational and task-scoped; no prompt override, automatic activation, credential collection, hidden networking, or broad agent control instructions were found.
Install Mechanism
The artifact is a small documentation-and-Python bundle using only standard-library imports; there are no package installs, dependency downloads, or setup hooks.
Credentials
The script operates on user-provided graph edges in memory and prints an example when run directly; it does not read local private files, use credentials, access the network, or mutate external systems.
Persistence & Privilege
No persistence, background workers, scheduled tasks, privilege escalation, or durable local state were found.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install transitive-closure-generator
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /transitive-closure-generator 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release – compute transitive closure on graphs, supporting inference, expansion, and cycle detection. - Supports multiple algorithms for closure computation, including DFS, BFS, Floyd-Warshall, and incremental methods. - Handles cycle detection with common techniques such as DFS coloring and topological sort. - Outputs closure edges, reachability data, path information, and cycle analysis. - Includes strategies for materialization and optimizations for performance. - Provides guidance and best practices for use in dependency analysis, hierarchies, reachability, and related tasks.
元数据
Slug transitive-closure-generator
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Knowledge Graph - Transitive Closure Generator 是什么?

Compute transitive closure on graphs to infer implicit relationships and expand graphs with logically implied connections. Supports multiple algorithms and c... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 30 次。

如何安装 Knowledge Graph - Transitive Closure Generator?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install transitive-closure-generator」即可一键安装,无需额外配置。

Knowledge Graph - Transitive Closure Generator 是免费的吗?

是的,Knowledge Graph - Transitive Closure Generator 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Knowledge Graph - Transitive Closure Generator 支持哪些平台?

Knowledge Graph - Transitive Closure Generator 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Knowledge Graph - Transitive Closure Generator?

由 Muhammad Asif(@fisa712)开发并维护,当前版本 v1.0.0。

💬 留言讨论