Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page to alto python #134

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions script/transform/page__alto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENDORDIR="$(cd $SCRIPTDIR/../../vendor/; pwd)"
JAR="$VENDORDIR/JPageConverter/PageConverter.jar"
INFILE="$1"
OUTFILE="$2"
ARGUMENT="$3"
Expand All @@ -16,17 +15,18 @@ if [[ "$2" = "-" ]]; then
OUTFILE="$(mktemp)"
fi

java -jar "$JAR" -neg-coords toZero -source-xml "$INFILE" -target-xml "$OUTFILE" -convert-to ALTO 2>&1
page-to-alto $ARGUMENT "$INFILE" > "$OUTFILE"; retval="$?"

if [[ "$1" = "-" ]]; then
rm "$INFILE"
fi

if (( retval > 0 ));then
rm "$OUTFILE"
exit $retval
fi

if [[ "$2" = "-" ]]; then
if [[ -z "$ARGUMENT" ]]; then
cat "$OUTFILE"
else
java -cp "$VENDORDIR/saxon9he.jar" net.sf.saxon.Query -s:"$OUTFILE" -qs:/ "$ARGUMENT"
fi
cat "$OUTFILE"
rm "$OUTFILE"
fi
32 changes: 32 additions & 0 deletions script/transform/page__alto_legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENDORDIR="$(cd $SCRIPTDIR/../../vendor/; pwd)"
JAR="$VENDORDIR/JPageConverter/PageConverter.jar"
INFILE="$1"
OUTFILE="$2"
ARGUMENT="$3"

if [[ "$1" = "-" ]]; then
INFILE="$(mktemp)"
cat >"$INFILE"
fi

if [[ "$2" = "-" ]]; then
OUTFILE="$(mktemp)"
fi

java -jar "$JAR" -neg-coords toZero -source-xml "$INFILE" -target-xml "$OUTFILE" -convert-to ALTO 2>&1

if [[ "$1" = "-" ]]; then
rm "$INFILE"
fi

if [[ "$2" = "-" ]]; then
if [[ -z "$ARGUMENT" ]]; then
cat "$OUTFILE"
else
java -cp "$VENDORDIR/saxon9he.jar" net.sf.saxon.Query -s:"$OUTFILE" -qs:/ "$ARGUMENT"
fi
rm "$OUTFILE"
fi
11 changes: 10 additions & 1 deletion vendor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RM = rm -rfv
UNZIP = unzip -o
WGET = wget --progress=bar:force --no-verbose
GIT_CLONE = git clone --depth 1
PIP = pip3

SAXON_HE_VERSION_MAJOR = 9
SAXON_HE_VERSION_MINOR = 9
Expand Down Expand Up @@ -45,6 +46,9 @@ ALTO2PAGE_ZIP = JPageConverter.zip
ALTO2PAGE_URL = https://github.com/PRImA-Research-Lab/prima-page-converter/releases/download/$(ALTO2PAGE_VERSION)/JPageConverter_$(ALTO2PAGE_VERSION).zip
ALTO2PAGE_DIR = JPageConverter

PAGE_TO_ALTO_REPO = page-to-alto
PAGE_TO_ALTO_URL = https://github.com/kba/page-to-alto

# {{{
# SAXON_BROWSER_VERSION = 1.1
# SAXON_BROWSER_ZIP = Saxon-CE_$(SAXON_BROWSER_VERSION).zip
Expand All @@ -69,7 +73,8 @@ all:\
$(PAGE2HOCR_REPO)\
$(HOCR_SPEC_REPO)\
$(SAXON_HE_JAR) \
$(ALTO2PAGE_DIR)
$(ALTO2PAGE_DIR) \
$(PAGE_TO_ALTO_REPO)

clean:
$(RM) $(ALTO_SCHEMA_REPO)
Expand Down Expand Up @@ -133,3 +138,7 @@ $(ALTO2PAGE_ZIP):
$(ALTO2PAGE_DIR): $(ALTO2PAGE_ZIP)
$(UNZIP) "$<"
mv "JPageConverter $(ALTO2PAGE_VERSION_MAJOR_MINOR)" "$@"

$(PAGE_TO_ALTO_REPO):
$(GIT_CLONE) "$(PAGE_TO_ALTO_URL)" "$@"
cd "$@"; $(PIP) install .