Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(5, 5): Frac(-14, 10),
(6, 6): Frac(-1),
(7, 7): Frac(-1),
(8, 8): Frac(-19, 10),
(9, 9): Frac(-16, 10),
(3, 4): Frac(-4),
(5, 6): Frac(-25, 10),
(7, 8): Frac(-22, 10),
(6, 7): Frac(-13, 10),
(8, 9): Frac(-24, 10),
(5, 7): Frac(-27, 10),
(6, 8): Frac(-23, 10),
(7, 9): Frac(-23, 10),
(6, 9): Frac(-23, 10),
}
self.assertRaises(ArgumentNotSatisfied,
_future_cost_estimate,
sentences,
phrase_prob)
def _future_cost_estimate(sentences,
phrase_prob):
'''
warning:
pass the complete one_word_prob
'''
s_len = len(sentences)
cost = {}
one_word_prob = {(st, ed): prob for (st, ed), prob in phrase_prob.items()
if st == ed}
if set(one_word_prob.keys()) != set((x, x) for x in range(1, s_len+1)):
raise ArgumentNotSatisfied("phrase_prob doesn't satisfy the condition")
# add one word prob
for tpl, prob in one_word_prob.items():
index = tpl[0]
cost[(index, index)] = prob
for length in range(1, s_len+1):
for start in range(1, s_len-length+1):
end = start + length
try:
cost[(start, end)] = phrase_prob[(start, end)]
except KeyError:
cost[(start, end)] = -float('inf')
for i in range(start, end):
_val = cost[(start, i)] + cost[(i+1, end)]
if _val > cost[(start, end)]: