Skip to content

Commit

Permalink
use quote module to send dumb quotes to marian,
Browse files Browse the repository at this point in the history
but return correctly quoted text to the user
  • Loading branch information
sam-writer committed Feb 24, 2020
1 parent 7be4125 commit 57365f2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions marian_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
WebSocketAddressException,
)

from marian_client.quote_manager import Quotes

GENERIC_WEBSOCKET_ERROR_CODE = 469


Expand Down Expand Up @@ -142,10 +144,11 @@ def _send_message(self, tokenized_sentence: str):
# since there is no hope if we can't connect
self._check_connection()

orig = tokenized_sentence
orignal_message = Quotes(tokenized_sentence)

try:
self.ws.send(tokenized_sentence)
# need to strip smart quotes before sending
self.ws.send(orignal_message.simplified)
except (
WebSocketConnectionClosedException,
WebSocketAddressException,
Expand Down Expand Up @@ -180,7 +183,9 @@ def _send_message(self, tokenized_sentence: str):
self.ws.connected = False

assert r is not None, "If r isn't set by here, we didn't send a request"
return success, r
# need to add back in smart quotes
corrected_message_requoted = orignal_message.requote_modified_string(r)
return success, corrected_message_requoted

def __call__(self, tokenized_sentence: str):

Expand Down

0 comments on commit 57365f2

Please sign in to comment.