Skip to content

Commit

Permalink
fix(fingerspelling): do not support invalid signs (too long)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Aug 17, 2024
1 parent 065eabe commit eaa83cb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion signwriting/fingerspelling/data/en-us-ase-asl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ Z,M528x507S10020492x477S2450a497x473
8,M511x514S1bb20492x486
9,M511x515S1ce20493x485
0,M508x508S17620493x492
@,M510x524S1f720488x487S2f104492x507S21600496x475,M512x528S1f720488x481S2e308488x501S2f900495x473,M512x523S1f720488x478S2e300487x496
@,M510x524S1f720488x487S2f104492x507S21600496x475,M512x528S1f720488x481S2e308488x501S2f900495x473,M512x523S1f720488x478S2e300487x496
.,M512x522S2f900498x479S26500497x488S1eb20488x503
/,M522x522S15a41478x478S22b05498x498
5 changes: 3 additions & 2 deletions signwriting/fingerspelling/fingerspelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ def spell(word: str, language=None, chars=None, vertical=True) -> Union[str, Non


if __name__ == "__main__":
for _word in ["12345", "hello", "Amit"]:
print(_word, spell(_word, language='en-us-ase-asl', vertical=False))
words = ["custom", "prited", "circuit", "board"]
spellings = [spell(word, language='en-us-ase-asl', vertical=True) for word in words]
print(" ".join(spellings))
19 changes: 19 additions & 0 deletions signwriting/fingerspelling/test_fingerspelling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from signwriting.fingerspelling.fingerspelling import spell


class FingerspellingCase(unittest.TestCase):

def test_successful_spelling(self):
sign = spell("abc", language='en-us-ase-asl', vertical=True)
self.assertEqual(sign, "M510x533S1f720487x466S14720493x486S16d20491x513")

def test_unsuccessful_spelling_throws(self):
long_word = "abcdefghijklmnopqrstuvwxyz"
with self.assertRaises(ValueError):
spell(long_word, language='en-us-ase-asl', vertical=True)


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions signwriting/formats/sign_to_fsw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from itertools import chain

from signwriting.types import Sign


def sign_to_fsw(sign: Sign) -> str:
symbols = [sign["box"]] + sign["symbols"]
all_positions = list(chain.from_iterable([s["position"] for s in symbols]))
if min(all_positions) < 250 or max(all_positions) > 750:
raise ValueError("Positions must be between 250 and 750")
symbols_str = [s["symbol"] + str(s["position"][0]) + 'x' + str(s["position"][1]) for s in symbols]
return "".join(symbols_str)

0 comments on commit eaa83cb

Please sign in to comment.