feat: initial text-extract v0.1.0 (text.extract@0.1.0)
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
First real F∆I capability module. Ships as alpha in the store
index — installable, but layout-naive PDF extraction. Bumps to
1.0.0 require either the planned service-mode variant
(host-services-backed pdfium/mupdf) or confirmed-good
extraction quality on a representative document set.
Capability surface:
Inputs: document : bytes (PDF or DOCX)
Outputs: extracted : json (ExtractedDocument)
Permissions: none — pure in-WASM, no filesystem, no network
Output schema:
{
"engine": "pdf-extract" | "zip+quick-xml",
"engine_version": "<version>",
"pages": [{ "number": <u32>, "text": <string>,
"confidence?": <f64>, "bbox?": {x,y,w,h} }]
}
The optional confidence and bbox fields are reserved for the
future service-mode variant. The host-services infrastructure
that backs pdfium/mupdf does not exist yet (Phase 0.5+); when
it lands, text-extract v0.2.0 will populate these fields without
an API break.
Engines:
PDF: pdf-extract 0.7 (pure Rust, MIT-licensed). Single-column
documents extract reliably. Multi-column or table-heavy
layouts may produce reordered text — documented in
README as a known limitation of the in-WASM v0.1.0 path.
DOCX: ad-hoc parser using the zip and quick-xml crates. Walks
word/document.xml, concatenates run-level text, inserts a
newline at each paragraph boundary. Tables, footnotes,
and embedded objects are not extracted in v0.1.0.
The module is the first reference user of fai-module-sdk. The
public surface is one #[fai_module] function — no wit_bindgen,
no Guest impl, no allow attributes. Testing surface is the same
function via crate-type = ["cdylib", "rlib"]; the SDK macro
gates its WASM glue on target_arch = "wasm32" so host integration
tests work out of the box.
Tests: 6 unit + 3 integration, all green. The DOCX integration
test builds a minimal valid DOCX in memory and verifies the
JSON output schema. PDF integration coverage will land in a
follow-up once a representative test fixture is bundled.
The Forgejo CI workflow clones fai/module-sdk into a sibling
location to satisfy the path-based dev dependency. The path
will switch to a versioned git tag once SDK releases stabilize.
Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
commit
cc72db0421
11 changed files with 1580 additions and 0 deletions
88
.forgejo/workflows/ci.yml
Normal file
88
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
RUSTFLAGS: "-D warnings"
|
||||||
|
RUST_TOOLCHAIN: "1.86"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
name: Linux x86_64 (Forgejo)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Manual external-URL checkout — see fai/platform CI for
|
||||||
|
# background. Lays this repo at $GITHUB_WORKSPACE.
|
||||||
|
- name: Checkout text-extract via external URL
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
mkdir -p "$GITHUB_WORKSPACE"
|
||||||
|
cd "$GITHUB_WORKSPACE"
|
||||||
|
git init -q
|
||||||
|
git remote add origin \
|
||||||
|
"https://x-access-token:${GITHUB_TOKEN}@git.flemming.ws/${GITHUB_REPOSITORY}.git"
|
||||||
|
git fetch --depth=1 origin "$GITHUB_SHA"
|
||||||
|
git checkout -q FETCH_HEAD
|
||||||
|
|
||||||
|
# text-extract depends on fai-module-sdk via a sibling-path
|
||||||
|
# dependency: ../../module_sdk/crates/fai-module-sdk
|
||||||
|
# We materialize that layout by cloning module-sdk two
|
||||||
|
# levels up from $GITHUB_WORKSPACE. This is a transient
|
||||||
|
# arrangement until the SDK is published as a versioned
|
||||||
|
# git tag or registry crate.
|
||||||
|
- name: Checkout fai/module-sdk into sibling layout
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
parent="$(dirname "$GITHUB_WORKSPACE")"
|
||||||
|
grandparent="$(dirname "$parent")"
|
||||||
|
sdk_dir="$grandparent/module_sdk"
|
||||||
|
mkdir -p "$sdk_dir"
|
||||||
|
cd "$sdk_dir"
|
||||||
|
git init -q
|
||||||
|
git remote add origin \
|
||||||
|
"https://x-access-token:${GITHUB_TOKEN}@git.flemming.ws/fai/module-sdk.git"
|
||||||
|
git fetch --depth=1 origin main
|
||||||
|
git checkout -q FETCH_HEAD
|
||||||
|
echo "module-sdk checked out at: $sdk_dir"
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
curl \
|
||||||
|
ca-certificates \
|
||||||
|
build-essential \
|
||||||
|
pkg-config \
|
||||||
|
libssl-dev \
|
||||||
|
git
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||||
|
| sh -s -- -y \
|
||||||
|
--profile minimal \
|
||||||
|
--default-toolchain "$RUST_TOOLCHAIN" \
|
||||||
|
--target wasm32-wasip2 \
|
||||||
|
--component rustfmt \
|
||||||
|
--component clippy
|
||||||
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Cargo fmt --check
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
- name: Cargo clippy
|
||||||
|
run: cargo clippy --all-targets -- -D warnings
|
||||||
|
|
||||||
|
- name: Cargo build (host)
|
||||||
|
run: cargo build --all-targets
|
||||||
|
|
||||||
|
- name: Cargo test (host)
|
||||||
|
run: cargo test --all-targets
|
||||||
|
|
||||||
|
- name: Cargo build (wasm32-wasip2)
|
||||||
|
run: cargo build --release --target wasm32-wasip2
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
target/
|
||||||
|
**/*.rs.bk
|
||||||
|
.DS_Store
|
||||||
821
Cargo.lock
generated
Normal file
821
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,821 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler2"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adobe-cmap-parser"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae8abfa9a4688de8fc9f42b3f013b6fffec18ed8a554f5f113577e0b9b3212a3"
|
||||||
|
dependencies = [
|
||||||
|
"pom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ahash"
|
||||||
|
version = "0.8.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"version_check",
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.102"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arbitrary"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
|
||||||
|
dependencies = [
|
||||||
|
"derive_arbitrary",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.20.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc32fast"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_arbitrary"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.10.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"crypto-common",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "displaydoc"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "encoding_rs"
|
||||||
|
version = "0.8.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "euclid"
|
||||||
|
version = "0.20.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2bb7ef65b3777a325d1eeefefab5b6d4959da54747e33bd6258e789640f307ad"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fai-module-sdk"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"fai-module-sdk-macros",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
"wit-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fai-module-sdk-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "id-arena"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown 0.17.0",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "leb128"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6cc46bac87ef8093eed6f272babb833b6443374399985ac8ed28471ee0918545"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lopdf"
|
||||||
|
version = "0.34.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c5c8ecfc6c72051981c0459f75ccc585e7ff67c70829560cda8e647882a9abff"
|
||||||
|
dependencies = [
|
||||||
|
"encoding_rs",
|
||||||
|
"flate2",
|
||||||
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
|
"log",
|
||||||
|
"md-5",
|
||||||
|
"nom",
|
||||||
|
"rangemap",
|
||||||
|
"time",
|
||||||
|
"weezl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "md-5"
|
||||||
|
version = "0.10.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.8.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
||||||
|
dependencies = [
|
||||||
|
"adler2",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pdf-extract"
|
||||||
|
version = "0.7.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cbb3a5387b94b9053c1e69d8abfd4dd6dae7afda65a5c5279bc1f42ab39df575"
|
||||||
|
dependencies = [
|
||||||
|
"adobe-cmap-parser",
|
||||||
|
"encoding_rs",
|
||||||
|
"euclid",
|
||||||
|
"lopdf",
|
||||||
|
"postscript",
|
||||||
|
"type1-encoding-parser",
|
||||||
|
"unicode-normalization",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pom"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "60f6ce597ecdcc9a098e7fddacb1065093a3d66446fa16c675e7e71d1b5c28e6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "postscript"
|
||||||
|
version = "0.14.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78451badbdaebaf17f053fd9152b3ffb33b516104eacb45e7864aaa9c712f306"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.2.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.106"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-xml"
|
||||||
|
version = "0.36.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rangemap"
|
||||||
|
version = "1.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "973443cf09a9c8656b574a866ab68dfa19f0867d0340648c7d2f6a71b8a8ea68"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_core"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.149"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simd-adler32"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.15.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spdx"
|
||||||
|
version = "0.10.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3"
|
||||||
|
dependencies = [
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.117"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "text_extract"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"fai-module-sdk",
|
||||||
|
"pdf-extract",
|
||||||
|
"quick-xml",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"zip",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"itoa",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde_core",
|
||||||
|
"time-core",
|
||||||
|
"time-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "71e552d1249bf61ac2a52db88179fd0673def1e1ad8243a00d9ec9ed71fee3dd"
|
||||||
|
dependencies = [
|
||||||
|
"num-conv",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "type1-encoding-parser"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa10c302f5a53b7ad27fd42a3996e23d096ba39b5b8dd6d9e683a05b01bee749"
|
||||||
|
dependencies = [
|
||||||
|
"pom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-normalization"
|
||||||
|
version = "0.1.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-encoder"
|
||||||
|
version = "0.220.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e913f9242315ca39eff82aee0e19ee7a372155717ff0eb082c741e435ce25ed1"
|
||||||
|
dependencies = [
|
||||||
|
"leb128",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-metadata"
|
||||||
|
version = "0.220.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "185dfcd27fa5db2e6a23906b54c28199935f71d9a27a1a27b3a88d6fee2afae7"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"spdx",
|
||||||
|
"wasm-encoder",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmparser"
|
||||||
|
version = "0.220.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d07b6a3b550fefa1a914b6d54fc175dd11c3392da11eee604e6ffc759805d25"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"bitflags",
|
||||||
|
"hashbrown 0.14.5",
|
||||||
|
"indexmap",
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "weezl"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a2b3e15cd6068f233926e7d8c7c588b2ec4fb7cc7bf3824115e7c7e2a8485a3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
"wit-bindgen-rust-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-core"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b632a5a0fa2409489bd49c9e6d99fcc61bb3d4ce9d1907d44662e75a28c71172"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"heck",
|
||||||
|
"wit-parser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7947d0131c7c9da3f01dfde0ab8bd4c4cf3c5bd49b6dba0ae640f1fa752572ea"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rust"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4329de4186ee30e2ef30a0533f9b3c123c019a237a7c82d692807bf1b3ee2697"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"heck",
|
||||||
|
"indexmap",
|
||||||
|
"prettyplease",
|
||||||
|
"syn",
|
||||||
|
"wasm-metadata",
|
||||||
|
"wit-bindgen-core",
|
||||||
|
"wit-component",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rust-macro"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "177fb7ee1484d113b4792cc480b1ba57664bbc951b42a4beebe573502135b1fc"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wit-bindgen-core",
|
||||||
|
"wit-bindgen-rust",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-component"
|
||||||
|
version = "0.220.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b505603761ed400c90ed30261f44a768317348e49f1864e82ecdc3b2744e5627"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bitflags",
|
||||||
|
"indexmap",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"wasm-encoder",
|
||||||
|
"wasm-metadata",
|
||||||
|
"wasmparser",
|
||||||
|
"wit-parser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-parser"
|
||||||
|
version = "0.220.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae2a7999ed18efe59be8de2db9cb2b7f84d88b27818c79353dfc53131840fe1a"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"id-arena",
|
||||||
|
"indexmap",
|
||||||
|
"log",
|
||||||
|
"semver",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"unicode-xid",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.48"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.48"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zip"
|
||||||
|
version = "2.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50"
|
||||||
|
dependencies = [
|
||||||
|
"arbitrary",
|
||||||
|
"crc32fast",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"displaydoc",
|
||||||
|
"flate2",
|
||||||
|
"indexmap",
|
||||||
|
"memchr",
|
||||||
|
"thiserror",
|
||||||
|
"zopfli",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zopfli"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"crc32fast",
|
||||||
|
"log",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
51
Cargo.toml
Normal file
51
Cargo.toml
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Standalone Cargo.toml — targets wasm32-wasip2.
|
||||||
|
#
|
||||||
|
# Build with:
|
||||||
|
# cargo build --release --target wasm32-wasip2
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "text_extract"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
authors = ["Dr. Stefan Flemming <platform@flemming.ai>"]
|
||||||
|
license = "Apache-2.0"
|
||||||
|
publish = false
|
||||||
|
description = "F∆I module — extract plain text from PDF and DOCX documents"
|
||||||
|
repository = "https://git.flemming.ws/fai-modules/text-extract"
|
||||||
|
rust-version = "1.85"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
fai-module-sdk = { path = "../../module_sdk/crates/fai-module-sdk" }
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
pdf-extract = "0.7"
|
||||||
|
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||||
|
quick-xml = "0.36"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_json = "1"
|
||||||
|
# Restricted features: deflate64 (a default feature of zip 2.x)
|
||||||
|
# requires the unstable `unbounded_shifts` library feature.
|
||||||
|
# We only need DEFLATE for round-tripping a minimal DOCX in tests.
|
||||||
|
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "s"
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
strip = "symbols"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unsafe_op_in_unsafe_fn = "warn"
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
unwrap_used = "deny"
|
||||||
|
expect_used = "deny"
|
||||||
|
panic = "deny"
|
||||||
|
print_stdout = "deny"
|
||||||
|
print_stderr = "deny"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
# Empty workspace table so this package is NOT picked up by a parent.
|
||||||
73
LICENSE
Normal file
73
LICENSE
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2026 fai-modules
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
15
NOTICE
Normal file
15
NOTICE
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
text-extract
|
||||||
|
Copyright 2026 Flemming.AI
|
||||||
|
|
||||||
|
This product includes software developed by Dr. Stefan Flemming
|
||||||
|
and contributors (https://flemming.ai/).
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
Third-party acknowledgments
|
||||||
|
|
||||||
|
PDF text extraction is delegated to the `pdf-extract` crate
|
||||||
|
(MIT license) and its dependencies. DOCX extraction uses the
|
||||||
|
`zip` (MIT/Apache-2.0) and `quick-xml` (MIT) crates.
|
||||||
|
|
||||||
|
Runtime dependencies and their licenses are documented in the
|
||||||
|
Software Bill of Materials (SBOM) generated on every release.
|
||||||
85
README.md
Normal file
85
README.md
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
# text-extract
|
||||||
|
|
||||||
|
F∆I module — extract plain text from PDF and DOCX documents.
|
||||||
|
|
||||||
|
## Capability
|
||||||
|
|
||||||
|
| Field | Value |
|
||||||
|
|-------|-------|
|
||||||
|
| Capability | `text.extract@0.1.0` |
|
||||||
|
| Inputs | `document: bytes` (PDF or DOCX) |
|
||||||
|
| Outputs | `extracted: json` (ExtractedDocument) |
|
||||||
|
| Permissions | _none_ — pure in-WASM, no filesystem, no network |
|
||||||
|
| Status (in store index) | `alpha` |
|
||||||
|
|
||||||
|
## Output schema
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"engine": "pdf-extract",
|
||||||
|
"engine_version": "0.7",
|
||||||
|
"pages": [
|
||||||
|
{ "number": 1, "text": "..." }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`confidence` and `bbox` per page are reserved for a future
|
||||||
|
service-mode variant (host-services-backed pdfium/mupdf engine).
|
||||||
|
v0.1.0 does not populate them; the schema accepts them as
|
||||||
|
optional so that v0.2.0 can extend without an interface break.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo build --release --target wasm32-wasip2
|
||||||
|
# Artifact: target/wasm32-wasip2/release/text_extract.wasm
|
||||||
|
```
|
||||||
|
|
||||||
|
The build depends on a sibling checkout of `fai/module-sdk`:
|
||||||
|
|
||||||
|
```
|
||||||
|
~/fai/
|
||||||
|
├── module_sdk/ # cloned from fai/module-sdk
|
||||||
|
└── fai_modules/
|
||||||
|
└── text-extract/ # this repo
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a temporary path-based dependency. Once `fai-module-sdk`
|
||||||
|
is published to a registry or a stable git tag, this module's
|
||||||
|
`Cargo.toml` will switch over. The Forgejo CI workflow checks out
|
||||||
|
the SDK repo into a sibling directory before building.
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo test # 9 tests: 6 unit + 3 integration
|
||||||
|
cargo test --release # same, optimized
|
||||||
|
```
|
||||||
|
|
||||||
|
The DOCX path is covered end-to-end by an integration test that
|
||||||
|
builds a minimal valid DOCX in memory and feeds it through
|
||||||
|
`invoke`. The PDF path is covered by unit tests on the page
|
||||||
|
splitter; full PDF coverage will land once the platform's hub
|
||||||
|
loads this wasm component as part of its store-install
|
||||||
|
integration test.
|
||||||
|
|
||||||
|
## Limitations of v0.1.0
|
||||||
|
|
||||||
|
- **Layout-naive PDF parsing.** Multi-column layouts and tables
|
||||||
|
may produce reordered text. Single-column documents work
|
||||||
|
reliably.
|
||||||
|
- **DOCX text only.** Tables, footnotes, headers/footers and
|
||||||
|
embedded objects are not yet extracted. Plain paragraph text
|
||||||
|
with run-level concatenation is the v0.1.0 surface.
|
||||||
|
- **No OCR.** Image-only PDFs return empty text per page.
|
||||||
|
An OCR variant will arrive as a separate module
|
||||||
|
(`text.ocr@x.y.z`) once the host-services infrastructure
|
||||||
|
for tesseract is in place.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Apache-2.0. See `LICENSE`.
|
||||||
|
|
||||||
|
Author: Dr. Stefan Flemming, Flemming.AI <platform@flemming.ai>
|
||||||
|
Repository: https://git.flemming.ws/fai-modules/text-extract
|
||||||
31
module.yaml
Normal file
31
module.yaml
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
schema_version: 1
|
||||||
|
name: text-extract
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
# Capability provided by this module.
|
||||||
|
provides:
|
||||||
|
- capability: text.extract
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
# Inputs the invoke function accepts.
|
||||||
|
inputs:
|
||||||
|
# The document to extract text from. Supported MIME types:
|
||||||
|
# application/pdf
|
||||||
|
# application/x-pdf
|
||||||
|
# application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
||||||
|
document: bytes
|
||||||
|
|
||||||
|
# Outputs produced.
|
||||||
|
outputs:
|
||||||
|
# JSON-encoded ExtractedDocument:
|
||||||
|
# { engine, engine_version, pages: [{number, text, confidence?, bbox?}] }
|
||||||
|
# confidence and bbox are reserved for a future service-mode variant
|
||||||
|
# (pdfium / mupdf via host services). v0.1.0 omits them.
|
||||||
|
extracted: json
|
||||||
|
|
||||||
|
# Permissions required.
|
||||||
|
#
|
||||||
|
# v0.1.0 runs entirely in-WASM with pure-Rust crates (pdf-extract,
|
||||||
|
# zip, quick-xml). No filesystem, no network. The empty list makes
|
||||||
|
# this explicit; the hub enforces it.
|
||||||
|
permissions: []
|
||||||
4
rust-toolchain.toml
Normal file
4
rust-toolchain.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "1.86"
|
||||||
|
targets = ["wasm32-wasip2"]
|
||||||
|
components = ["rustfmt", "clippy"]
|
||||||
274
src/lib.rs
Normal file
274
src/lib.rs
Normal file
|
|
@ -0,0 +1,274 @@
|
||||||
|
//! `text.extract` module — extract plain text from PDF or DOCX
|
||||||
|
//! documents.
|
||||||
|
//!
|
||||||
|
//! # Capability
|
||||||
|
//!
|
||||||
|
//! - **Input:** `document` — `bytes` payload, MIME type
|
||||||
|
//! `application/pdf` or
|
||||||
|
//! `application/vnd.openxmlformats-officedocument.wordprocessingml.document`.
|
||||||
|
//! - **Output:** `extracted` — `json` payload conforming to the
|
||||||
|
//! `ExtractedDocument` schema below.
|
||||||
|
//!
|
||||||
|
//! # Output schema
|
||||||
|
//!
|
||||||
|
//! ```json
|
||||||
|
//! {
|
||||||
|
//! "engine": "pdf-extract",
|
||||||
|
//! "engine_version": "0.7",
|
||||||
|
//! "pages": [
|
||||||
|
//! { "number": 1, "text": "..." }
|
||||||
|
//! ]
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Per-page `confidence` and `bbox` fields are reserved for a
|
||||||
|
//! future service-mode variant (Phase 0.5+, host-services-backed)
|
||||||
|
//! that uses pdfium or mupdf and exposes layout information.
|
||||||
|
//! v0.1.0 does not populate them; the schema accepts them as
|
||||||
|
//! optional so that the v0.2.0 service variant can add them
|
||||||
|
//! without an interface break.
|
||||||
|
//!
|
||||||
|
//! # Stability
|
||||||
|
//!
|
||||||
|
//! Module version `0.1.0` ships as `alpha` in the store index:
|
||||||
|
//! installable, but the PDF extraction quality is layout-naive
|
||||||
|
//! (single-column ok; multi-column or table-heavy documents may
|
||||||
|
//! produce reordered text). Bumping to `1.0.0` requires either
|
||||||
|
//! the service-mode variant or a confirmed-good extraction
|
||||||
|
//! quality on a representative document set.
|
||||||
|
|
||||||
|
#![allow(clippy::result_large_err)]
|
||||||
|
|
||||||
|
use fai_module_sdk::prelude::*;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
const PDF_MIME: &str = "application/pdf";
|
||||||
|
const PDF_MIME_ALT: &str = "application/x-pdf";
|
||||||
|
const DOCX_MIME: &str = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||||
|
|
||||||
|
const ENGINE_PDF: &str = "pdf-extract";
|
||||||
|
const ENGINE_PDF_VERSION: &str = "0.7";
|
||||||
|
const ENGINE_DOCX: &str = "zip+quick-xml";
|
||||||
|
const ENGINE_DOCX_VERSION: &str = "0.1";
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct ExtractedDocument {
|
||||||
|
engine: String,
|
||||||
|
engine_version: String,
|
||||||
|
pages: Vec<Page>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct Page {
|
||||||
|
number: u32,
|
||||||
|
text: String,
|
||||||
|
/// Reserved for a future service-mode variant. Populated only
|
||||||
|
/// when the underlying engine reports a per-page confidence.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
confidence: Option<f64>,
|
||||||
|
/// Reserved for a future service-mode variant. Populated only
|
||||||
|
/// when the underlying engine reports per-page bounding boxes.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
bbox: Option<BoundingBox>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct BoundingBox {
|
||||||
|
x: f64,
|
||||||
|
y: f64,
|
||||||
|
width: f64,
|
||||||
|
height: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fai_module]
|
||||||
|
pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
|
let bytes = inputs.require_bytes("document")?;
|
||||||
|
let extracted = match bytes.mime_type.as_str() {
|
||||||
|
PDF_MIME | PDF_MIME_ALT => extract_pdf(&bytes.data)?,
|
||||||
|
DOCX_MIME => extract_docx(&bytes.data)?,
|
||||||
|
other => {
|
||||||
|
return Err(ModuleError::invalid_input(format!(
|
||||||
|
"unsupported MIME type: {other} (supported: {PDF_MIME}, {DOCX_MIME})",
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Outputs::new().with_json("extracted", &extracted)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_pdf(data: &[u8]) -> Result<ExtractedDocument, ModuleError> {
|
||||||
|
let text = pdf_extract::extract_text_from_mem(data)
|
||||||
|
.map_err(|e| ModuleError::invalid_input(format!("PDF parsing failed: {e}")))?;
|
||||||
|
Ok(ExtractedDocument {
|
||||||
|
engine: ENGINE_PDF.to_string(),
|
||||||
|
engine_version: ENGINE_PDF_VERSION.to_string(),
|
||||||
|
pages: split_pdf_text_into_pages(&text),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// pdf-extract's `extract_text_from_mem` returns a single string
|
||||||
|
/// with form-feed (`\x0c`) characters between pages. Split on
|
||||||
|
/// that boundary so the consumer keeps the page structure.
|
||||||
|
fn split_pdf_text_into_pages(combined: &str) -> Vec<Page> {
|
||||||
|
let trimmed = combined.trim_matches('\x0c');
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
trimmed
|
||||||
|
.split('\x0c')
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, page_text)| Page {
|
||||||
|
number: u32::try_from(i + 1).unwrap_or(u32::MAX),
|
||||||
|
text: page_text.trim().to_string(),
|
||||||
|
confidence: None,
|
||||||
|
bbox: None,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_docx(data: &[u8]) -> Result<ExtractedDocument, ModuleError> {
|
||||||
|
let cursor = std::io::Cursor::new(data);
|
||||||
|
let mut archive = zip::ZipArchive::new(cursor)
|
||||||
|
.map_err(|e| ModuleError::invalid_input(format!("DOCX is not a valid ZIP: {e}")))?;
|
||||||
|
let mut document_xml = archive.by_name("word/document.xml").map_err(|_| {
|
||||||
|
ModuleError::invalid_input(
|
||||||
|
"DOCX archive does not contain word/document.xml — not a valid DOCX",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let mut buf = Vec::with_capacity(usize::try_from(document_xml.size()).unwrap_or(0));
|
||||||
|
std::io::Read::read_to_end(&mut document_xml, &mut buf)
|
||||||
|
.map_err(|e| ModuleError::internal(format!("failed reading word/document.xml: {e}")))?;
|
||||||
|
let text = extract_docx_text_from_xml(&buf)?;
|
||||||
|
Ok(ExtractedDocument {
|
||||||
|
engine: ENGINE_DOCX.to_string(),
|
||||||
|
engine_version: ENGINE_DOCX_VERSION.to_string(),
|
||||||
|
pages: vec![Page {
|
||||||
|
number: 1,
|
||||||
|
text,
|
||||||
|
confidence: None,
|
||||||
|
bbox: None,
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract visible text from a DOCX `document.xml` body.
|
||||||
|
///
|
||||||
|
/// DOCX paragraphs nest text runs as `<w:r><w:t>...</w:t></w:r>`.
|
||||||
|
/// We collect text from `<w:t>` elements, insert a newline at
|
||||||
|
/// each paragraph boundary, and skip everything else.
|
||||||
|
fn extract_docx_text_from_xml(xml: &[u8]) -> Result<String, ModuleError> {
|
||||||
|
use quick_xml::Reader;
|
||||||
|
use quick_xml::events::Event;
|
||||||
|
|
||||||
|
let mut reader = Reader::from_reader(xml);
|
||||||
|
reader.config_mut().trim_text(false);
|
||||||
|
|
||||||
|
let mut out = String::new();
|
||||||
|
let mut in_text = false;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match reader.read_event() {
|
||||||
|
Ok(Event::Start(e)) => {
|
||||||
|
if local_name_matches(e.name().as_ref(), b"t") {
|
||||||
|
in_text = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Event::End(e)) => {
|
||||||
|
if local_name_matches(e.name().as_ref(), b"t") {
|
||||||
|
in_text = false;
|
||||||
|
} else if local_name_matches(e.name().as_ref(), b"p") {
|
||||||
|
out.push('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Event::Text(e)) if in_text => {
|
||||||
|
let unescaped = e
|
||||||
|
.unescape()
|
||||||
|
.map_err(|err| ModuleError::invalid_input(format!("DOCX XML decode: {err}")))?;
|
||||||
|
out.push_str(&unescaped);
|
||||||
|
}
|
||||||
|
Ok(Event::Eof) => break,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(ModuleError::invalid_input(format!(
|
||||||
|
"DOCX XML parse error at position {}: {err}",
|
||||||
|
reader.error_position()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(out.trim_end().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn local_name_matches(qname: &[u8], local: &[u8]) -> bool {
|
||||||
|
match qname.iter().rposition(|b| *b == b':') {
|
||||||
|
Some(idx) => &qname[idx + 1..] == local,
|
||||||
|
None => qname == local,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#![allow(clippy::unwrap_used, clippy::panic)]
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn split_pdf_text_into_pages_handles_form_feed() {
|
||||||
|
let combined = "Page one text\x0cPage two text\x0c";
|
||||||
|
let pages = split_pdf_text_into_pages(combined);
|
||||||
|
assert_eq!(pages.len(), 2);
|
||||||
|
assert_eq!(pages[0].number, 1);
|
||||||
|
assert_eq!(pages[0].text, "Page one text");
|
||||||
|
assert_eq!(pages[1].number, 2);
|
||||||
|
assert_eq!(pages[1].text, "Page two text");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn split_pdf_text_into_pages_returns_empty_on_empty_input() {
|
||||||
|
assert!(split_pdf_text_into_pages("").is_empty());
|
||||||
|
assert!(split_pdf_text_into_pages("\x0c\x0c").is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn local_name_matches_qualified_and_unqualified() {
|
||||||
|
assert!(local_name_matches(b"w:t", b"t"));
|
||||||
|
assert!(local_name_matches(b"t", b"t"));
|
||||||
|
assert!(local_name_matches(b"namespace:p", b"p"));
|
||||||
|
assert!(!local_name_matches(b"w:t", b"p"));
|
||||||
|
assert!(!local_name_matches(b"w:tbl", b"t"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_docx_text_handles_paragraphs() {
|
||||||
|
let xml = br#"<?xml version="1.0"?>
|
||||||
|
<w:document xmlns:w="urn:test">
|
||||||
|
<w:body>
|
||||||
|
<w:p><w:r><w:t>Hello</w:t></w:r><w:r><w:t> World</w:t></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t>Second paragraph</w:t></w:r></w:p>
|
||||||
|
</w:body>
|
||||||
|
</w:document>"#;
|
||||||
|
let text = extract_docx_text_from_xml(xml).unwrap();
|
||||||
|
assert_eq!(text, "Hello World\nSecond paragraph");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_docx_text_skips_non_t_elements() {
|
||||||
|
let xml = br#"<w:document xmlns:w="urn:test">
|
||||||
|
<w:p>
|
||||||
|
<w:r><w:rPr><w:b/></w:rPr><w:t>Bold</w:t></w:r>
|
||||||
|
<w:r><w:t> normal</w:t></w:r>
|
||||||
|
</w:p>
|
||||||
|
</w:document>"#;
|
||||||
|
let text = extract_docx_text_from_xml(xml).unwrap();
|
||||||
|
assert_eq!(text, "Bold normal");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_docx_text_preserves_whitespace_in_t() {
|
||||||
|
// <w:t xml:space="preserve"> usually carries whitespace.
|
||||||
|
// Our extractor passes text through untouched.
|
||||||
|
let xml =
|
||||||
|
br#"<w:document xmlns:w="urn:test"><w:p><w:r><w:t> spaced </w:t></w:r></w:p></w:document>"#;
|
||||||
|
let text = extract_docx_text_from_xml(xml).unwrap();
|
||||||
|
assert_eq!(text, " spaced");
|
||||||
|
}
|
||||||
|
}
|
||||||
135
tests/docx_roundtrip.rs
Normal file
135
tests/docx_roundtrip.rs
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
//! End-to-end test for the DOCX path.
|
||||||
|
//!
|
||||||
|
//! Builds a minimal valid DOCX in memory, hands it to the
|
||||||
|
//! `invoke` entry point, and asserts the JSON output matches the
|
||||||
|
//! expected schema. The DOCX is a ZIP archive containing
|
||||||
|
//! `word/document.xml` plus the minimum `[Content_Types].xml`
|
||||||
|
//! that Office tools expect — that is the bare floor for a
|
||||||
|
//! parser to accept the file.
|
||||||
|
//!
|
||||||
|
//! The PDF path is covered by unit tests on the page splitter;
|
||||||
|
//! end-to-end PDF coverage will land once the platform's hub
|
||||||
|
//! integration test loads the wasm component and feeds it a
|
||||||
|
//! real PDF fixture.
|
||||||
|
|
||||||
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use fai_module_sdk::prelude::*;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use text_extract::invoke;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct ExtractedDocument {
|
||||||
|
engine: String,
|
||||||
|
engine_version: String,
|
||||||
|
pages: Vec<Page>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct Page {
|
||||||
|
number: u32,
|
||||||
|
text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
const DOCX_MIME: &str = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||||
|
|
||||||
|
const CONTENT_TYPES_XML: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||||
|
<Default Extension="xml" ContentType="application/xml"/>
|
||||||
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
||||||
|
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
|
||||||
|
</Types>"#;
|
||||||
|
|
||||||
|
const RELS_XML: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
||||||
|
</Relationships>"#;
|
||||||
|
|
||||||
|
const DOCUMENT_XML: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||||
|
<w:body>
|
||||||
|
<w:p><w:r><w:t>The quick brown fox</w:t></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t xml:space="preserve">jumps over </w:t></w:r><w:r><w:t>the lazy dog.</w:t></w:r></w:p>
|
||||||
|
</w:body>
|
||||||
|
</w:document>"#;
|
||||||
|
|
||||||
|
fn build_minimal_docx() -> Vec<u8> {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
{
|
||||||
|
let mut w = zip::ZipWriter::new(std::io::Cursor::new(&mut buf));
|
||||||
|
let opts: zip::write::SimpleFileOptions = zip::write::SimpleFileOptions::default()
|
||||||
|
.compression_method(zip::CompressionMethod::Deflated);
|
||||||
|
|
||||||
|
w.start_file("[Content_Types].xml", opts).unwrap();
|
||||||
|
w.write_all(CONTENT_TYPES_XML.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
w.start_file("_rels/.rels", opts).unwrap();
|
||||||
|
w.write_all(RELS_XML.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
w.start_file("word/document.xml", opts).unwrap();
|
||||||
|
w.write_all(DOCUMENT_XML.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
w.finish().unwrap();
|
||||||
|
}
|
||||||
|
buf
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dummy_context() -> Context {
|
||||||
|
Context {
|
||||||
|
invocation_id: "test".into(),
|
||||||
|
capability_namespace: "text".into(),
|
||||||
|
capability_name: "extract".into(),
|
||||||
|
deadline_ms: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn docx_round_trip_produces_expected_schema() {
|
||||||
|
let docx = build_minimal_docx();
|
||||||
|
let inputs = Inputs::from_pairs([("document", Payload::bytes(DOCX_MIME, docx))]);
|
||||||
|
|
||||||
|
let outputs = invoke(dummy_context(), inputs).expect("invoke ok");
|
||||||
|
let pairs = outputs.into_pairs();
|
||||||
|
assert_eq!(pairs.len(), 1, "exactly one output expected");
|
||||||
|
assert_eq!(pairs[0].0, "extracted");
|
||||||
|
|
||||||
|
let raw = match &pairs[0].1 {
|
||||||
|
Payload::Json(s) => s,
|
||||||
|
other => panic!("expected Json payload, got {other:?}"),
|
||||||
|
};
|
||||||
|
let doc: ExtractedDocument = serde_json::from_str(raw).expect("valid JSON");
|
||||||
|
|
||||||
|
assert_eq!(doc.engine, "zip+quick-xml");
|
||||||
|
assert_eq!(doc.engine_version, "0.1");
|
||||||
|
assert_eq!(doc.pages.len(), 1);
|
||||||
|
assert_eq!(doc.pages[0].number, 1);
|
||||||
|
assert!(
|
||||||
|
doc.pages[0].text.contains("quick brown fox"),
|
||||||
|
"missing first paragraph: {}",
|
||||||
|
doc.pages[0].text
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
doc.pages[0].text.contains("jumps over the lazy dog"),
|
||||||
|
"missing second paragraph: {}",
|
||||||
|
doc.pages[0].text
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupported_mime_type_returns_invalid_input() {
|
||||||
|
let inputs =
|
||||||
|
Inputs::from_pairs([("document", Payload::bytes("application/zip", vec![0u8; 32]))]);
|
||||||
|
let err = invoke(dummy_context(), inputs).expect_err("must fail");
|
||||||
|
let msg = format!("{err}");
|
||||||
|
assert!(msg.contains("unsupported MIME type"), "msg = {msg}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_document_input_returns_invalid_input() {
|
||||||
|
let inputs = Inputs::default();
|
||||||
|
let err = invoke(dummy_context(), inputs).expect_err("must fail");
|
||||||
|
let msg = format!("{err}");
|
||||||
|
assert!(msg.contains("missing input"), "msg = {msg}");
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue