我正在尝试使用模式包编写扩展的共轭函数。例如,当试图使用以下元组来结合动词声明时:
tuple = ('allege', 3, 'future', 'plural', 'subjunctive', 'progressive', False)
我得到了AttributeError: 'int' object has no attribute 'lower'.
当我打印元组项时,它们会很好地打印出来,甚至是元组的整数项,但是当我尝试在共轭函数中使用它们时,如下所示:
conjugate(tuple[0], tuple[1], tuple[2], tuple[3], tuple[4], tuple[5], tuple[6])
我收到AttributeError: 'int' object has no attribute 'lower'
错误,无法在conjugate()
函数中使用它。
有人可以帮我解决这个问题。
答案 0 :(得分:0)
conjugate
函数中的一个变量属于int
类型。
实施例
i = 1
i.lower()
最有可能的是tuple[1]
,这会给你带来麻烦。
答案 1 :(得分:0)
我完全忘了发布我的功能。我同时解决了这个问题,这是解决方案,以防将来有人使用它。
这是一个生成具有动词共轭所需参数的元组列表的函数:
def tuple_generate(list):
"""function generates list of all possible tuples for a list of verbs,
consisting of arguments needed for verb conjugation using
pattern.en conjugate function"""
value = 0
L = []
import pattern
from pattern.en import conjugate
tense = ['present', 'past', 'future']
person = [1, 2, 3]
number = ["singular", "plural"]
mood = ["indicative", "imperative", "conditional", "subjunctive"]
aspect = ["imperfective", "perfective", "progressive"]
negated = [False, True]
for i, a, b, c, d, e, f in [(i, a, b, c, d, e, f) for i in list for a in tense for b in person for c in number for d in mood for e in aspect for f in negated]:
x = i, a, b, c, d, e, f
#print x
value += 1
L.append(x)
return L
共轭功能本身:
def verb_conjugate(list):
"""function conjugates tuples of verbs and associated arguments
needed in the pattern.en conjugate function"""
import pattern
from pattern.en import conjugate
V = []
value = 0
for tuple in list:
x = conjugate(tuple[0], tuple[1], tuple[2], tuple[3], tuple[4], tuple[5], tuple[6])
value += 1
V.append(x)
V = sorted(set(V))
for i in V:
if i == None:
V.remove(i)
return V
对于我所做的事情,可能有一个更优雅的解决方案,但这是来自Python蚱蜢的土地。 :)
投注,