Skip to content

Commit b8e601d

Browse files
committed
- time formats no longer count as valid numbers for parser Extract()
- parser Extract() numbers() will not match time formats - increased version to 1.0.2
1 parent 15f9572 commit b8e601d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lara/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Lara - Lingusitic Aim Recognizer API
44

55
__all__ = 'nlp','parser','tippmix','entities'
6-
__version__ = '1.0.1'
6+
__version__ = '1.0.2'
77
__version_info__ = tuple(int(num) for num in __version__.split('.'))
88

99
import sys

lara/parser.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def __init__(self, text=''):
419419
elif text:
420420
self.text = text
421421
self.ntext = self._convert_numbers(self.text)
422-
self._text_ = ' '+self.text+' ' # some complex regular expressions were easier to write for padded text
422+
self._text_ = ' '+self.text+' ' # some complex regular expressions were easier to write for padded text
423423
self._ntext_= ' '+self.ntext+' ' # some complex regular expressions were easier to write for padded text
424424

425425
##### DATA MODEL #####
@@ -505,10 +505,10 @@ def digits(self,n=0,normalize=True,convert=True):
505505
def numbers(self,decimals=True,convert=True):
506506
if self.text:
507507
if decimals:
508-
matches = _re.findall(r'(?<!\d)(?<!\-)((?:\-\s?)?(?:(?:\d\s?)+(?:[\.\,]\d+[^\.\,])?|(?:[\.\,]\d+[^\.\,]))\-?)', re.IGNORECASE, self._ntext_ if convert else self._text_)
508+
matches = _re.findall(r'(?<!\d)(?<!\-)(?<!\:)((?:\-\s?)?(?:(?:\d\s?)+(?:[\.\,]\d+[^\.\,])?|(?:[\.\,]\d+[^\.\,\:]))[\-\:]?)', re.IGNORECASE, self._ntext_ if convert else self._text_)
509509
okay = []
510510
for item in matches:
511-
if item[-1]!='-':
511+
if item[-1] not in ('-',':'):
512512
item = item.replace(',','.')
513513
if not item[-1].isnumeric():
514514
item = item[:-1]
@@ -525,8 +525,8 @@ def numbers(self,decimals=True,convert=True):
525525
pass
526526
return okay
527527
else:
528-
matches = _re.findall(r'(?<!\d\-)(?<![\.\,\d])(\-?(?:\d\s?)+(?![\.\,]\d))[^\d\-]+', re.IGNORECASE, self._ntext_ if convert else self._text_)
529-
okay = [item for item in matches if item and item[-1]!='-']
528+
matches = _re.findall(r'(?<!\d\-)(?<![\.\,\d])(\-?(?:\d\s?)+(?![\.\,]\d))[^\d\-\:]+', re.IGNORECASE, self._ntext_ if convert else self._text_)
529+
okay = [item for item in matches if item and item[-1] not in ('-',':')]
530530
return [int(''.join(number.strip().split())) for number in okay]
531531
return []
532532

@@ -925,8 +925,6 @@ def _currencies_fallback(self):
925925
elif item in number:
926926
okay.append(item)
927927
return okay
928-
929-
930928

931929
# extract commands and arguments from text: "/help lara" will return ('help',['lara'])
932930
def commands(self):

0 commit comments

Comments
 (0)