Skip to content
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

Handle unicode text #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions theanets/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ class Text(object):
A string containing each character in the alphabet.
'''

def __init__(self, text, alpha=None, min_count=2, unknown='\0'):
def __init__(self, text, alpha=None, min_count=2, unknown=u'\0'):
self.alpha = alpha
if self.alpha is None:
self.alpha = ''.join(sorted(set(
char for char, count in
collections.Counter(text).items()
if char != unknown and count >= min_count)))
self.text = re.sub(r'[^{}]'.format(re.escape(self.alpha)), unknown, text)
self.text = re.sub(unicode(r'[^{}]', 'utf-8').format(re.escape(self.alpha)), unknown, text)
assert unknown not in self.alpha
self._rev_index = unknown + self.alpha
self._fwd_index = dict(zip(self._rev_index, range(1 + len(self.alpha))))
Expand Down