Ejemplo n.º 1
0
def cal_unit_price(info, currency):
    """
	计算单个材料价格
	读取相关信息
	输出一个字典,key为材料,value为价格
	"""
    price = {}

    for key, value in info.items():
        if (key == 'condition_line'):
            for condition in value:
                roman_sum = ''
                earth_sum = ''
                value_number = 0

                for temp in ['Silver', 'Gold', 'Iron']:
                    if re.search(temp, condition) != None:
                        sentense = condition.split(temp)

                        for i in sentense[0].split(' '):
                            if i:
                                roman = currency[i]
                                roman_sum = roman_sum.join(['', roman])
                                earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(
                                    roman_sum)

                        for i in sentense[1].split(' '):
                            if i.isdigit():
                                value_number = float(i)  #单价可能含小数

                        price[temp] = value_number / earth_sum
    return price
def cal_unit_price(info,currency):
	"""
	计算单个材料价格
	读取相关信息
	输出一个字典,key为材料,value为价格
	"""
	price={}

	for key,value in info.items():
		if(key=='condition_line'):
			for condition in value:
				roman_sum=''
				earth_sum=''
				value_number=0

				for temp in ['Silver','Gold','Iron']:
					if re.search(temp,condition) != None:
						sentense = condition.split(temp)

						for i in sentense[0].split(' '):
							if i:
								roman = currency[i]
								roman_sum = roman_sum.join(['',roman])
								earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(roman_sum)

						for i in sentense[1].split(' '):
							if i.isdigit():
								value_number = float(i)        #单价可能含小数

						price[temp] = value_number / earth_sum
	return price
Ejemplo n.º 3
0
def get_answers(info, currency, price):
    """
	返回模块
	读取相关参数
	返回结果
	"""
    for key, value in info.items():
        if (key == 'question_line'):
            for i in value:
                roman_sum = ''
                words_total = ''
                material = ''

                if re.search(r'^how much is', i) != None:
                    for words in i.split(' '):
                        if currency.has_key(words):
                            valuerance = currency[words]
                            words_total = words_total.join(['', words])
                            words_total = words_total.join(['', ' '])
                            roman_sum = roman_sum.join(['', valuerance])

                    earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(
                        roman_sum)
                    print words_total, 'is', earth_sum
                elif re.search(r'^how many Credits is', i) != None:
                    for words in i.split(' '):
                        if currency.has_key(words):
                            valuerance = currency[words]
                            words_total = words_total.join(['', words])
                            words_total = words_total.join(['', ' '])
                            roman_sum = roman_sum.join(['', valuerance])

                        earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(
                            roman_sum)
                        if price.has_key(words):
                            material_price = price[words]
                            material = words
                            total_price = earth_sum * material_price
                    print words_total, material, 'is', int(
                        total_price), 'Credits'  #为了保持与原题输出一致,省略小数点
                else:
                    print 'I have no idea what you are talking about'
def get_answers(info, currency, price):
	"""
	返回模块
	读取相关参数
	返回结果
	"""
	for key,value in info.items():
		if(key=='question_line'):
			for i in value:
				roman_sum=''
				words_total=''
				material=''

				if re.search(r'^how much is',i) != None:
					for words in i.split(' '):
						if currency.has_key(words):
							valuerance=currency[words]
							words_total = words_total.join(['',words])
							words_total = words_total.join(['',' '])
							roman_sum=roman_sum.join(['',valuerance])

					earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(roman_sum)
					print words_total,'is',earth_sum
				elif re.search(r'^how many Credits is',i) != None:
					for words in i.split(' '):
						if currency.has_key(words):
							valuerance = currency[words]
							words_total = words_total.join(['',words])
							words_total = words_total.join(['',' '])
							roman_sum = roman_sum.join(['',valuerance])

						earth_sum = translate_to_earth_numerals.translate_to_earth_numerals(roman_sum)
						if price.has_key(words):
							material_price = price[words]
							material = words
							total_price = earth_sum * material_price
					print words_total,material,'is',int(total_price),'Credits'                      #为了保持与原题输出一致,省略小数点
				else:
					print 'I have no idea what you are talking about'