Packages

Idiomatic Elixir interface to the Tesseract OCR engine via a NIF, accepting Vix.Vips.Image structs, file paths, or in-memory image binaries.

Current section

Files

Jump to
image_ocr lib mix tasks image.ocr.tessdata.list.ex
Raw

lib/mix/tasks/image.ocr.tessdata.list.ex

defmodule Mix.Tasks.Image.Ocr.Tessdata.List do
@shortdoc "List installed Tesseract trained-data files"
@moduledoc """
Lists every `<language>.traineddata` file in the resolved trained-data
directory along with provenance from the manifest.
## Usage
mix image.ocr.tessdata.list [--path DIR]
"""
use Mix.Task
alias Image.OCR.{Languages, Tessdata}
alias Image.OCR.Tessdata.Manifest
@switches [path: :string]
@impl Mix.Task
def run(args) do
{opts, _, _} = OptionParser.parse(args, switches: @switches)
Mix.Task.run("app.config")
dest = opts[:path] || Tessdata.datapath()
Mix.shell().info("Trained-data directory: #{dest}")
languages = Tessdata.installed_languages(datapath: dest)
if languages == [] do
Mix.shell().info("(no trained-data files found)")
else
manifest = Manifest.read(dest)
Enum.each(languages, fn lang ->
iso = Languages.from_tesseract(lang)
label = if iso == lang, do: lang, else: "#{iso} (#{lang})"
case Map.get(manifest, lang) do
nil ->
Mix.shell().info(" #{label} (no manifest entry)")
entry ->
Mix.shell().info(
" #{label} variant=#{entry.variant} branch=#{entry.branch} " <>
"size=#{entry.size}B sha256=#{String.slice(entry.sha256, 0, 12)}… " <>
"fetched=#{entry.fetched_at}"
)
end
end)
end
end
end