Skip to content

Commit

Permalink
Merge pull request #34 from AmyOlex/amydev
Browse files Browse the repository at this point in the history
Merging AmyDev with Master to create ground zero version for THYME data analyses.  All I did was change the parsing in the hasYear() method so that it returned the matched string instead of the original string.  This successfully removed the extraneous punctuation at the end that was not allowing conversion into and integer.
  • Loading branch information
AmyOlex authored Jun 9, 2018
2 parents 91ec7b3 + 6910028 commit 09537eb
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Chrono/TimePhrase_to_Chrono.py
Original file line number Diff line number Diff line change
Expand Up @@ -2495,26 +2495,28 @@ def hasYear(tpentity, flags):
for text in text_list:
# get start coordinate of this token in the full string so we can calculate the position of the temporal matches.
text_start, text_end = getSpan(text_norm, text)

#define regular expression to find a 4-digit year from the date format
if(re.search('([0-9]{1,2})[-/:]([0-9]{1,2})[-/:]([0-9]{4})',text)):
if len(text.split("/")) == 3:
start_idx, end_idx = getSpan(text,re.compile("/").split(text)[2])
return True, re.compile("/").split(text)[2], text_start+start_idx, text_start+end_idx, flags
elif len(text.split("-")) == 3:
start_idx, end_idx = getSpan(text,re.compile("-").split(text)[2])
return True, re.compile("-").split(text)[2], text_start+start_idx, text_start+end_idx, flags
result = re.search('([0-9]{1,2})[-/:]([0-9]{1,2})[-/:]([0-9]{4})',text).group(0)
if len(result.split("/")) == 3:
start_idx, end_idx = getSpan(result,re.compile("/").split(result)[2])
return True, re.compile("/").split(result)[2], text_start+start_idx, text_start+end_idx, flags
elif len(result.split("-")) == 3:
start_idx, end_idx = getSpan(result,re.compile("-").split(result)[2])
return True, re.compile("-").split(result)[2], text_start+start_idx, text_start+end_idx, flags
else:
return False, None, None, None, flags
## look for year at start of date
## added by Amy Olex
elif(re.search('([0-9]{4})[-/:]([0-9]{1,2})[-/:]([0-9]{1,2})',text)):
if len(text.split("/")) == 3:
start_idx, end_idx = getSpan(text,re.compile("/").split(text)[0])
return True, re.compile("/").split(text)[0], text_start+start_idx, text_start+end_idx, flags
elif len(text.split("-")) == 3:
start_idx, end_idx = getSpan(text,re.compile("-").split(text)[0])
return True, re.compile("-").split(text)[0], text_start+start_idx, text_start+end_idx, flags
result = re.search('([0-9]{4})[-/:]([0-9]{1,2})[-/:]([0-9]{1,2})',text).group(0)
if len(result.split("/")) == 3:
start_idx, end_idx = getSpan(result,re.compile("/").split(result)[0])
return True, re.compile("/").split(result)[0], text_start+start_idx, text_start+end_idx, flags
elif len(result.split("-")) == 3:
start_idx, end_idx = getSpan(result,re.compile("-").split(result)[0])
return True, re.compile("-").split(result)[0], text_start+start_idx, text_start+end_idx, flags
else:
return False, None, None, None, flags
## special case to look for c.yyyy
Expand Down

0 comments on commit 09537eb

Please sign in to comment.