Spaces:
Paused
Paused
from utils import clean_word | |
def generic_template(input_word, cleaned_word=None, similarity_score=None, confidence_score=None, similar_words=None, is_food=None, food_nonfood_score=None, dictionary_word=None, sr_legacy_food_category=None, wweia_category=None, dry_matter_content=None, water_content=None, leakage=None, specificity=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'similarity_score': similarity_score, | |
'confidence_score': confidence_score, | |
'similar_words': similar_words, | |
'is_food': is_food, | |
'food_nonfood_score': food_nonfood_score, | |
'dictionary_word': dictionary_word, | |
'sr_legacy_food_category': sr_legacy_food_category, | |
'wweia_category': wweia_category, | |
'dry_matter_content': dry_matter_content, | |
'water_content': water_content, | |
'leakage': leakage, | |
'specificity': specificity | |
} | |
def empty_template(input_word, cleaned_word=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'similarity_score': None, | |
'confidence_score': None, | |
'similar_words': None, | |
'is_food': None, | |
'food_nonfood_score': None, | |
'dictionary_word': None, | |
'sr_legacy_food_category': None, | |
'wweia_category': None, | |
'dry_matter_content': None, | |
'water_content': None, | |
'leakage': None, | |
'specificity': None | |
} | |
def usda_template(input_word, cleaned_word=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'dictionary_word': 'USDA Food Item', | |
'similarity_score': 1.0, | |
'confidence_score': 1.0, | |
'similar_words': None, | |
'is_food': True, | |
'food_nonfood_score': 1.0, | |
'sr_legacy_food_category': 'Government Donation (Not Counted)', | |
'wweia_category': 'Government Donation (Not Counted)', | |
'dry_matter_content': None, | |
'water_content': None, | |
'leakage': None, | |
'specificity': None | |
} | |
def nonfood_template(input_word, cleaned_word=None, food_nonfood_score=None, similar_words=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'similarity_score': None, | |
'confidence_score': None, | |
'similar_words': similar_words, | |
'is_food': False, | |
'food_nonfood_score': food_nonfood_score, | |
'dictionary_word': 'Non-Food Item', | |
'sr_legacy_food_category': 'Non-Food Item', | |
'wweia_category': 'Non-Food Item', | |
'dry_matter_content': 0, | |
'water_content': 0, | |
'leakage': 0, | |
'specificity': None | |
} | |
def heterogeneous_template(input_word, cleaned_word=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'similarity_score': 1, | |
'confidence_score': 1, | |
'similar_words': None, | |
'is_food': True, | |
'food_nonfood_score': 1, | |
'dictionary_word': 'Heterogeneous Mixture', | |
'wweia_category': 'Heterogeneous Mixture', | |
'sr_legacy_food_category': 'Heterogeneous Mixture', | |
'dry_matter_content': 0.27, | |
'water_content': 0.73, | |
'leakage': 0.1, | |
'specificity': 'Heterogeneous Mixture' | |
} | |
def multi_item_template(input_word, cleaned_word=None, conservative_mapping=None): | |
if cleaned_word is None: | |
cleaned_word = clean_word(input_word) | |
return { | |
'input_word': input_word, | |
'cleaned_word': cleaned_word, | |
'similarity_score': 1, | |
'confidence_score': 1, | |
'similar_words': None, | |
'is_food': True, | |
'food_nonfood_score': 1, | |
'dictionary_word': f"{conservative_mapping['dictionary_word']} (Lowest DMC)", | |
'wweia_category': conservative_mapping['wweia_category'], | |
'sr_legacy_food_category': conservative_mapping['sr_legacy_food_category'], | |
'dry_matter_content': conservative_mapping['dry_matter_content'], | |
'water_content': conservative_mapping['water_content'], | |
'leakage': conservative_mapping['leakage'], | |
'specificity': conservative_mapping['specificity'] | |
} | |