-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/truncate-sentences-in-transcript-str #153
feature/truncate-sentences-in-transcript-str #153
Conversation
Codecov Report
@@ Coverage Diff @@
## main #153 +/- ##
==========================================
- Coverage 94.82% 94.53% -0.30%
==========================================
Files 50 50
Lines 2531 2543 +12
==========================================
+ Hits 2400 2404 +4
- Misses 131 139 +8
Continue to review full report at Codecov.
|
I didn't even think of using a regex to strip. Cool! Could you show what happens when you simply call the object? In ipython instead of using print just call it: t = read_some_transcript()
t calling |
This is a little tricky. In ipython, we get the non-truncated version so it must use Looks like I'm not familiar with Jupyter, but how are you using the transcript objects? According to this post, Based on this I think we can/should only use |
It's a pretty common operation to do the following in notebooks: Where you load / compute some data and then just "print" out the loaded object at the end of the cell. I think this has become the norm in the jupyter world because if Python is running in an ipython client (jupyter) it will actually call to a Anyway, its the norm in jupyter world to do that. I think there may be a way to do it too. Technically all that is being printed is just string = "Transcript("
for k, v in self.to_dict().items():
if k != "sentences":
string += f"{k}={v}, "
else:
string += f"{k}=[...], "
# remove last comma and space
string = string[:-2]
# close paren
string += ")" I am not the happiest with that but it probably works? What may be interesting is to make it more pretty? like instead of just "[...]" we could say "[...] (n=1002)" for like "number of sentences" or something? Idk. now I am just tossing ideas out. Happy to merge this in because it is an improvement from where we are currently but your call. Feel free to merge or keep tinkering. |
Gotcha, yeah I was mainly curious whether changing
Good idea! I did something similar except I used |
It will now output the following when just calling the object (same content as before):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. I have never even heard of the vars
method. Very neat! Thanks!!
Link to Relevant Issue
This pull request resolves #149
Description of Changes
Changing
Transcript
's__str__
method to truncate sentences. I did this with regex which was the least hacky thing I could think of. Alternatively, I was thinking about doing something like creating a deepcopy ofself
in__str__
and replacingsentences
with[...]
, but that seems more hacky. There's not a standard way to hide/truncate a single property of a class afaik.repr()
will still show the full sentences.Testing
Running
print(EXAMPLE_TRANSCRIPT)
Before:
After