CoolFace
Apppublic

project-sign-language/Sign_language

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
NLP_Spacy_base_translator.py38 linesDownload Raw Back to src
1import spacy2from ASL_gloss_functions import process_sentence3 4## custom class for translation5"""6set of rules for ASL conversion:71. Uppercase Letters: Write each ASL sign in uppercase letters82. Non-Manual Signals (NMS): Indicate non-manual signals such as facial expressions or body movements above the glossed sign.93. Fingerspelling: Represent fingerspelled words with dashes between each letter.104. Lexicalized Fingerspelling: Indicate lexicalized fingerspelling with a # symbol.115. Repetition: Show repeated signs with a plus sign (+) after the gloss.126. Role Shift: Indicate role shift with "rs" before the gloss.137. Indexing/Pointing: Use "ix" followed by a subscript letter or number for indexing.148. Directional Signs: Indicate the direction of the sign with arrows or other indicators.159. Classifiers: Use abbreviations for classifiers.1610. Time Indicators: Place time indicators at the beginning of the sentence.1711. Topic-Comment Structure: Indicate the topic followed by the comment.1812. English Words/Concepts: Use English gloss in quotation marks for concepts without direct ASL equivalents.19"""20## reference language21nlp = spacy.load("en_core_web_sm")22 23class NlpSpacyBaseTranslator():24    def __init__(self, sentence):25        self.sentence = sentence26 27    def translate_to_gloss(self):28        """29        - doc: after nlp processing: I write a sentence for testing Today 17.05 p.m.30        - gloss: TODAY31        - generated_gloss: TODAY ix_1 I WRITE  SENTENCE FOR TEST 17.05 P.M.32        """33        print(f'self.sentence: {self.sentence}')34        doc = nlp(self.sentence)35        ##print(f'doc after nlp processing: {doc}')36        generated_gloss = process_sentence(doc) ## deterministic model = set of ASL-Gloss-rules functions37        print(f'generated_gloss: {generated_gloss}')38        return generated_gloss