Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试在nltk_contrib.timex中使用接地方法时出错_Python_Nltk - Fatal编程技术网

Python 尝试在nltk_contrib.timex中使用接地方法时出错

Python 尝试在nltk_contrib.timex中使用接地方法时出错,python,nltk,Python,Nltk,当我试图运行上面的代码时,我得到了以下错误 import datetime from nltk_contrib import timex now = datetime.date.today() basedate = timex.Date(now.year, now.month, now.day) print timex.ground(timex.tag("Hai i would like to go to mumbai 22nd of next month"), basedate) pri

当我试图运行上面的代码时,我得到了以下错误

import datetime
from nltk_contrib import timex

now = datetime.date.today()
basedate = timex.Date(now.year, now.month, now.day)

print timex.ground(timex.tag("Hai i would like to go to mumbai 22nd of next month"), basedate)

print str(datetime.date.day)

我应该如何纠正此错误

timex模块有一个错误,在
ground
函数中引用全局变量时没有赋值

要修复该错误,请添加以下代码,该代码应从第171行开始:

def接地(标记文字、基准日期):

#找到所有标识的timex并将其放入列表中
timex_regex=re.compile(r'.*?',re.DOTALL)
timex\u found=timex\u regex.findall(标记的\u文本)
timex_found=map(λtimex:re.sub(r'','',timex)\
timex_(已找到)
#相应地计算新的日期
对于在timex_中找到的timex:

全局月份#上述关于将月份添加为全局变量的解决方案在一行多次调用timex时会导致其他问题,因为除非再次导入,否则不会重置变量。这在AWS Lambda中的部署环境中发生

一个不是超级漂亮但不会引起问题的解决方案就是在ground函数中再次设置月份值:

# Find all identified timex and put them into a list
timex_regex = re.compile(r'<TIMEX2>.*?</TIMEX2>', re.DOTALL)
timex_found = timex_regex.findall(tagged_text)
timex_found = map(lambda timex:re.sub(r'</?TIMEX2.*?>', '', timex), \
            timex_found)

# Calculate the new date accordingly
for timex in timex_found:
    global month # <--- here is the global reference assignment
def地面(标记文字、基准日期):
#找到所有标识的timex并将其放入列表中
timex_regex=re.compile(r'.*?',re.DOTALL)
timex\u found=timex\u regex.findall(标记的\u文本)
timex_found=map(λtimex:re.sub(r'','',timex)\
timex_(已找到)
#相应地计算新的日期
对于在timex_中找到的timex:
month=“(一月|二月|三月|四月|五月|六月|七月|八月|九月|\

十月(十一月,十二月)“听起来你应该考虑在Github上提交一个bug:
# Find all identified timex and put them into a list
timex_regex = re.compile(r'<TIMEX2>.*?</TIMEX2>', re.DOTALL)
timex_found = timex_regex.findall(tagged_text)
timex_found = map(lambda timex:re.sub(r'</?TIMEX2.*?>', '', timex), \
            timex_found)

# Calculate the new date accordingly
for timex in timex_found:
    global month # <--- here is the global reference assignment
def ground(tagged_text, base_date):

    # Find all identified timex and put them into a list
    timex_regex = re.compile(r'<TIMEX2>.*?</TIMEX2>', re.DOTALL)
    timex_found = timex_regex.findall(tagged_text)
    timex_found = map(lambda timex:re.sub(r'</?TIMEX2.*?>', '', timex), \
            timex_found)

    # Calculate the new date accordingly
    for timex in timex_found:
        month = "(january|february|march|april|may|june|july|august|september| \
        october|november|december)" # <--- reset month to the value it is set to upon import