Skip to content

Commit

Permalink
feat(api texts): new TextRange class for getting text.
Browse files Browse the repository at this point in the history
  • Loading branch information
YishaiGlasner committed Aug 23, 2023
1 parent 5929826 commit e90b0e7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sefaria/model/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,29 @@ def __call__(cls, *args, **kwargs):
return super(TextFamilyDelegator, cls).__call__(*args, **kwargs)


class TextRange(AbstractTextRecord, metaclass=TextFamilyDelegator):

def __init__(self, oref, lang, vtitle):
if isinstance(oref.index_node, JaggedArrayNode):
self.oref = oref
else:
child_ref = oref.default_child_ref()
if child_ref == oref:
raise InputError("Can not get TextChunk at this level, please provide a more precise reference")
self.oref = child_ref
self.lang = lang
self.vtitle = vtitle
self._text = None

def set_text(self):
self._text = Version().load({'actualLanguage': self.lang, 'versionTitle': self.vtitle}, self.oref.part_projection())

def get_text(self):
if not self._text:
self.set_text()
return self._text


class TextChunk(AbstractTextRecord, metaclass=TextFamilyDelegator):
"""
A chunk of text corresponding to the provided :class:`Ref`, language, and optional version name.
Expand Down

0 comments on commit e90b0e7

Please sign in to comment.