defmodule Mix.Tasks.ExOkf.Graph do @shortdoc "Show the concept link graph" @moduledoc """ Prints graph statistics and edges for an OKF bundle. mix ex_okf.graph path/to/bundle mix ex_okf.graph path/to/bundle --backend adjacency """ use Mix.Task @impl Mix.Task def run(args) do {opts, paths, _} = OptionParser.parse(args, strict: [backend: :string, edges: :boolean]) path = List.first(paths) || Mix.raise("Usage: mix ex_okf.graph PATH") backend = case opts[:backend] do "graphblas" -> ExOKF.Graph.GraphBLAS "adjacency" -> ExOKF.Graph.Adjacency nil -> ExOKF.Graph.Adjacency other -> Mix.raise("Unknown backend: #{other}") end {:ok, bundle} = ExOKF.load(path, build_graph: false) bundle = ExOKF.Graph.index(bundle, backend) stats = ExOKF.Graph.stats(bundle) Mix.shell().info("Backend: #{inspect(stats.backend)}") Mix.shell().info("Nodes: #{stats.nodes}") Mix.shell().info("Edges: #{stats.edges}") if opts[:edges] != false do Mix.shell().info("\nEdges:") for {from, to} <- ExOKF.Graph.edges(bundle) do Mix.shell().info(" #{from} -> #{to}") end end :ok end end