Created
January 10, 2022 15:49
-
-
Save pmbaumgartner/66049c355fcfd73bda5bb72a8fd78540 to your computer and use it in GitHub Desktop.
Revisions
-
pmbaumgartner created this gist
Jan 10, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ from spacy.tokenizer import Tokenizer class CTLTokenizer(Tokenizer): # https://stackoverflow.com/a/58718664 def __call__(self, string) -> spacy.tokens.Doc: string = self.clean_string(string) doc = super().__call__(string) return doc def clean_string(self, string: str) -> str: """String cleaning function. You can call this to clean a string without tokenizing. e.g. nlp.tokenizer.clean_string('Some example sentence') """ if not string.endswith("."): string = string + "." return string