-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
|
||
from .word import Word | ||
|
||
string_types = ("".__class__, u"".__class__) | ||
|
||
|
||
class Census(object): | ||
def __init__(self, words, lang='eng'): | ||
if isinstance(words, ("".__class__, u"".__class__)): | ||
words = re.split('\s+', words) | ||
elif isinstance(words, (list, tuple)): | ||
words = list(words) | ||
else: | ||
raise ValueError('words argument must be either string or list') | ||
|
||
assert type(words) is list | ||
|
||
self.words = [] | ||
for word in list(words): | ||
if isinstance(word, string_types): | ||
self.words.append(Word(word, lang)) | ||
elif isinstance(word, Word): | ||
self.words.append(word) | ||
else: | ||
raise ValueError("Invalid word type: '%s'.\ Words must\ | ||
be ety.Word objects or strings" % str(type(word))) | ||
|
||
def __eq__(self, other): | ||
return self.words == other.words |
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