@@ -124,7 +124,7 @@ def keys(self):
124124 def values (self ):
125125 return self ._lazy ("values" )
126126
127- def update (self , * args ):
127+ def update (self , * args , ** kwargs ):
128128 return self ._lazy ("update" , * args )
129129
130130 def pop (self , * args ):
@@ -324,10 +324,10 @@ def penntreebank2universal(token, tag):
324324 ("cry" , - 1.00 ): set ((":'(" , ":'''(" , ";'(" )),
325325}
326326
327- RE_EMOTICONS = [
327+ TEMP_RE_EMOTICONS = [
328328 r" ?" .join ([re .escape (each ) for each in e ]) for v in EMOTICONS .values () for e in v
329329]
330- RE_EMOTICONS = re .compile (r"(%s)($|\s)" % "|" .join (RE_EMOTICONS ))
330+ RE_EMOTICONS = re .compile (r"(%s)($|\s)" % "|" .join (TEMP_RE_EMOTICONS ))
331331
332332# Handle sarcasm punctuation (!).
333333RE_SARCASM = re .compile (r"\( ?\! ?\)" )
@@ -490,9 +490,9 @@ class Lexicon(lazydict):
490490 def __init__ (
491491 self ,
492492 path = "" ,
493- morphology = None ,
494- context = None ,
495- entities = None ,
493+ morphology = "" ,
494+ context = "" ,
495+ entities = "" ,
496496 NNP = "NNP" ,
497497 language = None ,
498498 ):
@@ -724,7 +724,7 @@ def apply(self, tokens):
724724 t [i ] = [t [i ][0 ], r [1 ]]
725725 return t [len (o ) : - len (o )]
726726
727- def insert (self , i , tag1 , tag2 , cmd = "prevtag" , x = None , y = None ):
727+ def insert (self , i , tag1 , tag2 , cmd = "prevtag" , x = None , y = None , * args ):
728728 """Inserts a new rule that updates words with tag1 to tag2,
729729 given constraints x and y, e.g., Context.append("TO < NN", "VB")
730730 """
@@ -739,7 +739,7 @@ def insert(self, i, tag1, tag2, cmd="prevtag", x=None, y=None):
739739 def append (self , * args , ** kwargs ):
740740 self .insert (len (self ) - 1 , * args , ** kwargs )
741741
742- def extend (self , rules = None ):
742+ def extend (self , rules = None , * args ):
743743 if rules is None :
744744 rules = []
745745 for r in rules :
@@ -1570,9 +1570,8 @@ def parse(
15701570
15711571TOKENS = "tokens"
15721572
1573-
15741573class TaggedString (str ):
1575- def __new__ (self , string , tags = None , language = None ):
1574+ def __new__ (cls , string , tags = None , language = None ):
15761575 """Unicode string with tags and language attributes.
15771576 For example: TaggedString("cat/NN/NP", tags=["word", "pos", "chunk"]).
15781577 """
@@ -1588,7 +1587,7 @@ def __new__(self, string, tags=None, language=None):
15881587 for s in string
15891588 ]
15901589 string = "\n " .join (" " .join ("/" .join (token ) for token in s ) for s in string )
1591- s = str .__new__ (self , string )
1590+ s = str .__new__ (cls , string )
15921591 s .tags = list (tags )
15931592 s .language = language
15941593 return s
@@ -1634,7 +1633,7 @@ def language(self):
16341633 return self ._language
16351634
16361635 @classmethod
1637- def train (self , s , path = "spelling.txt" ):
1636+ def train (cls , s , path = "spelling.txt" ):
16381637 """Counts the words in the given string and saves the probabilities at the given path.
16391638 This can be used to generate a new model for the Spelling() constructor.
16401639 """
0 commit comments