-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lowercasing functionality to merge_tokens_into_text and col…
…lect_svo_triples
- Loading branch information
Showing
2 changed files
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from spacy.tokens import Doc, Token | ||
|
||
|
||
def merge_tokens_into_text(tokens: list[Token]) -> str: | ||
text = "".join(token.text_with_ws for token in tokens) | ||
return text.rstrip() | ||
def merge_tokens_into_text(tokens: list[Token], lower: bool = False) -> str: | ||
text = "".join(token.text_with_ws for token in tokens).rstrip() | ||
return text.lower() if lower else text | ||
|
||
|
||
def collect_svo_triples(doc: Doc) -> list[tuple[str, str, str]]: | ||
def collect_svo_triples(doc: Doc, lower: bool = False) -> list[tuple[str, str, str]]: | ||
svo_triples = [] | ||
for sentence in doc.sents: | ||
for s, v, o in sentence._.svo_triples: | ||
s = merge_tokens_into_text(s) | ||
v = merge_tokens_into_text(v) | ||
o = merge_tokens_into_text(o) | ||
s = merge_tokens_into_text(s, lower) | ||
v = merge_tokens_into_text(v, lower) | ||
o = merge_tokens_into_text(o, lower) | ||
svo_triples.append((s, v, o)) | ||
return svo_triples |
This file contains 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 characters