@@ -956,7 +956,7 @@ def currencies(self,normalize=True,convert=True):
956
956
return []
957
957
958
958
def _currencies_fallback (self ):
959
- dates = [item .replace ('-' ,':' ) for item in self .dates ()]
959
+ dates = [item .replace ('-' ,':' ) for item in self .dates ()]
960
960
number = [str (item ) for item in self .numbers ()]
961
961
against = [item [- 2 ] if (len (item )> 2 and item [- 1 ]== 0 and item [- 2 ]== '.' ) else item for item in number ]
962
962
ignore = []
@@ -977,15 +977,39 @@ def _currencies_fallback(self):
977
977
okay .append (item )
978
978
return okay
979
979
980
- # extract commands and arguments from text: " /help lara" will return ( 'help',[' lara'])
980
+ # extract commands and arguments from text: /help "about lara" will return [ 'help','about lara']
981
981
def commands (self ):
982
- if self .text and self .text [0 ] == '/' :
983
- commands = (lara .nlp .trim (str (self .text [1 :]))).split (" " )
984
- if len (commands )> 1 :
985
- return (commands [0 ],commands [1 :])
986
- else :
987
- return (commands [0 ],[])
988
- return ('' ,[])
982
+ result = []
983
+ if len (self .text )> 1 and self .text [0 ] in ('/' ,'\\ ' ):
984
+ quote = ''
985
+ keyword = ''
986
+ for char in self .text [1 :]:
987
+ if char in (' ' ,'"' ,"'" ):
988
+ if char == ' ' :
989
+ if quote :
990
+ keyword += ' '
991
+ else :
992
+ if keyword :
993
+ result .append (keyword )
994
+ keyword = ''
995
+ elif char in ('"' ,"'" ):
996
+ if not quote :
997
+ if keyword :
998
+ result .append (keyword )
999
+ keyword = ''
1000
+ quote = char
1001
+ elif quote == char :
1002
+ if keyword :
1003
+ result .append (keyword )
1004
+ keyword = ''
1005
+ quote = ''
1006
+ else :
1007
+ keyword += char
1008
+ else :
1009
+ keyword += char
1010
+ if keyword :
1011
+ result .append (keyword )
1012
+ return result
989
1013
990
1014
# extract list of emojis from text via https://gist.github.com/naotokui/
991
1015
def emojis (self ):
@@ -1065,9 +1089,9 @@ def timestamps(self,current=False):
1065
1089
dates = self .dates (False )
1066
1090
relative = self .relative_dates (False ,c_relative )
1067
1091
times = self .times (False ,True ,c_times )
1068
- dates_pos = []
1069
- relative_pos = []
1070
- times_pos = []
1092
+ dates_pos = []
1093
+ relative_pos = []
1094
+ times_pos = []
1071
1095
for item in dates :
1072
1096
for match in _re .finditer (r'\b' + re .escape (item ), re .IGNORECASE , self .ntext ):
1073
1097
dates_pos .append (match .span ()[0 ])
@@ -1083,13 +1107,13 @@ def timestamps(self,current=False):
1083
1107
dates = self .dates ()
1084
1108
relative = self .relative_dates (True ,c_relative )
1085
1109
times = self .times (True ,True ,c_times )
1086
- results = []
1087
- last_date = ''
1088
- last_date_a = ''
1089
- last_time = ''
1090
- dates_i = 0
1091
- relative_i = 0
1092
- times_i = 0
1110
+ results = []
1111
+ last_date = ''
1112
+ last_date_a = ''
1113
+ last_time = ''
1114
+ dates_i = 0
1115
+ relative_i = 0
1116
+ times_i = 0
1093
1117
for i in range (max (dates_pos + relative_pos + times_pos )+ 1 ):
1094
1118
if i == dates_pos [dates_i ]:
1095
1119
if last_date or last_time :
0 commit comments