mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Step 5 of Portuguese typing. Português, dictated or pinned in Keyboard › Keyboard layout, now types with its own model instead of English's word list standing in (Spoken.Portuguese, "pt"): - Keys: QWERTY, as English's (KeyboardLetters "pt"). - Holds: iPhone Hex's Portuguese long presses (KeyboardLanguage.swift) on a, e, i, o, u, c and n; other letters hold nothing, as on iPhone. - The strip's words between words: "eu", "o", "a" at a sentence's start, "e", "mas", "que" after a comma, and the commonest words where the pairs know none. - never-suggest.tsv: Portuguese rows curated from LDNOOBW's pt list (CC BY 4.0, credit extended): 11 slurs (viado, bicha, paneleiro, sapatão...) and 43 swear words with common inflections; ordinary words on that list (comer, cerveja, burro, saco, transar) and veado (deer) stay. - Swipe: swipe_paths.py and swipe-bench.py know "pt". Nederlands, Polski and Русский keep English's word list as a stand-in, as before. Tests (existing files): InsertionTest now expects Português's layout and typing model; NeverSuggestTest runs its filter, between-words and swipe checks for pt as for the other six. Verified on the Studio (host JVM, Gradle --no-daemon, no emulator): testDebugUnitTest passes; quality-gate.py all: pt PASS (83.75% fewer errors, 0.16% correct words changed, 98.30% accents, 7/7), the other six identical field for field to origin/dev's; swipe-bench.py, typical fingers: pt 96.3% first word right, 99.5% typed or in the strip over 11,580 swipes, the other six as in the README table. Not yet checked on an emulator.
81 lines
4.9 KiB
Python
Executable file
81 lines
4.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Score swipe typing on synthetic paths: how often the first word is right, how often the word is typed or in
|
|
the strip (top 4), and the time per swipe. The paths are swipe_paths.py's, the same ones the iPhone replay reads,
|
|
from the held-out sentences; each is decoded by the keyboard's own SwipeReader (SwipeReplay.java) on the host
|
|
JVM, or with --device on an emulator or phone against the installed APK, as replay.sh runs the tap replay.
|
|
|
|
android/benchmark/typing/swipe-bench.py [LANG ...] [--noise typical] [--device SERIAL] [--out DIR]
|
|
"""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
ANDROID = HERE.parents[1]
|
|
MODELS = ANDROID / 'app/src/main/assets/typing'
|
|
LANGUAGES = ['en', 'es', 'de', 'nb', 'fr', 'it', 'pt']
|
|
|
|
|
|
def paths(lang, noise, out):
|
|
"""The path set, made once per language and noise."""
|
|
target = out / f'{lang}-{noise}.tsv.gz'
|
|
if not target.is_file():
|
|
subprocess.run(['python3', HERE / 'swipe_paths.py', lang, target, '--noise', noise], check=True)
|
|
return target
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument('languages', nargs='*', help=' '.join(LANGUAGES) + ' (default: all)')
|
|
parser.add_argument('--noise', default='typical', choices=['typical', 'neat', 'sloppy', 'none'])
|
|
parser.add_argument('--device', help='adb serial: run on the device against the installed APK')
|
|
parser.add_argument('--out', type=Path, default=ANDROID / 'build/swipe-bench')
|
|
args = parser.parse_args()
|
|
if not set(args.languages) <= set(LANGUAGES):
|
|
parser.error('languages: ' + ' '.join(LANGUAGES))
|
|
args.languages = args.languages or LANGUAGES
|
|
args.out.mkdir(parents=True, exist_ok=True)
|
|
jdk = Path(os.environ['JAVA_HOME']) / 'bin' if 'JAVA_HOME' in os.environ else Path('')
|
|
with tempfile.TemporaryDirectory() as scratch:
|
|
tmp = Path(scratch)
|
|
cp = tmp / 'classpath'
|
|
subprocess.run([ANDROID / 'gradlew', '-q', '-I', HERE / 'gate-classpath.gradle', ':app:typingGateClasspath',
|
|
'-x', 'prepareSpeechModel', '-PgateClasspath=' + str(cp)], cwd=ANDROID, check=True)
|
|
classes = tmp / 'classes'
|
|
subprocess.run([jdk / 'javac', '-encoding', 'UTF-8', '--release', '8', '-Xlint:-options', '-cp', cp.read_text(), '-d', classes,
|
|
HERE / 'SwipeReplay.java'], check=True)
|
|
if args.device:
|
|
adb = ['adb', '-s', args.device]
|
|
sdk = Path(os.environ['ANDROID_HOME'])
|
|
lib = sdk / 'platforms/android-36/android.jar'
|
|
tools = max((sdk / 'build-tools').iterdir())
|
|
subprocess.run([jdk / 'jar', 'cf', tmp / 'replay.jar', '-C', classes, '.'], check=True)
|
|
subprocess.run([tools / 'd8', '--min-api', '31', '--lib', lib, '--output', tmp / 'replay-dex.jar', tmp / 'replay.jar'], check=True)
|
|
dev = '/data/local/tmp/hex-swipe'
|
|
subprocess.run(adb + ['shell', 'mkdir', '-p', dev], check=True)
|
|
subprocess.run(adb + ['push', tmp / 'replay-dex.jar', dev + '/replay.jar'], check=True, capture_output=True)
|
|
subprocess.run(adb + ['push', MODELS / 'never-suggest.tsv', dev], check=True, capture_output=True)
|
|
apk = subprocess.check_output(adb + ['shell', 'pm', 'path', 'ly.anoma.hex'], text=True).strip().removeprefix('package:')
|
|
for lang in args.languages:
|
|
source = paths(lang, args.noise, args.out)
|
|
words = args.out / f'{lang}-{args.noise}-words.tsv'
|
|
if args.device:
|
|
for side in ['hextm', 'capitals', 'valid']:
|
|
subprocess.run(adb + ['shell', 'rm', '-f', f'{dev}/{lang}.{side}'], check=True)
|
|
if (MODELS / f'{lang}.{side}').is_file():
|
|
subprocess.run(adb + ['push', MODELS / f'{lang}.{side}', dev], check=True, capture_output=True)
|
|
subprocess.run(adb + ['push', source, f'{dev}/{source.name}'], check=True, capture_output=True)
|
|
report = subprocess.check_output(adb + ['shell', f'CLASSPATH={dev}/replay.jar:{apk} app_process /system/bin '
|
|
f'local.hex.bench.SwipeReplay {dev}/{lang}.hextm {lang} {dev}/{source.name} {dev}/words.tsv'], text=True)
|
|
subprocess.run(adb + ['shell', 'rm', f'{dev}/{source.name}'], check=True)
|
|
subprocess.run(adb + ['pull', dev + '/words.tsv', words], check=True, capture_output=True)
|
|
else:
|
|
report = subprocess.check_output([jdk / 'java', '-Xmx1g', '-Dfile.encoding=UTF-8', '-cp', str(classes) + os.pathsep + cp.read_text(),
|
|
'local.hex.bench.SwipeReplay', MODELS / f'{lang}.hextm', lang, source, words], text=True)
|
|
(args.out / f'{lang}-{args.noise}{"-device" if args.device else ""}.txt').write_text(report)
|
|
print(report, flush=True)
|
|
|
|
|
|
main()
|