Repository: mark-watson/langchain-book-examples Branch: main Commit: e01426392468 Files: 159 Total size: 1.5 MB Directory structure: gitextract_du4dxcr1/ ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── CHAPTERS_and_CODE_no_longer_in-book/ │ ├── README.md │ └── zapier_integrations/ │ ├── README.md │ ├── README_code.md │ ├── get_google_calendar.py │ ├── requirements.txt │ └── send_gmail.py ├── Makefile ├── README.md ├── cooking_recipes/ │ ├── README.md │ ├── data/ │ │ ├── .gitignore │ │ ├── correlated-ingredients.json │ │ ├── desert.json │ │ ├── fish.json │ │ ├── ingredients.json │ │ ├── meat.json │ │ ├── misc.json │ │ ├── recipes.json │ │ ├── tiny.json │ │ └── vegetarian.json │ ├── data.py │ ├── recipe_generator.py │ └── text_data/ │ ├── Aioli Sauce.txt │ ├── Apple Muffins.txt │ ├── Balsamic Mushrooms.txt │ ├── Barbecued Chicken.txt │ ├── Barbecued Eggplant.txt │ ├── Barbecued Salmon with Basil.txt │ ├── Basil Vinaigrette Salad Dressing.txt │ ├── Black Bean Dip.txt │ ├── Borscht.txt │ ├── Brined Barbecued Chicken.txt │ ├── Cauliflower and Broccoli Pizza Crust.txt │ ├── Chicken Cacciatore.txt │ ├── Chicken Schnitzel.txt │ ├── Chicken with Cream of Mushroom Soup.txt │ ├── Chinese Shrimp with Zucchini Squash.txt │ ├── Crock Pot Lemon Honey Chicken.txt │ ├── Curried Chicken Legs.txt │ ├── Curried Yogurt Dip.txt │ ├── Dijon Sour Cream Dip.txt │ ├── Dijon Yogurt Dip.txt │ ├── Easy Cake.txt │ ├── English Scones.txt │ ├── Fresh Tomato Sauce.txt │ ├── Fried Chicken.txt │ ├── Homemade Salad Dressing.txt │ ├── Honey Chinese Shrimp.txt │ ├── Honey-Curried Chicken.txt │ ├── Indonesian Barbecue Sauce.txt │ ├── Indonesian Chicken Sate.txt │ ├── Irene's Snickerdoodle Cookies.txt │ ├── Japanese Ginger Salad Dressing.txt │ ├── Lemon Sesame Broccoli.txt │ ├── Poached Salmon with Wine and Lemon.txt │ ├── Quick Sweet and Sour Sauce.txt │ ├── Scottish Shortbread.txt │ ├── Simple Italian Chicken.txt │ ├── Spicy Barbecued Chicken.txt │ ├── Spicy Braised Chicken.txt │ ├── Tasty Black Bean Dip.txt │ └── Whole Wheat Bread.txt ├── data/ │ ├── chemistry.txt │ ├── economics.txt │ ├── health.txt │ └── sports.txt ├── data_small/ │ └── sports.txt ├── embedchain_test/ │ ├── .gitignore │ ├── README.md │ ├── app.py │ ├── data/ │ │ ├── haskell-cookbook.txt │ │ └── lovinglisp-2.txt │ ├── process_pdfs.py │ └── requirements.txt ├── extraction/ │ ├── README.md │ ├── person_data.py │ └── prompt.txt ├── from_langchain_docs/ │ ├── README.md │ ├── gpt_4o_test.py │ ├── memory_langchain_test.py │ ├── requirements.txt │ └── search_simple.py ├── google_drive_llm/ │ ├── .gitignore │ ├── README.md │ ├── data/ │ │ └── sports.txt │ ├── fetch_txt_files.py │ ├── index_and_QA.py │ └── requirements.txt ├── hugging_face/ │ ├── README.md │ ├── hf_transformer_local.py │ ├── requirements.txt │ ├── simple_example.py │ ├── test1.py │ └── throwaway_test.py ├── kg_search/ │ ├── Google_KG_helper.py │ ├── Google_Knowledge_Graph_Search.py │ └── README.md ├── kor/ │ ├── README.md │ └── dates.py ├── langchain_dbpedia_agent/ │ ├── QA.py │ ├── README.md │ ├── custom_func_dbpedia.py │ └── requirements.txt ├── langchain_getting_started/ │ ├── .gitignore │ ├── README.md │ ├── agent_test.py │ ├── chroma_persist_index.py │ ├── chroma_use_disk_index_for_query.py │ ├── country_information.py │ ├── directions_template.py │ ├── doc_search.py │ ├── read_text_files.py │ └── test.py ├── llama-index_case_study/ │ ├── .gitignore │ ├── README.md │ ├── requirements.txt │ └── web_page_QA.py ├── llama.cpp/ │ ├── README.md │ └── test.py ├── llm_enhanced_search_ddg_ollama/ │ ├── README.md │ └── llm_enhanced_search.py ├── neo4j/ │ ├── README.md │ ├── credentials.json │ └── test_example.py ├── ollama_langchain/ │ ├── README.md │ ├── llama3-instruct-8b.py │ ├── mistral-7b.py │ ├── rag_test.py │ └── requirements.txt ├── prompt_examples/ │ ├── two-shot-2-var.txt │ └── two-shot-2.txt ├── rag/ │ ├── README.md │ ├── requirements.txt │ ├── reranking_rag_llama_index.py │ ├── simple_llama_index_retrieve_docs.py │ └── simple_rag_llama_index.py ├── requirements.txt ├── sqlite/ │ ├── README.md │ ├── requirements.txt │ └── sqlite_chat_test.py ├── summarization/ │ ├── README.md │ ├── prompt.txt │ ├── requirements.txt │ └── summarization_example.py ├── tavily_search/ │ ├── READMS.md │ ├── langchain_test.py │ └── llamaindex_test.py ├── text_db_llm/ │ ├── README.md │ ├── data/ │ │ ├── chemistry.txt │ │ ├── economics.txt │ │ ├── health.txt │ │ └── sports.txt │ ├── requirements.txt │ └── text_db_llm.py ├── tool_search_math_example/ │ ├── requirements.txt │ └── tool_search_math_example.py └── tools_langchain/ ├── doc_example.py └── loop_collection_with_function.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: mark-watson custom: [“https://buy.stripe.com/aFa5kudvI3mTfv5c5F8N200” stripe.com] ================================================ FILE: .gitignore ================================================ *~ .DS_Store venv .idea *.pyc target client_secrets.json cl*.json index.json *.log cache ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/README.md ================================================ # Examples for older 2023 version of my book Look in sub-diurecotries for original book content that has been deprecated. The old book chapter is now a README.md file. For example, I deprecated the Zapier example so that book chapter is now available at [https://github.com/mark-watson/langchain-book-examples/blob/main/CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/README.md](https://github.com/mark-watson/langchain-book-examples/blob/main/CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/README.md) and the original Python code examples are in the same directory as the book chapter. ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/README.md ================================================ # Using Zapier Integrations With GMail and Google Calendar Zapier is a service for writing integrations with hundreds of cloud services. Here we will write some demos for writing automatic integrations with Gmail and Google Calendar. Using the Zapier service is simple. You need to register the services you want to interact with on the Zapier developer web site and then you can express how you want to interact with services using natural language prompts. ## Set Up Development Environment You will need a developer key for [Zapier Natural Language Actions API](https://nla.zapier.com/get-started/). Go to this linked web page and look for "Dev App" in the "Provider Name" column. If a key does not exist, you'll need to set up an action to create a key. Click "Set up Actions" and follow the instructions. Your key will be in the Personal API Key column for the "Dev App." Click to reveal and copy your key. You can [read the documentation](https://nla.zapier.com/api/v1/dynamic/docs). When I set up my Zapier account I set up three Zapier Natural Language Actions: - Gmail: Find Email - Gmail: Send Email - Google Calendar: Find Event If you do the same then you will see the Zapier registered actions: ![](zapier1.png) ## Sending a Test GMail In the following example replace **TEST_EMAIL_ADDRESS** with an email address that you can use for testing. ```python from langchain.llms import OpenAI from langchain.agents import initialize_agent from langchain.agents.agent_toolkits import ZapierToolkit from langchain.utilities.zapier import ZapierNLAWrapper llm = OpenAI(temperature=0) zapier = ZapierNLAWrapper() toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier) agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True) agent.run("Send an Email to TEST_EMAIL_ADDRESS via gmail that is a pitch for hiring Mark Watson as a consultant for deep learning and large language models") ``` Here is the sample output: ```console $ python send_gmail.py > Entering new AgentExecutor chain... I need to use the Gmail: Send Email tool Action: Gmail: Send Email Action Input: Send an email to TEST_EMAIL_ADDRESS with the subject "Pitch for Hiring Mark Watson as a Consultant for Deep Learning and Large Language Models" and the body "Dear Mark Watson, I am writing to you to pitch the idea of hiring you as a consultant for deep learning and large language models. I believe you have the expertise and experience to help us achieve our goals. Please let me know if you are interested in discussing further. Thank you for your time." Cc: not enough information provided in the instruction, missing Cc Observation: {"labelIds": "SENT"} Thought: I now know the final answer Final Answer: An email has been sent to TEST_EMAIL_ADDRESS with the subject "Pitch for Hiring Mark Watson as a Consultant for Deep Learning and Large Language Models" and the body "Dear Mark Watson, I am writing to you to pitch the idea of hiring you as a consultant for deep learning and large language models. I believe you have the expertise and experience to help us achieve our goals. Please let me know if you are interested in discussing further. Thank you for your time." > Finished chain. ``` ## Google Calendar Integration Example Assuming that you configured the Zapier Natural Language Action "Google Calendar: Find Event" then the same code we used to send an email in the last section works for checking calendar entries, you just need to change the natural language prompt: ```python from langchain.llms import OpenAI from langchain.agents import initialize_agent from langchain.agents.agent_toolkits import ZapierToolkit from langchain.utilities.zapier import ZapierNLAWrapper llm = OpenAI(temperature=0) zapier = ZapierNLAWrapper() toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier) agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True) agent.run("Get my Google Calendar entries for tomorrow") ``` And the output looks like: ```console $ python get_google_calendar.py > Entering new AgentExecutor chain... I need to find events in my Google Calendar Action: Google Calendar: Find Event Action Input: Find events in my Google Calendar tomorrow Observation: {"location": "Greg to call Mark on (928) XXX-ZZZZ", "kind": "calendar#event", "end__dateTime": "2023-03-23T10:00:00-07:00", "status": "confirmed", "end__dateTime_pretty": "Mar 23, 2023 10:00AM", "htmlLink": "https://zpr.io/WWWWWWWW"} Thought: I now know the final answer Final Answer: I have an event in my Google Calendar tomorrow at 10:00AM. > Finished chain. ``` I edited this output to remove some private information. ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/README_code.md ================================================ # Using Zapier Integrations with GMail and Google Calendar Zapier is a service for writing integrations with hundreds of cloud services. Here we will write some demos for writing automatic integrations with GMail and Google Calendar. I will also provide you, dear reader, with links for integrationg with Microsoft and other services. ## Setup You will need a developer key for [Zapier Natural Language Actions API](https://nla.zapier.com/get-started/). Go to this linked web page and look for "Dev App" in the "Provider Name" column. If a key does not exist, you'll need to setup an action to create a key. Click "Setup Actions" and follow the instructions. Your key will be in the Personal API Key column for the "Dev App." Click to reveal and copy your key. You can [read the documentation](https://nla.zapier.com/api/v1/dynamic/docs). ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/get_google_calendar.py ================================================ from langchain.llms import OpenAI from langchain.agents import initialize_agent from langchain.agents.agent_toolkits import ZapierToolkit from langchain.utilities.zapier import ZapierNLAWrapper llm = OpenAI(temperature=0) zapier = ZapierNLAWrapper() toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier) agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True) agent.run("Get my Google Calendar entries for tomorrow") ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/requirements.txt ================================================ langchain langchain_community openai ================================================ FILE: CHAPTERS_and_CODE_no_longer_in-book/zapier_integrations/send_gmail.py ================================================ from langchain.llms import OpenAI from langchain.agents import initialize_agent from langchain.agents.agent_toolkits import ZapierToolkit from langchain.utilities.zapier import ZapierNLAWrapper llm = OpenAI(temperature=0) zapier = ZapierNLAWrapper() toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier) agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True) agent.run("Send an Email to mark_watson99test.com via gmail that is a pitch for hiring Mark Watson as a consultant for deep learning and large language models") ================================================ FILE: Makefile ================================================ install: pip install llama_index langchain trafilatura openai SPARQLWrapper rdflib rdflib-jsonld pydrive kor clean: rm -r -f */*~ */#* rm -r -f */venv */*/venv rm -r -f */__pycache__ */*/__pycache__ ================================================ FILE: README.md ================================================ # Example code for my book "LangChain Project Lab Book: Hooking Large Language Models Up to the Real World" You can purchase this book on LeanPub and get free updates as new versions are released. This book can be purchased or read free online at [https://leanpub.com/langchain](https://leanpub.com/langchain). I would like to thank readers who have purchased this book! I very much appreciate your support. ## Older, non-supported, book chapters and code for these chapters now in directory CHAPTERS_and_CODE_no_longer_in-book ### Starting in October 2024 I am removing older material from my book and archiving it. See the following index for older material: [CHAPTERS_and_CODE_no_longer_in-book/README.md](CHAPTERS_and_CODE_no_longer_in-book/README.md) ================================================ FILE: cooking_recipes/README.md ================================================ # Using LLMs to Generate Recipes Updated 1/26/2024 for langchain-0.1.4 and using the new OpenAI embedding models See the chapter in my book for information. So far, this directory contain an initial experiment indexing my cookingspace.com recipe data and using LangChain and a prediction model to generate new recipes. ## Recipe Copyrights My JSON recipe files are Copyright 2010-2023 Mark Watson, as are the generated text file versions. What does copyright even mean for recipes? To the best of my knowledge, the only thing that can be copyright in recipes is the written cooking directions. ================================================ FILE: cooking_recipes/data/.gitignore ================================================ *~ ================================================ FILE: cooking_recipes/data/correlated-ingredients.json ================================================ {"chives": {"elbow macaroni":2, "red wine":3, "bacon":18, "cayenne pepper":8, "lemon juice":48, "honey":8, "swiss cheese":7, "paprika":26, "ground cinnamon":2, "bread":3, "yeast":6, "egg yolks":14, "green pepper":5, "baking powder":10, "saffron":2, "sesame oil":3, "cream of tartar":2, "pine nuts":8, "cinnamon":3, "avocado":3, "cheddar cheese":12, "tomatoes":23, "white pepper":18, "brown rice":2, "cauliflower":3, "frozen peas":2, "butter":120, "salmon":5, "orange juice":3, "lemon":11, "black pepper":19, "black olives":4, "buttermilk":5, "capers":7, "cornmeal":2, "cloves":6, "oil":18, "chicken":5, "blue cheese":6, "cucumber":7, "canola oil":4, "dried tarragon":5, "celery":15, "walnuts":5, "nutmeg":13, "bread crumbs":10, "baking soda":4, "tabasco sauce":6, "ginger":5, "balsamic vinegar":8, "fresh rosemary":2, "lime":3, "pecans":3, "peanut butter":2, "green onions":9, "cumin":4, "skim milk":2, "beets":2, "kidney beans":2, "parmesan cheese":15, "carrots":16, "mushrooms":22, "sour cream":32, "yogurt":3, "cream cheese":29, "tofu":3, "cherry tomatoes":2, "salsa":3, "parsley":76, "green olives":2, "rice vinegar":2, "chili powder":6, "spaghetti":2, "red wine vinegar":5, "cornstarch":4, "orange":4, "dried basil":2, "radishes":2, "catsup":3, "ground beef":4, "mozzarella cheese":2, "almonds":5, "eggs":40, "margarine":14, "fresh ginger":2, "kale":2, "garlic powder":15, "dried thyme":8, "whole wheat flour":6, "salt":167, "fresh basil":5, "bean sprouts":4, "potatoes":20, "allspice":2, "dijon mustard":17, "soy sauce":8, "broccoli":4, "white rice":2, "egg whites":6, "worcestershire sauce":9, "brown sugar":2, "lime juice":5, "dry mustard":10, "white flour":2, "mayonnaise":19, "fresh thyme":2, "vegetable oil":14, "olive oil":58, "curry powder":9, "flour":37, "vinegar":7, "white wine":11, "sherry":3, "oats":2, "whipping cream":5, "sugar":22}, "cumin": {"elbow macaroni":5, "canned beef broth":3, "red wine":16, "canned tomato sauce":5, "bacon":16, "cayenne pepper":133, "lemon juice":120, "honey":25, "swiss cheese":3, "paprika":177, "bread":2, "ground cinnamon":6, "yeast":2, "green pepper":109, "baking powder":10, "saffron":3, "sesame oil":9, "pine nuts":2, "cinnamon":73, "avocado":11, "cheddar cheese":33, "corn tortilla":2, "tomatoes":177, "white pepper":34, "brown rice":17, "black beans":43, "fresh garlic":3, "pinto beans":38, "cauliflower":12, "frozen peas":4, "butter":63, "salmon":2, "orange juice":13, "black pepper":171, "lemon":23, "tumeric":21, "black olives":13, "buttermilk":2, "powdered sugar":2, "hoisin sauce":2, "dried oregano":28, "eggplant":19, "capers":8, "cornmeal":14, "cloves":49, "oil":136, "chicken":25, "cucumber":12, "canola oil":13, "dried tarragon":2, "celery":45, "alfalfa sprouts":2, "fresh peaches":3, "walnuts":10, "nutmeg":34, "fresh cilantro":24, "baking soda":6, "bread crumbs":14, "corn syrup":2, "tabasco sauce":45, "ginger":68, "balsamic vinegar":8, "lime":17, "pecans":2, "peanut butter":9, "green onions":36, "frozen corn":13, "banana":2, "beets":3, "skim milk":11, "barley":5, "kidney beans":41, "shortening":6, "applesauce":2, "parmesan cheese":5, "carrots":65, "mushrooms":25, "sour cream":50, "yogurt":25, "cream cheese":12, "tofu":10, "cherry tomatoes":3, "salsa":22, "parsley":79, "green olives":4, "rice vinegar":3, "molasses":11, "beer":41, "chili powder":403, "spaghetti":3, "raisins":29, "red wine vinegar":15, "chives":4, "garam masala":19, "cornstarch":14, "orange":6, "dried basil":6, "radishes":2, "catsup":11, "ground beef":68, "mozzarella cheese":8, "romaine lettuce":2, "sweet red pepper":4, "cumin seeds":3, "barbecue sauce":3, "red pepper flakes":16, "almonds":13, "eggs":26, "margarine":15, "fresh ginger":7, "kale":3, "garlic powder":134, "dried thyme":7, "cream of mushroom soup":4, "whole wheat flour":2, "salt":625, "fresh basil":3, "bean sprouts":2, "potatoes":29, "frozen spinach":4, "celery seeds":2, "allspice":39, "dijon mustard":13, "soy sauce":38, "broccoli":3, "apples":4, "maple syrup":4, "sweet potatoes":6, "white rice":5, "egg whites":4, "worcestershire sauce":35, "dried cilantro":5, "brown sugar":40, "lime juice":52, "dry mustard":32, "mayonnaise":5, "chicken wings":5, "vegetable oil":123, "fresh thyme":2, "olive oil":257, "flour":71, "curry powder":50, "vinegar":48, "white wine":8, "sherry":5, "oats":4, "whipping cream":2, "chicken breast":11, "sugar":93}, "white wine": {"red wine":7, "bacon":27, "cayenne pepper":28, "lemon juice":92, "honey":29, "zucchini squash":2, "swiss cheese":17, "paprika":54, "ground cinnamon":5, "bread":4, "yeast":5, "egg yolks":22, "green pepper":21, "baking powder":7, "saffron":9, "sesame oil":15, "cinnamon":11, "pine nuts":6, "cream of tartar":2, "avocado":3, "cheddar cheese":4, "tomatoes":49, "white pepper":35, "brown rice":4, "black beans":6, "fresh garlic":3, "cauliflower":2, "frozen peas":2, "butter":241, "salmon":5, "orange juice":19, "lemon":40, "black pepper":58, "black olives":8, "buttermilk":3, "powdered sugar":8, "eggplant":2, "dried oregano":16, "hoisin sauce":3, "capers":21, "cloves":11, "oil":60, "chicken":31, "blue cheese":2, "cucumber":4, "canola oil":3, "dried tarragon":4, "strawberries":8, "celery":38, "fresh cilantro":5, "nutmeg":31, "bread crumbs":23, "baking soda":2, "corn syrup":3, "tabasco sauce":10, "ginger":14, "balsamic vinegar":11, "fresh rosemary":9, "lime":5, "peanut butter":2, "green onions":40, "cumin":8, "canned chicken broth":2, "banana":2, "skim milk":6, "barley":2, "shortening":5, "parmesan cheese":43, "carrots":39, "mushrooms":72, "sour cream":25, "yogurt":2, "tofu":2, "cream cheese":3, "cherry tomatoes":3, "salsa":2, "parsley":99, "green olives":6, "rice vinegar":3, "molasses":2, "chili powder":9, "spaghetti":7, "raisins":11, "red wine vinegar":14, "chives":11, "cornstarch":56, "orange":8, "dried basil":8, "catsup":8, "ground beef":8, "mozzarella cheese":7, "adzuki beans":2, "sweet red pepper":2, "barbecue sauce":2, "red pepper flakes":8, "almonds":6, "eggs":33, "margarine":20, "fresh ginger":3, "garlic powder":21, "dried thyme":14, "cream of mushroom soup":10, "vanilla":5, "whole wheat flour":2, "salt":342, "fresh basil":14, "shiitake mushrooms":5, "potatoes":12, "almond extract":4, "frozen spinach":2, "allspice":8, "dijon mustard":22, "soy sauce":46, "broccoli":4, "apples":9, "white rice":3, "yellow mustard":4, "maple syrup":10, "egg whites":5, "worcestershire sauce":34, "brown sugar":19, "lime juice":12, "dry mustard":15, "raw shrimp":3, "blueberries":2, "mayonnaise":4, "chicken wings":3, "fresh thyme":9, "olive oil":239, "vegetable oil":40, "flour":128, "curry powder":11, "vinegar":14, "sherry":8, "whipping cream":16, "chicken breast":6, "sugar":87}, "bread crumbs": {"elbow macaroni":5, "red wine":6, "bacon":18, "cayenne pepper":33, "lemon juice":77, "honey":8, "swiss cheese":16, "paprika":57, "bread":4, "ground cinnamon":7, "yeast":2, "egg yolks":22, "green pepper":31, "baking powder":9, "sesame oil":3, "cream of tartar":4, "pine nuts":13, "cinnamon":27, "avocado":2, "cheddar cheese":27, "tomatoes":30, "white pepper":26, "brown rice":7, "black beans":3, "pinto beans":3, "fresh garlic":2, "cauliflower":3, "butter":294, "frozen peas":3, "salmon":9, "orange juice":6, "lemon":23, "black pepper":65, "black olives":3, "buttermilk":4, "eggplant":23, "dried oregano":14, "capers":5, "cornmeal":6, "cloves":14, "oil":36, "chicken":10, "blue cheese":2, "cucumber":4, "canola oil":8, "dried tarragon":4, "celery":39, "fresh cilantro":2, "walnuts":12, "fresh peaches":2, "nutmeg":44, "baking soda":6, "tabasco sauce":14, "balsamic vinegar":8, "ginger":16, "fresh rosemary":2, "pecans":5, "cumin":14, "green onions":18, "frozen corn":4, "skim milk":15, "kidney beans":2, "shortening":8, "parmesan cheese":84, "applesauce":2, "carrots":18, "mushrooms":58, "sour cream":40, "yogurt":2, "brussels sprouts":2, "cream cheese":16, "tofu":12, "cherry tomatoes":3, "parsley":145, "green olives":2, "rice vinegar":2, "molasses":3, "beer":2, "chili powder":9, "spaghetti":2, "raisins":14, "red wine vinegar":3, "chives":10, "cornstarch":10, "orange":4, "dried basil":13, "radishes":2, "catsup":10, "ground beef":76, "romaine lettuce":2, "mozzarella cheese":21, "sweet red pepper":4, "cumin seeds":2, "barbecue sauce":2, "red pepper flakes":2, "almonds":6, "eggs":192, "margarine":55, "garlic powder":41, "dried thyme":7, "cream of mushroom soup":11, "vanilla":3, "whole wheat flour":2, "salt":415, "fresh basil":4, "potatoes":26, "frozen spinach":5, "celery seeds":2, "allspice":12, "dijon mustard":19, "soy sauce":24, "broccoli":3, "chicken legs":2, "apples":13, "sweet potatoes":2, "white rice":2, "shell macaroni":2, "maple syrup":2, "egg whites":22, "worcestershire sauce":63, "brown sugar":19, "lime juice":2, "dry mustard":30, "mayonnaise":33, "olive oil":121, "vegetable oil":37, "flour":185, "curry powder":22, "vinegar":13, "white wine":23, "sherry":14, "oats":4, "whipping cream":6, "chicken breast":4, "sugar":42}, "butter": {"canned beef broth":2, "elbow macaroni":17, "red wine":75, "canned tomato sauce":3, "bacon":156, "canned clams":2, "brown onions":3, "cayenne pepper":218, "honey":365, "lemon juice":973, "zucchini squash":3, "swiss cheese":86, "paprika":414, "ground cinnamon":270, "bread":93, "yeast":326, "egg yolks":536, "green pepper":145, "baking powder":1518, "saffron":35, "sesame oil":7, "cream of tartar":120, "cinnamon":1064, "pine nuts":57, "avocado":14, "cheddar cheese":207, "tomatoes":259, "white pepper":192, "brown rice":20, "black beans":6, "pinto beans":7, "fresh garlic":8, "cauliflower":15, "frozen peas":25, "salmon":26, "orange juice":222, "lemon":301, "black pepper":341, "tumeric":7, "black olives":21, "buttermilk":284, "powdered sugar":421, "hoisin sauce":3, "eggplant":35, "dried oregano":58, "capers":58, "cornmeal":74, "cloves":198, "oil":306, "chicken":146, "blue cheese":19, "cucumber":13, "canola oil":36, "flour tortilla":4, "dried tarragon":33, "strawberries":52, "celery":230, "alfalfa sprouts":2, "cornish game hens":12, "fresh peaches":15, "fresh cilantro":13, "walnuts":282, "nutmeg":710, "bread crumbs":294, "baking soda":1047, "tabasco sauce":118, "corn syrup":108, "balsamic vinegar":43, "ginger":134, "fresh rosemary":17, "lime":16, "pecans":328, "peanut butter":124, "frozen corn":10, "cumin":63, "green onions":166, "canned chicken broth":6, "beets":14, "banana":30, "skim milk":34, "barley":8, "kidney beans":9, "shortening":190, "parmesan cheese":376, "applesauce":40, "carrots":280, "mushrooms":440, "sour cream":675, "yogurt":38, "brussels sprouts":7, "tofu":6, "cream cheese":451, "cherry tomatoes":13, "salsa":12, "parsley":586, "green olives":12, "rice vinegar":7, "molasses":181, "chili powder":102, "beer":51, "spaghetti":24, "raisins":451, "red wine vinegar":52, "garam masala":12, "chives":120, "cornstarch":407, "orange":60, "dried basil":62, "radishes":6, "catsup":41, "ground beef":96, "adzuki beans":2, "mozzarella cheese":47, "sweet red pepper":22, "cumin seeds":14, "canned peaches":2, "barbecue sauce":6, "raw spinach":3, "red pepper flakes":19, "eggs":2909, "almonds":187, "margarine":39, "fresh ginger":8, "kale":7, "garlic powder":144, "dried thyme":111, "cream of mushroom soup":56, "low fat milk":4, "vanilla":1845, "whole wheat flour":131, "salt":6434, "fresh basil":45, "bean sprouts":4, "shiitake mushrooms":13, "potatoes":325, "almond extract":163, "frozen spinach":27, "celery seeds":6, "allspice":98, "dijon mustard":131, "soy sauce":108, "broccoli":40, "chicken legs":5, "apples":187, "shell macaroni":2, "white rice":16, "yellow mustard":3, "maple syrup":98, "sweet potatoes":54, "egg whites":221, "worcestershire sauce":324, "dried cilantro":2, "brown sugar":1081, "lime juice":43, "dry mustard":171, "raw shrimp":15, "white flour":30, "blueberries":61, "mayonnaise":103, "chicken wings":26, "fresh thyme":22, "vegetable oil":220, "olive oil":605, "flour":4221, "curry powder":150, "vinegar":165, "white wine":241, "sherry":153, "yam":2, "oats":53, "whipping cream":364, "chicken breast":19, "sugar":4965}, "canned tomato paste": {"worcestershire sauce":2, "flour":3, "garlic powder":2, "tomatoes":2, "lemon juice":2, "salt":3}, "fresh garlic": {"sour cream":2, "red wine":2, "cherry tomatoes":4, "salsa":2, "parsley":2, "cayenne pepper":2, "honey":4, "lemon juice":3, "beer":2, "paprika":2, "raisins":2, "yeast":2, "green pepper":2, "baking powder":2, "dried basil":4, "sesame oil":2, "catsup":2, "pine nuts":2, "cheddar cheese":3, "mozzarella cheese":4, "romaine lettuce":2, "tomatoes":2, "white pepper":2, "eggs":3, "margarine":2, "fresh ginger":7, "frozen peas":2, "butter":8, "garlic powder":3, "dried thyme":4, "orange juice":2, "salt":19, "black pepper":14, "fresh basil":3, "tumeric":2, "black olives":2, "buttermilk":2, "dried oregano":5, "hoisin sauce":2, "oil":2, "canola oil":3, "dijon mustard":2, "soy sauce":7, "fresh cilantro":2, "bread crumbs":2, "worcestershire sauce":4, "tabasco sauce":2, "brown sugar":3, "ginger":3, "balsamic vinegar":3, "lime juice":2, "dry mustard":4, "fresh rosemary":2, "peanut butter":2, "green onions":4, "cumin":3, "vegetable oil":5, "olive oil":15, "skim milk":2, "beets":2, "barley":2, "curry powder":2, "flour":4, "white wine":3, "parmesan cheese":4, "carrots":3, "sherry":2, "chicken breast":2, "mushrooms":2, "sugar":9}, "brussels sprouts": {"potatoes":3, "bacon":3, "dried oregano":2, "cayenne pepper":4, "parsley":3, "honey":2, "lemon juice":2, "chicken":2, "beer":3, "canola oil":3, "dijon mustard":4, "soy sauce":2, "raisins":3, "celery":2, "broccoli":2, "red wine vinegar":3, "walnuts":2, "nutmeg":2, "bread crumbs":2, "cornstarch":4, "sesame oil":2, "tabasco sauce":2, "balsamic vinegar":2, "cheddar cheese":2, "tomatoes":2, "cumin seeds":4, "green onions":3, "olive oil":2, "flour":2, "barley":2, "margarine":2, "butter":7, "dried thyme":3, "carrots":3, "sugar":2, "salt":11}, "beets": {"sour cream":11, "yogurt":2, "cream cheese":3, "parsley":6, "green olives":2, "rice vinegar":2, "lemon juice":19, "honey":7, "swiss cheese":2, "paprika":2, "ground cinnamon":4, "raisins":3, "red wine vinegar":12, "chives":2, "egg yolks":4, "cornstarch":4, "baking powder":2, "dried basil":3, "catsup":2, "cinnamon":7, "ground beef":2, "cheddar cheese":2, "tomatoes":3, "white pepper":3, "eggs":13, "fresh garlic":2, "margarine":3, "fresh ginger":2, "cauliflower":2, "butter":14, "garlic powder":3, "dried thyme":2, "vanilla":4, "orange juice":4, "black pepper":3, "salt":53, "lemon":5, "shiitake mushrooms":2, "buttermilk":2, "potatoes":12, "powdered sugar":3, "dried oregano":2, "capers":4, "cloves":6, "oil":8, "cucumber":3, "allspice":4, "celery seeds":2, "canola oil":2, "dijon mustard":5, "dried tarragon":2, "soy sauce":2, "celery":3, "apples":2, "walnuts":3, "egg whites":2, "baking soda":3, "brown sugar":9, "balsamic vinegar":4, "dry mustard":3, "lime":2, "mayonnaise":3, "green onions":2, "cumin":3, "olive oil":19, "vegetable oil":9, "flour":8, "vinegar":17, "parmesan cheese":3, "carrots":24, "sherry":2, "oats":2, "chicken breast":2, "sugar":46, "mushrooms":2}, "sweet red pepper": {"red wine":2, "bacon":4, "cayenne pepper":6, "lemon juice":20, "honey":3, "paprika":6, "bread":2, "green pepper":24, "baking powder":6, "saffron":4, "sesame oil":9, "cinnamon":5, "avocado":2, "cheddar cheese":6, "tomatoes":13, "white pepper":5, "brown rice":4, "black beans":4, "pinto beans":2, "cauliflower":4, "butter":22, "frozen peas":3, "orange juice":3, "lemon":2, "black pepper":14, "tumeric":2, "buttermilk":4, "hoisin sauce":2, "dried oregano":5, "eggplant":5, "capers":2, "cornmeal":3, "cloves":2, "oil":6, "chicken":4, "cucumber":4, "celery":11, "fresh cilantro":5, "nutmeg":4, "baking soda":2, "bread crumbs":4, "ginger":2, "balsamic vinegar":5, "fresh rosemary":2, "lime":2, "peanut butter":4, "green onions":25, "frozen corn":2, "cumin":4, "canned chicken broth":3, "skim milk":2, "kidney beans":2, "parmesan cheese":7, "carrots":15, "mushrooms":14, "sour cream":4, "tofu":2, "cream cheese":3, "salsa":3, "parsley":7, "rice vinegar":2, "beer":2, "chili powder":13, "raisins":4, "red wine vinegar":5, "cornstarch":8, "dried basil":9, "catsup":2, "ground beef":3, "red pepper flakes":3, "eggs":11, "margarine":4, "fresh ginger":3, "garlic powder":4, "dried thyme":5, "salt":89, "fresh basil":9, "bean sprouts":2, "potatoes":5, "celery seeds":4, "allspice":2, "dijon mustard":10, "soy sauce":12, "broccoli":3, "apples":2, "white rice":2, "sweet potatoes":2, "egg whites":2, "worcestershire sauce":3, "dried cilantro":2, "brown sugar":4, "lime juice":8, "dry mustard":8, "raw shrimp":2, "mayonnaise":5, "olive oil":53, "vegetable oil":31, "curry powder":7, "flour":8, "vinegar":9, "white wine":2, "sherry":2, "chicken breast":4, "sugar":23}, "cumin seeds": {"red wine":3, "coconut oil":2, "brown onions":2, "cayenne pepper":38, "lemon juice":37, "honey":3, "zucchini squash":2, "paprika":26, "ground cinnamon":11, "bread":2, "green pepper":4, "baking powder":2, "saffron":5, "sesame oil":2, "cinnamon":15, "pine nuts":3, "avocado":2, "cheddar cheese":2, "tomatoes":34, "white pepper":3, "brown rice":3, "black beans":5, "pinto beans":3, "cauliflower":3, "frozen peas":3, "butter":14, "salmon":2, "orange juice":4, "lemon":4, "black pepper":22, "tumeric":12, "dried oregano":11, "eggplant":5, "capers":2, "cloves":37, "oil":29, "chicken":8, "blue cheese":3, "canola oil":6, "fresh cilantro":7, "nutmeg":12, "bread crumbs":2, "baking soda":4, "tabasco sauce":3, "ginger":21, "lime":3, "peanut butter":2, "cumin":3, "green onions":8, "banana":2, "kidney beans":3, "shortening":2, "parmesan cheese":2, "carrots":10, "mushrooms":5, "sour cream":5, "yogurt":13, "brussels sprouts":4, "cherry tomatoes":2, "salsa":2, "parsley":4, "green olives":2, "molasses":3, "beer":3, "chili powder":27, "spaghetti":3, "raisins":8, "red wine vinegar":9, "garam masala":33, "cornstarch":2, "orange":2, "ground beef":2, "mozzarella cheese":2, "romaine lettuce":3, "eggs":5, "almonds":4, "fresh ginger":10, "garlic powder":5, "dried thyme":2, "salt":193, "potatoes":19, "frozen spinach":2, "celery seeds":3, "allspice":2, "dijon mustard":2, "soy sauce":2, "maple syrup":2, "white rice":3, "worcestershire sauce":3, "brown sugar":9, "lime juice":9, "dry mustard":3, "white flour":2, "vegetable oil":35, "olive oil":42, "flour":8, "curry powder":10, "vinegar":5, "whipping cream":4, "chicken breast":3, "sugar":25}, "celery": {"elbow macaroni":7, "red wine":11, "canned tomato sauce":2, "bacon":59, "cayenne pepper":70, "lemon juice":128, "honey":20, "swiss cheese":12, "paprika":82, "bread":20, "ground cinnamon":7, "yeast":7, "egg yolks":5, "green pepper":219, "baking powder":12, "saffron":4, "sesame oil":23, "cinnamon":22, "pine nuts":4, "avocado":2, "cheddar cheese":46, "tomatoes":157, "white pepper":46, "brown rice":27, "black beans":15, "pinto beans":13, "cauliflower":20, "frozen peas":16, "butter":230, "salmon":7, "orange juice":16, "black pepper":134, "lemon":28, "tumeric":4, "black olives":19, "buttermilk":2, "dried oregano":18, "eggplant":9, "capers":13, "cornmeal":5, "cloves":13, "oil":159, "chicken":93, "blue cheese":4, "cucumber":17, "canola oil":7, "dried tarragon":8, "cornish game hens":3, "alfalfa sprouts":4, "fresh cilantro":9, "walnuts":33, "nutmeg":28, "baking soda":2, "bread crumbs":39, "tabasco sauce":36, "balsamic vinegar":5, "ginger":33, "fresh rosemary":2, "lime":6, "pecans":19, "peanut butter":5, "frozen corn":3, "green onions":101, "cumin":45, "canned chicken broth":2, "beets":3, "skim milk":10, "barley":23, "kidney beans":25, "shortening":11, "applesauce":2, "parmesan cheese":34, "carrots":279, "mushrooms":118, "sour cream":58, "yogurt":8, "brussels sprouts":2, "tofu":11, "cream cheese":20, "cherry tomatoes":5, "salsa":2, "parsley":251, "green olives":10, "rice vinegar":8, "molasses":8, "chili powder":78, "beer":11, "spaghetti":16, "raisins":27, "red wine vinegar":21, "chives":15, "cornstarch":98, "orange":5, "dried basil":23, "radishes":10, "catsup":23, "ground beef":49, "romaine lettuce":2, "mozzarella cheese":6, "sweet red pepper":11, "canned tuna":2, "canned peaches":2, "barbecue sauce":2, "red pepper flakes":11, "eggs":104, "almonds":22, "margarine":68, "fresh ginger":5, "kale":4, "garlic powder":62, "dried thyme":39, "cream of mushroom soup":35, "low fat milk":2, "vanilla":2, "salt":797, "fresh basil":10, "bean sprouts":21, "shiitake mushrooms":5, "potatoes":103, "frozen spinach":2, "celery seeds":5, "allspice":12, "dijon mustard":23, "soy sauce":144, "broccoli":20, "apples":22, "shell macaroni":4, "white rice":4, "yellow mustard":4, "sweet potatoes":5, "egg whites":11, "worcestershire sauce":93, "dried cilantro":2, "brown sugar":40, "lime juice":6, "dry mustard":32, "raw shrimp":2, "mayonnaise":127, "chicken wings":5, "olive oil":123, "vegetable oil":82, "fresh thyme":8, "flour":185, "curry powder":53, "vinegar":91, "white wine":38, "sherry":43, "oats":2, "whipping cream":14, "chicken breast":15, "sugar":199}, "nutmeg": {"elbow macaroni":3, "red wine":11, "canned tomato sauce":4, "bacon":27, "brown onions":2, "cayenne pepper":56, "honey":109, "lemon juice":176, "swiss cheese":14, "paprika":73, "ground cinnamon":37, "bread":15, "yeast":46, "egg yolks":83, "green pepper":18, "baking powder":423, "saffron":8, "sesame oil":3, "pine nuts":11, "cinnamon":1126, "cream of tartar":20, "cheddar cheese":18, "tomatoes":25, "white pepper":62, "brown rice":5, "black beans":3, "pinto beans":3, "cauliflower":6, "frozen peas":5, "butter":710, "salmon":3, "orange juice":69, "lemon":39, "black pepper":73, "tumeric":6, "black olives":2, "buttermilk":55, "powdered sugar":42, "dried oregano":7, "eggplant":10, "capers":6, "cornmeal":13, "cloves":309, "oil":117, "chicken":17, "blue cheese":3, "cucumber":4, "dry rosemary":2, "canola oil":17, "dried tarragon":4, "strawberries":14, "celery":28, "cornish game hens":2, "alfalfa sprouts":2, "fresh cilantro":3, "fresh peaches":13, "walnuts":93, "bread crumbs":44, "baking soda":404, "tabasco sauce":5, "corn syrup":11, "balsamic vinegar":2, "ginger":196, "fresh rosemary":2, "lime":8, "pecans":53, "peanut butter":14, "green onions":16, "cumin":34, "skim milk":43, "banana":10, "barley":3, "kidney beans":2, "shortening":126, "parmesan cheese":78, "applesauce":66, "carrots":55, "mushrooms":55, "sour cream":69, "yogurt":9, "brussels sprouts":2, "tofu":2, "cream cheese":42, "parsley":52, "green olives":3, "rice vinegar":2, "molasses":98, "chili powder":18, "beer":9, "spaghetti":7, "raisins":308, "red wine vinegar":9, "garam masala":5, "chives":13, "cornstarch":84, "dried basil":6, "orange":15, "catsup":9, "ground beef":34, "romaine lettuce":2, "mozzarella cheese":21, "sweet red pepper":4, "cumin seeds":12, "canned peaches":2, "red pepper flakes":5, "eggs":697, "almonds":30, "margarine":121, "fresh ginger":4, "garlic powder":26, "dried thyme":14, "cream of mushroom soup":4, "low fat milk":2, "vanilla":325, "whole wheat flour":47, "salt":1340, "fresh basil":6, "bean sprouts":2, "shiitake mushrooms":2, "potatoes":44, "almond extract":16, "frozen spinach":16, "celery seeds":5, "allspice":231, "dijon mustard":16, "soy sauce":24, "broccoli":9, "chicken legs":3, "apples":108, "yellow mustard":2, "white rice":2, "maple syrup":40, "sweet potatoes":36, "egg whites":77, "worcestershire sauce":11, "brown sugar":371, "lime juice":12, "dry mustard":27, "white flour":11, "blueberries":16, "mayonnaise":5, "chicken wings":2, "fresh thyme":6, "olive oil":107, "vegetable oil":93, "flour":785, "curry powder":13, "vinegar":31, "white wine":31, "sherry":20, "yam":2, "oats":18, "whipping cream":51, "sugar":955}, "black beans": {"red wine":4, "elbow macaroni":2, "bacon":10, "brown onions":2, "cayenne pepper":23, "lemon juice":10, "honey":11, "paprika":7, "ground cinnamon":4, "green pepper":27, "baking powder":4, "sesame oil":5, "cinnamon":7, "avocado":5, "cheddar cheese":7, "tomatoes":32, "white pepper":4, "brown rice":7, "pinto beans":10, "butter":6, "salmon":2, "orange juice":3, "black pepper":21, "lemon":5, "black olives":4, "dried oregano":8, "hoisin sauce":3, "capers":2, "cloves":5, "oil":26, "chicken":2, "cucumber":2, "canola oil":4, "celery":15, "fresh cilantro":23, "nutmeg":3, "baking soda":2, "bread crumbs":3, "tabasco sauce":7, "balsamic vinegar":7, "ginger":6, "lime":6, "green onions":19, "cumin":43, "frozen corn":6, "skim milk":3, "barley":2, "kidney beans":12, "parmesan cheese":3, "carrots":16, "mushrooms":4, "sour cream":15, "cream cheese":4, "cherry tomatoes":3, "salsa":12, "parsley":9, "green olives":3, "rice vinegar":2, "molasses":3, "chili powder":58, "beer":5, "red wine vinegar":11, "cornstarch":4, "dried basil":6, "orange":3, "ground beef":3, "adzuki beans":2, "mozzarella cheese":2, "sweet red pepper":4, "cumin seeds":5, "barbecue sauce":2, "red pepper flakes":6, "eggs":5, "almonds":2, "margarine":2, "fresh ginger":3, "garlic powder":9, "dried thyme":4, "whole wheat flour":2, "salt":114, "fresh basil":2, "sriracha hot chili sauce":2, "potatoes":4, "allspice":4, "soy sauce":9, "white rice":5, "egg whites":3, "brown sugar":4, "lime juice":19, "dry mustard":3, "olive oil":59, "vegetable oil":34, "fresh thyme":2, "flour":5, "curry powder":4, "vinegar":8, "white wine":6, "sherry":3, "whipping cream":2, "chicken breast":2, "sugar":14}, "egg yolks": {"elbow macaroni":2, "red wine":9, "bacon":14, "cayenne pepper":27, "lemon juice":188, "honey":29, "swiss cheese":7, "paprika":27, "bread":8, "ground cinnamon":30, "yeast":11, "green pepper":8, "baking powder":152, "saffron":4, "sesame oil":4, "pine nuts":4, "cinnamon":75, "cream of tartar":74, "cheddar cheese":12, "tomatoes":9, "white pepper":22, "brown rice":2, "cauliflower":2, "butter":536, "salmon":3, "orange juice":29, "black pepper":21, "lemon":71, "buttermilk":18, "powdered sugar":74, "eggplant":4, "hoisin sauce":3, "dried oregano":4, "capers":14, "cornmeal":11, "cloves":16, "oil":36, "chicken":9, "cucumber":3, "canola oil":6, "dried tarragon":2, "strawberries":27, "celery":5, "alfalfa sprouts":3, "nutmeg":83, "fresh peaches":2, "walnuts":8, "bread crumbs":22, "baking soda":36, "corn syrup":3, "tabasco sauce":5, "ginger":9, "balsamic vinegar":3, "pecans":24, "peanut butter":9, "green onions":9, "skim milk":13, "beets":4, "kidney beans":2, "shortening":21, "applesauce":3, "parmesan cheese":25, "carrots":9, "mushrooms":24, "sour cream":64, "yogurt":6, "cream cheese":39, "cherry tomatoes":2, "parsley":35, "green olives":2, "molasses":5, "chili powder":3, "beer":9, "spaghetti":2, "raisins":35, "red wine vinegar":9, "chives":14, "cornstarch":124, "orange":10, "dried basil":3, "catsup":2, "ground beef":9, "mozzarella cheese":2, "canned tuna":2, "red pepper flakes":4, "eggs":148, "almonds":28, "margarine":44, "fresh ginger":3, "garlic powder":5, "dried thyme":4, "vanilla":320, "whole wheat flour":2, "salt":718, "fresh basil":4, "shiitake mushrooms":3, "potatoes":9, "almond extract":30, "celery seeds":2, "allspice":11, "dijon mustard":19, "soy sauce":4, "broccoli":2, "apples":10, "yellow mustard":2, "white rice":2, "maple syrup":15, "sweet potatoes":5, "egg whites":368, "worcestershire sauce":15, "brown sugar":61, "lime juice":13, "dry mustard":25, "white flour":2, "blueberries":8, "mayonnaise":7, "vegetable oil":35, "olive oil":45, "flour":388, "curry powder":7, "vinegar":23, "white wine":22, "sherry":28, "whipping cream":186, "chicken breast":3, "sugar":1122}, "bacon": {"elbow macaroni":6, "red wine":19, "canned beef broth":2, "cayenne pepper":34, "honey":8, "lemon juice":46, "swiss cheese":26, "paprika":50, "ground cinnamon":5, "bread":8, "yeast":3, "egg yolks":14, "green pepper":57, "baking powder":21, "saffron":2, "sesame oil":3, "cream of tartar":2, "cinnamon":8, "avocado":6, "cheddar cheese":45, "tomatoes":69, "white pepper":18, "brown rice":2, "black beans":10, "pinto beans":10, "cauliflower":2, "butter":156, "frozen peas":8, "salmon":5, "orange juice":7, "lemon":18, "black pepper":54, "black olives":3, "buttermilk":5, "powdered sugar":2, "eggplant":4, "dried oregano":9, "capers":5, "cornmeal":8, "cloves":13, "oil":51, "chicken":14, "blue cheese":6, "cucumber":5, "canola oil":4, "flour tortilla":4, "dried tarragon":4, "celery":59, "cornish game hens":2, "alfalfa sprouts":3, "fresh cilantro":5, "nutmeg":27, "walnuts":2, "baking soda":8, "bread crumbs":18, "tabasco sauce":16, "balsamic vinegar":9, "ginger":6, "fresh rosemary":4, "lime":2, "frozen corn":2, "cumin":16, "green onions":45, "skim milk":5, "barley":4, "kidney beans":18, "shortening":5, "parmesan cheese":42, "applesauce":2, "carrots":43, "mushrooms":54, "sour cream":76, "brussels sprouts":3, "cream cheese":14, "cherry tomatoes":6, "salsa":4, "parsley":75, "green olives":2, "molasses":23, "beer":14, "chili powder":26, "spaghetti":5, "raisins":5, "red wine vinegar":18, "chives":18, "cornstarch":33, "orange":3, "dried basil":10, "radishes":2, "catsup":32, "ground beef":34, "romaine lettuce":4, "mozzarella cheese":3, "sweet red pepper":4, "barbecue sauce":6, "raw spinach":2, "red pepper flakes":7, "almonds":4, "eggs":157, "margarine":13, "kale":3, "garlic powder":35, "dried thyme":20, "cream of mushroom soup":18, "whole wheat flour":2, "salt":516, "fresh basil":4, "bean sprouts":2, "potatoes":75, "frozen spinach":2, "celery seeds":3, "allspice":5, "dijon mustard":21, "soy sauce":36, "broccoli":8, "apples":7, "white rice":2, "sweet potatoes":2, "maple syrup":5, "yellow mustard":2, "egg whites":7, "worcestershire sauce":65, "dried cilantro":2, "brown sugar":83, "lime juice":4, "dry mustard":51, "mayonnaise":54, "chicken wings":2, "vegetable oil":54, "olive oil":59, "fresh thyme":6, "curry powder":6, "flour":143, "vinegar":97, "white wine":27, "sherry":11, "whipping cream":16, "chicken breast":2, "sugar":128}, "baking soda": {"coconut oil":2, "bacon":8, "cayenne pepper":9, "lemon juice":110, "honey":230, "swiss cheese":2, "paprika":6, "bread":2, "ground cinnamon":400, "yeast":58, "egg yolks":36, "green pepper":6, "baking powder":1877, "sesame oil":8, "cinnamon":991, "cream of tartar":142, "pine nuts":10, "cheddar cheese":11, "tomatoes":4, "white pepper":9, "brown rice":2, "black beans":2, "pinto beans":2, "butter":1047, "frozen peas":3, "orange juice":137, "black pepper":22, "lemon":19, "tumeric":3, "buttermilk":635, "powdered sugar":149, "dried oregano":5, "eggplant":3, "cornmeal":93, "cloves":209, "oil":274, "chicken":2, "cucumber":2, "canola oil":56, "strawberries":19, "celery":2, "fresh peaches":4, "walnuts":238, "nutmeg":404, "fresh cilantro":2, "bread crumbs":6, "corn syrup":50, "ginger":175, "fresh rosemary":2, "pecans":133, "peanut butter":115, "cumin":6, "green onions":5, "canned chicken broth":2, "banana":36, "skim milk":95, "beets":3, "shortening":481, "parmesan cheese":5, "applesauce":145, "carrots":55, "mushrooms":3, "sour cream":232, "yogurt":27, "tofu":4, "cream cheese":69, "salsa":2, "parsley":4, "rice vinegar":2, "molasses":269, "beer":10, "chili powder":12, "raisins":529, "garam masala":2, "chives":4, "cornstarch":61, "orange":41, "dried basil":6, "catsup":4, "ground beef":2, "mozzarella cheese":3, "sweet red pepper":2, "cumin seeds":4, "barbecue sauce":2, "red pepper flakes":2, "almonds":40, "eggs":1900, "margarine":349, "fresh ginger":6, "garlic powder":6, "dried thyme":7, "low fat milk":3, "vanilla":1393, "whole wheat flour":248, "salt":3399, "fresh basil":3, "bean sprouts":2, "potatoes":5, "almond extract":106, "allspice":139, "soy sauce":10, "apples":83, "maple syrup":47, "sweet potatoes":5, "egg whites":253, "worcestershire sauce":3, "brown sugar":903, "dry mustard":7, "white flour":48, "blueberries":51, "mayonnaise":10, "vegetable oil":406, "olive oil":17, "flour":1969, "curry powder":2, "vinegar":74, "white wine":2, "sherry":5, "oats":84, "whipping cream":23, "sugar":2741}, "black pepper": {"elbow macaroni":9, "red wine":44, "canned tomato sauce":6, "bacon":54, "cayenne pepper":250, "lemon juice":258, "honey":72, "swiss cheese":11, "zucchini squash":2, "paprika":328, "ground cinnamon":30, "bread":12, "dried bay leaf":2, "yeast":17, "egg yolks":21, "green pepper":90, "baking powder":44, "saffron":17, "sesame oil":46, "cream of tartar":3, "pine nuts":24, "cinnamon":87, "avocado":7, "cheddar cheese":45, "tomatoes":187, "white pepper":134, "brown rice":11, "black beans":21, "pinto beans":24, "fresh garlic":14, "cauliflower":9, "frozen peas":18, "butter":341, "salmon":4, "orange juice":29, "lemon":54, "tumeric":14, "black olives":15, "buttermilk":18, "powdered sugar":4, "hoisin sauce":6, "dried oregano":105, "eggplant":41, "capers":23, "cornmeal":28, "cloves":44, "oil":163, "chicken":61, "blue cheese":9, "cucumber":21, "dry rosemary":2, "canola oil":24, "dried tarragon":13, "strawberries":2, "celery":134, "cornish game hens":4, "walnuts":16, "nutmeg":73, "fresh cilantro":14, "bread crumbs":65, "baking soda":22, "tabasco sauce":78, "ginger":74, "balsamic vinegar":45, "fresh rosemary":5, "lime":14, "pecans":14, "peanut butter":8, "frozen corn":12, "cumin":171, "green onions":113, "canned chicken broth":2, "beets":3, "banana":4, "skim milk":40, "barley":3, "kidney beans":21, "shortening":17, "applesauce":3, "parmesan cheese":102, "carrots":150, "mushrooms":108, "sour cream":80, "yogurt":10, "cream cheese":24, "tofu":21, "cherry tomatoes":11, "salsa":9, "parsley":207, "green olives":9, "rice vinegar":9, "molasses":32, "beer":22, "chili powder":229, "spaghetti":15, "raisins":23, "red wine vinegar":79, "garam masala":13, "chives":19, "cornstarch":86, "orange":10, "dried basil":69, "radishes":2, "catsup":42, "ground beef":74, "romaine lettuce":4, "mozzarella cheese":41, "sweet red pepper":14, "canned tuna":2, "cumin seeds":22, "barbecue sauce":8, "red pepper flakes":35, "almonds":13, "eggs":176, "margarine":91, "fresh ginger":11, "kale":4, "garlic powder":273, "dried thyme":112, "cream of mushroom soup":13, "vanilla":9, "whole wheat flour":13, "salt":1964, "fresh basil":28, "bean sprouts":10, "shiitake mushrooms":7, "potatoes":118, "almond extract":2, "frozen spinach":8, "celery seeds":10, "allspice":68, "dijon mustard":76, "soy sauce":173, "broccoli":13, "chicken legs":3, "apples":15, "sweet potatoes":8, "maple syrup":12, "white rice":11, "yellow mustard":10, "red leaf lettuce":2, "egg whites":37, "worcestershire sauce":183, "dried cilantro":3, "brown sugar":145, "lime juice":36, "dry mustard":133, "raw shrimp":3, "white flour":8, "mayonnaise":59, "chicken wings":17, "vegetable oil":202, "fresh thyme":13, "olive oil":569, "flour":266, "curry powder":64, "vinegar":121, "white wine":58, "sherry":20, "yam":3, "whipping cream":9, "chicken breast":13, "sugar":297}, "brown rice": {"canned tomato sauce":2, "bacon":2, "cayenne pepper":5, "lemon juice":12, "honey":12, "zucchini squash":2, "swiss cheese":3, "paprika":14, "ground cinnamon":7, "egg yolks":2, "green pepper":13, "baking powder":2, "saffron":2, "sesame oil":4, "pine nuts":3, "cinnamon":15, "avocado":2, "cheddar cheese":4, "tomatoes":28, "white pepper":7, "black beans":7, "pinto beans":2, "cauliflower":2, "butter":20, "frozen peas":4, "salmon":2, "orange juice":2, "lemon":2, "black pepper":11, "black olives":2, "buttermilk":2, "eggplant":4, "dried oregano":6, "cornmeal":2, "cloves":5, "oil":16, "chicken":3, "cucumber":3, "canola oil":2, "dried tarragon":3, "celery":27, "alfalfa sprouts":2, "nutmeg":5, "walnuts":2, "baking soda":2, "bread crumbs":7, "tabasco sauce":12, "ginger":3, "balsamic vinegar":3, "lime":2, "pecans":3, "peanut butter":7, "green onions":13, "cumin":17, "canned chicken broth":2, "skim milk":3, "barley":9, "kidney beans":7, "parmesan cheese":4, "carrots":24, "mushrooms":19, "sour cream":3, "tofu":6, "salsa":4, "parsley":21, "green olives":2, "rice vinegar":4, "molasses":5, "chili powder":18, "raisins":7, "red wine vinegar":4, "chives":2, "cornstarch":5, "dried basil":11, "orange":4, "ground beef":4, "adzuki beans":2, "mozzarella cheese":3, "sweet red pepper":4, "cumin seeds":3, "red pepper flakes":2, "eggs":12, "almonds":3, "margarine":5, "fresh ginger":2, "garlic powder":20, "dried thyme":6, "vanilla":3, "whole wheat flour":3, "salt":75, "bean sprouts":4, "potatoes":4, "frozen spinach":2, "allspice":2, "dijon mustard":2, "soy sauce":24, "broccoli":5, "apples":3, "white rice":3, "maple syrup":2, "egg whites":2, "worcestershire sauce":2, "dry mustard":3, "mayonnaise":2, "fresh thyme":2, "vegetable oil":27, "olive oil":27, "flour":4, "curry powder":13, "vinegar":2, "white wine":4, "sherry":2, "sugar":6}, "baking powder": {"red wine":3, "bacon":21, "cayenne pepper":20, "lemon juice":206, "honey":305, "zucchini squash":2, "swiss cheese":4, "paprika":19, "ground cinnamon":392, "bread":9, "yeast":21, "egg yolks":152, "green pepper":11, "saffron":3, "sesame oil":7, "cream of tartar":78, "cinnamon":1027, "pine nuts":21, "cheddar cheese":42, "tomatoes":5, "white pepper":14, "brown rice":2, "black beans":4, "fresh garlic":2, "pinto beans":2, "cauliflower":2, "frozen peas":4, "butter":1518, "orange juice":211, "lemon":55, "black pepper":44, "tumeric":3, "black olives":5, "buttermilk":425, "powdered sugar":219, "eggplant":6, "dried oregano":11, "capers":2, "cornmeal":161, "cloves":179, "oil":405, "chicken":13, "blue cheese":2, "canola oil":79, "dried tarragon":3, "strawberries":41, "celery":12, "walnuts":237, "nutmeg":423, "fresh peaches":12, "fresh cilantro":4, "baking soda":1877, "bread crumbs":9, "tabasco sauce":6, "corn syrup":26, "ginger":95, "pecans":138, "peanut butter":80, "frozen corn":4, "green onions":16, "cumin":10, "beets":2, "banana":37, "skim milk":218, "barley":2, "kidney beans":2, "shortening":675, "parmesan cheese":12, "applesauce":167, "carrots":70, "mushrooms":10, "sour cream":188, "yogurt":32, "cream cheese":83, "tofu":5, "salsa":6, "parsley":21, "molasses":135, "chili powder":23, "beer":31, "raisins":483, "garam masala":4, "chives":10, "cornstarch":132, "orange":45, "dried basil":10, "catsup":3, "ground beef":8, "mozzarella cheese":6, "sweet red pepper":6, "cumin seeds":2, "canned peaches":2, "red pepper flakes":2, "almonds":93, "eggs":2558, "margarine":372, "fresh ginger":3, "kale":2, "garlic powder":22, "dried thyme":16, "low fat milk":2, "vanilla":1555, "whole wheat flour":282, "salt":4656, "fresh basil":5, "bean sprouts":2, "potatoes":18, "almond extract":182, "canned apricots":2, "celery seeds":2, "allspice":124, "dijon mustard":3, "soy sauce":13, "broccoli":3, "apples":115, "maple syrup":76, "sweet potatoes":11, "egg whites":442, "worcestershire sauce":8, "brown sugar":740, "lime juice":14, "dry mustard":16, "white flour":44, "blueberries":118, "mayonnaise":14, "chicken wings":2, "fresh thyme":2, "vegetable oil":527, "olive oil":38, "flour":3076, "curry powder":12, "vinegar":23, "white wine":7, "sherry":7, "oats":43, "whipping cream":68, "chicken breast":3, "sugar":3957}, "avocado": {"sour cream":29, "yogurt":2, "red wine":2, "cream cheese":8, "cherry tomatoes":4, "bacon":6, "salsa":8, "parsley":6, "cayenne pepper":6, "green olives":3, "rice vinegar":2, "honey":4, "lemon juice":34, "swiss cheese":3, "beer":2, "paprika":6, "chili powder":20, "red wine vinegar":8, "chives":3, "green pepper":2, "cornstarch":3, "dried basil":2, "orange":4, "sesame oil":2, "radishes":3, "catsup":4, "cinnamon":3, "ground beef":8, "cheddar cheese":16, "romaine lettuce":2, "corn tortilla":2, "sweet red pepper":2, "tomatoes":38, "cumin seeds":2, "white pepper":5, "brown rice":2, "red pepper flakes":2, "almonds":2, "eggs":10, "black beans":5, "frozen peas":2, "butter":14, "garlic powder":5, "orange juice":2, "black pepper":7, "lemon":8, "salt":71, "bean sprouts":2, "black olives":4, "buttermilk":2, "eggplant":2, "dried oregano":12, "capers":4, "cornmeal":2, "cloves":3, "oil":11, "chicken":4, "blue cheese":3, "cucumber":9, "canola oil":4, "dijon mustard":3, "soy sauce":3, "strawberries":4, "celery":2, "broccoli":2, "shell macaroni":2, "white rice":2, "alfalfa sprouts":6, "fresh cilantro":11, "red leaf lettuce":2, "bread crumbs":2, "worcestershire sauce":8, "tabasco sauce":3, "balsamic vinegar":2, "lime juice":26, "dry mustard":2, "lime":5, "mayonnaise":19, "green onions":17, "cumin":11, "olive oil":37, "vegetable oil":13, "curry powder":2, "flour":7, "kidney beans":7, "vinegar":10, "white wine":3, "parmesan cheese":5, "carrots":2, "sugar":16, "mushrooms":3}, "saffron": {"sour cream":5, "yogurt":7, "red wine":2, "cherry tomatoes":2, "bacon":2, "parsley":18, "cayenne pepper":4, "green olives":4, "lemon juice":12, "honey":5, "beer":3, "chili powder":3, "paprika":18, "bread":2, "ground cinnamon":2, "raisins":4, "red wine vinegar":2, "yeast":3, "chives":2, "garam masala":8, "egg yolks":4, "green pepper":16, "baking powder":3, "cornstarch":7, "dried basil":2, "cinnamon":13, "pine nuts":4, "sweet red pepper":4, "tomatoes":26, "cumin seeds":5, "white pepper":8, "brown rice":2, "red pepper flakes":2, "eggs":8, "almonds":11, "margarine":5, "fresh ginger":4, "frozen peas":3, "butter":35, "garlic powder":4, "dried thyme":3, "salt":83, "black pepper":17, "lemon":7, "fresh basil":2, "tumeric":3, "black olives":2, "potatoes":5, "almond extract":2, "capers":6, "cornmeal":2, "cloves":12, "oil":16, "chicken":23, "cucumber":2, "allspice":2, "canola oil":2, "soy sauce":2, "celery":4, "white rice":2, "nutmeg":8, "walnuts":3, "fresh cilantro":2, "tabasco sauce":4, "brown sugar":3, "ginger":13, "lime juice":2, "dry mustard":3, "raw shrimp":3, "mayonnaise":2, "green onions":4, "cumin":3, "canned chicken broth":2, "olive oil":68, "vegetable oil":8, "fresh thyme":2, "curry powder":2, "flour":10, "shortening":2, "vinegar":7, "parmesan cheese":6, "white wine":9, "carrots":6, "whipping cream":5, "chicken breast":2, "sugar":17, "mushrooms":4}, "whole wheat flour": {"bacon":2, "cayenne pepper":8, "lemon juice":29, "honey":246, "zucchini squash":2, "swiss cheese":2, "paprika":4, "ground cinnamon":54, "bread":2, "yeast":221, "egg yolks":2, "green pepper":3, "baking powder":282, "sesame oil":2, "cinnamon":139, "cream of tartar":8, "pine nuts":4, "cheddar cheese":6, "tomatoes":2, "white pepper":4, "brown rice":3, "black beans":2, "frozen peas":3, "butter":131, "orange juice":30, "black pepper":13, "black olives":3, "buttermilk":75, "powdered sugar":5, "dried oregano":7, "eggplant":2, "cornmeal":57, "cloves":16, "oil":89, "chicken":2, "cucumber":4, "canola oil":37, "dried tarragon":2, "strawberries":2, "fresh cilantro":2, "fresh peaches":2, "nutmeg":47, "walnuts":39, "baking soda":248, "bread crumbs":2, "corn syrup":5, "tabasco sauce":2, "ginger":22, "fresh rosemary":2, "pecans":15, "peanut butter":11, "cumin":2, "frozen corn":2, "skim milk":48, "banana":18, "shortening":28, "applesauce":56, "parmesan cheese":7, "carrots":21, "mushrooms":8, "sour cream":15, "yogurt":7, "tofu":3, "cream cheese":5, "parsley":7, "molasses":111, "chili powder":6, "beer":5, "raisins":111, "chives":6, "garam masala":3, "cornstarch":7, "orange":7, "dried basil":9, "catsup":2, "ground beef":2, "mozzarella cheese":4, "almonds":6, "eggs":135, "margarine":63, "garlic powder":28, "dried thyme":6, "low fat milk":2, "vanilla":78, "salt":756, "fresh basil":4, "potatoes":11, "almond extract":13, "frozen spinach":2, "allspice":21, "celery seeds":2, "dijon mustard":5, "soy sauce":15, "apples":16, "sweet potatoes":3, "maple syrup":17, "egg whites":51, "worcestershire sauce":2, "brown sugar":136, "dry mustard":2, "white flour":70, "blueberries":11, "fresh thyme":2, "olive oil":58, "vegetable oil":139, "flour":76, "curry powder":4, "vinegar":2, "white wine":2, "sherry":2, "oats":18, "whipping cream":2, "sugar":302}, "mayonnaise": {"elbow macaroni":4, "bacon":54, "cayenne pepper":40, "honey":36, "lemon juice":333, "swiss cheese":22, "paprika":97, "camembert cheese":2, "ground cinnamon":5, "bread":21, "egg yolks":7, "green pepper":62, "baking powder":14, "saffron":2, "sesame oil":6, "pine nuts":5, "cinnamon":10, "avocado":19, "cheddar cheese":56, "tomatoes":52, "white pepper":33, "brown rice":2, "cauliflower":4, "frozen peas":10, "butter":103, "salmon":9, "orange juice":9, "lemon":44, "black pepper":59, "tumeric":2, "black olives":13, "buttermilk":21, "powdered sugar":7, "eggplant":4, "hoisin sauce":2, "dried oregano":15, "capers":32, "cornmeal":3, "cloves":7, "oil":31, "chicken":38, "blue cheese":16, "cucumber":37, "flour tortilla":2, "dried tarragon":12, "strawberries":2, "celery":127, "alfalfa sprouts":3, "fresh cilantro":8, "nutmeg":5, "walnuts":21, "baking soda":10, "bread crumbs":33, "tabasco sauce":43, "balsamic vinegar":3, "ginger":6, "lime":5, "pecans":24, "peanut butter":4, "frozen corn":2, "cumin":5, "green onions":107, "beets":3, "skim milk":4, "banana":2, "kidney beans":2, "shortening":3, "parmesan cheese":75, "carrots":32, "mushrooms":16, "sour cream":235, "yogurt":15, "tofu":3, "cream cheese":88, "cherry tomatoes":7, "salsa":6, "parsley":72, "green olives":8, "rice vinegar":4, "beer":8, "chili powder":17, "raisins":20, "red wine vinegar":21, "garam masala":2, "chives":19, "cornstarch":8, "orange":3, "dried basil":13, "catsup":25, "radishes":9, "ground beef":14, "romaine lettuce":3, "mozzarella cheese":14, "sweet red pepper":5, "canned tuna":3, "barbecue sauce":3, "red pepper flakes":3, "eggs":145, "almonds":11, "margarine":13, "fresh ginger":2, "garlic powder":86, "dried thyme":8, "cream of mushroom soup":25, "vanilla":10, "salt":493, "fresh basil":7, "bean sprouts":2, "potatoes":24, "almond extract":2, "frozen spinach":7, "allspice":5, "celery seeds":5, "dijon mustard":98, "soy sauce":20, "broccoli":14, "apples":16, "maple syrup":2, "shell macaroni":2, "sweet potatoes":2, "yellow mustard":15, "red leaf lettuce":2, "egg whites":6, "worcestershire sauce":164, "brown sugar":10, "lime juice":17, "dry mustard":77, "raw shrimp":3, "chicken wings":5, "fresh thyme":2, "olive oil":52, "vegetable oil":24, "curry powder":98, "flour":61, "vinegar":74, "white wine":4, "sherry":7, "whipping cream":25, "chicken breast":6, "sugar":159}, "almond extract": {"sour cream":38, "yogurt":2, "red wine":2, "tofu":2, "cream cheese":43, "honey":33, "lemon juice":37, "molasses":4, "ground cinnamon":17, "raisins":14, "yeast":7, "egg yolks":30, "cornstarch":28, "baking powder":182, "saffron":2, "orange":7, "pine nuts":5, "cinnamon":47, "cream of tartar":39, "almonds":74, "eggs":230, "margarine":55, "butter":163, "low fat milk":2, "vanilla":161, "orange juice":21, "whole wheat flour":13, "black pepper":2, "lemon":5, "salt":330, "buttermilk":16, "powdered sugar":61, "cornmeal":2, "cloves":7, "oil":20, "canola oil":5, "allspice":3, "strawberries":6, "apples":6, "maple syrup":5, "fresh peaches":3, "walnuts":15, "nutmeg":16, "egg whites":81, "baking soda":106, "corn syrup":6, "brown sugar":50, "ginger":3, "pecans":10, "blueberries":3, "peanut butter":3, "mayonnaise":2, "canned chicken broth":2, "vegetable oil":21, "skim milk":18, "banana":4, "flour":227, "vinegar":3, "shortening":37, "white wine":4, "applesauce":5, "carrots":2, "oats":8, "whipping cream":31, "sugar":510}, "dried cilantro": {"sour cream":2, "buttermilk":2, "bacon":2, "cayenne pepper":2, "lemon juice":3, "chicken":2, "paprika":3, "chili powder":3, "allspice":2, "canola oil":2, "celery":2, "green pepper":2, "fresh cilantro":3, "sesame oil":2, "brown sugar":2, "ground beef":2, "ginger":3, "lime juice":4, "tomatoes":2, "sweet red pepper":2, "green onions":2, "cumin":5, "olive oil":2, "white pepper":2, "red pepper flakes":2, "flour":2, "butter":2, "vinegar":2, "garlic powder":3, "carrots":2, "sugar":4, "black pepper":3, "salt":6}, "celery seeds": {"sour cream":3, "elbow macaroni":2, "cream cheese":2, "bacon":3, "cayenne pepper":6, "lemon juice":10, "honey":5, "molasses":2, "paprika":14, "ground cinnamon":2, "yeast":3, "red wine vinegar":6, "egg yolks":2, "green pepper":3, "cornstarch":2, "baking powder":2, "catsup":2, "ground beef":2, "cream of tartar":2, "pine nuts":2, "cinnamon":3, "tomatoes":4, "sweet red pepper":4, "cumin seeds":3, "white pepper":5, "eggs":2, "margarine":2, "cauliflower":3, "fresh ginger":2, "butter":6, "garlic powder":6, "dried thyme":5, "vanilla":2, "whole wheat flour":2, "black pepper":10, "lemon":3, "salt":57, "fresh basil":3, "tumeric":5, "potatoes":3, "cloves":2, "oil":2, "chicken":2, "cucumber":2, "allspice":2, "dried tarragon":2, "dijon mustard":4, "soy sauce":3, "celery":5, "apples":2, "nutmeg":5, "egg whites":2, "bread crumbs":2, "worcestershire sauce":5, "tabasco sauce":2, "brown sugar":8, "balsamic vinegar":2, "ginger":3, "lime juice":2, "dry mustard":17, "mayonnaise":5, "green onions":2, "cumin":2, "chicken wings":2, "olive oil":11, "vegetable oil":6, "beets":2, "curry powder":5, "flour":3, "kidney beans":2, "vinegar":15, "carrots":8, "whipping cream":2, "sugar":36, "mushrooms":2}, "frozen spinach": {"sour cream":7, "yogurt":2, "tofu":2, "cream cheese":6, "bacon":2, "salsa":2, "parsley":6, "cayenne pepper":6, "lemon juice":7, "swiss cheese":4, "chili powder":2, "paprika":3, "ground cinnamon":2, "raisins":3, "garam masala":3, "cornstarch":2, "dried basil":2, "ground beef":4, "pine nuts":2, "cheddar cheese":7, "mozzarella cheese":11, "tomatoes":7, "cumin seeds":2, "white pepper":4, "brown rice":2, "eggs":22, "margarine":6, "fresh ginger":4, "cauliflower":2, "frozen peas":2, "butter":27, "garlic powder":6, "dried thyme":3, "cream of mushroom soup":2, "whole wheat flour":2, "black pepper":8, "salt":38, "lemon":3, "fresh basil":2, "black olives":2, "potatoes":2, "buttermilk":2, "dried oregano":3, "eggplant":2, "oil":9, "celery":2, "broccoli":2, "nutmeg":16, "egg whites":2, "bread crumbs":5, "worcestershire sauce":2, "ginger":3, "dry mustard":2, "pecans":3, "mayonnaise":7, "green onions":11, "cumin":4, "vegetable oil":7, "olive oil":13, "skim milk":3, "curry powder":3, "flour":18, "parmesan cheese":13, "white wine":2, "carrots":3, "whipping cream":2, "mushrooms":6, "sugar":8}, "egg whites": {"red wine":2, "bacon":7, "cayenne pepper":8, "honey":71, "lemon juice":151, "zucchini squash":2, "swiss cheese":5, "paprika":15, "bread":4, "ground cinnamon":87, "yeast":19, "egg yolks":368, "green pepper":5, "baking powder":442, "sesame oil":10, "pine nuts":11, "cream of tartar":254, "cinnamon":167, "cheddar cheese":10, "tomatoes":7, "white pepper":12, "brown rice":2, "black beans":3, "pinto beans":2, "cauliflower":2, "butter":221, "salmon":5, "orange juice":59, "lemon":31, "black pepper":37, "buttermilk":46, "powdered sugar":124, "eggplant":5, "dried oregano":11, "cornmeal":28, "cloves":29, "oil":44, "chicken":3, "canola oil":31, "strawberries":29, "celery":11, "fresh cilantro":2, "walnuts":36, "nutmeg":77, "baking soda":253, "bread crumbs":22, "tabasco sauce":2, "corn syrup":35, "balsamic vinegar":4, "ginger":28, "lime":4, "pecans":32, "peanut butter":13, "frozen corn":2, "green onions":18, "cumin":4, "canned chicken broth":2, "skim milk":150, "banana":7, "beets":2, "barley":2, "kidney beans":2, "shortening":35, "applesauce":55, "parmesan cheese":18, "carrots":17, "mushrooms":10, "sour cream":23, "yogurt":6, "tofu":4, "cream cheese":18, "cherry tomatoes":2, "salsa":5, "parsley":14, "rice vinegar":2, "molasses":27, "beer":3, "chili powder":5, "spaghetti":3, "raisins":74, "red wine vinegar":3, "chives":6, "cornstarch":147, "orange":9, "dried basil":11, "catsup":3, "ground beef":2, "mozzarella cheese":12, "sweet red pepper":2, "barbecue sauce":2, "red pepper flakes":4, "eggs":105, "almonds":36, "margarine":107, "fresh ginger":5, "garlic powder":20, "dried thyme":7, "vanilla":517, "whole wheat flour":51, "salt":945, "fresh basil":4, "bean sprouts":3, "shiitake mushrooms":2, "potatoes":11, "almond extract":81, "frozen spinach":2, "celery seeds":2, "allspice":13, "dijon mustard":5, "soy sauce":14, "chicken legs":2, "apples":28, "maple syrup":36, "sweet potatoes":6, "worcestershire sauce":7, "brown sugar":109, "lime juice":9, "dry mustard":11, "white flour":4, "blueberries":20, "mayonnaise":6, "chicken wings":3, "vegetable oil":109, "olive oil":44, "flour":323, "curry powder":5, "vinegar":31, "white wine":5, "sherry":19, "oats":13, "whipping cream":92, "chicken breast":6, "sugar":1246}, "frozen french fries": {"worcestershire sauce":2, "cheddar cheese":2, "cream of mushroom soup":3}, "molasses": {"red wine":4, "canned tomato sauce":3, "bacon":23, "cayenne pepper":15, "lemon juice":42, "honey":76, "paprika":22, "bread":3, "ground cinnamon":77, "yeast":99, "egg yolks":5, "green pepper":11, "baking powder":135, "sesame oil":2, "cinnamon":221, "cream of tartar":8, "tomatoes":9, "white pepper":5, "brown rice":5, "black beans":3, "pinto beans":3, "butter":181, "orange juice":29, "lemon":12, "black pepper":32, "tumeric":2, "buttermilk":53, "powdered sugar":14, "eggplant":2, "dried oregano":3, "hoisin sauce":3, "capers":2, "cornmeal":40, "cloves":78, "oil":47, "chicken":2, "canola oil":13, "dried tarragon":2, "celery":8, "fresh peaches":4, "nutmeg":98, "walnuts":9, "baking soda":269, "bread crumbs":3, "tabasco sauce":19, "corn syrup":5, "ginger":162, "balsamic vinegar":7, "fresh rosemary":2, "lime":2, "pecans":9, "peanut butter":7, "green onions":4, "cumin":11, "skim milk":10, "banana":2, "barley":2, "kidney beans":2, "shortening":99, "applesauce":21, "carrots":8, "mushrooms":6, "sour cream":12, "yogurt":3, "cream cheese":3, "cherry tomatoes":2, "parsley":4, "rice vinegar":3, "chili powder":32, "beer":14, "raisins":97, "red wine vinegar":20, "cornstarch":21, "dried basil":2, "orange":9, "catsup":31, "ground beef":6, "cumin seeds":3, "barbecue sauce":3, "red pepper flakes":4, "eggs":125, "almonds":8, "margarine":38, "fresh ginger":8, "garlic powder":22, "dried thyme":4, "vanilla":47, "whole wheat flour":111, "salt":609, "bean sprouts":2, "potatoes":3, "almond extract":4, "celery seeds":2, "allspice":51, "dijon mustard":19, "soy sauce":50, "apples":9, "white rice":2, "sweet potatoes":3, "maple syrup":15, "egg whites":27, "worcestershire sauce":48, "brown sugar":194, "lime juice":6, "dry mustard":73, "white flour":14, "blueberries":9, "chicken wings":5, "vegetable oil":65, "olive oil":31, "flour":214, "curry powder":9, "vinegar":65, "white wine":2, "sherry":2, "oats":12, "whipping cream":3, "sugar":256}, "sweet potatoes": {"red wine":2, "bacon":2, "cayenne pepper":5, "lemon juice":11, "honey":16, "paprika":3, "ground cinnamon":21, "yeast":3, "egg yolks":5, "green pepper":6, "baking powder":11, "sesame oil":2, "cream of tartar":3, "cinnamon":53, "cheddar cheese":2, "tomatoes":9, "white pepper":4, "pinto beans":2, "butter":54, "frozen peas":2, "orange juice":28, "black pepper":8, "lemon":2, "buttermilk":5, "eggplant":2, "dried oregano":2, "cloves":5, "oil":15, "chicken":5, "cucumber":2, "canola oil":3, "celery":5, "nutmeg":36, "walnuts":4, "baking soda":5, "bread crumbs":2, "corn syrup":4, "tabasco sauce":2, "balsamic vinegar":5, "ginger":11, "lime":3, "pecans":12, "peanut butter":2, "green onions":5, "cumin":6, "canned chicken broth":2, "skim milk":5, "shortening":5, "applesauce":3, "carrots":22, "mushrooms":2, "sour cream":2, "cream cheese":4, "tofu":2, "cherry tomatoes":2, "parsley":8, "molasses":3, "chili powder":5, "raisins":17, "red wine vinegar":4, "cornstarch":22, "orange":6, "catsup":2, "ground beef":2, "sweet red pepper":2, "eggs":27, "almonds":3, "margarine":21, "garlic powder":3, "dried thyme":4, "cream of mushroom soup":2, "vanilla":8, "whole wheat flour":3, "salt":132, "shiitake mushrooms":2, "potatoes":5, "allspice":8, "dijon mustard":4, "soy sauce":6, "broccoli":3, "apples":14, "chicken legs":2, "maple syrup":8, "egg whites":6, "worcestershire sauce":4, "brown sugar":47, "lime juice":2, "dry mustard":3, "mayonnaise":2, "vegetable oil":17, "olive oil":27, "fresh thyme":3, "curry powder":14, "flour":26, "vinegar":6, "sherry":4, "whipping cream":4, "sugar":56}, "yam": {"cornstarch":2, "dried basil":2, "balsamic vinegar":2, "ground beef":2, "cherry tomatoes":3, "green onions":2, "cloves":2, "vegetable oil":2, "olive oil":2, "flour":2, "margarine":2, "canola oil":2, "dijon mustard":2, "fresh ginger":2, "butter":2, "sherry":2, "carrots":2, "nutmeg":2, "salt":2, "mushrooms":2, "black pepper":3}, "fresh basil": {"red wine":10, "elbow macaroni":2, "canned tomato sauce":2, "bacon":4, "cayenne pepper":8, "lemon juice":31, "honey":6, "paprika":3, "yeast":2, "egg yolks":4, "green pepper":8, "baking powder":5, "saffron":2, "sesame oil":4, "pine nuts":15, "cinnamon":2, "tomatoes":52, "white pepper":10, "black beans":2, "fresh garlic":3, "cauliflower":2, "butter":45, "frozen peas":2, "orange juice":2, "black pepper":28, "lemon":11, "black olives":13, "buttermilk":4, "hoisin sauce":2, "eggplant":20, "dried oregano":19, "capers":10, "cornmeal":3, "cloves":2, "oil":13, "chicken":6, "blue cheese":2, "cucumber":2, "flour tortilla":2, "celery":10, "walnuts":2, "nutmeg":6, "fresh cilantro":4, "baking soda":3, "bread crumbs":4, "tabasco sauce":2, "balsamic vinegar":20, "fresh rosemary":11, "frozen corn":2, "cumin":3, "green onions":14, "skim milk":2, "parmesan cheese":53, "carrots":17, "mushrooms":20, "sour cream":10, "tofu":2, "cream cheese":7, "cherry tomatoes":10, "parsley":16, "rice vinegar":3, "beer":2, "chili powder":2, "spaghetti":8, "raisins":2, "red wine vinegar":24, "chives":5, "cornstarch":6, "dried basil":28, "ground beef":4, "mozzarella cheese":18, "sweet red pepper":9, "red pepper flakes":9, "eggs":17, "margarine":7, "fresh ginger":3, "garlic powder":8, "dried thyme":9, "whole wheat flour":4, "salt":141, "bean sprouts":2, "shiitake mushrooms":2, "potatoes":5, "frozen spinach":2, "allspice":2, "celery seeds":3, "dijon mustard":17, "soy sauce":9, "broccoli":4, "chicken legs":2, "maple syrup":2, "white rice":2, "egg whites":4, "worcestershire sauce":7, "brown sugar":6, "lime juice":4, "dry mustard":4, "mayonnaise":7, "olive oil":199, "vegetable oil":23, "fresh thyme":20, "flour":10, "curry powder":2, "vinegar":2, "white wine":14, "whipping cream":11, "chicken breast":4, "sugar":31}, "cashew":{"lemon":2, "salt":2}, "banana": {"sour cream":17, "yogurt":7, "cream cheese":3, "parsley":2, "cayenne pepper":4, "honey":31, "lemon juice":22, "molasses":2, "paprika":3, "chili powder":2, "bread":2, "ground cinnamon":10, "raisins":9, "red wine vinegar":2, "yeast":14, "baking powder":37, "cornstarch":5, "orange":12, "pine nuts":2, "cream of tartar":5, "cinnamon":29, "tomatoes":4, "cumin seeds":2, "white pepper":2, "almonds":6, "eggs":18, "pinto beans":2, "margarine":7, "fresh ginger":3, "butter":30, "vanilla":33, "orange juice":35, "whole wheat flour":18, "black pepper":4, "lemon":3, "salt":72, "potatoes":2, "buttermilk":7, "powdered sugar":7, "almond extract":4, "cornmeal":2, "cloves":3, "oil":11, "blue cheese":2, "cucumber":2, "allspice":2, "canola oil":4, "soy sauce":3, "strawberries":24, "broccoli":2, "apples":6, "maple syrup":3, "walnuts":15, "nutmeg":10, "egg whites":7, "baking soda":36, "corn syrup":2, "brown sugar":17, "balsamic vinegar":3, "ginger":4, "lime juice":5, "lime":2, "pecans":9, "blueberries":13, "peanut butter":9, "mayonnaise":2, "cumin":2, "green onions":2, "vegetable oil":17, "olive oil":3, "skim milk":11, "flour":33, "curry powder":12, "vinegar":2, "shortening":4, "white wine":2, "parmesan cheese":2, "applesauce":5, "carrots":4, "oats":3, "whipping cream":7, "mushrooms":2, "sugar":72}, "canned chicken broth": {"sour cream":4, "cayenne pepper":2, "lemon juice":6, "honey":3, "swiss cheese":3, "paprika":3, "chili powder":2, "cornstarch":10, "dried basil":5, "saffron":2, "catsup":2, "pine nuts":2, "sweet red pepper":3, "tomatoes":2, "white pepper":3, "brown rice":2, "red pepper flakes":2, "eggs":2, "fresh ginger":2, "frozen peas":3, "butter":6, "garlic powder":2, "dried thyme":4, "salt":19, "black pepper":2, "lemon":3, "potatoes":2, "almond extract":2, "dried oregano":6, "oil":3, "soy sauce":3, "celery":2, "chicken legs":2, "sweet potatoes":2, "egg whites":2, "baking soda":2, "lime juice":2, "dry mustard":2, "green onions":5, "olive oil":4, "vegetable oil":8, "curry powder":2, "flour":3, "vinegar":2, "white wine":2, "carrots":2, "chicken breast":3, "sugar":5, "mushrooms":2}, "canola oil": {"bacon":4, "cayenne pepper":17, "lemon juice":31, "honey":58, "paprika":18, "bread":3, "ground cinnamon":17, "yeast":25, "egg yolks":6, "green pepper":5, "baking powder":79, "saffron":2, "sesame oil":10, "pine nuts":4, "cinnamon":29, "cream of tartar":6, "avocado":4, "cheddar cheese":4, "tomatoes":23, "brown rice":2, "black beans":4, "fresh garlic":3, "pinto beans":2, "cauliflower":3, "frozen peas":7, "butter":36, "orange juice":20, "lemon":2, "black pepper":24, "tumeric":3, "black olives":2, "buttermilk":18, "powdered sugar":3, "dried oregano":16, "hoisin sauce":3, "cornmeal":6, "cloves":5, "oil":3, "chicken":2, "cucumber":4, "dried tarragon":2, "strawberries":2, "celery":7, "alfalfa sprouts":2, "walnuts":11, "nutmeg":17, "fresh cilantro":8, "baking soda":56, "bread crumbs":8, "tabasco sauce":4, "balsamic vinegar":8, "ginger":8, "fresh rosemary":8, "lime":2, "pecans":3, "peanut butter":2, "frozen corn":3, "green onions":13, "cumin":13, "beets":2, "skim milk":26, "banana":4, "barley":3, "kidney beans":2, "applesauce":6, "parmesan cheese":5, "carrots":25, "mushrooms":17, "sour cream":10, "yogurt":2, "brussels sprouts":3, "tofu":7, "cherry tomatoes":3, "salsa":7, "parsley":9, "rice vinegar":6, "molasses":13, "chili powder":27, "beer":3, "raisins":16, "red wine vinegar":9, "garam masala":5, "chives":4, "cornstarch":12, "dried basil":4, "orange":4, "catsup":2, "ground beef":4, "mozzarella cheese":2, "romaine lettuce":2, "cumin seeds":6, "red pepper flakes":2, "almonds":4, "eggs":50, "margarine":5, "fresh ginger":8, "garlic powder":6, "dried thyme":13, "vanilla":21, "whole wheat flour":37, "salt":263, "shiitake mushrooms":4, "potatoes":11, "almond extract":5, "allspice":4, "dijon mustard":11, "soy sauce":31, "broccoli":3, "apples":10, "sweet potatoes":3, "maple syrup":11, "egg whites":31, "worcestershire sauce":14, "dried cilantro":2, "brown sugar":17, "lime juice":13, "dry mustard":8, "white flour":3, "blueberries":7, "chicken wings":2, "fresh thyme":5, "vegetable oil":2, "olive oil":13, "curry powder":17, "flour":55, "vinegar":11, "white wine":3, "sherry":4, "oats":4, "yam":2, "chicken breast":6, "sugar":100}, "flour": {"canned beef broth":2, "elbow macaroni":19, "red wine":68, "bacon":143, "brown onions":2, "cayenne pepper":165, "honey":315, "lemon juice":619, "swiss cheese":61, "paprika":428, "bread":32, "ground cinnamon":200, "yeast":410, "egg yolks":388, "green pepper":140, "baking powder":3076, "saffron":10, "sesame oil":35, "pine nuts":23, "cream of tartar":154, "cinnamon":1504, "avocado":7, "cheddar cheese":150, "corn tortilla":2, "tomatoes":173, "white pepper":140, "brown rice":4, "black beans":5, "pinto beans":4, "fresh garlic":4, "cauliflower":14, "frozen peas":22, "butter":4221, "salmon":16, "orange juice":199, "lemon":191, "black pepper":266, "tumeric":7, "black olives":9, "buttermilk":391, "powdered sugar":341, "hoisin sauce":3, "eggplant":35, "dried oregano":40, "capers":30, "cornmeal":160, "cloves":277, "oil":957, "chicken":131, "blue cheese":6, "cucumber":4, "flour tortilla":2, "canola oil":55, "dried tarragon":11, "strawberries":44, "celery":185, "fresh peaches":12, "fresh cilantro":5, "nutmeg":785, "walnuts":327, "baking soda":1969, "bread crumbs":185, "corn syrup":40, "tabasco sauce":61, "balsamic vinegar":20, "ginger":217, "fresh rosemary":4, "lime":6, "pecans":257, "peanut butter":123, "frozen corn":7, "green onions":99, "cumin":71, "canned chicken broth":3, "beets":8, "skim milk":148, "banana":33, "barley":6, "kidney beans":7, "shortening":867, "parmesan cheese":204, "applesauce":124, "carrots":282, "mushrooms":300, "sour cream":522, "yogurt":44, "brussels sprouts":2, "cream cheese":282, "tofu":15, "cherry tomatoes":4, "salsa":5, "parsley":362, "green olives":7, "rice vinegar":3, "molasses":214, "chili powder":126, "beer":88, "spaghetti":16, "raisins":590, "red wine vinegar":39, "garam masala":3, "chives":37, "cornstarch":243, "orange":38, "dried basil":35, "catsup":43, "radishes":2, "ground beef":92, "mozzarella cheese":45, "sweet red pepper":8, "cumin seeds":8, "canned peaches":2, "barbecue sauce":8, "raw spinach":3, "red pepper flakes":11, "eggs":3597, "almonds":162, "margarine":662, "fresh ginger":8, "garlic powder":164, "dried thyme":72, "cream of mushroom soup":31, "low fat milk":7, "vanilla":2196, "whole wheat flour":76, "salt":7567, "fresh basil":10, "bean sprouts":5, "shiitake mushrooms":3, "potatoes":263, "almond extract":227, "frozen spinach":18, "canned apricots":2, "celery seeds":3, "allspice":165, "dijon mustard":61, "soy sauce":127, "broccoli":35, "chicken legs":3, "apples":225, "white rice":3, "yellow mustard":2, "shell macaroni":2, "sweet potatoes":26, "maple syrup":60, "canned tomato paste":3, "red leaf lettuce":2, "egg whites":323, "worcestershire sauce":237, "dried cilantro":2, "brown sugar":1252, "lime juice":25, "dry mustard":169, "raw shrimp":4, "white flour":4, "blueberries":86, "mayonnaise":61, "chicken wings":15, "vegetable oil":537, "olive oil":455, "fresh thyme":6, "curry powder":116, "vinegar":208, "white wine":128, "sherry":137, "yam":2, "oats":105, "whipping cream":145, "chicken breast":24, "sugar":5965}, "margarine": {"red wine":5, "elbow macaroni":5, "canned tomato sauce":2, "bacon":13, "cayenne pepper":37, "lemon juice":184, "honey":95, "swiss cheese":22, "paprika":83, "ground cinnamon":133, "bread":11, "yeast":77, "egg yolks":44, "green pepper":40, "baking powder":372, "saffron":5, "pine nuts":4, "cream of tartar":26, "cinnamon":263, "cheddar cheese":57, "tomatoes":37, "white pepper":40, "brown rice":5, "black beans":2, "fresh garlic":2, "cauliflower":2, "frozen peas":4, "butter":39, "salmon":3, "orange juice":64, "lemon":24, "black pepper":91, "tumeric":4, "black olives":7, "buttermilk":55, "powdered sugar":138, "eggplant":12, "dried oregano":11, "capers":5, "cornmeal":21, "cloves":37, "oil":39, "chicken":27, "cucumber":2, "canola oil":5, "flour tortilla":2, "dried tarragon":4, "strawberries":13, "celery":68, "cornish game hens":3, "fresh peaches":2, "fresh cilantro":5, "walnuts":62, "nutmeg":121, "baking soda":349, "bread crumbs":55, "corn syrup":27, "tabasco sauce":19, "balsamic vinegar":6, "ginger":37, "fresh rosemary":3, "pecans":66, "peanut butter":48, "green onions":32, "cumin":15, "frozen corn":6, "skim milk":139, "banana":7, "beets":3, "kidney beans":3, "shortening":36, "parmesan cheese":64, "applesauce":22, "carrots":71, "mushrooms":61, "sour cream":106, "yogurt":11, "brussels sprouts":2, "tofu":4, "cream cheese":125, "cherry tomatoes":2, "salsa":3, "parsley":84, "green olives":2, "molasses":38, "chili powder":37, "beer":6, "spaghetti":3, "raisins":125, "red wine vinegar":5, "garam masala":3, "chives":14, "cornstarch":97, "orange":15, "dried basil":23, "radishes":3, "catsup":9, "ground beef":13, "mozzarella cheese":18, "sweet red pepper":4, "red pepper flakes":3, "almonds":32, "eggs":474, "fresh ginger":2, "garlic powder":74, "dried thyme":21, "cream of mushroom soup":19, "low fat milk":7, "vanilla":426, "whole wheat flour":63, "salt":1259, "fresh basil":7, "bean sprouts":2, "potatoes":66, "almond extract":55, "frozen spinach":6, "celery seeds":2, "allspice":25, "dijon mustard":16, "soy sauce":26, "broccoli":10, "chicken legs":2, "apples":57, "yellow mustard":2, "white rice":2, "maple syrup":22, "sweet potatoes":21, "egg whites":107, "worcestershire sauce":59, "brown sugar":309, "lime juice":12, "dry mustard":31, "white flour":15, "blueberries":18, "mayonnaise":13, "chicken wings":3, "fresh thyme":3, "olive oil":52, "vegetable oil":46, "flour":662, "curry powder":29, "vinegar":27, "white wine":20, "sherry":14, "yam":2, "oats":30, "whipping cream":30, "chicken breast":11, "sugar":1005}, "red wine vinegar": {"elbow macaroni":3, "red wine":19, "bacon":18, "cayenne pepper":34, "lemon juice":70, "honey":49, "swiss cheese":2, "paprika":49, "bread":3, "ground cinnamon":14, "egg yolks":9, "green pepper":34, "saffron":2, "sesame oil":17, "pine nuts":14, "cinnamon":17, "avocado":8, "cheddar cheese":2, "tomatoes":83, "white pepper":19, "brown rice":4, "black beans":11, "pinto beans":3, "frozen peas":6, "butter":52, "salmon":2, "orange juice":18, "black pepper":79, "lemon":19, "tumeric":2, "black olives":13, "buttermilk":5, "dried oregano":48, "eggplant":15, "hoisin sauce":2, "capers":41, "cornmeal":2, "cloves":18, "oil":41, "chicken":13, "blue cheese":5, "cucumber":26, "canola oil":9, "flour tortilla":2, "dried tarragon":10, "celery":21, "alfalfa sprouts":5, "walnuts":4, "fresh cilantro":11, "nutmeg":9, "bread crumbs":3, "corn syrup":2, "tabasco sauce":21, "balsamic vinegar":13, "ginger":21, "fresh rosemary":6, "lime":5, "pecans":3, "peanut butter":2, "cumin":15, "green onions":36, "banana":2, "skim milk":3, "beets":12, "kidney beans":4, "shortening":3, "parmesan cheese":17, "carrots":32, "mushrooms":15, "sour cream":19, "brussels sprouts":3, "tofu":2, "cream cheese":4, "cherry tomatoes":17, "salsa":3, "parsley":48, "green olives":5, "rice vinegar":4, "molasses":20, "beer":13, "chili powder":44, "spaghetti":5, "raisins":18, "chives":5, "cornstarch":37, "dried basil":32, "orange":5, "radishes":4, "catsup":17, "ground beef":5, "mozzarella cheese":7, "romaine lettuce":5, "sweet red pepper":5, "cumin seeds":9, "red pepper flakes":14, "almonds":2, "eggs":14, "margarine":5, "fresh ginger":8, "garlic powder":43, "dried thyme":24, "cream of mushroom soup":2, "salt":432, "fresh basil":24, "bean sprouts":2, "shiitake mushrooms":2, "potatoes":6, "allspice":8, "celery seeds":6, "dijon mustard":100, "soy sauce":87, "broccoli":8, "apples":5, "maple syrup":3, "yellow mustard":8, "sweet potatoes":4, "egg whites":3, "worcestershire sauce":79, "brown sugar":76, "lime juice":22, "dry mustard":48, "raw shrimp":2, "mayonnaise":21, "chicken wings":3, "vegetable oil":101, "olive oil":390, "fresh thyme":10, "curry powder":6, "flour":39, "vinegar":2, "white wine":14, "sherry":9, "whipping cream":2, "chicken breast":5, "sugar":165}, "eggplant": {"elbow macaroni":2, "red wine":6, "bacon":4, "cayenne pepper":15, "lemon juice":42, "honey":7, "zucchini squash":2, "swiss cheese":5, "paprika":17, "bread":2, "ground cinnamon":4, "dried bay leaf":2, "yeast":2, "egg yolks":4, "green pepper":51, "baking powder":6, "sesame oil":5, "pine nuts":10, "cinnamon":12, "avocado":2, "cheddar cheese":6, "tomatoes":94, "white pepper":7, "brown rice":4, "cauliflower":5, "frozen peas":2, "butter":35, "lemon":13, "black pepper":41, "tumeric":4, "black olives":8, "dried oregano":24, "hoisin sauce":2, "capers":11, "cornmeal":3, "cloves":8, "oil":48, "chicken":7, "flour tortilla":2, "celery":9, "walnuts":2, "fresh cilantro":5, "nutmeg":10, "bread crumbs":23, "baking soda":3, "tabasco sauce":3, "balsamic vinegar":22, "ginger":12, "lime":2, "peanut butter":4, "cumin":19, "frozen corn":2, "green onions":6, "skim milk":5, "parmesan cheese":37, "applesauce":2, "carrots":18, "mushrooms":25, "sour cream":4, "yogurt":5, "tofu":3, "cherry tomatoes":5, "salsa":4, "parsley":34, "green olives":5, "molasses":2, "chili powder":12, "beer":2, "spaghetti":3, "raisins":5, "red wine vinegar":15, "garam masala":3, "cornstarch":8, "dried basil":16, "ground beef":14, "romaine lettuce":2, "mozzarella cheese":34, "sweet red pepper":5, "cumin seeds":5, "red pepper flakes":6, "almonds":2, "eggs":38, "margarine":12, "fresh ginger":3, "garlic powder":14, "dried thyme":7, "whole wheat flour":2, "salt":277, "fresh basil":20, "shiitake mushrooms":2, "potatoes":18, "frozen spinach":2, "allspice":4, "dijon mustard":2, "soy sauce":16, "broccoli":2, "sweet potatoes":2, "egg whites":5, "worcestershire sauce":4, "brown sugar":3, "lime juice":2, "raw shrimp":2, "mayonnaise":4, "vegetable oil":26, "olive oil":191, "flour":35, "curry powder":8, "vinegar":19, "white wine":2, "sherry":4, "oats":3, "whipping cream":2, "chicken breast":2, "sugar":56}, "worcestershire sauce": {"red wine":21, "elbow macaroni":6, "canned tomato sauce":2, "bacon":65, "cayenne pepper":124, "honey":65, "lemon juice":322, "swiss cheese":12, "paprika":248, "camembert cheese":2, "ground cinnamon":8, "bread":11, "yeast":4, "egg yolks":15, "green pepper":103, "baking powder":8, "sesame oil":9, "cinnamon":19, "pine nuts":4, "avocado":8, "cheddar cheese":56, "tomatoes":70, "white pepper":46, "brown rice":2, "pinto beans":4, "fresh garlic":4, "cauliflower":4, "frozen peas":5, "butter":324, "salmon":6, "orange juice":9, "black pepper":183, "lemon":75, "black olives":5, "buttermilk":10, "powdered sugar":3, "hoisin sauce":4, "dried oregano":36, "eggplant":4, "capers":17, "cornmeal":6, "cloves":17, "oil":119, "chicken":22, "blue cheese":12, "cucumber":11, "canola oil":14, "dried tarragon":6, "strawberries":2, "celery":93, "fresh cilantro":3, "nutmeg":11, "walnuts":7, "baking soda":3, "bread crumbs":63, "tabasco sauce":181, "corn syrup":4, "balsamic vinegar":11, "ginger":19, "fresh rosemary":2, "lime":3, "pecans":9, "peanut butter":7, "cumin":35, "frozen corn":8, "green onions":75, "skim milk":21, "barley":5, "kidney beans":9, "shortening":18, "parmesan cheese":56, "applesauce":2, "carrots":85, "mushrooms":82, "sour cream":99, "yogurt":4, "tofu":6, "cream cheese":82, "frozen french fries":2, "cherry tomatoes":6, "salsa":8, "parsley":118, "green olives":6, "rice vinegar":3, "molasses":48, "chili powder":190, "beer":38, "spaghetti":8, "raisins":10, "red wine vinegar":79, "garam masala":2, "chives":9, "cornstarch":50, "orange":4, "dried basil":28, "catsup":199, "ground beef":113, "romaine lettuce":3, "mozzarella cheese":8, "sweet red pepper":3, "canned tuna":2, "cumin seeds":3, "barbecue sauce":12, "red pepper flakes":8, "eggs":121, "almonds":4, "margarine":59, "fresh ginger":2, "garlic powder":192, "dried thyme":39, "cream of mushroom soup":23, "low fat milk":2, "whole wheat flour":2, "salt":1000, "fresh basil":7, "bean sprouts":2, "shiitake mushrooms":2, "potatoes":66, "frozen spinach":2, "celery seeds":5, "allspice":16, "dijon mustard":96, "soy sauce":133, "broccoli":2, "chicken legs":2, "apples":6, "sweet potatoes":4, "yellow mustard":9, "maple syrup":12, "white rice":3, "canned tomato paste":2, "egg whites":7, "brown sugar":272, "lime juice":21, "dry mustard":292, "raw shrimp":2, "white flour":2, "mayonnaise":164, "chicken wings":16, "fresh thyme":4, "olive oil":160, "vegetable oil":130, "flour":237, "curry powder":32, "vinegar":228, "white wine":34, "sherry":26, "whipping cream":26, "chicken breast":4, "sugar":197}, "soy sauce": {"canned beef broth":5, "red wine":18, "bacon":36, "cayenne pepper":65, "honey":315, "lemon juice":268, "swiss cheese":3, "paprika":62, "bread":5, "ground cinnamon":22, "yeast":4, "egg yolks":4, "green pepper":132, "baking powder":13, "saffron":2, "sesame oil":554, "pine nuts":8, "cinnamon":27, "avocado":3, "cheddar cheese":6, "tomatoes":61, "white pepper":70, "brown rice":24, "black beans":9, "fresh garlic":7, "pinto beans":4, "cauliflower":12, "frozen peas":15, "butter":108, "salmon":2, "orange juice":77, "black pepper":173, "lemon":37, "tumeric":6, "buttermilk":2, "powdered sugar":3, "eggplant":16, "hoisin sauce":100, "dried oregano":14, "capers":3, "cornmeal":4, "cloves":16, "oil":896, "chicken":73, "blue cheese":4, "cucumber":33, "canola oil":31, "dried tarragon":7, "celery":144, "alfalfa sprouts":4, "cornish game hens":7, "walnuts":11, "nutmeg":24, "fresh cilantro":29, "baking soda":10, "bread crumbs":24, "tabasco sauce":56, "corn syrup":5, "ginger":308, "balsamic vinegar":33, "lime":11, "pecans":4, "peanut butter":62, "cumin":38, "green onions":336, "canned chicken broth":3, "banana":3, "skim milk":2, "beets":2, "barley":9, "kidney beans":5, "shortening":8, "parmesan cheese":7, "carrots":146, "mushrooms":146, "sour cream":19, "yogurt":5, "brussels sprouts":2, "cream cheese":5, "tofu":53, "cherry tomatoes":19, "salsa":5, "parsley":59, "rice vinegar":107, "molasses":50, "beer":23, "chili powder":58, "spaghetti":13, "raisins":8, "red wine vinegar":87, "chives":8, "garam masala":8, "cornstarch":1167, "orange":13, "dried basil":15, "catsup":90, "radishes":10, "ground beef":44, "adzuki beans":3, "romaine lettuce":5, "sweet red pepper":12, "cumin seeds":2, "barbecue sauce":10, "red pepper flakes":37, "almonds":9, "eggs":171, "margarine":26, "fresh ginger":100, "kale":2, "garlic powder":214, "dried thyme":23, "cream of mushroom soup":10, "whole wheat flour":15, "salt":1292, "fresh basil":9, "bean sprouts":98, "shiitake mushrooms":24, "potatoes":32, "celery seeds":3, "allspice":23, "dijon mustard":64, "broccoli":34, "chicken legs":8, "yellow mustard":3, "white rice":4, "maple syrup":17, "sweet potatoes":6, "egg whites":14, "worcestershire sauce":133, "brown sugar":335, "lime juice":62, "dry mustard":102, "raw shrimp":12, "white flour":2, "mayonnaise":20, "chicken wings":52, "fresh thyme":5, "olive oil":164, "vegetable oil":429, "curry powder":73, "flour":127, "vinegar":270, "white wine":46, "sherry":531, "oats":3, "whipping cream":3, "chicken breast":85, "sugar":1198}, "cheddar cheese": {"canned beef broth":2, "red wine":2, "elbow macaroni":12, "canned tomato sauce":3, "bacon":45, "cayenne pepper":27, "lemon juice":34, "honey":7, "swiss cheese":17, "paprika":53, "ground cinnamon":5, "bread":12, "yeast":14, "egg yolks":12, "green pepper":74, "baking powder":42, "cinnamon":12, "avocado":16, "corn tortilla":5, "tomatoes":62, "white pepper":15, "brown rice":4, "black beans":7, "pinto beans":11, "fresh garlic":3, "cauliflower":8, "butter":207, "frozen peas":7, "salmon":4, "orange juice":2, "black pepper":45, "lemon":2, "tumeric":4, "black olives":19, "buttermilk":13, "dried oregano":14, "eggplant":6, "capers":3, "cornmeal":25, "cloves":3, "oil":32, "chicken":26, "blue cheese":2, "cucumber":3, "flour tortilla":6, "canola oil":4, "celery":46, "alfalfa sprouts":5, "fresh cilantro":10, "nutmeg":18, "walnuts":9, "bread crumbs":27, "baking soda":11, "tabasco sauce":12, "pecans":5, "peanut butter":2, "green onions":65, "frozen corn":5, "cumin":33, "skim milk":7, "beets":2, "barley":3, "kidney beans":17, "shortening":10, "applesauce":2, "parmesan cheese":36, "carrots":17, "mushrooms":45, "sour cream":132, "yogurt":6, "brussels sprouts":2, "tofu":3, "cream cheese":33, "frozen french fries":2, "salsa":24, "parsley":48, "chili powder":88, "beer":7, "spaghetti":10, "raisins":2, "red wine vinegar":2, "chives":12, "cornstarch":10, "dried basil":6, "radishes":2, "catsup":5, "ground beef":97, "romaine lettuce":2, "mozzarella cheese":25, "sweet red pepper":6, "canned tuna":2, "cumin seeds":2, "barbecue sauce":5, "red pepper flakes":2, "almonds":3, "eggs":218, "margarine":57, "kale":2, "garlic powder":43, "dried thyme":4, "cream of mushroom soup":33, "vanilla":2, "whole wheat flour":6, "salt":392, "potatoes":48, "frozen spinach":7, "allspice":8, "dijon mustard":11, "soy sauce":6, "broccoli":21, "apples":7, "sweet potatoes":2, "shell macaroni":3, "egg whites":10, "worcestershire sauce":56, "brown sugar":10, "lime juice":4, "dry mustard":56, "mayonnaise":56, "vegetable oil":42, "olive oil":36, "flour":150, "curry powder":17, "vinegar":8, "white wine":4, "sherry":6, "oats":2, "whipping cream":8, "chicken breast":6, "sugar":67}, "cornish game hens": {"cream cheese":2, "bacon":2, "hoisin sauce":4, "parsley":2, "cayenne pepper":2, "cloves":2, "honey":7, "oil":2, "lemon juice":11, "paprika":4, "allspice":2, "dijon mustard":3, "ground cinnamon":2, "soy sauce":7, "raisins":2, "celery":3, "apples":3, "maple syrup":3, "green pepper":2, "fresh cilantro":2, "walnuts":2, "nutmeg":2, "cornstarch":4, "orange":3, "brown sugar":7, "balsamic vinegar":2, "ginger":2, "cinnamon":3, "lime juice":4, "lime":2, "tomatoes":2, "green onions":4, "vegetable oil":3, "white pepper":2, "barbecue sauce":2, "olive oil":6, "margarine":3, "vinegar":2, "butter":12, "sherry":3, "carrots":2, "orange juice":4, "mushrooms":2, "black pepper":4, "sugar":5, "salt":18, "lemon":2}, "cucumber": {"red wine":2, "elbow macaroni":2, "bacon":5, "cayenne pepper":13, "lemon juice":71, "honey":6, "swiss cheese":2, "paprika":7, "bread":4, "yeast":2, "egg yolks":3, "green pepper":33, "saffron":2, "sesame oil":29, "cinnamon":3, "pine nuts":2, "avocado":9, "cheddar cheese":3, "tomatoes":55, "white pepper":12, "brown rice":3, "black beans":2, "cauliflower":2, "frozen peas":2, "butter":13, "salmon":3, "orange juice":3, "lemon":16, "black pepper":21, "tumeric":5, "black olives":6, "buttermilk":6, "hoisin sauce":2, "dried oregano":9, "capers":7, "cloves":2, "oil":30, "chicken":4, "blue cheese":3, "canola oil":4, "dried tarragon":3, "celery":17, "alfalfa sprouts":6, "fresh peaches":2, "fresh cilantro":9, "nutmeg":4, "baking soda":2, "bread crumbs":4, "tabasco sauce":16, "ginger":6, "balsamic vinegar":5, "lime":10, "peanut butter":5, "green onions":43, "cumin":12, "beets":3, "banana":2, "carrots":27, "mushrooms":8, "sour cream":35, "yogurt":12, "cream cheese":7, "cherry tomatoes":10, "salsa":2, "parsley":30, "green olives":2, "rice vinegar":20, "chili powder":8, "spaghetti":6, "raisins":2, "red wine vinegar":26, "garam masala":2, "chives":7, "cornstarch":11, "dried basil":5, "orange":3, "radishes":22, "catsup":2, "ground beef":3, "mozzarella cheese":2, "romaine lettuce":5, "sweet red pepper":4, "barbecue sauce":2, "red pepper flakes":5, "eggs":11, "margarine":2, "fresh ginger":6, "garlic powder":10, "dried thyme":2, "cream of mushroom soup":2, "whole wheat flour":4, "salt":223, "fresh basil":2, "bean sprouts":14, "shiitake mushrooms":2, "potatoes":10, "celery seeds":2, "allspice":4, "dijon mustard":12, "soy sauce":33, "apples":2, "maple syrup":3, "sweet potatoes":2, "worcestershire sauce":11, "brown sugar":10, "lime juice":15, "dry mustard":10, "mayonnaise":37, "chicken wings":2, "fresh thyme":2, "vegetable oil":28, "olive oil":85, "flour":4, "curry powder":10, "vinegar":41, "white wine":4, "sherry":5, "whipping cream":2, "chicken breast":2, "sugar":106}, "barbecue sauce": {"sour cream":2, "elbow macaroni":3, "red wine":2, "cherry tomatoes":2, "bacon":6, "salsa":2, "parsley":6, "cayenne pepper":5, "lemon juice":7, "honey":7, "swiss cheese":2, "molasses":3, "chili powder":16, "paprika":10, "bread":2, "ground cinnamon":2, "yeast":4, "green pepper":6, "dried basil":2, "radishes":2, "catsup":3, "ground beef":10, "cinnamon":2, "cheddar cheese":5, "mozzarella cheese":4, "tomatoes":2, "white pepper":2, "red pepper flakes":2, "eggs":3, "black beans":2, "butter":6, "garlic powder":11, "orange juice":3, "lemon":2, "black pepper":8, "salt":32, "potatoes":3, "dried oregano":2, "cornmeal":3, "oil":4, "chicken":3, "cucumber":2, "dijon mustard":4, "soy sauce":10, "celery":2, "cornish game hens":2, "walnuts":2, "egg whites":2, "bread crumbs":2, "baking soda":2, "worcestershire sauce":12, "tabasco sauce":2, "brown sugar":17, "ginger":2, "lime juice":2, "dry mustard":5, "mayonnaise":3, "frozen corn":2, "green onions":4, "cumin":3, "chicken wings":4, "vegetable oil":6, "olive oil":6, "barley":2, "flour":8, "kidney beans":4, "shortening":2, "vinegar":5, "white wine":2, "carrots":4, "sherry":2, "mushrooms":3, "sugar":10}, "yogurt": {"red wine":2, "cayenne pepper":13, "lemon juice":43, "honey":18, "swiss cheese":2, "paprika":18, "ground cinnamon":4, "yeast":11, "egg yolks":6, "green pepper":3, "baking powder":32, "saffron":7, "sesame oil":2, "cream of tartar":2, "pine nuts":5, "cinnamon":18, "avocado":2, "cheddar cheese":6, "tomatoes":15, "white pepper":5, "cauliflower":2, "butter":38, "orange juice":7, "black pepper":10, "lemon":6, "tumeric":6, "black olives":2, "buttermilk":2, "powdered sugar":3, "dried oregano":5, "eggplant":5, "capers":2, "cornmeal":3, "cloves":19, "oil":32, "chicken":14, "blue cheese":3, "cucumber":12, "canola oil":2, "flour tortilla":2, "dried tarragon":2, "strawberries":9, "celery":8, "fresh cilantro":2, "nutmeg":9, "walnuts":5, "bread crumbs":2, "baking soda":27, "tabasco sauce":2, "ginger":29, "lime":2, "pecans":6, "peanut butter":2, "cumin":25, "green onions":6, "beets":2, "skim milk":3, "banana":7, "kidney beans":2, "shortening":2, "applesauce":6, "parmesan cheese":5, "carrots":9, "mushrooms":8, "sour cream":10, "tofu":2, "cream cheese":2, "salsa":3, "parsley":20, "molasses":3, "chili powder":14, "beer":2, "raisins":11, "garam masala":22, "chives":3, "cornstarch":10, "orange":2, "radishes":4, "ground beef":2, "cumin seeds":13, "eggs":29, "almonds":12, "margarine":11, "fresh ginger":3, "garlic powder":5, "dried thyme":2, "vanilla":17, "whole wheat flour":7, "salt":150, "potatoes":12, "almond extract":2, "frozen spinach":2, "allspice":4, "dijon mustard":6, "soy sauce":5, "broccoli":4, "apples":9, "yellow mustard":2, "maple syrup":2, "egg whites":6, "worcestershire sauce":4, "brown sugar":5, "lime juice":9, "dry mustard":4, "white flour":4, "blueberries":5, "mayonnaise":15, "vegetable oil":28, "olive oil":25, "curry powder":18, "flour":44, "vinegar":6, "white wine":2, "sherry":3, "oats":4, "whipping cream":2, "chicken breast":6, "sugar":69}, "elbow macaroni": {"sour cream":3, "cream cheese":2, "canned tomato sauce":3, "bacon":6, "parsley":7, "cayenne pepper":8, "lemon juice":4, "honey":2, "swiss cheese":3, "chili powder":14, "paprika":9, "ground cinnamon":2, "bread":2, "red wine vinegar":3, "egg yolks":2, "chives":2, "green pepper":9, "cornstarch":4, "dried basil":6, "catsup":2, "cinnamon":2, "ground beef":12, "cheddar cheese":12, "mozzarella cheese":3, "tomatoes":4, "barbecue sauce":3, "white pepper":7, "eggs":11, "black beans":2, "margarine":5, "butter":17, "frozen peas":2, "garlic powder":4, "dried thyme":2, "cream of mushroom soup":7, "salt":59, "black pepper":9, "fresh basil":2, "black olives":2, "eggplant":2, "dried oregano":2, "capers":2, "oil":4, "chicken":2, "cucumber":2, "celery seeds":2, "dijon mustard":3, "celery":7, "apples":2, "alfalfa sprouts":2, "nutmeg":3, "bread crumbs":5, "worcestershire sauce":6, "tabasco sauce":3, "brown sugar":2, "dry mustard":15, "mayonnaise":4, "frozen corn":4, "cumin":5, "vegetable oil":6, "olive oil":17, "skim milk":8, "curry powder":2, "flour":19, "kidney beans":2, "vinegar":5, "parmesan cheese":11, "carrots":7, "whipping cream":4, "sugar":6, "mushrooms":5}, "raw shrimp": {"sour cream":2, "cream cheese":2, "parsley":5, "lemon juice":5, "swiss cheese":2, "paprika":5, "chili powder":2, "red wine vinegar":2, "green pepper":5, "cornstarch":9, "dried basil":3, "saffron":3, "sesame oil":6, "tomatoes":4, "sweet red pepper":2, "white pepper":2, "red pepper flakes":3, "eggs":5, "fresh ginger":2, "butter":15, "frozen peas":3, "garlic powder":5, "dried thyme":2, "black pepper":3, "salt":28, "lemon":2, "bean sprouts":2, "black olives":2, "dried oregano":2, "eggplant":2, "oil":7, "dijon mustard":3, "dried tarragon":2, "soy sauce":12, "celery":2, "fresh cilantro":2, "worcestershire sauce":2, "tabasco sauce":2, "ginger":2, "lime juice":3, "dry mustard":2, "fresh rosemary":2, "mayonnaise":3, "green onions":13, "fresh thyme":2, "olive oil":11, "vegetable oil":6, "flour":4, "curry powder":2, "white wine":3, "sherry":5, "carrots":2, "whipping cream":2, "chicken breast":2, "sugar":12, "mushrooms":2}, "coconut oil": {"cauliflower":3, "potatoes":4, "dried thyme":2, "carrots":2, "tomatoes":2, "cumin seeds":2, "baking soda":2, "lemon juice":2, "mushrooms":2, "sugar":2, "salt":13}, "frozen peas": {"elbow macaroni":2, "red wine":3, "bacon":8, "cayenne pepper":8, "honey":2, "lemon juice":10, "paprika":13, "ground cinnamon":2, "bread":2, "green pepper":10, "baking powder":4, "saffron":3, "sesame oil":5, "cinnamon":2, "pine nuts":2, "avocado":2, "cheddar cheese":7, "tomatoes":19, "white pepper":2, "brown rice":4, "fresh garlic":2, "cauliflower":2, "butter":25, "orange juice":2, "black pepper":18, "lemon":4, "tumeric":4, "black olives":2, "buttermilk":2, "dried oregano":8, "eggplant":2, "cloves":2, "oil":16, "chicken":6, "cucumber":2, "canola oil":7, "celery":16, "nutmeg":5, "walnuts":2, "fresh cilantro":2, "baking soda":3, "bread crumbs":3, "tabasco sauce":2, "ginger":3, "balsamic vinegar":4, "frozen corn":7, "green onions":16, "cumin":4, "canned chicken broth":3, "skim milk":7, "barley":3, "kidney beans":2, "shortening":5, "parmesan cheese":15, "carrots":45, "mushrooms":18, "sour cream":11, "tofu":4, "cherry tomatoes":3, "parsley":10, "rice vinegar":2, "chili powder":5, "spaghetti":4, "raisins":3, "red wine vinegar":6, "chives":2, "garam masala":4, "cornstarch":15, "dried basil":7, "catsup":2, "radishes":2, "ground beef":3, "sweet red pepper":3, "cumin seeds":3, "red pepper flakes":5, "eggs":16, "margarine":4, "fresh ginger":2, "garlic powder":12, "dried thyme":10, "cream of mushroom soup":6, "whole wheat flour":3, "salt":127, "fresh basil":2, "bean sprouts":3, "shiitake mushrooms":2, "potatoes":34, "frozen spinach":2, "dijon mustard":5, "soy sauce":15, "chicken legs":3, "sweet potatoes":2, "worcestershire sauce":5, "dry mustard":4, "raw shrimp":3, "mayonnaise":10, "chicken wings":2, "olive oil":26, "vegetable oil":23, "flour":22, "curry powder":12, "vinegar":2, "white wine":2, "sherry":3, "whipping cream":6, "chicken breast":2, "sugar":14}, "rice vinegar": {"sour cream":4, "tofu":2, "cherry tomatoes":4, "cayenne pepper":5, "parsley":3, "honey":40, "lemon juice":17, "molasses":3, "paprika":4, "spaghetti":2, "red wine vinegar":4, "garam masala":2, "chives":2, "green pepper":3, "cornstarch":32, "orange":2, "dried basil":3, "radishes":4, "sesame oil":66, "pine nuts":2, "avocado":2, "sweet red pepper":2, "tomatoes":4, "white pepper":11, "brown rice":4, "red pepper flakes":13, "black beans":2, "eggs":10, "fresh ginger":12, "frozen peas":2, "butter":7, "garlic powder":3, "dried thyme":2, "salmon":4, "orange juice":5, "lemon":3, "salt":112, "black pepper":9, "fresh basil":3, "bean sprouts":7, "shiitake mushrooms":4, "buttermilk":2, "dried oregano":3, "hoisin sauce":5, "capers":3, "cloves":3, "oil":14, "chicken":3, "blue cheese":3, "cucumber":20, "canola oil":6, "dried tarragon":2, "dijon mustard":15, "soy sauce":107, "strawberries":2, "celery":8, "broccoli":4, "white rice":2, "maple syrup":2, "alfalfa sprouts":3, "nutmeg":2, "fresh peaches":3, "fresh cilantro":15, "walnuts":2, "egg whites":2, "baking soda":2, "bread crumbs":2, "worcestershire sauce":3, "tabasco sauce":4, "brown sugar":15, "balsamic vinegar":6, "ginger":10, "lime juice":10, "dry mustard":8, "lime":2, "peanut butter":10, "mayonnaise":4, "cumin":3, "green onions":31, "vegetable oil":38, "olive oil":26, "beets":2, "flour":3, "curry powder":4, "vinegar":2, "white wine":3, "sherry":11, "carrots":16, "mushrooms":8, "sugar":121}, "cayenne pepper": {"canned beef broth":3, "elbow macaroni":8, "red wine":9, "bacon":34, "brown onions":3, "lemon juice":137, "honey":52, "swiss cheese":12, "paprika":270, "bread":7, "ground cinnamon":46, "yeast":5, "egg yolks":27, "green pepper":62, "baking powder":20, "saffron":4, "sesame oil":14, "cream of tartar":4, "pine nuts":5, "cinnamon":58, "avocado":6, "cheddar cheese":27, "tomatoes":100, "white pepper":84, "brown rice":5, "black beans":23, "fresh garlic":2, "pinto beans":10, "cauliflower":8, "frozen peas":8, "butter":218, "salmon":3, "orange juice":20, "black pepper":250, "lemon":34, "tumeric":13, "black olives":5, "buttermilk":9, "hoisin sauce":7, "eggplant":15, "dried oregano":69, "capers":9, "cornmeal":15, "cloves":23, "oil":76, "chicken":29, "blue cheese":4, "cucumber":13, "dry rosemary":2, "canola oil":17, "dried tarragon":7, "strawberries":2, "celery":70, "cornish game hens":2, "alfalfa sprouts":2, "fresh peaches":2, "fresh cilantro":19, "nutmeg":56, "walnuts":10, "baking soda":9, "bread crumbs":33, "corn syrup":2, "tabasco sauce":48, "ginger":43, "balsamic vinegar":7, "fresh rosemary":3, "lime":12, "pecans":13, "peanut butter":4, "frozen corn":9, "green onions":75, "cumin":133, "canned chicken broth":2, "banana":4, "skim milk":15, "barley":2, "kidney beans":15, "shortening":5, "applesauce":3, "parmesan cheese":26, "carrots":59, "mushrooms":29, "sour cream":42, "yogurt":13, "brussels sprouts":4, "tofu":6, "cream cheese":20, "cherry tomatoes":3, "salsa":14, "parsley":85, "green olives":2, "rice vinegar":5, "molasses":15, "chili powder":182, "beer":21, "raisins":25, "red wine vinegar":34, "chives":8, "garam masala":27, "cornstarch":33, "dried basil":24, "orange":5, "catsup":21, "ground beef":38, "mozzarella cheese":7, "romaine lettuce":2, "sweet red pepper":6, "cumin seeds":38, "barbecue sauce":5, "red pepper flakes":8, "almonds":4, "eggs":86, "margarine":37, "fresh ginger":20, "garlic powder":167, "dried thyme":69, "cream of mushroom soup":4, "vanilla":2, "whole wheat flour":8, "salt":928, "fresh basil":8, "bean sprouts":5, "shiitake mushrooms":3, "potatoes":25, "frozen spinach":6, "celery seeds":6, "allspice":41, "dijon mustard":33, "soy sauce":65, "broccoli":2, "chicken legs":2, "apples":6, "maple syrup":2, "yellow mustard":6, "white rice":6, "sweet potatoes":5, "egg whites":8, "worcestershire sauce":124, "dried cilantro":2, "brown sugar":72, "lime juice":32, "dry mustard":75, "white flour":4, "mayonnaise":40, "chicken wings":7, "vegetable oil":149, "olive oil":244, "fresh thyme":6, "flour":165, "curry powder":56, "vinegar":52, "white wine":28, "sherry":12, "oats":2, "whipping cream":17, "chicken breast":8, "sugar":136}, "green onions": {"red wine":8, "bacon":45, "brown onions":2, "cayenne pepper":75, "honey":51, "lemon juice":137, "swiss cheese":21, "paprika":54, "camembert cheese":2, "bread":4, "ground cinnamon":14, "egg yolks":9, "green pepper":84, "baking powder":16, "saffron":4, "sesame oil":121, "pine nuts":8, "cinnamon":11, "avocado":17, "cheddar cheese":65, "tomatoes":121, "white pepper":46, "brown rice":13, "black beans":19, "fresh garlic":4, "pinto beans":5, "cauliflower":6, "butter":166, "frozen peas":16, "salmon":4, "orange juice":32, "black pepper":113, "lemon":28, "tumeric":2, "black olives":28, "buttermilk":10, "eggplant":6, "hoisin sauce":26, "dried oregano":28, "capers":9, "cornmeal":3, "cloves":6, "oil":102, "chicken":42, "blue cheese":3, "cucumber":43, "dry rosemary":2, "flour tortilla":3, "canola oil":13, "dried tarragon":9, "strawberries":2, "celery":101, "cornish game hens":4, "alfalfa sprouts":5, "fresh peaches":2, "nutmeg":16, "walnuts":8, "fresh cilantro":43, "baking soda":5, "bread crumbs":18, "tabasco sauce":29, "balsamic vinegar":19, "ginger":40, "fresh rosemary":2, "lime":11, "pecans":8, "peanut butter":12, "frozen corn":3, "cumin":36, "canned chicken broth":5, "banana":2, "skim milk":11, "beets":2, "barley":4, "kidney beans":6, "shortening":4, "parmesan cheese":55, "carrots":77, "mushrooms":109, "sour cream":112, "yogurt":6, "brussels sprouts":3, "cream cheese":53, "tofu":18, "cherry tomatoes":15, "salsa":23, "parsley":148, "green olives":10, "rice vinegar":31, "molasses":4, "beer":4, "chili powder":66, "spaghetti":14, "raisins":10, "red wine vinegar":36, "garam masala":5, "chives":9, "cornstarch":186, "orange":9, "dried basil":27, "catsup":10, "radishes":13, "ground beef":23, "romaine lettuce":4, "mozzarella cheese":13, "adzuki beans":2, "sweet red pepper":25, "cumin seeds":8, "barbecue sauce":4, "raw spinach":2, "red pepper flakes":18, "almonds":9, "eggs":149, "margarine":32, "fresh ginger":34, "garlic powder":62, "dried thyme":26, "cream of mushroom soup":13, "salt":622, "fresh basil":14, "bean sprouts":43, "shiitake mushrooms":9, "potatoes":45, "frozen spinach":11, "celery seeds":2, "allspice":7, "dijon mustard":39, "soy sauce":336, "broccoli":12, "chicken legs":2, "apples":4, "maple syrup":3, "white rice":5, "sweet potatoes":5, "yellow mustard":4, "egg whites":18, "worcestershire sauce":75, "dried cilantro":2, "brown sugar":46, "lime juice":60, "dry mustard":36, "raw shrimp":13, "canned vegetable broth":3, "white flour":4, "mayonnaise":107, "chicken wings":5, "olive oil":215, "vegetable oil":180, "fresh thyme":8, "curry powder":43, "flour":99, "vinegar":50, "white wine":40, "sherry":32, "yam":2, "whipping cream":20, "chicken breast":18, "sugar":253}, "ginger": {"canned beef broth":3, "red wine":4, "bacon":6, "brown onions":2, "cayenne pepper":43, "honey":114, "lemon juice":109, "paprika":57, "ground cinnamon":8, "yeast":30, "egg yolks":9, "green pepper":21, "baking powder":95, "saffron":13, "sesame oil":82, "cream of tartar":9, "pine nuts":4, "cinnamon":394, "tomatoes":40, "white pepper":23, "brown rice":3, "black beans":6, "fresh garlic":3, "cauliflower":11, "frozen peas":3, "butter":134, "salmon":2, "orange juice":47, "black pepper":74, "lemon":27, "tumeric":20, "buttermilk":24, "powdered sugar":7, "hoisin sauce":14, "eggplant":12, "capers":2, "cornmeal":11, "cloves":196, "oil":178, "chicken":36, "cucumber":6, "canola oil":8, "dried tarragon":2, "celery":33, "cornish game hens":2, "fresh peaches":2, "fresh cilantro":8, "nutmeg":196, "walnuts":19, "baking soda":175, "bread crumbs":16, "tabasco sauce":8, "corn syrup":7, "balsamic vinegar":8, "lime":11, "pecans":7, "peanut butter":16, "cumin":68, "green onions":40, "frozen corn":2, "banana":4, "skim milk":12, "barley":2, "kidney beans":2, "shortening":74, "parmesan cheese":4, "applesauce":16, "carrots":52, "mushrooms":35, "sour cream":23, "yogurt":29, "cream cheese":14, "tofu":12, "cherry tomatoes":5, "parsley":25, "green olives":2, "rice vinegar":10, "molasses":162, "chili powder":34, "beer":6, "raisins":76, "red wine vinegar":21, "garam masala":29, "chives":5, "cornstarch":145, "orange":17, "catsup":10, "radishes":4, "ground beef":10, "sweet red pepper":2, "cumin seeds":21, "barbecue sauce":2, "red pepper flakes":11, "eggs":151, "almonds":18, "margarine":37, "kale":3, "garlic powder":63, "vanilla":57, "whole wheat flour":22, "salt":677, "bean sprouts":18, "potatoes":17, "almond extract":3, "frozen spinach":3, "celery seeds":3, "allspice":93, "dijon mustard":5, "soy sauce":308, "broccoli":5, "chicken legs":3, "apples":23, "sweet potatoes":11, "maple syrup":20, "egg whites":28, "worcestershire sauce":19, "dried cilantro":3, "brown sugar":187, "lime juice":26, "dry mustard":50, "raw shrimp":2, "white flour":10, "blueberries":2, "mayonnaise":6, "chicken wings":6, "fresh thyme":2, "olive oil":47, "vegetable oil":110, "flour":217, "curry powder":41, "vinegar":106, "white wine":14, "sherry":48, "oats":6, "whipping cream":10, "chicken breast":21, "sugar":487}, "walnuts": {"red wine":5, "bacon":2, "cayenne pepper":10, "lemon juice":86, "honey":61, "paprika":6, "camembert cheese":2, "bread":3, "ground cinnamon":67, "yeast":13, "egg yolks":8, "green pepper":6, "baking powder":237, "saffron":3, "sesame oil":5, "pine nuts":8, "cinnamon":199, "cream of tartar":13, "cheddar cheese":9, "tomatoes":5, "white pepper":2, "brown rice":2, "frozen peas":2, "butter":282, "salmon":2, "orange juice":29, "black pepper":16, "lemon":12, "buttermilk":28, "powdered sugar":50, "hoisin sauce":2, "eggplant":2, "dried oregano":5, "cornmeal":6, "cloves":35, "oil":70, "chicken":8, "blue cheese":6, "canola oil":11, "strawberries":8, "celery":33, "alfalfa sprouts":2, "cornish game hens":2, "nutmeg":93, "baking soda":238, "bread crumbs":12, "tabasco sauce":2, "corn syrup":11, "balsamic vinegar":7, "ginger":19, "fresh rosemary":3, "pecans":14, "peanut butter":6, "green onions":8, "cumin":10, "skim milk":9, "banana":15, "beets":3, "shortening":50, "parmesan cheese":13, "applesauce":13, "carrots":25, "mushrooms":13, "sour cream":41, "yogurt":5, "brussels sprouts":2, "tofu":6, "cream cheese":49, "parsley":27, "green olives":2, "rice vinegar":2, "molasses":9, "chili powder":4, "beer":4, "spaghetti":3, "raisins":136, "red wine vinegar":4, "chives":5, "garam masala":3, "cornstarch":21, "orange":20, "dried basil":5, "radishes":2, "ground beef":2, "romaine lettuce":2, "mozzarella cheese":4, "barbecue sauce":2, "red pepper flakes":2, "eggs":326, "almonds":18, "margarine":62, "fresh ginger":3, "garlic powder":9, "dried thyme":6, "vanilla":229, "whole wheat flour":39, "salt":521, "fresh basil":2, "potatoes":3, "almond extract":15, "allspice":24, "dijon mustard":13, "soy sauce":11, "broccoli":4, "apples":41, "sweet potatoes":4, "maple syrup":9, "egg whites":36, "worcestershire sauce":7, "brown sugar":149, "lime juice":6, "dry mustard":5, "white flour":5, "blueberries":3, "mayonnaise":21, "fresh thyme":2, "vegetable oil":70, "olive oil":58, "flour":327, "curry powder":6, "vinegar":13, "sherry":6, "oats":7, "whipping cream":16, "sugar":527}, "frozen corn": {"sour cream":4, "elbow macaroni":4, "bacon":2, "salsa":4, "cayenne pepper":9, "parsley":3, "honey":2, "lemon juice":2, "beer":2, "chili powder":17, "paprika":4, "ground cinnamon":2, "garam masala":2, "green pepper":9, "baking powder":4, "cornstarch":3, "dried basil":4, "cinnamon":3, "ground beef":3, "cheddar cheese":5, "mozzarella cheese":2, "tomatoes":9, "sweet red pepper":2, "barbecue sauce":2, "white pepper":2, "red pepper flakes":3, "black beans":6, "eggs":8, "pinto beans":3, "margarine":6, "frozen peas":7, "butter":10, "garlic powder":3, "dried thyme":4, "cream of mushroom soup":2, "whole wheat flour":2, "black pepper":12, "salt":42, "fresh basil":2, "potatoes":10, "eggplant":2, "cornmeal":3, "cloves":2, "oil":3, "chicken":3, "canola oil":3, "dijon mustard":3, "celery":3, "maple syrup":2, "fresh cilantro":3, "egg whites":2, "bread crumbs":4, "worcestershire sauce":8, "tabasco sauce":2, "brown sugar":2, "balsamic vinegar":2, "ginger":2, "lime juice":7, "dry mustard":3, "mayonnaise":2, "green onions":3, "cumin":13, "vegetable oil":9, "olive oil":13, "skim milk":5, "curry powder":3, "barley":2, "flour":7, "vinegar":2, "carrots":12, "whipping cream":4, "chicken breast":2, "mushrooms":3, "sugar":5}, "mozzarella cheese": {"red wine":4, "elbow macaroni":3, "bacon":3, "brown onions":2, "cayenne pepper":7, "lemon juice":11, "honey":4, "swiss cheese":6, "zucchini squash":2, "paprika":11, "bread":2, "yeast":8, "egg yolks":2, "green pepper":31, "baking powder":6, "pine nuts":4, "cheddar cheese":25, "tomatoes":36, "white pepper":9, "brown rice":3, "black beans":2, "pinto beans":2, "fresh garlic":4, "butter":47, "black pepper":41, "lemon":3, "black olives":5, "dried oregano":37, "eggplant":34, "hoisin sauce":2, "capers":6, "cornmeal":5, "cloves":2, "oil":29, "chicken":6, "cucumber":2, "flour tortilla":3, "canola oil":2, "celery":6, "nutmeg":21, "walnuts":4, "fresh cilantro":3, "bread crumbs":21, "baking soda":3, "tabasco sauce":5, "balsamic vinegar":8, "pecans":2, "green onions":13, "cumin":8, "frozen corn":2, "skim milk":7, "shortening":2, "parmesan cheese":170, "carrots":9, "mushrooms":40, "sour cream":17, "tofu":2, "cream cheese":10, "cherry tomatoes":4, "salsa":7, "parsley":40, "green olives":2, "chili powder":3, "spaghetti":12, "red wine vinegar":7, "chives":2, "cornstarch":12, "dried basil":36, "radishes":2, "catsup":2, "ground beef":50, "cumin seeds":2, "barbecue sauce":4, "red pepper flakes":8, "eggs":94, "margarine":18, "garlic powder":36, "dried thyme":6, "cream of mushroom soup":4, "whole wheat flour":4, "salt":209, "fresh basil":18, "shiitake mushrooms":2, "potatoes":4, "frozen spinach":11, "dijon mustard":5, "broccoli":5, "egg whites":12, "worcestershire sauce":8, "dry mustard":3, "mayonnaise":14, "vegetable oil":16, "olive oil":120, "fresh thyme":2, "flour":45, "white wine":7, "sherry":4, "whipping cream":4, "chicken breast":7, "sugar":40}, "zucchini squash": {"potatoes":2, "eggplant":2, "parsley":2, "honey":2, "lemon juice":2, "chicken":2, "paprika":2, "chili powder":2, "dijon mustard":2, "green pepper":3, "egg whites":2, "baking powder":2, "dried basil":2, "pine nuts":2, "cinnamon":2, "mozzarella cheese":2, "cumin seeds":2, "olive oil":3, "skim milk":2, "brown rice":2, "curry powder":2, "eggs":2, "cauliflower":2, "shortening":2, "butter":3, "garlic powder":2, "white wine":2, "parmesan cheese":3, "carrots":2, "whole wheat flour":2, "salt":10, "black pepper":2}, "sweet red onions": {"olive oil":3, "balsamic vinegar":2, "dry mustard":2, "carrots":2}, "spaghetti": {"sour cream":5, "red wine":3, "tofu":2, "canned tomato sauce":4, "bacon":5, "parsley":31, "green olives":3, "honey":3, "rice vinegar":2, "lemon juice":9, "swiss cheese":3, "chili powder":12, "paprika":4, "raisins":3, "red wine vinegar":5, "chives":2, "egg yolks":2, "green pepper":13, "cornstarch":8, "orange":2, "dried basil":8, "radishes":2, "sesame oil":10, "pine nuts":4, "ground beef":17, "cinnamon":6, "cheddar cheese":10, "mozzarella cheese":12, "tomatoes":23, "cumin seeds":3, "white pepper":2, "red pepper flakes":7, "almonds":2, "eggs":22, "margarine":3, "fresh ginger":2, "butter":24, "frozen peas":4, "garlic powder":9, "dried thyme":2, "cream of mushroom soup":3, "orange juice":2, "salt":94, "black pepper":15, "lemon":5, "fresh basil":8, "bean sprouts":3, "black olives":3, "shiitake mushrooms":2, "eggplant":3, "dried oregano":15, "capers":5, "cloves":2, "oil":11, "chicken":10, "cucumber":6, "allspice":4, "soy sauce":13, "celery":16, "broccoli":4, "walnuts":3, "nutmeg":7, "egg whites":3, "bread crumbs":2, "worcestershire sauce":8, "tabasco sauce":2, "brown sugar":2, "balsamic vinegar":2, "lime juice":2, "dry mustard":3, "fresh rosemary":2, "peanut butter":4, "cumin":3, "green onions":14, "fresh thyme":2, "vegetable oil":16, "olive oil":77, "flour":16, "shortening":2, "white wine":7, "parmesan cheese":34, "carrots":7, "sherry":6, "whipping cream":4, "chicken breast":2, "mushrooms":18, "sugar":18}, "sherry": {"red wine":5, "bacon":11, "cayenne pepper":12, "honey":41, "lemon juice":43, "swiss cheese":3, "paprika":50, "bread":3, "egg yolks":28, "green pepper":16, "baking powder":7, "sesame oil":89, "cinnamon":17, "cream of tartar":3, "cheddar cheese":6, "tomatoes":22, "white pepper":22, "brown rice":2, "black beans":3, "fresh garlic":2, "cauliflower":4, "frozen peas":3, "butter":153, "orange juice":17, "black pepper":20, "lemon":11, "black olives":2, "powdered sugar":3, "eggplant":4, "dried oregano":6, "hoisin sauce":26, "capers":2, "cloves":7, "oil":435, "chicken":28, "blue cheese":2, "cucumber":5, "canola oil":4, "dried tarragon":4, "strawberries":6, "celery":43, "cornish game hens":3, "walnuts":6, "nutmeg":20, "bread crumbs":14, "baking soda":5, "tabasco sauce":8, "balsamic vinegar":3, "ginger":48, "lime":2, "pecans":3, "peanut butter":4, "green onions":32, "cumin":5, "beets":2, "skim milk":4, "barley":2, "shortening":3, "applesauce":2, "parmesan cheese":26, "carrots":35, "mushrooms":64, "sour cream":22, "yogurt":3, "tofu":3, "cream cheese":5, "salsa":2, "parsley":27, "green olives":3, "rice vinegar":11, "molasses":2, "chili powder":6, "spaghetti":6, "raisins":8, "red wine vinegar":9, "chives":3, "cornstarch":378, "orange":7, "dried basil":7, "catsup":17, "radishes":3, "ground beef":4, "mozzarella cheese":4, "sweet red pepper":2, "barbecue sauce":2, "red pepper flakes":3, "almonds":8, "eggs":56, "margarine":14, "fresh ginger":17, "garlic powder":20, "kale":2, "dried thyme":10, "cream of mushroom soup":3, "vanilla":5, "whole wheat flour":2, "salt":592, "bean sprouts":22, "shiitake mushrooms":4, "potatoes":7, "allspice":3, "dijon mustard":5, "soy sauce":531, "broccoli":6, "apples":4, "chicken legs":2, "white rice":2, "sweet potatoes":4, "maple syrup":6, "egg whites":19, "worcestershire sauce":26, "brown sugar":42, "lime juice":2, "dry mustard":20, "raw shrimp":5, "mayonnaise":7, "chicken wings":5, "olive oil":35, "fresh thyme":2, "vegetable oil":34, "flour":137, "curry powder":16, "vinegar":50, "white wine":8, "yam":2, "whipping cream":13, "chicken breast":34, "sugar":401}, "tofu": {"canned tomato sauce":3, "cayenne pepper":6, "lemon juice":29, "honey":13, "paprika":6, "bread":2, "green pepper":6, "baking powder":5, "sesame oil":21, "cinnamon":4, "cream of tartar":3, "cheddar cheese":3, "tomatoes":13, "brown rice":6, "pinto beans":2, "cauliflower":4, "frozen peas":4, "butter":6, "orange juice":3, "black pepper":21, "lemon":2, "tumeric":2, "black olives":2, "eggplant":3, "capers":2, "cornmeal":2, "cloves":6, "oil":41, "canola oil":7, "strawberries":2, "celery":11, "nutmeg":2, "walnuts":6, "bread crumbs":12, "baking soda":4, "ginger":12, "balsamic vinegar":3, "pecans":2, "peanut butter":13, "cumin":10, "green onions":18, "skim milk":3, "kidney beans":3, "shortening":2, "parmesan cheese":3, "applesauce":2, "carrots":12, "mushrooms":27, "yogurt":2, "salsa":4, "parsley":11, "rice vinegar":2, "chili powder":14, "spaghetti":2, "raisins":6, "red wine vinegar":2, "garam masala":2, "chives":3, "cornstarch":24, "orange":2, "dried basil":2, "romaine lettuce":2, "mozzarella cheese":2, "sweet red pepper":2, "red pepper flakes":2, "eggs":10, "almonds":2, "margarine":4, "fresh ginger":6, "garlic powder":16, "vanilla":8, "whole wheat flour":3, "salt":57, "fresh basil":2, "bean sprouts":5, "potatoes":3, "almond extract":2, "frozen spinach":2, "allspice":3, "dijon mustard":3, "soy sauce":53, "broccoli":8, "maple syrup":4, "sweet potatoes":2, "egg whites":4, "worcestershire sauce":6, "brown sugar":4, "lime juice":3, "white flour":3, "mayonnaise":3, "vegetable oil":25, "olive oil":21, "curry powder":6, "flour":15, "vinegar":7, "white wine":2, "sherry":3, "oats":2, "sugar":32}, "dried bay leaf": {"olive oil":2, "dried basil":2, "dried oregano":2, "eggplant":2, "whipping cream":2, "salt":2, "mushrooms":2, "black pepper":2}, "bean sprouts": {"sour cream":2, "tofu":5, "bacon":2, "cayenne pepper":5, "lemon juice":7, "rice vinegar":7, "molasses":2, "paprika":11, "chili powder":4, "spaghetti":3, "red wine vinegar":2, "yeast":2, "chives":4, "green pepper":9, "baking powder":2, "cornstarch":56, "dried basil":2, "catsup":2, "sesame oil":28, "radishes":4, "ground beef":9, "avocado":2, "romaine lettuce":2, "tomatoes":4, "sweet red pepper":2, "white pepper":4, "brown rice":4, "raw spinach":2, "red pepper flakes":4, "eggs":30, "margarine":2, "fresh ginger":7, "cauliflower":5, "frozen peas":3, "butter":4, "garlic powder":2, "cream of mushroom soup":3, "orange juice":2, "black pepper":10, "lemon":3, "salt":83, "fresh basil":2, "tumeric":2, "shiitake mushrooms":4, "potatoes":5, "hoisin sauce":8, "oil":71, "chicken":10, "cucumber":14, "soy sauce":98, "celery":21, "broccoli":3, "white rice":2, "alfalfa sprouts":2, "fresh cilantro":2, "nutmeg":2, "egg whites":3, "baking soda":2, "worcestershire sauce":2, "brown sugar":9, "balsamic vinegar":2, "ginger":18, "lime juice":12, "dry mustard":3, "raw shrimp":2, "lime":6, "mayonnaise":2, "peanut butter":6, "green onions":43, "cumin":2, "olive oil":2, "vegetable oil":37, "flour":5, "curry powder":4, "shortening":2, "vinegar":6, "sherry":22, "carrots":18, "chicken breast":10, "sugar":74, "mushrooms":30}, "ground cinnamon": {"elbow macaroni":2, "red wine":8, "canned tomato sauce":3, "bacon":5, "cayenne pepper":46, "honey":146, "lemon juice":117, "paprika":22, "bread":7, "yeast":9, "egg yolks":30, "green pepper":7, "baking powder":392, "saffron":2, "sesame oil":3, "cinnamon":10, "pine nuts":16, "cream of tartar":11, "cheddar cheese":5, "corn tortilla":6, "tomatoes":23, "white pepper":5, "brown rice":7, "black beans":4, "pinto beans":3, "cauliflower":2, "frozen peas":2, "butter":270, "orange juice":72, "lemon":25, "black pepper":30, "tumeric":2, "black olives":2, "buttermilk":58, "powdered sugar":71, "eggplant":4, "dried oregano":20, "cornmeal":9, "cloves":23, "oil":34, "chicken":16, "canola oil":17, "dried tarragon":2, "strawberries":5, "celery":7, "cornish game hens":2, "walnuts":67, "nutmeg":37, "fresh peaches":4, "fresh cilantro":7, "baking soda":400, "bread crumbs":7, "tabasco sauce":5, "corn syrup":7, "balsamic vinegar":2, "ginger":8, "fresh rosemary":2, "lime":4, "pecans":45, "peanut butter":5, "frozen corn":2, "green onions":14, "cumin":6, "skim milk":69, "banana":10, "beets":4, "barley":2, "kidney beans":2, "shortening":47, "applesauce":33, "carrots":41, "mushrooms":4, "sour cream":46, "yogurt":4, "cream cheese":24, "salsa":2, "parsley":4, "green olives":3, "molasses":77, "beer":5, "chili powder":37, "raisins":223, "red wine vinegar":14, "chives":2, "garam masala":5, "cornstarch":65, "orange":25, "dried basil":3, "catsup":4, "ground beef":9, "cumin seeds":11, "barbecue sauce":2, "red pepper flakes":3, "eggs":428, "almonds":26, "margarine":133, "fresh ginger":10, "garlic powder":15, "dried thyme":19, "low fat milk":3, "vanilla":141, "whole wheat flour":54, "salt":843, "potatoes":10, "almond extract":17, "frozen spinach":2, "canned apricots":3, "celery seeds":2, "allspice":19, "dijon mustard":2, "soy sauce":22, "broccoli":2, "apples":58, "white rice":4, "sweet potatoes":21, "maple syrup":34, "egg whites":87, "worcestershire sauce":8, "brown sugar":209, "lime juice":16, "dry mustard":18, "white flour":2, "blueberries":14, "mayonnaise":5, "chicken wings":3, "fresh thyme":4, "vegetable oil":184, "olive oil":72, "flour":200, "curry powder":20, "vinegar":24, "white wine":5, "oats":7, "whipping cream":36, "sugar":843}, "sesame oil": {"red wine":8, "bacon":3, "cayenne pepper":14, "lemon juice":37, "honey":58, "paprika":6, "ground cinnamon":3, "yeast":2, "egg yolks":4, "green pepper":16, "baking powder":7, "pine nuts":2, "cinnamon":2, "avocado":2, "tomatoes":9, "white pepper":54, "brown rice":4, "black beans":5, "fresh garlic":2, "cauliflower":3, "frozen peas":5, "butter":7, "orange juice":13, "lemon":4, "black pepper":46, "tumeric":3, "hoisin sauce":48, "eggplant":5, "cloves":3, "oil":100, "chicken":15, "blue cheese":2, "cucumber":29, "canola oil":10, "dried tarragon":2, "celery":23, "alfalfa sprouts":3, "walnuts":5, "nutmeg":3, "fresh cilantro":13, "bread crumbs":3, "baking soda":8, "tabasco sauce":10, "ginger":82, "balsamic vinegar":9, "lime":3, "pecans":2, "peanut butter":22, "cumin":9, "green onions":121, "shortening":2, "carrots":49, "mushrooms":35, "sour cream":3, "yogurt":2, "brussels sprouts":2, "tofu":21, "cherry tomatoes":3, "parsley":8, "rice vinegar":66, "molasses":2, "beer":3, "chili powder":14, "spaghetti":10, "red wine vinegar":17, "chives":3, "cornstarch":266, "dried basil":2, "orange":4, "radishes":6, "catsup":5, "ground beef":9, "romaine lettuce":2, "sweet red pepper":9, "cumin seeds":2, "red pepper flakes":15, "almonds":4, "eggs":51, "fresh ginger":47, "kale":2, "garlic powder":11, "dried thyme":2, "whole wheat flour":2, "salt":391, "fresh basil":4, "bean sprouts":28, "shiitake mushrooms":13, "potatoes":2, "dijon mustard":14, "soy sauce":554, "broccoli":18, "chicken legs":3, "white rice":2, "maple syrup":3, "sweet potatoes":2, "egg whites":10, "worcestershire sauce":9, "dried cilantro":2, "brown sugar":42, "lime juice":15, "dry mustard":9, "raw shrimp":6, "mayonnaise":6, "chicken wings":6, "vegetable oil":126, "olive oil":37, "flour":35, "curry powder":11, "vinegar":50, "white wine":15, "sherry":89, "whipping cream":3, "chicken breast":21, "sugar":391}, "cream of tartar": {"sour cream":17, "yogurt":2, "tofu":3, "cream cheese":6, "bacon":2, "cayenne pepper":4, "lemon juice":46, "honey":16, "swiss cheese":3, "molasses":8, "beer":2, "paprika":2, "ground cinnamon":11, "raisins":7, "yeast":4, "chives":2, "egg yolks":74, "green pepper":2, "cornstarch":58, "baking powder":78, "orange":4, "cinnamon":40, "tomatoes":2, "white pepper":3, "eggs":141, "almonds":7, "margarine":26, "fresh ginger":2, "butter":120, "garlic powder":2, "dried thyme":2, "orange juice":15, "vanilla":208, "whole wheat flour":8, "black pepper":3, "lemon":6, "salt":344, "tumeric":3, "potatoes":2, "buttermilk":14, "powdered sugar":49, "almond extract":39, "dried oregano":2, "cornmeal":6, "cloves":2, "oil":17, "celery seeds":2, "allspice":2, "canola oil":6, "strawberries":9, "broccoli":2, "apples":2, "maple syrup":3, "sweet potatoes":3, "nutmeg":20, "walnuts":13, "egg whites":254, "bread crumbs":4, "baking soda":142, "corn syrup":8, "brown sugar":34, "ginger":9, "lime juice":7, "dry mustard":2, "lime":2, "white flour":3, "pecans":9, "blueberries":2, "peanut butter":4, "vegetable oil":20, "banana":5, "skim milk":11, "flour":154, "shortening":46, "vinegar":8, "applesauce":4, "parmesan cheese":3, "white wine":2, "sherry":3, "oats":3, "whipping cream":37, "mushrooms":2, "sugar":479}, "garlic powder": {"canned beef broth":2, "elbow macaroni":4, "red wine":7, "canned tomato sauce":7, "bacon":35, "canned clams":2, "cayenne pepper":167, "lemon juice":171, "honey":48, "zucchini squash":2, "swiss cheese":9, "paprika":365, "bread":5, "ground cinnamon":15, "yeast":19, "egg yolks":5, "green pepper":91, "baking powder":22, "saffron":4, "sesame oil":11, "cream of tartar":2, "pine nuts":3, "cinnamon":26, "avocado":5, "cheddar cheese":43, "tomatoes":77, "white pepper":120, "brown rice":20, "black beans":9, "fresh garlic":3, "pinto beans":13, "cauliflower":7, "butter":144, "frozen peas":12, "salmon":4, "orange juice":19, "lemon":21, "black pepper":273, "tumeric":6, "black olives":11, "buttermilk":15, "hoisin sauce":2, "dried oregano":108, "eggplant":14, "capers":6, "cornmeal":22, "cloves":8, "oil":124, "chicken":42, "blue cheese":4, "cucumber":10, "flour tortilla":2, "canola oil":6, "dried tarragon":10, "celery":62, "alfalfa sprouts":3, "walnuts":9, "nutmeg":26, "fresh cilantro":9, "baking soda":6, "bread crumbs":41, "corn syrup":2, "tabasco sauce":53, "ginger":63, "balsamic vinegar":5, "lime":4, "pecans":4, "peanut butter":8, "frozen corn":3, "green onions":62, "cumin":134, "canned chicken broth":2, "skim milk":22, "beets":3, "barley":8, "kidney beans":18, "shortening":8, "parmesan cheese":107, "applesauce":3, "carrots":58, "mushrooms":55, "sour cream":74, "yogurt":5, "cream cheese":55, "tofu":16, "cherry tomatoes":10, "salsa":14, "parsley":78, "green olives":5, "rice vinegar":3, "molasses":22, "chili powder":262, "beer":16, "spaghetti":9, "raisins":7, "red wine vinegar":43, "garam masala":3, "chives":15, "cornstarch":73, "orange":6, "dried basil":94, "catsup":40, "ground beef":93, "adzuki beans":2, "romaine lettuce":4, "mozzarella cheese":36, "sweet red pepper":4, "cumin seeds":5, "canned peaches":2, "barbecue sauce":11, "red pepper flakes":13, "almonds":7, "eggs":101, "margarine":74, "fresh ginger":6, "dried thyme":69, "cream of mushroom soup":18, "low fat milk":2, "whole wheat flour":28, "salt":935, "fresh basil":8, "bean sprouts":2, "potatoes":45, "frozen spinach":6, "celery seeds":6, "allspice":22, "dijon mustard":33, "soy sauce":214, "broccoli":12, "chicken legs":2, "apples":3, "maple syrup":3, "yellow mustard":3, "shell macaroni":4, "white rice":4, "sweet potatoes":3, "canned tomato paste":2, "egg whites":20, "worcestershire sauce":192, "dried cilantro":3, "brown sugar":113, "lime juice":18, "dry mustard":133, "raw shrimp":5, "white flour":6, "mayonnaise":86, "chicken wings":18, "fresh thyme":2, "vegetable oil":129, "olive oil":159, "flour":164, "curry powder":42, "vinegar":76, "white wine":21, "sherry":20, "oats":5, "whipping cream":4, "chicken breast":9, "sugar":192}, "cornmeal": {"bacon":8, "cayenne pepper":15, "lemon juice":7, "honey":44, "swiss cheese":2, "paprika":19, "bread":2, "ground cinnamon":9, "yeast":52, "egg yolks":11, "green pepper":4, "baking powder":161, "saffron":2, "pine nuts":5, "cinnamon":22, "cream of tartar":6, "avocado":2, "cheddar cheese":25, "tomatoes":5, "white pepper":5, "brown rice":2, "pinto beans":2, "butter":74, "orange juice":3, "lemon":7, "black pepper":28, "black olives":3, "buttermilk":64, "eggplant":3, "dried oregano":14, "cloves":2, "oil":42, "chicken":3, "canola oil":6, "strawberries":2, "celery":5, "fresh cilantro":3, "walnuts":6, "nutmeg":13, "bread crumbs":6, "baking soda":93, "tabasco sauce":2, "ginger":11, "balsamic vinegar":4, "fresh rosemary":3, "pecans":3, "peanut butter":3, "frozen corn":3, "cumin":14, "green onions":3, "banana":2, "skim milk":11, "kidney beans":3, "shortening":32, "applesauce":14, "parmesan cheese":13, "carrots":4, "mushrooms":2, "sour cream":16, "yogurt":3, "cream cheese":4, "tofu":2, "salsa":2, "parsley":10, "molasses":40, "chili powder":35, "beer":4, "raisins":14, "red wine vinegar":2, "chives":2, "cornstarch":8, "dried basil":9, "catsup":2, "ground beef":13, "mozzarella cheese":5, "sweet red pepper":3, "barbecue sauce":3, "red pepper flakes":3, "almonds":2, "eggs":107, "margarine":21, "garlic powder":22, "kale":2, "dried thyme":11, "vanilla":11, "whole wheat flour":57, "salt":438, "fresh basil":3, "shiitake mushrooms":2, "potatoes":2, "almond extract":2, "allspice":4, "dijon mustard":2, "soy sauce":4, "apples":2, "maple syrup":8, "egg whites":28, "worcestershire sauce":6, "brown sugar":21, "dry mustard":10, "white flour":16, "blueberries":4, "mayonnaise":3, "fresh thyme":3, "olive oil":66, "vegetable oil":62, "flour":160, "vinegar":5, "oats":5, "whipping cream":4, "sugar":195}, "fresh thyme": {"sour cream":6, "red wine":3, "cream cheese":2, "cherry tomatoes":2, "bacon":6, "cayenne pepper":6, "parsley":14, "green olives":2, "honey":12, "lemon juice":13, "paprika":2, "chili powder":2, "spaghetti":2, "ground cinnamon":4, "raisins":3, "red wine vinegar":10, "chives":2, "green pepper":2, "cornstarch":3, "baking powder":2, "orange":5, "saffron":2, "radishes":2, "pine nuts":2, "cinnamon":3, "mozzarella cheese":2, "tomatoes":11, "white pepper":4, "brown rice":2, "red pepper flakes":3, "eggs":9, "black beans":2, "margarine":3, "butter":22, "kale":2, "garlic powder":2, "dried thyme":16, "orange juice":3, "whole wheat flour":2, "lemon":6, "salt":81, "black pepper":13, "fresh basil":20, "black olives":2, "shiitake mushrooms":3, "buttermilk":2, "potatoes":8, "dried oregano":3, "capers":3, "cornmeal":3, "cloves":2, "oil":5, "chicken":4, "cucumber":2, "canola oil":5, "allspice":3, "dried tarragon":2, "dijon mustard":10, "soy sauce":5, "celery":8, "sweet potatoes":3, "fresh cilantro":3, "walnuts":2, "nutmeg":6, "worcestershire sauce":4, "brown sugar":4, "ginger":2, "balsamic vinegar":10, "lime juice":3, "dry mustard":3, "fresh rosemary":14, "raw shrimp":2, "pecans":4, "mayonnaise":2, "green onions":8, "cumin":2, "vegetable oil":15, "olive oil":72, "skim milk":2, "barley":3, "flour":6, "curry powder":3, "vinegar":4, "parmesan cheese":9, "white wine":9, "sherry":2, "carrots":14, "whipping cream":4, "mushrooms":10, "sugar":10}, "red leaf lettuce": {"olive oil":2, "vegetable oil":2, "cornstarch":2, "flour":2, "avocado":2, "dried oregano":2, "mayonnaise":2, "salt":2, "sugar":2, "black pepper":2}, "raw spinach": {"sour cream":2, "bean sprouts":2, "potatoes":2, "bacon":2, "tomatoes":2, "parsley":2, "green onions":2, "olive oil":2, "vegetable oil":2, "eggs":4, "flour":3, "paprika":2, "butter":3, "vinegar":2, "parmesan cheese":2, "carrots":2, "green pepper":2, "salt":3}, "brown sugar": {"canned beef broth":2, "elbow macaroni":2, "red wine":25, "canned tomato sauce":4, "bacon":83, "brown onions":2, "cayenne pepper":72, "lemon juice":332, "honey":160, "paprika":115, "bread":10, "ground cinnamon":209, "yeast":100, "egg yolks":61, "green pepper":72, "baking powder":740, "saffron":3, "sesame oil":42, "pine nuts":2, "cinnamon":891, "cream of tartar":34, "cheddar cheese":10, "corn tortilla":2, "tomatoes":55, "white pepper":25, "black beans":4, "fresh garlic":3, "pinto beans":6, "cauliflower":3, "butter":1081, "salmon":2, "orange juice":135, "black pepper":145, "lemon":55, "tumeric":7, "black olives":5, "buttermilk":97, "powdered sugar":69, "hoisin sauce":4, "eggplant":3, "dried oregano":15, "capers":6, "cornmeal":21, "cloves":190, "oil":202, "chicken":21, "cucumber":10, "canola oil":17, "dried tarragon":7, "strawberries":11, "celery":40, "alfalfa sprouts":2, "cornish game hens":7, "fresh cilantro":4, "fresh peaches":8, "nutmeg":371, "walnuts":149, "baking soda":903, "bread crumbs":19, "corn syrup":60, "tabasco sauce":44, "balsamic vinegar":27, "ginger":187, "lime":12, "pecans":151, "peanut butter":123, "frozen corn":2, "green onions":46, "cumin":40, "beets":9, "skim milk":56, "banana":17, "barley":2, "kidney beans":20, "shortening":286, "parmesan cheese":10, "applesauce":91, "carrots":69, "mushrooms":16, "sour cream":84, "yogurt":5, "tofu":4, "cream cheese":76, "cherry tomatoes":5, "salsa":5, "parsley":30, "rice vinegar":15, "molasses":194, "chili powder":142, "beer":43, "spaghetti":2, "raisins":374, "red wine vinegar":76, "chives":2, "garam masala":6, "cornstarch":216, "dried basil":9, "orange":32, "radishes":2, "catsup":159, "ground beef":75, "romaine lettuce":3, "sweet red pepper":4, "cumin seeds":9, "canned peaches":2, "barbecue sauce":17, "red pepper flakes":21, "eggs":845, "almonds":44, "margarine":309, "fresh ginger":25, "garlic powder":113, "dried thyme":22, "cream of mushroom soup":3, "low fat milk":2, "vanilla":926, "whole wheat flour":136, "salt":2255, "fresh basil":6, "bean sprouts":9, "shiitake mushrooms":2, "potatoes":18, "almond extract":50, "celery seeds":8, "allspice":137, "dijon mustard":44, "soy sauce":335, "broccoli":3, "chicken legs":2, "apples":155, "maple syrup":37, "sweet potatoes":47, "yellow mustard":9, "egg whites":109, "worcestershire sauce":272, "dried cilantro":2, "lime juice":46, "dry mustard":231, "white flour":35, "blueberries":13, "mayonnaise":10, "chicken wings":26, "fresh thyme":4, "olive oil":88, "vegetable oil":204, "flour":1252, "curry powder":33, "vinegar":337, "white wine":19, "sherry":42, "oats":81, "whipping cream":34, "chicken breast":8, "sugar":782}, "whipping cream": {"red wine":3, "elbow macaroni":4, "bacon":16, "cayenne pepper":17, "lemon juice":138, "honey":19, "swiss cheese":7, "paprika":17, "camembert cheese":2, "ground cinnamon":36, "bread":4, "dried bay leaf":2, "yeast":3, "egg yolks":186, "green pepper":4, "baking powder":68, "saffron":5, "sesame oil":3, "pine nuts":3, "cinnamon":47, "cream of tartar":37, "cheddar cheese":8, "tomatoes":13, "white pepper":28, "black beans":2, "cauliflower":3, "butter":364, "frozen peas":6, "salmon":4, "orange juice":28, "lemon":29, "black pepper":9, "tumeric":2, "black olives":3, "buttermilk":17, "powdered sugar":89, "dried oregano":5, "eggplant":2, "capers":5, "cornmeal":4, "cloves":10, "oil":25, "chicken":8, "cucumber":2, "dried tarragon":8, "strawberries":43, "celery":14, "fresh cilantro":2, "nutmeg":51, "fresh peaches":4, "walnuts":16, "bread crumbs":6, "baking soda":23, "tabasco sauce":4, "corn syrup":7, "ginger":10, "fresh rosemary":2, "lime":3, "pecans":33, "peanut butter":7, "cumin":2, "green onions":20, "frozen corn":4, "skim milk":2, "banana":7, "shortening":9, "applesauce":4, "parmesan cheese":30, "carrots":12, "mushrooms":24, "sour cream":45, "yogurt":2, "cream cheese":95, "cherry tomatoes":2, "parsley":18, "molasses":3, "chili powder":4, "spaghetti":4, "raisins":21, "red wine vinegar":2, "chives":5, "garam masala":3, "cornstarch":77, "orange":14, "dried basil":7, "radishes":2, "catsup":3, "ground beef":3, "mozzarella cheese":4, "cumin seeds":4, "red pepper flakes":2, "eggs":312, "almonds":25, "margarine":30, "fresh ginger":4, "garlic powder":4, "dried thyme":12, "cream of mushroom soup":3, "vanilla":265, "whole wheat flour":2, "salt":450, "fresh basil":11, "potatoes":14, "almond extract":31, "frozen spinach":2, "celery seeds":2, "allspice":5, "dijon mustard":33, "soy sauce":3, "chicken legs":2, "apples":10, "maple syrup":12, "sweet potatoes":4, "egg whites":92, "worcestershire sauce":26, "brown sugar":34, "lime juice":10, "dry mustard":7, "raw shrimp":2, "white flour":2, "blueberries":3, "mayonnaise":25, "fresh thyme":4, "vegetable oil":31, "olive oil":67, "flour":145, "curry powder":11, "vinegar":6, "white wine":16, "sherry":13, "sugar":750}, "salsa": {"red wine":2, "bacon":4, "cayenne pepper":14, "lemon juice":9, "honey":3, "swiss cheese":2, "paprika":6, "ground cinnamon":2, "yeast":2, "green pepper":19, "baking powder":6, "cinnamon":3, "avocado":8, "cheddar cheese":24, "tomatoes":15, "white pepper":5, "brown rice":4, "black beans":12, "pinto beans":10, "fresh garlic":2, "butter":12, "orange juice":3, "black pepper":9, "black olives":6, "buttermilk":2, "dried oregano":13, "eggplant":4, "cornmeal":2, "cloves":2, "oil":16, "chicken":6, "cucumber":2, "canola oil":7, "flour tortilla":5, "strawberries":2, "celery":2, "alfalfa sprouts":3, "fresh cilantro":14, "baking soda":2, "tabasco sauce":3, "balsamic vinegar":2, "lime":4, "pecans":4, "cumin":22, "green onions":23, "frozen corn":4, "skim milk":5, "kidney beans":5, "shortening":2, "parmesan cheese":3, "carrots":3, "mushrooms":8, "sour cream":61, "yogurt":3, "tofu":4, "cream cheese":10, "green olives":2, "chili powder":50, "beer":2, "raisins":3, "red wine vinegar":3, "chives":3, "cornstarch":8, "orange":2, "dried basil":4, "catsup":4, "radishes":2, "ground beef":16, "mozzarella cheese":7, "sweet red pepper":3, "cumin seeds":2, "barbecue sauce":2, "red pepper flakes":2, "eggs":30, "margarine":3, "garlic powder":14, "dried thyme":2, "salt":65, "shiitake mushrooms":2, "potatoes":6, "frozen spinach":2, "dijon mustard":7, "soy sauce":5, "apples":2, "white rice":2, "egg whites":5, "worcestershire sauce":8, "brown sugar":5, "lime juice":19, "dry mustard":2, "white flour":2, "mayonnaise":6, "olive oil":30, "vegetable oil":26, "flour":5, "vinegar":3, "white wine":2, "sherry":2, "chicken breast":5, "sugar":7}, "paprika": {"canned beef broth":3, "elbow macaroni":9, "red wine":21, "canned tomato sauce":4, "bacon":50, "brown onions":5, "cayenne pepper":270, "lemon juice":283, "honey":52, "zucchini squash":2, "swiss cheese":14, "camembert cheese":3, "ground cinnamon":22, "bread":23, "yeast":7, "egg yolks":27, "green pepper":95, "baking powder":19, "saffron":18, "sesame oil":6, "pine nuts":2, "cream of tartar":2, "cinnamon":64, "avocado":6, "cheddar cheese":53, "tomatoes":143, "white pepper":118, "brown rice":14, "black beans":7, "fresh garlic":2, "pinto beans":10, "cauliflower":6, "frozen peas":13, "butter":414, "salmon":5, "orange juice":28, "lemon":63, "black pepper":328, "tumeric":12, "black olives":8, "buttermilk":14, "powdered sugar":2, "eggplant":17, "dried oregano":66, "capers":20, "cornmeal":19, "cloves":49, "oil":176, "chicken":76, "blue cheese":10, "cucumber":7, "flour tortilla":2, "canola oil":18, "dried tarragon":12, "strawberries":2, "celery":82, "cornish game hens":4, "walnuts":6, "nutmeg":73, "fresh cilantro":9, "baking soda":6, "bread crumbs":57, "tabasco sauce":61, "ginger":57, "balsamic vinegar":4, "fresh rosemary":3, "lime":3, "pecans":15, "peanut butter":4, "frozen corn":4, "cumin":177, "green onions":54, "canned chicken broth":3, "beets":2, "banana":3, "skim milk":27, "barley":4, "kidney beans":14, "shortening":30, "applesauce":2, "parmesan cheese":79, "carrots":81, "mushrooms":87, "sour cream":179, "yogurt":18, "tofu":6, "cream cheese":33, "cherry tomatoes":5, "salsa":6, "parsley":166, "green olives":8, "rice vinegar":4, "molasses":22, "beer":43, "chili powder":281, "spaghetti":4, "raisins":14, "red wine vinegar":49, "garam masala":20, "chives":26, "cornstarch":67, "orange":8, "dried basil":31, "radishes":3, "catsup":60, "ground beef":70, "mozzarella cheese":11, "sweet red pepper":6, "cumin seeds":26, "barbecue sauce":10, "raw spinach":2, "red pepper flakes":18, "eggs":151, "almonds":19, "margarine":83, "fresh ginger":11, "kale":2, "garlic powder":365, "dried thyme":92, "cream of mushroom soup":28, "whole wheat flour":4, "salt":1611, "fresh basil":3, "bean sprouts":11, "potatoes":126, "frozen spinach":3, "allspice":46, "celery seeds":14, "dijon mustard":40, "soy sauce":62, "broccoli":8, "chicken legs":3, "apples":8, "white rice":4, "maple syrup":4, "yellow mustard":2, "sweet potatoes":3, "egg whites":15, "worcestershire sauce":248, "dried cilantro":3, "brown sugar":115, "lime juice":27, "dry mustard":208, "raw shrimp":5, "white flour":2, "mayonnaise":97, "chicken wings":12, "fresh thyme":2, "vegetable oil":193, "olive oil":257, "flour":428, "curry powder":77, "vinegar":145, "white wine":54, "sherry":50, "whipping cream":17, "chicken breast":18, "sugar":255}, "barley": {"red wine":2, "brussels sprouts":2, "bacon":4, "cayenne pepper":2, "parsley":18, "lemon juice":5, "honey":3, "molasses":2, "paprika":4, "ground cinnamon":2, "raisins":5, "green pepper":5, "cornstarch":2, "baking powder":2, "orange":2, "dried basil":7, "catsup":3, "cinnamon":2, "ground beef":3, "cheddar cheese":3, "tomatoes":16, "barbecue sauce":2, "brown rice":9, "black beans":2, "almonds":2, "fresh garlic":2, "pinto beans":2, "butter":8, "frozen peas":3, "garlic powder":8, "dried thyme":4, "orange juice":3, "black pepper":3, "salt":42, "lemon":2, "buttermilk":3, "potatoes":12, "dried oregano":4, "oil":9, "chicken":5, "canola oil":3, "dijon mustard":2, "soy sauce":9, "celery":23, "chicken legs":2, "maple syrup":2, "nutmeg":3, "egg whites":2, "worcestershire sauce":5, "tabasco sauce":2, "brown sugar":2, "balsamic vinegar":3, "ginger":2, "fresh rosemary":2, "lime":2, "cumin":5, "green onions":4, "frozen corn":2, "fresh thyme":3, "vegetable oil":4, "olive oil":10, "skim milk":4, "flour":6, "curry powder":4, "kidney beans":5, "shortening":2, "vinegar":3, "white wine":2, "sherry":2, "carrots":36, "oats":2, "mushrooms":10, "sugar":5}, "romaine lettuce": {"sour cream":2, "tofu":2, "bacon":4, "cayenne pepper":2, "parsley":2, "lemon juice":9, "chili powder":2, "raisins":3, "red wine vinegar":5, "green pepper":2, "cornstarch":3, "dried basil":2, "sesame oil":2, "radishes":2, "avocado":2, "cheddar cheese":2, "tomatoes":3, "cumin seeds":3, "white pepper":2, "fresh garlic":2, "garlic powder":4, "salt":11, "black pepper":4, "lemon":2, "bean sprouts":2, "black olives":3, "eggplant":2, "oil":2, "blue cheese":4, "cucumber":5, "canola oil":2, "dijon mustard":3, "soy sauce":5, "celery":2, "broccoli":2, "alfalfa sprouts":3, "walnuts":2, "nutmeg":2, "bread crumbs":2, "worcestershire sauce":3, "brown sugar":3, "balsamic vinegar":2, "lime juice":2, "mayonnaise":3, "cumin":2, "green onions":4, "vegetable oil":6, "olive oil":14, "parmesan cheese":8, "chicken breast":2, "mushrooms":3, "sugar":6}, "fresh peaches": {"sour cream":4, "cream cheese":2, "buttermilk":2, "powdered sugar":2, "almond extract":3, "cayenne pepper":2, "cloves":2, "lemon juice":8, "honey":3, "rice vinegar":3, "cucumber":2, "molasses":4, "dijon mustard":2, "ground cinnamon":4, "yeast":2, "garam masala":2, "egg yolks":2, "maple syrup":4, "green pepper":2, "nutmeg":13, "baking soda":4, "bread crumbs":2, "baking powder":12, "cornstarch":7, "brown sugar":8, "ginger":2, "cinnamon":13, "lime juice":2, "cumin":3, "green onions":2, "olive oil":3, "skim milk":2, "eggs":9, "flour":12, "margarine":2, "fresh ginger":2, "butter":15, "vanilla":2, "orange juice":5, "whipping cream":4, "whole wheat flour":2, "lemon":2, "sugar":34, "salt":21}, "olive oil": {"elbow macaroni":17, "canned beef broth":6, "red wine":109, "canned tomato sauce":10, "bacon":59, "brown onions":2, "cayenne pepper":244, "honey":210, "lemon juice":803, "zucchini squash":3, "swiss cheese":16, "paprika":257, "bread":25, "ground cinnamon":72, "dried bay leaf":2, "yeast":145, "egg yolks":45, "green pepper":223, "baking powder":38, "saffron":68, "sesame oil":37, "pine nuts":175, "cinnamon":119, "avocado":37, "cheddar cheese":36, "corn tortilla":3, "tomatoes":667, "white pepper":126, "brown rice":27, "black beans":59, "pinto beans":20, "fresh garlic":15, "cauliflower":18, "frozen peas":26, "butter":605, "salmon":7, "orange juice":86, "black pepper":569, "lemon":236, "tumeric":14, "black olives":116, "buttermilk":21, "powdered sugar":3, "hoisin sauce":8, "eggplant":191, "dried oregano":358, "capers":187, "cornmeal":66, "cloves":68, "oil":52, "chicken":96, "blue cheese":13, "cucumber":85, "dry rosemary":4, "flour tortilla":7, "canola oil":13, "dried tarragon":46, "strawberries":4, "celery":123, "alfalfa sprouts":9, "cornish game hens":6, "fresh peaches":3, "walnuts":58, "nutmeg":107, "fresh cilantro":54, "baking soda":17, "bread crumbs":121, "corn syrup":2, "tabasco sauce":72, "ginger":47, "balsamic vinegar":281, "fresh rosemary":67, "lime":38, "pecans":13, "peanut butter":8, "frozen corn":13, "green onions":215, "cumin":257, "canned chicken broth":4, "banana":3, "skim milk":38, "beets":19, "barley":10, "kidney beans":35, "shortening":2, "parmesan cheese":477, "carrots":352, "mushrooms":272, "sour cream":82, "yogurt":25, "brussels sprouts":2, "tofu":21, "cream cheese":20, "cherry tomatoes":66, "salsa":30, "parsley":532, "green olives":47, "rice vinegar":26, "molasses":31, "chili powder":232, "beer":33, "spaghetti":77, "raisins":74, "red wine vinegar":390, "garam masala":4, "chives":58, "cornstarch":95, "orange":35, "dried basil":239, "catsup":11, "radishes":13, "ground beef":57, "romaine lettuce":14, "mozzarella cheese":120, "sweet red pepper":53, "canned tuna":2, "sweet red onions":3, "cumin seeds":42, "barbecue sauce":6, "raw spinach":2, "red pepper flakes":124, "almonds":19, "eggs":322, "margarine":52, "fresh ginger":22, "kale":15, "garlic powder":159, "dried thyme":234, "cream of mushroom soup":3, "low fat milk":2, "whole wheat flour":58, "salt":3604, "fresh basil":199, "bean sprouts":2, "shiitake mushrooms":21, "potatoes":190, "frozen spinach":13, "canned apricots":2, "celery seeds":11, "allspice":46, "dijon mustard":281, "soy sauce":164, "broccoli":45, "apples":13, "chicken legs":9, "yellow mustard":5, "maple syrup":14, "white rice":18, "sweet potatoes":27, "red leaf lettuce":2, "egg whites":44, "worcestershire sauce":160, "dried cilantro":2, "brown sugar":88, "lime juice":148, "dry mustard":108, "raw shrimp":11, "canned vegetable broth":4, "white flour":17, "blueberries":2, "mayonnaise":52, "chicken wings":5, "vegetable oil":99, "fresh thyme":72, "flour":455, "curry powder":92, "vinegar":149, "white wine":239, "sherry":35, "yam":2, "oats":4, "whipping cream":67, "chicken breast":35, "sugar":673}, "allspice": {"red wine":9, "canned tomato sauce":2, "bacon":5, "cayenne pepper":41, "honey":54, "lemon juice":42, "paprika":46, "bread":7, "ground cinnamon":19, "yeast":13, "egg yolks":11, "green pepper":15, "baking powder":124, "saffron":2, "cream of tartar":2, "cinnamon":411, "pine nuts":12, "cheddar cheese":8, "tomatoes":32, "white pepper":12, "brown rice":2, "black beans":4, "butter":98, "orange juice":25, "black pepper":68, "lemon":20, "tumeric":9, "buttermilk":29, "powdered sugar":5, "eggplant":4, "dried oregano":6, "capers":3, "cornmeal":4, "cloves":179, "oil":44, "chicken":13, "cucumber":4, "flour tortilla":2, "canola oil":4, "dried tarragon":2, "strawberries":2, "celery":12, "cornish game hens":2, "walnuts":24, "nutmeg":231, "baking soda":139, "bread crumbs":12, "corn syrup":4, "tabasco sauce":11, "ginger":93, "balsamic vinegar":5, "lime":6, "pecans":23, "peanut butter":4, "green onions":7, "cumin":39, "beets":4, "banana":2, "skim milk":6, "kidney beans":3, "shortening":44, "parmesan cheese":2, "applesauce":29, "carrots":16, "mushrooms":5, "sour cream":7, "yogurt":4, "cream cheese":4, "tofu":3, "cherry tomatoes":2, "parsley":20, "green olives":2, "molasses":51, "chili powder":38, "beer":9, "spaghetti":4, "raisins":103, "red wine vinegar":8, "garam masala":2, "chives":2, "cornstarch":18, "dried basil":4, "orange":9, "catsup":8, "ground beef":23, "sweet red pepper":2, "cumin seeds":2, "red pepper flakes":3, "almonds":22, "eggs":149, "margarine":25, "fresh ginger":3, "kale":2, "garlic powder":22, "dried thyme":15, "cream of mushroom soup":2, "vanilla":73, "whole wheat flour":21, "salt":443, "fresh basil":2, "shiitake mushrooms":2, "potatoes":12, "almond extract":3, "celery seeds":2, "dijon mustard":5, "soy sauce":23, "broccoli":3, "apples":24, "yellow mustard":2, "maple syrup":9, "sweet potatoes":8, "egg whites":13, "worcestershire sauce":16, "dried cilantro":2, "brown sugar":137, "lime juice":7, "dry mustard":22, "white flour":6, "blueberries":3, "mayonnaise":5, "chicken wings":4, "vegetable oil":45, "olive oil":46, "fresh thyme":3, "flour":165, "curry powder":13, "vinegar":64, "white wine":8, "sherry":3, "oats":6, "whipping cream":5, "chicken breast":3, "sugar":264}, "strawberries": {"sour cream":15, "yogurt":9, "red wine":3, "tofu":2, "cream cheese":21, "salsa":2, "cayenne pepper":2, "rice vinegar":2, "lemon juice":71, "honey":30, "paprika":2, "chili powder":2, "ground cinnamon":5, "raisins":3, "yeast":4, "egg yolks":27, "baking powder":41, "cornstarch":39, "orange":13, "pine nuts":3, "cream of tartar":9, "cinnamon":22, "avocado":4, "white pepper":2, "red pepper flakes":2, "eggs":48, "almonds":4, "margarine":13, "butter":52, "vanilla":53, "orange juice":49, "whole wheat flour":2, "black pepper":2, "lemon":12, "salt":78, "buttermilk":8, "powdered sugar":16, "almond extract":6, "cornmeal":2, "cloves":3, "oil":5, "allspice":2, "canola oil":2, "dijon mustard":3, "apples":6, "maple syrup":3, "nutmeg":14, "walnuts":8, "egg whites":29, "baking soda":19, "worcestershire sauce":2, "corn syrup":3, "brown sugar":11, "balsamic vinegar":8, "lime juice":6, "lime":5, "pecans":6, "blueberries":38, "peanut butter":3, "mayonnaise":2, "green onions":2, "olive oil":4, "vegetable oil":9, "skim milk":5, "banana":24, "flour":44, "vinegar":3, "shortening":6, "applesauce":4, "white wine":8, "carrots":2, "sherry":6, "oats":2, "whipping cream":43, "sugar":269}, "red pepper flakes": {"red wine":6, "bacon":7, "cayenne pepper":8, "lemon juice":27, "honey":19, "paprika":18, "ground cinnamon":3, "egg yolks":4, "green pepper":13, "baking powder":2, "saffron":2, "sesame oil":15, "cinnamon":4, "pine nuts":4, "avocado":2, "cheddar cheese":2, "tomatoes":26, "white pepper":6, "brown rice":2, "black beans":6, "pinto beans":3, "cauliflower":3, "butter":19, "frozen peas":5, "salmon":2, "orange juice":5, "lemon":4, "black pepper":35, "tumeric":2, "black olives":4, "hoisin sauce":3, "dried oregano":17, "eggplant":6, "capers":8, "cornmeal":3, "cloves":4, "oil":10, "chicken":4, "cucumber":5, "canola oil":2, "strawberries":2, "celery":11, "walnuts":2, "nutmeg":5, "fresh cilantro":5, "bread crumbs":2, "baking soda":2, "tabasco sauce":11, "ginger":11, "balsamic vinegar":9, "fresh rosemary":2, "lime":5, "peanut butter":2, "cumin":16, "green onions":18, "frozen corn":3, "canned chicken broth":2, "kidney beans":6, "parmesan cheese":16, "carrots":20, "mushrooms":11, "sour cream":6, "tofu":2, "cream cheese":2, "cherry tomatoes":3, "salsa":2, "parsley":25, "rice vinegar":13, "molasses":4, "chili powder":21, "beer":5, "spaghetti":7, "raisins":4, "red wine vinegar":14, "cornstarch":16, "orange":2, "dried basil":20, "catsup":2, "ground beef":7, "mozzarella cheese":8, "sweet red pepper":3, "barbecue sauce":2, "eggs":10, "margarine":3, "fresh ginger":4, "kale":2, "garlic powder":13, "dried thyme":17, "salt":149, "fresh basil":9, "bean sprouts":4, "shiitake mushrooms":3, "potatoes":4, "allspice":3, "dijon mustard":6, "soy sauce":37, "broccoli":7, "white rice":3, "yellow mustard":3, "maple syrup":5, "egg whites":4, "worcestershire sauce":8, "dried cilantro":2, "brown sugar":21, "lime juice":9, "dry mustard":5, "raw shrimp":3, "mayonnaise":3, "chicken wings":4, "olive oil":124, "fresh thyme":3, "vegetable oil":25, "flour":11, "curry powder":10, "vinegar":11, "white wine":8, "sherry":3, "whipping cream":2, "chicken breast":2, "sugar":45}, "corn tortilla": {"sour cream":4, "brown sugar":2, "ground beef":2, "lime juice":2, "avocado":2, "cheddar cheese":5, "lime":3, "tomatoes":2, "cumin":2, "oil":4, "chicken":2, "vegetable oil":3, "olive oil":3, "swiss cheese":2, "flour":2, "eggs":2, "chili powder":2, "almonds":2, "ground cinnamon":6, "raisins":3, "salt":8}, "broccoli": {"red wine":2, "bacon":8, "cayenne pepper":2, "lemon juice":16, "honey":8, "swiss cheese":5, "paprika":8, "ground cinnamon":2, "egg yolks":2, "green pepper":10, "baking powder":3, "sesame oil":18, "pine nuts":4, "cream of tartar":2, "cinnamon":2, "avocado":2, "cheddar cheese":21, "tomatoes":14, "white pepper":8, "brown rice":5, "cauliflower":30, "butter":40, "salmon":2, "orange juice":5, "black pepper":13, "lemon":4, "black olives":2, "hoisin sauce":2, "dried oregano":7, "eggplant":2, "capers":2, "oil":29, "chicken":11, "blue cheese":2, "canola oil":3, "celery":20, "alfalfa sprouts":2, "nutmeg":9, "walnuts":4, "bread crumbs":3, "ginger":5, "balsamic vinegar":2, "pecans":4, "green onions":12, "cumin":3, "skim milk":8, "banana":2, "parmesan cheese":20, "carrots":48, "mushrooms":33, "sour cream":4, "yogurt":4, "brussels sprouts":2, "tofu":8, "cream cheese":3, "cherry tomatoes":4, "parsley":12, "green olives":3, "rice vinegar":4, "beer":3, "chili powder":3, "spaghetti":4, "raisins":3, "red wine vinegar":8, "garam masala":2, "chives":4, "cornstarch":35, "dried basil":5, "radishes":2, "romaine lettuce":2, "mozzarella cheese":5, "sweet red pepper":3, "red pepper flakes":7, "eggs":20, "margarine":10, "fresh ginger":3, "garlic powder":12, "dried thyme":4, "cream of mushroom soup":4, "salt":111, "fresh basil":4, "bean sprouts":3, "potatoes":10, "frozen spinach":2, "allspice":3, "dijon mustard":7, "soy sauce":34, "sweet potatoes":3, "worcestershire sauce":2, "brown sugar":3, "lime juice":2, "dry mustard":7, "mayonnaise":14, "olive oil":45, "vegetable oil":29, "flour":35, "curry powder":9, "vinegar":10, "white wine":4, "sherry":6, "chicken breast":3, "sugar":30}, "low fat milk": {"cream cheese":2, "buttermilk":2, "canned tomato sauce":2, "almond extract":2, "parsley":2, "oil":2, "lemon juice":2, "honey":2, "ground cinnamon":3, "raisins":4, "celery":2, "nutmeg":2, "baking soda":3, "baking powder":2, "worcestershire sauce":2, "cornstarch":2, "tabasco sauce":2, "catsup":2, "brown sugar":2, "cinnamon":4, "lime juice":2, "olive oil":2, "white pepper":2, "vegetable oil":3, "eggs":8, "flour":7, "curry powder":2, "margarine":7, "butter":4, "garlic powder":2, "dried thyme":2, "parmesan cheese":3, "orange juice":2, "whole wheat flour":2, "sugar":3, "salt":10}, "powdered sugar": {"sour cream":52, "yogurt":3, "cream cheese":153, "bacon":2, "honey":17, "lemon juice":92, "molasses":14, "paprika":2, "bread":5, "ground cinnamon":71, "raisins":40, "yeast":15, "egg yolks":74, "baking powder":219, "cornstarch":47, "orange":6, "catsup":2, "cream of tartar":49, "cinnamon":126, "pine nuts":4, "white pepper":2, "almonds":49, "eggs":365, "margarine":138, "butter":421, "salmon":2, "orange juice":39, "vanilla":430, "whole wheat flour":5, "lemon":14, "salt":468, "black pepper":4, "potatoes":2, "buttermilk":21, "almond extract":61, "cloves":13, "oil":36, "canola oil":3, "allspice":5, "dijon mustard":2, "soy sauce":3, "strawberries":16, "apples":17, "maple syrup":13, "fresh peaches":2, "nutmeg":42, "walnuts":50, "egg whites":124, "baking soda":149, "worcestershire sauce":3, "corn syrup":4, "brown sugar":69, "ginger":7, "lime juice":7, "lime":3, "white flour":2, "pecans":55, "blueberries":7, "mayonnaise":7, "peanut butter":53, "cumin":2, "olive oil":3, "vegetable oil":49, "beets":3, "skim milk":27, "banana":7, "flour":341, "shortening":53, "vinegar":5, "white wine":8, "applesauce":12, "sherry":3, "carrots":14, "oats":12, "whipping cream":89, "chicken breast":2, "sugar":496}, "dijon mustard": {"elbow macaroni":3, "red wine":7, "bacon":21, "cayenne pepper":33, "lemon juice":150, "honey":149, "zucchini squash":2, "swiss cheese":12, "paprika":40, "bread":3, "ground cinnamon":2, "yeast":6, "egg yolks":19, "green pepper":17, "baking powder":3, "sesame oil":14, "cinnamon":7, "pine nuts":7, "avocado":3, "cheddar cheese":11, "tomatoes":23, "white pepper":28, "brown rice":2, "fresh garlic":2, "pinto beans":2, "cauliflower":4, "frozen peas":5, "butter":131, "orange juice":26, "black pepper":76, "lemon":21, "black olives":3, "buttermilk":10, "powdered sugar":2, "eggplant":2, "dried oregano":25, "hoisin sauce":4, "capers":24, "cornmeal":2, "cloves":4, "oil":33, "chicken":14, "blue cheese":5, "cucumber":12, "dry rosemary":3, "canola oil":11, "dried tarragon":33, "strawberries":3, "celery":23, "cornish game hens":3, "alfalfa sprouts":6, "fresh peaches":2, "fresh cilantro":2, "walnuts":13, "nutmeg":16, "bread crumbs":19, "tabasco sauce":20, "corn syrup":3, "ginger":5, "balsamic vinegar":56, "fresh rosemary":8, "lime":3, "pecans":4, "frozen corn":3, "green onions":39, "cumin":13, "skim milk":8, "beets":5, "barley":2, "parmesan cheese":24, "carrots":34, "mushrooms":27, "sour cream":50, "yogurt":6, "brussels sprouts":4, "cream cheese":16, "tofu":3, "cherry tomatoes":7, "salsa":7, "parsley":50, "green olives":2, "rice vinegar":15, "molasses":19, "chili powder":22, "beer":12, "raisins":7, "red wine vinegar":100, "garam masala":2, "chives":17, "cornstarch":34, "dried basil":24, "radishes":4, "catsup":6, "ground beef":6, "romaine lettuce":3, "mozzarella cheese":5, "sweet red pepper":10, "cumin seeds":2, "barbecue sauce":4, "red pepper flakes":6, "almonds":3, "eggs":56, "margarine":16, "fresh ginger":4, "kale":3, "garlic powder":33, "dried thyme":41, "cream of mushroom soup":2, "whole wheat flour":5, "salt":346, "fresh basil":17, "shiitake mushrooms":2, "potatoes":8, "canned apricots":2, "celery seeds":4, "allspice":5, "soy sauce":64, "broccoli":7, "apples":6, "yellow mustard":3, "sweet potatoes":4, "maple syrup":15, "egg whites":5, "worcestershire sauce":96, "brown sugar":44, "lime juice":22, "dry mustard":28, "raw shrimp":3, "white flour":2, "mayonnaise":98, "chicken wings":5, "olive oil":281, "vegetable oil":114, "fresh thyme":10, "curry powder":21, "flour":61, "vinegar":26, "white wine":22, "sherry":5, "yam":2, "whipping cream":33, "chicken breast":6, "sugar":83}, "parsley": {"elbow macaroni":7, "red wine":32, "canned beef broth":2, "canned tomato sauce":2, "bacon":75, "cayenne pepper":85, "lemon juice":300, "honey":27, "zucchini squash":2, "swiss cheese":22, "paprika":166, "ground cinnamon":4, "bread":29, "yeast":18, "egg yolks":35, "green pepper":104, "baking powder":21, "saffron":18, "sesame oil":8, "pine nuts":30, "cinnamon":36, "avocado":6, "cheddar cheese":48, "tomatoes":245, "white pepper":52, "brown rice":21, "black beans":9, "fresh garlic":2, "pinto beans":6, "cauliflower":9, "frozen peas":10, "butter":586, "salmon":14, "orange juice":13, "black pepper":207, "lemon":94, "tumeric":3, "black olives":26, "buttermilk":11, "hoisin sauce":2, "dried oregano":28, "eggplant":34, "capers":50, "cornmeal":10, "cloves":31, "oil":213, "chicken":70, "blue cheese":9, "cucumber":30, "flour tortilla":2, "canola oil":9, "dried tarragon":7, "celery":251, "cornish game hens":2, "alfalfa sprouts":4, "fresh cilantro":9, "walnuts":27, "nutmeg":52, "baking soda":4, "bread crumbs":145, "tabasco sauce":41, "corn syrup":3, "balsamic vinegar":24, "ginger":25, "fresh rosemary":4, "lime":7, "pecans":14, "peanut butter":4, "frozen corn":3, "green onions":148, "cumin":79, "banana":2, "skim milk":12, "beets":6, "barley":18, "kidney beans":12, "shortening":10, "applesauce":2, "parmesan cheese":182, "carrots":189, "mushrooms":213, "sour cream":82, "yogurt":20, "brussels sprouts":3, "tofu":11, "cream cheese":28, "cherry tomatoes":11, "green olives":23, "rice vinegar":3, "molasses":4, "chili powder":48, "beer":16, "spaghetti":31, "raisins":23, "red wine vinegar":48, "chives":76, "cornstarch":46, "dried basil":34, "orange":10, "catsup":12, "radishes":5, "ground beef":65, "romaine lettuce":2, "adzuki beans":3, "mozzarella cheese":40, "sweet red pepper":7, "cumin seeds":4, "barbecue sauce":6, "raw spinach":2, "red pepper flakes":25, "almonds":19, "eggs":232, "margarine":84, "fresh ginger":6, "kale":3, "garlic powder":78, "dried thyme":38, "cream of mushroom soup":17, "low fat milk":2, "whole wheat flour":7, "salt":1139, "fresh basil":16, "shiitake mushrooms":4, "potatoes":139, "frozen spinach":6, "allspice":20, "dijon mustard":50, "soy sauce":59, "broccoli":12, "apples":10, "shell macaroni":3, "yellow mustard":2, "white rice":6, "sweet potatoes":8, "maple syrup":2, "egg whites":14, "worcestershire sauce":118, "brown sugar":30, "lime juice":17, "dry mustard":49, "raw shrimp":5, "white flour":3, "mayonnaise":72, "chicken wings":4, "fresh thyme":14, "vegetable oil":117, "olive oil":532, "curry powder":39, "flour":362, "vinegar":68, "white wine":99, "sherry":27, "oats":7, "whipping cream":18, "chicken breast":5, "sugar":163}, "orange juice": {"red wine":8, "bacon":7, "cayenne pepper":20, "lemon juice":275, "honey":164, "paprika":28, "ground cinnamon":72, "bread":7, "yeast":12, "egg yolks":29, "green pepper":10, "baking powder":211, "sesame oil":13, "cinnamon":178, "cream of tartar":15, "pine nuts":3, "avocado":2, "cheddar cheese":2, "tomatoes":14, "white pepper":9, "brown rice":2, "black beans":3, "fresh garlic":2, "frozen peas":2, "butter":222, "black pepper":29, "lemon":27, "buttermilk":16, "powdered sugar":39, "hoisin sauce":7, "dried oregano":8, "capers":4, "cornmeal":3, "cloves":30, "oil":52, "chicken":15, "blue cheese":2, "cucumber":3, "canola oil":20, "dried tarragon":3, "strawberries":49, "celery":16, "cornish game hens":4, "alfalfa sprouts":2, "fresh cilantro":7, "walnuts":29, "nutmeg":69, "fresh peaches":5, "baking soda":137, "bread crumbs":6, "tabasco sauce":7, "corn syrup":7, "balsamic vinegar":14, "ginger":47, "fresh rosemary":7, "lime":9, "pecans":23, "peanut butter":6, "green onions":32, "cumin":13, "skim milk":19, "banana":35, "beets":4, "barley":3, "shortening":27, "applesauce":9, "carrots":54, "mushrooms":7, "sour cream":22, "yogurt":7, "tofu":3, "cream cheese":29, "salsa":3, "parsley":13, "green olives":3, "rice vinegar":5, "molasses":29, "beer":2, "chili powder":15, "spaghetti":2, "raisins":105, "red wine vinegar":18, "chives":3, "cornstarch":140, "dried basil":7, "orange":64, "catsup":5, "radishes":3, "ground beef":2, "sweet red pepper":3, "cumin seeds":4, "barbecue sauce":3, "red pepper flakes":5, "almonds":10, "eggs":197, "margarine":64, "fresh ginger":7, "garlic powder":19, "dried thyme":15, "cream of mushroom soup":2, "low fat milk":2, "vanilla":97, "whole wheat flour":30, "salt":548, "fresh basil":2, "bean sprouts":2, "potatoes":10, "almond extract":21, "allspice":25, "dijon mustard":26, "soy sauce":77, "broccoli":5, "chicken legs":2, "apples":33, "yellow mustard":3, "sweet potatoes":28, "maple syrup":18, "egg whites":59, "worcestershire sauce":9, "brown sugar":135, "lime juice":48, "dry mustard":19, "white flour":3, "blueberries":20, "mayonnaise":9, "chicken wings":4, "fresh thyme":3, "olive oil":86, "vegetable oil":90, "curry powder":28, "flour":199, "vinegar":32, "white wine":19, "sherry":17, "oats":3, "whipping cream":28, "chicken breast":6, "sugar":633}, "eggs": {"elbow macaroni":11, "red wine":14, "canned tomato sauce":2, "bacon":157, "brown onions":2, "cayenne pepper":86, "lemon juice":525, "honey":271, "zucchini squash":2, "swiss cheese":84, "paprika":151, "camembert cheese":2, "ground cinnamon":428, "bread":85, "yeast":166, "egg yolks":148, "green pepper":97, "baking powder":2558, "saffron":8, "sesame oil":51, "pine nuts":33, "cream of tartar":141, "cinnamon":1239, "avocado":10, "cheddar cheese":218, "corn tortilla":2, "tomatoes":126, "white pepper":97, "brown rice":12, "black beans":5, "fresh garlic":3, "cauliflower":12, "frozen peas":16, "butter":2909, "salmon":20, "orange juice":197, "black pepper":176, "lemon":138, "tumeric":2, "black olives":22, "buttermilk":430, "powdered sugar":365, "hoisin sauce":7, "eggplant":38, "dried oregano":51, "capers":14, "cornmeal":107, "cloves":202, "oil":748, "chicken":46, "blue cheese":4, "cucumber":11, "flour tortilla":7, "canola oil":50, "dried tarragon":13, "strawberries":48, "celery":104, "alfalfa sprouts":5, "fresh cilantro":7, "fresh peaches":9, "walnuts":326, "nutmeg":697, "baking soda":1900, "bread crumbs":192, "tabasco sauce":41, "corn syrup":49, "balsamic vinegar":7, "ginger":151, "fresh rosemary":5, "lime":3, "pecans":304, "peanut butter":110, "frozen corn":8, "cumin":26, "green onions":149, "canned chicken broth":2, "beets":13, "banana":18, "skim milk":90, "shortening":538, "parmesan cheese":209, "applesauce":81, "carrots":119, "mushrooms":113, "sour cream":564, "yogurt":29, "tofu":10, "cream cheese":454, "cherry tomatoes":7, "salsa":30, "parsley":232, "green olives":10, "rice vinegar":10, "molasses":125, "chili powder":48, "beer":24, "spaghetti":22, "raisins":559, "red wine vinegar":14, "garam masala":4, "chives":40, "cornstarch":359, "orange":65, "dried basil":50, "radishes":2, "catsup":26, "ground beef":169, "mozzarella cheese":94, "sweet red pepper":11, "canned tuna":2, "cumin seeds":5, "barbecue sauce":3, "raw spinach":4, "red pepper flakes":10, "almonds":132, "margarine":474, "fresh ginger":5, "kale":3, "garlic powder":101, "dried thyme":44, "cream of mushroom soup":38, "low fat milk":8, "vanilla":2594, "whole wheat flour":135, "salt":6373, "fresh basil":17, "bean sprouts":30, "shiitake mushrooms":6, "potatoes":138, "almond extract":230, "frozen spinach":22, "celery seeds":2, "allspice":149, "dijon mustard":56, "soy sauce":171, "broccoli":20, "apples":130, "yellow mustard":6, "sweet potatoes":27, "maple syrup":72, "white rice":8, "egg whites":105, "worcestershire sauce":121, "brown sugar":845, "lime juice":28, "dry mustard":159, "raw shrimp":5, "white flour":33, "blueberries":68, "mayonnaise":145, "chicken wings":7, "fresh thyme":9, "vegetable oil":597, "olive oil":322, "curry powder":33, "flour":3597, "vinegar":114, "white wine":33, "sherry":56, "oats":57, "whipping cream":312, "chicken breast":13, "sugar":5984}, "orange": {"red wine":6, "bacon":3, "cayenne pepper":5, "lemon juice":34, "honey":35, "swiss cheese":2, "paprika":8, "ground cinnamon":25, "bread":2, "yeast":4, "egg yolks":10, "green pepper":5, "baking powder":45, "sesame oil":4, "cream of tartar":4, "cinnamon":44, "pine nuts":5, "avocado":4, "tomatoes":6, "white pepper":5, "brown rice":4, "black beans":3, "butter":60, "orange juice":64, "lemon":85, "black pepper":10, "buttermilk":10, "powdered sugar":6, "dried oregano":3, "capers":3, "cloves":22, "oil":13, "chicken":5, "cucumber":3, "canola oil":4, "strawberries":13, "celery":5, "cornish game hens":3, "alfalfa sprouts":2, "fresh cilantro":4, "walnuts":20, "nutmeg":15, "baking soda":41, "bread crumbs":4, "tabasco sauce":4, "corn syrup":2, "balsamic vinegar":7, "ginger":17, "fresh rosemary":2, "lime":19, "pecans":9, "peanut butter":2, "cumin":6, "green onions":9, "banana":12, "skim milk":5, "barley":2, "shortening":6, "applesauce":2, "parmesan cheese":2, "carrots":18, "mushrooms":3, "sour cream":8, "yogurt":2, "tofu":2, "cream cheese":4, "salsa":2, "parsley":10, "rice vinegar":2, "molasses":9, "spaghetti":2, "raisins":41, "red wine vinegar":5, "chives":4, "cornstarch":26, "catsup":3, "radishes":2, "cumin seeds":2, "red pepper flakes":2, "eggs":65, "almonds":6, "margarine":15, "fresh ginger":2, "garlic powder":6, "dried thyme":5, "vanilla":16, "whole wheat flour":7, "salt":122, "shiitake mushrooms":3, "potatoes":2, "almond extract":7, "allspice":9, "soy sauce":13, "apples":15, "maple syrup":5, "sweet potatoes":6, "egg whites":9, "worcestershire sauce":4, "brown sugar":32, "lime juice":4, "dry mustard":5, "blueberries":6, "mayonnaise":3, "vegetable oil":23, "fresh thyme":5, "olive oil":35, "curry powder":6, "flour":38, "vinegar":10, "white wine":8, "sherry":7, "oats":3, "whipping cream":14, "sugar":208}, "salmon": {"sour cream":9, "cream cheese":9, "bacon":5, "cayenne pepper":3, "parsley":14, "rice vinegar":4, "lemon juice":34, "honey":4, "swiss cheese":4, "paprika":5, "beer":2, "raisins":2, "red wine vinegar":2, "chives":5, "egg yolks":3, "green pepper":5, "cornstarch":2, "cinnamon":2, "cheddar cheese":4, "tomatoes":9, "cumin seeds":2, "white pepper":2, "brown rice":2, "red pepper flakes":2, "black beans":2, "almonds":2, "eggs":20, "margarine":3, "fresh ginger":2, "butter":26, "garlic powder":4, "dried thyme":2, "cream of mushroom soup":5, "salt":40, "lemon":6, "black pepper":4, "powdered sugar":2, "dried oregano":2, "capers":2, "cloves":3, "oil":5, "cucumber":3, "soy sauce":2, "celery":7, "broccoli":2, "apples":2, "walnuts":2, "nutmeg":3, "egg whites":5, "bread crumbs":9, "worcestershire sauce":6, "tabasco sauce":4, "brown sugar":2, "ginger":2, "dry mustard":2, "lime":2, "mayonnaise":9, "cumin":2, "green onions":4, "olive oil":7, "vegetable oil":7, "skim milk":3, "flour":16, "shortening":2, "vinegar":2, "white wine":5, "parmesan cheese":2, "carrots":2, "whipping cream":4, "mushrooms":4, "sugar":8}, "vinegar": {"elbow macaroni":5, "red wine":17, "canned tomato sauce":2, "bacon":97, "cayenne pepper":52, "lemon juice":131, "honey":80, "swiss cheese":2, "paprika":145, "bread":4, "ground cinnamon":24, "yeast":9, "egg yolks":23, "green pepper":123, "baking powder":23, "saffron":7, "sesame oil":50, "pine nuts":2, "cinnamon":116, "cream of tartar":8, "avocado":10, "cheddar cheese":8, "tomatoes":114, "white pepper":33, "brown rice":2, "black beans":8, "pinto beans":7, "cauliflower":12, "frozen peas":2, "butter":165, "salmon":2, "orange juice":32, "lemon":41, "black pepper":121, "tumeric":9, "black olives":10, "buttermilk":14, "powdered sugar":5, "hoisin sauce":4, "dried oregano":16, "eggplant":19, "capers":29, "cornmeal":5, "cloves":105, "oil":311, "chicken":29, "blue cheese":6, "cucumber":41, "canola oil":11, "dried tarragon":4, "strawberries":3, "celery":91, "alfalfa sprouts":2, "cornish game hens":2, "fresh cilantro":2, "nutmeg":31, "walnuts":13, "bread crumbs":13, "baking soda":74, "corn syrup":8, "tabasco sauce":45, "ginger":106, "fresh rosemary":2, "lime":6, "pecans":9, "peanut butter":11, "frozen corn":2, "green onions":50, "cumin":48, "canned chicken broth":2, "banana":2, "skim milk":5, "beets":17, "barley":3, "kidney beans":23, "shortening":42, "parmesan cheese":6, "applesauce":7, "carrots":84, "mushrooms":30, "sour cream":55, "yogurt":6, "tofu":7, "cream cheese":10, "cherry tomatoes":4, "salsa":3, "parsley":68, "green olives":6, "rice vinegar":2, "molasses":65, "chili powder":134, "beer":11, "raisins":53, "red wine vinegar":2, "garam masala":5, "chives":7, "cornstarch":207, "orange":10, "dried basil":7, "radishes":8, "catsup":146, "ground beef":59, "sweet red pepper":9, "cumin seeds":5, "barbecue sauce":5, "raw spinach":2, "red pepper flakes":11, "eggs":114, "almonds":13, "margarine":27, "fresh ginger":7, "kale":2, "garlic powder":76, "dried thyme":7, "vanilla":76, "whole wheat flour":2, "salt":1359, "fresh basil":2, "bean sprouts":6, "potatoes":52, "almond extract":3, "allspice":64, "celery seeds":15, "dijon mustard":26, "soy sauce":270, "broccoli":10, "apples":35, "white rice":2, "yellow mustard":3, "sweet potatoes":6, "maple syrup":6, "egg whites":31, "worcestershire sauce":228, "dried cilantro":2, "brown sugar":337, "lime juice":14, "dry mustard":195, "blueberries":2, "mayonnaise":74, "chicken wings":16, "olive oil":149, "vegetable oil":127, "fresh thyme":4, "flour":208, "curry powder":28, "white wine":14, "sherry":50, "whipping cream":6, "chicken breast":12, "sugar":1030}, "kale": {"sour cream":3, "shiitake mushrooms":2, "potatoes":9, "bacon":3, "dried oregano":2, "cornmeal":2, "parsley":3, "lemon juice":3, "oil":5, "honey":2, "chicken":2, "paprika":2, "allspice":2, "dijon mustard":3, "soy sauce":2, "celery":4, "chives":2, "baking powder":2, "tabasco sauce":2, "sesame oil":2, "balsamic vinegar":2, "ginger":3, "cheddar cheese":2, "tomatoes":2, "cumin":3, "olive oil":15, "fresh thyme":2, "vegetable oil":5, "skim milk":2, "red pepper flakes":2, "curry powder":2, "eggs":3, "pinto beans":2, "vinegar":2, "butter":7, "dried thyme":3, "parmesan cheese":5, "carrots":3, "sherry":2, "sugar":5, "salt":20, "black pepper":4}, "white flour": {"sour cream":6, "yogurt":4, "tofu":3, "cream cheese":3, "salsa":2, "parsley":3, "cayenne pepper":4, "lemon juice":8, "honey":36, "molasses":14, "paprika":2, "chili powder":4, "beer":2, "ground cinnamon":2, "raisins":16, "yeast":51, "egg yolks":2, "chives":2, "baking powder":44, "cornstarch":4, "dried basil":3, "catsup":2, "cinnamon":26, "cream of tartar":3, "tomatoes":3, "cumin seeds":2, "white pepper":2, "eggs":33, "margarine":15, "butter":30, "garlic powder":6, "orange juice":3, "vanilla":18, "whole wheat flour":70, "salt":164, "black pepper":8, "tumeric":2, "black olives":2, "buttermilk":9, "powdered sugar":2, "dried oregano":3, "cornmeal":16, "cloves":7, "oil":20, "chicken":2, "allspice":6, "canola oil":3, "dijon mustard":2, "soy sauce":2, "apples":2, "maple syrup":3, "nutmeg":11, "walnuts":5, "egg whites":4, "baking soda":48, "worcestershire sauce":2, "tabasco sauce":2, "brown sugar":35, "ginger":10, "lime juice":3, "dry mustard":2, "fresh rosemary":2, "blueberries":2, "peanut butter":3, "green onions":4, "olive oil":17, "vegetable oil":21, "skim milk":5, "flour":4, "curry powder":2, "shortening":17, "applesauce":9, "parmesan cheese":4, "carrots":3, "oats":5, "whipping cream":2, "sugar":93}, "cauliflower": {"sour cream":2, "yogurt":2, "cream cheese":3, "tofu":4, "cherry tomatoes":3, "bacon":2, "coconut oil":3, "cayenne pepper":8, "parsley":9, "green olives":3, "honey":2, "lemon juice":15, "zucchini squash":2, "paprika":6, "chili powder":3, "ground cinnamon":2, "bread":2, "raisins":2, "garam masala":10, "chives":3, "egg yolks":2, "green pepper":10, "cornstarch":11, "baking powder":2, "dried basil":3, "catsup":2, "radishes":2, "sesame oil":3, "cinnamon":3, "pine nuts":2, "cheddar cheese":8, "sweet red pepper":4, "tomatoes":23, "cumin seeds":3, "white pepper":5, "brown rice":2, "red pepper flakes":3, "eggs":12, "margarine":2, "fresh ginger":2, "frozen peas":2, "butter":15, "garlic powder":7, "dried thyme":3, "lemon":4, "salt":89, "black pepper":9, "tumeric":4, "fresh basil":2, "bean sprouts":5, "black olives":3, "potatoes":24, "eggplant":5, "capers":4, "cloves":2, "frozen spinach":2, "oil":29, "chicken":3, "cucumber":2, "canola oil":3, "celery seeds":3, "dijon mustard":4, "soy sauce":12, "celery":20, "broccoli":30, "alfalfa sprouts":2, "fresh cilantro":2, "nutmeg":6, "egg whites":2, "bread crumbs":3, "worcestershire sauce":4, "brown sugar":3, "ginger":11, "balsamic vinegar":2, "dry mustard":3, "mayonnaise":4, "cumin":12, "green onions":6, "olive oil":18, "vegetable oil":14, "skim milk":2, "beets":2, "curry powder":4, "flour":14, "kidney beans":2, "vinegar":12, "white wine":2, "parmesan cheese":10, "sherry":4, "carrots":52, "whipping cream":3, "chicken breast":2, "mushrooms":16, "sugar":26}, "flour tortilla": {"fresh basil":2, "sour cream":7, "yogurt":2, "potatoes":3, "buttermilk":2, "bacon":4, "dried oregano":4, "eggplant":2, "salsa":5, "parsley":2, "lemon juice":2, "paprika":2, "allspice":2, "red wine vinegar":2, "green pepper":2, "fresh cilantro":3, "cinnamon":2, "lime juice":2, "cheddar cheese":6, "mozzarella cheese":3, "mayonnaise":2, "peanut butter":2, "green onions":3, "vegetable oil":5, "white pepper":2, "olive oil":7, "flour":2, "eggs":7, "pinto beans":2, "margarine":2, "butter":4, "garlic powder":2, "dried thyme":2, "chicken breast":2, "salt":7}, "applesauce": {"sour cream":5, "yogurt":6, "red wine":3, "tofu":2, "cream cheese":2, "bacon":2, "parsley":2, "cayenne pepper":3, "lemon juice":15, "honey":62, "molasses":21, "chili powder":3, "beer":2, "paprika":2, "ground cinnamon":33, "raisins":71, "yeast":89, "egg yolks":3, "cornstarch":3, "baking powder":167, "orange":2, "dried basil":4, "catsup":4, "cream of tartar":4, "ground beef":4, "cinnamon":170, "cheddar cheese":2, "almonds":4, "eggs":81, "margarine":22, "fresh ginger":2, "butter":40, "garlic powder":3, "vanilla":87, "orange juice":9, "whole wheat flour":56, "lemon":2, "black pepper":3, "salt":280, "potatoes":4, "buttermilk":14, "powdered sugar":12, "eggplant":2, "dried oregano":3, "almond extract":5, "cornmeal":14, "cloves":42, "oil":14, "blue cheese":2, "allspice":29, "canola oil":6, "strawberries":4, "celery":2, "apples":20, "sweet potatoes":3, "maple syrup":10, "nutmeg":66, "walnuts":13, "egg whites":55, "bread crumbs":2, "baking soda":145, "worcestershire sauce":2, "corn syrup":3, "brown sugar":91, "ginger":16, "dry mustard":4, "white flour":9, "pecans":10, "blueberries":5, "peanut butter":5, "cumin":2, "vegetable oil":26, "banana":5, "skim milk":26, "curry powder":4, "flour":124, "vinegar":7, "shortening":18, "parmesan cheese":3, "sherry":2, "carrots":9, "oats":23, "whipping cream":4, "sugar":194}, "corn syrup": {"sour cream":3, "cream cheese":4, "cayenne pepper":2, "parsley":3, "honey":5, "lemon juice":9, "molasses":5, "chili powder":3, "ground cinnamon":7, "raisins":23, "red wine vinegar":2, "yeast":4, "egg yolks":3, "baking powder":26, "cornstarch":13, "orange":2, "cream of tartar":8, "cinnamon":31, "tomatoes":2, "almonds":9, "eggs":49, "margarine":27, "butter":108, "garlic powder":2, "orange juice":7, "vanilla":124, "whole wheat flour":5, "salt":133, "buttermilk":7, "powdered sugar":4, "almond extract":6, "cloves":8, "oil":3, "allspice":4, "dijon mustard":3, "soy sauce":5, "strawberries":3, "apples":7, "maple syrup":2, "sweet potatoes":4, "nutmeg":11, "walnuts":11, "egg whites":35, "baking soda":50, "worcestershire sauce":4, "brown sugar":60, "ginger":7, "dry mustard":2, "pecans":21, "blueberries":4, "peanut butter":13, "cumin":2, "chicken wings":2, "olive oil":2, "vegetable oil":2, "banana":2, "skim milk":9, "curry powder":2, "flour":40, "vinegar":8, "shortening":13, "applesauce":3, "white wine":3, "carrots":2, "oats":3, "whipping cream":7, "sugar":183}, "fresh cilantro": {"red wine":2, "canned beef broth":2, "bacon":5, "cayenne pepper":19, "honey":14, "lemon juice":21, "paprika":9, "ground cinnamon":7, "yeast":2, "green pepper":9, "baking powder":4, "saffron":2, "sesame oil":13, "cinnamon":5, "pine nuts":3, "avocado":11, "cheddar cheese":10, "tomatoes":41, "white pepper":8, "black beans":23, "pinto beans":4, "fresh garlic":2, "cauliflower":2, "butter":13, "frozen peas":2, "orange juice":7, "black pepper":14, "lemon":5, "black olives":4, "buttermilk":3, "hoisin sauce":4, "dried oregano":15, "eggplant":5, "cornmeal":3, "oil":10, "chicken":3, "cucumber":9, "canola oil":8, "flour tortilla":3, "dried tarragon":2, "celery":9, "alfalfa sprouts":2, "cornish game hens":2, "nutmeg":3, "baking soda":2, "bread crumbs":2, "tabasco sauce":7, "ginger":8, "balsamic vinegar":3, "lime":8, "peanut butter":3, "frozen corn":3, "cumin":24, "green onions":43, "skim milk":2, "kidney beans":3, "shortening":2, "parmesan cheese":3, "carrots":14, "mushrooms":3, "sour cream":23, "yogurt":2, "cream cheese":3, "cherry tomatoes":2, "salsa":14, "parsley":9, "green olives":2, "rice vinegar":15, "chili powder":39, "beer":4, "raisins":2, "red wine vinegar":11, "garam masala":3, "cornstarch":5, "orange":4, "radishes":3, "ground beef":6, "mozzarella cheese":3, "sweet red pepper":5, "cumin seeds":7, "red pepper flakes":5, "eggs":7, "margarine":5, "fresh ginger":10, "garlic powder":9, "dried thyme":4, "whole wheat flour":2, "salt":144, "fresh basil":4, "bean sprouts":2, "potatoes":7, "dijon mustard":2, "soy sauce":29, "maple syrup":2, "egg whites":2, "worcestershire sauce":3, "dried cilantro":3, "brown sugar":4, "lime juice":59, "dry mustard":2, "raw shrimp":2, "mayonnaise":8, "fresh thyme":3, "olive oil":54, "vegetable oil":54, "curry powder":6, "flour":5, "vinegar":2, "white wine":5, "whipping cream":2, "chicken breast":3, "sugar":25}, "beer": {"red wine":2, "bacon":14, "cayenne pepper":21, "honey":15, "lemon juice":20, "swiss cheese":2, "paprika":43, "ground cinnamon":5, "bread":3, "yeast":10, "egg yolks":9, "green pepper":5, "baking powder":31, "saffron":3, "sesame oil":3, "cream of tartar":2, "cinnamon":19, "avocado":2, "cheddar cheese":7, "tomatoes":20, "white pepper":5, "black beans":5, "fresh garlic":2, "pinto beans":5, "butter":51, "salmon":2, "orange juice":2, "lemon":10, "black pepper":22, "dried oregano":10, "hoisin sauce":2, "eggplant":2, "capers":2, "cornmeal":4, "cloves":8, "oil":34, "chicken":6, "canola oil":3, "celery":11, "nutmeg":9, "walnuts":4, "fresh cilantro":4, "bread crumbs":2, "baking soda":10, "tabasco sauce":22, "ginger":6, "lime":5, "pecans":3, "peanut butter":3, "green onions":4, "cumin":41, "frozen corn":2, "kidney beans":3, "shortening":5, "parmesan cheese":5, "applesauce":2, "carrots":8, "mushrooms":12, "sour cream":11, "yogurt":2, "brussels sprouts":3, "cream cheese":3, "salsa":2, "parsley":16, "molasses":14, "chili powder":45, "raisins":4, "red wine vinegar":13, "cornstarch":11, "dried basil":2, "catsup":11, "ground beef":9, "sweet red pepper":2, "cumin seeds":3, "red pepper flakes":5, "eggs":24, "margarine":6, "garlic powder":16, "dried thyme":7, "cream of mushroom soup":2, "vanilla":7, "whole wheat flour":5, "salt":166, "fresh basil":2, "potatoes":11, "allspice":9, "dijon mustard":12, "soy sauce":23, "broccoli":3, "apples":4, "yellow mustard":2, "maple syrup":3, "egg whites":3, "worcestershire sauce":38, "brown sugar":43, "lime juice":6, "dry mustard":31, "white flour":2, "mayonnaise":8, "chicken wings":5, "olive oil":33, "vegetable oil":31, "flour":88, "curry powder":2, "vinegar":11, "chicken breast":2, "sugar":68}, "white rice": {"red wine":2, "bacon":2, "salsa":2, "parsley":6, "cayenne pepper":6, "rice vinegar":2, "lemon juice":7, "honey":2, "molasses":2, "paprika":4, "chili powder":5, "ground cinnamon":4, "raisins":5, "egg yolks":2, "chives":2, "green pepper":7, "cornstarch":3, "dried basil":2, "saffron":2, "sesame oil":2, "ground beef":2, "cinnamon":5, "pine nuts":2, "avocado":2, "tomatoes":7, "sweet red pepper":2, "cumin seeds":3, "white pepper":4, "brown rice":3, "red pepper flakes":3, "black beans":5, "eggs":8, "almonds":2, "margarine":2, "butter":16, "garlic powder":4, "dried thyme":5, "cream of mushroom soup":2, "vanilla":2, "black pepper":11, "salt":34, "lemon":3, "fresh basil":2, "bean sprouts":2, "potatoes":2, "dried oregano":6, "capers":2, "oil":5, "chicken":3, "soy sauce":4, "celery":4, "nutmeg":2, "bread crumbs":2, "worcestershire sauce":3, "tabasco sauce":3, "lime juice":3, "green onions":5, "cumin":5, "olive oil":18, "vegetable oil":4, "skim milk":4, "flour":3, "curry powder":5, "vinegar":2, "parmesan cheese":3, "white wine":3, "sherry":2, "chicken breast":2, "mushrooms":5, "sugar":8}, "carrots": {"elbow macaroni":7, "red wine":38, "coconut oil":2, "bacon":43, "cayenne pepper":59, "lemon juice":124, "honey":56, "zucchini squash":2, "swiss cheese":5, "paprika":81, "bread":6, "ground cinnamon":41, "yeast":5, "egg yolks":9, "green pepper":114, "baking powder":70, "saffron":6, "sesame oil":49, "pine nuts":10, "cinnamon":97, "avocado":2, "cheddar cheese":17, "tomatoes":195, "white pepper":39, "brown rice":24, "black beans":16, "fresh garlic":3, "pinto beans":10, "cauliflower":52, "butter":280, "frozen peas":45, "salmon":2, "orange juice":54, "black pepper":150, "lemon":34, "tumeric":5, "black olives":7, "buttermilk":10, "powdered sugar":14, "hoisin sauce":8, "eggplant":18, "dried oregano":43, "capers":8, "cornmeal":4, "cloves":44, "oil":208, "chicken":59, "blue cheese":3, "cucumber":27, "dry rosemary":2, "canola oil":25, "dried tarragon":5, "strawberries":2, "celery":279, "alfalfa sprouts":2, "cornish game hens":2, "fresh cilantro":14, "nutmeg":55, "walnuts":25, "baking soda":55, "bread crumbs":18, "corn syrup":2, "tabasco sauce":17, "balsamic vinegar":17, "ginger":52, "fresh rosemary":7, "lime":4, "pecans":12, "peanut butter":14, "frozen corn":12, "cumin":65, "green onions":77, "canned chicken broth":2, "beets":24, "banana":4, "skim milk":18, "barley":36, "kidney beans":21, "shortening":13, "applesauce":9, "parmesan cheese":40, "mushrooms":139, "sour cream":43, "yogurt":9, "brussels sprouts":3, "cream cheese":17, "tofu":12, "cherry tomatoes":12, "salsa":3, "parsley":189, "green olives":4, "rice vinegar":16, "molasses":8, "beer":8, "chili powder":49, "spaghetti":7, "raisins":61, "red wine vinegar":32, "garam masala":5, "chives":16, "cornstarch":122, "orange":18, "dried basil":55, "radishes":19, "catsup":23, "ground beef":31, "mozzarella cheese":9, "sweet red pepper":15, "sweet red onions":2, "cumin seeds":10, "barbecue sauce":4, "raw spinach":2, "red pepper flakes":20, "almonds":12, "eggs":119, "margarine":71, "fresh ginger":20, "kale":3, "garlic powder":58, "dried thyme":85, "cream of mushroom soup":13, "vanilla":34, "whole wheat flour":21, "salt":1057, "fresh basil":17, "bean sprouts":18, "shiitake mushrooms":8, "potatoes":369, "almond extract":2, "frozen spinach":3, "celery seeds":8, "allspice":16, "dijon mustard":34, "soy sauce":146, "broccoli":48, "chicken legs":6, "apples":24, "yellow mustard":2, "shell macaroni":3, "maple syrup":9, "sweet potatoes":22, "egg whites":17, "worcestershire sauce":85, "dried cilantro":2, "brown sugar":69, "lime juice":17, "dry mustard":36, "raw shrimp":2, "white flour":3, "mayonnaise":32, "chicken wings":3, "fresh thyme":14, "olive oil":352, "vegetable oil":184, "flour":282, "curry powder":59, "vinegar":84, "white wine":39, "sherry":35, "yam":2, "oats":4, "whipping cream":12, "chicken breast":10, "sugar":316}, "almonds": {"red wine":4, "bacon":4, "cayenne pepper":4, "honey":45, "lemon juice":40, "swiss cheese":2, "paprika":19, "ground cinnamon":26, "bread":3, "yeast":20, "egg yolks":28, "green pepper":9, "baking powder":93, "saffron":11, "sesame oil":4, "cinnamon":75, "pine nuts":12, "cream of tartar":7, "avocado":2, "cheddar cheese":3, "corn tortilla":2, "tomatoes":18, "white pepper":4, "brown rice":3, "black beans":2, "pinto beans":4, "butter":187, "salmon":2, "orange juice":10, "lemon":18, "black pepper":13, "buttermilk":5, "powdered sugar":49, "dried oregano":3, "eggplant":2, "capers":2, "cornmeal":2, "cloves":33, "oil":37, "chicken":27, "blue cheese":2, "dry rosemary":2, "canola oil":4, "strawberries":4, "celery":22, "nutmeg":30, "walnuts":18, "baking soda":40, "bread crumbs":6, "corn syrup":9, "ginger":18, "fresh rosemary":2, "pecans":7, "peanut butter":3, "cumin":13, "green onions":9, "skim milk":4, "banana":6, "barley":2, "shortening":10, "applesauce":4, "parmesan cheese":5, "carrots":12, "mushrooms":10, "sour cream":22, "yogurt":12, "tofu":2, "cream cheese":31, "cherry tomatoes":2, "parsley":19, "green olives":3, "molasses":8, "chili powder":5, "spaghetti":2, "raisins":80, "red wine vinegar":2, "garam masala":5, "chives":5, "cornstarch":28, "orange":6, "ground beef":4, "cumin seeds":4, "eggs":132, "margarine":32, "fresh ginger":4, "garlic powder":7, "dried thyme":3, "vanilla":82, "whole wheat flour":6, "salt":240, "potatoes":5, "almond extract":74, "allspice":22, "dijon mustard":3, "soy sauce":9, "apples":14, "maple syrup":6, "sweet potatoes":3, "white rice":2, "egg whites":36, "worcestershire sauce":4, "brown sugar":44, "lime juice":4, "dry mustard":2, "blueberries":2, "mayonnaise":11, "chicken wings":2, "vegetable oil":29, "olive oil":19, "flour":162, "curry powder":10, "vinegar":13, "white wine":6, "sherry":8, "oats":8, "whipping cream":25, "chicken breast":3, "sugar":323}, "chicken legs": {"fresh basil":2, "red wine":2, "dried oregano":3, "cayenne pepper":2, "honey":3, "lemon juice":6, "oil":5, "chili powder":2, "paprika":3, "soy sauce":8, "sweet potatoes":2, "green pepper":2, "nutmeg":3, "egg whites":2, "bread crumbs":2, "cornstarch":7, "worcestershire sauce":2, "dried basil":4, "sesame oil":3, "catsup":2, "brown sugar":2, "cinnamon":2, "ginger":3, "tomatoes":4, "green onions":2, "canned chicken broth":2, "vegetable oil":7, "olive oil":9, "barley":2, "curry powder":2, "flour":3, "margarine":2, "shortening":2, "frozen peas":3, "butter":5, "garlic powder":2, "dried thyme":5, "sherry":2, "carrots":6, "whipping cream":2, "orange juice":2, "salt":20, "mushrooms":4, "sugar":6, "lemon":2, "black pepper":3}, "parmesan cheese": {"elbow macaroni":11, "red wine":15, "canned beef broth":2, "bacon":42, "cayenne pepper":26, "lemon juice":77, "honey":7, "zucchini squash":3, "swiss cheese":32, "paprika":79, "camembert cheese":2, "bread":15, "yeast":30, "egg yolks":25, "green pepper":43, "baking powder":12, "saffron":6, "cinnamon":6, "cream of tartar":3, "pine nuts":43, "avocado":5, "cheddar cheese":36, "tomatoes":85, "white pepper":33, "brown rice":4, "black beans":3, "fresh garlic":4, "cauliflower":10, "frozen peas":15, "butter":376, "salmon":2, "black pepper":102, "lemon":27, "black olives":19, "buttermilk":8, "eggplant":37, "dried oregano":66, "capers":15, "cornmeal":13, "cloves":3, "oil":62, "chicken":28, "blue cheese":3, "canola oil":5, "dried tarragon":3, "celery":34, "fresh cilantro":3, "nutmeg":78, "walnuts":13, "baking soda":5, "bread crumbs":84, "tabasco sauce":16, "ginger":4, "balsamic vinegar":16, "fresh rosemary":8, "pecans":2, "cumin":5, "green onions":55, "banana":2, "skim milk":22, "beets":3, "kidney beans":4, "shortening":6, "applesauce":3, "carrots":40, "mushrooms":112, "sour cream":64, "yogurt":5, "cream cheese":36, "tofu":3, "cherry tomatoes":9, "salsa":3, "parsley":182, "green olives":4, "chili powder":10, "beer":5, "spaghetti":34, "raisins":5, "red wine vinegar":17, "chives":15, "cornstarch":20, "orange":2, "dried basil":77, "catsup":4, "ground beef":72, "adzuki beans":2, "mozzarella cheese":170, "romaine lettuce":8, "sweet red pepper":7, "cumin seeds":2, "raw spinach":2, "red pepper flakes":16, "eggs":209, "almonds":5, "margarine":64, "fresh ginger":3, "kale":5, "garlic powder":107, "dried thyme":22, "cream of mushroom soup":17, "low fat milk":3, "vanilla":2, "whole wheat flour":7, "salt":640, "fresh basil":53, "shiitake mushrooms":6, "potatoes":29, "frozen spinach":13, "allspice":2, "dijon mustard":24, "soy sauce":7, "broccoli":20, "apples":2, "maple syrup":2, "white rice":3, "egg whites":18, "worcestershire sauce":56, "brown sugar":10, "lime juice":5, "dry mustard":28, "white flour":4, "mayonnaise":75, "chicken wings":3, "vegetable oil":45, "olive oil":477, "fresh thyme":9, "curry powder":7, "flour":204, "vinegar":6, "white wine":43, "sherry":26, "oats":2, "whipping cream":30, "chicken breast":12, "sugar":99}, "dried basil": {"elbow macaroni":6, "red wine":12, "canned tomato sauce":2, "bacon":10, "cayenne pepper":24, "lemon juice":54, "honey":12, "zucchini squash":2, "swiss cheese":4, "paprika":31, "ground cinnamon":3, "dried bay leaf":2, "yeast":10, "egg yolks":3, "green pepper":37, "baking powder":10, "saffron":2, "sesame oil":2, "cinnamon":8, "pine nuts":10, "avocado":2, "cheddar cheese":6, "tomatoes":77, "white pepper":15, "brown rice":11, "black beans":6, "fresh garlic":4, "pinto beans":2, "cauliflower":3, "frozen peas":7, "butter":62, "orange juice":7, "lemon":9, "black pepper":69, "black olives":11, "buttermilk":4, "dried oregano":253, "eggplant":16, "capers":14, "cornmeal":9, "cloves":5, "oil":23, "chicken":11, "cucumber":5, "canola oil":4, "dried tarragon":11, "celery":23, "alfalfa sprouts":2, "nutmeg":6, "walnuts":5, "bread crumbs":13, "baking soda":6, "tabasco sauce":9, "balsamic vinegar":22, "fresh rosemary":3, "pecans":3, "green onions":27, "frozen corn":4, "cumin":6, "canned chicken broth":5, "beets":3, "skim milk":11, "barley":7, "kidney beans":8, "shortening":2, "applesauce":4, "parmesan cheese":77, "carrots":55, "mushrooms":37, "sour cream":9, "tofu":2, "cream cheese":6, "cherry tomatoes":10, "salsa":4, "parsley":34, "rice vinegar":3, "molasses":2, "beer":2, "chili powder":22, "spaghetti":8, "raisins":3, "red wine vinegar":32, "chives":2, "cornstarch":22, "catsup":4, "ground beef":29, "mozzarella cheese":36, "romaine lettuce":2, "sweet red pepper":9, "barbecue sauce":2, "red pepper flakes":20, "eggs":50, "margarine":23, "fresh ginger":2, "garlic powder":94, "dried thyme":126, "cream of mushroom soup":3, "whole wheat flour":9, "salt":353, "fresh basil":28, "bean sprouts":2, "shiitake mushrooms":4, "potatoes":20, "frozen spinach":2, "allspice":4, "dijon mustard":24, "soy sauce":15, "broccoli":5, "chicken legs":4, "white rice":2, "yellow mustard":2, "egg whites":11, "worcestershire sauce":28, "brown sugar":9, "lime juice":3, "dry mustard":17, "raw shrimp":3, "white flour":3, "mayonnaise":13, "vegetable oil":46, "olive oil":239, "curry powder":3, "flour":35, "vinegar":7, "white wine":8, "sherry":7, "yam":2, "whipping cream":7, "chicken breast":3, "sugar":80}, "cinnamon": {"elbow macaroni":2, "red wine":13, "canned tomato sauce":2, "bacon":8, "brown onions":2, "cayenne pepper":58, "honey":336, "lemon juice":299, "zucchini squash":2, "swiss cheese":2, "paprika":64, "bread":18, "ground cinnamon":10, "yeast":121, "egg yolks":75, "green pepper":24, "baking powder":1027, "saffron":13, "sesame oil":2, "pine nuts":21, "cream of tartar":40, "avocado":3, "cheddar cheese":12, "tomatoes":70, "white pepper":14, "brown rice":15, "black beans":7, "pinto beans":5, "cauliflower":3, "frozen peas":2, "butter":1064, "salmon":2, "orange juice":178, "black pepper":87, "lemon":59, "tumeric":18, "black olives":3, "buttermilk":121, "powdered sugar":126, "eggplant":12, "dried oregano":11, "capers":10, "cornmeal":22, "cloves":583, "oil":316, "chicken":27, "cucumber":3, "flour tortilla":2, "canola oil":29, "dried tarragon":2, "strawberries":22, "celery":22, "cornish game hens":3, "fresh cilantro":5, "fresh peaches":13, "nutmeg":1126, "walnuts":199, "bread crumbs":27, "baking soda":991, "tabasco sauce":7, "corn syrup":31, "balsamic vinegar":4, "ginger":394, "lime":12, "pecans":131, "peanut butter":20, "frozen corn":3, "cumin":73, "green onions":11, "beets":7, "banana":29, "skim milk":94, "barley":2, "kidney beans":3, "shortening":300, "parmesan cheese":6, "applesauce":170, "carrots":97, "mushrooms":9, "sour cream":123, "yogurt":18, "cream cheese":105, "tofu":4, "cherry tomatoes":2, "salsa":3, "parsley":36, "green olives":6, "molasses":221, "beer":19, "chili powder":62, "spaghetti":6, "raisins":746, "red wine vinegar":17, "garam masala":3, "chives":3, "cornstarch":151, "dried basil":8, "orange":44, "radishes":2, "catsup":11, "ground beef":35, "sweet red pepper":5, "cumin seeds":15, "canned peaches":3, "barbecue sauce":2, "red pepper flakes":4, "eggs":1239, "almonds":75, "margarine":263, "fresh ginger":8, "garlic powder":26, "dried thyme":10, "low fat milk":4, "vanilla":842, "whole wheat flour":139, "salt":2385, "fresh basil":2, "shiitake mushrooms":2, "potatoes":27, "almond extract":47, "celery seeds":3, "allspice":411, "dijon mustard":7, "soy sauce":27, "broccoli":2, "chicken legs":2, "apples":331, "maple syrup":64, "white rice":5, "sweet potatoes":53, "egg whites":167, "worcestershire sauce":19, "brown sugar":891, "lime juice":21, "dry mustard":22, "white flour":26, "blueberries":43, "mayonnaise":10, "chicken wings":2, "fresh thyme":3, "olive oil":119, "vegetable oil":232, "flour":1504, "curry powder":38, "vinegar":116, "white wine":11, "sherry":17, "oats":64, "whipping cream":47, "chicken breast":8, "sugar":2551}, "canned vegetable broth": {"olive oil":4, "chili powder":2, "shiitake mushrooms":2, "dried oregano":2, "green onions":3, "salt":2}, "oats": {"yogurt":4, "cream cheese":2, "tofu":2, "canned tomato sauce":2, "cayenne pepper":2, "parsley":7, "honey":37, "lemon juice":8, "molasses":12, "chili powder":2, "ground cinnamon":7, "raisins":39, "yeast":43, "chives":2, "cornstarch":5, "baking powder":43, "orange":3, "catsup":2, "ground beef":4, "cinnamon":64, "cream of tartar":3, "cheddar cheese":2, "tomatoes":2, "eggs":57, "almonds":8, "margarine":30, "butter":53, "garlic powder":5, "vanilla":66, "orange juice":3, "whole wheat flour":18, "salt":163, "buttermilk":5, "potatoes":4, "powdered sugar":12, "eggplant":3, "almond extract":8, "cornmeal":5, "cloves":8, "oil":23, "allspice":6, "canola oil":4, "soy sauce":3, "strawberries":2, "celery":2, "apples":10, "maple syrup":4, "nutmeg":18, "walnuts":7, "egg whites":13, "bread crumbs":4, "baking soda":84, "corn syrup":3, "brown sugar":81, "ginger":6, "dry mustard":2, "white flour":5, "pecans":8, "blueberries":4, "peanut butter":14, "cumin":4, "vegetable oil":15, "olive oil":4, "banana":3, "skim milk":6, "beets":2, "curry powder":3, "flour":105, "barley":2, "shortening":24, "parmesan cheese":2, "applesauce":23, "carrots":4, "sugar":90}, "curry powder": {"elbow macaroni":2, "red wine":3, "bacon":6, "cayenne pepper":56, "lemon juice":138, "honey":55, "zucchini squash":2, "paprika":77, "bread":5, "ground cinnamon":20, "yeast":4, "egg yolks":7, "green pepper":43, "baking powder":12, "saffron":2, "sesame oil":11, "cinnamon":38, "pine nuts":3, "avocado":2, "cheddar cheese":17, "tomatoes":49, "white pepper":29, "brown rice":13, "black beans":4, "pinto beans":2, "fresh garlic":2, "cauliflower":4, "frozen peas":12, "butter":150, "orange juice":28, "lemon":16, "black pepper":64, "tumeric":7, "black olives":4, "buttermilk":5, "hoisin sauce":2, "eggplant":8, "dried oregano":2, "capers":3, "cloves":15, "oil":79, "chicken":36, "blue cheese":2, "cucumber":10, "canola oil":17, "dried tarragon":3, "celery":53, "walnuts":6, "fresh cilantro":6, "nutmeg":13, "bread crumbs":22, "baking soda":2, "corn syrup":2, "tabasco sauce":11, "balsamic vinegar":5, "ginger":41, "fresh rosemary":3, "lime":2, "pecans":2, "peanut butter":14, "cumin":50, "green onions":43, "frozen corn":3, "canned chicken broth":2, "banana":12, "skim milk":12, "barley":4, "kidney beans":4, "shortening":3, "applesauce":4, "parmesan cheese":7, "carrots":59, "mushrooms":24, "sour cream":54, "yogurt":18, "tofu":6, "cream cheese":16, "cherry tomatoes":5, "parsley":39, "green olives":5, "rice vinegar":4, "molasses":9, "beer":2, "chili powder":46, "raisins":67, "red wine vinegar":6, "garam masala":7, "chives":9, "cornstarch":42, "dried basil":3, "orange":6, "radishes":2, "catsup":7, "ground beef":11, "sweet red pepper":7, "cumin seeds":10, "canned peaches":2, "red pepper flakes":10, "almonds":10, "eggs":33, "margarine":29, "fresh ginger":12, "kale":2, "garlic powder":42, "dried thyme":19, "cream of mushroom soup":9, "low fat milk":2, "whole wheat flour":4, "salt":474, "fresh basil":2, "bean sprouts":4, "shiitake mushrooms":3, "potatoes":28, "frozen spinach":3, "allspice":13, "celery seeds":5, "dijon mustard":21, "soy sauce":73, "broccoli":9, "chicken legs":2, "apples":29, "maple syrup":2, "sweet potatoes":14, "white rice":5, "egg whites":5, "worcestershire sauce":32, "brown sugar":33, "lime juice":22, "dry mustard":31, "raw shrimp":2, "white flour":2, "mayonnaise":98, "chicken wings":4, "olive oil":92, "vegetable oil":88, "fresh thyme":3, "flour":116, "vinegar":28, "white wine":11, "sherry":16, "oats":3, "whipping cream":11, "chicken breast":11, "sugar":83}, "swiss cheese": {"sour cream":14, "yogurt":2, "elbow macaroni":3, "cream cheese":7, "bacon":26, "salsa":2, "parsley":22, "cayenne pepper":12, "green olives":2, "honey":2, "lemon juice":7, "beer":2, "paprika":14, "spaghetti":3, "bread":4, "red wine vinegar":2, "yeast":7, "egg yolks":7, "chives":7, "green pepper":11, "baking powder":4, "cornstarch":4, "orange":2, "dried basil":4, "radishes":2, "cream of tartar":3, "ground beef":7, "cinnamon":2, "avocado":3, "cheddar cheese":17, "mozzarella cheese":6, "corn tortilla":2, "tomatoes":17, "barbecue sauce":2, "white pepper":13, "brown rice":3, "almonds":2, "eggs":84, "margarine":22, "butter":86, "garlic powder":9, "dried thyme":2, "salmon":4, "cream of mushroom soup":4, "whole wheat flour":2, "lemon":4, "salt":129, "black pepper":11, "black olives":2, "potatoes":5, "eggplant":5, "dried oregano":6, "cornmeal":2, "cloves":2, "frozen spinach":4, "oil":7, "chicken":8, "blue cheese":5, "cucumber":2, "dijon mustard":12, "soy sauce":3, "celery":12, "broccoli":5, "maple syrup":2, "alfalfa sprouts":3, "nutmeg":14, "egg whites":5, "baking soda":2, "bread crumbs":16, "worcestershire sauce":12, "balsamic vinegar":2, "dry mustard":10, "raw shrimp":2, "mayonnaise":22, "cumin":3, "green onions":21, "canned chicken broth":3, "olive oil":16, "vegetable oil":11, "beets":2, "skim milk":6, "flour":61, "kidney beans":2, "shortening":2, "vinegar":2, "parmesan cheese":32, "white wine":17, "sherry":3, "carrots":5, "whipping cream":7, "chicken breast":3, "sugar":25, "mushrooms":22}, "oil": {"elbow macaroni":4, "red wine":33, "canned tomato sauce":2, "bacon":51, "cayenne pepper":76, "honey":197, "lemon juice":228, "swiss cheese":7, "paprika":176, "ground cinnamon":34, "bread":18, "yeast":141, "egg yolks":36, "green pepper":165, "baking powder":405, "saffron":16, "sesame oil":100, "pine nuts":15, "cream of tartar":17, "cinnamon":316, "avocado":11, "cheddar cheese":32, "corn tortilla":4, "tomatoes":250, "white pepper":54, "brown rice":16, "black beans":26, "fresh garlic":2, "pinto beans":6, "cauliflower":29, "butter":306, "frozen peas":16, "salmon":5, "orange juice":52, "lemon":67, "black pepper":163, "tumeric":16, "black olives":13, "buttermilk":58, "powdered sugar":36, "hoisin sauce":23, "eggplant":48, "dried oregano":35, "capers":22, "cornmeal":42, "cloves":75, "chicken":114, "blue cheese":5, "cucumber":30, "dry rosemary":2, "canola oil":3, "dried tarragon":3, "strawberries":5, "celery":159, "alfalfa sprouts":2, "cornish game hens":2, "fresh cilantro":10, "walnuts":70, "nutmeg":117, "baking soda":274, "bread crumbs":36, "corn syrup":3, "tabasco sauce":32, "ginger":178, "balsamic vinegar":10, "fresh rosemary":5, "lime":13, "pecans":42, "peanut butter":26, "frozen corn":3, "cumin":136, "green onions":102, "canned chicken broth":3, "beets":8, "banana":11, "skim milk":21, "barley":9, "kidney beans":22, "shortening":13, "parmesan cheese":62, "applesauce":14, "carrots":208, "mushrooms":162, "sour cream":114, "yogurt":32, "cream cheese":27, "tofu":41, "cherry tomatoes":9, "salsa":16, "parsley":213, "green olives":6, "rice vinegar":14, "molasses":47, "chili powder":158, "beer":34, "spaghetti":11, "raisins":116, "red wine vinegar":41, "chives":18, "garam masala":32, "cornstarch":731, "dried basil":23, "orange":13, "radishes":8, "catsup":58, "ground beef":66, "romaine lettuce":2, "adzuki beans":2, "mozzarella cheese":29, "sweet red pepper":6, "cumin seeds":29, "canned peaches":2, "barbecue sauce":4, "red pepper flakes":10, "eggs":748, "almonds":37, "margarine":39, "fresh ginger":28, "kale":5, "garlic powder":124, "dried thyme":22, "cream of mushroom soup":14, "low fat milk":2, "vanilla":258, "whole wheat flour":89, "salt":2800, "fresh basil":13, "bean sprouts":71, "sriracha hot chili sauce":2, "shiitake mushrooms":4, "potatoes":140, "almond extract":20, "frozen spinach":9, "celery seeds":2, "allspice":44, "dijon mustard":33, "soy sauce":896, "broccoli":29, "chicken legs":5, "apples":54, "yellow mustard":2, "shell macaroni":3, "white rice":5, "maple syrup":18, "sweet potatoes":15, "egg whites":44, "worcestershire sauce":119, "brown sugar":202, "lime juice":45, "dry mustard":65, "raw shrimp":7, "white flour":20, "blueberries":11, "mayonnaise":31, "chicken wings":16, "fresh thyme":5, "vegetable oil":16, "olive oil":52, "curry powder":79, "flour":957, "vinegar":311, "white wine":60, "sherry":435, "oats":23, "whipping cream":25, "chicken breast":82, "sugar":1465}, "vegetable oil": {"canned beef broth":5, "red wine":22, "elbow macaroni":6, "canned tomato sauce":11, "bacon":54, "brown onions":2, "cayenne pepper":149, "honey":227, "lemon juice":344, "swiss cheese":11, "paprika":193, "bread":9, "ground cinnamon":184, "yeast":92, "egg yolks":35, "green pepper":140, "baking powder":527, "saffron":8, "sesame oil":126, "pine nuts":17, "cinnamon":232, "cream of tartar":20, "avocado":13, "cheddar cheese":42, "corn tortilla":3, "tomatoes":196, "white pepper":66, "brown rice":27, "black beans":34, "fresh garlic":5, "pinto beans":14, "cauliflower":14, "butter":220, "frozen peas":23, "salmon":7, "orange juice":90, "black pepper":202, "lemon":60, "tumeric":9, "black olives":8, "buttermilk":97, "powdered sugar":49, "eggplant":26, "hoisin sauce":14, "dried oregano":87, "capers":34, "cornmeal":62, "cloves":56, "oil":16, "chicken":56, "blue cheese":4, "cucumber":28, "canola oil":2, "flour tortilla":5, "dried tarragon":14, "strawberries":9, "celery":82, "cornish game hens":3, "alfalfa sprouts":6, "fresh cilantro":54, "walnuts":70, "nutmeg":93, "baking soda":406, "bread crumbs":37, "corn syrup":2, "tabasco sauce":38, "balsamic vinegar":23, "ginger":110, "fresh rosemary":5, "lime":24, "pecans":25, "peanut butter":24, "frozen corn":9, "green onions":180, "cumin":123, "canned chicken broth":8, "beets":9, "banana":17, "skim milk":71, "barley":4, "kidney beans":16, "shortening":11, "applesauce":26, "parmesan cheese":45, "carrots":184, "mushrooms":111, "sour cream":117, "yogurt":28, "tofu":25, "cream cheese":31, "cherry tomatoes":18, "salsa":26, "parsley":117, "green olives":6, "rice vinegar":38, "molasses":65, "chili powder":221, "beer":31, "spaghetti":16, "raisins":149, "red wine vinegar":101, "chives":14, "garam masala":35, "cornstarch":336, "dried basil":46, "orange":23, "radishes":5, "catsup":38, "ground beef":59, "adzuki beans":4, "romaine lettuce":6, "mozzarella cheese":16, "sweet red pepper":31, "canned tuna":2, "cumin seeds":35, "barbecue sauce":6, "raw spinach":2, "red pepper flakes":25, "eggs":597, "almonds":29, "margarine":46, "fresh ginger":44, "kale":5, "garlic powder":129, "dried thyme":95, "cream of mushroom soup":7, "low fat milk":3, "vanilla":159, "whole wheat flour":139, "salt":2524, "fresh basil":23, "bean sprouts":37, "shiitake mushrooms":8, "potatoes":114, "almond extract":21, "frozen spinach":7, "celery seeds":6, "allspice":45, "dijon mustard":114, "soy sauce":429, "broccoli":29, "chicken legs":7, "apples":28, "yellow mustard":2, "maple syrup":14, "white rice":4, "sweet potatoes":17, "red leaf lettuce":2, "egg whites":109, "worcestershire sauce":130, "brown sugar":204, "lime juice":106, "dry mustard":88, "raw shrimp":6, "white flour":21, "blueberries":20, "mayonnaise":24, "chicken wings":27, "olive oil":99, "fresh thyme":15, "curry powder":88, "flour":537, "vinegar":127, "white wine":40, "sherry":34, "yam":2, "oats":15, "whipping cream":31, "chicken breast":21, "sugar":1133}, "pinto beans": {"sour cream":6, "red wine":2, "tofu":2, "bacon":10, "salsa":10, "parsley":6, "cayenne pepper":10, "lemon juice":8, "molasses":3, "chili powder":59, "paprika":10, "beer":5, "ground cinnamon":3, "red wine vinegar":3, "green pepper":19, "baking powder":2, "cornstarch":2, "dried basil":2, "ground beef":10, "cinnamon":5, "cheddar cheese":11, "mozzarella cheese":2, "sweet red pepper":2, "tomatoes":23, "cumin seeds":3, "white pepper":2, "brown rice":2, "red pepper flakes":3, "black beans":10, "almonds":4, "butter":7, "garlic powder":13, "kale":2, "dried thyme":3, "cream of mushroom soup":2, "black pepper":24, "salt":64, "black olives":4, "buttermilk":2, "potatoes":2, "dried oregano":6, "cornmeal":2, "cloves":5, "oil":6, "flour tortilla":2, "canola oil":2, "dijon mustard":2, "soy sauce":4, "celery":13, "maple syrup":3, "sweet potatoes":2, "nutmeg":3, "fresh cilantro":4, "egg whites":2, "baking soda":2, "bread crumbs":3, "worcestershire sauce":4, "tabasco sauce":7, "brown sugar":6, "lime juice":3, "dry mustard":4, "peanut butter":2, "frozen corn":3, "green onions":5, "cumin":38, "vegetable oil":14, "olive oil":20, "skim milk":2, "banana":2, "flour":4, "barley":2, "curry powder":2, "kidney beans":20, "shortening":3, "vinegar":7, "carrots":10, "sugar":8, "mushrooms":5}, "lamb shank":{"salt":2, "lemon juice":2}, "lemon juice": {"canned beef broth":2, "elbow macaroni":4, "red wine":22, "canned tomato sauce":2, "coconut oil":2, "bacon":46, "cayenne pepper":137, "honey":295, "swiss cheese":7, "zucchini squash":2, "paprika":283, "bread":23, "ground cinnamon":117, "yeast":11, "egg yolks":188, "green pepper":98, "baking powder":206, "saffron":12, "sesame oil":37, "cream of tartar":46, "pine nuts":24, "cinnamon":299, "avocado":34, "cheddar cheese":34, "tomatoes":194, "white pepper":108, "brown rice":12, "black beans":10, "fresh garlic":3, "pinto beans":8, "cauliflower":15, "frozen peas":10, "butter":973, "salmon":34, "orange juice":275, "lemon":87, "black pepper":258, "tumeric":16, "black olives":22, "buttermilk":34, "powdered sugar":92, "hoisin sauce":7, "eggplant":42, "dried oregano":70, "capers":71, "cornmeal":7, "cloves":62, "oil":228, "chicken":95, "blue cheese":14, "cucumber":71, "dry rosemary":2, "flour tortilla":2, "canola oil":31, "dried tarragon":34, "strawberries":71, "celery":128, "alfalfa sprouts":7, "cornish game hens":11, "fresh peaches":8, "fresh cilantro":21, "nutmeg":176, "walnuts":86, "baking soda":110, "bread crumbs":77, "corn syrup":9, "tabasco sauce":92, "balsamic vinegar":47, "ginger":109, "fresh rosemary":11, "lime":7, "pecans":41, "peanut butter":28, "frozen corn":2, "green onions":137, "cumin":120, "canned chicken broth":6, "beets":19, "banana":22, "skim milk":42, "barley":5, "kidney beans":8, "shortening":49, "parmesan cheese":77, "applesauce":15, "carrots":124, "mushrooms":136, "sour cream":248, "yogurt":43, "brussels sprouts":2, "tofu":29, "cream cheese":195, "cherry tomatoes":25, "salsa":9, "parsley":300, "green olives":10, "rice vinegar":17, "molasses":42, "chili powder":99, "beer":20, "spaghetti":9, "raisins":109, "red wine vinegar":70, "garam masala":38, "chives":48, "cornstarch":341, "orange":34, "dried basil":54, "radishes":20, "catsup":78, "ground beef":29, "mozzarella cheese":11, "romaine lettuce":9, "sweet red pepper":20, "canned tuna":3, "cumin seeds":37, "barbecue sauce":7, "red pepper flakes":27, "eggs":525, "almonds":40, "margarine":184, "fresh ginger":34, "kale":3, "garlic powder":171, "dried thyme":56, "cream of mushroom soup":13, "low fat milk":2, "vanilla":257, "whole wheat flour":29, "salt":2421, "fresh basil":31, "bean sprouts":7, "shiitake mushrooms":8, "potatoes":65, "almond extract":37, "frozen spinach":7, "canned apricots":2, "celery seeds":10, "allspice":42, "dijon mustard":150, "soy sauce":268, "broccoli":16, "chicken legs":6, "apples":109, "yellow mustard":2, "shell macaroni":2, "white rice":7, "maple syrup":37, "sweet potatoes":11, "canned tomato paste":2, "egg whites":151, "worcestershire sauce":322, "dried cilantro":3, "brown sugar":332, "lime juice":40, "dry mustard":151, "raw shrimp":5, "white flour":8, "blueberries":45, "mayonnaise":333, "chicken wings":18, "fresh thyme":13, "olive oil":803, "vegetable oil":344, "flour":619, "curry powder":138, "vinegar":131, "lamb shank":2, "white wine":92, "sherry":43, "oats":8, "whipping cream":138, "chicken breast":21, "sugar":1688}, "garam masala": {"yogurt":22, "tofu":2, "cherry tomatoes":2, "cayenne pepper":27, "honey":2, "rice vinegar":2, "lemon juice":38, "chili powder":21, "paprika":20, "ground cinnamon":5, "raisins":3, "green pepper":4, "baking powder":4, "cornstarch":2, "saffron":8, "ground beef":3, "cinnamon":3, "tomatoes":43, "cumin seeds":33, "white pepper":4, "eggs":4, "almonds":5, "margarine":3, "cauliflower":10, "fresh ginger":18, "frozen peas":4, "butter":12, "garlic powder":3, "whole wheat flour":3, "lemon":7, "salt":143, "black pepper":13, "tumeric":8, "potatoes":32, "buttermilk":3, "eggplant":3, "cloves":8, "frozen spinach":3, "oil":32, "chicken":8, "cucumber":2, "allspice":2, "canola oil":5, "dijon mustard":2, "soy sauce":8, "broccoli":2, "fresh peaches":2, "walnuts":3, "fresh cilantro":3, "nutmeg":5, "baking soda":2, "worcestershire sauce":2, "brown sugar":6, "ginger":29, "dry mustard":4, "lime":3, "peanut butter":2, "mayonnaise":2, "green onions":5, "cumin":19, "frozen corn":2, "vegetable oil":35, "olive oil":4, "flour":3, "curry powder":7, "kidney beans":3, "vinegar":5, "carrots":5, "whipping cream":3, "chicken breast":2, "mushrooms":4, "sugar":18}, "tumeric": {"sour cream":2, "yogurt":6, "canned beef broth":2, "tofu":2, "parsley":3, "cayenne pepper":13, "lemon juice":16, "honey":12, "molasses":2, "chili powder":14, "paprika":12, "ground cinnamon":2, "raisins":3, "red wine vinegar":2, "garam masala":8, "green pepper":7, "cornstarch":4, "baking powder":3, "saffron":3, "sesame oil":3, "radishes":2, "catsup":3, "cream of tartar":3, "cinnamon":18, "cheddar cheese":4, "sweet red pepper":2, "tomatoes":13, "cumin seeds":12, "white pepper":3, "red pepper flakes":2, "eggs":2, "fresh garlic":2, "margarine":4, "fresh ginger":3, "cauliflower":4, "frozen peas":4, "butter":7, "garlic powder":6, "salt":58, "lemon":5, "black pepper":14, "bean sprouts":2, "potatoes":11, "buttermilk":2, "dried oregano":3, "eggplant":4, "cloves":10, "oil":16, "chicken":5, "cucumber":5, "canola oil":3, "allspice":9, "celery seeds":5, "soy sauce":6, "celery":4, "nutmeg":6, "baking soda":3, "brown sugar":7, "balsamic vinegar":2, "ginger":20, "dry mustard":13, "white flour":2, "mayonnaise":2, "cumin":21, "green onions":2, "chicken wings":2, "vegetable oil":9, "olive oil":14, "flour":7, "curry powder":7, "kidney beans":2, "vinegar":9, "carrots":5, "whipping cream":2, "mushrooms":5, "sugar":25}, "lemon": {"red wine":10, "canned beef broth":3, "bacon":18, "cayenne pepper":34, "honey":73, "lemon juice":87, "swiss cheese":4, "paprika":63, "bread":5, "ground cinnamon":25, "yeast":10, "egg yolks":71, "green pepper":22, "baking powder":55, "saffron":7, "sesame oil":4, "pine nuts":8, "cinnamon":59, "cream of tartar":6, "avocado":8, "cheddar cheese":2, "tomatoes":55, "white pepper":18, "brown rice":2, "black beans":5, "cauliflower":4, "butter":301, "frozen peas":4, "salmon":6, "orange juice":27, "black pepper":54, "tumeric":5, "black olives":9, "buttermilk":4, "powdered sugar":14, "hoisin sauce":4, "eggplant":13, "dried oregano":16, "capers":28, "cornmeal":7, "cloves":34, "oil":67, "chicken":33, "blue cheese":2, "cucumber":16, "canola oil":2, "dried tarragon":6, "strawberries":12, "celery":28, "cornish game hens":2, "alfalfa sprouts":3, "fresh peaches":2, "fresh cilantro":5, "walnuts":12, "nutmeg":39, "bread crumbs":23, "baking soda":19, "tabasco sauce":20, "balsamic vinegar":11, "ginger":27, "fresh rosemary":2, "lime":26, "pecans":6, "green onions":28, "cumin":23, "canned chicken broth":3, "skim milk":4, "beets":5, "banana":3, "barley":2, "kidney beans":2, "shortening":10, "applesauce":2, "parmesan cheese":27, "carrots":34, "cashew":2, "mushrooms":29, "sour cream":35, "yogurt":6, "tofu":2, "cream cheese":8, "cherry tomatoes":4, "parsley":94, "green olives":11, "rice vinegar":3, "molasses":12, "chili powder":23, "beer":10, "spaghetti":5, "raisins":38, "red wine vinegar":19, "chives":11, "garam masala":7, "cornstarch":39, "dried basil":9, "orange":85, "radishes":2, "catsup":14, "ground beef":6, "romaine lettuce":2, "mozzarella cheese":3, "adzuki beans":2, "sweet red pepper":2, "cumin seeds":4, "barbecue sauce":2, "red pepper flakes":4, "almonds":18, "eggs":138, "margarine":24, "fresh ginger":10, "garlic powder":21, "dried thyme":15, "vanilla":33, "salt":483, "fresh basil":11, "bean sprouts":3, "shiitake mushrooms":3, "potatoes":17, "almond extract":5, "frozen spinach":3, "allspice":20, "celery seeds":3, "dijon mustard":21, "soy sauce":37, "broccoli":4, "chicken legs":2, "apples":27, "yellow mustard":3, "maple syrup":3, "sweet potatoes":2, "white rice":3, "egg whites":31, "worcestershire sauce":75, "brown sugar":55, "lime juice":2, "dry mustard":25, "raw shrimp":2, "blueberries":5, "mayonnaise":44, "chicken wings":4, "fresh thyme":6, "vegetable oil":60, "olive oil":236, "curry powder":16, "flour":191, "vinegar":41, "white wine":40, "sherry":11, "whipping cream":29, "chicken breast":5, "sugar":379}, "capers": {"red wine":7, "elbow macaroni":2, "canned tomato sauce":2, "bacon":5, "cayenne pepper":9, "lemon juice":71, "honey":4, "paprika":20, "bread":5, "yeast":2, "egg yolks":14, "green pepper":15, "baking powder":2, "saffron":6, "cinnamon":10, "pine nuts":10, "avocado":4, "cheddar cheese":3, "tomatoes":37, "white pepper":7, "black beans":2, "cauliflower":4, "butter":58, "salmon":2, "orange juice":4, "black pepper":23, "lemon":28, "black olives":28, "buttermilk":3, "eggplant":11, "dried oregano":22, "cloves":6, "oil":22, "chicken":10, "blue cheese":2, "cucumber":7, "dried tarragon":5, "celery":13, "alfalfa sprouts":2, "nutmeg":6, "bread crumbs":5, "tabasco sauce":9, "balsamic vinegar":19, "ginger":2, "lime":3, "pecans":2, "green onions":9, "cumin":8, "skim milk":2, "beets":4, "parmesan cheese":15, "carrots":8, "mushrooms":12, "sour cream":14, "yogurt":2, "cream cheese":7, "tofu":2, "cherry tomatoes":2, "parsley":50, "green olives":22, "rice vinegar":3, "molasses":2, "beer":2, "chili powder":3, "spaghetti":5, "raisins":9, "red wine vinegar":41, "chives":7, "cornstarch":11, "dried basil":14, "orange":3, "catsup":2, "ground beef":11, "mozzarella cheese":6, "sweet red pepper":2, "canned tuna":2, "cumin seeds":2, "red pepper flakes":8, "almonds":2, "eggs":14, "margarine":5, "garlic powder":6, "dried thyme":6, "salt":151, "fresh basil":10, "potatoes":4, "allspice":3, "dijon mustard":24, "soy sauce":3, "broccoli":2, "white rice":2, "worcestershire sauce":17, "brown sugar":6, "lime juice":9, "dry mustard":10, "mayonnaise":32, "olive oil":187, "vegetable oil":34, "fresh thyme":3, "flour":30, "curry powder":3, "vinegar":29, "white wine":21, "sherry":2, "whipping cream":5, "chicken breast":3, "sugar":41}, "canned apricots": {"olive oil":2, "baking powder":2, "sour cream":2, "flour":2, "dijon mustard":2, "ground cinnamon":3, "vanilla":2, "honey":2, "salt":2, "lemon juice":2}, "brown onions": {"brown sugar":2, "ginger":2, "cinnamon":2, "potatoes":3, "mozzarella cheese":2, "cayenne pepper":3, "cloves":2, "cumin seeds":2, "green onions":2, "vegetable oil":2, "olive oil":2, "flour":2, "eggs":2, "paprika":5, "black beans":2, "fresh ginger":2, "butter":3, "nutmeg":2, "salt":3, "sugar":2}, "cream of mushroom soup": {"sour cream":51, "elbow macaroni":7, "red wine":3, "cream cheese":5, "frozen french fries":3, "bacon":18, "cayenne pepper":4, "parsley":17, "green olives":2, "lemon juice":13, "swiss cheese":4, "chili powder":15, "paprika":28, "beer":2, "spaghetti":3, "bread":5, "red wine vinegar":2, "yeast":2, "green pepper":23, "cornstarch":5, "dried basil":3, "catsup":5, "ground beef":46, "cheddar cheese":33, "mozzarella cheese":4, "tomatoes":4, "white pepper":4, "eggs":38, "pinto beans":2, "margarine":19, "butter":56, "frozen peas":6, "garlic powder":18, "dried thyme":2, "salmon":5, "orange juice":2, "salt":93, "black pepper":13, "bean sprouts":3, "potatoes":21, "buttermilk":3, "dried oregano":2, "frozen spinach":2, "oil":14, "chicken":29, "cucumber":2, "allspice":2, "dijon mustard":2, "soy sauce":10, "celery":35, "broccoli":4, "sweet potatoes":2, "white rice":2, "nutmeg":4, "bread crumbs":11, "worcestershire sauce":23, "tabasco sauce":2, "brown sugar":3, "dry mustard":9, "peanut butter":2, "mayonnaise":25, "cumin":4, "green onions":13, "frozen corn":2, "olive oil":3, "vegetable oil":7, "skim milk":5, "flour":31, "curry powder":9, "kidney beans":2, "shortening":6, "parmesan cheese":17, "white wine":10, "carrots":13, "sherry":3, "whipping cream":3, "chicken breast":2, "sugar":3, "mushrooms":30}, "lime juice": {"red wine":7, "bacon":4, "cayenne pepper":32, "lemon juice":40, "honey":68, "paprika":27, "ground cinnamon":16, "yeast":2, "egg yolks":13, "green pepper":12, "baking powder":14, "saffron":2, "sesame oil":15, "cream of tartar":7, "cinnamon":21, "pine nuts":4, "avocado":26, "cheddar cheese":4, "corn tortilla":2, "tomatoes":75, "white pepper":18, "black beans":19, "pinto beans":3, "fresh garlic":2, "butter":43, "orange juice":48, "lemon":2, "black pepper":36, "black olives":4, "buttermilk":5, "powdered sugar":7, "eggplant":2, "dried oregano":11, "capers":9, "cloves":9, "oil":45, "chicken":12, "cucumber":15, "flour tortilla":2, "canola oil":13, "dried tarragon":3, "strawberries":6, "celery":6, "cornish game hens":4, "fresh peaches":2, "walnuts":6, "nutmeg":12, "fresh cilantro":59, "bread crumbs":2, "tabasco sauce":16, "balsamic vinegar":5, "ginger":26, "fresh rosemary":2, "lime":10, "pecans":4, "peanut butter":4, "green onions":60, "cumin":52, "frozen corn":7, "canned chicken broth":2, "banana":5, "skim milk":4, "shortening":4, "parmesan cheese":5, "carrots":17, "mushrooms":4, "sour cream":28, "yogurt":9, "tofu":3, "cream cheese":11, "cherry tomatoes":5, "salsa":19, "parsley":17, "green olives":5, "rice vinegar":10, "molasses":6, "beer":6, "chili powder":58, "spaghetti":2, "raisins":6, "red wine vinegar":22, "chives":5, "cornstarch":24, "dried basil":3, "orange":4, "radishes":3, "catsup":6, "ground beef":2, "adzuki beans":2, "romaine lettuce":2, "sweet red pepper":8, "cumin seeds":9, "canned peaches":3, "barbecue sauce":2, "red pepper flakes":9, "eggs":28, "almonds":4, "margarine":12, "fresh ginger":17, "garlic powder":18, "dried thyme":6, "low fat milk":2, "vanilla":6, "salt":348, "fresh basil":4, "bean sprouts":12, "potatoes":7, "celery seeds":2, "allspice":7, "dijon mustard":22, "soy sauce":62, "broccoli":2, "apples":5, "sweet potatoes":2, "white rice":3, "maple syrup":10, "egg whites":9, "worcestershire sauce":21, "dried cilantro":4, "brown sugar":46, "dry mustard":8, "raw shrimp":3, "white flour":3, "blueberries":5, "mayonnaise":17, "chicken wings":8, "fresh thyme":3, "olive oil":148, "vegetable oil":106, "curry powder":22, "flour":25, "vinegar":14, "white wine":12, "sherry":2, "whipping cream":10, "chicken breast":7, "sugar":204}, "green olives": {"sour cream":3, "cream cheese":2, "bacon":2, "salsa":2, "cayenne pepper":2, "parsley":23, "honey":2, "lemon juice":10, "swiss cheese":2, "chili powder":5, "paprika":8, "spaghetti":3, "bread":2, "ground cinnamon":3, "raisins":7, "red wine vinegar":5, "chives":2, "egg yolks":2, "green pepper":10, "saffron":4, "catsup":2, "pine nuts":4, "ground beef":9, "cinnamon":6, "avocado":3, "mozzarella cheese":2, "tomatoes":16, "cumin seeds":2, "white pepper":2, "brown rice":2, "almonds":3, "eggs":10, "black beans":3, "margarine":2, "cauliflower":3, "butter":12, "garlic powder":5, "cream of mushroom soup":2, "orange juice":3, "salt":39, "black pepper":9, "lemon":11, "black olives":21, "potatoes":4, "dried oregano":3, "eggplant":5, "capers":22, "cloves":3, "oil":6, "chicken":5, "blue cheese":2, "cucumber":2, "allspice":2, "dijon mustard":2, "dried tarragon":3, "celery":10, "broccoli":3, "yellow mustard":2, "walnuts":2, "nutmeg":3, "fresh cilantro":2, "bread crumbs":2, "worcestershire sauce":6, "tabasco sauce":2, "ginger":2, "balsamic vinegar":2, "lime juice":5, "lime":3, "mayonnaise":8, "green onions":10, "cumin":4, "olive oil":47, "vegetable oil":6, "fresh thyme":2, "beets":2, "flour":7, "curry powder":5, "vinegar":6, "parmesan cheese":4, "white wine":6, "sherry":3, "carrots":4, "mushrooms":10, "sugar":15}, "chicken": {"elbow macaroni":2, "red wine":10, "canned tomato sauce":2, "bacon":14, "cayenne pepper":29, "honey":32, "lemon juice":95, "zucchini squash":2, "swiss cheese":8, "paprika":76, "ground cinnamon":16, "bread":4, "yeast":2, "egg yolks":9, "green pepper":47, "baking powder":13, "saffron":23, "sesame oil":15, "pine nuts":5, "cinnamon":27, "avocado":4, "cheddar cheese":26, "corn tortilla":2, "tomatoes":53, "white pepper":9, "brown rice":3, "black beans":2, "cauliflower":3, "frozen peas":6, "butter":146, "orange juice":15, "black pepper":61, "lemon":33, "tumeric":5, "black olives":5, "buttermilk":5, "eggplant":7, "hoisin sauce":4, "dried oregano":15, "capers":10, "cornmeal":3, "cloves":29, "oil":114, "cucumber":4, "canola oil":2, "dried tarragon":4, "celery":93, "fresh cilantro":3, "walnuts":8, "nutmeg":17, "baking soda":2, "bread crumbs":10, "tabasco sauce":4, "balsamic vinegar":4, "ginger":36, "fresh rosemary":6, "lime":7, "pecans":6, "peanut butter":3, "green onions":42, "cumin":25, "frozen corn":3, "skim milk":7, "barley":5, "kidney beans":3, "shortening":8, "parmesan cheese":28, "carrots":59, "mushrooms":59, "sour cream":40, "yogurt":14, "brussels sprouts":2, "cream cheese":4, "salsa":6, "parsley":70, "green olives":5, "rice vinegar":3, "molasses":2, "beer":6, "chili powder":18, "spaghetti":10, "raisins":19, "red wine vinegar":13, "chives":5, "garam masala":8, "cornstarch":62, "dried basil":11, "orange":5, "catsup":12, "radishes":4, "ground beef":5, "mozzarella cheese":6, "sweet red pepper":4, "cumin seeds":8, "barbecue sauce":3, "red pepper flakes":4, "eggs":46, "almonds":27, "margarine":27, "fresh ginger":8, "kale":2, "garlic powder":42, "dried thyme":14, "cream of mushroom soup":29, "whole wheat flour":2, "salt":414, "fresh basil":6, "bean sprouts":10, "potatoes":25, "celery seeds":2, "allspice":13, "dijon mustard":14, "soy sauce":73, "broccoli":11, "apples":7, "maple syrup":3, "sweet potatoes":5, "white rice":3, "egg whites":3, "worcestershire sauce":22, "dried cilantro":2, "brown sugar":21, "lime juice":12, "dry mustard":11, "white flour":2, "mayonnaise":38, "chicken wings":2, "vegetable oil":56, "olive oil":96, "fresh thyme":4, "flour":131, "curry powder":36, "vinegar":29, "white wine":31, "sherry":28, "whipping cream":8, "chicken breast":2, "sugar":69}, "raisins": {"red wine":8, "canned tomato sauce":4, "bacon":5, "cayenne pepper":25, "lemon juice":109, "honey":188, "paprika":14, "ground cinnamon":223, "bread":16, "yeast":91, "egg yolks":35, "green pepper":18, "baking powder":483, "saffron":4, "cream of tartar":7, "cinnamon":746, "pine nuts":29, "cheddar cheese":2, "corn tortilla":3, "tomatoes":32, "white pepper":7, "brown rice":7, "fresh garlic":2, "cauliflower":2, "butter":451, "frozen peas":3, "salmon":2, "orange juice":105, "lemon":38, "black pepper":23, "tumeric":3, "black olives":4, "buttermilk":81, "powdered sugar":40, "dried oregano":10, "eggplant":5, "capers":9, "cornmeal":14, "cloves":184, "oil":116, "chicken":19, "cucumber":2, "dry rosemary":2, "canola oil":16, "dried tarragon":2, "strawberries":3, "celery":27, "cornish game hens":2, "fresh cilantro":2, "walnuts":136, "nutmeg":308, "bread crumbs":14, "baking soda":529, "tabasco sauce":5, "corn syrup":23, "balsamic vinegar":7, "ginger":76, "fresh rosemary":2, "lime":7, "pecans":64, "peanut butter":28, "green onions":10, "cumin":29, "beets":3, "skim milk":52, "banana":9, "barley":5, "kidney beans":4, "shortening":137, "applesauce":71, "parmesan cheese":5, "carrots":61, "mushrooms":7, "sour cream":51, "yogurt":11, "brussels sprouts":3, "tofu":6, "cream cheese":25, "cherry tomatoes":2, "salsa":3, "parsley":23, "green olives":7, "molasses":97, "chili powder":21, "beer":4, "spaghetti":3, "red wine vinegar":18, "garam masala":3, "cornstarch":47, "dried basil":3, "orange":41, "catsup":4, "radishes":2, "ground beef":15, "romaine lettuce":3, "sweet red pepper":4, "cumin seeds":8, "red pepper flakes":4, "almonds":80, "eggs":559, "margarine":125, "fresh ginger":5, "garlic powder":7, "dried thyme":5, "low fat milk":4, "vanilla":381, "whole wheat flour":111, "salt":1175, "fresh basil":2, "potatoes":7, "almond extract":14, "frozen spinach":3, "allspice":103, "dijon mustard":7, "soy sauce":8, "broccoli":3, "apples":110, "maple syrup":30, "sweet potatoes":17, "white rice":5, "egg whites":74, "worcestershire sauce":10, "brown sugar":374, "lime juice":6, "dry mustard":11, "white flour":16, "blueberries":5, "mayonnaise":20, "fresh thyme":3, "olive oil":74, "vegetable oil":149, "flour":590, "curry powder":67, "vinegar":53, "white wine":11, "sherry":8, "oats":39, "whipping cream":21, "chicken breast":3, "sugar":982}, "cream cheese": {"red wine":2, "elbow macaroni":2, "bacon":14, "cayenne pepper":20, "lemon juice":195, "honey":26, "swiss cheese":7, "paprika":33, "camembert cheese":4, "ground cinnamon":24, "bread":8, "yeast":4, "egg yolks":39, "green pepper":19, "baking powder":83, "cream of tartar":6, "pine nuts":8, "cinnamon":105, "avocado":8, "cheddar cheese":33, "tomatoes":16, "white pepper":20, "black beans":4, "cauliflower":3, "butter":451, "salmon":9, "orange juice":29, "black pepper":24, "lemon":8, "black olives":26, "buttermilk":17, "powdered sugar":153, "dried oregano":6, "capers":7, "cornmeal":4, "cloves":8, "oil":27, "chicken":4, "blue cheese":26, "cucumber":7, "dry rosemary":2, "dried tarragon":2, "strawberries":21, "celery":20, "alfalfa sprouts":3, "cornish game hens":2, "fresh peaches":2, "fresh cilantro":3, "nutmeg":42, "walnuts":49, "baking soda":69, "bread crumbs":16, "tabasco sauce":24, "corn syrup":4, "ginger":14, "fresh rosemary":2, "lime":2, "pecans":63, "peanut butter":21, "green onions":53, "cumin":12, "skim milk":5, "beets":3, "banana":3, "shortening":16, "applesauce":2, "parmesan cheese":36, "carrots":17, "mushrooms":21, "sour cream":274, "yogurt":2, "cherry tomatoes":4, "salsa":10, "parsley":28, "green olives":2, "molasses":3, "beer":3, "chili powder":12, "raisins":25, "red wine vinegar":4, "chives":29, "cornstarch":82, "orange":4, "dried basil":6, "radishes":5, "catsup":6, "ground beef":9, "mozzarella cheese":10, "sweet red pepper":3, "red pepper flakes":2, "eggs":454, "almonds":31, "margarine":125, "garlic powder":55, "dried thyme":3, "cream of mushroom soup":5, "low fat milk":2, "vanilla":419, "whole wheat flour":5, "salt":399, "fresh basil":7, "potatoes":15, "almond extract":43, "frozen spinach":6, "allspice":4, "celery seeds":2, "dijon mustard":16, "soy sauce":5, "broccoli":3, "apples":11, "yellow mustard":2, "maple syrup":4, "sweet potatoes":4, "egg whites":18, "worcestershire sauce":82, "brown sugar":76, "lime juice":11, "dry mustard":19, "raw shrimp":2, "white flour":3, "blueberries":17, "mayonnaise":88, "fresh thyme":2, "olive oil":20, "vegetable oil":31, "curry powder":16, "flour":282, "vinegar":10, "white wine":3, "sherry":5, "oats":2, "whipping cream":95, "chicken breast":2, "sugar":831}, "dry mustard": {"elbow macaroni":15, "red wine":6, "canned tomato sauce":7, "bacon":51, "cayenne pepper":75, "lemon juice":151, "honey":90, "swiss cheese":10, "paprika":208, "bread":18, "ground cinnamon":18, "yeast":3, "egg yolks":25, "green pepper":52, "baking powder":16, "saffron":3, "sesame oil":9, "pine nuts":2, "cream of tartar":2, "cinnamon":22, "avocado":2, "cheddar cheese":56, "tomatoes":25, "white pepper":57, "brown rice":3, "black beans":3, "pinto beans":4, "fresh garlic":4, "cauliflower":3, "frozen peas":4, "butter":171, "salmon":2, "orange juice":19, "lemon":25, "black pepper":133, "tumeric":13, "black olives":2, "buttermilk":5, "dried oregano":14, "capers":10, "cornmeal":10, "cloves":20, "oil":65, "chicken":11, "blue cheese":5, "cucumber":10, "canola oil":8, "dried tarragon":13, "celery":32, "alfalfa sprouts":2, "walnuts":5, "nutmeg":27, "fresh cilantro":2, "bread crumbs":30, "baking soda":7, "corn syrup":2, "tabasco sauce":51, "ginger":50, "balsamic vinegar":7, "fresh rosemary":2, "lime":2, "pecans":5, "peanut butter":3, "frozen corn":3, "green onions":36, "cumin":32, "canned chicken broth":2, "skim milk":31, "beets":3, "kidney beans":6, "shortening":12, "applesauce":4, "parmesan cheese":28, "carrots":36, "mushrooms":31, "sour cream":46, "yogurt":4, "cream cheese":19, "cherry tomatoes":6, "salsa":2, "parsley":49, "rice vinegar":8, "molasses":73, "chili powder":94, "beer":31, "spaghetti":3, "raisins":11, "red wine vinegar":48, "garam masala":4, "chives":10, "cornstarch":48, "dried basil":17, "orange":5, "radishes":2, "catsup":67, "ground beef":32, "mozzarella cheese":3, "sweet red pepper":8, "sweet red onions":2, "cumin seeds":3, "barbecue sauce":5, "red pepper flakes":5, "almonds":2, "eggs":159, "margarine":31, "fresh ginger":3, "garlic powder":133, "dried thyme":28, "cream of mushroom soup":9, "whole wheat flour":2, "salt":827, "fresh basil":4, "bean sprouts":3, "shiitake mushrooms":2, "potatoes":25, "frozen spinach":2, "celery seeds":17, "allspice":22, "dijon mustard":28, "soy sauce":102, "broccoli":7, "apples":7, "sweet potatoes":3, "maple syrup":17, "egg whites":11, "worcestershire sauce":292, "brown sugar":231, "lime juice":8, "raw shrimp":2, "white flour":2, "mayonnaise":77, "chicken wings":13, "fresh thyme":3, "vegetable oil":88, "olive oil":108, "curry powder":31, "flour":169, "vinegar":195, "white wine":15, "sherry":20, "oats":2, "whipping cream":7, "chicken breast":4, "sugar":254}, "potatoes": {"red wine":10, "canned tomato sauce":2, "coconut oil":4, "bacon":75, "canned clams":2, "brown onions":3, "cayenne pepper":25, "honey":9, "lemon juice":65, "zucchini squash":2, "swiss cheese":5, "paprika":126, "ground cinnamon":10, "bread":10, "yeast":5, "egg yolks":9, "green pepper":56, "baking powder":18, "saffron":5, "sesame oil":2, "cream of tartar":2, "pine nuts":2, "cinnamon":27, "cheddar cheese":48, "tomatoes":153, "white pepper":31, "brown rice":4, "black beans":4, "pinto beans":2, "cauliflower":24, "butter":325, "frozen peas":34, "orange juice":10, "lemon":17, "black pepper":118, "tumeric":11, "black olives":7, "buttermilk":5, "powdered sugar":2, "eggplant":18, "dried oregano":25, "capers":4, "cornmeal":2, "cloves":15, "oil":140, "chicken":25, "blue cheese":5, "cucumber":10, "flour tortilla":3, "canola oil":11, "dried tarragon":4, "celery":103, "fresh cilantro":7, "nutmeg":44, "walnuts":3, "baking soda":5, "bread crumbs":26, "tabasco sauce":6, "balsamic vinegar":2, "ginger":17, "fresh rosemary":6, "lime":4, "pecans":6, "peanut butter":6, "cumin":29, "frozen corn":10, "green onions":45, "canned chicken broth":2, "banana":2, "skim milk":20, "beets":12, "barley":12, "kidney beans":3, "shortening":13, "applesauce":4, "parmesan cheese":29, "carrots":369, "mushrooms":49, "sour cream":72, "yogurt":12, "brussels sprouts":3, "cream cheese":15, "tofu":3, "cherry tomatoes":5, "salsa":6, "parsley":139, "green olives":4, "molasses":3, "chili powder":29, "beer":11, "raisins":7, "red wine vinegar":6, "garam masala":32, "chives":20, "cornstarch":26, "orange":2, "dried basil":20, "radishes":4, "catsup":11, "ground beef":42, "adzuki beans":2, "mozzarella cheese":4, "sweet red pepper":5, "cumin seeds":19, "barbecue sauce":3, "raw spinach":2, "red pepper flakes":4, "eggs":138, "almonds":5, "margarine":66, "fresh ginger":15, "kale":9, "garlic powder":45, "dried thyme":32, "cream of mushroom soup":21, "vanilla":6, "whole wheat flour":11, "salt":857, "fresh basil":5, "bean sprouts":5, "frozen spinach":2, "celery seeds":3, "allspice":12, "dijon mustard":8, "soy sauce":32, "broccoli":10, "apples":11, "maple syrup":2, "white rice":2, "yellow mustard":4, "sweet potatoes":5, "egg whites":11, "worcestershire sauce":66, "brown sugar":18, "lime juice":7, "dry mustard":25, "blueberries":2, "mayonnaise":24, "olive oil":190, "vegetable oil":114, "fresh thyme":8, "curry powder":28, "flour":263, "vinegar":52, "white wine":12, "sherry":7, "oats":4, "whipping cream":14, "chicken breast":3, "sugar":154}, "lime": {"red wine":3, "bacon":2, "cayenne pepper":12, "lemon juice":7, "honey":13, "paprika":3, "ground cinnamon":4, "green pepper":4, "sesame oil":3, "pine nuts":3, "cinnamon":12, "cream of tartar":2, "avocado":5, "corn tortilla":3, "tomatoes":12, "white pepper":4, "brown rice":2, "black beans":6, "butter":16, "salmon":2, "orange juice":9, "lemon":26, "black pepper":14, "powdered sugar":3, "dried oregano":12, "eggplant":2, "hoisin sauce":3, "capers":3, "cloves":11, "oil":13, "chicken":7, "cucumber":10, "canola oil":2, "strawberries":5, "celery":6, "cornish game hens":2, "nutmeg":8, "fresh cilantro":8, "tabasco sauce":5, "ginger":11, "balsamic vinegar":4, "cumin":17, "green onions":11, "skim milk":2, "beets":2, "banana":2, "barley":2, "carrots":4, "mushrooms":2, "sour cream":10, "yogurt":2, "cream cheese":2, "cherry tomatoes":3, "salsa":4, "parsley":7, "green olives":3, "rice vinegar":2, "molasses":2, "beer":5, "chili powder":8, "raisins":7, "red wine vinegar":5, "garam masala":3, "chives":3, "cornstarch":5, "orange":19, "radishes":2, "sweet red pepper":2, "cumin seeds":3, "red pepper flakes":5, "eggs":3, "fresh ginger":5, "garlic powder":4, "dried thyme":3, "vanilla":3, "salt":93, "bean sprouts":6, "shiitake mushrooms":2, "potatoes":4, "allspice":6, "dijon mustard":3, "soy sauce":11, "sweet potatoes":3, "egg whites":4, "worcestershire sauce":3, "brown sugar":12, "lime juice":10, "dry mustard":2, "blueberries":2, "mayonnaise":5, "vegetable oil":24, "olive oil":38, "flour":6, "curry powder":2, "vinegar":6, "white wine":5, "sherry":2, "whipping cream":3, "chicken breast":4, "sugar":51}, "salt": {"canned beef broth":7, "elbow macaroni":59, "red wine":165, "canned tomato sauce":21, "coconut oil":13, "bacon":516, "canned clams":3, "brown onions":3, "cayenne pepper":928, "lemon juice":2421, "honey":1244, "zucchini squash":10, "swiss cheese":129, "paprika":1611, "camembert cheese":2, "bread":131, "ground cinnamon":843, "dried bay leaf":2, "yeast":1230, "egg yolks":718, "green pepper":767, "baking powder":4656, "saffron":83, "sesame oil":391, "pine nuts":167, "cinnamon":2385, "cream of tartar":344, "avocado":71, "cheddar cheese":392, "corn tortilla":8, "tomatoes":1322, "white pepper":722, "brown rice":75, "black beans":114, "fresh garlic":19, "pinto beans":64, "cauliflower":89, "butter":6434, "frozen peas":127, "salmon":40, "orange juice":548, "lemon":483, "black pepper":1964, "tumeric":58, "black olives":73, "buttermilk":829, "powdered sugar":468, "hoisin sauce":51, "dried oregano":472, "eggplant":277, "capers":151, "cornmeal":438, "cloves":611, "oil":2800, "chicken":414, "blue cheese":38, "cucumber":223, "dry rosemary":2, "flour tortilla":7, "canola oil":263, "dried tarragon":72, "strawberries":78, "celery":797, "cornish game hens":18, "alfalfa sprouts":13, "fresh cilantro":144, "fresh peaches":21, "nutmeg":1340, "walnuts":521, "bread crumbs":415, "baking soda":3399, "corn syrup":133, "tabasco sauce":272, "ginger":677, "balsamic vinegar":214, "fresh rosemary":50, "lime":93, "pecans":374, "peanut butter":229, "frozen corn":42, "cumin":625, "green onions":622, "canned chicken broth":19, "skim milk":422, "banana":72, "beets":53, "barley":42, "kidney beans":104, "shortening":1377, "parmesan cheese":640, "applesauce":280, "carrots":1057, "cashew":2, "mushrooms":672, "sour cream":1198, "yogurt":150, "brussels sprouts":11, "tofu":57, "cream cheese":399, "cherry tomatoes":64, "salsa":65, "parsley":1139, "green olives":39, "rice vinegar":112, "molasses":609, "chili powder":1111, "beer":166, "spaghetti":94, "raisins":1175, "red wine vinegar":432, "garam masala":143, "chives":167, "cornstarch":1741, "dried basil":353, "orange":122, "catsup":287, "radishes":42, "ground beef":712, "adzuki beans":3, "romaine lettuce":11, "mozzarella cheese":209, "sweet red pepper":89, "canned tuna":2, "cumin seeds":193, "canned peaches":3, "barbecue sauce":32, "raw spinach":3, "red pepper flakes":149, "eggs":6373, "almonds":240, "margarine":1259, "fresh ginger":144, "kale":20, "garlic powder":935, "dried thyme":485, "cream of mushroom soup":93, "low fat milk":10, "vanilla":3155, "whole wheat flour":756, "fresh basil":141, "bean sprouts":83, "shiitake mushrooms":31, "potatoes":857, "almond extract":330, "frozen spinach":38, "canned apricots":2, "celery seeds":57, "allspice":443, "dijon mustard":346, "soy sauce":1292, "broccoli":111, "chicken legs":20, "apples":303, "shell macaroni":2, "white rice":34, "yellow mustard":28, "maple syrup":182, "sweet potatoes":132, "canned tomato paste":3, "red leaf lettuce":2, "egg whites":945, "worcestershire sauce":1000, "dried cilantro":6, "brown sugar":2255, "lime juice":348, "dry mustard":827, "raw shrimp":28, "canned vegetable broth":2, "white flour":164, "blueberries":113, "mayonnaise":493, "chicken wings":57, "vegetable oil":2524, "olive oil":3604, "fresh thyme":81, "curry powder":474, "flour":7567, "vinegar":1359, "lamb shank":2, "white wine":342, "sherry":592, "yam":2, "oats":163, "whipping cream":450, "chicken breast":125, "sugar":12133}, "sugar": {"elbow macaroni":6, "red wine":58, "canned tomato sauce":3, "coconut oil":2, "bacon":128, "canned clams":2, "brown onions":2, "cayenne pepper":136, "lemon juice":1688, "honey":409, "swiss cheese":25, "paprika":255, "bread":46, "ground cinnamon":843, "yeast":874, "egg yolks":1122, "green pepper":202, "baking powder":3957, "saffron":17, "sesame oil":391, "pine nuts":58, "cinnamon":2551, "cream of tartar":479, "avocado":16, "cheddar cheese":67, "tomatoes":272, "white pepper":125, "brown rice":6, "black beans":14, "pinto beans":8, "fresh garlic":9, "cauliflower":26, "frozen peas":14, "butter":4965, "salmon":8, "orange juice":633, "black pepper":297, "lemon":379, "tumeric":25, "black olives":14, "buttermilk":653, "powdered sugar":496, "hoisin sauce":69, "dried oregano":98, "eggplant":56, "capers":41, "cornmeal":195, "cloves":418, "oil":1465, "chicken":69, "blue cheese":12, "cucumber":106, "dry rosemary":2, "canola oil":100, "dried tarragon":13, "strawberries":269, "celery":199, "alfalfa sprouts":4, "cornish game hens":5, "fresh cilantro":25, "nutmeg":955, "walnuts":527, "fresh peaches":34, "bread crumbs":42, "baking soda":2741, "tabasco sauce":84, "corn syrup":183, "balsamic vinegar":71, "ginger":487, "fresh rosemary":8, "lime":51, "pecans":474, "peanut butter":258, "frozen corn":5, "green onions":253, "cumin":93, "canned chicken broth":5, "beets":46, "skim milk":282, "banana":72, "barley":5, "kidney beans":25, "shortening":1042, "parmesan cheese":99, "applesauce":194, "carrots":316, "mushrooms":96, "sour cream":809, "yogurt":69, "brussels sprouts":2, "cream cheese":831, "tofu":32, "cherry tomatoes":21, "salsa":7, "parsley":163, "green olives":15, "rice vinegar":121, "molasses":256, "chili powder":197, "beer":68, "spaghetti":18, "raisins":982, "red wine vinegar":165, "chives":22, "garam masala":18, "cornstarch":1780, "dried basil":80, "orange":208, "catsup":96, "radishes":18, "ground beef":102, "adzuki beans":2, "mozzarella cheese":40, "romaine lettuce":6, "sweet red pepper":23, "cumin seeds":25, "canned peaches":4, "barbecue sauce":10, "red pepper flakes":45, "eggs":5984, "almonds":323, "margarine":1005, "fresh ginger":79, "kale":5, "garlic powder":192, "dried thyme":67, "cream of mushroom soup":3, "low fat milk":3, "vanilla":4410, "whole wheat flour":302, "salt":12133, "fresh basil":31, "bean sprouts":74, "shiitake mushrooms":7, "potatoes":154, "almond extract":510, "frozen spinach":8, "celery seeds":36, "allspice":264, "dijon mustard":83, "soy sauce":1198, "broccoli":30, "chicken legs":6, "apples":384, "yellow mustard":6, "sweet potatoes":56, "maple syrup":74, "white rice":8, "red leaf lettuce":2, "egg whites":1246, "worcestershire sauce":197, "dried cilantro":4, "brown sugar":782, "lime juice":204, "dry mustard":254, "raw shrimp":12, "white flour":93, "blueberries":212, "mayonnaise":159, "chicken wings":23, "fresh thyme":10, "olive oil":673, "vegetable oil":1133, "flour":5965, "curry powder":83, "vinegar":1030, "white wine":87, "sherry":401, "oats":90, "whipping cream":750, "chicken breast":61}, "canned tomato sauce": {"fresh basil":2, "sour cream":3, "elbow macaroni":3, "tofu":3, "potatoes":2, "dried oregano":5, "capers":2, "parsley":2, "lemon juice":2, "honey":2, "oil":2, "chicken":2, "molasses":3, "paprika":4, "chili powder":5, "allspice":2, "spaghetti":4, "ground cinnamon":3, "raisins":4, "celery":2, "green pepper":2, "nutmeg":4, "worcestershire sauce":2, "dried basil":2, "catsup":4, "tabasco sauce":4, "brown sugar":4, "cinnamon":2, "pine nuts":2, "ground beef":2, "dry mustard":7, "fresh rosemary":2, "cheddar cheese":3, "tomatoes":2, "cumin":5, "white pepper":4, "vegetable oil":11, "olive oil":10, "brown rice":2, "eggs":2, "margarine":2, "vinegar":2, "butter":3, "garlic powder":7, "dried thyme":2, "oats":2, "low fat milk":2, "sugar":3, "black pepper":6, "salt":21, "mushrooms":4}, "pine nuts": {"red wine":3, "canned tomato sauce":2, "cayenne pepper":5, "lemon juice":24, "honey":14, "zucchini squash":2, "paprika":2, "bread":2, "ground cinnamon":16, "yeast":2, "egg yolks":4, "green pepper":7, "baking powder":21, "saffron":4, "sesame oil":2, "cinnamon":21, "tomatoes":16, "white pepper":6, "brown rice":3, "fresh garlic":2, "cauliflower":2, "butter":57, "frozen peas":2, "orange juice":3, "black pepper":24, "lemon":8, "black olives":12, "buttermilk":3, "powdered sugar":4, "eggplant":10, "hoisin sauce":5, "dried oregano":8, "capers":10, "cornmeal":5, "cloves":5, "oil":15, "chicken":5, "cucumber":2, "canola oil":4, "dried tarragon":3, "strawberries":3, "celery":4, "nutmeg":11, "walnuts":8, "fresh cilantro":3, "baking soda":10, "bread crumbs":13, "tabasco sauce":2, "ginger":4, "balsamic vinegar":11, "fresh rosemary":2, "lime":3, "pecans":2, "cumin":2, "green onions":8, "canned chicken broth":2, "banana":2, "skim milk":4, "shortening":3, "parmesan cheese":43, "carrots":10, "mushrooms":11, "sour cream":4, "yogurt":5, "cream cheese":8, "cherry tomatoes":6, "parsley":30, "green olives":4, "rice vinegar":2, "chili powder":4, "spaghetti":4, "raisins":29, "red wine vinegar":14, "chives":8, "cornstarch":11, "dried basil":10, "orange":5, "ground beef":6, "mozzarella cheese":4, "cumin seeds":3, "red pepper flakes":4, "almonds":12, "eggs":33, "margarine":4, "fresh ginger":4, "garlic powder":3, "dried thyme":6, "vanilla":8, "whole wheat flour":4, "salt":167, "fresh basil":15, "potatoes":2, "almond extract":5, "frozen spinach":2, "allspice":12, "celery seeds":2, "dijon mustard":7, "soy sauce":8, "broccoli":4, "maple syrup":2, "white rice":2, "egg whites":11, "worcestershire sauce":4, "brown sugar":2, "lime juice":4, "dry mustard":2, "mayonnaise":5, "vegetable oil":17, "olive oil":175, "fresh thyme":2, "curry powder":3, "flour":23, "vinegar":2, "white wine":6, "whipping cream":3, "sugar":58}, "yeast": {"bacon":3, "cayenne pepper":5, "lemon juice":11, "honey":247, "swiss cheese":7, "paprika":7, "ground cinnamon":9, "egg yolks":11, "baking powder":21, "saffron":3, "sesame oil":2, "pine nuts":2, "cinnamon":121, "cream of tartar":4, "cheddar cheese":14, "white pepper":2, "fresh garlic":2, "butter":326, "orange juice":12, "black pepper":17, "lemon":10, "black olives":3, "buttermilk":50, "powdered sugar":15, "hoisin sauce":2, "dried oregano":8, "eggplant":2, "capers":2, "cornmeal":52, "cloves":11, "oil":141, "chicken":2, "blue cheese":5, "cucumber":2, "canola oil":25, "strawberries":4, "celery":7, "alfalfa sprouts":2, "fresh cilantro":2, "fresh peaches":2, "nutmeg":46, "walnuts":13, "baking soda":58, "bread crumbs":2, "tabasco sauce":3, "corn syrup":4, "ginger":30, "fresh rosemary":2, "pecans":17, "peanut butter":3, "cumin":2, "skim milk":10, "banana":14, "shortening":59, "parmesan cheese":30, "applesauce":89, "carrots":5, "mushrooms":8, "sour cream":19, "yogurt":11, "cream cheese":4, "salsa":2, "parsley":18, "molasses":99, "beer":10, "chili powder":3, "raisins":91, "chives":6, "cornstarch":4, "orange":4, "dried basil":10, "mozzarella cheese":8, "barbecue sauce":4, "eggs":166, "almonds":20, "margarine":77, "fresh ginger":2, "garlic powder":19, "dried thyme":3, "cream of mushroom soup":2, "vanilla":32, "whole wheat flour":221, "salt":1230, "fresh basil":2, "bean sprouts":2, "potatoes":5, "almond extract":7, "celery seeds":3, "allspice":13, "dijon mustard":6, "soy sauce":4, "apples":8, "sweet potatoes":3, "yellow mustard":2, "maple syrup":22, "egg whites":19, "worcestershire sauce":4, "brown sugar":100, "lime juice":2, "dry mustard":3, "white flour":51, "blueberries":5, "vegetable oil":92, "olive oil":145, "flour":410, "curry powder":4, "vinegar":9, "white wine":5, "oats":43, "whipping cream":3, "chicken breast":3, "sugar":874}, "shiitake mushrooms": {"salsa":2, "cayenne pepper":3, "parsley":4, "lemon juice":8, "honey":5, "rice vinegar":4, "spaghetti":2, "red wine vinegar":2, "egg yolks":3, "cornstarch":7, "dried basil":4, "orange":3, "sesame oil":13, "cinnamon":2, "mozzarella cheese":2, "tomatoes":2, "white pepper":2, "red pepper flakes":3, "eggs":6, "fresh ginger":3, "frozen peas":2, "butter":13, "kale":2, "dried thyme":4, "lemon":3, "black pepper":7, "salt":31, "fresh basil":2, "bean sprouts":4, "buttermilk":2, "dried oregano":2, "hoisin sauce":2, "eggplant":2, "cornmeal":2, "oil":4, "cucumber":2, "allspice":2, "canola oil":4, "dijon mustard":2, "soy sauce":24, "celery":5, "sweet potatoes":2, "nutmeg":2, "egg whites":2, "worcestershire sauce":2, "brown sugar":2, "balsamic vinegar":3, "dry mustard":2, "fresh rosemary":2, "lime":2, "canned vegetable broth":2, "pecans":2, "green onions":9, "olive oil":21, "vegetable oil":8, "fresh thyme":3, "skim milk":2, "beets":2, "flour":3, "curry powder":3, "white wine":5, "parmesan cheese":6, "carrots":8, "sherry":4, "chicken breast":3, "sugar":7, "mushrooms":4}, "dried thyme": {"elbow macaroni":2, "red wine":13, "canned beef broth":3, "canned tomato sauce":2, "bacon":20, "coconut oil":2, "cayenne pepper":69, "honey":26, "lemon juice":56, "swiss cheese":2, "paprika":92, "camembert cheese":2, "bread":3, "ground cinnamon":19, "yeast":3, "egg yolks":4, "green pepper":15, "baking powder":16, "saffron":3, "sesame oil":2, "cream of tartar":2, "pine nuts":6, "cinnamon":10, "cheddar cheese":4, "tomatoes":48, "white pepper":38, "brown rice":6, "black beans":4, "pinto beans":3, "fresh garlic":4, "cauliflower":3, "butter":111, "frozen peas":10, "salmon":2, "orange juice":15, "lemon":15, "black pepper":112, "black olives":2, "buttermilk":6, "dried oregano":140, "eggplant":7, "capers":6, "cornmeal":11, "cloves":10, "oil":22, "chicken":14, "cucumber":2, "flour tortilla":2, "canola oil":13, "dried tarragon":22, "celery":39, "fresh cilantro":4, "walnuts":6, "nutmeg":14, "bread crumbs":7, "baking soda":7, "tabasco sauce":13, "balsamic vinegar":24, "fresh rosemary":6, "lime":3, "pecans":5, "green onions":26, "cumin":7, "frozen corn":4, "canned chicken broth":4, "beets":2, "skim milk":5, "barley":4, "kidney beans":3, "parmesan cheese":22, "carrots":85, "mushrooms":42, "sour cream":6, "yogurt":2, "brussels sprouts":3, "cream cheese":3, "cherry tomatoes":6, "salsa":2, "parsley":38, "rice vinegar":2, "molasses":4, "beer":7, "chili powder":30, "spaghetti":2, "raisins":5, "red wine vinegar":24, "chives":8, "cornstarch":34, "orange":5, "dried basil":126, "catsup":5, "ground beef":8, "mozzarella cheese":6, "sweet red pepper":5, "cumin seeds":2, "red pepper flakes":17, "almonds":3, "eggs":44, "margarine":21, "fresh ginger":3, "kale":3, "garlic powder":69, "cream of mushroom soup":2, "low fat milk":2, "whole wheat flour":6, "salt":485, "fresh basil":9, "shiitake mushrooms":4, "potatoes":32, "frozen spinach":3, "celery seeds":5, "allspice":15, "dijon mustard":41, "soy sauce":23, "broccoli":4, "apples":5, "chicken legs":5, "sweet potatoes":4, "white rice":5, "yellow mustard":2, "egg whites":7, "worcestershire sauce":39, "brown sugar":22, "lime juice":6, "dry mustard":28, "raw shrimp":2, "mayonnaise":8, "chicken wings":3, "fresh thyme":16, "olive oil":234, "vegetable oil":95, "flour":72, "curry powder":19, "vinegar":7, "white wine":14, "sherry":10, "whipping cream":12, "chicken breast":2, "sugar":67}, "water": {"elbow macaroni":22, "canned beef broth":5, "red wine":73, "canned tomato sauce":14, "bacon":177, "cayenne pepper":269, "lemon juice":1111, "honey":653, "zucchini squash":4, "swiss cheese":31, "paprika":441, "bread":22, "ground cinnamon":324, "yeast":719, "egg yolks":252, "green pepper":332, "baking powder":566, "saffron":27, "sesame oil":219, "cream of tartar":136, "cinnamon":666, "pine nuts":47, "avocado":20, "cheddar cheese":114, "corn tortilla":2, "tomatoes":460, "white pepper":172, "brown rice":86, "black beans":66, "fresh garlic":8, "pinto beans":48, "cauliflower":34, "frozen peas":66, "butter":1763, "salmon":11, "orange juice":234, "black pepper":555, "lemon":250, "tumeric":27, "black olives":12, "buttermilk":93, "powdered sugar":148, "dried oregano":175, "hoisin sauce":37, "eggplant":75, "capers":36, "cornmeal":152, "cloves":229, "oil":1314, "chicken":151, "blue cheese":13, "cucumber":62, "dry rosemary":2, "flour tortilla":2, "canola oil":85, "dried tarragon":20, "strawberries":82, "celery":410, "cornish game hens":3, "alfalfa sprouts":3, "fresh peaches":4, "fresh cilantro":54, "nutmeg":340, "walnuts":135, "baking soda":552, "bread crumbs":118, "corn syrup":72, "tabasco sauce":111, "balsamic vinegar":75, "ginger":266, "fresh rosemary":14, "lime":41, "pecans":106, "peanut butter":76, "frozen corn":23, "green onions":290, "cumin":240, "canned chicken broth":5, "beets":30, "banana":33, "skim milk":102, "barley":57, "kidney beans":53, "shortening":330, "parmesan cheese":198, "applesauce":122, "carrots":628, "mushrooms":279, "sour cream":297, "yogurt":52, "brussels sprouts":8, "tofu":41, "cream cheese":96, "frozen french fries":2, "cherry tomatoes":20, "salsa":37, "parsley":409, "green olives":10, "rice vinegar":65, "molasses":240, "chili powder":523, "beer":38, "spaghetti":31, "raisins":404, "red wine vinegar":146, "chives":39, "garam masala":57, "cornstarch":1444, "dried basil":132, "orange":73, "radishes":17, "catsup":163, "ground beef":325, "adzuki beans":2, "romaine lettuce":6, "mozzarella cheese":60, "sweet red pepper":23, "sweet red onions":2, "canned tuna":2, "cumin seeds":81, "barbecue sauce":19, "red pepper flakes":75, "almonds":92, "eggs":1263, "margarine":449, "fresh ginger":72, "kale":14, "garlic powder":372, "dried thyme":176, "cream of mushroom soup":64, "low fat milk":2, "vanilla":723, "whole wheat flour":287, "salt":7651, "fresh basil":41, "bean sprouts":49, "shiitake mushrooms":20, "potatoes":387, "almond extract":101, "frozen spinach":8, "canned apricots":2, "celery seeds":20, "allspice":158, "dijon mustard":106, "soy sauce":1125, "broccoli":65, "chicken legs":9, "apples":132, "shell macaroni":4, "white rice":23, "yellow mustard":9, "maple syrup":95, "sweet potatoes":51, "canned tomato paste":2, "red leaf lettuce":2, "egg whites":339, "worcestershire sauce":438, "dried cilantro":4, "brown sugar":833, "lime juice":106, "dry mustard":234, "raw shrimp":10, "canned vegetable broth":3, "white flour":62, "blueberries":51, "mayonnaise":82, "chicken wings":27, "fresh thyme":23, "vegetable oil":974, "olive oil":1119, "flour":1951, "curry powder":188, "vinegar":699, "lamb shank":2, "white wine":123, "sherry":351, "yam":3, "oats":57, "whipping cream":199, "chicken breast":60, "sugar":4936}, "canned tuna": {"worcestershire sauce":2, "cheddar cheese":2, "capers":2, "mayonnaise":3, "lemon juice":3, "vegetable oil":2, "olive oil":2, "eggs":2, "bread":2, "celery":2, "egg yolks":2, "vanilla":2, "salt":2, "black pepper":2}, "radishes": {"sour cream":11, "yogurt":4, "red wine":2, "cream cheese":5, "cherry tomatoes":8, "bacon":2, "salsa":2, "parsley":5, "lemon juice":20, "rice vinegar":4, "swiss cheese":2, "paprika":3, "spaghetti":2, "bread":2, "raisins":2, "red wine vinegar":4, "chives":2, "green pepper":12, "cornstarch":5, "orange":2, "sesame oil":6, "cinnamon":2, "avocado":3, "cheddar cheese":2, "romaine lettuce":2, "mozzarella cheese":2, "tomatoes":7, "barbecue sauce":2, "white pepper":3, "eggs":2, "margarine":3, "fresh ginger":3, "cauliflower":2, "frozen peas":2, "butter":6, "orange juice":3, "lemon":2, "black pepper":2, "salt":42, "tumeric":2, "bean sprouts":4, "black olives":2, "potatoes":4, "dried oregano":2, "oil":8, "chicken":4, "cucumber":22, "dijon mustard":4, "soy sauce":10, "celery":10, "broccoli":2, "apples":3, "alfalfa sprouts":3, "walnuts":2, "fresh cilantro":3, "bread crumbs":2, "brown sugar":2, "ginger":4, "balsamic vinegar":3, "lime juice":3, "dry mustard":2, "lime":2, "peanut butter":2, "mayonnaise":9, "green onions":13, "cumin":2, "fresh thyme":2, "olive oil":13, "vegetable oil":5, "flour":2, "curry powder":2, "kidney beans":2, "vinegar":8, "carrots":19, "sherry":3, "whipping cream":2, "chicken breast":2, "sugar":18, "mushrooms":4}, "dried oregano": {"elbow macaroni":2, "red wine":12, "canned tomato sauce":5, "bacon":9, "cayenne pepper":69, "lemon juice":70, "honey":13, "swiss cheese":6, "paprika":66, "camembert cheese":2, "bread":3, "ground cinnamon":20, "dried bay leaf":2, "yeast":8, "egg yolks":4, "green pepper":40, "baking powder":11, "pine nuts":8, "cinnamon":11, "cream of tartar":2, "avocado":12, "cheddar cheese":14, "tomatoes":90, "white pepper":13, "brown rice":6, "black beans":8, "pinto beans":6, "fresh garlic":5, "frozen peas":8, "butter":58, "salmon":2, "orange juice":8, "black pepper":105, "lemon":16, "tumeric":3, "black olives":11, "buttermilk":4, "eggplant":24, "capers":22, "cornmeal":14, "cloves":9, "oil":35, "chicken":15, "blue cheese":2, "cucumber":9, "flour tortilla":4, "canola oil":16, "dried tarragon":12, "celery":18, "walnuts":5, "nutmeg":7, "fresh cilantro":15, "bread crumbs":14, "baking soda":5, "tabasco sauce":10, "balsamic vinegar":21, "fresh rosemary":2, "lime":12, "pecans":2, "peanut butter":2, "cumin":28, "green onions":28, "canned chicken broth":6, "beets":2, "skim milk":14, "barley":4, "kidney beans":9, "applesauce":3, "parmesan cheese":66, "carrots":43, "mushrooms":28, "sour cream":21, "yogurt":5, "brussels sprouts":2, "cream cheese":6, "cherry tomatoes":4, "salsa":13, "parsley":28, "green olives":3, "rice vinegar":3, "molasses":3, "beer":10, "chili powder":107, "spaghetti":15, "raisins":10, "red wine vinegar":48, "cornstarch":17, "orange":3, "dried basil":253, "radishes":2, "catsup":5, "ground beef":37, "mozzarella cheese":37, "sweet red pepper":5, "cumin seeds":11, "barbecue sauce":2, "red pepper flakes":17, "almonds":3, "eggs":51, "margarine":11, "fresh ginger":3, "kale":2, "garlic powder":108, "dried thyme":140, "cream of mushroom soup":2, "whole wheat flour":7, "salt":472, "fresh basil":19, "shiitake mushrooms":2, "potatoes":25, "frozen spinach":3, "allspice":6, "dijon mustard":25, "soy sauce":14, "broccoli":7, "chicken legs":3, "white rice":6, "sweet potatoes":2, "red leaf lettuce":2, "egg whites":11, "worcestershire sauce":36, "brown sugar":15, "lime juice":11, "dry mustard":14, "raw shrimp":2, "white flour":3, "canned vegetable broth":2, "mayonnaise":15, "chicken wings":3, "olive oil":358, "vegetable oil":87, "fresh thyme":3, "flour":40, "curry powder":2, "vinegar":16, "white wine":16, "sherry":6, "whipping cream":5, "chicken breast":9, "sugar":98}, "bread": {"red wine":2, "elbow macaroni":2, "bacon":8, "cayenne pepper":7, "lemon juice":23, "honey":7, "swiss cheese":4, "paprika":23, "ground cinnamon":7, "egg yolks":8, "green pepper":10, "baking powder":9, "saffron":2, "pine nuts":2, "cinnamon":18, "cheddar cheese":12, "tomatoes":10, "white pepper":2, "cauliflower":2, "butter":93, "frozen peas":2, "orange juice":7, "black pepper":12, "lemon":5, "powdered sugar":5, "dried oregano":3, "eggplant":2, "capers":5, "cornmeal":2, "oil":18, "chicken":4, "cucumber":4, "canola oil":3, "celery":20, "alfalfa sprouts":2, "walnuts":3, "nutmeg":15, "bread crumbs":4, "baking soda":2, "tabasco sauce":4, "fresh rosemary":2, "pecans":3, "peanut butter":3, "green onions":4, "cumin":2, "skim milk":7, "banana":2, "shortening":3, "parmesan cheese":15, "carrots":6, "mushrooms":7, "sour cream":6, "tofu":2, "cream cheese":8, "parsley":29, "green olives":2, "molasses":3, "chili powder":7, "beer":3, "raisins":16, "red wine vinegar":3, "chives":3, "cornstarch":7, "orange":2, "radishes":2, "catsup":4, "ground beef":18, "mozzarella cheese":2, "sweet red pepper":2, "canned tuna":2, "cumin seeds":2, "barbecue sauce":2, "almonds":3, "eggs":85, "margarine":11, "garlic powder":5, "dried thyme":3, "cream of mushroom soup":5, "vanilla":21, "whole wheat flour":2, "salt":131, "potatoes":10, "allspice":7, "dijon mustard":3, "soy sauce":5, "apples":12, "maple syrup":7, "egg whites":4, "worcestershire sauce":11, "brown sugar":10, "dry mustard":18, "blueberries":2, "mayonnaise":21, "olive oil":25, "vegetable oil":9, "flour":32, "curry powder":5, "vinegar":4, "white wine":4, "sherry":3, "whipping cream":4, "sugar":46}, "chicken breast": {"red wine":2, "bacon":2, "cayenne pepper":8, "lemon juice":21, "honey":8, "swiss cheese":3, "paprika":18, "yeast":3, "egg yolks":3, "green pepper":12, "baking powder":3, "saffron":2, "sesame oil":21, "cinnamon":8, "cheddar cheese":6, "tomatoes":13, "white pepper":9, "black beans":2, "fresh garlic":2, "cauliflower":2, "frozen peas":2, "butter":19, "orange juice":6, "black pepper":13, "lemon":5, "black olives":2, "powdered sugar":2, "eggplant":2, "dried oregano":9, "hoisin sauce":2, "capers":3, "cloves":3, "oil":82, "chicken":2, "blue cheese":2, "cucumber":2, "canola oil":6, "flour tortilla":2, "dried tarragon":3, "celery":15, "fresh cilantro":3, "bread crumbs":4, "tabasco sauce":4, "ginger":21, "balsamic vinegar":3, "lime":4, "pecans":5, "peanut butter":3, "green onions":18, "cumin":11, "frozen corn":2, "canned chicken broth":3, "skim milk":2, "beets":2, "shortening":2, "parmesan cheese":12, "carrots":10, "mushrooms":14, "sour cream":13, "yogurt":6, "cream cheese":2, "salsa":5, "parsley":5, "beer":2, "chili powder":5, "spaghetti":2, "raisins":3, "red wine vinegar":5, "garam masala":2, "cornstarch":86, "dried basil":3, "radishes":2, "catsup":6, "mozzarella cheese":7, "romaine lettuce":2, "sweet red pepper":4, "cumin seeds":3, "red pepper flakes":2, "almonds":3, "eggs":13, "margarine":11, "fresh ginger":3, "garlic powder":9, "dried thyme":2, "cream of mushroom soup":2, "salt":125, "fresh basil":4, "bean sprouts":10, "shiitake mushrooms":3, "potatoes":3, "allspice":3, "dijon mustard":6, "soy sauce":85, "broccoli":3, "apples":2, "white rice":2, "maple syrup":2, "egg whites":6, "worcestershire sauce":4, "brown sugar":8, "lime juice":7, "dry mustard":4, "raw shrimp":2, "mayonnaise":6, "olive oil":35, "vegetable oil":21, "curry powder":11, "flour":24, "vinegar":12, "white wine":6, "sherry":34, "sugar":61}, "dried tarragon": {"sour cream":4, "yogurt":2, "cream cheese":2, "bacon":4, "cayenne pepper":7, "parsley":7, "green olives":3, "rice vinegar":2, "lemon juice":34, "honey":11, "molasses":2, "chili powder":2, "paprika":12, "ground cinnamon":2, "raisins":2, "red wine vinegar":10, "chives":5, "egg yolks":2, "green pepper":3, "baking powder":3, "cornstarch":5, "dried basil":11, "sesame oil":2, "pine nuts":3, "cinnamon":2, "tomatoes":6, "white pepper":10, "brown rice":3, "eggs":13, "margarine":4, "butter":33, "garlic powder":10, "dried thyme":22, "orange juice":3, "whole wheat flour":2, "lemon":6, "salt":72, "black pepper":13, "black olives":2, "potatoes":4, "dried oregano":12, "capers":5, "oil":3, "chicken":4, "cucumber":3, "canola oil":2, "allspice":2, "celery seeds":2, "dijon mustard":33, "soy sauce":7, "celery":8, "apples":2, "alfalfa sprouts":2, "fresh cilantro":2, "nutmeg":4, "bread crumbs":4, "worcestershire sauce":6, "tabasco sauce":3, "brown sugar":7, "ginger":2, "balsamic vinegar":6, "lime juice":3, "dry mustard":13, "raw shrimp":2, "mayonnaise":12, "cumin":2, "green onions":9, "fresh thyme":2, "vegetable oil":14, "olive oil":46, "beets":2, "skim milk":4, "curry powder":3, "flour":11, "vinegar":4, "parmesan cheese":3, "white wine":4, "carrots":5, "sherry":4, "whipping cream":8, "chicken breast":3, "mushrooms":14, "sugar":13}, "pecans": {"cayenne pepper":13, "lemon juice":41, "honey":24, "paprika":15, "ground cinnamon":45, "bread":3, "yeast":17, "egg yolks":24, "green pepper":3, "baking powder":138, "sesame oil":2, "pine nuts":2, "cinnamon":131, "cream of tartar":9, "cheddar cheese":5, "white pepper":3, "brown rice":3, "butter":328, "orange juice":23, "black pepper":14, "lemon":6, "black olives":4, "buttermilk":38, "powdered sugar":55, "hoisin sauce":2, "dried oregano":2, "capers":2, "cornmeal":3, "cloves":24, "oil":42, "chicken":6, "canola oil":3, "strawberries":6, "celery":19, "nutmeg":53, "walnuts":14, "baking soda":133, "bread crumbs":5, "corn syrup":21, "tabasco sauce":4, "balsamic vinegar":2, "ginger":7, "fresh rosemary":3, "peanut butter":7, "green onions":8, "cumin":2, "skim milk":5, "banana":9, "shortening":34, "applesauce":10, "parmesan cheese":2, "carrots":12, "mushrooms":9, "sour cream":42, "yogurt":6, "tofu":2, "cream cheese":63, "cherry tomatoes":3, "salsa":4, "parsley":14, "molasses":9, "chili powder":3, "beer":3, "raisins":64, "red wine vinegar":3, "chives":3, "cornstarch":24, "dried basil":3, "orange":9, "catsup":2, "ground beef":2, "mozzarella cheese":2, "eggs":304, "almonds":7, "margarine":66, "garlic powder":4, "dried thyme":5, "vanilla":244, "whole wheat flour":15, "salt":374, "shiitake mushrooms":2, "potatoes":6, "almond extract":10, "frozen spinach":3, "allspice":23, "dijon mustard":4, "soy sauce":4, "broccoli":4, "apples":26, "maple syrup":14, "sweet potatoes":12, "egg whites":32, "worcestershire sauce":9, "brown sugar":151, "lime juice":4, "dry mustard":5, "blueberries":5, "mayonnaise":24, "vegetable oil":25, "olive oil":13, "fresh thyme":4, "curry powder":2, "flour":257, "vinegar":9, "sherry":3, "oats":8, "whipping cream":33, "chicken breast":5, "sugar":474}, "tomatoes": {"elbow macaroni":4, "red wine":37, "canned tomato sauce":2, "coconut oil":2, "bacon":69, "cayenne pepper":100, "lemon juice":194, "honey":19, "swiss cheese":17, "paprika":143, "bread":10, "ground cinnamon":23, "egg yolks":9, "green pepper":245, "baking powder":5, "saffron":26, "sesame oil":9, "cream of tartar":2, "cinnamon":70, "pine nuts":16, "avocado":38, "cheddar cheese":62, "corn tortilla":2, "white pepper":28, "brown rice":28, "black beans":32, "fresh garlic":2, "pinto beans":23, "cauliflower":23, "frozen peas":19, "butter":259, "salmon":9, "orange juice":14, "lemon":55, "black pepper":187, "tumeric":13, "black olives":52, "buttermilk":3, "hoisin sauce":2, "eggplant":94, "dried oregano":90, "capers":37, "cornmeal":5, "cloves":41, "oil":250, "chicken":53, "blue cheese":10, "cucumber":55, "canola oil":23, "dried tarragon":6, "celery":157, "cornish game hens":2, "alfalfa sprouts":5, "walnuts":5, "fresh cilantro":41, "nutmeg":25, "baking soda":4, "bread crumbs":30, "corn syrup":2, "tabasco sauce":50, "balsamic vinegar":43, "ginger":40, "fresh rosemary":6, "lime":12, "peanut butter":8, "frozen corn":9, "green onions":121, "cumin":177, "canned chicken broth":2, "banana":4, "beets":3, "skim milk":5, "barley":16, "kidney beans":59, "shortening":15, "parmesan cheese":85, "carrots":195, "mushrooms":122, "sour cream":87, "yogurt":15, "brussels sprouts":2, "tofu":13, "cream cheese":16, "cherry tomatoes":5, "salsa":15, "parsley":245, "green olives":16, "rice vinegar":4, "molasses":9, "chili powder":249, "beer":20, "spaghetti":23, "raisins":32, "red wine vinegar":83, "garam masala":43, "chives":23, "cornstarch":64, "orange":6, "dried basil":77, "radishes":7, "catsup":8, "ground beef":133, "romaine lettuce":3, "mozzarella cheese":36, "sweet red pepper":13, "cumin seeds":34, "barbecue sauce":2, "raw spinach":2, "red pepper flakes":26, "eggs":126, "almonds":18, "margarine":37, "fresh ginger":16, "kale":2, "garlic powder":77, "dried thyme":48, "cream of mushroom soup":4, "whole wheat flour":2, "salt":1322, "fresh basil":52, "bean sprouts":4, "shiitake mushrooms":2, "potatoes":153, "frozen spinach":7, "celery seeds":4, "allspice":32, "dijon mustard":23, "soy sauce":61, "broccoli":14, "chicken legs":4, "apples":10, "maple syrup":3, "shell macaroni":4, "yellow mustard":2, "sweet potatoes":9, "white rice":7, "canned tomato paste":2, "egg whites":7, "worcestershire sauce":70, "dried cilantro":2, "brown sugar":55, "lime juice":75, "dry mustard":25, "raw shrimp":4, "white flour":3, "mayonnaise":52, "chicken wings":5, "fresh thyme":11, "olive oil":667, "vegetable oil":196, "flour":173, "curry powder":49, "vinegar":114, "white wine":49, "sherry":22, "oats":2, "whipping cream":13, "chicken breast":13, "sugar":272}, "red wine": {"bacon":19, "cayenne pepper":9, "lemon juice":22, "honey":10, "paprika":21, "ground cinnamon":8, "bread":2, "egg yolks":9, "green pepper":19, "baking powder":3, "saffron":2, "sesame oil":8, "pine nuts":3, "cinnamon":13, "avocado":2, "cheddar cheese":2, "tomatoes":37, "white pepper":10, "black beans":4, "fresh garlic":2, "pinto beans":2, "frozen peas":3, "butter":75, "orange juice":8, "lemon":10, "black pepper":44, "black olives":4, "buttermilk":3, "dried oregano":12, "eggplant":6, "capers":7, "cloves":20, "oil":33, "chicken":10, "cucumber":2, "strawberries":3, "celery":11, "fresh cilantro":2, "walnuts":5, "nutmeg":11, "bread crumbs":6, "tabasco sauce":3, "ginger":4, "balsamic vinegar":9, "fresh rosemary":3, "lime":3, "cumin":16, "green onions":8, "skim milk":2, "barley":2, "kidney beans":4, "shortening":2, "applesauce":3, "parmesan cheese":15, "carrots":38, "mushrooms":42, "sour cream":14, "yogurt":2, "cream cheese":2, "salsa":2, "parsley":32, "molasses":4, "beer":2, "chili powder":17, "spaghetti":3, "raisins":8, "red wine vinegar":19, "chives":3, "cornstarch":10, "dried basil":12, "orange":6, "catsup":3, "radishes":2, "ground beef":12, "mozzarella cheese":4, "sweet red pepper":2, "cumin seeds":3, "barbecue sauce":2, "red pepper flakes":6, "eggs":14, "almonds":4, "margarine":5, "fresh ginger":2, "garlic powder":7, "dried thyme":13, "cream of mushroom soup":3, "vanilla":3, "salt":165, "fresh basil":10, "potatoes":10, "almond extract":2, "allspice":9, "dijon mustard":7, "soy sauce":18, "broccoli":2, "apples":14, "chicken legs":2, "sweet potatoes":2, "white rice":2, "maple syrup":3, "egg whites":2, "worcestershire sauce":21, "brown sugar":25, "lime juice":7, "dry mustard":6, "vegetable oil":22, "fresh thyme":3, "olive oil":109, "flour":68, "curry powder":3, "vinegar":17, "white wine":7, "sherry":5, "whipping cream":3, "chicken breast":2, "sugar":58}, "chili powder": {"canned beef broth":4, "elbow macaroni":14, "red wine":17, "canned tomato sauce":5, "bacon":26, "cayenne pepper":182, "honey":44, "lemon juice":99, "zucchini squash":2, "paprika":281, "bread":7, "ground cinnamon":37, "yeast":3, "egg yolks":3, "green pepper":204, "baking powder":23, "saffron":3, "sesame oil":14, "pine nuts":4, "cinnamon":62, "avocado":20, "cheddar cheese":88, "corn tortilla":2, "tomatoes":249, "white pepper":39, "brown rice":18, "black beans":58, "pinto beans":59, "cauliflower":3, "frozen peas":5, "butter":102, "orange juice":15, "black pepper":229, "lemon":23, "tumeric":14, "black olives":21, "buttermilk":9, "dried oregano":107, "eggplant":12, "capers":3, "cornmeal":35, "cloves":34, "oil":158, "chicken":18, "blue cheese":4, "cucumber":8, "canola oil":27, "dried tarragon":2, "strawberries":2, "celery":78, "alfalfa sprouts":2, "walnuts":4, "fresh cilantro":39, "nutmeg":18, "baking soda":12, "bread crumbs":9, "corn syrup":3, "tabasco sauce":77, "balsamic vinegar":5, "ginger":34, "lime":8, "pecans":3, "peanut butter":20, "cumin":403, "green onions":66, "frozen corn":17, "canned chicken broth":2, "banana":2, "skim milk":17, "kidney beans":104, "shortening":14, "applesauce":3, "parmesan cheese":10, "carrots":49, "mushrooms":24, "sour cream":74, "yogurt":14, "tofu":14, "cream cheese":12, "cherry tomatoes":5, "salsa":50, "parsley":48, "green olives":5, "molasses":32, "beer":45, "spaghetti":12, "raisins":21, "red wine vinegar":44, "chives":6, "garam masala":21, "cornstarch":28, "dried basil":22, "catsup":65, "ground beef":250, "romaine lettuce":2, "mozzarella cheese":3, "sweet red pepper":13, "cumin seeds":27, "barbecue sauce":16, "red pepper flakes":21, "almonds":5, "eggs":48, "margarine":37, "fresh ginger":7, "garlic powder":262, "dried thyme":30, "cream of mushroom soup":15, "whole wheat flour":6, "salt":1111, "fresh basil":2, "bean sprouts":4, "potatoes":29, "frozen spinach":2, "allspice":38, "dijon mustard":22, "soy sauce":58, "broccoli":3, "apples":7, "chicken legs":2, "yellow mustard":2, "sweet potatoes":5, "white rice":5, "maple syrup":7, "egg whites":5, "worcestershire sauce":190, "dried cilantro":3, "brown sugar":142, "lime juice":58, "dry mustard":94, "raw shrimp":2, "white flour":4, "canned vegetable broth":2, "mayonnaise":17, "chicken wings":10, "fresh thyme":2, "vegetable oil":221, "olive oil":232, "flour":126, "curry powder":46, "vinegar":134, "white wine":9, "sherry":6, "oats":2, "whipping cream":4, "chicken breast":5, "sugar":197}, "catsup": {"red wine":3, "elbow macaroni":2, "canned tomato sauce":4, "bacon":32, "cayenne pepper":21, "lemon juice":78, "honey":38, "paprika":60, "ground cinnamon":4, "bread":4, "egg yolks":2, "green pepper":22, "baking powder":3, "sesame oil":5, "cinnamon":11, "avocado":4, "cheddar cheese":5, "tomatoes":8, "white pepper":5, "fresh garlic":2, "cauliflower":2, "butter":41, "frozen peas":2, "orange juice":5, "lemon":14, "black pepper":42, "tumeric":3, "powdered sugar":2, "hoisin sauce":13, "dried oregano":5, "capers":2, "cornmeal":2, "cloves":5, "oil":58, "chicken":12, "blue cheese":4, "cucumber":2, "canola oil":2, "celery":23, "nutmeg":9, "bread crumbs":10, "baking soda":4, "tabasco sauce":20, "ginger":10, "balsamic vinegar":2, "pecans":2, "peanut butter":2, "cumin":11, "green onions":10, "canned chicken broth":2, "beets":2, "barley":3, "kidney beans":5, "shortening":10, "applesauce":4, "parmesan cheese":4, "carrots":23, "mushrooms":11, "sour cream":14, "cream cheese":6, "cherry tomatoes":3, "salsa":4, "parsley":12, "green olives":2, "molasses":31, "chili powder":65, "beer":11, "raisins":4, "red wine vinegar":17, "chives":3, "cornstarch":49, "orange":3, "dried basil":4, "ground beef":68, "mozzarella cheese":2, "sweet red pepper":2, "barbecue sauce":3, "red pepper flakes":2, "eggs":26, "margarine":9, "fresh ginger":2, "garlic powder":40, "dried thyme":5, "cream of mushroom soup":5, "low fat milk":2, "whole wheat flour":2, "salt":287, "bean sprouts":2, "potatoes":11, "allspice":8, "celery seeds":2, "dijon mustard":6, "soy sauce":90, "chicken legs":2, "maple syrup":4, "yellow mustard":3, "sweet potatoes":2, "egg whites":3, "worcestershire sauce":199, "brown sugar":159, "lime juice":6, "dry mustard":67, "white flour":2, "mayonnaise":25, "chicken wings":13, "vegetable oil":38, "olive oil":11, "flour":43, "curry powder":7, "vinegar":146, "white wine":8, "sherry":17, "oats":2, "whipping cream":3, "chicken breast":6, "sugar":96}, "apples": {"elbow macaroni":2, "red wine":14, "bacon":7, "cayenne pepper":6, "honey":50, "lemon juice":109, "paprika":8, "ground cinnamon":58, "bread":12, "yeast":8, "egg yolks":10, "green pepper":5, "baking powder":115, "cinnamon":331, "cream of tartar":2, "cheddar cheese":7, "tomatoes":10, "brown rice":3, "butter":187, "salmon":2, "orange juice":33, "black pepper":15, "lemon":27, "buttermilk":7, "powdered sugar":17, "cornmeal":2, "cloves":47, "oil":54, "chicken":7, "cucumber":2, "canola oil":10, "dried tarragon":2, "strawberries":6, "celery":22, "alfalfa sprouts":2, "cornish game hens":3, "nutmeg":108, "walnuts":41, "baking soda":83, "bread crumbs":13, "corn syrup":7, "tabasco sauce":3, "ginger":23, "pecans":26, "peanut butter":4, "green onions":4, "cumin":4, "beets":2, "skim milk":11, "banana":6, "kidney beans":2, "shortening":25, "parmesan cheese":2, "applesauce":20, "carrots":24, "mushrooms":5, "sour cream":17, "yogurt":9, "cream cheese":11, "salsa":2, "parsley":10, "molasses":9, "chili powder":7, "beer":4, "raisins":110, "red wine vinegar":5, "cornstarch":40, "orange":15, "radishes":3, "ground beef":6, "sweet red pepper":2, "eggs":130, "almonds":14, "margarine":57, "fresh ginger":3, "garlic powder":3, "dried thyme":5, "vanilla":113, "whole wheat flour":16, "salt":303, "potatoes":11, "almond extract":6, "celery seeds":2, "allspice":24, "dijon mustard":6, "sweet potatoes":14, "maple syrup":12, "egg whites":28, "worcestershire sauce":6, "brown sugar":155, "lime juice":5, "dry mustard":7, "white flour":2, "blueberries":7, "mayonnaise":16, "chicken wings":2, "vegetable oil":28, "olive oil":13, "flour":225, "curry powder":29, "vinegar":35, "white wine":9, "sherry":4, "oats":10, "whipping cream":10, "chicken breast":2, "sugar":384}, "black olives": {"red wine":4, "elbow macaroni":2, "bacon":3, "cayenne pepper":5, "lemon juice":22, "honey":4, "swiss cheese":2, "paprika":8, "ground cinnamon":2, "yeast":3, "green pepper":27, "baking powder":5, "saffron":2, "pine nuts":12, "cinnamon":3, "avocado":4, "cheddar cheese":19, "tomatoes":52, "white pepper":3, "brown rice":2, "black beans":4, "fresh garlic":2, "pinto beans":4, "cauliflower":3, "frozen peas":2, "butter":21, "black pepper":15, "lemon":9, "eggplant":8, "dried oregano":11, "capers":28, "cornmeal":3, "cloves":3, "oil":13, "chicken":5, "blue cheese":4, "cucumber":6, "canola oil":2, "dried tarragon":2, "celery":19, "alfalfa sprouts":2, "fresh cilantro":4, "nutmeg":2, "bread crumbs":3, "tabasco sauce":7, "balsamic vinegar":5, "fresh rosemary":3, "pecans":4, "cumin":13, "green onions":28, "kidney beans":3, "shortening":3, "parmesan cheese":19, "carrots":7, "mushrooms":14, "sour cream":24, "yogurt":2, "tofu":2, "cream cheese":26, "cherry tomatoes":3, "salsa":6, "parsley":26, "green olives":21, "chili powder":21, "spaghetti":3, "raisins":4, "red wine vinegar":13, "chives":4, "cornstarch":2, "dried basil":11, "radishes":2, "ground beef":5, "romaine lettuce":3, "mozzarella cheese":5, "red pepper flakes":4, "eggs":22, "margarine":7, "fresh ginger":2, "garlic powder":11, "dried thyme":2, "whole wheat flour":3, "salt":73, "fresh basil":13, "potatoes":7, "frozen spinach":2, "dijon mustard":3, "broccoli":2, "maple syrup":3, "worcestershire sauce":5, "brown sugar":5, "lime juice":4, "dry mustard":2, "raw shrimp":2, "white flour":2, "mayonnaise":13, "fresh thyme":2, "vegetable oil":8, "olive oil":116, "flour":9, "curry powder":4, "vinegar":10, "white wine":8, "sherry":2, "whipping cream":3, "chicken breast":2, "sugar":14}, "white pepper": {"canned beef broth":2, "elbow macaroni":7, "red wine":10, "canned tomato sauce":4, "bacon":18, "cayenne pepper":84, "honey":29, "lemon juice":108, "swiss cheese":13, "paprika":118, "bread":2, "ground cinnamon":5, "yeast":2, "egg yolks":22, "green pepper":22, "baking powder":14, "saffron":8, "sesame oil":54, "cream of tartar":3, "pine nuts":6, "cinnamon":14, "avocado":5, "cheddar cheese":15, "tomatoes":28, "brown rice":7, "black beans":4, "fresh garlic":2, "pinto beans":2, "cauliflower":5, "frozen peas":2, "butter":192, "salmon":2, "orange juice":9, "lemon":18, "black pepper":134, "tumeric":3, "black olives":3, "buttermilk":10, "powdered sugar":2, "hoisin sauce":4, "dried oregano":13, "eggplant":7, "capers":7, "cornmeal":5, "cloves":12, "oil":54, "chicken":9, "blue cheese":6, "cucumber":12, "dry rosemary":2, "flour tortilla":2, "dried tarragon":10, "strawberries":2, "celery":46, "alfalfa sprouts":2, "cornish game hens":2, "fresh cilantro":8, "nutmeg":62, "walnuts":2, "bread crumbs":26, "baking soda":9, "tabasco sauce":26, "balsamic vinegar":8, "ginger":23, "fresh rosemary":2, "lime":4, "pecans":3, "peanut butter":3, "frozen corn":2, "cumin":34, "green onions":46, "canned chicken broth":3, "banana":2, "beets":3, "skim milk":17, "kidney beans":2, "shortening":3, "parmesan cheese":33, "carrots":39, "mushrooms":38, "sour cream":49, "yogurt":5, "cream cheese":20, "cherry tomatoes":4, "salsa":5, "parsley":52, "green olives":2, "rice vinegar":11, "molasses":5, "chili powder":39, "beer":5, "spaghetti":2, "raisins":7, "red wine vinegar":19, "chives":18, "garam masala":4, "cornstarch":95, "orange":5, "dried basil":15, "radishes":3, "catsup":5, "ground beef":14, "mozzarella cheese":9, "romaine lettuce":2, "sweet red pepper":5, "cumin seeds":3, "barbecue sauce":2, "red pepper flakes":6, "almonds":4, "eggs":97, "margarine":40, "fresh ginger":9, "garlic powder":120, "dried thyme":38, "cream of mushroom soup":4, "low fat milk":2, "whole wheat flour":4, "salt":722, "fresh basil":10, "bean sprouts":4, "shiitake mushrooms":2, "potatoes":31, "frozen spinach":4, "celery seeds":5, "allspice":12, "dijon mustard":28, "soy sauce":70, "broccoli":8, "white rice":4, "sweet potatoes":4, "egg whites":12, "worcestershire sauce":46, "dried cilantro":2, "brown sugar":25, "lime juice":18, "dry mustard":57, "raw shrimp":2, "white flour":2, "mayonnaise":33, "chicken wings":2, "fresh thyme":4, "vegetable oil":66, "olive oil":126, "flour":140, "curry powder":29, "vinegar":33, "white wine":35, "sherry":22, "whipping cream":28, "chicken breast":9, "sugar":125}, "balsamic vinegar": {"red wine":9, "bacon":9, "cayenne pepper":7, "honey":24, "lemon juice":47, "swiss cheese":2, "paprika":4, "ground cinnamon":2, "egg yolks":3, "green pepper":2, "sesame oil":9, "cinnamon":4, "pine nuts":11, "avocado":2, "tomatoes":43, "white pepper":8, "brown rice":3, "black beans":7, "fresh garlic":3, "cauliflower":2, "frozen peas":4, "butter":43, "orange juice":14, "black pepper":45, "lemon":11, "tumeric":2, "black olives":5, "buttermilk":2, "eggplant":22, "dried oregano":21, "hoisin sauce":4, "capers":19, "cornmeal":4, "cloves":5, "oil":10, "chicken":4, "blue cheese":4, "cucumber":5, "canola oil":8, "dried tarragon":6, "strawberries":8, "celery":5, "cornish game hens":2, "nutmeg":2, "fresh cilantro":3, "walnuts":7, "bread crumbs":8, "tabasco sauce":4, "ginger":8, "fresh rosemary":5, "lime":4, "pecans":2, "green onions":19, "frozen corn":2, "cumin":8, "banana":3, "beets":4, "barley":3, "kidney beans":2, "parmesan cheese":16, "carrots":17, "mushrooms":20, "sour cream":6, "brussels sprouts":2, "tofu":3, "cherry tomatoes":11, "salsa":2, "parsley":24, "green olives":2, "rice vinegar":6, "molasses":7, "chili powder":5, "spaghetti":2, "raisins":7, "red wine vinegar":13, "chives":8, "cornstarch":11, "dried basil":22, "orange":7, "radishes":3, "catsup":2, "romaine lettuce":2, "mozzarella cheese":8, "sweet red pepper":5, "sweet red onions":2, "red pepper flakes":9, "eggs":7, "margarine":6, "fresh ginger":4, "kale":2, "garlic powder":5, "dried thyme":24, "salt":214, "fresh basil":20, "bean sprouts":2, "shiitake mushrooms":3, "potatoes":2, "celery seeds":2, "allspice":5, "dijon mustard":56, "soy sauce":33, "broccoli":2, "yellow mustard":2, "maple syrup":4, "sweet potatoes":5, "egg whites":4, "worcestershire sauce":11, "brown sugar":27, "lime juice":5, "dry mustard":7, "blueberries":2, "mayonnaise":3, "chicken wings":3, "olive oil":281, "vegetable oil":23, "fresh thyme":10, "flour":20, "curry powder":5, "white wine":11, "sherry":3, "yam":2, "chicken breast":3, "sugar":71}, "blueberries": {"sour cream":14, "yogurt":5, "cream cheese":17, "honey":17, "lemon juice":45, "molasses":9, "ground cinnamon":14, "bread":2, "raisins":5, "yeast":5, "egg yolks":8, "baking powder":118, "cornstarch":35, "orange":6, "cream of tartar":2, "cinnamon":43, "canned peaches":2, "eggs":68, "almonds":2, "margarine":18, "fresh ginger":2, "butter":61, "vanilla":43, "orange juice":20, "whole wheat flour":11, "salt":113, "lemon":5, "potatoes":2, "buttermilk":19, "powdered sugar":7, "almond extract":3, "cornmeal":4, "oil":11, "allspice":3, "canola oil":7, "strawberries":38, "apples":7, "maple syrup":7, "walnuts":3, "nutmeg":16, "egg whites":20, "baking soda":51, "corn syrup":4, "brown sugar":13, "ginger":2, "balsamic vinegar":2, "lime juice":5, "lime":2, "white flour":2, "pecans":5, "olive oil":2, "vegetable oil":20, "banana":13, "skim milk":18, "flour":86, "vinegar":2, "shortening":11, "applesauce":5, "white wine":2, "oats":4, "whipping cream":3, "sugar":212}, "shell macaroni": {"tabasco sauce":3, "ground beef":5, "avocado":2, "cheddar cheese":3, "parsley":3, "tomatoes":4, "mayonnaise":2, "lemon juice":2, "oil":3, "flour":2, "butter":2, "garlic powder":4, "celery":4, "carrots":3, "green pepper":2, "salt":2, "bread crumbs":2, "mushrooms":2}, "sriracha hot chili sauce":{"black beans":2, "oil":2}, "canned beef broth": {"tumeric":2, "sour cream":3, "bacon":2, "parsley":2, "cayenne pepper":3, "lemon juice":2, "honey":2, "chili powder":4, "paprika":3, "soy sauce":5, "fresh cilantro":2, "cornstarch":4, "brown sugar":2, "ginger":3, "ground beef":2, "cheddar cheese":2, "cumin":3, "white pepper":2, "vegetable oil":5, "olive oil":6, "flour":2, "butter":2, "garlic powder":2, "dried thyme":3, "parmesan cheese":2, "lemon":3, "salt":7, "mushrooms":2}, "fresh ginger": {"red wine":2, "brown onions":2, "cayenne pepper":20, "honey":15, "lemon juice":34, "paprika":11, "ground cinnamon":10, "yeast":2, "egg yolks":3, "green pepper":6, "baking powder":3, "saffron":4, "sesame oil":47, "cream of tartar":2, "cinnamon":8, "pine nuts":4, "tomatoes":16, "white pepper":9, "brown rice":2, "black beans":3, "fresh garlic":7, "cauliflower":2, "frozen peas":2, "butter":8, "salmon":2, "orange juice":7, "black pepper":11, "lemon":10, "tumeric":3, "black olives":2, "buttermilk":4, "dried oregano":3, "eggplant":3, "hoisin sauce":10, "cloves":8, "oil":28, "chicken":8, "cucumber":6, "canola oil":8, "celery":5, "walnuts":3, "fresh peaches":2, "fresh cilantro":10, "nutmeg":4, "baking soda":6, "tabasco sauce":3, "balsamic vinegar":4, "lime":5, "peanut butter":6, "cumin":7, "green onions":34, "canned chicken broth":2, "banana":3, "beets":2, "kidney beans":2, "shortening":2, "applesauce":2, "parmesan cheese":3, "carrots":20, "mushrooms":10, "sour cream":3, "yogurt":3, "tofu":6, "cherry tomatoes":4, "parsley":6, "rice vinegar":12, "molasses":8, "chili powder":7, "spaghetti":2, "raisins":5, "red wine vinegar":8, "garam masala":18, "chives":2, "cornstarch":52, "dried basil":2, "orange":2, "catsup":2, "radishes":3, "ground beef":2, "sweet red pepper":3, "cumin seeds":10, "red pepper flakes":4, "almonds":4, "eggs":5, "margarine":2, "garlic powder":6, "dried thyme":3, "salt":144, "fresh basil":3, "bean sprouts":7, "shiitake mushrooms":3, "potatoes":15, "frozen spinach":4, "allspice":3, "celery seeds":2, "dijon mustard":4, "soy sauce":100, "broccoli":3, "apples":3, "maple syrup":5, "egg whites":5, "worcestershire sauce":2, "brown sugar":25, "lime juice":17, "dry mustard":3, "raw shrimp":2, "blueberries":2, "mayonnaise":2, "chicken wings":3, "olive oil":22, "vegetable oil":44, "curry powder":12, "flour":8, "vinegar":7, "white wine":3, "sherry":17, "yam":2, "whipping cream":4, "chicken breast":3, "sugar":79}, "buttermilk": {"red wine":3, "bacon":5, "cayenne pepper":9, "lemon juice":34, "honey":58, "paprika":14, "ground cinnamon":58, "yeast":50, "egg yolks":18, "green pepper":3, "baking powder":425, "cinnamon":121, "pine nuts":3, "cream of tartar":14, "avocado":2, "cheddar cheese":13, "tomatoes":3, "white pepper":10, "brown rice":2, "pinto beans":2, "fresh garlic":2, "frozen peas":2, "butter":284, "orange juice":16, "lemon":4, "black pepper":18, "tumeric":2, "powdered sugar":21, "dried oregano":4, "capers":3, "cornmeal":64, "cloves":24, "oil":58, "chicken":5, "blue cheese":8, "cucumber":6, "flour tortilla":2, "canola oil":18, "strawberries":8, "celery":2, "fresh peaches":2, "nutmeg":55, "walnuts":28, "fresh cilantro":3, "baking soda":635, "bread crumbs":4, "tabasco sauce":3, "corn syrup":7, "balsamic vinegar":2, "ginger":24, "fresh rosemary":2, "pecans":38, "peanut butter":2, "cumin":2, "green onions":10, "banana":7, "skim milk":5, "beets":2, "barley":3, "shortening":100, "parmesan cheese":8, "applesauce":14, "carrots":10, "mushrooms":3, "sour cream":22, "yogurt":2, "cream cheese":17, "cherry tomatoes":2, "salsa":2, "parsley":11, "rice vinegar":2, "molasses":53, "chili powder":9, "raisins":81, "red wine vinegar":5, "garam masala":3, "chives":5, "cornstarch":16, "dried basil":4, "orange":10, "ground beef":5, "sweet red pepper":4, "almonds":5, "eggs":430, "margarine":55, "fresh ginger":4, "garlic powder":15, "dried thyme":6, "cream of mushroom soup":3, "low fat milk":2, "vanilla":228, "whole wheat flour":75, "salt":829, "fresh basil":4, "shiitake mushrooms":2, "potatoes":5, "almond extract":16, "frozen spinach":2, "allspice":29, "dijon mustard":10, "soy sauce":2, "apples":7, "sweet potatoes":5, "maple syrup":15, "egg whites":46, "worcestershire sauce":10, "dried cilantro":2, "brown sugar":97, "lime juice":5, "dry mustard":5, "white flour":9, "blueberries":19, "mayonnaise":21, "chicken wings":3, "fresh thyme":2, "vegetable oil":97, "olive oil":21, "flour":391, "curry powder":5, "vinegar":14, "white wine":3, "oats":5, "whipping cream":17, "sugar":653}, "camembert cheese": {"worcestershire sauce":2, "sour cream":2, "cream cheese":4, "dried oregano":2, "mayonnaise":2, "green onions":2, "eggs":2, "paprika":3, "parmesan cheese":2, "dried thyme":2, "whipping cream":2, "walnuts":2, "salt":2}, "canned clams": {"butter":2, "garlic powder":2, "potatoes":2, "sugar":2, "salt":3}, "mushrooms": {"elbow macaroni":5, "red wine":42, "canned beef broth":2, "canned tomato sauce":4, "coconut oil":2, "bacon":54, "cayenne pepper":29, "lemon juice":136, "honey":26, "swiss cheese":22, "paprika":87, "ground cinnamon":4, "bread":7, "dried bay leaf":2, "yeast":8, "egg yolks":24, "green pepper":122, "baking powder":10, "saffron":4, "sesame oil":35, "cream of tartar":2, "pine nuts":11, "cinnamon":9, "avocado":3, "cheddar cheese":45, "tomatoes":122, "white pepper":38, "brown rice":19, "black beans":4, "fresh garlic":2, "pinto beans":5, "cauliflower":16, "frozen peas":18, "butter":440, "salmon":4, "orange juice":7, "black pepper":108, "lemon":29, "tumeric":5, "black olives":14, "buttermilk":3, "hoisin sauce":4, "eggplant":25, "dried oregano":28, "capers":12, "cornmeal":2, "cloves":15, "oil":162, "chicken":59, "blue cheese":4, "cucumber":8, "canola oil":17, "dried tarragon":14, "celery":118, "cornish game hens":2, "alfalfa sprouts":3, "fresh cilantro":3, "walnuts":13, "nutmeg":55, "baking soda":3, "bread crumbs":58, "tabasco sauce":8, "ginger":35, "balsamic vinegar":20, "fresh rosemary":4, "lime":2, "pecans":9, "frozen corn":3, "green onions":109, "cumin":25, "canned chicken broth":2, "banana":2, "beets":2, "skim milk":12, "barley":10, "kidney beans":7, "shortening":7, "parmesan cheese":112, "carrots":139, "sour cream":94, "yogurt":8, "cream cheese":21, "tofu":27, "cherry tomatoes":19, "salsa":8, "parsley":213, "green olives":10, "rice vinegar":8, "molasses":6, "chili powder":24, "beer":12, "spaghetti":18, "raisins":7, "red wine vinegar":15, "garam masala":4, "chives":22, "cornstarch":111, "orange":3, "dried basil":37, "radishes":4, "catsup":11, "ground beef":47, "romaine lettuce":3, "mozzarella cheese":40, "sweet red pepper":14, "cumin seeds":5, "barbecue sauce":3, "red pepper flakes":11, "almonds":10, "eggs":113, "margarine":61, "fresh ginger":10, "garlic powder":55, "dried thyme":42, "cream of mushroom soup":30, "whole wheat flour":8, "salt":672, "fresh basil":20, "bean sprouts":30, "shiitake mushrooms":4, "potatoes":49, "frozen spinach":6, "celery seeds":2, "allspice":5, "dijon mustard":27, "soy sauce":146, "broccoli":33, "chicken legs":4, "apples":5, "shell macaroni":2, "maple syrup":2, "white rice":5, "sweet potatoes":2, "egg whites":10, "worcestershire sauce":82, "brown sugar":16, "lime juice":4, "dry mustard":31, "raw shrimp":2, "mayonnaise":16, "olive oil":272, "vegetable oil":111, "fresh thyme":10, "curry powder":24, "flour":300, "vinegar":30, "white wine":72, "sherry":64, "yam":2, "whipping cream":24, "chicken breast":14, "sugar":96}, "honey": {"canned beef broth":2, "elbow macaroni":2, "red wine":10, "canned tomato sauce":2, "bacon":8, "cayenne pepper":52, "lemon juice":295, "swiss cheese":2, "zucchini squash":2, "paprika":52, "bread":7, "ground cinnamon":146, "yeast":247, "egg yolks":29, "green pepper":22, "baking powder":305, "saffron":5, "sesame oil":58, "pine nuts":14, "cream of tartar":16, "cinnamon":336, "avocado":4, "cheddar cheese":7, "tomatoes":19, "white pepper":29, "brown rice":12, "black beans":11, "fresh garlic":4, "cauliflower":2, "frozen peas":2, "butter":365, "salmon":4, "orange juice":164, "lemon":73, "black pepper":72, "tumeric":12, "black olives":4, "buttermilk":58, "powdered sugar":17, "eggplant":7, "dried oregano":13, "hoisin sauce":38, "capers":4, "cornmeal":44, "cloves":60, "oil":197, "chicken":32, "blue cheese":2, "cucumber":6, "dry rosemary":2, "canola oil":58, "dried tarragon":11, "strawberries":30, "celery":20, "alfalfa sprouts":4, "cornish game hens":7, "fresh peaches":3, "fresh cilantro":14, "nutmeg":109, "walnuts":61, "baking soda":230, "bread crumbs":8, "corn syrup":5, "tabasco sauce":21, "ginger":114, "balsamic vinegar":24, "fresh rosemary":9, "lime":13, "pecans":24, "peanut butter":55, "frozen corn":2, "green onions":51, "cumin":25, "canned chicken broth":3, "beets":7, "skim milk":33, "banana":31, "barley":3, "kidney beans":3, "shortening":52, "parmesan cheese":7, "applesauce":62, "carrots":56, "mushrooms":26, "sour cream":40, "yogurt":18, "brussels sprouts":2, "cream cheese":26, "tofu":13, "cherry tomatoes":10, "salsa":3, "parsley":27, "green olives":2, "rice vinegar":40, "molasses":76, "chili powder":44, "beer":15, "spaghetti":3, "raisins":188, "red wine vinegar":49, "garam masala":2, "chives":8, "cornstarch":124, "dried basil":12, "orange":35, "catsup":38, "ground beef":4, "mozzarella cheese":4, "adzuki beans":2, "sweet red pepper":3, "cumin seeds":3, "barbecue sauce":7, "red pepper flakes":19, "eggs":271, "almonds":45, "margarine":95, "fresh ginger":15, "kale":2, "garlic powder":48, "dried thyme":26, "low fat milk":2, "vanilla":208, "whole wheat flour":246, "salt":1244, "fresh basil":6, "shiitake mushrooms":5, "potatoes":9, "almond extract":33, "canned apricots":2, "celery seeds":5, "allspice":54, "dijon mustard":149, "soy sauce":315, "broccoli":8, "chicken legs":3, "apples":50, "yellow mustard":5, "white rice":2, "maple syrup":20, "sweet potatoes":16, "egg whites":71, "worcestershire sauce":65, "brown sugar":160, "lime juice":68, "dry mustard":90, "white flour":36, "blueberries":17, "mayonnaise":36, "chicken wings":29, "fresh thyme":12, "vegetable oil":227, "olive oil":210, "flour":315, "curry powder":55, "vinegar":80, "white wine":29, "sherry":41, "oats":37, "whipping cream":19, "chicken breast":8, "sugar":409}, "alfalfa sprouts": {"sour cream":5, "elbow macaroni":2, "cream cheese":3, "bacon":3, "salsa":3, "parsley":4, "cayenne pepper":2, "lemon juice":7, "honey":4, "rice vinegar":3, "swiss cheese":3, "chili powder":2, "bread":2, "yeast":2, "red wine vinegar":5, "egg yolks":3, "green pepper":3, "dried basil":2, "orange":2, "radishes":3, "sesame oil":3, "avocado":6, "cheddar cheese":5, "romaine lettuce":3, "tomatoes":5, "white pepper":2, "brown rice":2, "eggs":5, "cauliflower":2, "butter":2, "garlic powder":3, "orange juice":2, "lemon":3, "salt":13, "bean sprouts":2, "black olives":2, "capers":2, "oil":2, "cucumber":6, "canola oil":2, "dijon mustard":6, "dried tarragon":2, "soy sauce":4, "celery":4, "broccoli":2, "apples":2, "walnuts":2, "fresh cilantro":2, "nutmeg":2, "brown sugar":2, "dry mustard":2, "mayonnaise":3, "green onions":5, "cumin":2, "olive oil":9, "vegetable oil":6, "skim milk":2, "kidney beans":2, "vinegar":2, "carrots":2, "sugar":4, "mushrooms":3}, "vanilla": {"sour cream":302, "yogurt":17, "red wine":3, "tofu":8, "cream cheese":419, "cayenne pepper":2, "lemon juice":257, "honey":208, "molasses":47, "beer":7, "bread":21, "ground cinnamon":141, "raisins":381, "yeast":32, "egg yolks":320, "baking powder":1555, "cornstarch":262, "orange":16, "pine nuts":8, "cream of tartar":208, "cinnamon":842, "cheddar cheese":2, "canned tuna":2, "brown rice":3, "eggs":2594, "almonds":82, "margarine":426, "butter":1845, "orange juice":97, "whole wheat flour":78, "black pepper":9, "lemon":33, "salt":3155, "potatoes":6, "buttermilk":228, "powdered sugar":430, "almond extract":161, "cornmeal":11, "cloves":108, "oil":258, "canned apricots":2, "celery seeds":2, "allspice":73, "canola oil":21, "strawberries":53, "celery":2, "apples":113, "white rice":2, "sweet potatoes":8, "maple syrup":44, "fresh peaches":2, "walnuts":229, "nutmeg":325, "egg whites":517, "bread crumbs":3, "baking soda":1393, "corn syrup":124, "brown sugar":926, "ginger":57, "lime juice":6, "lime":3, "white flour":18, "pecans":244, "blueberries":43, "mayonnaise":10, "peanut butter":195, "vegetable oil":159, "beets":4, "banana":33, "skim milk":108, "flour":2196, "vinegar":76, "shortening":408, "parmesan cheese":2, "white wine":5, "applesauce":87, "sherry":5, "carrots":34, "oats":66, "whipping cream":265, "sugar":4410}, "sour cream": {"elbow macaroni":3, "canned beef broth":3, "red wine":14, "canned tomato sauce":3, "bacon":76, "cayenne pepper":42, "lemon juice":248, "honey":40, "swiss cheese":14, "paprika":179, "camembert cheese":2, "bread":6, "ground cinnamon":46, "yeast":19, "egg yolks":64, "green pepper":62, "baking powder":188, "saffron":5, "sesame oil":3, "pine nuts":4, "cream of tartar":17, "cinnamon":123, "avocado":29, "cheddar cheese":132, "corn tortilla":4, "tomatoes":87, "white pepper":49, "brown rice":3, "black beans":15, "fresh garlic":2, "pinto beans":6, "cauliflower":2, "frozen peas":11, "butter":675, "salmon":9, "orange juice":22, "lemon":35, "black pepper":80, "tumeric":2, "black olives":24, "buttermilk":22, "powdered sugar":52, "eggplant":4, "dried oregano":21, "capers":14, "cornmeal":16, "cloves":25, "oil":114, "chicken":40, "blue cheese":16, "cucumber":35, "flour tortilla":7, "canola oil":10, "dried tarragon":4, "strawberries":15, "celery":58, "alfalfa sprouts":5, "fresh peaches":4, "nutmeg":69, "walnuts":41, "fresh cilantro":23, "bread crumbs":40, "baking soda":232, "corn syrup":3, "tabasco sauce":36, "balsamic vinegar":6, "ginger":23, "lime":10, "pecans":42, "peanut butter":4, "frozen corn":4, "green onions":112, "cumin":50, "canned chicken broth":4, "skim milk":4, "beets":11, "banana":17, "kidney beans":10, "shortening":40, "applesauce":5, "parmesan cheese":64, "carrots":43, "mushrooms":94, "yogurt":10, "cream cheese":274, "cherry tomatoes":2, "salsa":61, "parsley":82, "green olives":3, "rice vinegar":4, "molasses":12, "beer":11, "chili powder":74, "spaghetti":5, "raisins":51, "red wine vinegar":19, "chives":32, "cornstarch":75, "dried basil":9, "orange":8, "radishes":11, "catsup":14, "ground beef":89, "romaine lettuce":2, "mozzarella cheese":17, "sweet red pepper":4, "cumin seeds":5, "canned peaches":2, "barbecue sauce":2, "raw spinach":2, "red pepper flakes":6, "almonds":22, "eggs":564, "margarine":106, "fresh ginger":3, "garlic powder":74, "kale":3, "dried thyme":6, "cream of mushroom soup":51, "vanilla":302, "whole wheat flour":15, "salt":1198, "fresh basil":10, "bean sprouts":2, "potatoes":72, "almond extract":38, "frozen spinach":7, "canned apricots":2, "celery seeds":3, "allspice":7, "dijon mustard":50, "soy sauce":19, "broccoli":4, "apples":17, "sweet potatoes":2, "yellow mustard":2, "maple syrup":9, "egg whites":23, "worcestershire sauce":99, "dried cilantro":2, "brown sugar":84, "lime juice":28, "dry mustard":46, "raw shrimp":2, "white flour":6, "blueberries":14, "mayonnaise":235, "chicken wings":6, "fresh thyme":6, "olive oil":82, "vegetable oil":117, "flour":522, "curry powder":54, "vinegar":55, "white wine":25, "sherry":22, "whipping cream":45, "chicken breast":13, "sugar":809}, "tabasco sauce": {"red wine":3, "elbow macaroni":3, "canned tomato sauce":4, "bacon":16, "cayenne pepper":48, "honey":21, "lemon juice":92, "paprika":61, "ground cinnamon":5, "bread":4, "yeast":3, "egg yolks":5, "green pepper":45, "baking powder":6, "saffron":4, "sesame oil":10, "pine nuts":2, "cinnamon":7, "avocado":3, "cheddar cheese":12, "tomatoes":50, "white pepper":26, "brown rice":12, "black beans":7, "fresh garlic":2, "pinto beans":7, "frozen peas":2, "butter":118, "salmon":4, "orange juice":7, "lemon":20, "black pepper":78, "black olives":7, "buttermilk":3, "hoisin sauce":2, "dried oregano":10, "eggplant":3, "capers":9, "cornmeal":2, "cloves":3, "oil":32, "chicken":4, "blue cheese":3, "cucumber":16, "canola oil":4, "dried tarragon":3, "celery":36, "walnuts":2, "fresh cilantro":7, "nutmeg":5, "bread crumbs":14, "balsamic vinegar":4, "ginger":8, "lime":5, "pecans":4, "peanut butter":2, "frozen corn":2, "green onions":29, "cumin":45, "skim milk":2, "barley":2, "kidney beans":6, "shortening":3, "parmesan cheese":16, "carrots":17, "mushrooms":8, "sour cream":36, "yogurt":2, "brussels sprouts":2, "cream cheese":24, "cherry tomatoes":3, "salsa":3, "parsley":41, "green olives":2, "rice vinegar":4, "molasses":19, "beer":22, "chili powder":77, "spaghetti":2, "raisins":5, "red wine vinegar":21, "chives":6, "cornstarch":12, "orange":4, "dried basil":9, "catsup":20, "ground beef":18, "mozzarella cheese":5, "cumin seeds":3, "barbecue sauce":2, "red pepper flakes":11, "eggs":41, "margarine":19, "fresh ginger":3, "kale":2, "garlic powder":53, "dried thyme":13, "cream of mushroom soup":2, "low fat milk":2, "whole wheat flour":2, "salt":272, "fresh basil":2, "potatoes":6, "allspice":11, "celery seeds":2, "dijon mustard":20, "soy sauce":56, "apples":3, "sweet potatoes":2, "shell macaroni":3, "maple syrup":7, "yellow mustard":3, "white rice":3, "egg whites":2, "worcestershire sauce":181, "brown sugar":44, "lime juice":16, "dry mustard":51, "raw shrimp":2, "white flour":2, "mayonnaise":43, "chicken wings":15, "olive oil":72, "vegetable oil":38, "flour":61, "curry powder":11, "vinegar":45, "white wine":10, "sherry":8, "whipping cream":4, "chicken breast":4, "sugar":84}, "canned peaches": {"baking powder":2, "sour cream":2, "brown sugar":2, "cinnamon":3, "lime juice":3, "blueberries":2, "oil":2, "curry powder":2, "flour":2, "butter":2, "garlic powder":2, "celery":2, "nutmeg":2, "salt":3, "sugar":4}, "maple syrup": {"red wine":3, "bacon":5, "cayenne pepper":2, "lemon juice":37, "honey":20, "swiss cheese":2, "paprika":4, "bread":7, "ground cinnamon":34, "yeast":22, "egg yolks":15, "green pepper":3, "baking powder":76, "sesame oil":3, "pine nuts":2, "cinnamon":64, "cream of tartar":3, "tomatoes":3, "brown rice":2, "pinto beans":3, "butter":98, "orange juice":18, "black pepper":12, "lemon":3, "black olives":3, "buttermilk":15, "powdered sugar":13, "hoisin sauce":3, "cornmeal":8, "cloves":11, "oil":18, "chicken":3, "cucumber":3, "canola oil":11, "strawberries":3, "cornish game hens":3, "fresh cilantro":2, "fresh peaches":4, "walnuts":9, "nutmeg":40, "baking soda":47, "bread crumbs":2, "tabasco sauce":7, "corn syrup":2, "ginger":20, "balsamic vinegar":4, "fresh rosemary":2, "pecans":14, "peanut butter":6, "frozen corn":2, "cumin":4, "green onions":3, "skim milk":15, "banana":3, "barley":2, "shortening":8, "parmesan cheese":2, "applesauce":10, "carrots":9, "mushrooms":2, "sour cream":9, "yogurt":2, "tofu":4, "cream cheese":4, "parsley":2, "rice vinegar":2, "molasses":15, "chili powder":7, "beer":3, "raisins":30, "red wine vinegar":3, "cornstarch":19, "orange":5, "catsup":4, "ground beef":2, "cumin seeds":2, "red pepper flakes":5, "almonds":6, "eggs":72, "margarine":22, "fresh ginger":5, "garlic powder":3, "vanilla":44, "whole wheat flour":17, "salt":182, "fresh basil":2, "potatoes":2, "almond extract":5, "allspice":9, "dijon mustard":15, "soy sauce":17, "apples":12, "yellow mustard":2, "sweet potatoes":8, "egg whites":36, "worcestershire sauce":12, "brown sugar":37, "lime juice":10, "dry mustard":17, "white flour":3, "blueberries":7, "mayonnaise":2, "chicken wings":2, "olive oil":14, "vegetable oil":14, "flour":60, "curry powder":2, "vinegar":6, "white wine":10, "sherry":6, "oats":4, "whipping cream":12, "chicken breast":2, "sugar":74}, "fresh rosemary": {"red wine":3, "cream cheese":2, "cherry tomatoes":2, "canned tomato sauce":2, "bacon":4, "parsley":4, "cayenne pepper":3, "lemon juice":11, "honey":9, "molasses":2, "paprika":3, "spaghetti":2, "ground cinnamon":2, "bread":2, "raisins":2, "yeast":2, "red wine vinegar":6, "chives":2, "cornstarch":4, "orange":2, "dried basil":3, "pine nuts":2, "tomatoes":6, "sweet red pepper":2, "white pepper":2, "red pepper flakes":2, "almonds":2, "eggs":5, "fresh garlic":2, "margarine":3, "butter":17, "dried thyme":6, "orange juice":7, "whole wheat flour":2, "lemon":2, "black pepper":5, "salt":50, "fresh basil":11, "black olives":3, "shiitake mushrooms":2, "buttermilk":2, "potatoes":6, "dried oregano":2, "cornmeal":3, "cloves":2, "oil":5, "chicken":6, "canola oil":8, "dijon mustard":8, "celery":2, "maple syrup":2, "walnuts":3, "nutmeg":2, "baking soda":2, "bread crumbs":2, "worcestershire sauce":2, "balsamic vinegar":5, "lime juice":2, "dry mustard":2, "raw shrimp":2, "white flour":2, "pecans":3, "green onions":2, "vegetable oil":5, "fresh thyme":14, "olive oil":67, "barley":2, "curry powder":3, "flour":4, "vinegar":2, "parmesan cheese":8, "white wine":9, "carrots":7, "whipping cream":2, "sugar":8, "mushrooms":4}, "ground beef": {"canned beef broth":2, "elbow macaroni":12, "red wine":12, "canned tomato sauce":2, "bacon":34, "cayenne pepper":38, "honey":4, "lemon juice":29, "swiss cheese":7, "paprika":70, "ground cinnamon":9, "bread":18, "egg yolks":9, "green pepper":117, "baking powder":8, "sesame oil":9, "cinnamon":35, "pine nuts":6, "avocado":8, "cheddar cheese":97, "corn tortilla":2, "tomatoes":133, "white pepper":14, "brown rice":4, "black beans":3, "pinto beans":10, "frozen peas":3, "butter":96, "orange juice":2, "black pepper":74, "lemon":6, "black olives":5, "buttermilk":5, "hoisin sauce":3, "eggplant":14, "dried oregano":37, "capers":11, "cornmeal":13, "cloves":13, "oil":66, "chicken":5, "blue cheese":2, "cucumber":3, "canola oil":4, "celery":49, "walnuts":2, "fresh cilantro":6, "nutmeg":34, "baking soda":2, "bread crumbs":76, "tabasco sauce":18, "ginger":10, "pecans":2, "peanut butter":2, "frozen corn":3, "cumin":68, "green onions":23, "skim milk":3, "beets":2, "barley":3, "kidney beans":45, "shortening":25, "parmesan cheese":72, "applesauce":4, "carrots":31, "mushrooms":47, "sour cream":89, "yogurt":2, "cream cheese":9, "cherry tomatoes":2, "salsa":16, "parsley":65, "green olives":9, "molasses":6, "beer":9, "chili powder":250, "spaghetti":17, "raisins":15, "red wine vinegar":5, "garam masala":3, "chives":4, "cornstarch":31, "dried basil":29, "catsup":68, "mozzarella cheese":50, "sweet red pepper":3, "cumin seeds":2, "barbecue sauce":10, "red pepper flakes":7, "eggs":169, "almonds":4, "margarine":13, "fresh ginger":2, "garlic powder":93, "dried thyme":8, "cream of mushroom soup":46, "whole wheat flour":2, "salt":712, "fresh basil":4, "bean sprouts":9, "potatoes":42, "frozen spinach":4, "celery seeds":2, "allspice":23, "dijon mustard":6, "soy sauce":44, "apples":6, "sweet potatoes":2, "shell macaroni":5, "maple syrup":2, "white rice":2, "yellow mustard":3, "egg whites":2, "worcestershire sauce":113, "dried cilantro":2, "brown sugar":75, "lime juice":2, "dry mustard":32, "mayonnaise":14, "chicken wings":4, "vegetable oil":59, "olive oil":57, "flour":92, "curry powder":11, "vinegar":59, "white wine":8, "sherry":4, "oats":4, "yam":2, "whipping cream":3, "sugar":102}, "blue cheese": {"sour cream":16, "yogurt":3, "cream cheese":26, "bacon":6, "parsley":9, "cayenne pepper":4, "green olives":2, "honey":2, "lemon juice":14, "rice vinegar":3, "swiss cheese":5, "chili powder":4, "paprika":10, "red wine vinegar":5, "yeast":5, "chives":6, "baking powder":2, "cornstarch":2, "catsup":4, "sesame oil":2, "ground beef":2, "avocado":3, "cheddar cheese":2, "romaine lettuce":4, "tomatoes":10, "cumin seeds":3, "white pepper":6, "almonds":2, "eggs":4, "butter":19, "garlic powder":4, "orange juice":2, "black pepper":9, "salt":38, "lemon":2, "fresh basil":2, "black olives":4, "buttermilk":8, "potatoes":5, "dried oregano":2, "capers":2, "oil":5, "cucumber":3, "dijon mustard":5, "soy sauce":4, "celery":4, "broccoli":2, "walnuts":6, "nutmeg":3, "bread crumbs":2, "worcestershire sauce":12, "tabasco sauce":3, "balsamic vinegar":4, "dry mustard":5, "mayonnaise":16, "green onions":3, "chicken wings":5, "olive oil":13, "vegetable oil":4, "banana":2, "curry powder":2, "flour":6, "vinegar":6, "white wine":2, "applesauce":2, "parmesan cheese":3, "carrots":3, "sherry":2, "chicken breast":2, "mushrooms":4, "sugar":12}, "chicken wings": {"sour cream":6, "bacon":2, "cayenne pepper":7, "parsley":4, "lemon juice":18, "honey":29, "molasses":5, "chili powder":10, "paprika":12, "beer":5, "ground cinnamon":3, "red wine vinegar":3, "green pepper":2, "baking powder":2, "cornstarch":17, "catsup":13, "sesame oil":6, "cinnamon":2, "ground beef":4, "tomatoes":5, "barbecue sauce":4, "white pepper":2, "red pepper flakes":4, "eggs":7, "almonds":2, "margarine":3, "fresh ginger":3, "frozen peas":2, "butter":26, "garlic powder":18, "dried thyme":3, "orange juice":4, "lemon":4, "salt":57, "black pepper":17, "tumeric":2, "buttermilk":3, "dried oregano":3, "hoisin sauce":3, "cloves":2, "oil":16, "chicken":2, "blue cheese":5, "cucumber":2, "canola oil":2, "celery seeds":2, "allspice":4, "dijon mustard":5, "soy sauce":52, "celery":5, "apples":2, "maple syrup":2, "nutmeg":2, "egg whites":3, "worcestershire sauce":16, "corn syrup":2, "tabasco sauce":15, "brown sugar":26, "balsamic vinegar":3, "ginger":6, "lime juice":8, "dry mustard":13, "peanut butter":3, "mayonnaise":5, "cumin":5, "green onions":5, "olive oil":5, "vegetable oil":27, "curry powder":4, "flour":15, "vinegar":16, "parmesan cheese":3, "white wine":3, "sherry":5, "carrots":3, "sugar":23}, "shortening": {"red wine":2, "bacon":5, "cayenne pepper":5, "lemon juice":49, "honey":52, "swiss cheese":2, "zucchini squash":2, "paprika":30, "ground cinnamon":47, "bread":3, "yeast":59, "egg yolks":21, "green pepper":10, "baking powder":675, "saffron":2, "sesame oil":2, "pine nuts":3, "cream of tartar":46, "cinnamon":300, "cheddar cheese":10, "tomatoes":15, "white pepper":3, "pinto beans":3, "butter":190, "frozen peas":5, "salmon":2, "orange juice":27, "lemon":10, "black pepper":17, "black olives":3, "buttermilk":100, "powdered sugar":53, "cornmeal":32, "cloves":90, "oil":13, "chicken":8, "strawberries":6, "celery":11, "walnuts":50, "nutmeg":126, "fresh cilantro":2, "baking soda":481, "bread crumbs":8, "tabasco sauce":3, "corn syrup":13, "ginger":74, "pecans":34, "peanut butter":46, "cumin":6, "green onions":4, "skim milk":3, "banana":4, "barley":2, "parmesan cheese":6, "applesauce":18, "carrots":13, "mushrooms":7, "sour cream":40, "yogurt":2, "tofu":2, "cream cheese":16, "salsa":2, "parsley":10, "molasses":99, "chili powder":14, "beer":5, "spaghetti":2, "raisins":137, "red wine vinegar":3, "cornstarch":23, "orange":6, "dried basil":2, "catsup":10, "ground beef":25, "mozzarella cheese":2, "cumin seeds":2, "barbecue sauce":2, "eggs":538, "almonds":10, "margarine":36, "fresh ginger":2, "garlic powder":8, "cream of mushroom soup":6, "vanilla":408, "whole wheat flour":28, "salt":1377, "bean sprouts":2, "potatoes":13, "almond extract":37, "allspice":44, "soy sauce":8, "chicken legs":2, "apples":25, "maple syrup":8, "sweet potatoes":5, "egg whites":35, "worcestershire sauce":18, "brown sugar":286, "lime juice":4, "dry mustard":12, "white flour":17, "blueberries":11, "mayonnaise":3, "olive oil":2, "vegetable oil":11, "flour":867, "curry powder":3, "vinegar":42, "white wine":5, "sherry":3, "oats":24, "whipping cream":9, "chicken breast":2, "sugar":1042}, "cloves": {"red wine":20, "bacon":13, "brown onions":2, "cayenne pepper":23, "lemon juice":62, "honey":60, "swiss cheese":2, "paprika":49, "ground cinnamon":23, "yeast":11, "egg yolks":16, "green pepper":15, "baking powder":179, "saffron":12, "sesame oil":3, "cream of tartar":2, "cinnamon":583, "pine nuts":5, "avocado":3, "cheddar cheese":3, "tomatoes":41, "white pepper":12, "brown rice":5, "black beans":5, "pinto beans":5, "cauliflower":2, "frozen peas":2, "butter":198, "salmon":3, "orange juice":30, "black pepper":44, "lemon":34, "tumeric":10, "black olives":3, "buttermilk":24, "powdered sugar":13, "dried oregano":9, "eggplant":8, "capers":6, "cornmeal":2, "oil":75, "chicken":29, "cucumber":2, "canola oil":5, "strawberries":3, "celery":13, "cornish game hens":2, "fresh peaches":2, "nutmeg":309, "walnuts":35, "bread crumbs":14, "baking soda":209, "tabasco sauce":3, "corn syrup":8, "balsamic vinegar":5, "ginger":196, "fresh rosemary":2, "lime":11, "pecans":24, "peanut butter":5, "frozen corn":2, "cumin":49, "green onions":6, "beets":6, "skim milk":10, "banana":3, "kidney beans":4, "shortening":90, "parmesan cheese":3, "applesauce":42, "carrots":44, "mushrooms":15, "sour cream":25, "yogurt":19, "tofu":6, "cream cheese":8, "cherry tomatoes":2, "salsa":2, "parsley":31, "green olives":3, "rice vinegar":3, "molasses":78, "chili powder":34, "beer":8, "spaghetti":2, "raisins":184, "red wine vinegar":18, "chives":6, "garam masala":8, "cornstarch":26, "dried basil":5, "orange":22, "catsup":5, "ground beef":13, "mozzarella cheese":2, "sweet red pepper":2, "cumin seeds":37, "red pepper flakes":4, "eggs":202, "almonds":33, "margarine":37, "fresh ginger":8, "garlic powder":8, "dried thyme":10, "vanilla":108, "whole wheat flour":16, "salt":611, "fresh basil":2, "potatoes":15, "almond extract":7, "celery seeds":2, "allspice":179, "dijon mustard":4, "soy sauce":16, "apples":47, "sweet potatoes":5, "maple syrup":11, "egg whites":29, "worcestershire sauce":17, "brown sugar":190, "lime juice":9, "dry mustard":20, "white flour":7, "mayonnaise":7, "chicken wings":2, "fresh thyme":2, "vegetable oil":56, "olive oil":68, "flour":277, "curry powder":15, "vinegar":105, "white wine":11, "sherry":7, "oats":8, "yam":2, "whipping cream":10, "chicken breast":3, "sugar":418}, "yellow mustard": {"sour cream":2, "yogurt":2, "cream cheese":2, "bacon":2, "parsley":2, "cayenne pepper":6, "green olives":2, "lemon juice":2, "honey":5, "beer":2, "paprika":2, "chili powder":2, "red wine vinegar":8, "yeast":2, "egg yolks":2, "green pepper":2, "cornstarch":3, "dried basil":2, "catsup":3, "ground beef":3, "tomatoes":2, "red pepper flakes":3, "eggs":6, "margarine":2, "butter":3, "garlic powder":3, "dried thyme":2, "orange juice":3, "black pepper":10, "salt":28, "lemon":3, "potatoes":4, "oil":2, "allspice":2, "dijon mustard":3, "soy sauce":3, "celery":4, "maple syrup":2, "nutmeg":2, "worcestershire sauce":9, "tabasco sauce":3, "brown sugar":9, "balsamic vinegar":2, "mayonnaise":15, "green onions":4, "olive oil":5, "vegetable oil":2, "flour":2, "kidney beans":2, "vinegar":3, "white wine":4, "carrots":2, "sugar":6}, "skim milk": {"red wine":2, "elbow macaroni":8, "bacon":5, "cayenne pepper":15, "lemon juice":42, "honey":33, "zucchini squash":2, "swiss cheese":6, "paprika":27, "bread":7, "ground cinnamon":69, "yeast":10, "egg yolks":13, "green pepper":13, "baking powder":218, "pine nuts":4, "cinnamon":94, "cream of tartar":11, "cheddar cheese":7, "tomatoes":5, "white pepper":17, "brown rice":3, "black beans":3, "fresh garlic":2, "pinto beans":2, "cauliflower":2, "butter":34, "frozen peas":7, "salmon":3, "orange juice":19, "lemon":4, "black pepper":40, "buttermilk":5, "powdered sugar":27, "eggplant":5, "dried oregano":14, "capers":2, "cornmeal":11, "cloves":10, "oil":21, "chicken":7, "canola oil":26, "dried tarragon":4, "strawberries":5, "celery":10, "alfalfa sprouts":2, "fresh peaches":2, "fresh cilantro":2, "walnuts":9, "nutmeg":43, "baking soda":95, "bread crumbs":15, "corn syrup":9, "tabasco sauce":2, "ginger":12, "lime":2, "pecans":5, "peanut butter":12, "cumin":11, "green onions":11, "frozen corn":5, "banana":11, "barley":4, "kidney beans":2, "shortening":3, "applesauce":26, "parmesan cheese":22, "carrots":18, "mushrooms":12, "sour cream":4, "yogurt":3, "tofu":3, "cream cheese":5, "cherry tomatoes":2, "salsa":5, "parsley":12, "molasses":10, "chili powder":17, "raisins":52, "red wine vinegar":3, "chives":2, "cornstarch":69, "dried basil":11, "orange":5, "ground beef":3, "mozzarella cheese":7, "sweet red pepper":2, "eggs":90, "almonds":4, "margarine":139, "kale":2, "garlic powder":22, "dried thyme":5, "cream of mushroom soup":5, "vanilla":108, "whole wheat flour":48, "salt":422, "fresh basil":2, "shiitake mushrooms":2, "potatoes":20, "almond extract":18, "frozen spinach":3, "allspice":6, "dijon mustard":8, "soy sauce":2, "broccoli":8, "apples":11, "sweet potatoes":5, "maple syrup":15, "white rice":4, "egg whites":150, "worcestershire sauce":21, "brown sugar":56, "lime juice":4, "dry mustard":31, "white flour":5, "blueberries":18, "mayonnaise":4, "fresh thyme":2, "olive oil":38, "vegetable oil":71, "flour":148, "curry powder":12, "vinegar":5, "white wine":6, "sherry":4, "oats":6, "whipping cream":2, "chicken breast":2, "sugar":282}, "cherry tomatoes": {"sour cream":2, "cream cheese":4, "bacon":6, "cayenne pepper":3, "parsley":11, "lemon juice":25, "rice vinegar":4, "honey":10, "molasses":2, "chili powder":5, "paprika":5, "raisins":2, "red wine vinegar":17, "garam masala":2, "chives":2, "egg yolks":2, "green pepper":20, "cornstarch":6, "saffron":2, "dried basil":10, "catsup":3, "sesame oil":3, "radishes":8, "ground beef":2, "cinnamon":2, "pine nuts":6, "avocado":4, "mozzarella cheese":4, "tomatoes":5, "cumin seeds":2, "white pepper":4, "barbecue sauce":2, "red pepper flakes":3, "black beans":3, "eggs":7, "almonds":2, "fresh garlic":4, "margarine":2, "cauliflower":3, "fresh ginger":4, "frozen peas":3, "butter":13, "garlic powder":10, "dried thyme":6, "lemon":4, "black pepper":11, "salt":64, "fresh basil":10, "black olives":3, "potatoes":5, "buttermilk":2, "eggplant":5, "dried oregano":4, "capers":2, "cloves":2, "oil":9, "cucumber":10, "allspice":2, "canola oil":3, "dijon mustard":7, "soy sauce":19, "celery":5, "broccoli":4, "sweet potatoes":2, "fresh cilantro":2, "egg whites":2, "bread crumbs":3, "worcestershire sauce":6, "tabasco sauce":3, "brown sugar":5, "ginger":5, "balsamic vinegar":11, "lime juice":5, "dry mustard":6, "fresh rosemary":2, "lime":3, "pecans":3, "peanut butter":2, "mayonnaise":7, "cumin":3, "green onions":15, "fresh thyme":2, "vegetable oil":18, "olive oil":66, "skim milk":2, "curry powder":5, "flour":4, "vinegar":4, "white wine":3, "parmesan cheese":9, "carrots":12, "yam":3, "whipping cream":2, "sugar":21, "mushrooms":19}, "green pepper": {"elbow macaroni":9, "red wine":19, "canned tomato sauce":2, "bacon":57, "cayenne pepper":62, "honey":22, "lemon juice":98, "swiss cheese":11, "zucchini squash":3, "paprika":95, "bread":10, "ground cinnamon":7, "egg yolks":8, "baking powder":11, "saffron":16, "sesame oil":16, "cream of tartar":2, "cinnamon":24, "pine nuts":7, "avocado":2, "cheddar cheese":74, "tomatoes":245, "white pepper":22, "brown rice":13, "black beans":27, "fresh garlic":2, "pinto beans":19, "cauliflower":10, "frozen peas":10, "butter":145, "salmon":5, "orange juice":10, "black pepper":90, "lemon":22, "tumeric":7, "black olives":27, "buttermilk":3, "hoisin sauce":5, "eggplant":51, "dried oregano":40, "capers":15, "cornmeal":4, "cloves":15, "oil":165, "chicken":47, "cucumber":33, "canola oil":5, "flour tortilla":2, "dried tarragon":3, "celery":219, "cornish game hens":2, "alfalfa sprouts":3, "fresh peaches":2, "walnuts":6, "nutmeg":18, "fresh cilantro":9, "bread crumbs":31, "baking soda":6, "tabasco sauce":45, "balsamic vinegar":2, "ginger":21, "lime":4, "pecans":3, "peanut butter":4, "frozen corn":9, "green onions":84, "cumin":109, "skim milk":13, "barley":5, "kidney beans":43, "shortening":10, "parmesan cheese":43, "carrots":114, "mushrooms":122, "sour cream":62, "yogurt":3, "tofu":6, "cream cheese":19, "cherry tomatoes":20, "salsa":19, "parsley":104, "green olives":10, "rice vinegar":3, "molasses":11, "chili powder":204, "beer":5, "spaghetti":13, "raisins":18, "red wine vinegar":34, "garam masala":4, "chives":5, "cornstarch":115, "dried basil":37, "orange":5, "radishes":12, "catsup":22, "ground beef":117, "romaine lettuce":2, "mozzarella cheese":31, "sweet red pepper":24, "cumin seeds":4, "barbecue sauce":6, "raw spinach":2, "red pepper flakes":13, "eggs":97, "almonds":9, "margarine":40, "fresh ginger":6, "garlic powder":91, "dried thyme":15, "cream of mushroom soup":23, "whole wheat flour":3, "salt":767, "fresh basil":8, "bean sprouts":9, "potatoes":56, "celery seeds":3, "allspice":15, "dijon mustard":17, "soy sauce":132, "broccoli":10, "chicken legs":2, "apples":5, "shell macaroni":2, "maple syrup":3, "sweet potatoes":6, "yellow mustard":2, "white rice":7, "egg whites":5, "worcestershire sauce":103, "dried cilantro":2, "brown sugar":72, "lime juice":12, "dry mustard":52, "raw shrimp":5, "mayonnaise":62, "chicken wings":2, "fresh thyme":2, "vegetable oil":140, "olive oil":223, "curry powder":43, "flour":140, "vinegar":123, "white wine":21, "sherry":16, "whipping cream":4, "chicken breast":12, "sugar":202}, "adzuki beans": {"lime juice":2, "potatoes":2, "parsley":3, "green onions":2, "oil":2, "honey":2, "vegetable oil":4, "brown rice":2, "black beans":2, "soy sauce":3, "butter":2, "garlic powder":2, "white wine":2, "parmesan cheese":2, "lemon":2, "salt":3, "sugar":2}, "kidney beans": {"sour cream":10, "yogurt":2, "elbow macaroni":2, "red wine":4, "tofu":3, "bacon":18, "salsa":5, "cayenne pepper":15, "parsley":12, "honey":3, "lemon juice":8, "swiss cheese":2, "molasses":2, "beer":3, "chili powder":104, "paprika":14, "ground cinnamon":2, "raisins":4, "red wine vinegar":4, "chives":2, "garam masala":3, "egg yolks":2, "green pepper":43, "baking powder":2, "cornstarch":6, "dried basil":8, "radishes":2, "catsup":5, "cinnamon":3, "ground beef":45, "avocado":7, "cheddar cheese":17, "sweet red pepper":2, "tomatoes":59, "cumin seeds":3, "white pepper":2, "barbecue sauce":4, "brown rice":7, "red pepper flakes":6, "black beans":12, "margarine":3, "pinto beans":20, "cauliflower":2, "fresh ginger":2, "frozen peas":2, "butter":9, "garlic powder":18, "dried thyme":3, "cream of mushroom soup":2, "lemon":2, "salt":104, "black pepper":21, "tumeric":2, "black olives":3, "potatoes":3, "dried oregano":9, "cornmeal":3, "cloves":4, "oil":22, "chicken":3, "canola oil":2, "celery seeds":2, "allspice":3, "soy sauce":5, "celery":25, "apples":2, "yellow mustard":2, "alfalfa sprouts":2, "fresh cilantro":3, "nutmeg":2, "egg whites":2, "bread crumbs":2, "worcestershire sauce":9, "tabasco sauce":6, "brown sugar":20, "balsamic vinegar":2, "ginger":2, "dry mustard":6, "mayonnaise":2, "cumin":41, "green onions":6, "vegetable oil":16, "olive oil":35, "skim milk":2, "barley":5, "flour":7, "curry powder":4, "vinegar":23, "parmesan cheese":4, "carrots":21, "sugar":25, "mushrooms":7}, "hoisin sauce": {"parsley":2, "cayenne pepper":7, "honey":38, "rice vinegar":5, "lemon juice":7, "molasses":3, "beer":2, "yeast":2, "red wine vinegar":2, "egg yolks":3, "green pepper":5, "cornstarch":42, "catsup":13, "sesame oil":48, "pine nuts":5, "ground beef":3, "mozzarella cheese":2, "sweet red pepper":2, "tomatoes":2, "white pepper":4, "red pepper flakes":3, "black beans":3, "eggs":7, "fresh garlic":2, "fresh ginger":10, "butter":3, "garlic powder":2, "orange juice":7, "lemon":4, "black pepper":6, "salt":51, "fresh basil":2, "bean sprouts":8, "shiitake mushrooms":2, "eggplant":2, "oil":23, "chicken":4, "cucumber":2, "canola oil":3, "dijon mustard":4, "soy sauce":100, "broccoli":2, "maple syrup":3, "cornish game hens":4, "walnuts":2, "fresh cilantro":4, "worcestershire sauce":4, "tabasco sauce":2, "brown sugar":4, "ginger":14, "balsamic vinegar":4, "lime":3, "pecans":2, "peanut butter":4, "mayonnaise":2, "green onions":26, "cumin":2, "chicken wings":3, "vegetable oil":14, "olive oil":8, "curry powder":2, "flour":3, "vinegar":4, "white wine":3, "carrots":8, "sherry":26, "chicken breast":2, "mushrooms":4, "sugar":69}, "dry rosemary": {"cornstarch":2, "cream cheese":2, "cayenne pepper":2, "green onions":2, "honey":2, "oil":2, "lemon juice":2, "olive oil":4, "white pepper":2, "almonds":2, "dijon mustard":3, "raisins":2, "carrots":2, "nutmeg":2, "sugar":2, "salt":2, "black pepper":2}, "cornstarch": {"elbow macaroni":4, "canned beef broth":4, "red wine":10, "bacon":33, "cayenne pepper":33, "lemon juice":341, "honey":124, "swiss cheese":4, "paprika":67, "ground cinnamon":65, "bread":7, "yeast":4, "egg yolks":124, "green pepper":115, "baking powder":132, "saffron":7, "sesame oil":266, "pine nuts":11, "cinnamon":151, "cream of tartar":58, "avocado":3, "cheddar cheese":10, "tomatoes":64, "white pepper":95, "brown rice":5, "black beans":4, "pinto beans":2, "cauliflower":11, "frozen peas":15, "butter":407, "salmon":2, "orange juice":140, "lemon":39, "black pepper":86, "tumeric":4, "black olives":2, "buttermilk":16, "powdered sugar":47, "dried oregano":17, "eggplant":8, "hoisin sauce":42, "capers":11, "cornmeal":8, "cloves":26, "oil":731, "chicken":62, "blue cheese":2, "cucumber":11, "dry rosemary":2, "canola oil":12, "dried tarragon":5, "strawberries":39, "celery":98, "cornish game hens":4, "fresh cilantro":5, "fresh peaches":7, "nutmeg":84, "walnuts":21} } ================================================ FILE: cooking_recipes/data/desert.json ================================================ [ { "name": "Easy Cake", "num_served": 8, "ingredients": [ { "name": "butter", "amount": "1", "units": "cup", "description": "Butter" }, { "name": "brown sugar", "amount": "2", "units": "cup", "description": "Sugar" }, { "name": "flour", "amount": "3", "units": "cup", "description": "Flour" }, { "name": "eggs", "amount": "4", "units": "", "description": "Eggs" }, { "name": "baking powder", "amount": "5", "units": "teaspoon", "description": "Baking powder" }, { "name": "skim milk", "amount": "1", "units": "cup", "description": "Milk" }, { "name": "vanilla (extract)", "amount": "1", "units": "teaspoon", "description": "Vanilla extract" } ], "directions": ["Preheat oven to 350F.", "Mix together butter, sugar, eggs and vanilla extract in a mixing bowl.", "Mix in milk and then baking powder. Mix in flour, stirring lightly.", "Bake for 30 minutes."] }, { "name": "Apple Muffins", "num_served": 10, "ingredients": [ { "name": "egg", "amount": "1", "units": "", "description": "Egg" }, { "name": "milk", "amount": "1/2", "units": "cup", "description": "Milk" }, { "name": "vegetable oil", "amount": "1/4", "units": "cup", "description": "Vegetable oil" }, { "name": "applesauce", "amount": "1/2", "units": "cup", "description": "Applesauce" }, { "name": "flour", "amount": "1 1/2", "units": "cup", "description": "Flour" }, { "name": "brown sugar", "amount": "3/4", "units": "cup", "description": "Sugar" }, { "name": "baking powder", "amount": "2", "units": "teaspoon", "description": "Baking powder" }, { "name": "cinnamon", "amount": "1/2", "units": "teaspoon", "description": "Cinnamon" }, { "name": "salt", "amount": "1/2", "units": "teaspoon", "description": "Salt" } ], "directions": ["preheat oven to 375F.", "Beat egg in a bowl and then stir in milk, oil, and the applesauce.", "Then mix in the flour, most of the brown sugar, baking powder, cinnamon, and salt until everything is moist. Place batter in paper baking cups - about half to two thirds full. Sprinkle remainder of brown sugar top of muffins.", "Bake 25 to 30 minutes."] }, { "name": "Irene's Snickerdoodle Cookies", "num_served": 10, "ingredients": [ { "name": "shortening (vegetable)", "amount": "1", "units": "cup", "description": "Shortening" }, { "name": "sugar", "amount": "1 3/4", "units": "cup", "description": "Sugar" }, { "name": "eggs", "amount": "2", "units": "", "description": "Eggs" }, { "name": "flour", "amount": "3", "units": "cup", "description": "Flour" }, { "name": "cream of tartar", "amount": "2", "units": "teaspoon", "description": "Cream of tartar" }, { "name": "baking soda", "amount": "1", "units": "teaspoon", "description": "Soda" }, { "name": "salt", "amount": "1/4", "units": "teaspoon", "description": "Salt" }, { "name": "cinnamon", "amount": "1", "units": "dash", "description": "Cinnamon sugar" } ], "directions": ["preheat oven to 375F.", "Mix together the vegetable shortening, sugar and eggs in a small mixing bowl.", "Sift together flour and mix well with the cream of tartar, soda and salt.", "Mix together both mixtures and roll into balls about one inch in diameter and roll in cinnamon and sugar.", "Put on a lightly greased baking sheet, leaving about 1 1/2 inches between the cookies.", "Bake from 10 to 12 minutes until done."] }, { "name": "Scottish Shortbread", "num_served":10, "ingredients": [ { "name": "flour", "amount": "4", "units": "cup", "description": "Plain flour" }, { "name": "butter", "amount": "2", "units": "cup", "description": "Butter (nothing else will do)" }, { "name": "sugar", "amount": "1/2", "units": "cup", "description": "Sugar" }, { "name": "salt", "amount": "1", "units": "dash", "description": "Salt" } ], "directions": ["Preheat oven to 350F", "Sift flour on a large board. Place the sugar in a separate area on the board and mix in the butter.", "Knead in flour adding small amounts at a time.", "Grease a baking sheet. Roll dough into small balls, about one inch in diameter.", "Flatten the balls and place on the baking sheet.", "Bake for 30 minutes."] } ] ================================================ FILE: cooking_recipes/data/fish.json ================================================ [ {"name":"Honey Chinese Shrimp", "num_served":4, "ingredients": [{"name":"honey", "amount":"1/4", "units":"cup", "description":"Honey"}, {"name":"raw shrimp (medium-large)", "amount":"16", "units":"", "description":""}, {"name":"red wine", "amount":"1/4", "units":"cup", "description":"Red wine"}, {"name":"sesame oil", "amount":"2", "units":"tablespoon", "description":"Sesame oil"}, {"name":"soy sauce", "amount":"1.5", "units":"tablespoon", "description":"Soy Sauce"}, {"name":"worcestershire sauce (optional)", "amount":"1", "units":"teaspoon", "description":"Worcestershire"}, {"name":"Sriracha Hot Chili Sauce (optional, or substitute any chili sauce)", "amount":"2", "units":"teaspoon", "description":"Sriracha Hot Chili Sauce"}, {"name":"orange juice", "amount":"1/4", "units":"cup", "description":"Orange juice"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Black pepper"}], "directions": ["Mix together all ingredients and marinate in the refrigerator for at least one hour.", "There are two ways to cook this dish:", "1. Barbecue on a grill, occasionally basting with more marinade.", "2. Remove shrimp from marinade sauce and fry in a hot non-stick frying pan.", "This is good served over brown or white rice with a side of steamed vegetables."]}, { "name": "Chinese Shrimp with Zucchini Squash", "num_served": 2, "ingredients": [ { "name": "raw shrimp (or defrosted frozen)", "amount": "14", "units": "medium-large", "description": "medium shrimp" }, { "name": "cornstarch", "amount": "1", "units": "tablespoon", "description": "Cornstarch" }, { "name": "salt", "amount": "1/2", "units": "teaspoon", "description": "Salt" }, { "name": "black pepper", "amount": "1/2", "units": "teaspoon", "description": "Pepper" }, { "name": "zucchini squash (chopped)", "amount": "2", "units": "cup", "description": "Zucchini" }, { "name": "vegetable oil", "amount": "2", "units": "tablespoon", "description": "Oil" }, { "name": "sherry", "amount": "1", "units": "tablespoon", "description": "Sherry" }, { "name": "soy sauce", "amount": "1", "units": "tablespoon", "description": "Soy sauce" } ], "directions": ["I vary the proportion of shrimp to Zucchini squash depending on both my tastes and how much shrimp and Zucchini I have on-hand that I want to use up.", "Shell and chop the shrimps into three or four pieces and roll in cornstarch, salt and pepper - use a small bowl for this.", "Wash the zucchini and coarsely chop.", "Heat the oil in a non-stick pan and fry Zucchini until it is mostly done before adding the shrimp and the sherry.", "When the shrimp are done then mix in the soy sauce and serve immediately.", "Note: I like to eat this dish as-is but you might want to also try serving it with cooked Chinese style noodles or even a small amount of cooked Italian pasta."] } ] ================================================ FILE: cooking_recipes/data/ingredients.json ================================================ {"101010101": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":-0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt": "NULL NO NUTRIENT INGREDIENT -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":0.0, "folate_dfe":0.0, "choline":0.0, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":0.0, "ndb_no":1083011, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.0, "id":101010101, "energy_in_kcal":0.0, "fat_mono_unsaturated":0.0, "description": "NULL NO NUTRIENT INGREDIENT -- 1 cup", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "10101022": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":6.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":-0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt": "RED PEPPER FLAKES -- 1 tablespoon", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":20.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":9.0, "folate_dfe":0.0, "choline":0.0, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tablespoon", "calcium":0.0, "ndb_no":1083011, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.0, "id":10101022, "energy_in_kcal":0.0, "fat_mono_unsaturated":0.0, "description": "RED PEPPER FLAKES -- 1 tablespoon", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "10101674": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":5.0, "pantothenic_acid":0.0, "phosphorus":4.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":2.0, "sugar":-0.0, "vitamin_b12":3.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":2.0, "lipid_total":0.0, "prompt": "CHICKEN BROTH -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":6.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":236.0, "folate_dfe":0.0, "choline":0.0, "sodium":30.0, "magnesium":1.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":0.0, "ndb_no":1083011, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":3.0, "id":101010101, "energy_in_kcal":0.0, "fat_mono_unsaturated":0.0, "description": "CHICKEN BROTH -- 1 cup", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":1.0, "riboflavin":3.0, "copper":0.0}, "512": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":59.0, "pantothenic_acid":0.336, "phosphorus":100.0, "beta_crytoxanthin":-1.0, "thiamin":0.04, "selenium":2.3, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":4.97, "sugar":-1.0, "vitamin_b12":0.38, "cholesterol":4.0, "retinol":58.0, "potassium":162.0, "fat_poly_unsaturated":0.036, "lipid_total":0.97, "prompt": "MILK,LOWFAT,FLUID,1% MILKFAT,W\/ NONFAT MILK SOL&VIT A -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.045, "fiber":0.0, "vitamin_c":1.0, "protein":3.48, "vitamin_a":204.0, "niacin":0.09, "fat_saturated":0.604, "weight1_gram":245.0, "folate_dfe":5.0, "choline":-1.0, "sodium":52.0, "magnesium":14.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":128.0, "ndb_no":1083, "folate_total":5.0, "lutein_zeaxanthin":-1.0, "iron":0.05, "id":512, "energy_in_kcal":43.0, "fat_mono_unsaturated":0.28, "description": "MILK,LOWFAT,FLUID,1% MILKFAT,W\/ NONFAT MILK SOL&VIT A", "refuse_percent":0.0, "food_folate":5.0, "manganese":0.002, "zinc":0.4, "riboflavin":0.173, "copper":0.01}, "3008": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.313, "phosphorus":575.0, "beta_crytoxanthin":9.0, "thiamin":0.364, "selenium":0.7, "vitamin_k":53.9, "alpha_carotene":0.0, "carbohydrate":13.08, "sugar":3.59, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":597.0, "fat_poly_unsaturated":34.071, "lipid_total":68.37, "prompt":"NUTS,PINE NUTS,DRIED -- 1 cup", "vitamin_e":9.33, "vitamin_b6":0.094, "fiber":3.7, "vitamin_c":0.8, "protein":13.69, "vitamin_a":29.0, "niacin":4.387, "fat_saturated":4.899, "weight1_gram":135.08, "folate_dfe":34.0, "choline":55.8, "sodium":2.0, "magnesium":251.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":16.0, "ndb_no":12147, "folate_total":34.0, "lutein_zeaxanthin":53.9, "iron":5.53, "id":3008, "energy_in_kcal":673.0, "fat_mono_unsaturated":18.764, "description":"NUTS,PINE NUTS,DRIED", "refuse_percent":23.0, "food_folate":34.0, "manganese":8.802, "zinc":6.45, "riboflavin":0.227, "copper":1.324}, "2529": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":14.0, "pantothenic_acid":0.132, "phosphorus":11.0, "beta_crytoxanthin":77.0, "thiamin":0.013, "selenium":0.4, "vitamin_k":2.2, "alpha_carotene":58.0, "carbohydrate":23.98, "sugar":22.18, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":130.0, "fat_poly_unsaturated":0.064, "lipid_total":0.13, "prompt":"PEACHES,FRZ,SLICED,SWTND -- 1 cup, thawed", "vitamin_e":0.62, "vitamin_b6":0.018, "fiber":1.8, "vitamin_c":94.2, "protein":0.63, "vitamin_a":284.0, "niacin":0.653, "fat_saturated":0.014, "weight1_gram":250.0, "folate_dfe":3.0, "choline":5.1, "sodium":6.0, "magnesium":5.0, "folic_acid":0.0, "weight1_description":"1 cup, thawed", "calcium":3.0, "ndb_no":9250, "folate_total":3.0, "lutein_zeaxanthin":2.2, "iron":0.37, "id":2529, "energy_in_kcal":94.0, "fat_mono_unsaturated":0.048, "description":"PEACHES,FRZ,SLICED,SWTND", "refuse_percent":0.0, "food_folate":3.0, "manganese":0.029, "zinc":0.05, "riboflavin":0.035, "copper":0.024}, "3649": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":50.0, "pantothenic_acid":0.075, "phosphorus":37.0, "beta_crytoxanthin":1137.0, "thiamin":0.055, "selenium":0.6, "vitamin_k":207.0, "alpha_carotene":0.0, "carbohydrate":7.34, "sugar":2.33, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":276.0, "fat_poly_unsaturated":0.074, "lipid_total":0.19, "prompt": "ONIONS,SPRING OR SCALLIONS (INCL TOPS&BULB),RAW -- 1 cup, chopped", "vitamin_e":0.55, "vitamin_b6":0.061, "fiber":2.6, "vitamin_c":18.8, "protein":1.83, "vitamin_a":997.0, "niacin":0.525, "fat_saturated":0.032, "weight1_gram":100.0, "folate_dfe":64.0, "choline":5.7, "sodium":16.0, "magnesium":20.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":72.0, "ndb_no":11291, "folate_total":64.0, "lutein_zeaxanthin":207.0, "iron":1.48, "id":3649, "energy_in_kcal":32.0, "fat_mono_unsaturated":0.027, "description":"ONIONS,SPRING OR SCALLIONS (INCL TOPS&BULB),RAW", "refuse_percent":4.0, "food_folate":64.0, "manganese":0.16, "zinc":0.39, "riboflavin":0.08, "copper":0.083}, "4801": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":-1.0, "pantothenic_acid":-1.0, "phosphorus":300.0, "beta_crytoxanthin":-1.0, "thiamin":0.253, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":64.2, "sugar":8.04, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":-1.0, "potassium":93.0, "fat_poly_unsaturated":1.77, "lipid_total":22.9, "prompt":"NABISCO,NABISCO RITZ CRACKERS -- 1 serving", "vitamin_e":-1.0, "vitamin_b6":0.036, "fiber":1.9, "vitamin_c":0.0, "protein":7.2, "vitamin_a":0.0, "niacin":3.81, "fat_saturated":3.92, "weight1_gram":16.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":776.0, "magnesium":20.0, "folic_acid":-1.0, "weight1_description":"1 serving", "calcium":147.0, "ndb_no":18621, "folate_total":60.0, "lutein_zeaxanthin":-1.0, "iron":4.05, "id":4801, "energy_in_kcal":492.0, "fat_mono_unsaturated":17.95, "description":"NABISCO,NABISCO RITZ CRACKERS", "refuse_percent":0.0, "food_folate":-1.0, "manganese":-1.0, "zinc":1.45, "riboflavin":0.306, "copper":-1.0}, "6913": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.285, "phosphorus":83.0, "beta_crytoxanthin":0.0, "thiamin":0.096, "selenium":9.8, "vitamin_k":0.6, "alpha_carotene":0.0, "carbohydrate":22.96, "sugar":0.35, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":43.0, "fat_poly_unsaturated":0.323, "lipid_total":0.9, "prompt":"RICE,BROWN,LONG-GRAIN,CKD -- 1 cup", "vitamin_e":0.03, "vitamin_b6":0.145, "fiber":1.8, "vitamin_c":0.0, "protein":2.58, "vitamin_a":0.0, "niacin":1.528, "fat_saturated":0.18, "weight1_gram":195.0, "folate_dfe":4.0, "choline":9.2, "sodium":5.0, "magnesium":43.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":10.0, "ndb_no":20037, "folate_total":4.0, "lutein_zeaxanthin":0.6, "iron":0.42, "id":6913, "energy_in_kcal":111.0, "fat_mono_unsaturated":0.327, "description":"RICE,BROWN,LONG-GRAIN,CKD", "refuse_percent":0.0, "food_folate":4.0, "manganese":0.905, "zinc":0.63, "riboflavin":0.025, "copper":0.1}, "929": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":13.6, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":41.7, "lipid_total":100.0, "prompt":"OIL,SESAME,SALAD OR COOKING -- 1 tablespoon", "vitamin_e":1.4, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":14.2, "weight1_gram":13.6, "folate_dfe":0.0, "choline":0.2, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tablespoon", "calcium":0.0, "ndb_no":4058, "folate_total":0.0, "lutein_zeaxanthin":13.6, "iron":0.0, "id":929, "energy_in_kcal":884.0, "fat_mono_unsaturated":39.7, "description":"OIL,SESAME,SALAD OR COOKING", "refuse_percent":0.0, "food_folate":0.0, "manganese":-1.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "5057": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.63, "phosphorus":166.0, "beta_crytoxanthin":0.0, "thiamin":0.05, "selenium":30.6, "vitamin_k":4.3, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":2.28, "cholesterol":106.0, "retinol":0.0, "potassium":257.0, "fat_poly_unsaturated":0.97, "lipid_total":13.46, "prompt": "LAMB,DOM,FORESHANK,LN&FAT,1\/4\"FAT,CHOIC,CKD,BRSD -- 1 piece, cooked, excluding refuse (yield from 1 lb raw meat with refuse)", "vitamin_e":0.18, "vitamin_b6":0.1, "fiber":0.0, "vitamin_c":0.0, "protein":28.37, "vitamin_a":0.0, "niacin":5.46, "fat_saturated":5.63, "weight1_gram":148.0, "folate_dfe":17.0, "choline":110.0, "sodium":72.0, "magnesium":22.0, "folic_acid":0.0, "weight1_description": "1 piece, cooked, excluding refuse (yield from 1 lb raw meat with refuse)", "calcium":20.0, "ndb_no":17008, "folate_total":17.0, "lutein_zeaxanthin":4.3, "iron":2.14, "id":5057, "energy_in_kcal":243.0, "fat_mono_unsaturated":5.68, "description":"LAMB,DOM,FORESHANK,LN&FAT,1\/4\"FAT,CHOIC,CKD,BRSD", "refuse_percent":56.0, "food_folate":17.0, "manganese":0.025, "zinc":7.69, "riboflavin":0.19, "copper":0.123}, "6914": {"beta_carotene":-1.0, "lycopene":1.09, "vitamin_a_rae":0.0, "pantothenic_acid":1.349, "phosphorus":523.0, "beta_crytoxanthin":-1.0, "thiamin":0.763, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":66.27, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":429.0, "fat_poly_unsaturated":2.535, "lipid_total":6.9, "prompt":"OATS -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.119, "fiber":10.6, "vitamin_c":0.0, "protein":16.89, "vitamin_a":0.0, "niacin":0.961, "fat_saturated":1.217, "weight1_gram":156.0, "folate_dfe":56.0, "choline":-1.0, "sodium":2.0, "magnesium":177.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":54.0, "ndb_no":20038, "folate_total":56.0, "lutein_zeaxanthin":-1.0, "iron":4.72, "id":6914, "energy_in_kcal":389.0, "fat_mono_unsaturated":2.178, "description":"OATS", "refuse_percent":0.0, "food_folate":56.0, "manganese":4.916, "zinc":3.97, "riboflavin":0.139, "copper":0.626}, "3363": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.203, "phosphorus":34.0, "beta_crytoxanthin":0.0, "thiamin":0.025, "selenium":0.7, "vitamin_k":0.1, "alpha_carotene":0.0, "carbohydrate":17.77, "sugar":1.7, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":415.0, "fat_poly_unsaturated":0.154, "lipid_total":0.75, "prompt":"GINGER ROOT,RAW -- 1 tsp", "vitamin_e":0.26, "vitamin_b6":0.16, "fiber":2.0, "vitamin_c":5.0, "protein":1.82, "vitamin_a":0.0, "niacin":0.75, "fat_saturated":0.203, "weight1_gram":2.0, "folate_dfe":11.0, "choline":28.8, "sodium":13.0, "magnesium":43.0, "folic_acid":0.0, "weight1_description":"1 tsp", "calcium":16.0, "ndb_no":11216, "folate_total":11.0, "lutein_zeaxanthin":0.1, "iron":0.6, "id":3363, "energy_in_kcal":80.0, "fat_mono_unsaturated":0.154, "description":"GINGER ROOT,RAW", "refuse_percent":7.0, "food_folate":11.0, "manganese":0.229, "zinc":0.34, "riboflavin":0.034, "copper":0.226}, "3555": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":1.497, "phosphorus":86.0, "beta_crytoxanthin":0.0, "thiamin":0.081, "selenium":9.3, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":3.28, "sugar":1.65, "vitamin_b12":0.04, "cholesterol":0.0, "retinol":0.0, "potassium":318.0, "fat_poly_unsaturated":0.139, "lipid_total":0.34, "prompt":"MUSHROOMS,WHITE,RAW -- 1 cup, pieces or slices", "vitamin_e":0.01, "vitamin_b6":0.104, "fiber":1.0, "vitamin_c":2.1, "protein":3.09, "vitamin_a":0.0, "niacin":3.607, "fat_saturated":0.043, "weight1_gram":70.0, "folate_dfe":16.0, "choline":17.3, "sodium":5.0, "magnesium":9.0, "folic_acid":0.0, "weight1_description":"1 cup, pieces or slices", "calcium":3.0, "ndb_no":11260, "folate_total":16.0, "lutein_zeaxanthin":0.0, "iron":0.5, "id":3555, "energy_in_kcal":22.0, "fat_mono_unsaturated":0.0, "description":"MUSHROOMS,WHITE,RAW", "refuse_percent":3.0, "food_folate":16.0, "manganese":0.047, "zinc":0.52, "riboflavin":0.402, "copper":0.318}, "1859": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":3.0, "pantothenic_acid":0.061, "phosphorus":11.0, "beta_crytoxanthin":29.0, "thiamin":0.017, "selenium":0.0, "vitamin_k":2.2, "alpha_carotene":11.0, "carbohydrate":13.81, "sugar":10.39, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":107.0, "fat_poly_unsaturated":0.051, "lipid_total":0.17, "prompt":"APPLES,RAW,WITH SKIN -- 1 cup, quartered or chopped", "vitamin_e":0.18, "vitamin_b6":0.041, "fiber":2.4, "vitamin_c":4.6, "protein":0.26, "vitamin_a":54.0, "niacin":0.091, "fat_saturated":0.028, "weight1_gram":125.0, "folate_dfe":3.0, "choline":3.4, "sodium":1.0, "magnesium":5.0, "folic_acid":0.0, "weight1_description":"1 cup, quartered or chopped", "calcium":6.0, "ndb_no":9003, "folate_total":3.0, "lutein_zeaxanthin":2.2, "iron":0.12, "id":1859, "energy_in_kcal":52.0, "fat_mono_unsaturated":0.007, "description":"APPLES,RAW,WITH SKIN", "refuse_percent":10.0, "food_folate":3.0, "manganese":0.035, "zinc":0.04, "riboflavin":0.026, "copper":0.027}, "292": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":684.0, "pantothenic_acid":0.11, "phosphorus":24.0, "beta_crytoxanthin":0.0, "thiamin":0.005, "selenium":1.0, "vitamin_k":7.0, "alpha_carotene":0.0, "carbohydrate":0.06, "sugar":0.06, "vitamin_b12":0.17, "cholesterol":215.0, "retinol":671.0, "potassium":24.0, "fat_poly_unsaturated":3.043, "lipid_total":81.11, "prompt":"BUTTER,WITH SALT -- 1 cup", "vitamin_e":2.32, "vitamin_b6":0.003, "fiber":0.0, "vitamin_c":0.0, "protein":0.85, "vitamin_a":2499.0, "niacin":0.042, "fat_saturated":51.368, "weight1_gram":227.0, "folate_dfe":3.0, "choline":18.8, "sodium":576.0, "magnesium":2.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":24.0, "ndb_no":1001, "folate_total":3.0, "lutein_zeaxanthin":7.0, "iron":0.02, "id":292, "energy_in_kcal":717.0, "fat_mono_unsaturated":21.021, "description":"BUTTER,WITH SALT", "refuse_percent":0.0, "food_folate":3.0, "manganese":0.0, "zinc":0.09, "riboflavin":0.034, "copper":0.0}, "3652": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.098, "phosphorus":27.0, "beta_crytoxanthin":6.0, "thiamin":0.041, "selenium":0.5, "vitamin_k":0.3, "alpha_carotene":0.0, "carbohydrate":7.55, "sugar":5.02, "vitamin_b12":-1.0, "cholesterol":0.0, "retinol":-1.0, "potassium":119.0, "fat_poly_unsaturated":-1.0, "lipid_total":0.08, "prompt":"ONIONS,SWT,RAW -- 1 onion", "vitamin_e":0.02, "vitamin_b6":0.13, "fiber":0.9, "vitamin_c":4.8, "protein":0.8, "vitamin_a":1.0, "niacin":0.133, "fat_saturated":-1.0, "weight1_gram":331.48, "folate_dfe":-1.0, "choline":5.5, "sodium":8.0, "magnesium":9.0, "folic_acid":-1.0, "weight1_description":"1 onion", "calcium":20.0, "ndb_no":11294, "folate_total":23.0, "lutein_zeaxanthin":0.3, "iron":0.26, "id":3652, "energy_in_kcal":32.0, "fat_mono_unsaturated":-1.0, "description":"ONIONS,SWT,RAW", "refuse_percent":16.0, "food_folate":23.0, "manganese":0.076, "zinc":0.13, "riboflavin":0.02, "copper":0.056}, "1988": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":3.0, "pantothenic_acid":0.124, "phosphorus":12.0, "beta_crytoxanthin":80.0, "thiamin":0.037, "selenium":0.1, "vitamin_k":19.3, "alpha_carotene":0.0, "carbohydrate":14.49, "sugar":9.96, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":77.0, "fat_poly_unsaturated":0.146, "lipid_total":0.33, "prompt":"BLUEBERRIES,RAW -- 1 cup", "vitamin_e":0.57, "vitamin_b6":0.052, "fiber":2.4, "vitamin_c":9.7, "protein":0.74, "vitamin_a":54.0, "niacin":0.418, "fat_saturated":0.028, "weight1_gram":147.72, "folate_dfe":6.0, "choline":6.0, "sodium":1.0, "magnesium":6.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":6.0, "ndb_no":9050, "folate_total":6.0, "lutein_zeaxanthin":19.3, "iron":0.28, "id":1988, "energy_in_kcal":57.0, "fat_mono_unsaturated":0.047, "description":"BLUEBERRIES,RAW", "refuse_percent":5.0, "food_folate":6.0, "manganese":0.336, "zinc":0.16, "riboflavin":0.041, "copper":0.057}, "3109": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.229, "phosphorus":489.0, "beta_crytoxanthin":1.0, "thiamin":0.074, "selenium":2.8, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":19.29, "sugar":4.9, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":746.0, "fat_poly_unsaturated":12.649, "lipid_total":52.83, "prompt":"ALMONDS,DRY RSTD,W\/SALT -- 1 cup, whole kernels", "vitamin_e":26.0, "vitamin_b6":0.126, "fiber":11.8, "vitamin_c":0.0, "protein":22.09, "vitamin_a":1.0, "niacin":3.85, "fat_saturated":4.047, "weight1_gram":138.0, "folate_dfe":33.0, "choline":52.1, "sodium":339.0, "magnesium":286.0, "folic_acid":0.0, "weight1_description":"1 cup, whole kernels", "calcium":266.0, "ndb_no":12563, "folate_total":33.0, "lutein_zeaxanthin":0.0, "iron":4.51, "id":3109, "energy_in_kcal":597.0, "fat_mono_unsaturated":33.658, "description":"ALMONDS,DRY RSTD,W\/SALT", "refuse_percent":0.0, "food_folate":33.0, "manganese":2.62, "zinc":3.54, "riboflavin":0.859, "copper":1.17}, "1509": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":31.0, "pantothenic_acid":0.573, "phosphorus":66.0, "beta_crytoxanthin":1403.0, "thiamin":0.071, "selenium":2.5, "vitamin_k":101.6, "alpha_carotene":1.0, "carbohydrate":6.64, "sugar":1.7, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":316.0, "fat_poly_unsaturated":0.038, "lipid_total":0.37, "prompt":"BROCCOLI,RAW -- 1 cup, chopped", "vitamin_e":0.78, "vitamin_b6":0.175, "fiber":2.6, "vitamin_c":89.2, "protein":2.82, "vitamin_a":623.0, "niacin":0.639, "fat_saturated":0.039, "weight1_gram":90.93, "folate_dfe":63.0, "choline":18.7, "sodium":33.0, "magnesium":21.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":47.0, "ndb_no":11090, "folate_total":63.0, "lutein_zeaxanthin":101.6, "iron":0.73, "id":1509, "energy_in_kcal":34.0, "fat_mono_unsaturated":0.011, "description":"BROCCOLI,RAW", "refuse_percent":39.0, "food_folate":63.0, "manganese":0.21, "zinc":0.41, "riboflavin":0.117, "copper":0.049}, "3845": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.341, "phosphorus":72.0, "beta_crytoxanthin":31.0, "thiamin":0.072, "selenium":0.8, "vitamin_k":2.8, "alpha_carotene":0.0, "carbohydrate":19.59, "sugar":1.43, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":545.0, "fat_poly_unsaturated":0.042, "lipid_total":0.15, "prompt": "POTATOES,RED,FLESH & SKN,BKD -- 1 potato, large (3\" to 4-1\/4\" dia.", "vitamin_e":0.04, "vitamin_b6":0.212, "fiber":1.8, "vitamin_c":12.6, "protein":2.3, "vitamin_a":10.0, "niacin":1.595, "fat_saturated":0.025, "weight1_gram":298.9, "folate_dfe":27.0, "choline":18.9, "sodium":12.0, "magnesium":28.0, "folic_acid":0.0, "weight1_description":"1 potato, large (3\" to 4-1\/4\" dia.", "calcium":9.0, "ndb_no":11358, "folate_total":27.0, "lutein_zeaxanthin":2.8, "iron":0.7, "id":3845, "energy_in_kcal":89.0, "fat_mono_unsaturated":0.002, "description":"POTATOES,RED,FLESH & SKN,BKD", "refuse_percent":0.0, "food_folate":27.0, "manganese":0.173, "zinc":0.4, "riboflavin":0.05, "copper":0.174}, "6981": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.135, "phosphorus":54.0, "beta_crytoxanthin":56.0, "thiamin":0.083, "selenium":8.6, "vitamin_k":0.8, "alpha_carotene":0.0, "carbohydrate":28.22, "sugar":0.28, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":93.0, "fat_poly_unsaturated":0.214, "lipid_total":0.44, "prompt":"BARLEY,PEARLED,COOKED -- 1 cup", "vitamin_e":0.01, "vitamin_b6":0.115, "fiber":3.8, "vitamin_c":0.0, "protein":2.26, "vitamin_a":7.0, "niacin":2.063, "fat_saturated":0.093, "weight1_gram":157.0, "folate_dfe":16.0, "choline":13.4, "sodium":3.0, "magnesium":22.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":11.0, "ndb_no":20006, "folate_total":16.0, "lutein_zeaxanthin":0.8, "iron":1.33, "id":6981, "energy_in_kcal":123.0, "fat_mono_unsaturated":0.057, "description":"BARLEY,PEARLED,COOKED", "refuse_percent":0.0, "food_folate":16.0, "manganese":0.259, "zinc":0.82, "riboflavin":0.062, "copper":0.105}, "4102": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":25.0, "pantothenic_acid":0.367, "phosphorus":93.0, "beta_crytoxanthin":-1.0, "thiamin":0.042, "selenium":0.3, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":3.11, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":459.0, "fat_poly_unsaturated":0.169, "lipid_total":0.4, "prompt":"SQUASH,ZUCCHINI,BABY,RAW -- 1 large", "vitamin_e":-1.0, "vitamin_b6":0.142, "fiber":1.1, "vitamin_c":34.1, "protein":2.71, "vitamin_a":490.0, "niacin":0.705, "fat_saturated":0.083, "weight1_gram":16.0, "folate_dfe":20.0, "choline":-1.0, "sodium":3.0, "magnesium":33.0, "folic_acid":0.0, "weight1_description":"1 large", "calcium":21.0, "ndb_no":11953, "folate_total":20.0, "lutein_zeaxanthin":-1.0, "iron":0.79, "id":4102, "energy_in_kcal":21.0, "fat_mono_unsaturated":0.031, "description":"SQUASH,ZUCCHINI,BABY,RAW", "refuse_percent":13.0, "food_folate":20.0, "manganese":0.196, "zinc":0.83, "riboflavin":0.036, "copper":0.097}, "6246": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":-1.0, "pantothenic_acid":-1.0, "phosphorus":378.0, "beta_crytoxanthin":-1.0, "thiamin":0.96, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":67.9, "sugar":10.0, "vitamin_b12":-1.0, "cholesterol":14.0, "retinol":-1.0, "potassium":423.0, "fat_poly_unsaturated":-1.0, "lipid_total":3.7, "prompt": "KRAFT MACARONI & CHEESE DINNER ORIGINAL FLAVOR,UNPREP -- 1 NLEA Serving, (makes about 1 cup prepared)", "vitamin_e":-1.0, "vitamin_b6":-1.0, "fiber":2.1, "vitamin_c":0.5, "protein":16.2, "vitamin_a":72.0, "niacin":6.48, "fat_saturated":1.8, "weight1_gram":70.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":802.0, "magnesium":-1.0, "folic_acid":-1.0, "weight1_description": "1 NLEA Serving, (makes about 1 cup prepared)", "calcium":132.0, "ndb_no":22005, "folate_total":93.0, "lutein_zeaxanthin":-1.0, "iron":3.66, "id":6246, "energy_in_kcal":370.0, "fat_mono_unsaturated":-1.0, "description": "KRAFT MACARONI & CHEESE DINNER ORIGINAL FLAVOR,UNPREP", "refuse_percent":0.0, "food_folate":-1.0, "manganese":-1.0, "zinc":-1.0, "riboflavin":0.59, "copper":-1.0}, "390": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":137.0, "pantothenic_acid":0.09, "phosphorus":524.0, "beta_crytoxanthin":0.0, "thiamin":0.101, "selenium":16.3, "vitamin_k":1.3, "alpha_carotene":0.0, "carbohydrate":3.83, "sugar":0.6, "vitamin_b12":2.31, "cholesterol":54.0, "retinol":133.0, "potassium":95.0, "fat_poly_unsaturated":0.626, "lipid_total":20.03, "prompt": "CHEESE,MOZZARELLA,PART SKIM MILK,LO MOIST -- 1 cup, diced", "vitamin_e":0.37, "vitamin_b6":0.079, "fiber":0.0, "vitamin_c":0.0, "protein":25.96, "vitamin_a":517.0, "niacin":0.119, "fat_saturated":12.67, "weight1_gram":132.0, "folate_dfe":10.0, "choline":14.2, "sodium":528.0, "magnesium":26.0, "folic_acid":0.0, "weight1_description":"1 cup, diced", "calcium":731.0, "ndb_no":1029, "folate_total":10.0, "lutein_zeaxanthin":1.3, "iron":0.25, "id":390, "energy_in_kcal":302.0, "fat_mono_unsaturated":5.73, "description":"CHEESE,MOZZARELLA,PART SKIM MILK,LO MOIST", "refuse_percent":0.0, "food_folate":10.0, "manganese":0.011, "zinc":3.13, "riboflavin":0.329, "copper":0.027}, "1574": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":38.0, "pantothenic_acid":0.309, "phosphorus":69.0, "beta_crytoxanthin":1590.0, "thiamin":0.139, "selenium":1.6, "vitamin_k":177.0, "alpha_carotene":0.0, "carbohydrate":8.95, "sugar":2.2, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":389.0, "fat_poly_unsaturated":0.153, "lipid_total":0.3, "prompt":"BRUSSELS SPROUTS,RAW -- 1 cup", "vitamin_e":0.88, "vitamin_b6":0.219, "fiber":3.8, "vitamin_c":85.0, "protein":3.38, "vitamin_a":754.0, "niacin":0.745, "fat_saturated":0.062, "weight1_gram":88.0, "folate_dfe":61.0, "choline":19.1, "sodium":25.0, "magnesium":23.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":42.0, "ndb_no":11098, "folate_total":61.0, "lutein_zeaxanthin":177.0, "iron":1.4, "id":1574, "energy_in_kcal":43.0, "fat_mono_unsaturated":0.023, "description":"BRUSSELS SPROUTS,RAW", "refuse_percent":10.0, "food_folate":61.0, "manganese":0.337, "zinc":0.42, "riboflavin":0.09, "copper":0.07}, "3079": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":75.0, "pantothenic_acid":0.186, "phosphorus":29.0, "beta_crytoxanthin":-1.0, "thiamin":0.046, "selenium":0.4, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":3.18, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":212.0, "fat_poly_unsaturated":0.076, "lipid_total":0.19, "prompt":"TOMATOES,ORANGE,RAW -- 1 cup, chopped", "vitamin_e":-1.0, "vitamin_b6":0.06, "fiber":0.9, "vitamin_c":16.0, "protein":1.16, "vitamin_a":1496.0, "niacin":0.593, "fat_saturated":0.025, "weight1_gram":158.0, "folate_dfe":29.0, "choline":-1.0, "sodium":42.0, "magnesium":8.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":5.0, "ndb_no":11695, "folate_total":29.0, "lutein_zeaxanthin":-1.0, "iron":0.47, "id":3079, "energy_in_kcal":16.0, "fat_mono_unsaturated":0.028, "description":"TOMATOES,ORANGE,RAW", "refuse_percent":9.0, "food_folate":29.0, "manganese":0.088, "zinc":0.14, "riboflavin":0.034, "copper":0.062}, "295": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":198.0, "pantothenic_acid":1.729, "phosphorus":387.0, "beta_crytoxanthin":0.0, "thiamin":0.029, "selenium":14.5, "vitamin_k":2.4, "alpha_carotene":0.0, "carbohydrate":2.34, "sugar":0.5, "vitamin_b12":1.22, "cholesterol":75.0, "retinol":192.0, "potassium":256.0, "fat_poly_unsaturated":0.8, "lipid_total":28.74, "prompt":"CHEESE,BLUE -- 1 oz", "vitamin_e":0.25, "vitamin_b6":0.166, "fiber":0.0, "vitamin_c":0.0, "protein":21.4, "vitamin_a":763.0, "niacin":1.016, "fat_saturated":18.669, "weight1_gram":28.35, "folate_dfe":36.0, "choline":15.4, "sodium":1395.0, "magnesium":23.0, "folic_acid":0.0, "weight1_description":"1 oz", "calcium":528.0, "ndb_no":1004, "folate_total":36.0, "lutein_zeaxanthin":2.4, "iron":0.31, "id":295, "energy_in_kcal":353.0, "fat_mono_unsaturated":7.778, "description":"CHEESE,BLUE", "refuse_percent":0.0, "food_folate":36.0, "manganese":0.009, "zinc":2.66, "riboflavin":0.382, "copper":0.04}, "487": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":279.0, "pantothenic_acid":0.259, "phosphorus":61.0, "beta_crytoxanthin":0.0, "thiamin":0.024, "selenium":0.5, "vitamin_k":2.7, "alpha_carotene":0.0, "carbohydrate":2.96, "sugar":0.11, "vitamin_b12":0.2, "cholesterol":111.0, "retinol":274.0, "potassium":97.0, "fat_poly_unsaturated":0.884, "lipid_total":30.91, "prompt":"CREAM,FLUID,LT WHIPPING -- 1 cup, whipped", "vitamin_e":0.88, "vitamin_b6":0.028, "fiber":0.0, "vitamin_c":0.6, "protein":2.17, "vitamin_a":1013.0, "niacin":0.042, "fat_saturated":19.337, "weight1_gram":120.0, "folate_dfe":4.0, "choline":16.8, "sodium":34.0, "magnesium":7.0, "folic_acid":0.0, "weight1_description":"1 cup, whipped", "calcium":69.0, "ndb_no":1052, "folate_total":4.0, "lutein_zeaxanthin":2.7, "iron":0.03, "id":487, "energy_in_kcal":292.0, "fat_mono_unsaturated":9.093, "description":"CREAM,FLUID,LT WHIPPING", "refuse_percent":0.0, "food_folate":4.0, "manganese":0.001, "zinc":0.25, "riboflavin":0.125, "copper":0.007}, "3655": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":421.0, "pantothenic_acid":0.4, "phosphorus":58.0, "beta_crytoxanthin":5561.0, "thiamin":0.086, "selenium":0.1, "vitamin_k":1640.0, "alpha_carotene":0.0, "carbohydrate":6.33, "sugar":0.85, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":554.0, "fat_poly_unsaturated":0.124, "lipid_total":0.79, "prompt":"PARSLEY,RAW -- 1 cup", "vitamin_e":0.75, "vitamin_b6":0.09, "fiber":3.3, "vitamin_c":133.0, "protein":2.97, "vitamin_a":8424.0, "niacin":1.313, "fat_saturated":0.132, "weight1_gram":60.0, "folate_dfe":152.0, "choline":12.8, "sodium":56.0, "magnesium":50.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":138.0, "ndb_no":11297, "folate_total":152.0, "lutein_zeaxanthin":1640.0, "iron":6.2, "id":3655, "energy_in_kcal":36.0, "fat_mono_unsaturated":0.295, "description":"PARSLEY,RAW", "refuse_percent":5.0, "food_folate":152.0, "manganese":0.16, "zinc":1.07, "riboflavin":0.098, "copper":0.149}, "7079": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.431, "phosphorus":189.0, "beta_crytoxanthin":18.0, "thiamin":0.891, "selenium":63.2, "vitamin_k":0.1, "alpha_carotene":0.0, "carbohydrate":74.67, "sugar":2.67, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":223.0, "fat_poly_unsaturated":0.564, "lipid_total":1.51, "prompt":"MACARONI,DRY,ENR -- 1 cup, elbow shaped", "vitamin_e":0.11, "vitamin_b6":0.142, "fiber":3.2, "vitamin_c":0.0, "protein":13.04, "vitamin_a":0.0, "niacin":7.177, "fat_saturated":0.277, "weight1_gram":105.0, "folate_dfe":391.0, "choline":15.1, "sodium":6.0, "magnesium":53.0, "folic_acid":219.0, "weight1_description":"1 cup, elbow shaped", "calcium":21.0, "ndb_no":20099, "folate_total":237.0, "lutein_zeaxanthin":0.1, "iron":3.3, "id":7079, "energy_in_kcal":371.0, "fat_mono_unsaturated":0.171, "description":"MACARONI,DRY,ENR", "refuse_percent":0.0, "food_folate":18.0, "manganese":0.917, "zinc":1.41, "riboflavin":0.4, "copper":0.289}, "4071": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.165, "phosphorus":20.0, "beta_crytoxanthin":10.0, "thiamin":0.012, "selenium":0.6, "vitamin_k":1.3, "alpha_carotene":0.0, "carbohydrate":3.4, "sugar":1.86, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":233.0, "fat_poly_unsaturated":0.048, "lipid_total":0.1, "prompt":"RADISHES,RAW -- 1 cup, slices", "vitamin_e":0.0, "vitamin_b6":0.071, "fiber":1.6, "vitamin_c":14.8, "protein":0.68, "vitamin_a":7.0, "niacin":0.254, "fat_saturated":0.032, "weight1_gram":116.0, "folate_dfe":25.0, "choline":6.5, "sodium":39.0, "magnesium":10.0, "folic_acid":0.0, "weight1_description":"1 cup, slices", "calcium":25.0, "ndb_no":11429, "folate_total":25.0, "lutein_zeaxanthin":1.3, "iron":0.34, "id":4071, "energy_in_kcal":16.0, "fat_mono_unsaturated":0.017, "description":"RADISHES,RAW", "refuse_percent":10.0, "food_folate":25.0, "manganese":0.069, "zinc":0.28, "riboflavin":0.039, "copper":0.05}, "3080": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.11, "phosphorus":36.0, "beta_crytoxanthin":-1.0, "thiamin":0.041, "selenium":0.4, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":2.98, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":258.0, "fat_poly_unsaturated":0.108, "lipid_total":0.26, "prompt":"TOMATOES,YELLOW,RAW -- 1 cup, chopped", "vitamin_e":-1.0, "vitamin_b6":0.056, "fiber":0.7, "vitamin_c":9.0, "protein":0.98, "vitamin_a":0.0, "niacin":1.179, "fat_saturated":0.036, "weight1_gram":139.0, "folate_dfe":30.0, "choline":-1.0, "sodium":23.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":11.0, "ndb_no":11696, "folate_total":30.0, "lutein_zeaxanthin":-1.0, "iron":0.49, "id":3080, "energy_in_kcal":15.0, "fat_mono_unsaturated":0.04, "description":"TOMATOES,YELLOW,RAW", "refuse_percent":9.0, "food_folate":30.0, "manganese":0.12, "zinc":0.28, "riboflavin":0.047, "copper":0.101}, "1224": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":-1.0, "phosphorus":8.0, "beta_crytoxanthin":-1.0, "thiamin":-1.0, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":0.27, "sugar":0.0, "vitamin_b12":-1.0, "cholesterol":-1.0, "retinol":-1.0, "potassium":39.0, "fat_poly_unsaturated":-1.0, "lipid_total":0.0, "prompt":"VINEGAR,RED WINE -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":-1.0, "fiber":0.0, "vitamin_c":0.5, "protein":0.04, "vitamin_a":0.0, "niacin":-1.0, "fat_saturated":0.0, "weight1_gram":239.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":8.0, "magnesium":4.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":6.0, "ndb_no":2068, "folate_total":-1.0, "lutein_zeaxanthin":-1.0, "iron":0.45, "id":1224, "energy_in_kcal":19.0, "fat_mono_unsaturated":-1.0, "description":"VINEGAR,RED WINE", "refuse_percent":0.0, "food_folate":-1.0, "manganese":0.046, "zinc":0.03, "riboflavin":-1.0, "copper":0.01}, "3816": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.545, "phosphorus":174.0, "beta_crytoxanthin":0.0, "thiamin":0.03, "selenium":21.5, "vitamin_k":2.3, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":2.65, "cholesterol":84.0, "retinol":0.0, "potassium":305.0, "fat_poly_unsaturated":0.636, "lipid_total":21.83, "prompt": "BEEF,GROUND,PATTIES,FRZ,CKD,BRLD -- 1 unit, cooked (yield from 1 lb raw meat)", "vitamin_e":0.0, "vitamin_b6":0.435, "fiber":0.0, "vitamin_c":0.0, "protein":23.05, "vitamin_a":0.0, "niacin":5.305, "fat_saturated":8.805, "weight1_gram":313.0, "folate_dfe":21.0, "choline":74.6, "sodium":77.0, "magnesium":19.0, "folic_acid":0.0, "weight1_description":"1 unit, cooked (yield from 1 lb raw meat)", "calcium":11.0, "ndb_no":13317, "folate_total":21.0, "lutein_zeaxanthin":2.3, "iron":2.42, "id":3816, "energy_in_kcal":295.0, "fat_mono_unsaturated":9.358, "description":"BEEF,GROUND,PATTIES,FRZ,CKD,BRLD", "refuse_percent":0.0, "food_folate":21.0, "manganese":0.022, "zinc":4.84, "riboflavin":0.176, "copper":0.077}, "1225": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":-1.0, "phosphorus":19.0, "beta_crytoxanthin":-1.0, "thiamin":-1.0, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":17.03, "sugar":14.95, "vitamin_b12":-1.0, "cholesterol":-1.0, "retinol":-1.0, "potassium":112.0, "fat_poly_unsaturated":-1.0, "lipid_total":0.0, "prompt":"VINEGAR,BALSAMIC -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":-1.0, "fiber":-1.0, "vitamin_c":0.0, "protein":0.49, "vitamin_a":0.0, "niacin":-1.0, "fat_saturated":0.0, "weight1_gram":255.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":23.0, "magnesium":12.0, "folic_acid":-1.0, "weight1_description":"1 cup", "calcium":27.0, "ndb_no":2069, "folate_total":-1.0, "lutein_zeaxanthin":-1.0, "iron":0.72, "id":1225, "energy_in_kcal":88.0, "fat_mono_unsaturated":-1.0, "description":"VINEGAR,BALSAMIC", "refuse_percent":0.0, "food_folate":-1.0, "manganese":0.131, "zinc":0.08, "riboflavin":-1.0, "copper":0.026}, "393": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":120.0, "pantothenic_acid":0.325, "phosphorus":729.0, "beta_crytoxanthin":0.0, "thiamin":0.029, "selenium":17.7, "vitamin_k":1.9, "alpha_carotene":0.0, "carbohydrate":4.06, "sugar":0.9, "vitamin_b12":2.26, "cholesterol":88.0, "retinol":117.0, "potassium":125.0, "fat_poly_unsaturated":1.173, "lipid_total":28.61, "prompt":"CHEESE,PARMESAN,GRATED -- 1 cup", "vitamin_e":0.26, "vitamin_b6":0.049, "fiber":0.0, "vitamin_c":0.0, "protein":38.46, "vitamin_a":442.0, "niacin":0.114, "fat_saturated":17.301, "weight1_gram":100.0, "folate_dfe":10.0, "choline":15.4, "sodium":1529.0, "magnesium":38.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":1109.0, "ndb_no":1032, "folate_total":10.0, "lutein_zeaxanthin":1.9, "iron":0.9, "id":393, "energy_in_kcal":431.0, "fat_mono_unsaturated":8.375, "description":"CHEESE,PARMESAN,GRATED", "refuse_percent":0.0, "food_folate":10.0, "manganese":0.085, "zinc":3.87, "riboflavin":0.486, "copper":0.238}, "3753": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":18.0, "pantothenic_acid":0.099, "phosphorus":20.0, "beta_crytoxanthin":341.0, "thiamin":0.057, "selenium":0.0, "vitamin_k":7.4, "alpha_carotene":7.0, "carbohydrate":4.64, "sugar":2.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":175.0, "fat_poly_unsaturated":0.062, "lipid_total":0.17, "prompt":"PEPPERS,SWT,GRN,RAW -- 1 cup, chopped", "vitamin_e":0.37, "vitamin_b6":0.224, "fiber":1.7, "vitamin_c":80.4, "protein":0.86, "vitamin_a":370.0, "niacin":0.48, "fat_saturated":0.058, "weight1_gram":149.0, "folate_dfe":10.0, "choline":5.5, "sodium":3.0, "magnesium":10.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":10.0, "ndb_no":11333, "folate_total":10.0, "lutein_zeaxanthin":7.4, "iron":0.34, "id":3753, "energy_in_kcal":20.0, "fat_mono_unsaturated":0.008, "description":"PEPPERS,SWT,GRN,RAW", "refuse_percent":18.0, "food_folate":10.0, "manganese":0.122, "zinc":0.13, "riboflavin":0.028, "copper":0.066}, "298": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":241.0, "pantothenic_acid":1.364, "phosphorus":347.0, "beta_crytoxanthin":0.0, "thiamin":0.028, "selenium":14.5, "vitamin_k":2.0, "alpha_carotene":0.0, "carbohydrate":0.46, "sugar":0.46, "vitamin_b12":1.3, "cholesterol":72.0, "retinol":240.0, "potassium":187.0, "fat_poly_unsaturated":0.724, "lipid_total":24.26, "prompt":"CHEESE,CAMEMBERT -- 1 cup", "vitamin_e":0.21, "vitamin_b6":0.227, "fiber":0.0, "vitamin_c":0.0, "protein":19.8, "vitamin_a":820.0, "niacin":0.63, "fat_saturated":15.259, "weight1_gram":246.0, "folate_dfe":62.0, "choline":15.4, "sodium":842.0, "magnesium":20.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":388.0, "ndb_no":1007, "folate_total":62.0, "lutein_zeaxanthin":2.0, "iron":0.33, "id":298, "energy_in_kcal":300.0, "fat_mono_unsaturated":7.023, "description":"CHEESE,CAMEMBERT", "refuse_percent":0.0, "food_folate":62.0, "manganese":0.038, "zinc":2.38, "riboflavin":0.488, "copper":0.021}, "4458": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":7.0, "pantothenic_acid":0.314, "phosphorus":55.0, "beta_crytoxanthin":0.0, "thiamin":0.112, "selenium":0.7, "vitamin_k":2.3, "alpha_carotene":0.0, "carbohydrate":27.88, "sugar":0.5, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":816.0, "fat_poly_unsaturated":0.076, "lipid_total":0.17, "prompt":"YAM,RAW -- 1 cup, cubes", "vitamin_e":0.35, "vitamin_b6":0.293, "fiber":4.1, "vitamin_c":17.1, "protein":1.53, "vitamin_a":138.0, "niacin":0.552, "fat_saturated":0.037, "weight1_gram":150.0, "folate_dfe":23.0, "choline":16.5, "sodium":9.0, "magnesium":21.0, "folic_acid":0.0, "weight1_description":"1 cup, cubes", "calcium":17.0, "ndb_no":11601, "folate_total":23.0, "lutein_zeaxanthin":2.3, "iron":0.54, "id":4458, "energy_in_kcal":118.0, "fat_mono_unsaturated":0.006, "description":"YAM,RAW", "refuse_percent":14.0, "food_folate":23.0, "manganese":0.397, "zinc":0.24, "riboflavin":0.032, "copper":0.178}, "3722": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.314, "phosphorus":176.0, "beta_crytoxanthin":0.0, "thiamin":0.101, "selenium":13.9, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":2.79, "cholesterol":61.0, "retinol":0.0, "potassium":281.0, "fat_poly_unsaturated":0.55, "lipid_total":15.41, "prompt": "BEEF,SHRT LOIN,T-BONE STEAK,LN & FAT,1\/4\" FAT,USDA CHOIC,RAW -- 1 lb", "vitamin_e":0.11, "vitamin_b6":0.388, "fiber":0.0, "vitamin_c":0.0, "protein":19.17, "vitamin_a":0.0, "niacin":3.67, "fat_saturated":5.838, "weight1_gram":453.6, "folate_dfe":6.0, "choline":-1.0, "sodium":54.0, "magnesium":20.0, "folic_acid":0.0, "weight1_description":"1 lb", "calcium":4.0, "ndb_no":13233, "folate_total":6.0, "lutein_zeaxanthin":-1.0, "iron":3.29, "id":3722, "energy_in_kcal":221.0, "fat_mono_unsaturated":6.7, "description": "BEEF,SHRT LOIN,T-BONE STEAK,LN & FAT,1\/4\" FAT,USDA CHOIC,RAW", "refuse_percent":22.0, "food_folate":6.0, "manganese":0.013, "zinc":3.32, "riboflavin":0.175, "copper":0.08}, "3882": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.76, "phosphorus":89.0, "beta_crytoxanthin":34.0, "thiamin":0.2, "selenium":0.6, "vitamin_k":0.3, "alpha_carotene":0.0, "carbohydrate":19.02, "sugar":3.22, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":270.0, "fat_poly_unsaturated":0.559, "lipid_total":1.18, "prompt": "CORN,SWEET,WHITE,RAW -- 1 ear, small (5-1\/2\" to 6-1\/2\" long)", "vitamin_e":0.07, "vitamin_b6":0.055, "fiber":2.7, "vitamin_c":6.8, "protein":3.22, "vitamin_a":1.0, "niacin":1.7, "fat_saturated":0.182, "weight1_gram":73.0, "folate_dfe":46.0, "choline":-1.0, "sodium":15.0, "magnesium":37.0, "folic_acid":0.0, "weight1_description":"1 ear, small (5-1\/2\" to 6-1\/2\" long)", "calcium":2.0, "ndb_no":11900, "folate_total":46.0, "lutein_zeaxanthin":0.3, "iron":0.52, "id":3882, "energy_in_kcal":86.0, "fat_mono_unsaturated":0.347, "description":"CORN,SWEET,WHITE,RAW", "refuse_percent":64.0, "food_folate":46.0, "manganese":0.161, "zinc":0.45, "riboflavin":0.06, "copper":0.054}, "3243": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":218.0, "pantothenic_acid":0.324, "phosphorus":58.0, "beta_crytoxanthin":323.0, "thiamin":0.078, "selenium":0.9, "vitamin_k":212.7, "alpha_carotene":0.0, "carbohydrate":4.35, "sugar":1.85, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":296.0, "fat_poly_unsaturated":0.267, "lipid_total":0.73, "prompt":"CHIVES,RAW -- 1 tbsp, chopped", "vitamin_e":0.21, "vitamin_b6":0.138, "fiber":2.5, "vitamin_c":58.1, "protein":3.27, "vitamin_a":4353.0, "niacin":0.647, "fat_saturated":0.146, "weight1_gram":3.0, "folate_dfe":105.0, "choline":5.2, "sodium":3.0, "magnesium":42.0, "folic_acid":0.0, "weight1_description":"1 tbsp, chopped", "calcium":92.0, "ndb_no":11156, "folate_total":105.0, "lutein_zeaxanthin":212.7, "iron":1.6, "id":3243, "energy_in_kcal":30.0, "fat_mono_unsaturated":0.095, "description":"CHIVES,RAW", "refuse_percent":0.0, "food_folate":105.0, "manganese":0.373, "zinc":0.56, "riboflavin":0.115, "copper":0.157}, "491": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":177.0, "pantothenic_acid":0.36, "phosphorus":85.0, "beta_crytoxanthin":0.0, "thiamin":0.035, "selenium":2.2, "vitamin_k":1.0, "alpha_carotene":0.0, "carbohydrate":4.27, "sugar":0.16, "vitamin_b12":0.3, "cholesterol":44.0, "retinol":174.0, "potassium":144.0, "fat_poly_unsaturated":0.778, "lipid_total":20.96, "prompt":"CREAM,SOUR,CULTURED -- 1 cup", "vitamin_e":0.6, "vitamin_b6":0.016, "fiber":0.0, "vitamin_c":0.9, "protein":3.16, "vitamin_a":648.0, "niacin":0.067, "fat_saturated":13.047, "weight1_gram":230.0, "folate_dfe":11.0, "choline":19.2, "sodium":53.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":116.0, "ndb_no":1056, "folate_total":11.0, "lutein_zeaxanthin":1.0, "iron":0.06, "id":491, "energy_in_kcal":214.0, "fat_mono_unsaturated":6.054, "description":"CREAM,SOUR,CULTURED", "refuse_percent":0.0, "food_folate":11.0, "manganese":0.003, "zinc":0.27, "riboflavin":0.149, "copper":0.019}, "3563": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":3.594, "phosphorus":29.0, "beta_crytoxanthin":0.0, "thiamin":0.037, "selenium":24.8, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":14.39, "sugar":3.61, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":117.0, "fat_poly_unsaturated":0.034, "lipid_total":0.22, "prompt":"MUSHROOMS,SHIITAKE,CKD,WO\/SALT -- 1 cup, pieces", "vitamin_e":0.03, "vitamin_b6":0.159, "fiber":2.1, "vitamin_c":0.3, "protein":1.56, "vitamin_a":0.0, "niacin":1.5, "fat_saturated":0.05, "weight1_gram":145.0, "folate_dfe":21.0, "choline":36.8, "sodium":4.0, "magnesium":14.0, "folic_acid":0.0, "weight1_description":"1 cup, pieces", "calcium":3.0, "ndb_no":11269, "folate_total":21.0, "lutein_zeaxanthin":0.0, "iron":0.44, "id":3563, "energy_in_kcal":56.0, "fat_mono_unsaturated":0.07, "description":"MUSHROOMS,SHIITAKE,CKD,WO\/SALT", "refuse_percent":0.0, "food_folate":21.0, "manganese":0.204, "zinc":1.33, "riboflavin":0.17, "copper":0.896}, "2763": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":8.0, "pantothenic_acid":0.563, "phosphorus":70.0, "beta_crytoxanthin":0.0, "thiamin":0.076, "selenium":0.6, "vitamin_k":30.5, "alpha_carotene":6.0, "carbohydrate":2.1, "sugar":0.18, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":79.0, "fat_poly_unsaturated":0.409, "lipid_total":0.69, "prompt":"ALFALFA SEEDS,SPROUTED,RAW -- 1 cup", "vitamin_e":0.02, "vitamin_b6":0.034, "fiber":1.9, "vitamin_c":8.2, "protein":3.99, "vitamin_a":155.0, "niacin":0.481, "fat_saturated":0.069, "weight1_gram":33.0, "folate_dfe":36.0, "choline":14.4, "sodium":6.0, "magnesium":27.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":32.0, "ndb_no":11001, "folate_total":36.0, "lutein_zeaxanthin":30.5, "iron":0.96, "id":2763, "energy_in_kcal":23.0, "fat_mono_unsaturated":0.056, "description":"ALFALFA SEEDS,SPROUTED,RAW", "refuse_percent":0.0, "food_folate":36.0, "manganese":0.188, "zinc":0.92, "riboflavin":0.126, "copper":0.157}, "843": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":43.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":26.1, "lipid_total":100.0, "prompt": "SHORTENING,HOUSEHOLD,SOYBN (HYDR) -COTTONSEED (HYDR) -- 1 cup", "vitamin_e":0.8, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":25.0, "weight1_gram":205.0, "folate_dfe":0.0, "choline":0.2, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":0.0, "ndb_no":4031, "folate_total":0.0, "lutein_zeaxanthin":43.0, "iron":0.0, "id":843, "energy_in_kcal":884.0, "fat_mono_unsaturated":44.5, "description": "SHORTENING,HOUSEHOLD,SOYBN (HYDR) -COTTONSEED (HYDR)", "refuse_percent":0.0, "food_folate":0.0, "manganese":-1.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "300": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":265.0, "pantothenic_acid":0.413, "phosphorus":512.0, "beta_crytoxanthin":0.0, "thiamin":0.027, "selenium":13.9, "vitamin_k":2.8, "alpha_carotene":0.0, "carbohydrate":1.28, "sugar":0.52, "vitamin_b12":0.83, "cholesterol":105.0, "retinol":258.0, "potassium":98.0, "fat_poly_unsaturated":0.942, "lipid_total":33.14, "prompt":"CHEESE,CHEDDAR -- 1 cup, diced", "vitamin_e":0.29, "vitamin_b6":0.074, "fiber":0.0, "vitamin_c":0.0, "protein":24.9, "vitamin_a":1002.0, "niacin":0.08, "fat_saturated":21.092, "weight1_gram":132.0, "folate_dfe":18.0, "choline":16.5, "sodium":621.0, "magnesium":28.0, "folic_acid":0.0, "weight1_description":"1 cup, diced", "calcium":721.0, "ndb_no":1009, "folate_total":18.0, "lutein_zeaxanthin":2.8, "iron":0.68, "id":300, "energy_in_kcal":403.0, "fat_mono_unsaturated":9.391, "description":"CHEESE,CHEDDAR", "refuse_percent":0.0, "food_folate":18.0, "manganese":0.01, "zinc":3.11, "riboflavin":0.375, "copper":0.031}, "3468": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":290.0, "pantothenic_acid":0.142, "phosphorus":30.0, "beta_crytoxanthin":2312.0, "thiamin":0.072, "selenium":0.4, "vitamin_k":102.5, "alpha_carotene":0.0, "carbohydrate":3.29, "sugar":1.19, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":247.0, "fat_poly_unsaturated":0.16, "lipid_total":0.3, "prompt":"LETTUCE,COS OR ROMAINE,RAW -- 1 cup, shredded", "vitamin_e":0.13, "vitamin_b6":0.074, "fiber":2.1, "vitamin_c":24.0, "protein":1.23, "vitamin_a":5807.0, "niacin":0.313, "fat_saturated":0.039, "weight1_gram":46.9, "folate_dfe":136.0, "choline":9.9, "sodium":8.0, "magnesium":14.0, "folic_acid":0.0, "weight1_description":"1 cup, shredded", "calcium":33.0, "ndb_no":11251, "folate_total":136.0, "lutein_zeaxanthin":102.5, "iron":0.97, "id":3468, "energy_in_kcal":17.0, "fat_mono_unsaturated":0.012, "description":"LETTUCE,COS OR ROMAINE,RAW", "refuse_percent":6.0, "food_folate":136.0, "manganese":0.155, "zinc":0.23, "riboflavin":0.067, "copper":0.048}, "1261": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":122.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":25.588, "lipid_total":100.0, "prompt": "OIL,INDUSTRIAL,CANOLA W\/ ANTIFOAMING AGENT -- 1 tablespoon", "vitamin_e":17.1, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":7.615, "weight1_gram":13.6, "folate_dfe":0.0, "choline":0.2, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tablespoon", "calcium":0.0, "ndb_no":4643, "folate_total":0.0, "lutein_zeaxanthin":122.0, "iron":0.0, "id":1261, "energy_in_kcal":884.0, "fat_mono_unsaturated":62.093, "description":"OIL,INDUSTRIAL,CANOLA W\/ ANTIFOAMING AGENT", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "3469": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":25.0, "pantothenic_acid":0.091, "phosphorus":20.0, "beta_crytoxanthin":277.0, "thiamin":0.041, "selenium":0.1, "vitamin_k":24.1, "alpha_carotene":0.0, "carbohydrate":2.97, "sugar":1.97, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":141.0, "fat_poly_unsaturated":0.074, "lipid_total":0.14, "prompt": "LETTUCE,ICEBERG (INCL CRISPHEAD TYPES),RAW -- 1 cup, shredded", "vitamin_e":0.18, "vitamin_b6":0.042, "fiber":1.2, "vitamin_c":2.8, "protein":0.9, "vitamin_a":502.0, "niacin":0.123, "fat_saturated":0.018, "weight1_gram":72.48, "folate_dfe":29.0, "choline":6.7, "sodium":10.0, "magnesium":7.0, "folic_acid":0.0, "weight1_description":"1 cup, shredded", "calcium":18.0, "ndb_no":11252, "folate_total":29.0, "lutein_zeaxanthin":24.1, "iron":0.41, "id":3469, "energy_in_kcal":14.0, "fat_mono_unsaturated":0.006, "description":"LETTUCE,ICEBERG (INCL CRISPHEAD TYPES),RAW", "refuse_percent":5.0, "food_folate":29.0, "manganese":0.125, "zinc":0.15, "riboflavin":0.025, "copper":0.025}, "3597": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":157.0, "pantothenic_acid":0.317, "phosphorus":26.0, "beta_crytoxanthin":51.0, "thiamin":0.054, "selenium":0.1, "vitamin_k":4.9, "alpha_carotene":490.0, "carbohydrate":6.03, "sugar":4.2, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":211.0, "fat_poly_unsaturated":0.07, "lipid_total":0.3, "prompt":"PEPPERS,SWT,RED,RAW -- 1 cup, chopped", "vitamin_e":1.58, "vitamin_b6":0.291, "fiber":2.1, "vitamin_c":127.7, "protein":0.99, "vitamin_a":3131.0, "niacin":0.979, "fat_saturated":0.027, "weight1_gram":149.0, "folate_dfe":46.0, "choline":5.6, "sodium":4.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":7.0, "ndb_no":11821, "folate_total":46.0, "lutein_zeaxanthin":4.9, "iron":0.43, "id":3597, "energy_in_kcal":31.0, "fat_mono_unsaturated":0.003, "description":"PEPPERS,SWT,RED,RAW", "refuse_percent":18.0, "food_folate":46.0, "manganese":0.112, "zinc":0.25, "riboflavin":0.085, "copper":0.017}, "4717": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.132, "phosphorus":4.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":1.2, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":98.09, "sugar":97.02, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":133.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"SUGARS,BROWN -- 1 cup, packed", "vitamin_e":0.0, "vitamin_b6":0.041, "fiber":0.0, "vitamin_c":0.0, "protein":0.12, "vitamin_a":0.0, "niacin":0.11, "fat_saturated":0.0, "weight1_gram":220.0, "folate_dfe":1.0, "choline":2.3, "sodium":28.0, "magnesium":9.0, "folic_acid":0.0, "weight1_description":"1 cup, packed", "calcium":83.0, "ndb_no":19334, "folate_total":1.0, "lutein_zeaxanthin":0.0, "iron":0.71, "id":4717, "energy_in_kcal":380.0, "fat_mono_unsaturated":0.0, "description":"SUGARS,BROWN", "refuse_percent":0.0, "food_folate":1.0, "manganese":0.064, "zinc":0.03, "riboflavin":0.0, "copper":0.047}, "6893": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":11.0, "pantothenic_acid":0.424, "phosphorus":210.0, "beta_crytoxanthin":1355.0, "thiamin":0.385, "selenium":15.5, "vitamin_k":0.3, "alpha_carotene":0.0, "carbohydrate":74.26, "sugar":0.64, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":287.0, "fat_poly_unsaturated":2.163, "lipid_total":4.74, "prompt":"CORN,YELLOW -- 1 cup", "vitamin_e":0.49, "vitamin_b6":0.622, "fiber":7.3, "vitamin_c":0.0, "protein":9.42, "vitamin_a":214.0, "niacin":3.627, "fat_saturated":0.667, "weight1_gram":166.0, "folate_dfe":19.0, "choline":-1.0, "sodium":35.0, "magnesium":127.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":7.0, "ndb_no":20014, "folate_total":19.0, "lutein_zeaxanthin":0.3, "iron":2.71, "id":6893, "energy_in_kcal":365.0, "fat_mono_unsaturated":1.251, "description":"CORN,YELLOW", "refuse_percent":0.0, "food_folate":19.0, "manganese":0.485, "zinc":2.21, "riboflavin":0.201, "copper":0.314}, "366": {"beta_carotene":4431.0, "lycopene":4431.0, "vitamin_a_rae":12.0, "pantothenic_acid":0.037, "phosphorus":17.0, "beta_crytoxanthin":0.0, "thiamin":0.01, "selenium":1.3, "vitamin_k":1.8, "alpha_carotene":0.0, "carbohydrate":36.25, "sugar":26.06, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":208.0, "fat_poly_unsaturated":0.17, "lipid_total":0.29, "prompt":"SAUCE,BARBECUE -- 1 serving, 2 tbsp", "vitamin_e":0.66, "vitamin_b6":0.041, "fiber":0.6, "vitamin_c":0.7, "protein":0.0, "vitamin_a":235.0, "niacin":0.487, "fat_saturated":0.0, "weight1_gram":34.51, "folate_dfe":2.0, "choline":2.9, "sodium":1119.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 serving, 2 tbsp", "calcium":12.0, "ndb_no":6150, "folate_total":2.0, "lutein_zeaxanthin":1.8, "iron":0.21, "id":366, "energy_in_kcal":150.0, "fat_mono_unsaturated":0.074, "description":"SAUCE,BARBECUE", "refuse_percent":0.0, "food_folate":2.0, "manganese":0.225, "zinc":0.13, "riboflavin":0.032, "copper":0.079}, "3662": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":38.0, "pantothenic_acid":0.104, "phosphorus":108.0, "beta_crytoxanthin":2477.0, "thiamin":0.266, "selenium":1.8, "vitamin_k":24.8, "alpha_carotene":0.0, "carbohydrate":14.45, "sugar":5.67, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":244.0, "fat_poly_unsaturated":0.187, "lipid_total":0.4, "prompt":"PEAS,GREEN,RAW -- 1 cup", "vitamin_e":0.13, "vitamin_b6":0.169, "fiber":5.1, "vitamin_c":40.0, "protein":5.42, "vitamin_a":765.0, "niacin":2.09, "fat_saturated":0.071, "weight1_gram":145.0, "folate_dfe":65.0, "choline":28.4, "sodium":5.0, "magnesium":33.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":25.0, "ndb_no":11304, "folate_total":65.0, "lutein_zeaxanthin":24.8, "iron":1.47, "id":3662, "energy_in_kcal":81.0, "fat_mono_unsaturated":0.035, "description":"PEAS,GREEN,RAW", "refuse_percent":62.0, "food_folate":65.0, "manganese":0.41, "zinc":1.24, "riboflavin":0.132, "copper":0.176}, "4718": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.6, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":99.98, "sugar":99.91, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":2.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"SUGARS,GRANULATED -- 1 serving, packet", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":2.84, "folate_dfe":0.0, "choline":0.0, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 serving, packet", "calcium":1.0, "ndb_no":19335, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.01, "id":4718, "energy_in_kcal":387.0, "fat_mono_unsaturated":0.0, "description":"SUGARS,GRANULATED", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.019, "copper":0.0}, "3183": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.88, "phosphorus":531.0, "beta_crytoxanthin":23.0, "thiamin":0.363, "selenium":20.3, "vitamin_k":34.7, "alpha_carotene":0.0, "carbohydrate":30.16, "sugar":5.01, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":632.0, "fat_poly_unsaturated":8.546, "lipid_total":47.77, "prompt":"CASHEW NUTS,OIL RSTD,W\/SALT -- 1 cup, whole", "vitamin_e":0.92, "vitamin_b6":0.323, "fiber":3.3, "vitamin_c":0.3, "protein":16.84, "vitamin_a":0.0, "niacin":1.736, "fat_saturated":8.478, "weight1_gram":129.08, "folate_dfe":25.0, "choline":61.0, "sodium":308.0, "magnesium":273.0, "folic_acid":0.0, "weight1_description":"1 cup, whole", "calcium":43.0, "ndb_no":12586, "folate_total":25.0, "lutein_zeaxanthin":34.7, "iron":6.05, "id":3183, "energy_in_kcal":581.0, "fat_mono_unsaturated":25.923, "description":"CASHEW NUTS,OIL RSTD,W\/SALT", "refuse_percent":0.0, "food_folate":25.0, "manganese":1.668, "zinc":5.35, "riboflavin":0.218, "copper":2.043}, "2319": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":2.0, "pantothenic_acid":0.232, "phosphorus":15.0, "beta_crytoxanthin":-1.0, "thiamin":0.05, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":10.7, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":145.0, "fat_poly_unsaturated":0.089, "lipid_total":0.3, "prompt":"LEMONS,RAW,WITH PEEL -- 1 fruit, without seeds", "vitamin_e":-1.0, "vitamin_b6":0.109, "fiber":4.7, "vitamin_c":77.0, "protein":1.2, "vitamin_a":30.0, "niacin":0.2, "fat_saturated":0.039, "weight1_gram":108.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":3.0, "magnesium":12.0, "folic_acid":-1.0, "weight1_description":"1 fruit, without seeds", "calcium":61.0, "ndb_no":9151, "folate_total":-1.0, "lutein_zeaxanthin":-1.0, "iron":0.7, "id":2319, "energy_in_kcal":20.0, "fat_mono_unsaturated":0.011, "description":"LEMONS,RAW,WITH PEEL", "refuse_percent":2.0, "food_folate":-1.0, "manganese":-1.0, "zinc":0.1, "riboflavin":0.04, "copper":0.26}, "4719": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.6, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":99.6, "sugar":97.91, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":2.0, "fat_poly_unsaturated":0.05, "lipid_total":0.1, "prompt":"SUGARS,POWDERED -- 1 cup, unsifted", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.02, "weight1_gram":120.0, "folate_dfe":0.0, "choline":0.0, "sodium":1.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 cup, unsifted", "calcium":1.0, "ndb_no":19336, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.02, "id":4719, "energy_in_kcal":389.0, "fat_mono_unsaturated":0.032, "description":"SUGARS,POWDERED", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.001, "zinc":0.0, "riboflavin":0.019, "copper":0.001}, "3791": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":961.0, "pantothenic_acid":0.884, "phosphorus":54.0, "beta_crytoxanthin":0.0, "thiamin":0.107, "selenium":0.2, "vitamin_k":2.3, "alpha_carotene":0.0, "carbohydrate":20.71, "sugar":11.09, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":475.0, "fat_poly_unsaturated":0.092, "lipid_total":0.15, "prompt": "SWEET POTATO,CKD,BKD IN SKN,W\/ SALT -- 1 medium, (2\" dia, 5\" long, raw)", "vitamin_e":0.71, "vitamin_b6":0.286, "fiber":3.3, "vitamin_c":19.6, "protein":2.01, "vitamin_a":19218.0, "niacin":1.487, "fat_saturated":0.052, "weight1_gram":114.0, "folate_dfe":6.0, "choline":13.1, "sodium":246.0, "magnesium":27.0, "folic_acid":0.0, "weight1_description":"1 medium, (2\" dia, 5\" long, raw)", "calcium":38.0, "ndb_no":11875, "folate_total":6.0, "lutein_zeaxanthin":2.3, "iron":0.69, "id":3791, "energy_in_kcal":92.0, "fat_mono_unsaturated":0.002, "description":"SWEET POTATO,CKD,BKD IN SKN,W\/ SALT", "refuse_percent":22.0, "food_folate":6.0, "manganese":0.497, "zinc":0.32, "riboflavin":0.106, "copper":0.161}, "2799": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.125, "phosphorus":24.0, "beta_crytoxanthin":26.0, "thiamin":0.024, "selenium":0.4, "vitamin_k":2.2, "alpha_carotene":0.0, "carbohydrate":7.68, "sugar":4.89, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":153.0, "fat_poly_unsaturated":0.155, "lipid_total":0.3, "prompt":"STRAWBERRIES,RAW -- 1 cup, halves", "vitamin_e":0.29, "vitamin_b6":0.047, "fiber":2.0, "vitamin_c":58.8, "protein":0.67, "vitamin_a":12.0, "niacin":0.386, "fat_saturated":0.015, "weight1_gram":152.0, "folate_dfe":24.0, "choline":5.7, "sodium":1.0, "magnesium":13.0, "folic_acid":0.0, "weight1_description":"1 cup, halves", "calcium":16.0, "ndb_no":9316, "folate_total":24.0, "lutein_zeaxanthin":2.2, "iron":0.41, "id":2799, "energy_in_kcal":32.0, "fat_mono_unsaturated":0.043, "description":"STRAWBERRIES,RAW", "refuse_percent":6.0, "food_folate":24.0, "manganese":0.386, "zinc":0.14, "riboflavin":0.022, "copper":0.048}, "943": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":819.0, "pantothenic_acid":0.084, "phosphorus":23.0, "beta_crytoxanthin":0.0, "thiamin":0.01, "selenium":0.0, "vitamin_k":93.0, "alpha_carotene":0.0, "carbohydrate":0.7, "sugar":0.0, "vitamin_b12":0.1, "cholesterol":0.0, "retinol":768.0, "potassium":42.0, "fat_poly_unsaturated":24.302, "lipid_total":80.71, "prompt":"MARGARINE,REG,UNSPEC OILS,W\/SALT -- 1 tsp", "vitamin_e":9.0, "vitamin_b6":0.009, "fiber":0.0, "vitamin_c":0.2, "protein":0.16, "vitamin_a":3571.0, "niacin":0.023, "fat_saturated":15.189, "weight1_gram":4.7, "folate_dfe":1.0, "choline":12.4, "sodium":943.0, "magnesium":3.0, "folic_acid":0.0, "weight1_description":"1 tsp", "calcium":30.0, "ndb_no":4132, "folate_total":1.0, "lutein_zeaxanthin":93.0, "iron":0.06, "id":943, "energy_in_kcal":717.0, "fat_mono_unsaturated":38.877, "description":"MARGARINE,REG,UNSPEC OILS,W\/SALT", "refuse_percent":0.0, "food_folate":1.0, "manganese":-1.0, "zinc":0.0, "riboflavin":0.037, "copper":0.0}, "6095": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":5.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.2, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":61.5, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":16500.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"LEAVENING AGENTS,CRM OF TARTAR -- 1 tsp", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.2, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":3.0, "folate_dfe":0.0, "choline":0.0, "sodium":52.0, "magnesium":2.0, "folic_acid":0.0, "weight1_description":"1 tsp", "calcium":8.0, "ndb_no":18373, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":3.72, "id":6095, "energy_in_kcal":258.0, "fat_mono_unsaturated":0.0, "description":"LEAVENING AGENTS,CRM OF TARTAR", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.205, "zinc":0.42, "riboflavin":0.0, "copper":0.195}, "2320": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.103, "phosphorus":6.0, "beta_crytoxanthin":9.0, "thiamin":0.03, "selenium":0.1, "vitamin_k":0.0, "alpha_carotene":17.0, "carbohydrate":8.63, "sugar":2.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":124.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"LEMON JUICE,RAW -- 1 cup", "vitamin_e":0.15, "vitamin_b6":0.051, "fiber":0.4, "vitamin_c":46.0, "protein":0.38, "vitamin_a":20.0, "niacin":0.1, "fat_saturated":0.0, "weight1_gram":244.0, "folate_dfe":13.0, "choline":5.1, "sodium":1.0, "magnesium":6.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":7.0, "ndb_no":9152, "folate_total":13.0, "lutein_zeaxanthin":0.0, "iron":0.03, "id":2320, "energy_in_kcal":25.0, "fat_mono_unsaturated":0.0, "description":"LEMON JUICE,RAW", "refuse_percent":0.0, "food_folate":13.0, "manganese":0.008, "zinc":0.05, "riboflavin":0.01, "copper":0.029}, "1424": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":16.0, "pantothenic_acid":1.058, "phosphorus":173.0, "beta_crytoxanthin":0.0, "thiamin":0.073, "selenium":15.7, "vitamin_k":1.8, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.37, "cholesterol":70.0, "retinol":16.0, "potassium":229.0, "fat_poly_unsaturated":0.75, "lipid_total":3.08, "prompt": "CHICKEN,BROILERS OR FRYERS,MEAT ONLY,RAW -- 1 unit, (yield from 1 lb ready-to-cook chicken)", "vitamin_e":0.21, "vitamin_b6":0.43, "fiber":0.0, "vitamin_c":2.3, "protein":21.39, "vitamin_a":52.0, "niacin":8.239, "fat_saturated":0.79, "weight1_gram":197.0, "folate_dfe":7.0, "choline":65.7, "sodium":77.0, "magnesium":25.0, "folic_acid":0.0, "weight1_description": "1 unit, (yield from 1 lb ready-to-cook chicken)", "calcium":12.0, "ndb_no":5011, "folate_total":7.0, "lutein_zeaxanthin":1.8, "iron":0.89, "id":1424, "energy_in_kcal":119.0, "fat_mono_unsaturated":0.9, "description":"CHICKEN,BROILERS OR FRYERS,MEAT ONLY,RAW", "refuse_percent":52.0, "food_folate":7.0, "manganese":0.019, "zinc":1.54, "riboflavin":0.142, "copper":0.053}, "7152": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.419, "phosphorus":89.0, "beta_crytoxanthin":81.0, "thiamin":0.108, "selenium":25.9, "vitamin_k":0.7, "alpha_carotene":0.0, "carbohydrate":26.54, "sugar":0.8, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":44.0, "fat_poly_unsaturated":0.213, "lipid_total":0.54, "prompt":"SPAGHETTI,WHOLE-WHEAT,CKD -- 1 cup", "vitamin_e":0.3, "vitamin_b6":0.079, "fiber":4.5, "vitamin_c":0.0, "protein":5.33, "vitamin_a":3.0, "niacin":0.707, "fat_saturated":0.099, "weight1_gram":140.0, "folate_dfe":5.0, "choline":10.7, "sodium":3.0, "magnesium":30.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":15.0, "ndb_no":20125, "folate_total":5.0, "lutein_zeaxanthin":0.7, "iron":1.06, "id":7152, "energy_in_kcal":124.0, "fat_mono_unsaturated":0.075, "description":"SPAGHETTI,WHOLE-WHEAT,CKD", "refuse_percent":0.0, "food_folate":5.0, "manganese":1.379, "zinc":0.81, "riboflavin":0.045, "copper":0.167}, "241": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":18.0, "pantothenic_acid":1.178, "phosphorus":167.0, "beta_crytoxanthin":0.0, "thiamin":0.079, "selenium":13.5, "vitamin_k":2.9, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.36, "cholesterol":80.0, "retinol":18.0, "potassium":229.0, "fat_poly_unsaturated":0.95, "lipid_total":3.81, "prompt": "CHICKEN,BROILERS OR FRYERS,LEG,MEAT ONLY,RAW -- 1 leg, bone and skin removed (yield from 1 lb ready-to-cook chicken)", "vitamin_e":0.32, "vitamin_b6":0.33, "fiber":0.0, "vitamin_c":0.0, "protein":20.13, "vitamin_a":61.0, "niacin":6.067, "fat_saturated":0.98, "weight1_gram":78.0, "folate_dfe":10.0, "choline":61.8, "sodium":86.0, "magnesium":23.0, "folic_acid":0.0, "weight1_description": "1 leg, bone and skin removed (yield from 1 lb ready-to-cook chicken)", "calcium":11.0, "ndb_no":5080, "folate_total":10.0, "lutein_zeaxanthin":2.9, "iron":1.02, "id":241, "energy_in_kcal":120.0, "fat_mono_unsaturated":1.18, "description":"CHICKEN,BROILERS OR FRYERS,LEG,MEAT ONLY,RAW", "refuse_percent":43.0, "food_folate":10.0, "manganese":0.021, "zinc":2.06, "riboflavin":0.193, "copper":0.064}, "2417": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":17.0, "pantothenic_acid":0.015, "phosphorus":3.0, "beta_crytoxanthin":510.0, "thiamin":0.003, "selenium":0.9, "vitamin_k":1.4, "alpha_carotene":8.0, "carbohydrate":5.61, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":9.0, "fat_poly_unsaturated":0.586, "lipid_total":6.87, "prompt":"OLIVES,RIPE,CND (JUMBO-SUPER COLOSSAL) -- 1 jumbo", "vitamin_e":1.65, "vitamin_b6":0.012, "fiber":2.5, "vitamin_c":1.5, "protein":0.97, "vitamin_a":346.0, "niacin":0.022, "fat_saturated":0.909, "weight1_gram":8.3, "folate_dfe":0.0, "choline":6.6, "sodium":898.0, "magnesium":4.0, "folic_acid":0.0, "weight1_description":"1 jumbo", "calcium":94.0, "ndb_no":9194, "folate_total":0.0, "lutein_zeaxanthin":1.4, "iron":3.32, "id":2417, "energy_in_kcal":81.0, "fat_mono_unsaturated":5.071, "description":"OLIVES,RIPE,CND (JUMBO-SUPER COLOSSAL)", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.02, "zinc":0.22, "riboflavin":0.0, "copper":0.226}, "401": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":220.0, "pantothenic_acid":0.429, "phosphorus":567.0, "beta_crytoxanthin":0.0, "thiamin":0.063, "selenium":18.2, "vitamin_k":2.5, "alpha_carotene":0.0, "carbohydrate":5.38, "sugar":1.32, "vitamin_b12":3.34, "cholesterol":92.0, "retinol":214.0, "potassium":77.0, "fat_poly_unsaturated":0.972, "lipid_total":27.8, "prompt":"CHEESE,SWISS -- 1 cup, diced", "vitamin_e":0.38, "vitamin_b6":0.083, "fiber":0.0, "vitamin_c":0.0, "protein":26.93, "vitamin_a":830.0, "niacin":0.092, "fat_saturated":17.779, "weight1_gram":132.0, "folate_dfe":6.0, "choline":15.5, "sodium":192.0, "magnesium":38.0, "folic_acid":0.0, "weight1_description":"1 cup, diced", "calcium":791.0, "ndb_no":1040, "folate_total":6.0, "lutein_zeaxanthin":2.5, "iron":0.2, "id":401, "energy_in_kcal":380.0, "fat_mono_unsaturated":7.274, "description":"CHEESE,SWISS", "refuse_percent":0.0, "food_folate":6.0, "manganese":0.005, "zinc":4.36, "riboflavin":0.296, "copper":0.043}, "3473": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":375.0, "pantothenic_acid":0.144, "phosphorus":28.0, "beta_crytoxanthin":1724.0, "thiamin":0.064, "selenium":1.5, "vitamin_k":140.3, "alpha_carotene":0.0, "carbohydrate":2.26, "sugar":0.48, "vitamin_b12":-1.0, "cholesterol":-1.0, "retinol":-1.0, "potassium":187.0, "fat_poly_unsaturated":-1.0, "lipid_total":0.22, "prompt":"LETTUCE,RED LEAF,RAW -- 1 cup, shredded", "vitamin_e":0.15, "vitamin_b6":0.1, "fiber":0.9, "vitamin_c":3.7, "protein":1.33, "vitamin_a":7492.0, "niacin":0.321, "fat_saturated":-1.0, "weight1_gram":28.27, "folate_dfe":-1.0, "choline":11.8, "sodium":25.0, "magnesium":12.0, "folic_acid":-1.0, "weight1_description":"1 cup, shredded", "calcium":33.0, "ndb_no":11257, "folate_total":36.0, "lutein_zeaxanthin":140.3, "iron":1.2, "id":3473, "energy_in_kcal":16.0, "fat_mono_unsaturated":-1.0, "description":"LETTUCE,RED LEAF,RAW", "refuse_percent":20.0, "food_folate":36.0, "manganese":0.203, "zinc":0.2, "riboflavin":0.077, "copper":0.028}, "1489": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.825, "phosphorus":100.0, "beta_crytoxanthin":-1.0, "thiamin":0.39, "selenium":0.6, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":13.05, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":307.0, "fat_poly_unsaturated":0.407, "lipid_total":0.7, "prompt":"BEANS,NAVY,MATURE SEEDS,SPROUTED,RAW -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.191, "fiber":-1.0, "vitamin_c":18.8, "protein":6.15, "vitamin_a":4.0, "niacin":1.22, "fat_saturated":0.085, "weight1_gram":104.0, "folate_dfe":132.0, "choline":-1.0, "sodium":13.0, "magnesium":101.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":15.0, "ndb_no":11046, "folate_total":132.0, "lutein_zeaxanthin":-1.0, "iron":1.93, "id":1489, "energy_in_kcal":67.0, "fat_mono_unsaturated":0.052, "description":"BEANS,NAVY,MATURE SEEDS,SPROUTED,RAW", "refuse_percent":0.0, "food_folate":132.0, "manganese":0.408, "zinc":0.89, "riboflavin":0.215, "copper":0.356}, "1649": {"beta_carotene":1.0, "lycopene":1.0, "vitamin_a_rae":835.0, "pantothenic_acid":0.273, "phosphorus":35.0, "beta_crytoxanthin":256.0, "thiamin":0.066, "selenium":0.1, "vitamin_k":13.2, "alpha_carotene":0.0, "carbohydrate":9.58, "sugar":4.74, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":320.0, "fat_poly_unsaturated":0.117, "lipid_total":0.24, "prompt":"CARROTS,RAW -- 1 cup, chopped", "vitamin_e":0.66, "vitamin_b6":0.138, "fiber":2.8, "vitamin_c":5.9, "protein":0.93, "vitamin_a":16706.0, "niacin":0.983, "fat_saturated":0.037, "weight1_gram":128.0, "folate_dfe":19.0, "choline":8.8, "sodium":69.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":33.0, "ndb_no":11124, "folate_total":19.0, "lutein_zeaxanthin":13.2, "iron":0.3, "id":1649, "energy_in_kcal":41.0, "fat_mono_unsaturated":0.014, "description":"CARROTS,RAW", "refuse_percent":11.0, "food_folate":19.0, "manganese":0.143, "zinc":0.24, "riboflavin":0.058, "copper":0.045}, "6097": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":11.3, "phosphorus":1290.0, "beta_crytoxanthin":0.0, "thiamin":2.36, "selenium":24.1, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":38.2, "sugar":0.0, "vitamin_b12":0.02, "cholesterol":0.0, "retinol":0.0, "potassium":2000.0, "fat_poly_unsaturated":0.01, "lipid_total":4.6, "prompt":"LEAVENING AGENTS,YEAST,BAKER'S,ACTIVE DRY -- 1 tbsp", "vitamin_e":0.0, "vitamin_b6":1.55, "fiber":21.0, "vitamin_c":0.3, "protein":38.3, "vitamin_a":1.0, "niacin":39.75, "fat_saturated":0.595, "weight1_gram":12.0, "folate_dfe":2340.0, "choline":32.0, "sodium":50.0, "magnesium":98.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":64.0, "ndb_no":18375, "folate_total":2340.0, "lutein_zeaxanthin":0.0, "iron":16.6, "id":6097, "energy_in_kcal":295.0, "fat_mono_unsaturated":2.562, "description":"LEAVENING AGENTS,YEAST,BAKER'S,ACTIVE DRY", "refuse_percent":0.0, "food_folate":2340.0, "manganese":0.55, "zinc":6.4, "riboflavin":5.47, "copper":0.5}, "594": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":61.0, "pantothenic_acid":0.357, "phosphorus":101.0, "beta_crytoxanthin":0.0, "thiamin":0.045, "selenium":3.1, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":4.96, "sugar":5.09, "vitamin_b12":0.53, "cholesterol":2.0, "retinol":61.0, "potassium":156.0, "fat_poly_unsaturated":0.003, "lipid_total":0.08, "prompt":"MILK,NONFAT,FLUID,W\/ VIT A (FAT FREE OR SKIM) -- 1 cup", "vitamin_e":0.01, "vitamin_b6":0.037, "fiber":0.0, "vitamin_c":0.0, "protein":3.37, "vitamin_a":204.0, "niacin":0.094, "fat_saturated":0.051, "weight1_gram":245.0, "folate_dfe":5.0, "choline":15.6, "sodium":42.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":125.0, "ndb_no":1085, "folate_total":5.0, "lutein_zeaxanthin":0.0, "iron":0.03, "id":594, "energy_in_kcal":34.0, "fat_mono_unsaturated":0.021, "description":"MILK,NONFAT,FLUID,W\/ VIT A (FAT FREE OR SKIM)", "refuse_percent":0.0, "food_folate":5.0, "manganese":0.003, "zinc":0.42, "riboflavin":0.182, "copper":0.013}, "2738": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.095, "phosphorus":101.0, "beta_crytoxanthin":0.0, "thiamin":0.106, "selenium":0.6, "vitamin_k":3.5, "alpha_carotene":0.0, "carbohydrate":79.18, "sugar":59.19, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":749.0, "fat_poly_unsaturated":0.037, "lipid_total":0.46, "prompt":"RAISINS,SEEDLESS -- 1 cup, packed", "vitamin_e":0.12, "vitamin_b6":0.174, "fiber":3.7, "vitamin_c":2.3, "protein":3.07, "vitamin_a":0.0, "niacin":0.766, "fat_saturated":0.058, "weight1_gram":165.0, "folate_dfe":5.0, "choline":11.1, "sodium":11.0, "magnesium":32.0, "folic_acid":0.0, "weight1_description":"1 cup, packed", "calcium":50.0, "ndb_no":9298, "folate_total":5.0, "lutein_zeaxanthin":3.5, "iron":1.88, "id":2738, "energy_in_kcal":299.0, "fat_mono_unsaturated":0.051, "description":"RAISINS,SEEDLESS", "refuse_percent":0.0, "food_folate":5.0, "manganese":0.299, "zinc":0.22, "riboflavin":0.125, "copper":0.318}, "6898": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":11.0, "pantothenic_acid":0.425, "phosphorus":241.0, "beta_crytoxanthin":1355.0, "thiamin":0.385, "selenium":15.5, "vitamin_k":0.3, "alpha_carotene":0.0, "carbohydrate":76.89, "sugar":0.64, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":287.0, "fat_poly_unsaturated":1.638, "lipid_total":3.59, "prompt":"CORNMEAL,WHOLE-GRAIN,YEL -- 1 cup", "vitamin_e":0.42, "vitamin_b6":0.304, "fiber":7.3, "vitamin_c":0.0, "protein":8.12, "vitamin_a":214.0, "niacin":3.632, "fat_saturated":0.505, "weight1_gram":122.0, "folate_dfe":25.0, "choline":21.6, "sodium":35.0, "magnesium":127.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":6.0, "ndb_no":20020, "folate_total":25.0, "lutein_zeaxanthin":0.3, "iron":3.45, "id":6898, "energy_in_kcal":362.0, "fat_mono_unsaturated":0.948, "description":"CORNMEAL,WHOLE-GRAIN,YEL", "refuse_percent":0.0, "food_folate":25.0, "manganese":0.498, "zinc":1.82, "riboflavin":0.201, "copper":0.193}, "1874": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.063, "phosphorus":7.0, "beta_crytoxanthin":16.0, "thiamin":0.003, "selenium":0.1, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":11.54, "sugar":10.93, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":126.0, "fat_poly_unsaturated":0.031, "lipid_total":0.1, "prompt": "APPLE JUC,FRZ CONC,UNSWTND,DIL W\/3 VOLUME H2O WO\/ VIT C -- 1 cup", "vitamin_e":0.01, "vitamin_b6":0.033, "fiber":0.1, "vitamin_c":0.6, "protein":0.14, "vitamin_a":0.0, "niacin":0.038, "fat_saturated":0.018, "weight1_gram":239.0, "folate_dfe":0.0, "choline":1.8, "sodium":7.0, "magnesium":5.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":6.0, "ndb_no":9018, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.26, "id":1874, "energy_in_kcal":47.0, "fat_mono_unsaturated":0.002, "description": "APPLE JUC,FRZ CONC,UNSWTND,DIL W\/3 VOLUME H2O WO\/ VIT C", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.063, "zinc":0.04, "riboflavin":0.015, "copper":0.014}, "6098": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":10.0, "pantothenic_acid":0.623, "phosphorus":177.0, "beta_crytoxanthin":-1.0, "thiamin":0.961, "selenium":24.7, "vitamin_k":46.0, "alpha_carotene":0.0, "carbohydrate":68.49, "sugar":5.74, "vitamin_b12":-1.0, "cholesterol":1.0, "retinol":-1.0, "potassium":231.0, "fat_poly_unsaturated":2.3, "lipid_total":5.48, "prompt":"BREAD CRUMBS,DRY,GRATED,SEASONED -- 1 cup", "vitamin_e":0.26, "vitamin_b6":0.171, "fiber":4.9, "vitamin_c":2.7, "protein":14.13, "vitamin_a":193.0, "niacin":6.161, "fat_saturated":1.391, "weight1_gram":120.0, "folate_dfe":188.0, "choline":-1.0, "sodium":1759.0, "magnesium":46.0, "folic_acid":99.0, "weight1_description":"1 cup", "calcium":182.0, "ndb_no":18376, "folate_total":119.0, "lutein_zeaxanthin":46.0, "iron":4.92, "id":6098, "energy_in_kcal":383.0, "fat_mono_unsaturated":1.168, "description":"BREAD CRUMBS,DRY,GRATED,SEASONED", "refuse_percent":0.0, "food_folate":20.0, "manganese":0.984, "zinc":1.43, "riboflavin":0.415, "copper":0.244}, "4531": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":1.06, "phosphorus":358.0, "beta_crytoxanthin":0.0, "thiamin":0.073, "selenium":5.6, "vitamin_k":0.6, "alpha_carotene":0.0, "carbohydrate":19.56, "sugar":9.22, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":649.0, "fat_poly_unsaturated":14.161, "lipid_total":50.39, "prompt":"PEANUT BUTTER,SMOOTH STYLE,W\/ SALT -- 1 cup", "vitamin_e":8.99, "vitamin_b6":0.543, "fiber":6.0, "vitamin_c":0.0, "protein":25.09, "vitamin_a":0.0, "niacin":13.403, "fat_saturated":10.51, "weight1_gram":258.0, "folate_dfe":74.0, "choline":63.0, "sodium":459.0, "magnesium":154.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":43.0, "ndb_no":16098, "folate_total":74.0, "lutein_zeaxanthin":0.6, "iron":1.87, "id":4531, "energy_in_kcal":588.0, "fat_mono_unsaturated":24.216, "description":"PEANUT BUTTER,SMOOTH STYLE,W\/ SALT", "refuse_percent":0.0, "food_folate":74.0, "manganese":1.466, "zinc":2.91, "riboflavin":0.105, "copper":0.473}, "691": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":27.0, "pantothenic_acid":0.389, "phosphorus":95.0, "beta_crytoxanthin":0.0, "thiamin":0.029, "selenium":2.2, "vitamin_k":0.2, "alpha_carotene":0.0, "carbohydrate":4.66, "sugar":4.66, "vitamin_b12":0.37, "cholesterol":13.0, "retinol":27.0, "potassium":155.0, "fat_poly_unsaturated":0.092, "lipid_total":3.25, "prompt": "YOGURT,PLN,WHL MILK,8 GRAMS PROT PER 8 OZ -- 1 cup, (8 fl oz)", "vitamin_e":0.06, "vitamin_b6":0.032, "fiber":0.0, "vitamin_c":0.5, "protein":3.47, "vitamin_a":99.0, "niacin":0.075, "fat_saturated":2.096, "weight1_gram":245.0, "folate_dfe":7.0, "choline":15.2, "sodium":46.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup, (8 fl oz)", "calcium":121.0, "ndb_no":1116, "folate_total":7.0, "lutein_zeaxanthin":0.2, "iron":0.05, "id":691, "energy_in_kcal":61.0, "fat_mono_unsaturated":0.893, "description":"YOGURT,PLN,WHL MILK,8 GRAMS PROT PER 8 OZ", "refuse_percent":0.0, "food_folate":7.0, "manganese":0.004, "zinc":0.59, "riboflavin":0.142, "copper":0.009}, "4851": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.43, "phosphorus":168.0, "beta_crytoxanthin":-1.0, "thiamin":0.115, "selenium":1.2, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":24.77, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":532.0, "fat_poly_unsaturated":-1.0, "lipid_total":0.1, "prompt":"BEANS,ADZUKI,MATURE SD,CKD,BLD,W\/SALT -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.096, "fiber":7.3, "vitamin_c":0.0, "protein":7.52, "vitamin_a":6.0, "niacin":0.717, "fat_saturated":0.036, "weight1_gram":230.0, "folate_dfe":121.0, "choline":-1.0, "sodium":244.0, "magnesium":52.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":28.0, "ndb_no":16302, "folate_total":121.0, "lutein_zeaxanthin":-1.0, "iron":2.0, "id":4851, "energy_in_kcal":128.0, "fat_mono_unsaturated":-1.0, "description":"BEANS,ADZUKI,MATURE SD,CKD,BLD,W\/SALT", "refuse_percent":0.0, "food_folate":121.0, "manganese":0.573, "zinc":1.77, "riboflavin":0.064, "copper":0.298}, "7155": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.438, "phosphorus":97.0, "beta_crytoxanthin":79.0, "thiamin":0.08, "selenium":39.7, "vitamin_k":0.3, "alpha_carotene":0.0, "carbohydrate":72.53, "sugar":0.31, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":100.0, "fat_poly_unsaturated":0.727, "lipid_total":1.66, "prompt":"WHEAT FLOURS,BREAD,UNENR -- -1", "vitamin_e":0.4, "vitamin_b6":0.037, "fiber":2.4, "vitamin_c":0.0, "protein":11.98, "vitamin_a":2.0, "niacin":1.0, "fat_saturated":0.244, "weight1_gram":137.0, "folate_dfe":33.0, "choline":10.4, "sodium":2.0, "magnesium":25.0, "folic_acid":0.0, "weight1_description":"1 cup, unsifted, dipped", "calcium":15.0, "ndb_no":20129, "folate_total":33.0, "lutein_zeaxanthin":0.3, "iron":0.9, "id":7155, "energy_in_kcal":361.0, "fat_mono_unsaturated":0.14, "description":"WHEAT FLOURS,BREAD,UNENR", "refuse_percent":0.0, "food_folate":33.0, "manganese":0.792, "zinc":0.85, "riboflavin":0.06, "copper":0.182}, "1044": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":15.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":63.3, "lipid_total":100.0, "prompt":"OIL,VEGETABLE,WALNUT -- 1 cup", "vitamin_e":0.4, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":9.1, "weight1_gram":218.0, "folate_dfe":0.0, "choline":0.4, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":0.0, "ndb_no":4528, "folate_total":0.0, "lutein_zeaxanthin":15.0, "iron":0.0, "id":1044, "energy_in_kcal":884.0, "fat_mono_unsaturated":22.8, "description":"OIL,VEGETABLE,WALNUT", "refuse_percent":0.0, "food_folate":0.0, "manganese":-1.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "1140": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":8.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.1, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.93, "sugar":0.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":73.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"VINEGAR,CIDER -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":239.0, "folate_dfe":0.0, "choline":0.0, "sodium":5.0, "magnesium":5.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":7.0, "ndb_no":2048, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.2, "id":1140, "energy_in_kcal":21.0, "fat_mono_unsaturated":0.0, "description":"VINEGAR,CIDER", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.249, "zinc":0.04, "riboflavin":0.0, "copper":0.008}, "2324": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":2.0, "pantothenic_acid":0.217, "phosphorus":18.0, "beta_crytoxanthin":0.0, "thiamin":0.03, "selenium":0.4, "vitamin_k":0.6, "alpha_carotene":0.0, "carbohydrate":10.54, "sugar":1.69, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":102.0, "fat_poly_unsaturated":0.055, "lipid_total":0.2, "prompt":"LIMES,RAW -- 1 fruit, (2\" dia)", "vitamin_e":0.22, "vitamin_b6":0.043, "fiber":2.8, "vitamin_c":29.1, "protein":0.7, "vitamin_a":50.0, "niacin":0.2, "fat_saturated":0.022, "weight1_gram":67.0, "folate_dfe":8.0, "choline":5.1, "sodium":2.0, "magnesium":6.0, "folic_acid":0.0, "weight1_description":"1 fruit, (2\" dia)", "calcium":33.0, "ndb_no":9159, "folate_total":8.0, "lutein_zeaxanthin":0.6, "iron":0.6, "id":2324, "energy_in_kcal":30.0, "fat_mono_unsaturated":0.019, "description":"LIMES,RAW", "refuse_percent":16.0, "food_folate":8.0, "manganese":0.008, "zinc":0.11, "riboflavin":0.02, "copper":0.065}, "308": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":366.0, "pantothenic_acid":0.271, "phosphorus":104.0, "beta_crytoxanthin":0.0, "thiamin":0.017, "selenium":2.4, "vitamin_k":2.9, "alpha_carotene":0.0, "carbohydrate":2.66, "sugar":0.2, "vitamin_b12":0.42, "cholesterol":110.0, "retinol":359.0, "potassium":119.0, "fat_poly_unsaturated":1.265, "lipid_total":34.87, "prompt":"CHEESE,CREAM -- 1 cup", "vitamin_e":0.3, "vitamin_b6":0.047, "fiber":0.0, "vitamin_c":0.0, "protein":7.55, "vitamin_a":1346.0, "niacin":0.101, "fat_saturated":21.966, "weight1_gram":232.0, "folate_dfe":13.0, "choline":27.2, "sodium":296.0, "magnesium":6.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":80.0, "ndb_no":1017, "folate_total":13.0, "lutein_zeaxanthin":2.9, "iron":1.2, "id":308, "energy_in_kcal":349.0, "fat_mono_unsaturated":9.838, "description":"CHEESE,CREAM", "refuse_percent":0.0, "food_folate":13.0, "manganese":0.004, "zinc":0.54, "riboflavin":0.197, "copper":0.016}, "1492": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.258, "phosphorus":100.0, "beta_crytoxanthin":-1.0, "thiamin":0.274, "selenium":1.4, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":30.88, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":646.0, "fat_poly_unsaturated":0.276, "lipid_total":0.48, "prompt": "BEANS,PINTO,IMMAT SEEDS,FRZ,CKD,BLD,DRND,WO\/SALT -- 1 package, (10 oz) yields", "vitamin_e":-1.0, "vitamin_b6":0.194, "fiber":8.6, "vitamin_c":0.7, "protein":9.31, "vitamin_a":0.0, "niacin":0.632, "fat_saturated":0.058, "weight1_gram":284.0, "folate_dfe":34.0, "choline":-1.0, "sodium":83.0, "magnesium":54.0, "folic_acid":0.0, "weight1_description":"1 package, (10 oz) yields", "calcium":52.0, "ndb_no":11049, "folate_total":34.0, "lutein_zeaxanthin":-1.0, "iron":2.71, "id":1492, "energy_in_kcal":162.0, "fat_mono_unsaturated":0.035, "description":"BEANS,PINTO,IMMAT SEEDS,FRZ,CKD,BLD,DRND,WO\/SALT", "refuse_percent":0.0, "food_folate":34.0, "manganese":0.493, "zinc":0.69, "riboflavin":0.108, "copper":0.088}, "2516": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":16.0, "pantothenic_acid":0.153, "phosphorus":20.0, "beta_crytoxanthin":91.0, "thiamin":0.024, "selenium":0.1, "vitamin_k":2.6, "alpha_carotene":67.0, "carbohydrate":9.54, "sugar":8.39, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":190.0, "fat_poly_unsaturated":0.086, "lipid_total":0.25, "prompt":"PEACHES,RAW -- 1 cup, slices", "vitamin_e":0.73, "vitamin_b6":0.025, "fiber":1.5, "vitamin_c":6.6, "protein":0.91, "vitamin_a":326.0, "niacin":0.806, "fat_saturated":0.019, "weight1_gram":153.83, "folate_dfe":4.0, "choline":6.1, "sodium":0.0, "magnesium":9.0, "folic_acid":0.0, "weight1_description":"1 cup, slices", "calcium":6.0, "ndb_no":9236, "folate_total":4.0, "lutein_zeaxanthin":2.6, "iron":0.25, "id":2516, "energy_in_kcal":39.0, "fat_mono_unsaturated":0.067, "description":"PEACHES,RAW", "refuse_percent":4.0, "food_folate":4.0, "manganese":0.061, "zinc":0.17, "riboflavin":0.031, "copper":0.068}, "2261": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":11.0, "pantothenic_acid":1.31, "phosphorus":561.0, "beta_crytoxanthin":0.0, "thiamin":0.459, "selenium":65.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":1.5, "sugar":0.0, "vitamin_b12":1.3, "cholesterol":113.0, "retinol":11.0, "potassium":591.0, "fat_poly_unsaturated":4.447, "lipid_total":40.3, "prompt":"PORK,CURED,BACON,CKD,PAN-FRIED -- 1 slice, cooked", "vitamin_e":0.3, "vitamin_b6":0.389, "fiber":0.0, "vitamin_c":0.0, "protein":38.34, "vitamin_a":37.0, "niacin":11.575, "fat_saturated":13.291, "weight1_gram":7.94, "folate_dfe":2.0, "choline":130.8, "sodium":2428.0, "magnesium":36.0, "folic_acid":0.0, "weight1_description":"1 slice, cooked", "calcium":12.0, "ndb_no":10862, "folate_total":2.0, "lutein_zeaxanthin":0.0, "iron":1.38, "id":2261, "energy_in_kcal":533.0, "fat_mono_unsaturated":17.976, "description":"PORK,CURED,BACON,CKD,PAN-FRIED", "refuse_percent":0.0, "food_folate":2.0, "manganese":0.022, "zinc":3.64, "riboflavin":0.277, "copper":0.146}, "2325": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":2.0, "pantothenic_acid":0.123, "phosphorus":14.0, "beta_crytoxanthin":0.0, "thiamin":0.025, "selenium":0.1, "vitamin_k":0.6, "alpha_carotene":0.0, "carbohydrate":8.42, "sugar":1.69, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":117.0, "fat_poly_unsaturated":0.023, "lipid_total":0.07, "prompt":"LIME JUICE,RAW -- 1 cup", "vitamin_e":0.22, "vitamin_b6":0.038, "fiber":0.4, "vitamin_c":30.0, "protein":0.42, "vitamin_a":50.0, "niacin":0.142, "fat_saturated":0.008, "weight1_gram":241.53, "folate_dfe":10.0, "choline":5.1, "sodium":2.0, "magnesium":8.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":14.0, "ndb_no":9160, "folate_total":10.0, "lutein_zeaxanthin":0.6, "iron":0.09, "id":2325, "energy_in_kcal":25.0, "fat_mono_unsaturated":0.008, "description":"LIME JUICE,RAW", "refuse_percent":0.0, "food_folate":10.0, "manganese":0.018, "zinc":0.08, "riboflavin":0.015, "copper":0.027}, "373": {"beta_carotene":10515.0, "lycopene":10515.0, "vitamin_a_rae":15.0, "pantothenic_acid":0.007, "phosphorus":31.0, "beta_crytoxanthin":0.0, "thiamin":0.022, "selenium":0.9, "vitamin_k":4.5, "alpha_carotene":0.0, "carbohydrate":6.26, "sugar":3.06, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":297.0, "fat_poly_unsaturated":0.115, "lipid_total":0.16, "prompt":"SAUCE,SALSA,RTS -- 1 cup", "vitamin_e":1.18, "vitamin_b6":0.175, "fiber":1.6, "vitamin_c":1.9, "protein":1.54, "vitamin_a":292.0, "niacin":0.075, "fat_saturated":0.03, "weight1_gram":259.0, "folate_dfe":4.0, "choline":11.7, "sodium":600.0, "magnesium":15.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":27.0, "ndb_no":6164, "folate_total":4.0, "lutein_zeaxanthin":4.5, "iron":0.46, "id":373, "energy_in_kcal":27.0, "fat_mono_unsaturated":0.025, "description":"SAUCE,SALSA,RTS", "refuse_percent":0.0, "food_folate":4.0, "manganese":0.121, "zinc":0.37, "riboflavin":0.032, "copper":0.132}, "597": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":7.0, "pantothenic_acid":0.275, "phosphorus":89.0, "beta_crytoxanthin":0.0, "thiamin":0.034, "selenium":2.0, "vitamin_k":0.1, "alpha_carotene":0.0, "carbohydrate":4.79, "sugar":4.79, "vitamin_b12":0.22, "cholesterol":4.0, "retinol":7.0, "potassium":151.0, "fat_poly_unsaturated":0.033, "lipid_total":0.88, "prompt":"MILK,BTTRMLK,FLUID,CULTURED,LOWFAT -- 1 cup", "vitamin_e":0.05, "vitamin_b6":0.034, "fiber":0.0, "vitamin_c":1.0, "protein":3.31, "vitamin_a":26.0, "niacin":0.058, "fat_saturated":0.548, "weight1_gram":245.0, "folate_dfe":5.0, "choline":16.0, "sodium":105.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":116.0, "ndb_no":1088, "folate_total":5.0, "lutein_zeaxanthin":0.1, "iron":0.05, "id":597, "energy_in_kcal":40.0, "fat_mono_unsaturated":0.254, "description":"MILK,BTTRMLK,FLUID,CULTURED,LOWFAT", "refuse_percent":0.0, "food_folate":5.0, "manganese":0.002, "zinc":0.42, "riboflavin":0.154, "copper":0.011}, "4725": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.059, "selenium":0.7, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":76.79, "sugar":26.77, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":1.0, "fat_poly_unsaturated":0.0, "lipid_total":0.2, "prompt":"SYRUPS,CORN,LT -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":340.55, "folate_dfe":0.0, "choline":0.0, "sodium":62.0, "magnesium":1.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":13.0, "ndb_no":19350, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.0, "id":4725, "energy_in_kcal":283.0, "fat_mono_unsaturated":0.0, "description":"SYRUPS,CORN,LT", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.44, "riboflavin":0.0, "copper":0.0}, "4853": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.26, "phosphorus":152.0, "beta_crytoxanthin":0.0, "thiamin":0.225, "selenium":1.2, "vitamin_k":3.3, "alpha_carotene":0.0, "carbohydrate":24.35, "sugar":0.32, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":433.0, "fat_poly_unsaturated":0.149, "lipid_total":0.35, "prompt": "BEANS,BLACK TURTLE SOUP,MATURE SEEDS,CKD,BLD,W\/SALT -- 1 cup", "vitamin_e":0.87, "vitamin_b6":0.077, "fiber":5.3, "vitamin_c":0.0, "protein":8.18, "vitamin_a":0.0, "niacin":0.527, "fat_saturated":0.089, "weight1_gram":185.0, "folate_dfe":86.0, "choline":32.6, "sodium":239.0, "magnesium":49.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":55.0, "ndb_no":16317, "folate_total":86.0, "lutein_zeaxanthin":3.3, "iron":2.85, "id":4853, "energy_in_kcal":130.0, "fat_mono_unsaturated":0.03, "description": "BEANS,BLACK TURTLE SOUP,MATURE SEEDS,CKD,BLD,W\/SALT", "refuse_percent":0.0, "food_folate":86.0, "manganese":0.327, "zinc":0.76, "riboflavin":0.056, "copper":0.269}, "7061": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":1.008, "phosphorus":346.0, "beta_crytoxanthin":220.0, "thiamin":0.447, "selenium":70.7, "vitamin_k":1.9, "alpha_carotene":0.0, "carbohydrate":72.57, "sugar":0.41, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":405.0, "fat_poly_unsaturated":0.779, "lipid_total":1.87, "prompt":"WHEAT FLOUR,WHOLE-GRAIN -- 1 cup", "vitamin_e":0.82, "vitamin_b6":0.341, "fiber":12.2, "vitamin_c":0.0, "protein":13.7, "vitamin_a":9.0, "niacin":6.365, "fat_saturated":0.322, "weight1_gram":120.0, "folate_dfe":44.0, "choline":31.2, "sodium":5.0, "magnesium":138.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":34.0, "ndb_no":20080, "folate_total":44.0, "lutein_zeaxanthin":1.9, "iron":3.88, "id":7061, "energy_in_kcal":339.0, "fat_mono_unsaturated":0.232, "description":"WHEAT FLOUR,WHOLE-GRAIN", "refuse_percent":0.0, "food_folate":44.0, "manganese":3.799, "zinc":2.93, "riboflavin":0.215, "copper":0.382}, "150": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":25.0, "pantothenic_acid":0.804, "phosphorus":174.0, "beta_crytoxanthin":0.0, "thiamin":0.063, "selenium":16.6, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.34, "cholesterol":64.0, "retinol":24.0, "potassium":220.0, "fat_poly_unsaturated":1.96, "lipid_total":9.25, "prompt": "CHICKEN,BROILERS OR FRYERS,BREAST,MEAT&SKN,RAW -- .5 breast, bone removed (yield from 1 lb ready-to-cook chicken)", "vitamin_e":0.31, "vitamin_b6":0.53, "fiber":0.0, "vitamin_c":0.0, "protein":20.85, "vitamin_a":83.0, "niacin":9.908, "fat_saturated":2.66, "weight1_gram":87.0, "folate_dfe":4.0, "choline":67.1, "sodium":63.0, "magnesium":25.0, "folic_acid":0.0, "weight1_description": ".5 breast, bone removed (yield from 1 lb ready-to-cook chicken)", "calcium":11.0, "ndb_no":5057, "folate_total":4.0, "lutein_zeaxanthin":0.0, "iron":0.74, "id":150, "energy_in_kcal":172.0, "fat_mono_unsaturated":3.82, "description":"CHICKEN,BROILERS OR FRYERS,BREAST,MEAT&SKN,RAW", "refuse_percent":20.0, "food_folate":4.0, "manganese":0.018, "zinc":0.8, "riboflavin":0.085, "copper":0.039}, "241": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":25.0, "pantothenic_acid":0.804, "phosphorus":174.0, "beta_crytoxanthin":0.0, "thiamin":0.063, "selenium":16.6, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.34, "cholesterol":64.0, "retinol":24.0, "potassium":220.0, "fat_poly_unsaturated":1.96, "lipid_total":9.25, "prompt": "CHICKEN,BROILERS OR FRYERS,BREAST,MEAT&SKN,RAW -- 1 leg, bone removed (yield from 1 lb ready-to-cook chicken)", "vitamin_e":0.31, "vitamin_b6":0.53, "fiber":0.0, "vitamin_c":0.0, "protein":20.85, "vitamin_a":83.0, "niacin":9.908, "fat_saturated":2.66, "weight1_gram":87.0, "folate_dfe":4.0, "choline":67.1, "sodium":63.0, "magnesium":25.0, "folic_acid":0.0, "weight1_description": "1 leg, bone removed (yield from 1 lb ready-to-cook chicken)", "calcium":11.0, "ndb_no":5057, "folate_total":4.0, "lutein_zeaxanthin":0.0, "iron":0.74, "id":150, "energy_in_kcal":172.0, "fat_mono_unsaturated":3.82, "description":"CHICKEN,LEG,RAW", "refuse_percent":20.0, "food_folate":4.0, "manganese":0.018, "zinc":0.8, "riboflavin":0.085, "copper":0.039}, "2422": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":11.0, "pantothenic_acid":0.25, "phosphorus":12.0, "beta_crytoxanthin":129.0, "thiamin":0.1, "selenium":0.5, "vitamin_k":0.0, "alpha_carotene":116.0, "carbohydrate":11.54, "sugar":9.14, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":169.0, "fat_poly_unsaturated":0.042, "lipid_total":0.21, "prompt":"ORANGES,RAW,FLORIDA -- 1 cup, sections without membranes", "vitamin_e":0.18, "vitamin_b6":0.051, "fiber":2.4, "vitamin_c":45.0, "protein":0.7, "vitamin_a":225.0, "niacin":0.4, "fat_saturated":0.025, "weight1_gram":185.0, "folate_dfe":17.0, "choline":8.4, "sodium":0.0, "magnesium":10.0, "folic_acid":0.0, "weight1_description":"1 cup, sections without membranes", "calcium":43.0, "ndb_no":9203, "folate_total":17.0, "lutein_zeaxanthin":0.0, "iron":0.09, "id":2422, "energy_in_kcal":46.0, "fat_mono_unsaturated":0.039, "description":"ORANGES,RAW,FLORIDA", "refuse_percent":26.0, "food_folate":17.0, "manganese":0.024, "zinc":0.08, "riboflavin":0.04, "copper":0.039}, "5526": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":54.0, "pantothenic_acid":0.276, "phosphorus":205.0, "beta_crytoxanthin":0.0, "thiamin":0.028, "selenium":38.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.91, "sugar":0.0, "vitamin_b12":1.16, "cholesterol":152.0, "retinol":54.0, "potassium":185.0, "fat_poly_unsaturated":0.669, "lipid_total":1.73, "prompt":"SHRIMP,MIXED SPECIES,RAW -- 1 medium", "vitamin_e":1.1, "vitamin_b6":0.104, "fiber":0.0, "vitamin_c":2.0, "protein":20.31, "vitamin_a":180.0, "niacin":2.552, "fat_saturated":0.328, "weight1_gram":6.0, "folate_dfe":3.0, "choline":80.9, "sodium":148.0, "magnesium":37.0, "folic_acid":0.0, "weight1_description":"1 medium", "calcium":52.0, "ndb_no":15149, "folate_total":3.0, "lutein_zeaxanthin":0.0, "iron":2.41, "id":5526, "energy_in_kcal":106.0, "fat_mono_unsaturated":0.253, "description":"SHRIMP,MIXED SPECIES,RAW", "refuse_percent":0.0, "food_folate":3.0, "manganese":0.05, "zinc":1.11, "riboflavin":0.034, "copper":0.264}, "1494": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":35.0, "pantothenic_acid":0.094, "phosphorus":38.0, "beta_crytoxanthin":640.0, "thiamin":0.084, "selenium":0.6, "vitamin_k":14.4, "alpha_carotene":0.0, "carbohydrate":7.13, "sugar":1.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":209.0, "fat_poly_unsaturated":0.059, "lipid_total":0.12, "prompt":"BEANS,SNAP,GREEN,RAW -- 1 cup", "vitamin_e":0.41, "vitamin_b6":0.074, "fiber":3.4, "vitamin_c":16.3, "protein":1.82, "vitamin_a":690.0, "niacin":0.752, "fat_saturated":0.026, "weight1_gram":110.0, "folate_dfe":37.0, "choline":15.3, "sodium":6.0, "magnesium":25.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":37.0, "ndb_no":11052, "folate_total":37.0, "lutein_zeaxanthin":14.4, "iron":1.04, "id":1494, "energy_in_kcal":31.0, "fat_mono_unsaturated":0.005, "description":"BEANS,SNAP,GREEN,RAW", "refuse_percent":12.0, "food_folate":37.0, "manganese":0.214, "zinc":0.24, "riboflavin":0.105, "copper":0.069}, "4598": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.068, "phosphorus":4.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.8, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":82.4, "sugar":82.12, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":52.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"HONEY -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.024, "fiber":0.2, "vitamin_c":0.5, "protein":0.3, "vitamin_a":0.0, "niacin":0.121, "fat_saturated":0.0, "weight1_gram":339.0, "folate_dfe":2.0, "choline":2.2, "sodium":4.0, "magnesium":2.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":6.0, "ndb_no":19296, "folate_total":2.0, "lutein_zeaxanthin":0.0, "iron":0.42, "id":4598, "energy_in_kcal":304.0, "fat_mono_unsaturated":0.0, "description":"HONEY", "refuse_percent":0.0, "food_folate":2.0, "manganese":0.08, "zinc":0.22, "riboflavin":0.038, "copper":0.036}, "4151": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":469.0, "pantothenic_acid":0.065, "phosphorus":49.0, "beta_crytoxanthin":12198.0, "thiamin":0.078, "selenium":1.0, "vitamin_k":482.9, "alpha_carotene":0.0, "carbohydrate":3.63, "sugar":0.42, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":558.0, "fat_poly_unsaturated":0.165, "lipid_total":0.39, "prompt":"SPINACH,RAW -- 1 cup", "vitamin_e":2.03, "vitamin_b6":0.195, "fiber":2.2, "vitamin_c":28.1, "protein":2.86, "vitamin_a":9377.0, "niacin":0.724, "fat_saturated":0.063, "weight1_gram":30.0, "folate_dfe":194.0, "choline":18.0, "sodium":79.0, "magnesium":79.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":99.0, "ndb_no":11457, "folate_total":194.0, "lutein_zeaxanthin":482.9, "iron":2.71, "id":4151, "energy_in_kcal":23.0, "fat_mono_unsaturated":0.01, "description":"SPINACH,RAW", "refuse_percent":28.0, "food_folate":194.0, "manganese":0.897, "zinc":0.53, "riboflavin":0.189, "copper":0.13}, "4631": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.376, "phosphorus":130.0, "beta_crytoxanthin":0.0, "thiamin":0.059, "selenium":0.8, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":5.57, "sugar":1.7, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":212.0, "fat_poly_unsaturated":0.044, "lipid_total":0.1, "prompt":"SOY SAU MADE FROM SOY (TAMARI) -- 1 tbsp", "vitamin_e":0.0, "vitamin_b6":0.2, "fiber":0.8, "vitamin_c":0.0, "protein":10.51, "vitamin_a":0.0, "niacin":3.951, "fat_saturated":0.011, "weight1_gram":18.0, "folate_dfe":18.0, "choline":38.4, "sodium":5586.0, "magnesium":40.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":20.0, "ndb_no":16124, "folate_total":18.0, "lutein_zeaxanthin":0.0, "iron":2.38, "id":4631, "energy_in_kcal":60.0, "fat_mono_unsaturated":0.017, "description":"SOY SAU MADE FROM SOY (TAMARI)", "refuse_percent":0.0, "food_folate":18.0, "manganese":0.499, "zinc":0.43, "riboflavin":0.152, "copper":0.135}, "463199": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"table salt -- 1 tbsp", "vitamin_e":0.0, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":0.0, "folate_dfe":0.0, "choline":0.0, "sodium":33516.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":0.0, "ndb_no":16124, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.0, "id":463199, "energy_in_kcal":0.0, "fat_mono_unsaturated":0.0, "description":"SALT", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "1144": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.011, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.003, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":14.4, "sugar":14.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"VANILLA EXTRACT,IMITN,NO ALCOHOL -- 1 tbsp", "vitamin_e":0.0, "vitamin_b6":0.008, "fiber":0.0, "vitamin_c":0.0, "protein":0.03, "vitamin_a":0.0, "niacin":0.129, "fat_saturated":0.0, "weight1_gram":13.0, "folate_dfe":0.0, "choline":0.0, "sodium":3.0, "magnesium":1.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":3.0, "ndb_no":2052, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.05, "id":1144, "energy_in_kcal":56.0, "fat_mono_unsaturated":0.0, "description":"VANILLA EXTRACT,IMITN,NO ALCOHOL", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.001, "zinc":0.01, "riboflavin":0.029, "copper":0.003}, "2424": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":10.0, "pantothenic_acid":0.19, "phosphorus":17.0, "beta_crytoxanthin":115.0, "thiamin":0.09, "selenium":0.1, "vitamin_k":0.1, "alpha_carotene":169.0, "carbohydrate":10.4, "sugar":8.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":200.0, "fat_poly_unsaturated":0.04, "lipid_total":0.2, "prompt":"ORANGE JUICE,RAW -- 1 cup", "vitamin_e":0.04, "vitamin_b6":0.04, "fiber":0.2, "vitamin_c":50.0, "protein":0.7, "vitamin_a":200.0, "niacin":0.4, "fat_saturated":0.024, "weight1_gram":248.0, "folate_dfe":30.0, "choline":6.2, "sodium":1.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":11.0, "ndb_no":9206, "folate_total":30.0, "lutein_zeaxanthin":0.1, "iron":0.2, "id":2424, "energy_in_kcal":45.0, "fat_mono_unsaturated":0.036, "description":"ORANGE JUICE,RAW", "refuse_percent":0.0, "food_folate":30.0, "manganese":0.014, "zinc":0.05, "riboflavin":0.03, "copper":0.044}, "3576": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.123, "phosphorus":29.0, "beta_crytoxanthin":4.0, "thiamin":0.046, "selenium":0.5, "vitamin_k":0.4, "alpha_carotene":0.0, "carbohydrate":9.34, "sugar":4.24, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":146.0, "fat_poly_unsaturated":0.017, "lipid_total":0.1, "prompt":"ONIONS,RAW -- 1 cup, chopped", "vitamin_e":0.02, "vitamin_b6":0.12, "fiber":1.7, "vitamin_c":7.4, "protein":1.1, "vitamin_a":2.0, "niacin":0.116, "fat_saturated":0.042, "weight1_gram":160.0, "folate_dfe":19.0, "choline":6.1, "sodium":4.0, "magnesium":10.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":23.0, "ndb_no":11282, "folate_total":19.0, "lutein_zeaxanthin":0.4, "iron":0.21, "id":3576, "energy_in_kcal":40.0, "fat_mono_unsaturated":0.013, "description":"ONIONS,RAW", "refuse_percent":10.0, "food_folate":19.0, "manganese":0.129, "zinc":0.17, "riboflavin":0.027, "copper":0.039}, "357698": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":0.0, "lipid_total":0.0, "prompt":"GARLIC,RAW -- 1 clove, chopped", "vitamin_e":0.0, "vitamin_b6":2.0, "fiber":0.0, "vitamin_c":2.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":0.0, "weight1_gram":0.0, "folate_dfe":0.0, "choline":0.0, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 clove, chopped", "calcium":1.0, "ndb_no":11282, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":0.0, "id":357698, "energy_in_kcal":0.0, "fat_mono_unsaturated":0.0, "description":"GARLIC,RAW", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "1656": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.652, "phosphorus":44.0, "beta_crytoxanthin":33.0, "thiamin":0.057, "selenium":0.6, "vitamin_k":16.0, "alpha_carotene":0.0, "carbohydrate":5.3, "sugar":2.4, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":303.0, "fat_poly_unsaturated":0.048, "lipid_total":0.1, "prompt":"CAULIFLOWER,RAW -- 1 cup", "vitamin_e":0.08, "vitamin_b6":0.222, "fiber":2.5, "vitamin_c":46.4, "protein":1.98, "vitamin_a":13.0, "niacin":0.526, "fat_saturated":0.015, "weight1_gram":100.0, "folate_dfe":57.0, "choline":45.2, "sodium":30.0, "magnesium":15.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":22.0, "ndb_no":11135, "folate_total":57.0, "lutein_zeaxanthin":16.0, "iron":0.44, "id":1656, "energy_in_kcal":25.0, "fat_mono_unsaturated":0.007, "description":"CAULIFLOWER,RAW", "refuse_percent":61.0, "food_folate":57.0, "manganese":0.156, "zinc":0.28, "riboflavin":0.063, "copper":0.042}, "4728": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.036, "phosphorus":2.0, "beta_crytoxanthin":0.0, "thiamin":0.006, "selenium":0.6, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":67.09, "sugar":59.52, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":204.0, "fat_poly_unsaturated":0.1, "lipid_total":0.2, "prompt":"SYRUPS,MAPLE -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.002, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.03, "fat_saturated":0.036, "weight1_gram":322.45, "folate_dfe":0.0, "choline":1.6, "sodium":9.0, "magnesium":14.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":67.0, "ndb_no":19353, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":1.2, "id":4728, "energy_in_kcal":261.0, "fat_mono_unsaturated":0.064, "description":"SYRUPS,MAPLE", "refuse_percent":0.0, "food_folate":0.0, "manganese":3.298, "zinc":4.16, "riboflavin":0.01, "copper":0.074}, "5752": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":59.0, "pantothenic_acid":1.273, "phosphorus":332.0, "beta_crytoxanthin":-1.0, "thiamin":0.1, "selenium":14.1, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":0.0, "sugar":-1.0, "vitamin_b12":3.17, "cholesterol":63.0, "retinol":59.0, "potassium":460.0, "fat_poly_unsaturated":1.963, "lipid_total":8.23, "prompt":"SALMON,COHO,FARMED,CKD,DRY HEAT -- 1 fillet", "vitamin_e":-1.0, "vitamin_b6":0.568, "fiber":0.0, "vitamin_c":1.5, "protein":24.3, "vitamin_a":197.0, "niacin":7.393, "fat_saturated":1.944, "weight1_gram":143.0, "folate_dfe":14.0, "choline":-1.0, "sodium":52.0, "magnesium":34.0, "folic_acid":0.0, "weight1_description":"1 fillet", "calcium":12.0, "ndb_no":15239, "folate_total":14.0, "lutein_zeaxanthin":-1.0, "iron":0.39, "id":5752, "energy_in_kcal":178.0, "fat_mono_unsaturated":3.618, "description":"SALMON,COHO,FARMED,CKD,DRY HEAT", "refuse_percent":0.0, "food_folate":14.0, "manganese":0.021, "zinc":0.47, "riboflavin":0.113, "copper":0.089}, "4088": {"beta_carotene":16709.0, "lycopene":16709.0, "vitamin_a_rae":47.0, "pantothenic_acid":0.046, "phosphorus":33.0, "beta_crytoxanthin":0.0, "thiamin":0.011, "selenium":0.3, "vitamin_k":2.8, "alpha_carotene":0.0, "carbohydrate":25.15, "sugar":22.77, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":382.0, "fat_poly_unsaturated":0.126, "lipid_total":0.31, "prompt":"CATSUP -- 1 cup", "vitamin_e":1.46, "vitamin_b6":0.149, "fiber":0.3, "vitamin_c":15.1, "protein":1.74, "vitamin_a":933.0, "niacin":1.426, "fat_saturated":0.043, "weight1_gram":240.0, "folate_dfe":10.0, "choline":12.5, "sodium":1114.0, "magnesium":19.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":18.0, "ndb_no":11935, "folate_total":10.0, "lutein_zeaxanthin":2.8, "iron":0.51, "id":4088, "energy_in_kcal":97.0, "fat_mono_unsaturated":0.047, "description":"CATSUP", "refuse_percent":0.0, "food_folate":10.0, "manganese":0.128, "zinc":0.26, "riboflavin":0.132, "copper":0.181}, "5849": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.242, "phosphorus":140.0, "beta_crytoxanthin":-1.0, "thiamin":0.244, "selenium":1.2, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":23.71, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":355.0, "fat_poly_unsaturated":0.231, "lipid_total":0.54, "prompt":"BEANS,BLACK,MATURE SEEDS,CKD,BLD,WO\/SALT -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.069, "fiber":8.7, "vitamin_c":0.0, "protein":8.86, "vitamin_a":6.0, "niacin":0.505, "fat_saturated":0.139, "weight1_gram":172.0, "folate_dfe":149.0, "choline":-1.0, "sodium":1.0, "magnesium":70.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":27.0, "ndb_no":16015, "folate_total":149.0, "lutein_zeaxanthin":-1.0, "iron":2.1, "id":5849, "energy_in_kcal":132.0, "fat_mono_unsaturated":0.047, "description":"BEANS,BLACK,MATURE SEEDS,CKD,BLD,WO\/SALT", "refuse_percent":0.0, "food_folate":149.0, "manganese":0.444, "zinc":1.12, "riboflavin":0.059, "copper":0.209}, "4857": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.22, "phosphorus":142.0, "beta_crytoxanthin":0.0, "thiamin":0.16, "selenium":1.2, "vitamin_k":3.3, "alpha_carotene":0.0, "carbohydrate":22.8, "sugar":0.32, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":403.0, "fat_poly_unsaturated":0.275, "lipid_total":0.5, "prompt": "BEANS,KIDNEY,ALL TYPES,MATURE SEEDS,CKD,BLD,W\/SALT -- 1 cup", "vitamin_e":0.87, "vitamin_b6":0.12, "fiber":6.4, "vitamin_c":1.2, "protein":8.67, "vitamin_a":0.0, "niacin":0.578, "fat_saturated":0.072, "weight1_gram":177.0, "folate_dfe":130.0, "choline":-1.0, "sodium":238.0, "magnesium":45.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":28.0, "ndb_no":16328, "folate_total":130.0, "lutein_zeaxanthin":3.3, "iron":2.94, "id":4857, "energy_in_kcal":127.0, "fat_mono_unsaturated":0.039, "description":"BEANS,KIDNEY,ALL TYPES,MATURE SEEDS,CKD,BLD,W\/SALT", "refuse_percent":0.0, "food_folate":130.0, "manganese":0.477, "zinc":1.07, "riboflavin":0.058, "copper":0.242}, "1977": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":84.0, "pantothenic_acid":0.2, "phosphorus":19.0, "beta_crytoxanthin":-1.0, "thiamin":0.02, "selenium":0.4, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":25.1, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":229.0, "fat_poly_unsaturated":0.02, "lipid_total":0.1, "prompt":"APRICOTS,FROZEN,SWEETENED -- 1 cup", "vitamin_e":-1.0, "vitamin_b6":0.06, "fiber":2.2, "vitamin_c":9.0, "protein":0.7, "vitamin_a":1680.0, "niacin":0.8, "fat_saturated":0.007, "weight1_gram":242.0, "folate_dfe":2.0, "choline":-1.0, "sodium":4.0, "magnesium":9.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":10.0, "ndb_no":9035, "folate_total":2.0, "lutein_zeaxanthin":-1.0, "iron":0.9, "id":1977, "energy_in_kcal":98.0, "fat_mono_unsaturated":0.044, "description":"APRICOTS,FROZEN,SWEETENED", "refuse_percent":0.0, "food_folate":2.0, "manganese":0.05, "zinc":0.1, "riboflavin":0.04, "copper":0.064}, "4057": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.473, "phosphorus":78.0, "beta_crytoxanthin":12.0, "thiamin":0.098, "selenium":0.4, "vitamin_k":1.8, "alpha_carotene":0.0, "carbohydrate":23.51, "sugar":0.2, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":-1.0, "potassium":400.0, "fat_poly_unsaturated":0.218, "lipid_total":3.39, "prompt": "POTATOES,FRENCH FR,STK FRIES,SALT ADDED IN PROC,FRZ,AS PRCH -- 10 strip", "vitamin_e":0.08, "vitamin_b6":0.168, "fiber":1.9, "vitamin_c":18.4, "protein":2.19, "vitamin_a":4.0, "niacin":2.005, "fat_saturated":0.688, "weight1_gram":153.38, "folate_dfe":-1.0, "choline":-1.0, "sodium":317.0, "magnesium":21.0, "folic_acid":-1.0, "weight1_description":"10 strip", "calcium":9.0, "ndb_no":11411, "folate_total":38.0, "lutein_zeaxanthin":1.8, "iron":0.65, "id":4057, "energy_in_kcal":133.0, "fat_mono_unsaturated":2.025, "description": "POTATOES,FRENCH FR,STK FRIES,SALT ADDED IN PROC,FRZ,AS PRCH", "refuse_percent":0.0, "food_folate":38.0, "manganese":0.161, "zinc":0.36, "riboflavin":0.072, "copper":0.092}, "7226": {"beta_carotene":-1.0, "lycopene":0.11, "vitamin_a_rae":0.0, "pantothenic_acid":0.431, "phosphorus":189.0, "beta_crytoxanthin":-1.0, "thiamin":0.09, "selenium":63.2, "vitamin_k":0.1, "alpha_carotene":-1.0, "carbohydrate":74.67, "sugar":2.67, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":223.0, "fat_poly_unsaturated":0.564, "lipid_total":1.51, "prompt":"MACARONI,DRY,UNENRICHED -- 1 cup, elbow shaped", "vitamin_e":0.11, "vitamin_b6":0.142, "fiber":3.2, "vitamin_c":0.0, "protein":13.04, "vitamin_a":0.0, "niacin":1.7, "fat_saturated":0.277, "weight1_gram":105.0, "folate_dfe":18.0, "choline":-1.0, "sodium":6.0, "magnesium":53.0, "folic_acid":0.0, "weight1_description":"1 cup, elbow shaped", "calcium":21.0, "ndb_no":20499, "folate_total":18.0, "lutein_zeaxanthin":0.1, "iron":1.3, "id":7226, "energy_in_kcal":371.0, "fat_mono_unsaturated":0.171, "description":"MACARONI,DRY,UNENRICHED", "refuse_percent":0.0, "food_folate":18.0, "manganese":0.917, "zinc":1.41, "riboflavin":0.06, "copper":0.289}, "3354": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":4.0, "pantothenic_acid":0.24, "phosphorus":21.0, "beta_crytoxanthin":16.0, "thiamin":0.031, "selenium":0.1, "vitamin_k":7.2, "alpha_carotene":18.0, "carbohydrate":2.16, "sugar":1.38, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":136.0, "fat_poly_unsaturated":0.003, "lipid_total":0.16, "prompt":"CUCUMBER,PEELED,RAW -- 1 cup, pared chopped", "vitamin_e":0.03, "vitamin_b6":0.051, "fiber":0.7, "vitamin_c":3.2, "protein":0.59, "vitamin_a":72.0, "niacin":0.037, "fat_saturated":0.013, "weight1_gram":133.0, "folate_dfe":14.0, "choline":5.7, "sodium":2.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup, pared chopped", "calcium":14.0, "ndb_no":11206, "folate_total":14.0, "lutein_zeaxanthin":7.2, "iron":0.22, "id":3354, "energy_in_kcal":12.0, "fat_mono_unsaturated":0.002, "description":"CUCUMBER,PEELED,RAW", "refuse_percent":27.0, "food_folate":14.0, "manganese":0.073, "zinc":0.17, "riboflavin":0.025, "copper":0.071}, "410": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":97.0, "pantothenic_acid":0.289, "phosphorus":95.0, "beta_crytoxanthin":0.0, "thiamin":0.035, "selenium":1.8, "vitamin_k":1.3, "alpha_carotene":0.0, "carbohydrate":4.3, "sugar":0.16, "vitamin_b12":0.33, "cholesterol":37.0, "retinol":95.0, "potassium":130.0, "fat_poly_unsaturated":0.427, "lipid_total":11.5, "prompt":"CREAM,FLUID,HALF AND HALF -- 1 cup", "vitamin_e":0.33, "vitamin_b6":0.039, "fiber":0.0, "vitamin_c":0.9, "protein":2.96, "vitamin_a":354.0, "niacin":0.078, "fat_saturated":7.158, "weight1_gram":242.0, "folate_dfe":3.0, "choline":18.7, "sodium":41.0, "magnesium":10.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":105.0, "ndb_no":1049, "folate_total":3.0, "lutein_zeaxanthin":1.3, "iron":0.07, "id":410, "energy_in_kcal":130.0, "fat_mono_unsaturated":3.321, "description":"CREAM,FLUID,HALF AND HALF", "refuse_percent":0.0, "food_folate":3.0, "manganese":0.001, "zinc":0.51, "riboflavin":0.149, "copper":0.01}, "4634": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.051, "phosphorus":92.0, "beta_crytoxanthin":0.0, "thiamin":0.047, "selenium":8.9, "vitamin_k":2.0, "alpha_carotene":0.0, "carbohydrate":1.8, "sugar":0.7, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":120.0, "fat_poly_unsaturated":2.081, "lipid_total":3.69, "prompt": "TOFU,SOFT,PREP W\/CA SULFATE&MAGNESIUM CHLORIDE (NIGARI) -- 1 cup, (1\/2\" cubes)", "vitamin_e":0.01, "vitamin_b6":0.052, "fiber":0.2, "vitamin_c":0.2, "protein":6.55, "vitamin_a":7.0, "niacin":0.535, "fat_saturated":0.533, "weight1_gram":248.0, "folate_dfe":44.0, "choline":27.4, "sodium":8.0, "magnesium":27.0, "folic_acid":0.0, "weight1_description":"1 cup, (1\/2\" cubes)", "calcium":111.0, "ndb_no":16127, "folate_total":44.0, "lutein_zeaxanthin":2.0, "iron":1.11, "id":4634, "energy_in_kcal":61.0, "fat_mono_unsaturated":0.814, "description": "TOFU,SOFT,PREP W\/CA SULFATE&MAGNESIUM CHLORIDE (NIGARI)", "refuse_percent":0.0, "food_folate":44.0, "manganese":0.389, "zinc":0.64, "riboflavin":0.037, "copper":0.157}, "698": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":28.0, "pantothenic_acid":0.26, "phosphorus":120.0, "beta_crytoxanthin":70.0, "thiamin":0.012, "selenium":6.7, "vitamin_k":0.06, "alpha_carotene":1.4, "carbohydrate":0.18, "sugar":0.18, "vitamin_b12":0.25, "cholesterol":250.0, "retinol":30.0, "potassium":28.0, "fat_poly_unsaturated":0.364, "lipid_total":1.9, "prompt":"EGG,WHOLE,RAW,FRESH -- 1 unit", "vitamin_e":0.19, "vitamin_b6":0.1, "fiber":0.0, "vitamin_c":0.0, "protein":60.0, "vitamin_a":96.0, "niacin":0.012, "fat_saturated":3.0, "weight1_gram":46.0, "folate_dfe":9.0, "choline":10.1, "sodium":3.0, "magnesium":1.0, "folic_acid":0.0, "weight1_description":"1 unit", "calcium":11.0, "ndb_no":1123, "folate_total":9.0, "lutein_zeaxanthin":0.06, "iron":0.4, "id":698, "energy_in_kcal":28.0, "fat_mono_unsaturated":0.85, "description":"EGG,WHOLE,RAW,FRESH", "refuse_percent":2.2, "food_folate":9.0, "manganese":0.008, "zinc":0.23, "riboflavin":0.4, "copper":0.022}, "4155": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":586.0, "pantothenic_acid":0.094, "phosphorus":49.0, "beta_crytoxanthin":12651.0, "thiamin":0.094, "selenium":6.0, "vitamin_k":372.0, "alpha_carotene":0.0, "carbohydrate":4.21, "sugar":0.65, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":346.0, "fat_poly_unsaturated":0.082, "lipid_total":0.57, "prompt":"SPINACH,FRZ,CHOPD OR LEAF,UNPREP -- 1 cup", "vitamin_e":2.9, "vitamin_b6":0.172, "fiber":2.9, "vitamin_c":5.5, "protein":3.63, "vitamin_a":11726.0, "niacin":0.507, "fat_saturated":0.041, "weight1_gram":156.0, "folate_dfe":145.0, "choline":22.1, "sodium":74.0, "magnesium":75.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":129.0, "ndb_no":11463, "folate_total":145.0, "lutein_zeaxanthin":372.0, "iron":1.89, "id":4155, "energy_in_kcal":29.0, "fat_mono_unsaturated":0.0, "description":"SPINACH,FRZ,CHOPD OR LEAF,UNPREP", "refuse_percent":0.0, "food_folate":145.0, "manganese":0.704, "zinc":0.56, "riboflavin":0.224, "copper":0.144}, "5435": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":6.0, "pantothenic_acid":0.124, "phosphorus":217.0, "beta_crytoxanthin":0.0, "thiamin":0.008, "selenium":65.7, "vitamin_k":2.5, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":1.17, "cholesterol":42.0, "retinol":6.0, "potassium":237.0, "fat_poly_unsaturated":1.109, "lipid_total":2.97, "prompt":"TUNA,WHITE,CND IN H2O,DRND SOL -- 1 can", "vitamin_e":0.85, "vitamin_b6":0.217, "fiber":0.0, "vitamin_c":0.0, "protein":23.62, "vitamin_a":20.0, "niacin":5.799, "fat_saturated":0.792, "weight1_gram":172.0, "folate_dfe":2.0, "choline":29.3, "sodium":377.0, "magnesium":33.0, "folic_acid":0.0, "weight1_description":"1 can", "calcium":14.0, "ndb_no":15126, "folate_total":2.0, "lutein_zeaxanthin":2.5, "iron":0.97, "id":5435, "energy_in_kcal":128.0, "fat_mono_unsaturated":0.784, "description":"TUNA,WHITE,CND IN H2O,DRND SOL", "refuse_percent":0.0, "food_folate":2.0, "manganese":0.019, "zinc":0.48, "riboflavin":0.044, "copper":0.039}, "699": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.19, "phosphorus":15.0, "beta_crytoxanthin":0.0, "thiamin":0.004, "selenium":20.0, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":0.73, "sugar":0.71, "vitamin_b12":0.09, "cholesterol":0.0, "retinol":0.0, "potassium":163.0, "fat_poly_unsaturated":0.0, "lipid_total":0.17, "prompt":"EGG,WHITE,RAW,FRESH -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.005, "fiber":0.0, "vitamin_c":0.0, "protein":10.9, "vitamin_a":0.0, "niacin":0.105, "fat_saturated":0.0, "weight1_gram":243.0, "folate_dfe":4.0, "choline":1.1, "sodium":166.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":7.0, "ndb_no":1124, "folate_total":4.0, "lutein_zeaxanthin":0.0, "iron":0.08, "id":699, "energy_in_kcal":48.0, "fat_mono_unsaturated":0.0, "description":"EGG,WHITE,RAW,FRESH", "refuse_percent":0.0, "food_folate":4.0, "manganese":0.011, "zinc":0.03, "riboflavin":0.439, "copper":0.023}, "7131": {"beta_carotene":18604.0, "lycopene":18604.0, "vitamin_a_rae":21.0, "pantothenic_acid":-1.0, "phosphorus":32.0, "beta_crytoxanthin":0.0, "thiamin":0.07, "selenium":0.6, "vitamin_k":3.5, "alpha_carotene":0.0, "carbohydrate":8.71, "sugar":4.24, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":371.0, "fat_poly_unsaturated":0.079, "lipid_total":0.2, "prompt":"TOMATO SAU,NO SALT -- 1 cup", "vitamin_e":1.74, "vitamin_b6":0.16, "fiber":1.5, "vitamin_c":13.1, "protein":1.3, "vitamin_a":427.0, "niacin":1.15, "fat_saturated":0.028, "weight1_gram":244.0, "folate_dfe":9.0, "choline":12.1, "sodium":11.0, "magnesium":19.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":14.0, "ndb_no":43217, "folate_total":9.0, "lutein_zeaxanthin":3.5, "iron":0.77, "id":7131, "energy_in_kcal":42.0, "fat_mono_unsaturated":0.029, "description":"TOMATO SAU,NO SALT", "refuse_percent":0.0, "food_folate":9.0, "manganese":0.131, "zinc":0.25, "riboflavin":0.06, "copper":0.196}, "1084": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":22.0, "pantothenic_acid":0.636, "phosphorus":160.0, "beta_crytoxanthin":0.0, "thiamin":0.092, "selenium":15.8, "vitamin_k":2.4, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.4, "cholesterol":91.0, "retinol":22.0, "potassium":269.0, "fat_poly_unsaturated":0.81, "lipid_total":3.33, "prompt":"CHICKEN,CORNISH GAME HENS,MEAT ONLY,RAW -- 1 bird, whole", "vitamin_e":0.21, "vitamin_b6":0.385, "fiber":0.0, "vitamin_c":0.6, "protein":20.04, "vitamin_a":75.0, "niacin":6.744, "fat_saturated":0.85, "weight1_gram":239.0, "folate_dfe":3.0, "choline":-1.0, "sodium":68.0, "magnesium":21.0, "folic_acid":0.0, "weight1_description":"1 bird, whole", "calcium":12.0, "ndb_no":5309, "folate_total":3.0, "lutein_zeaxanthin":2.4, "iron":0.74, "id":1084, "energy_in_kcal":116.0, "fat_mono_unsaturated":1.07, "description":"CHICKEN,CORNISH GAME HENS,MEAT ONLY,RAW", "refuse_percent":57.0, "food_folate":3.0, "manganese":0.017, "zinc":1.31, "riboflavin":0.216, "copper":0.053}, "7324": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.39, "phosphorus":43.0, "beta_crytoxanthin":0.0, "thiamin":0.02, "selenium":7.5, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":28.17, "sugar":0.05, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":35.0, "fat_poly_unsaturated":0.076, "lipid_total":0.28, "prompt":"RICE,WHITE,LONG-GRAIN,REG,CKD,UNENR,WO\/SALT -- 1 cup", "vitamin_e":0.04, "vitamin_b6":0.093, "fiber":0.4, "vitamin_c":0.0, "protein":2.69, "vitamin_a":0.0, "niacin":0.4, "fat_saturated":0.077, "weight1_gram":158.0, "folate_dfe":3.0, "choline":2.1, "sodium":1.0, "magnesium":12.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":10.0, "ndb_no":20445, "folate_total":3.0, "lutein_zeaxanthin":0.0, "iron":0.2, "id":7324, "energy_in_kcal":130.0, "fat_mono_unsaturated":0.088, "description":"RICE,WHITE,LONG-GRAIN,REG,CKD,UNENR,WO\/SALT", "refuse_percent":0.0, "food_folate":3.0, "manganese":0.472, "zinc":0.49, "riboflavin":0.013, "copper":0.069}, "4572": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.194, "phosphorus":314.0, "beta_crytoxanthin":-1.0, "thiamin":0.112, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":46.6, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":154.0, "fat_poly_unsaturated":1.122, "lipid_total":2.5, "prompt":"TORTILLAS,RTB OR -FRY,CORN,WO\/ SALT -- 1 oz", "vitamin_e":-1.0, "vitamin_b6":0.219, "fiber":5.2, "vitamin_c":0.0, "protein":5.7, "vitamin_a":0.0, "niacin":1.498, "fat_saturated":0.334, "weight1_gram":28.35, "folate_dfe":183.0, "choline":-1.0, "sodium":11.0, "magnesium":65.0, "folic_acid":99.0, "weight1_description":"1 oz", "calcium":175.0, "ndb_no":18449, "folate_total":114.0, "lutein_zeaxanthin":-1.0, "iron":1.4, "id":4572, "energy_in_kcal":222.0, "fat_mono_unsaturated":0.649, "description":"TORTILLAS,RTB OR -FRY,CORN,WO\/ SALT", "refuse_percent":0.0, "food_folate":15.0, "manganese":0.402, "zinc":0.94, "riboflavin":0.073, "copper":0.154}, "4604": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.804, "phosphorus":31.0, "beta_crytoxanthin":0.0, "thiamin":0.041, "selenium":17.8, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":74.73, "sugar":55.49, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":1464.0, "fat_poly_unsaturated":0.05, "lipid_total":0.1, "prompt":"MOLASSES -- 1 cup", "vitamin_e":0.0, "vitamin_b6":0.67, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.93, "fat_saturated":0.018, "weight1_gram":337.16, "folate_dfe":0.0, "choline":13.3, "sodium":37.0, "magnesium":242.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":205.0, "ndb_no":19304, "folate_total":0.0, "lutein_zeaxanthin":0.0, "iron":4.72, "id":4604, "energy_in_kcal":290.0, "fat_mono_unsaturated":0.032, "description":"MOLASSES", "refuse_percent":0.0, "food_folate":0.0, "manganese":1.53, "zinc":0.29, "riboflavin":0.002, "copper":0.487}, "700": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":381.0, "pantothenic_acid":2.99, "phosphorus":390.0, "beta_crytoxanthin":1094.0, "thiamin":0.176, "selenium":56.0, "vitamin_k":0.7, "alpha_carotene":33.0, "carbohydrate":3.59, "sugar":0.56, "vitamin_b12":1.95, "cholesterol":1234.0, "retinol":371.0, "potassium":109.0, "fat_poly_unsaturated":4.204, "lipid_total":26.54, "prompt":"EGG,YOLK,RAW,FRSH -- 1 cup", "vitamin_e":2.58, "vitamin_b6":0.35, "fiber":0.0, "vitamin_c":0.0, "protein":15.86, "vitamin_a":1442.0, "niacin":0.024, "fat_saturated":9.551, "weight1_gram":243.0, "folate_dfe":146.0, "choline":682.3, "sodium":48.0, "magnesium":5.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":129.0, "ndb_no":1125, "folate_total":146.0, "lutein_zeaxanthin":0.7, "iron":2.73, "id":700, "energy_in_kcal":317.0, "fat_mono_unsaturated":11.738, "description":"EGG,YOLK,RAW,FRSH", "refuse_percent":0.0, "food_folate":146.0, "manganese":0.055, "zinc":2.3, "riboflavin":0.528, "copper":0.077}, "1980": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":7.0, "pantothenic_acid":1.463, "phosphorus":54.0, "beta_crytoxanthin":271.0, "thiamin":0.075, "selenium":0.4, "vitamin_k":21.0, "alpha_carotene":27.0, "carbohydrate":8.64, "sugar":0.3, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":507.0, "fat_poly_unsaturated":1.816, "lipid_total":15.41, "prompt":"AVOCADOS,RAW,CALIFORNIA -- 1 cup, pureed", "vitamin_e":1.97, "vitamin_b6":0.287, "fiber":6.8, "vitamin_c":8.8, "protein":1.96, "vitamin_a":147.0, "niacin":1.912, "fat_saturated":2.126, "weight1_gram":230.0, "folate_dfe":89.0, "choline":14.2, "sodium":8.0, "magnesium":29.0, "folic_acid":0.0, "weight1_description":"1 cup, pureed", "calcium":13.0, "ndb_no":9038, "folate_total":89.0, "lutein_zeaxanthin":21.0, "iron":0.61, "id":1980, "energy_in_kcal":167.0, "fat_mono_unsaturated":9.799, "description":"AVOCADOS,RAW,CALIFORNIA", "refuse_percent":33.0, "food_folate":89.0, "manganese":0.149, "zinc":0.68, "riboflavin":0.143, "copper":0.17}, "3357": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":1.0, "pantothenic_acid":0.281, "phosphorus":25.0, "beta_crytoxanthin":0.0, "thiamin":0.039, "selenium":0.3, "vitamin_k":3.5, "alpha_carotene":0.0, "carbohydrate":5.7, "sugar":2.35, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":230.0, "fat_poly_unsaturated":0.076, "lipid_total":0.19, "prompt":"EGGPLANT,RAW -- 1 cup, cubes", "vitamin_e":0.3, "vitamin_b6":0.084, "fiber":3.4, "vitamin_c":2.2, "protein":1.01, "vitamin_a":27.0, "niacin":0.649, "fat_saturated":0.034, "weight1_gram":82.0, "folate_dfe":22.0, "choline":6.9, "sodium":2.0, "magnesium":14.0, "folic_acid":0.0, "weight1_description":"1 cup, cubes", "calcium":9.0, "ndb_no":11209, "folate_total":22.0, "lutein_zeaxanthin":3.5, "iron":0.24, "id":3357, "energy_in_kcal":24.0, "fat_mono_unsaturated":0.016, "description":"EGGPLANT,RAW", "refuse_percent":19.0, "food_folate":22.0, "manganese":0.25, "zinc":0.16, "riboflavin":0.037, "copper":0.082}, "1341": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":197.6, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":65.138, "lipid_total":100.0, "prompt":"USDA CMDTY FD,OIL,VEG,LO SATURATED FAT -- 1 tbsp", "vitamin_e":9.21, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":7.429, "weight1_gram":13.6, "folate_dfe":0.0, "choline":-1.0, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":0.0, "ndb_no":4670, "folate_total":0.0, "lutein_zeaxanthin":197.6, "iron":0.02, "id":1341, "energy_in_kcal":884.0, "fat_mono_unsaturated":22.73, "description":"USDA CMDTY FD,OIL,VEG,LO SATURATED FAT", "refuse_percent":0.0, "food_folate":0.0, "manganese":-1.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "3453": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":769.0, "pantothenic_acid":0.091, "phosphorus":56.0, "beta_crytoxanthin":39550.0, "thiamin":0.11, "selenium":0.9, "vitamin_k":817.0, "alpha_carotene":0.0, "carbohydrate":10.01, "sugar":-1.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":447.0, "fat_poly_unsaturated":0.338, "lipid_total":0.7, "prompt":"KALE,RAW -- 1 cup, chopped", "vitamin_e":0.0, "vitamin_b6":0.271, "fiber":2.0, "vitamin_c":120.0, "protein":3.3, "vitamin_a":15376.0, "niacin":1.0, "fat_saturated":0.091, "weight1_gram":67.0, "folate_dfe":29.0, "choline":-1.0, "sodium":43.0, "magnesium":34.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":135.0, "ndb_no":11233, "folate_total":29.0, "lutein_zeaxanthin":817.0, "iron":1.7, "id":3453, "energy_in_kcal":50.0, "fat_mono_unsaturated":0.052, "description":"KALE,RAW", "refuse_percent":39.0, "food_folate":29.0, "manganese":0.774, "zinc":0.44, "riboflavin":0.13, "copper":0.29}, "1501": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":2.0, "pantothenic_acid":0.155, "phosphorus":40.0, "beta_crytoxanthin":0.0, "thiamin":0.031, "selenium":0.7, "vitamin_k":0.2, "alpha_carotene":0.0, "carbohydrate":9.56, "sugar":6.76, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":325.0, "fat_poly_unsaturated":0.06, "lipid_total":0.17, "prompt":"BEETS,RAW -- 1 cup", "vitamin_e":0.04, "vitamin_b6":0.067, "fiber":2.8, "vitamin_c":4.9, "protein":1.61, "vitamin_a":33.0, "niacin":0.334, "fat_saturated":0.027, "weight1_gram":136.0, "folate_dfe":109.0, "choline":6.0, "sodium":78.0, "magnesium":23.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":16.0, "ndb_no":11080, "folate_total":109.0, "lutein_zeaxanthin":0.2, "iron":0.8, "id":1501, "energy_in_kcal":43.0, "fat_mono_unsaturated":0.032, "description":"BEETS,RAW", "refuse_percent":33.0, "food_folate":109.0, "manganese":0.329, "zinc":0.35, "riboflavin":0.04, "copper":0.075}, "4797": {"beta_carotene":-1.0, "lycopene":-1.0, "vitamin_a_rae":-1.0, "pantothenic_acid":-1.0, "phosphorus":-1.0, "beta_crytoxanthin":-1.0, "thiamin":-1.0, "selenium":-1.0, "vitamin_k":-1.0, "alpha_carotene":-1.0, "carbohydrate":49.6, "sugar":-1.0, "vitamin_b12":-1.0, "cholesterol":-1.0, "retinol":-1.0, "potassium":-1.0, "fat_poly_unsaturated":0.924, "lipid_total":6.0, "prompt": "MISSION FOODS,MISSION FLR TORTILLAS,SOFT TACO,8 INCH -- 1 serving", "vitamin_e":-1.0, "vitamin_b6":-1.0, "fiber":-1.0, "vitamin_c":-1.0, "protein":8.7, "vitamin_a":-1.0, "niacin":-1.0, "fat_saturated":0.695, "weight1_gram":51.0, "folate_dfe":-1.0, "choline":-1.0, "sodium":488.0, "magnesium":-1.0, "folic_acid":-1.0, "weight1_description":"1 serving", "calcium":191.0, "ndb_no":18616, "folate_total":-1.0, "lutein_zeaxanthin":-1.0, "iron":1.99, "id":4797, "energy_in_kcal":287.0, "fat_mono_unsaturated":2.771, "description": "MISSION FOODS,MISSION FLR TORTILLAS,SOFT TACO,8 INCH", "refuse_percent":0.0, "food_folate":-1.0, "manganese":-1.0, "zinc":-1.0, "riboflavin":-1.0, "copper":-1.0}, "6141": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":-1.0, "phosphorus":25.0, "beta_crytoxanthin":0.0, "thiamin":0.01, "selenium":1.6, "vitamin_k":24.7, "alpha_carotene":0.0, "carbohydrate":0.3, "sugar":0.3, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":14.0, "fat_poly_unsaturated":45.539, "lipid_total":77.8, "prompt":"MAYONNAISE DRSNG,NO CHOL -- 1 cup", "vitamin_e":11.79, "vitamin_b6":0.01, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.01, "fat_saturated":10.784, "weight1_gram":239.0, "folate_dfe":0.0, "choline":0.7, "sodium":486.0, "magnesium":1.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":7.0, "ndb_no":43598, "folate_total":0.0, "lutein_zeaxanthin":24.7, "iron":0.23, "id":6141, "energy_in_kcal":688.0, "fat_mono_unsaturated":18.026, "description":"MAYONNAISE DRSNG,NO CHOL", "refuse_percent":0.0, "food_folate":0.0, "manganese":-1.0, "zinc":0.13, "riboflavin":0.06, "copper":0.0}, "5534": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":90.0, "pantothenic_acid":0.362, "phosphorus":169.0, "beta_crytoxanthin":0.0, "thiamin":0.08, "selenium":24.3, "vitamin_k":0.2, "alpha_carotene":0.0, "carbohydrate":2.57, "sugar":0.0, "vitamin_b12":49.44, "cholesterol":34.0, "retinol":90.0, "potassium":314.0, "fat_poly_unsaturated":0.282, "lipid_total":0.97, "prompt": "CLAM,MIXED SPECIES,RAW -- 1 cup, (with liquid and clams)", "vitamin_e":0.31, "vitamin_b6":0.06, "fiber":0.0, "vitamin_c":13.0, "protein":12.77, "vitamin_a":300.0, "niacin":1.765, "fat_saturated":0.094, "weight1_gram":227.0, "folate_dfe":16.0, "choline":65.0, "sodium":56.0, "magnesium":9.0, "folic_acid":0.0, "weight1_description":"1 cup, (with liquid and clams)", "calcium":46.0, "ndb_no":15157, "folate_total":16.0, "lutein_zeaxanthin":0.2, "iron":13.98, "id":5534, "energy_in_kcal":74.0, "fat_mono_unsaturated":0.08, "description":"CLAM,MIXED SPECIES,RAW", "refuse_percent":0.0, "food_folate":16.0, "manganese":0.5, "zinc":1.37, "riboflavin":0.213, "copper":0.344}, "1662": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":22.0, "pantothenic_acid":0.246, "phosphorus":24.0, "beta_crytoxanthin":283.0, "thiamin":0.021, "selenium":0.4, "vitamin_k":29.3, "alpha_carotene":0.0, "carbohydrate":2.97, "sugar":1.83, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":260.0, "fat_poly_unsaturated":0.079, "lipid_total":0.17, "prompt":"CELERY,RAW -- 1 cup, chopped", "vitamin_e":0.27, "vitamin_b6":0.074, "fiber":1.6, "vitamin_c":3.1, "protein":0.69, "vitamin_a":449.0, "niacin":0.32, "fat_saturated":0.042, "weight1_gram":101.4, "folate_dfe":36.0, "choline":6.1, "sodium":80.0, "magnesium":11.0, "folic_acid":0.0, "weight1_description":"1 cup, chopped", "calcium":40.0, "ndb_no":11143, "folate_total":36.0, "lutein_zeaxanthin":29.3, "iron":0.2, "id":1662, "energy_in_kcal":16.0, "fat_mono_unsaturated":0.032, "description":"CELERY,RAW", "refuse_percent":11.0, "food_folate":36.0, "manganese":0.103, "zinc":0.13, "riboflavin":0.057, "copper":0.035}, "4766": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.616, "phosphorus":126.0, "beta_crytoxanthin":13.0, "thiamin":0.427, "selenium":29.7, "vitamin_k":0.5, "alpha_carotene":0.0, "carbohydrate":61.93, "sugar":3.59, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":140.0, "fat_poly_unsaturated":0.83, "lipid_total":2.14, "prompt": "BREAD, FRENCH OR VIENNA, TSTD (IND SOURDOUGH) -- 1 slice, small", "vitamin_e":0.19, "vitamin_b6":0.096, "fiber":3.1, "vitamin_c":0.2, "protein":13.0, "vitamin_a":0.0, "niacin":5.38, "fat_saturated":0.502, "weight1_gram":29.0, "folate_dfe":217.0, "choline":17.5, "sodium":720.0, "magnesium":31.0, "folic_acid":111.0, "weight1_description":"1 slice, small", "calcium":47.0, "ndb_no":18030, "folate_total":140.0, "lutein_zeaxanthin":0.5, "iron":3.87, "id":4766, "energy_in_kcal":319.0, "fat_mono_unsaturated":0.386, "description":"BREAD, FRENCH OR VIENNA, TSTD (IND SOURDOUGH)", "refuse_percent":0.0, "food_folate":29.0, "manganese":0.573, "zinc":1.05, "riboflavin":0.37, "copper":0.15}, "926": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":0.5, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":0.0, "fat_poly_unsaturated":1.8, "lipid_total":100.0, "prompt":"VEGETABLE OIL,COCONUT -- 1 tbsp", "vitamin_e":0.09, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":86.5, "weight1_gram":13.6, "folate_dfe":0.0, "choline":0.3, "sodium":0.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tbsp", "calcium":0.0, "ndb_no":4047, "folate_total":0.0, "lutein_zeaxanthin":0.5, "iron":0.04, "id":926, "energy_in_kcal":862.0, "fat_mono_unsaturated":5.8, "description":"VEGETABLE OIL,COCONUT", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}, "1982": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":3.0, "pantothenic_acid":0.334, "phosphorus":22.0, "beta_crytoxanthin":22.0, "thiamin":0.031, "selenium":1.0, "vitamin_k":0.5, "alpha_carotene":0.0, "carbohydrate":22.84, "sugar":12.23, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":358.0, "fat_poly_unsaturated":0.073, "lipid_total":0.33, "prompt":"BANANAS,RAW -- 1 cup, mashed", "vitamin_e":0.1, "vitamin_b6":0.367, "fiber":2.6, "vitamin_c":8.7, "protein":1.09, "vitamin_a":64.0, "niacin":0.665, "fat_saturated":0.112, "weight1_gram":225.0, "folate_dfe":20.0, "choline":9.8, "sodium":1.0, "magnesium":27.0, "folic_acid":0.0, "weight1_description":"1 cup, mashed", "calcium":5.0, "ndb_no":9040, "folate_total":20.0, "lutein_zeaxanthin":0.5, "iron":0.26, "id":1982, "energy_in_kcal":89.0, "fat_mono_unsaturated":0.032, "description":"BANANAS,RAW", "refuse_percent":36.0, "food_folate":20.0, "manganese":0.27, "zinc":0.15, "riboflavin":0.073, "copper":0.078}, "3006": {"beta_carotene":-1.0, "lycopene":2.53, "vitamin_a_rae":5.0, "pantothenic_acid":0.737, "phosphorus":263.0, "beta_crytoxanthin":-1.0, "thiamin":0.473, "selenium":6.0, "vitamin_k":62.0, "alpha_carotene":-1.0, "carbohydrate":13.01, "sugar":3.97, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":392.0, "fat_poly_unsaturated":23.584, "lipid_total":75.23, "prompt":"PECANS,OIL RSTD,WO\/SALT -- 1 cup", "vitamin_e":2.53, "vitamin_b6":0.187, "fiber":9.5, "vitamin_c":0.7, "protein":9.2, "vitamin_a":104.0, "niacin":1.2, "fat_saturated":7.238, "weight1_gram":110.0, "folate_dfe":15.0, "choline":-1.0, "sodium":1.0, "magnesium":121.0, "folic_acid":0.0, "weight1_description":"1 cup", "calcium":67.0, "ndb_no":12144, "folate_total":15.0, "lutein_zeaxanthin":-1.0, "iron":2.47, "id":3006, "energy_in_kcal":715.0, "fat_mono_unsaturated":40.97, "description":"PECANS,OIL RSTD,WO\/SALT", "refuse_percent":0.0, "food_folate":15.0, "manganese":3.7, "zinc":4.47, "riboflavin":0.11, "copper":1.2}, "1087": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":17.0, "pantothenic_acid":0.545, "phosphorus":205.0, "beta_crytoxanthin":0.0, "thiamin":0.074, "selenium":33.2, "vitamin_k":0.0, "alpha_carotene":0.0, "carbohydrate":3.34, "sugar":2.04, "vitamin_b12":0.4, "cholesterol":126.0, "retinol":17.0, "potassium":190.0, "fat_poly_unsaturated":2.359, "lipid_total":12.67, "prompt":"CHICKEN,WING,FRZ,GLAZED,BARBECUE FLAV -- 1 piece", "vitamin_e":0.36, "vitamin_b6":0.142, "fiber":0.6, "vitamin_c":0.0, "protein":19.67, "vitamin_a":58.0, "niacin":5.5, "fat_saturated":3.321, "weight1_gram":29.33, "folate_dfe":10.0, "choline":-1.0, "sodium":615.0, "magnesium":20.0, "folic_acid":0.0, "weight1_description":"1 piece", "calcium":28.0, "ndb_no":5312, "folate_total":10.0, "lutein_zeaxanthin":-1.0, "iron":2.41, "id":1087, "energy_in_kcal":211.0, "fat_mono_unsaturated":5.766, "description":"CHICKEN,WING,FRZ,GLAZED,BARBECUE FLAV", "refuse_percent":33.0, "food_folate":10.0, "manganese":0.0, "zinc":1.14, "riboflavin":0.242, "copper":0.039}, "927": {"beta_carotene":0.0, "lycopene":0.0, "vitamin_a_rae":0.0, "pantothenic_acid":0.0, "phosphorus":0.0, "beta_crytoxanthin":0.0, "thiamin":0.0, "selenium":0.0, "vitamin_k":60.2, "alpha_carotene":0.0, "carbohydrate":0.0, "sugar":0.0, "vitamin_b12":0.0, "cholesterol":0.0, "retinol":0.0, "potassium":1.0, "fat_poly_unsaturated":10.523, "lipid_total":100.0, "prompt":"OIL,OLIVE,SALAD OR COOKING -- 1 tablespoon", "vitamin_e":14.35, "vitamin_b6":0.0, "fiber":0.0, "vitamin_c":0.0, "protein":0.0, "vitamin_a":0.0, "niacin":0.0, "fat_saturated":13.808, "weight1_gram":13.5, "folate_dfe":0.0, "choline":0.3, "sodium":2.0, "magnesium":0.0, "folic_acid":0.0, "weight1_description":"1 tablespoon", "calcium":1.0, "ndb_no":4053, "folate_total":0.0, "lutein_zeaxanthin":60.2, "iron":0.56, "id":927, "energy_in_kcal":884.0, "fat_mono_unsaturated":72.961, "description":"OIL,OLIVE,SALAD OR COOKING", "refuse_percent":0.0, "food_folate":0.0, "manganese":0.0, "zinc":0.0, "riboflavin":0.0, "copper":0.0}} ================================================ FILE: cooking_recipes/data/meat.json ================================================ [ {"name":"Fried Chicken", "num_served":3, "ingredients": [{"name":"chicken (whole fryer)", "amount":"1", "units":"", "description":"Frying chickens"}, {"name":"flour", "amount":"1/4", "units":"cup", "description":"Flour"}, {"name":"salt", "amount":"1/2", "units":"teaspoon", "description":"Salt"}, {"name":"black pepper", "amount":"1/2", "units":"teaspoon", "description":"Pepper"}, {"name":"cayenne pepper", "amount":"1/2", "units":"teaspoon", "description":"Cayenne pepper"}, {"name":"butter", "amount":"4", "units":"tablespoon", "description":"Butter"}, {"name":"vegetable oil", "amount":"8", "units":"tablespoon", "description":"Vegetable oil"}], "directions": ["Mix flour, salt and pepper in bag, add chicken and shake.", "Heat oil in a large skillet on high. Brown chicken on skin side.", "Turn over the chicken, reducing the heat to medium and brown other side.", "Turn over and cook over lower heat until the chicken is tender when stuck with a fork.", "Drain off oil and serve."]}, {"name":"Chicken Schnitzel", "num_served":6, "ingredients": [{"name":"chicken breast", "amount":"2", "units":"pounds", "description":"Chicken Breasts"}, {"name":"egg", "amount":"4", "units":"unit", "description":"Eggs"}, {"name":"flour", "amount":"1.5", "units":"cup", "description":"Flour"}, {"name":"bread crumbs", "amount":"1", "units":"cup", "description":"Bread Crumbs"}, {"name":"vegetable oil", "amount":"5", "units":"tablespoon", "description":"Vegetable oil"}], "directions": ["Slice Chicken Breasts 2 parts so each piece is as large an area and thin as possible.", "Remove skin and any excess fat.", "Optional: place on a cutting board and pound flatter.", "Dip chicken in beaten eggs, roll in flour, then in bread crumbs.", "Heat oil in a (preferably nonstick) frying pan.", "Fry the Schnitzel on each side until golden brown and the chicken is done (cut into chicken to make sure it is cooked)."]}, { "name": "Barbecued Chicken", "num_served":2, "ingredients": [ { "name": "chicken breast", "amount": "2", "units": "unit", "description": "Boneless chicken breasts" }, { "name": "soy sauce", "amount": "2", "units": "tablespoon", "description": "Soy sauce" }, { "name": "white wine", "amount": "2", "units": "tablespoon", "description": "White wine" }, { "name": "vegetable oil", "amount": "1", "units": "tablespoon", "description": "Vegetable oil" }, { "name": "cornstarch", "amount": "1", "units": "tablespoon", "description": "Cornstarch" } ], "pictures": [ ["barbecue_chicken", "       Prepared Barbequed Chicken
       (photo by Joe Foodie CC BY 2.0)"] ], "directions": ["Mix together all of the sauce ingredients and pour half the sauce over chicken, coating the chicken on all sides.", "Let this stand for a while and then put the chicken on your barbeque (charcoal or gas grill works fine).", "Brush the sauce over the top of the chicken and grill for about 10 minutes, then turn over and apply more barbeque sauce on the top", "Be careful to not burn the chicken. Before removing from the grill, cut into a thick piece and make sure it is done."] }, { "name": "Brined Barbecued Chicken", "num_served":2, "ingredients": [ { "name": "chicken breast", "amount": "2", "units": "unit", "description": "Boneless chicken breasts" }, { "name": "soy sauce", "amount": "4", "units": "tablespoon", "description": "Soy sauce" }, { "name": "white wine", "amount": "4", "units": "tablespoon", "description": "White wine" }, { "name": "vegetable oil", "amount": "2", "units": "tablespoon", "description": "Vegetable oil" }, { "name": "cornstarch", "amount": "2", "units": "tablespoon", "description": "Cornstarch" } ], "directions": ["Mix together all of the sauce ingredients. Put half the sauce in a large pan of cold water, add two additional tablespoons of salt, and stir. Add the chicken and store in the refrigerator overnight.", "Before barbequeing, remove the chicken from the brine solution and pour half of the sauce (made the day before) over chicken, coating the chicken on all sides.", "Put the chicken on your barbeque (charcoal or gas grill works fine).", "Brush the sauce over the top of the chicken and grill for about 10 minutes, then turn over and apply more barbeque sauce on the top", "Be careful to not burn the chicken. Before removing from the grill, cut into a thick piece and make sure it is done.", "NOTE: it is important to use cold water for brining and immediately refrigerate the brine after adding the chicken."] }, {"name":"Barbecued Salmon with Basil", "num_served":4, "ingredients": [{"name":"salmon (small fillet or steak)", "amount":"4", "units":"unit", "description": "Salmon steaks"}, {"name":"olive oil", "amount":"2", "units":"tablespoon", "description":"Olive oil"}, {"name":"dried basil", "amount":"1", "units":"teaspoon", "description":"Dried and crushed basil"}, {"name":"lemon", "amount":"1", "units":"", "description":"Lemon wedges"}], "pictures": [ ["barbequed_salmon", "       Barbequed Salmon
       (photo by Jon Sullivan public domain)"] ], "directions": ["Mix the juice from half the lemon, olive oil and basil and thoroughly coat the salmon with this mixture.", "Cook the salmon over hot coals (or a gas grill) for about 5 minutes per side.", "Remove fish from barbeque and test for doneness. Serve with the remaining half lemon cut into thin wedges."]}, {"name":"Spicy Braised Chicken", "num_served":4, "ingredients": [{"name":"red pepper flakes", "amount":"1", "units":"teaspoon", "description":"Red peppers"}, {"name":"vegetable oil", "amount":"1", "units":"tablespoon", "description":"Oil"}, {"name":"salt", "amount":"1", "units":"teaspoon", "description":"Salt"}, {"name":"chicken (boneless)", "amount":"1", "units":"pound", "description":"Chicken meat"}, {"name":"fresh ginger (minced)", "amount":"1", "units":"tablespoon", "description":"Fresh ginger"}, {"name":"brown sugar", "amount":"1", "units":"tablespoon", "description":"Brown sugar"}, {"name":"sherry", "amount":"2", "units":"teaspoon", "description":"Sherry"}, {"name":"cornstarch", "amount":"1", "units":"teaspoon", "description":"Cornstarch"}, {"name":"soy sauce", "amount":"2", "units":"teaspoon", "description":"Soy sauce"}], "directions": ["Using a small bowl, mix the cornstarch to a smooth paste with the soy sauce and set aside.", "Cut up the chicken into small bite-size pieces. Over medium high heat add oil and fry the chicken and minced fresh ginger for 1 minute.", "Add in the mixed cornstarch and soy sauce and cook for another minute, stiring often.", "Add the sugar and sherry and cook for another minute.", "Test the chicken for doneness and then serve."]} , {"name":"Crock Pot Lemon Honey Chicken", "num_served":4, "ingredients": [{"name":"chicken", "amount":"1", "units":"", "description":"Roaster Chicken"}, { "name": "water", "amount": "1/2", "units": "cup", "description": "Water" }, {"name":"lemon", "amount":"2", "units":"", "description":"Lemon"}, {"name":"salt", "amount":"1/2", "units":"teaspoon", "description":"Salt"}, {"name":"black pepper", "amount":"1/2", "units":"teaspoon", "description":"Pepper"}, {"name":"honey", "amount":"1/4", "units":"cup", "description":"Honey"}], "directions": ["Wash the Chicken and trim off excess fat.", "Put the washed chicken in a crock pot and squeeze the juice from one lemon over the chicken.", "Then sprinkle the salt and pepper over the chicken, and finally pour the honey over the chicken.", "Cook the chicken on low heat until done. After serving the chicken, squeeze some juice from the second lemon over each portion."]}, {"name":"Chicken Cacciatore", "num_served":4, "ingredients": [{"name":"chicken breast", "amount":"2", "units":"", "description":"Pieces chicken"}, {"name":"tomatoes", "amount":"2", "units":"", "description":"Crushed tomatoes"}, {"name":"brown sugar", "amount":"2", "units":"teaspoon", "description":"Sugar"}, {"name":"salt", "amount":"2", "units":"teaspoon", "description":"Salt"}, {"name":"black pepper", "amount":"1", "units":"teaspoon", "description":"Pepper"}, {"name":"butter", "amount":"1", "units":"teaspoon", "description":"Butter"}, {"name":"vegetable oil", "amount":"2", "units":"tablespoon", "description":"Oil"}, {"name":"dry rosemary", "amount":"1", "units":"teaspoon", "description":"Rosemary"}], "directions": ["Wash the chicken and cook it for 5 minutes a side with butter, oil, and rosemary in a large skillet under medium heat.", "Then cut up the tomatoes and mix in with the cooking chicken chicken. Add the basil, sage, rosemary and parsley, sugar, salt, and pepper.", "Cover and cook on low to medium heat for about two hours. Check chicken for doneness before serving"]}, {"name":"Chicken with Cream of Mushroom Soup", "num_served":2, "ingredients": [{"name":"chicken breast", "amount":"2", "units":"", "description":"Pieces chicken"}, {"name":"vegetable oil", "amount":"1", "units":"tablespoon", "description":"Oil"}, {"name":"sour cream", "amount":"1/2", "units":"cup", "description":"Pint sour cream"}, {"name":"salt", "amount":"1/2", "units":"teaspoon", "description":"Salt"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Pepper"}, {"name":"canned soup (cream of mushroom)", "amount":"1", "units":"can", "description":"Cream of mushroom soup (I use Campbell's)"}], "directions": ["Heat oil in a non-stick frying pan with medium heat. Lightly brown the chicken, about minutes per side.", "Mix in the salt, pepper, and soup, then cover, and cook under low heat for about 30 minutes, stirring occasionally.", "Mix in the sour cream, cook for another 5 minutes. Make sure the chicken is done and tender before serving."]}, {"name":"Simple Italian Chicken", "num_served":4, "ingredients": [{"name":"chicken breast (skinless)", "amount":"2", "units":"lb", "description":"Skinned chicken breasts"}, {"name":"olive oil", "amount":"2", "units":"tablespoon", "description":"Olive oil"}, {"name":"lemon juice", "amount":"2", "units":"tablespoon", "description":"Lemon juice"}, {"name":"fresh garlic (peeled and finely chopped)", "amount":"2", "units":"", "description":"Cloves garlic,crushed"}, {"name":"dried oregano", "amount":"1/2", "units":"teaspoon", "description":"Oregano"}, {"name":"white wine", "amount":"4", "units":"tablespoon", "description":"Dry white wine"}], "directions": ["Preheat oven to 375F. Grease a deep baking pan with half of the olive oil.", "Mix all remaining ingredients except the chicken in the baking dish and stir together.", "Wash the chicken and place in the baking dish, rolling the chicken to coat it with the mixture.", "Cover the baking dish and cook for 45 minutes. Optional: uncover the baking dish the last 15 minutes.", "Test the chicken for doneness and tenderness before serving."]}, {"name":"Curried Chicken Legs", "num_served":8, "ingredients": [{"name":"chicken legs", "amount":"8", "units":"", "description":"Chicken legs"}, {"name":"curry powder", "amount":"4", "units":"teaspoon", "description":"Curry powder"}, {"name":"fresh garlic (peeled and finely chopped)", "amount":"1", "units":"", "description":"Cloves garlic,crushed"}, {"name":"vegetable oil", "amount":"2", "units":"tablespoon", "description":"Oil"}, {"name":"yogurt", "amount":"1/2", "units":"cup", "description":"Plain yogurt"}, {"name":"lemon juice", "amount":"3", "units":"tablespoon", "description":"Lemon juice"}, {"name":"brown sugar", "amount":"2", "units":"teaspoon", "description":"Packed brown sugar"}], "directions": ["Preheat oven to 400F.", "Cut at joint into thighs and drumsticks. You can also but just thighs or the drumbsticks as to your prefenerence, adjusted the recipe.", "Trim any hanging fat and excess skin from chicken.", "Heat half of the oil in a small non-stick pan and slowly add in the curry powder, mixing well. Then immediately add the peeled and finely chopped garlic. Cook over medium heat for a few minutes until the garlic softens.", "Put the contents of the pan into a large bowl, then mixing in yogurt, lemon juice and brownsugar.", "Add chicken, rolling it around to thoroughly coat. Let this then sit at room temperature for at least 10 minutes.", "Line a baking sheet with aluminum foil (always with the shiny side up) and use the remaining half of the oil to greese the foil.", "Put the chicken on the sheet skin side down and cover the chcken with the remaining sauce from the large bowl.", "Bake for about 40 minutes. Check chicken for doneness before serving with either rice or pita bread.", "Optional: serve with Chutney sauce, yogurt, and/or sour cream.", "Pro tip: make enough for leftovers for lunch the next day!"]}, {"name":"Poached Salmon with Wine and Lemon", "num_served":4, "ingredients": [{"name":"lemon juice", "amount":"1/4", "units":"cup", "description":"Lemon juice"}, {"name":"white wine", "amount":"1/4", "units":"cup", "description":"Dry white wine"}, {"name":"salmon (small fillets or steaks)", "amount":"4", "units":"", "description":"Salmon fillets"}, {"name":"salt", "amount":"1/4", "units":"teaspoon", "description":"Salt"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Pepper"}, { "name": "water", "amount": "1/4", "units": "cup", "description": "Water" } ], "directions": ["Use a heavy frying pan with a cover or small dutch oven to make this.", "Over medium heat bring the lemon juice and wine to a boil, adding in the salt and pepper, then water.", "Add salmon 'bad looking side' down and cover the pan.", "Poach salmon for 7 or 8 minutes. The fish should easily flake when it is done. Remove from the pan and eat immediately."]}, {"name":"Honey-Curried Chicken", "num_served":6, "ingredients": [{"name":"chicken breast", "amount":"2", "units":"pound", "description":"Chicken breasts"}, {"name":"vegetable oil", "amount":"2", "units":"teaspoon", "description":"Vegetable oil"}, {"name":"orange juice", "amount":"1/4", "units":"cup", "description":"Orange juice"}, {"name":"honey", "amount":"1/4", "units":"cup", "description":"Honey"}, {"name":"dijon mustard", "amount":"1", "units":"tablespoon", "description":"Dijon mustard"}, {"name":"curry powder", "amount":"2", "units":"teaspoon", "description":"Curry powder pinch cayenne pepper"}, {"name":"cayenne pepper", "amount":"1/4", "units":"teaspoon", "description":"cayenne pepper"}], "directions": ["preheat oven to 400F", "Grease a baking dish vegetable oil. Remove skin from chicken.", "Arrange chicken in a single layer bone side down if you are not using boneless chicken breasts.", "Mix the remaining ingredients in a small bowl and pour 2/3 over the chicken.", "Bake chicken covered for 10 minutes (15 minutes if bones in chicken breasts), basting once. Turn chicken over and baste with the remaining sauce.", "Bake, now uncovered, for 15 minutes (20 minutes if bones in chicken breasts) longer. Test chicken for doneness and tenderness before serving."]}, {"name":"Spicy Barbecued Chicken", "num_served":4, "ingredients": [{"name":"chicken (whole fryer)", "amount":"1", "units":"", "description":"chicken (2 lb)"}, {"name":"lemon", "amount":"1", "units":"", "description":"Juice of 1 lemon"}, {"name":"fresh garlic", "amount":"2", "units":"", "description":"Cloves garlic"}, {"name":"black pepper", "amount":"2", "units":"teaspoon", "description":"Fresh ground black pepper"}, {"name":"salt", "amount":"1", "units":"teaspoon", "description":"Salt"}, {"name":"cayenne pepper", "amount":"2", "units":"teaspoon", "description":"Ground cayenne pepper"}, {"name":"paprika", "amount":"1", "units":"teaspoon", "description":"Paprika"}, {"name":"butter (melted)", "amount":"2", "units":"tablespoon", "description":"Melted butter"}], "directions": ["Cut as much extra fat and loose skin as you can from the chicken. Later when you are grilling it this will help to minimize grease flames burning the chicken.", "Split the chicken by cutting down the backbone and opening it to leave the breast attached - flatten out as much as possible while still keeping the chicken in one piece.", "Squeeze the juice from the lemon on to the chicken. Mix together the cayenne pepper, black pepper, salt, peeled and crushed garlic, paprika and add to the melted butter; pur and rub this mixture over the chicken.", "Refrigerate the chicken (it can be uncovered) for at least an hour or two to let the spices set.", "Prepare a gas grill or charcoal grill. For a gas grill heat it to medium temperature. For a charcoal grill, use a modest amount of charcoal to avoid too high of cooking heat. Put the chicken breast side up onto the grill and cover the grill with the lid.", "Cook chicken for 30 minutes without turning it. Turn the chicken and cook uncovered for about another 5 to 10 minutes to crisp up the skin.", "Remove the chicken from the grill, cut into a thick area (thigh or breast) to make sure it is done, let it cool for 5 minutes and then serve.", "Note: if you substitute chicken parts like legs or breasts then the cooking time will be reduced; keep an eye on the chicken and test for doneness before serving."]}, {"name":"Indonesian Chicken Sate", "num_served":4, "ingredients": [{"name":"chicken breast (half breasts, bones and skin removed)", "amount":"4", "units":"", "description": "Skinless, boneless chicken breast halves (about 1 1/2 pounds)"}, {"name":"soy sauce", "amount":"1/4", "units":"cup", "description":"Reduced-sodium soy sauce"}, {"name":"lemon", "amount":"1", "units":"", "description":"Fresh lemon juice"}, {"name":"molasses", "amount":"1", "units":"tablespoon", "description":"Dark molasses"}, {"name":"red pepper flakes", "amount":"1", "units":"teaspoon", "description":"Red Pepper Flakes"}, {"name":"fresh garlic (peeled and very finely chopped)", "amount":"1", "units":"tablespoon", "description":"Garlic Powder Granules"}, {"name":"fresh ginger", "amount":"1", "units":"tablespoon", "description":"Ginger"}], "directions": ["Cut breasts into long 1 inch strips. Put the chicken and all of the other ingredients into a large bowl and mix well making sure the chicken is well coated. Cover the bowl and refrigerate for two hours or longer. Stir up the bowl a few times while the chicken is marinating.", "You can use either a (gas or charcoal) grill or the broiler in your oven to cook the Sate.", "Optional: skewer the chicken strips on wet bamboo skewers - or you can cook the chicken loose if you don't have skewers.", "Broil or grill about 4 minutes on each side, occasionally applying more marinade.", "Optional: if you have any available, serve with Indonesian or Thai peanut sauce, or chutney."]} ] ================================================ FILE: cooking_recipes/data/misc.json ================================================ [ { "name": "Whole Wheat Bread", "num_served":10, "ingredients": [ { "name": "water", "amount": "1 1/2", "units": "cup", "description": "Water" }, { "name": "vegetable oil", "amount": "1 1/3", "units": "tablespoon", "description": "Vegetable oil" }, { "name": "honey", "amount": "1/4", "units": "cup", "description": "Honey" }, { "name": "salt", "amount": "1/2", "units": "teaspoon", "description": "Salt" }, { "name": "whole wheat flour", "amount": "4", "units": "cup", "description": "Whole wheat bread flour" }, { "name": "yeast", "amount": "3", "units": "teaspoon", "description": "Yeast" } ], "directions": [ "Lightly grease two 9x5 inch loaf pans.", "Blend all ingredients and then place on a large floured surface and knead for 5 or 6 minutes.", "Place in a covered bowl in a warm area and let it rise for about one hour.", "Preheat oven to 375F. Bake for 35 to 40 minutes."] }, { "name": "Homemade Salad Dressing", "num_served":16, "ingredients": [ { "name": "salt", "amount": "1", "units": "teaspoon", "description": "Salt" }, { "name": "black pepper", "amount": "1/4", "units": "teaspoon", "description": "Black Pepper" }, { "name": "paprika", "amount": "1/2", "units": "teaspoon", "description": "Paprika" }, { "name": "dry mustard", "amount": "1", "units": "pinch", "description": "Dry Mustard" }, { "name": "brown sugar", "amount": "1", "units": "teaspoon", "description": "Sugar" }, { "name": "olive oil", "amount": "1/2", "units": "cup", "description": "Olive Oil" }, { "name": "red wine vinegar", "amount": "1/4", "units": "cup", "description": "Wine Vinegar" }, { "name": "fresh garlic ", "amount": "2", "units": "clove", "description": "Clove Garlic" } ], "directions": [ "Dissolve sugar, salt, pepper, paprika, and dry mustard in olive oil.", "Stir in vinegar. Peel and mince garlic and and add to dressing."] }, { "name": "Aioli Sauce", "num_served":8, "ingredients": [ { "name": "egg yolks", "amount": "3", "units": "unit", "description": "Egg yolks" }, { "name": "fresh garlic", "amount": "4", "units": "clove", "description": "Cloves garlic" }, { "name": "lemon juice", "amount": "1", "units": "tablespoon", "description": "Lemon juice" }, { "name": "salt", "amount": "1/3", "units": "teaspoon", "description": "Salt" }, { "name": "tabasco sauce", "amount": "1/4", "units": "teaspoon", "description": "Tabasco" }, { "name": "worcestershire sauce", "amount": "1/4", "units": "teaspoon", "description": "Worcestershire sauce" }, { "name": "black pepper", "amount": "1/4", "units": "teaspoon", "description": "Freshly ground black pepper" }, { "name": "mayonnaise", "amount": "1/4", "units": "cup", "description": "Mayonnaise" }, { "name": "olive oil", "amount": "3/4", "units": "cup", "description": "Extra virgin olive oil" }, { "name": "water (boiling)", "amount": "3", "units": "tablespoon", "description": "Boiling water" } ], "pictures": [ ["aioli_sauce", "       Prepared Aioli Sauce
       (photo by Ralph Sperling public domain)"] ], "directions": ["Blend together the egg yolks, garlic, lemon, salt and pepper in a blender or food processor for about 2 minutes.", "Very slowly add the oil and mayonnaise while continuing to blend the mixture.", "Add the seasonings and mix together. Add the boiling water, stir well, and refrigerate for later use."] }, { "name": "Indonesian Barbecue Sauce", "num_served":12, "ingredients": [ { "name": "corn syrup", "amount": "1/2", "units": "cup", "description": "Corn syrup (dark)" }, { "name": "peanut butter", "amount": "1/4", "units": "cup", "description": "Creamy peanut butter" }, { "name": "soy sauce", "amount": "1/4", "units": "cup", "description": "Soy sauce" }, { "name": "vinegar", "amount": "1/4", "units": "cup", "description": "Cider vinegar" }, { "name": "green onions", "amount": "1/4", "units": "cup", "description": "Sliced green onions" }, { "name": "fresh garlic (peeled and minced)", "amount": "4", "units": "clove", "description": "garlic" }, { "name": "cloves (ground)", "amount": "1", "units": "teaspoon", "description": "Clove " }, { "name": "fresh ginger (peeled and minced)", "amount": "2", "units": "teaspoon", "description": "Ginger" }, { "name": "red pepper flakes", "amount": "1", "units": "teaspoon", "description": "Crushed dried red pepper" } ], "directions": ["Mix together all ingredients and let sit for at least one hour before using.", "Refrigerate or freeze any unused barbecue sauce for future use."] }, {"name":"Basil Vinaigrette Salad Dressing", "num_served":12, "ingredients": [{"name":"balsamic vinegar", "amount":"1/4", "units":"cup", "description":"balsamic vinegar"}, {"name":"dried basil", "amount":"1/4", "units":"teaspoon", "description":"dried basil (or 1/2 tsp fresh)"}, {"name":"dried oregano", "amount":"1/4", "units":"teaspoon", "description":"Dried oregano (or 1/2 tsp fresh)"}, { "name": "olive oil", "amount": "1", "units": "tablespoon", "description": "Olive Oil" } ], "directions": ["Mix all ingredients in a bowl. Let sit at least 2 or 3 minutes before using on a salad.", "Refrigerate extra dressing for future use."]}, {"name":"Black Bean Dip", "num_served":6, "ingredients": [{"name":"black beans (cooked or canned)", "amount":"2", "units":"cup", "description":"Refried Black Beans (see rec.)"}, {"name":"sour cream", "amount":"1/4", "units":"cup", "description":"Sour cream"}, {"name":"cumin", "amount":"1", "units":"teaspoon", "description":"Ground cumin"}, {"name":"salsa", "amount":"1/2", "units":"cup", "description":"Salsa"}], "directions": ["Use either a food processor or a mixing bowl and hand mixer to make this appetizer.", "Blend the black beans and cumin for at least one minute until the mixture is fairly smooth.", "Stir in salsa and sour cream and lightly mix. Serve immediately or store in the refrigerator."]}, {"name":"Borscht", "num_served":4, "ingredients": [{"name":"beets (raw and sliced)", "amount":"2", "units":"cup", "description":"Beets"}, {"name":"brown onions", "amount":"1", "units":"", "description":"Onion"}, {"name":"fresh garlic", "amount":"2", "units":"clove", "description":"Garlic clove"}, {"name":"water", "amount":"2", "units":"quart", "description":"Water"}, {"name":"salt", "amount":"2", "units":"teaspoon", "description":"Salt"}, {"name":"brown sugar", "amount":"3", "units":"tablespoon", "description":"Sugar"}, {"name":"lemon juice", "amount":"1/4", "units":"cup", "description":"Lemon juice"}], "directions": ["Wash and peel beets and thickly slice so they cook faster. Peel the onion and garlic cloves. Leave the onion and garlic cloves whole since we will be removing them later.", "Mix everything except the lemon juice and sugar in a large covered pot and cook over low heat for one hour.", "Add the sugar and lemon juice. Cook an additional thirty minutes, remove from heat and let cool. Discard the onion and garlic and use a hand mixer to blend into a cold soup.", "Optional: place a small spoonful of sour cream on top of each serving."]}, {"name":"Curried Yogurt Dip", "num_served":6, "ingredients": [{"name":"yogurt (plain)", "amount":"1", "units":"cup", "description":"Plain Yogurt"}, {"name":"curry powder", "amount":"1.5", "units":"teaspoon", "description":"Curry powder"}, {"name":"sriracha hot chili sauce", "amount":"1/2", "units":"teaspoon", "description":"Hot pepper sauce"}, {"name":"lemon juice", "amount":"1", "units":"teaspoon", "description":"Lemon juice"}, {"name":"honey", "amount":"1/2", "units":"teaspoon", "description":"Honey"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Black pepper"}, {"name":"salt", "amount":"1/4", "units":"teaspoon", "description":"Salt"}, {"name":"almonds", "amount":"3", "units":"tablespoon", "description":"almonds"}], "directions": ["Combine ingredients (except almonds!) stirring well.", "Divide into four small serving bowls. Set aside for about 15 minutes at room temperature before serving.", "Then, finely chop almonds are sprinkle on top of the yogurt dip.", "Place the small bowls containing the dip on larger plates with cut up fresh vegetables and/or chips."]}, {"name":"Dijon Sour Cream Dip", "num_served":6, "ingredients": [{"name":"sour cream", "amount":"1", "units":"cup", "description":"Sour cream OR Plain yogurt"}, {"name":"mayonnaise", "amount":"1/3", "units":"cup", "description":"Mayonnaise"}, {"name":"dijon mustard", "amount":"1/4", "units":"cup", "description":"Dijon mustard"}, {"name":"green onions", "amount":"1", "units":"tablespoon", "description":"Finely-chopped green onion"}, {"name":"salt", "amount":"0.25", "units":"teaspoon", "description":"Seasoned salt"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Black pepper"}], "directions": ["Mix all ingredients, cover and store in the refrigerator for at least 30 minutes before serving.", "Serve dip into small bowls containing and place on larger plates with cut up fresh vegetables and/or chips."]}, {"name":"Dijon Yogurt Dip", "num_served":6, "ingredients": [{"name":"yogurt", "amount":"1", "units":"cup", "description":"Sour cream OR Plain yogurt"}, {"name":"mayonnaise", "amount":"1/3", "units":"cup", "description":"Mayonnaise"}, {"name":"dijon mustard", "amount":"1/4", "units":"cup", "description":"Dijon mustard"}, {"name":"green onions", "amount":"2", "units":"tablespoon", "description":"Finely-chopped green onion"}, {"name":"salt", "amount":"0.5", "units":"teaspoon", "description":"Seasoned salt"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"Black pepper"}], "directions": ["Mix all ingredients, cover and store in the refrigerator for at least 30 minutes before serving.", "Serve dip into small bowls containing and place on larger plates with cut up fresh vegetables and/or chips."]}, {"name":"English Scones", "num_served":6, "ingredients": [{"name":"flour", "amount":"2.5", "units":"cup", "description":"Flour"}, {"name":"cream of tartar", "amount":"1", "units":"teaspoon", "description":"Cream of tartar"}, {"name":"baking soda", "amount":"1", "units":"teaspoon", "description":"Baking soda"}, {"name":"brown sugar", "amount":"3", "units":"tablespoon", "description":"Sugar"}, {"name":"salt", "amount":"1/2", "units":"teaspoon", "description": "Salt"}, {"name":"butter", "amount":"1/2", "units":"cup", "description":"Butter"}, {"name":"milk", "amount":"1", "units":"cup", "description":"Milk"}], "directions": ["Preheat oven to 400F.", "Mix flour, cream of tartar, baking soda, sugar, and salt together. Slowly mix in the butter and when all of the butter is mixed in the mix in the milk.", "Form into three round balls on floured board and then flatten. Partially cut through each of the three portions to make four pie-like portions.", "Bake for 15 minutes. Cool for a few minutes then serve immediateley."]}, {"name":"Tasty Black Bean Dip", "num_served":4, "ingredients": [{"name":"black beans", "amount":"1.5", "units":"cup", "description":"16-0z can black beans"}, {"name":"sweet red onions (finely chopped)", "amount":"2", "units":"tablespoon", "description":"Chopped red onion"}, {"name":"balsamic vinegar", "amount":"1", "units":"tablespoon", "description":"Balsamic vinegar"}, {"name":"fresh garlic (peeled and finely chopped)", "amount":"1", "units":"", "description":"Clove garlic"}, { "name": "olive oil", "amount": "1/2", "units": "cup", "description": "Olive Oil" } ], "directions": ["You can use canned black beans (each 12 ounce can is about 1 1/2 cups) or cook dry beans according to package directions and then cool.", "Combine ingredients in the blender or food processor and mix for about 1 minute to either a fine or course consistency depending on your tastes and preferences.", "I like to serve this in small individual bowls place on a larger plate so there is plenty of room on each plate for pita bread, chips, and/or cut up raw vegetables."]}, {"name":"Fresh Tomato Sauce", "num_served":4, "ingredients": [{"name":"tomatoes (medium size, diced)", "amount":"12", "units":"", "description":"Tomatoes"}, {"name":"brown sugar", "amount":"2", "units":"tablespoon", "description":"Sugar"}, {"name":"black pepper", "amount":"1", "units":"teaspoon", "description":"black pepper"}, {"name":"salt", "amount":"1", "units":"teaspoon", "description":"Salt"}, {"name":"fresh basil", "amount":"1", "units":"cup", "description":"Fresh basil"}], "directions": ["Place all ingredients in heavy saucepan or dutch oven and bring to a slow boil. Lower heat and cook covered for 40 minutes, stirring occasionally.", "I suggest using a small amount for a meal immediately (with cooked pasta) and freezing most of it for future meals.", "This is a great recipe to use up extra tomatoes from your garden or when tomatoes are in season and inexpensive to buy."]}, {"name":"Japanese Ginger Salad Dressing", "num_served":4, "ingredients": [{"name":"rice vinegar", "amount":"1", "units":"tablespoon", "description":"Rice vinegar"}, {"name":"vegetable oil", "amount":"2", "units":"teaspoon", "description":"Vegetable oil"}, {"name":"sesame oil", "amount":"1.5", "units":"tablespoon", "description":"Sesame oil"}, {"name":"fresh ginger (grated or very finely chopped)", "amount":"1", "units":"tablespoon", "description":"Grated fresh ginger"}, {"name":"soy sauce", "amount":"1", "units":"teaspoon", "description":"Soy sauce"}], "directions":["Mix all ingredients together and let sit for at least 10 minutes before using.", "Some of the ingredients will settle so make sure you stir well before pouring over salad."]}, {"name":"Quick Sweet and Sour Sauce", "num_served":8, "ingredients": [{"name":"white vinegar", "amount":"1", "units":"cup", "description":"White vinegar"}, {"name":"brown sugar", "amount":"2/3", "units":"cup", "description":"Sugar"}, {"name":"ketchup", "amount":"2", "units":"tablespoon", "description":"Ketchup"}, {"name":"fresh ginger (peeled and very finely chopped)", "amount":"2", "units":"tablespoon", "description":"fresh ginger"}, {"name":"salt", "amount":"1/4", "units":"teaspoon", "description": "Salt"}, {"name":"tabasco sauce", "amount":"1/4", "units":"teaspoon", "description":"Tabasco sauce"}], "directions": ["Use a medium size pan to combine the vinegar, sugar, ketchup, ginger, salt and tabasco sauce and bring to a boil under high heat.", "Cook until the sauce is reduced to a fairly thick sauce. You don't want the sauce to be runny but you also don't want it to be too thick. Pay attention while cooking the sauce!"]} ] ================================================ FILE: cooking_recipes/data/recipes.json ================================================ [ { "items": [ ["onions", ["2 ", "onion"], 2.0, "onion"], ["fresh garlic (peeled and finely sliced)", ["1 1/2", "tablespoons"], 0.09, "cup"], ["green pepper", ["1 ", "cup chopped"], 1.0, "cup chopped"], ["tomatoes", ["2 ", "cup chopped"], 2.0, "cup chopped"], ["salt", ["2 ", "teaspoons"], 0.04, "cup"], ["black pepper", ["1/3", "teaspoons"], 0.125, "tbsp"], ["Worcestershire Sauce", ["1 1/5", "tablespoons"], 0.075, "cup"], ["paprika", ["2 ", "teaspoons"], 0.6667, "tbsp"], ["red wine vinegar", ["1/3", "cup"], 0.33333, "cup"], ["water", ["12 ", "fl oz"], 12.0, "fl oz"], ["cucumber", ["1 ", "cup pared chopped"], 1.0, "cup pared chopped"], ["chives", ["1 ", "tbsp chopped"], 1.0, "tbsp chopped"], ["olive oil", ["5 ", "tablespoons"], 5.0, "tbsp"] ], "recipe": { "rating": 3.0, "name": "Gazpacho", "directions": "Combine the onions, garlic, green peppers and tomatoes. Force through a sieve or puree in a blender. Add the salt, pepper and paprika. Add the olive oil gradually, beating steadily. Add the vinegar and water and stir well. Season to taste. Refrigerate and chill for at least two hours, using a wooden or glass bowl; do not use a metal bowl. Add the cucumber slices before serving.\u003Cbr/\u003E\u003Cbr/\u003EIf desired, slices of toast rubbed with garlic may be served with the Gazpacho. ", "num_served": 4, "id": 1, "num_ratings": 2 } }, { "items": [ ["chicken breast", ["1 ", "unit ( yield from 1 lb ready-to-cook chicken)"], 1.0, "unit ( yield from 1 lb ready-to-cook chicken)"], ["olive oil", ["1 ", "tablespoons"], 1.0, "tbsp"], ["curry powder", ["2 1/4", "teaspoons"], 0.75, "tbsp"], ["cumin seeds", ["2/3", "tbsp whole"], 0.6667, "tbsp whole"], ["yogurt (low fat plain)", ["3/4", "cup ( 8 fl oz)"], 0.75, "cup ( 8 fl oz)"], ["fresh peaches", ["1 1/2", "cup slices"], 1.5, "cup slices"], ["apples (tart with skin)", ["1 ", "cup slices"], 1.0, "cup slices"], ["celery", ["1/2", "cup chopped"], 0.5, "cup chopped"], ["cashew (nuts)", ["1/2 ", "cup"], 0.5, "cup"], ["black pepper", ["1/5", "tbsp ground"], 0.2, "tbsp ground"] ], "recipe": { "rating": 3.0, "name": "Curried Chicken Salad", "directions": "Toast cumin seeds for one or two minutes until they become fragrant and slightly browned. Peel and slice peaches. Bone and skin chicken breasts. Thinly slice celery and green onions. Dice unpeeled tart apples.\u003Cbr/\u003E\u003Cbr/\u003EMix oil, one tsp. of curry powder and one tsp. of cumin. Coat chicken breasts and broil until done. Set aside.\u003Cbr/\u003E\u003Cbr/\u003EIn a medium bowl add peaches, celery, green onions, yogurt, and remaining curry and cumin. Add cut up chicken and mix well.\u003Cbr/\u003E\u003Cbr/\u003EGarnish with peaches and cut up chives.", "num_served": 4, "id": 2, "num_ratings": 2 } }, { "items": [ ["Cornish Game Hens", ["4 ", "bird whole"], 4.0, "bird whole"], ["black pepper", ["1 1/2", "teaspoons"], 0.5, "tbsp"], ["dried basil", ["2 ", "tsp leaves"], 2.0, "tsp leaves"], ["rosemary", ["1 ", "tsp leaves"], 1.0, "tsp leaves"], ["salt", ["1 1/2", "teaspoons"], 0.03, "cup"] ], "recipe": { "rating": 2.0, "name": "Barbecued Cornish Game Hens", "directions": "Wash the Cornish Game Hens and with a large knife cut them each in two pieces (each piece has one leg, one wing, half a breast, and half a back). Trim the excess skin and fat from the cut edges, wash the hens in cold water and place in a large covered baking dish. Add the salt, pepper, and dried basil to the baking dish and rub the ingredients over the hens. Wash your hands with plenty of soap (because you just handled raw poultry), cover the baking dish, and cook in a 350 degree oven for about 30 minutes.\u003Cbr/\u003E\u003Cbr/\u003EStart the coals on your barbecue. Take the hens from the oven baking dish and place back side down over the hot coals. Cook for about 10 minutes and then turn over and cook for an additional 10 minutes. It might be necessary to move the hens if the burning charcoal flares up (if you did cut away some excess skin and fat this is likely to not happen).\u003Cbr/\u003E\u003Cbr/\u003ECooking time may vary depending on how hot the coals are.\u003Cbr/\u003E\u003Cbr/\u003ECut into the hens with a small sharp knife to make sure that they are done before serving.\u003Cbr/\u003E\u003Cbr/\u003EOptional:we sometimes spread a little teriyaki or barbeque sauce on the hens while cooking on the barbeque. They do also taste great with just the basil, salt, and pepper.\u003Cbr/\u003E\u003Cbr/\u003EServing size:a whole Cornish Game Hen makes a large serving for one person. We usually serve a whole hen per person only if we are just having a salad with the hen. If you have a few side dishes, then half a Cornish Game Hen makes a good serving. ", "num_served": 4, "id": 3, "num_ratings": 1 }, "pictures": [ ["barbequed_cornish_game_hen", "       Prepared Barbecued Cornish Game Hen
       (photo by Davie Boy public domain)"] ] }, { "items": [ ["chicken (fryer)", ["1 ", "unit ( yield from 1 lb ready-to-cook chicken)"], 1.0, "unit ( yield from 1 lb ready-to-cook chicken)"], ["vegetable oil", ["1/3", "cup"], 0.33333, "cup"], ["water", ["16 ", "fl oz"], 16.0, "fl oz"], ["brown onions (peeled and chopped)", ["1/2", "cup chopped"], 0.5, "cup chopped"], ["green pepper (seeded and chopped in strips)", ["1/2", "cup strips"], 0.5, "cup strips"], ["white rice", ["1 ", "cup"], 1.0, "cup"], ["tumeric", ["1/3", "teaspoons"], 0.1, "tbsp"], ["chicken broth (canned)", ["1 ", "cup"], 1.0, "cup"], ["frozen peas", ["1/2", "(0.5) cup"], 0.5, "(0.5) cup"] ], "recipe": { "rating": 2.0, "name": "Arroz con Pollo", "directions": "Heat oil in a large skillet over moderately high heat. Add lightly salted chicken pieces and brown on all sides for about 15 minutes. Reduce heat to low. Add 1/3 cup of water and simmer for approximately 10 minutes. Remove chicken and juices from pan and set aside. Return 3 tablespoons of liquid to pan, add onion, rice and green pepper and cook over moderately high head stirring occasionally until mixture is lightly browned. Return de-fatted remaining pan juices to pan with two cups of water, tumeric, 1 tsp. Salt, pepper, broth mix and pimiento.\u003Cbr/\u003E\u003Cbr/\u003EBring rice to a boil, arrange browned chicken on top. Reduce heat to moderately low, cover and cook 10 minutes. Sprinkle peas over chicken, cover and continue cooking 5 to 10 minutes.", "num_served": 4, "id": 5, "num_ratings": 1 }, "pictures": [ ["arroz_con_pollo", "       Prepared Arroz con Pollo
       (photo by Kobako CC BY-SA 2.5)"] ] }, { "items": [ ["salmon (fillet, skin removed)", ["1", "unit"], 1, "oz boneless"], ["brown rice", ["1 ", "cup"], 1.0, "cup"], ["chicken broth (canned)", ["2 ", "cup"], 2.0, "cup"], ["pine nuts", ["1/3", "cup"], 0.3333, "cup"], ["sesame oil", ["2 ", "tablespoons"], 2.0, "tbsp"], ["broccoli", ["2 ", "cup chopped"], 2.0, "cup chopped"] ], "recipe": { "rating": 2.0, "name": "Salmon Rice", "directions": "In a heavy pot suitable for cooking rice, add the finely chopped onion and about one-third of the chicken broth. Cover and cook over low heat for a few minutes. Add half the sesame oil, the washed brown rice and the pine (pinyon) nuts. Add the water and bring to a boil. As soon as the water comes to a boil, turn down the heat as low as possible, cover tightly and cook for about 20 to 25 minutes or until the mixture dries out and the rice is tender.\u003Cbr/\u003E\u003Cbr/\u003EWash the broccoli, discarding only the very bottom of the stems. Separate the florets into bite size pieces. Note: The broccoli stems are very nutritious, but will need to be cooked slightly longer than the rest of the broccoli. Cut them off just just under the tops and slice thinly or dice into 1/8\" pieces.\u003Cbr/\u003E\u003Cbr/\u003EMix the prepared broccoli stems, the rest of the chicken broth, and the rest of the sesame oil in a heavy skillet. Cook covered over medium heat for about 5 or 6 minutes. Stir in the broccoli florets and cook for about one additional minute. Remove the skin and bones from the salmon and add to the pan. Cook covered for just under 10 minutes over low heat until done, being careful not to overcook.\u003Cbr/\u003E\u003Cbr/\u003EServe the rice on one side of each plate and add salmon mixture from the skillet on the other side. Add a bit of fresh parsley garnish, if available.", "num_served": 4, "id": 6, "num_ratings": 1 } }, { "items": [ ["black beans", ["1 ", "cup"], 1.0, "cup"], ["adzuki beans", ["1/2", "cup"], 0.5, "cup"], ["kidney beans", ["1/2", "cup"], 0.5, "cup"], ["pinto beans", ["1/2", "cup"], 0.5, "cup"], ["fresh garlic", ["1 1/5", "tablespoons"], 0.075, "cup"], ["dried oregano", ["2 ", "tsp leaves"], 2.0, "tsp leaves"], ["coriander", ["1/2 ", "tsp leaves"], 0.5, "tsp leaves"], ["marjoram", ["1/2 ", "tsp"], 0.5, "tsp"], ["cumin", ["1/2", "tsp"], 0.5, "tsp"], ["cumin seeds", ["1/2", "tsp whole"], 0.5, "tsp whole"], ["dried bay leaf", ["1/2", "tbsp crumbled"], 0.5, "tbsp crumbled"], ["black pepper", ["1 ", "tablespoons"], 1.0, "tbsp"], ["brown onions (chopped)", ["1 ", "cup chopped"], 1.0, "cup chopped"], ["chili powder", ["1 1/2", "tablespoons"], 1.5, "tbsp"], ["salt", ["1 ", "teaspoons"], 0.02, "cup"] ], "recipe": { "rating": 2.0, "name": "SouthWest Beans", "directions": "Inspect the beans making sure there are no small stones. Rinse.\u003Cbr/\u003E\u003Cbr/\u003EWash the beans and soak overnight (up to 24 hours is OK). If you do not have time to presoak the beans, boil for 5 minutes and turn off heat for about one hour.\u003Cbr/\u003E\u003Cbr/\u003EDrain and wash beans and then add to a large soup pot with 5 to 6 cups of water. (You might have to add additional water later). Add all ingredients (but no salt, this makes them tough during cooking), cover, and cook at a slow boil for a few hours, adding water as required to keep the beans slightly covered in water.\u003Cbr/\u003E\u003Cbr/\u003E The onion should be finely chopped. Cook covered for another hour. Note: if there is too much water in the beans, you can cook them uncovered until the liquid is reduced.\u003Cbr/\u003E\u003Cbr/\u003EAdd salt before serving. Adding salt earlier makes the beans tough. OPTIONAL: when the beans are cooked, put about 1/3 of the cooked beans in a blender, puree for about 10 seconds, and add them back to the rest of the cooked beans. This optional step gives the beans a tasty creamy consistency.\u003Cbr/\u003E\u003Cbr/\u003EIdea for left over beans: warm and serve with grated cheese and a fried egg on top.", "num_served": 4, "id": 7, "num_ratings": 1 }, "pictures": [ ["southwestbeans1", "       Beans soaking in water"], ["southwestbeans2", "       All ingredients starting to boil"], ["southwestbeans3", "       With puréed beens added back in"], ["southwestbeans4", "       Save some for leftovers"] ] }, { "items": [ ["T-Bone steak", ["1 ", "piece cooked excluding refuse ( yield from 1 lb raw meat with refuse)"], 1.0, "piece cooked excluding refuse ( yield from 1 lb raw meat with refuse)"], ["barbecue sauce", ["1 ", "serving 2 tbsp"], 1.0, "serving 2 tbsp"] ], "recipe": { "rating": 3.0, "name": "Barbecued T-Bone Steak", "directions": "Trim excess loose fat from steak.\u003Cbr/\u003E\u003Cbr/\u003EBarbecue over hot coals and add barbecue sauce to taste.\u003Cbr/\u003E\u003Cbr/\u003ERemember to wash your hands after handling raw meat!", "num_served": 1, "id": 8, "num_ratings": 2 } }, { "items": [ ["egg", ["2 ", "large"], 2.0, "large"], ["mayonnaise", ["1 2/3", "tablespoons"], 0.1, "cup"], ["iceberg lettuce", ["1/4", "cup shredded"], 0.25, "cup shredded"], ["bread (toasted)", ["2 ", "slice small"], 2.0, "slice small"], ["bread (toasted sourdough french bread)", ["1/10", "teaspoons"], 0.0007, "cup"], ["black pepper", ["1/3", "teaspoons"], 0.1, "tbsp"] ], "recipe": { "rating": 3.0, "name": "Egg Salad Sandwich", "directions": "Peel boiled eggs, mash, and mix with mayonnaise.\u003Cbr/\u003E\u003Cbr/\u003EAdd salt and pepper to taste.\u003Cbr/\u003E\u003Cbr/\u003EServe with shredded lettuce on toast.", "num_served": 1, "id": 10, "num_ratings": 2 } }, { "items": [ ["bread (toasted sourdough french)", ["1 ", "slice small"], 1.0, "slice small"], ["peanut butter", ["2 ", "tablespoons"], 2.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Peanut butter toast", "directions": "", "num_served": 1, "id": 11, "num_ratings": 1 } }, { "items": [ ["apples", ["2/3", "cup quartered or chopped"], 0.6666, "cup quartered or chopped"] ], "recipe": { "rating": 2.0, "name": "Apple", "directions": "Eat as is.", "num_served": 1, "id": 12, "num_ratings": 1 } }, { "items": [ ["apples", ["2/3", "cup quartered or chopped"], 0.66666, "cup quartered or chopped"] ], "recipe": { "rating": 2.0, "name": "Fresh apple desert", "directions": "Eat as is.", "num_served": 1, "id": 13, "num_ratings": 1 } }, { "items": [ ["ear of fresh corn", ["1 ", "ear small ( 5-1/2"], 1.0, "ear small ( 5-1/2"], ["butter (with salt)", ["1 1/3", "teaspoons"], 0.0265, "cup"], ["black pepper", ["1/5", "teaspoons"], 0.0666, "tbsp"], ["salt", ["1/5", "teaspoons"], 0.004, "cup"] ], "recipe": { "rating": 2.0, "name": "Corn on the cob with butter, salt, and pepper", "directions": "Boil or steam corn - cook to desired tenderness.\u003Cbr/\u003E\u003Cbr/\u003ESeason with butter, salt, and pepper.", "num_served": 1, "id": 16, "num_ratings": 1 } }, { "items": [ ["Corn", ["1 ", "ear small ( 5-1/2"], 1.0, "ear small ( 5-1/2"], ["black pepper", ["1/3", "teaspoons"], 0.1, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Corn on the cob with black pepper", "directions": "Boil or steam corn - cook to desired tenderness.\u003Cbr/\u003E\u003Cbr/\u003ETo reduce sodium, do not use butter (usually contains salt) or add extra salt.\u003Cbr/\u003E\u003Cbr/\u003EAdd pepper to taste.", "num_served": 1, "id": 17, "num_ratings": 1 } }, { "items": [ ["Camembert cheese", ["3 ", "tablespoons"], 0.187, "cup"], ["Nabisco Ritz Crackers", ["1 ", "serving"], 1.0, "serving"] ], "recipe": { "rating": 2.0, "name": "Camembert cheese and crackers", "directions": "Spread softened cheese (let ripen at room temperature for at least 30 minutes before eating) on crackers.", "num_served": 1, "id": 18, "num_ratings": 1 } }, { "items": [ ["Cheddar Cheese", ["1 ", "cup diced"], 1.0, "cup diced"], ["tortilla chips", ["16 ", "oz"], 16.0, "oz"], ["ear of fresh corn", ["1 ", "cup"], 1.0, "cup"], ["Tabasco Sauce", ["1 ", "tsp"], 1.0, "tsp"], ["brown onions", ["1/4", "cup chopped"], 0.25, "cup chopped"] ], "recipe": { "rating": 2.0, "name": "Cheddar Cheese Nachos", "directions": "Cover tortilla chips with cheese and onions (optional) and diced fresh tomatoes.\u003Cbr/\u003E\u003Cbr/\u003EAdd Tabasco Sauce or red taco sauce, too taste.\u003Cbr/\u003E\u003Cbr/\u003ECook in microwave oven until the cheese has melted. ", "num_served": 4, "id": 23, "num_ratings": 1 } }, { "items": [ ["lamb shank", ["4 ", "piece cooked excluding refuse ( yield from 1 lb raw meat with refuse)"], 4.0, "piece cooked excluding refuse ( yield from 1 lb raw meat with refuse)"], ["dried thyme (fresh thyme if you have it)", ["1/3", "tsp"], 0.3333, "tsp"], ["black pepper", ["1 ", "teaspoons"], 0.3333, "tbsp"], ["salt", ["1 ", "teaspoons"], 0.02083, "cup"], ["brown onions", ["3/4", "cup chopped"], 0.75, "cup chopped"], ["olive oil", ["2 ", "tablespoons"], 2.0, "tbsp"], ["fresh garlic", ["2 ", "tablespoons"], 0.125, "cup"], ["dry rosemary (fresh rosemary if you have it)", ["1 1/2", "tablespoons"], 1.5, "tbsp"], ["white wine", ["8 ", "fl oz"], 8.0, "fl oz"], ["saffron", ["1/2", "teaspoons"], 0.152, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Mark's Baked Lamb Shanks", "directions": "Start by cutting off excess fat from the lamb shanks. You will notice clear membrane covering most of the meat; try to remove most of this membrane with a sharp knife - however, do not remove any of the meat, just the membrane.\u003Cbr/\u003E\u003Cbr/\u003ECoarsely chop the onion and garlic. Then add all ingredients to a covered oven baking dish. Depending on the size of the dish, the lamb shanks will probably be about 1/3 covered by liquid. Add enough water to cover about 1/2 to 2/3 of the lamb shanks.\u003Cbr/\u003E\u003Cbr/\u003EPlace the covered baking dish in the refrigerator for a time interval of 1 hour to overnight. If possible during this period, occasionally turn the lamb shanks in the liquid.\u003Cbr/\u003E\u003Cbr/\u003ETurn the oven on and set it to 325 degrees F. It is not really necessary to preheat the oven. Cook the covered lamb shanks for 1 1/2 to 2 hours. Then uncover the lamb shanks and let them cook for an additional 20 to 30 minutes to allow some of the liquid to dry up. You will want some liquid for serving the lamb shanks. You will want to serve the lamb shanks with:\u003Cbr/\u003E\u003Cbr/\u003E * A large helping of steamed vegetables * A side dish of a small serving of either noodles, baked potato, or rice\u003Cbr/\u003E\u003Cbr/\u003EPlace one lamb shank on each plate with the vegetables and other side dish. Then spoon some of the liquid from the baking dish over the lamb shanks. This liquid will contain a fair amount of fat so while you should generously spoon it over the lamb shanks please avoid pouring it over the vegetables and side dish. Some of the liquid will flow on the plate into the vegetables and side dish which is OK and adds flavor.", "num_served": 4, "id": 25, "num_ratings": 1 } }, { "items": [ ["brown rice (cooked)", ["2 ", "cup"], 2.0, "cup"], ["soy sauce", ["2 ", "tablespoons"], 2.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Brown rice", "directions": "Cook rice as per directions. If you buy your brown rice in bulk at a health food store (a good idea!) add 1 part rice to 2 parts water and cook in either a rice cooker or a pan with a tightly fitting top - do not lift the lid while rice is cooking.\u003Cbr/\u003E\u003Cbr/\u003EIf you are not on a low sodium diet, add soy sauce to taste.", "num_served": 4, "id": 26, "num_ratings": 1 } }, { "items": [ ["white rice (cooked)", ["2 ", "cup"], 2.0, "cup"] ], "recipe": { "rating": 2.0, "name": "White rice", "directions": "Cook rice as per package directions.\u003Cbr/\u003E\u003Cbr/\u003EIf you buy your rice in bulk, cook with 1 part dry rice to 2 parts water. Cook in a tightly covered pan for 20 minutes or use a rice cooker.", "num_served": 4, "id": 27, "num_ratings": 1 } }, { "items": [ ["potatoes", ["1 ", "potato large"], 1.0, "potato large"], ["butter", ["1 ", "tablespoons"], 0.0625, "cup"], ["sour cream", ["1 ", "tablespoons"], 0.0625, "cup"], ["salt", ["1/6", "teaspoons"], 0.003, "cup"], ["black pepper", ["1/10", "teaspoons"], 0.02, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Baked potato", "directions": "Wash potatoes and bake in 325 oven for about 90 minutes.\u003Cbr/\u003E\u003Cbr/\u003EServe with salt, pepper, butter, and sour cream.", "num_served": 1, "id": 30, "num_ratings": 1 } }, { "items": [ ["redleaf lettuce", ["1/2", "cup shredded"], 0.5, "cup shredded"], ["raw carrot", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["sweet (purple) raw onion", ["1/8", "onion"], 0.125, "onion"], ["pealed raw cucumber", ["1/8", "cup pared chopped"], 0.125, "cup pared chopped"], ["olive oil", ["1 ", "tablespoons"], 1.0, "tbsp"], ["red wine or balsamic vinegar", ["1 1/10", "tablespoons"], 0.065, "cup"], ["black pepper", ["1/4", "teaspoons"], 0.07, "tbsp"], ["salt", ["1/10", "teaspoons"], 0.002, "cup"] ], "recipe": { "rating": 3.0, "name": "Tossed summer salad", "directions": "Wash lettuce, carrot, onion, and cucumber; cut into bite size pieces.\u003Cbr/\u003E\u003Cbr/\u003EAdd remaining ingredients and mix well.", "num_served": 1, "id": 33, "num_ratings": 2 } }, { "items": [ ["egg", ["2 ", "large"], 2.0, "large"], ["bacon", ["2 ", "slice cooked"], 2.0, "slice cooked"], ["bread (1 slice)", ["1 ", "oz"], 1.0, "oz"], ["butter", ["1 ", "teaspoons"], 0.0208, "cup"] ], "recipe": { "rating": 2.5, "name": "Eggs, bacon, and toast with butter", "directions": "Fry eggs in half the butter. Cook bacon and drain.\u003Cbr/\u003E\u003Cbr/\u003EUse remaining butter on toast.", "num_served": 1, "id": 34, "num_ratings": 2 } }, { "items": [ ["bread", ["4 ", "slice small"], 4.0, "slice small"], ["ground cinnamon", ["1/2", "teaspoons"], 0.152, "tbsp"], ["ground nutmeg", ["1/2", "teaspoons"], 0.152, "tbsp"], ["orange (just the peel)", ["1/2", "teaspoons"], 0.152, "tbsp"], ["lemon (just the peel)", ["1/2", "teaspoons"], 0.152, "tbsp"], ["egg yolks", ["1/4", "cup"], 0.25, "cup"], ["maple syrup", ["1/2", "cup"], 0.5, "cup"], ["baking soda", ["1/8", "tsp"], 0.125, "tsp"], ["raisins", ["1/4", "cup packed"], 0.25, "cup packed"], ["low fat milk", ["2 ", "cup"], 2.0, "cup"], ["vanilla extract", ["1 1/2", "teaspoons"], 0.5, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Bread Pudding", "directions": "Cube bread and place in 13x9 inch pan. Combine cinnamon, nutmeg, orange and lemon peels, walnuts and raisins and sprinkle evenly over bread cubes. Beat egg yolks, maple syrup and baking soda. Scald the milk. Stir egg mixture and vanilla into milk and pur over bread mixture. Bake at 350 one hour or until golden.", "num_served": 4, "id": 35, "num_ratings": 1 } }, { "items": [ ["flour tortilla", ["2 ", "serving"], 2.0, "serving"], ["Cheddar cheese", ["1/8", "cup diced"], 0.125, "cup diced"], ["black olives", ["4 ", "jumbo"], 4.0, "jumbo"], ["tomato (diced)", ["1/4", "cup"], 0.25, "cup"], ["Olive oil", ["1 ", "tablespoons"], 1.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Cheese quesadilla", "directions": "If you are making two small quesadillas, you can cook them together in a large frying pan, or separately in a small pan. One large tortilla can be substituted for 2 8-inch tortillas.\u003Cbr/\u003E\u003Cbr/\u003EAdd oil to a pan and set heat for medium. Cook one side of the tortillas until the cooked side starts to slightly blacken.\u003Cbr/\u003E\u003Cbr/\u003EThe tomato and large olives should be coarsely chopped.\u003Cbr/\u003E\u003Cbr/\u003ETurn tortillas and add all ingredients, mixed, and being careful to keep ingredients away from the edges of the tortillas. Lower heat slightly, and cook until the cheese melts and the outer side of the tortillas slightly blacken.", "num_served": 1, "id": 36, "num_ratings": 1 } }, { "items": [ ["Salmon", ["1 ", "fillet"], 1.0, "fillet"], ["green onions (scallions)", ["1 ", "cup chopped"], 1.0, "cup chopped"], ["low fat milk", ["2 ", "cup"], 2.0, "cup"], ["olive oil", ["2 ", "tablespoons"], 2.0, "tbsp"], ["salt", ["1/3", "teaspoons"], 0.0069, "cup"], ["black pepper", ["1/3", "teaspoons"], 0.1, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Salmon and Scallions Soup", "directions": "Wash and chop scallions. Mix scallions with olive oil, salt, and pepper and start to cook over low heat for 1 minute, then add milk and cook under medim heat until the milk has boiled for one minute.\u003Cbr/\u003E\u003Cbr/\u003EWhile the milk is heating, remove the skin from the salmon and cut into small pieces.\u003Cbr/\u003E\u003Cbr/\u003EAdd the salmon to the lightly boiling milk, reduce heat to very low, cover, and cook for 10 minutes.", "num_served": 4, "id": 37, "num_ratings": 1 } }, { "items": [ ["canned tuna (in water, not oil), drained", ["1/2", "cup solid or chunks"], 0.5, "cup solid or chunks"], ["frozen corn", ["1/4", "(0.5) cup"], 0.25, "(0.5) cup"], ["frozen peas", ["1/4", "(0.5) cup"], 0.25, "(0.5) cup"], ["dry pasta (any type)", ["1 ", "cup"], 1.0, "cup"], ["brown onions", ["1/3", "cup chopped"], 0.3333, "cup chopped"], ["salt", ["1/4", "teaspoons"], 0.005, "cup"], ["mayonnaise", ["2 ", "tablespoons"], 0.125, "cup"], ["black pepper", ["1/5", "teaspoons"], 0.06667, "tbsp"], ["olive oil", ["1 ", "tablespoons"], 1.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Pasta Salad with Tuna, Corn, and Peas", "directions": "This can be a complete \"one dish meal\":\u003Cbr/\u003E\u003Cbr/\u003ECook pasta according to directions, drain, and cool.\u003Cbr/\u003E\u003Cbr/\u003ECook corn and peas according to package directions, rinse, and cool.\u003Cbr/\u003E\u003Cbr/\u003EFinely chop white onion.\u003Cbr/\u003E\u003Cbr/\u003EMix all ingredients and place in refrigerator for at least 15 minutes to cool.", "num_served": 2, "id": 38, "num_ratings": 1 } }, { "items": [ ["cheddar cheese", ["1/4", "cup sliced"], 0.25, "cup sliced"], ["bread (preferably French bread)", ["2 ", "slice small"], 2.0, "slice small"], ["butter", ["1 ", "tablespoons"], 0.0625, "cup"] ], "recipe": { "rating": 2.0, "name": "Grilled Cheddar Cheese Sandwich", "directions": "Melt butter in a skillet and brown one side of both pieces of bread.\u003Cbr/\u003E\u003Cbr/\u003ETurn over one slice, add cheese and cover with other slice of bread.\u003Cbr/\u003E\u003Cbr/\u003ETurn after the bottom is browned and serve when the other side is done. ", "num_served": 1, "id": 39, "num_ratings": 1 } }, { "items": [ ["elbow macaroni", ["2 ", "cup elbow shaped"], 2.0, "cup elbow shaped"], ["olive oil", ["2 ", "tablespoons"], 2.0, "tbsp"], ["butter", ["1 1/3", "tablespoons"], 0.08, "cup"], ["carrots", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["brown onions", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["mushrooms", ["1/2", "cup pieces or slices"], 0.5, "cup pieces or slices"], ["broccoli", ["1/2", "cup flowerets"], 0.5, "cup flowerets"], ["half-and-half", ["1 ", "cup"], 1.0, "cup"], ["Swiss cheese", ["3/4", "cup diced"], 0.75, "cup diced"], ["egg", ["2 ", "large"], 2.0, "large"], ["salt", ["1 ", "teaspoons"], 0.02, "cup"], ["black pepper", ["1 ", "teaspoons"], 0.333, "tbsp"], ["raw shrimp", ["12 ", "medium"], 12.0, "medium"] ], "recipe": { "rating": 2.0, "name": "Shrimp Macaroni and Cheese", "directions": "\u003Cp\u003ECook the elbow macaroni according to directions on package. Do not overcook. Heat oven to 375 degrees. While the elbow macaroni is cooking finely chop: carrots, onions, and broccoli. Thinly slice the mushrooms. Chop the cheese into small cubes. Cut the shrimp in half, lengthwise. Use half the butter to lightly cook the shrimp in a non-stick pan for two minutes and set aside. Use half the butter to grease a 9 by 13 inch baking pan. In a large bowl, beat the eggs and then add all remaining ingredients, including the cooked elbow macaroni. Mix everything together and pour into the baking dish. Bake covered for 30 minutes. Uncover and cook for another 10 minutes. Remove from oven and cool for 10 minutes before serving.\u003Cp\u003E", "num_served": 4, "id": 50, "num_ratings": 1 } }, { "items": [ ["canned soup (any of your favorites)", ["1 ", "serving 1/3 cup"], 1.0, "serving 1/3 cup"], ["Optional: broccoli (raw and chopped)", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["Optional: carrots (raw and chopped)", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["Optional: brussels sprouts (raw and chopped)", ["1/4", "cup"], 0.25, "cup"], ["Optional: celery (raw and chopped)", ["1/4", "cup chopped"], 0.25, "cup chopped"] ], "recipe": { "rating": 2.0, "name": "Canned Soup with Fresh Vegetables", "directions": "\u003Cp\u003EThis is one of my favorite lunches that is easy to prepare, tastes great, and is healthy because of the fresh vegetables. Start by filling a covered sauce pan about 1/2 inch with water and place over medium to high heat. Starting with the 'tougher' vegetables first finely chop the vegetables and add to the water. Cover the sauce pan and cook for about 5 minutes, then add the canned soup and heat just until everything reaches a boil.\u003C/p\u003E", "num_served": 2, "id": 44, "num_ratings": 1 } }, { "items": [ ["sweet red onions (brown onions are fine to use also)", ["1/4", "cup chopped"], 0.25, "cup chopped"], ["Olive Oil", ["5 ", "tablespoons"], 5.0, "tbsp"], ["Sriracha Hot Chili Sauce", ["1 1/2", "teaspoons"], 0.5, "tbsp"], ["Optional: white wine", ["4 ", "fl oz"], 4.0, "fl oz"], ["Optional: zucchini squash (raw and chopped)", ["1/2", "cup chopped"], 0.5, "cup chopped"], ["Optional: spinach (raw and chopped)", ["1/2", "cup"], 0.5, "cup"], ["Optional: broccoli (raw and chopped)", ["1/2", "cup chopped"], 0.5, "cup chopped"], ["fresh garlic (finely chopped)", ["1 1/3", "tablespoons"], 0.08, "cup"], ["raw shrimp (peeled. defrost if frozen)", ["1/2", "cup"], 0.5, "cup"], ["brown rice (cooked as per directions; white rice is also OK)", ["1 1/2", "cup"], 1.5, "cup"], ["salt (to taste)", ["3/4", "teaspoons"], 0.015, "cup"] ], "recipe": { "rating": 2.0, "name": "Spicy Shrimp with Vegetables and Rice", "directions": "You can experiment with this recipe by adjusting the relative amounts of shrimp and vegetables. For a healthy meal I prefer using relatively few shrimp (slicing them in half lengthwise) and a lot of vegetables. Sometimes I use fewer fresh vegetables and more shrimp (and then leave the shrimp whole).\n\nThe white wine is optional. You can substitute some canned vegetable broth or water.\n\nPut half the olive oil in a heavy frying pan that has a lid (which we will use later). Heat the oil and cook the onion for about a minute before adding the chopped vegetables and then the hot chili sauce.\n\nAfter a few minutes add the finely chopped fresh garlic, give everything a good stir, and cook for another minute before adding the wine (or broth, or water). Stir again, cover the frying pan, reduce heat and slowly cook for another 5 minutes, stirring occasionally. Add the raw shrimp, stir, cover, and cook for another 5 minutes (stirring occasionally to make sure the shrimp get cooked).\n\nIf you use pre-cooked shrimp (not really recommended) then delay adding the defrosted cooked shrimp for a few minutes. You don't want to overcook already cooked shrimp.\n\nUncover the pan and add the cooked rice. Keeping the heat low, stir the ingredients together and cook for another few minutes. Finally, add the remaining olive oil, stir well, turn off the heat, cover the pan and let everything sit for a few minutes before serving.\n\nYou can also serve the shrimp and vegetables on top of the cooked rice instead of mixing in the rice at the end of cooking the shrimp and vegetables.\n\nI like to keep frozen raw shrimp in the freezer. This recipe works well when I have vegetables need to use up. This recipe also works well when I have left over cooked rice to use up.\n\nIf I have leftovers for this recipe I like to make another meal by heating lightly in the microwave and adding some sour cream before eating. The sour cream adds a great flavor and makes leftovers taste different.", "num_served": 2, "id": 42, "num_ratings": 1 } }, { "items": [ ["brown onions", ["1 ", "onion"], 1.0, "onion"], ["sweet red pepper (bell pepper)", ["1 ", "cup strips"], 1.0, "cup strips"], ["olive oil", ["1/3", "cup"], 20.0, "tbsp"], ["fresh garlic (peeled and chopped)", ["5", "clove"], 0.2, "cup"], ["fresh basil (chopped)", ["5 ", "(2) tbsp chopped"], 5.0, "(2) tbsp chopped"], ["salt", ["1", "teaspoons"], 0.01, "cup"], ["black pepper", ["1/2", "teaspoons"], 0.1, "tbsp"], ["red pepper flakes", ["1", "teaspoons"], 0.2, "tbsp"], ["canned chopped tomatoes", ["4", "cup"], 1.8, "cup"], ["water", ["12 ", "fl oz"], 12.0, "fl oz"], ["dry pasta (uncooked spaghetti)", ["2 1/5", "cup"], 2.2, "cup"] ], "recipe": { "rating": 2.0, "name": "Marinara Sauce", "directions": "

Note that you can substitute fresh chopped tomatoes for all or some of the canned tomatoes.

Put 1/3 of the olive oil in a large heavy pan and start to heat to low temperature while chopping the onion and red bell peppers in a food processor. Chop either coarsely of finely depending on how smooth you want your Marinara Sauce.

Fry the onion and red bell peppers over medium-high heat for about 10 minutes, stirring often. While you are doing this peel the garlic and chop it finely. Lower the heat and add the garlic and continue stirring frequently for about 5 minutes. While you are stirring open the canned tomatos (or sauce with diced tomatoes - your choice). With medium heat, add the tomato sauce and another 1/3 of the olive oil and stir often to mix all the ingredients. After about 10 minutes, add half the water, stir well, reduce the heat and cover. I cook the sauce under very low heat for about 3 hours but you can reduce the cooking time if you need to. I set an alarm to go off every 20 minutes to remind me to stir the sauce and add a little bit of water if the sauce is very thick. About 5 minutes before turning off the heat I add the final 1/3 of the olive oil to the sauce. I usually let the sauce sit for 15 or 20 minutes after it is done before serving over pasta.

Cook your favorite pasta as per the directions on the package and serve with sauce.

Pro tip: this recipe is a lot of work so I usually make a very large quantity of Marinara Sauce and freeze some of it for future use.

This Marinara sauce is useful as a base for other recipes and is delicious to eat as-is.

", "num_served": 6, "id": 41, "num_ratings": 1 }, "pictures": [ ["marinara1", "       Peppers and onion"], ["marinara2", "       Chop before
       food processing"], ["marinara3", "       Peppers and onion
       ready for cooking"], ["marinara4", "       Peppers and onion
       fried in oil"], ["marinara5", "      Thinly slice/chop garlic"], ["marinara6", "      Ready to eat with pasta"] ] }, { "items": [ ["sweet potatoes", ["4 ", "medium ( 2"], 4.0, "medium ( 2"], ["Olive oil", ["6 ", "tablespoons"], 6.0, "tbsp"], ["salt (to taste)", ["1/3", "teaspoons"], 0.007, "cup"] ], "recipe": { "rating": 2.0, "name": "Sweet Potato French Fries", "directions": "\u003Cp\u003EThese fries are tasty and also very healthy since they are baked and not fried. Turn oven on and set to 400 degrees. Peal the sweet potatoes and cut them into the shape of french fries. Poor most of the olive oil onto a cookie sheet and roll the raw sweet potato french fries in the oil to cover them. Then spread out the french fries and dribble the remaining olive oil over the fries. Don't worry if the oven is fully pre-heated. The oven can continue to heat up while the fries are cooking. It will take about 30 minutes to cook the fries if you cut them sweet potato into thin pieces, and a little longer if the fries are thicker.\u003C/p\u003E ", "num_served": 4, "id": 43, "num_ratings": 1 } }, { "items": [ ["chicken breast (raw, full, from a frying chicken)", ["1 ", "unit ( yield from 1 lb ready-to-cook chicken)"], 1.0, "unit ( yield from 1 lb ready-to-cook chicken)"], ["Sriracha Hot Chili Sauce", ["4 ", "tsp or 1 packet"], 4.0, "tsp or 1 packet"], ["honey", ["1/3", "cup"], 0.3, "cup"], ["soy sauce", ["1 ", "tablespoons"], 1.0, "tbsp"], ["Coconut oil", ["2 ", "tablespoons"], 2.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Sweet and Spicy Chicken Breasts", "directions": "\u003Cp\u003EDepending on your tastes and what you already have in your kitchen, you can vary the flavor of this recipe a lot by using either Sriracha Hot Chili Sauce (substitute a smaller amount of Tabasco sauce if you are out of Sriracha) or prepared mustard. (Prepared mustard can be Dijon or plain yellow mustard.) My Favorite is mixing in a little of both Sriracha and Dijon mustard. Mix the Sriracha, mustard, honey, and soy sauce on a paper plate and coat the boanless and skinless chicken with this mixture. Heat the Coconut oil to medium high heat in a no-stick pan and add the chicken. Cook the chicken for about 7 or 8 minutes per side. Cut into the fattest piece of chicken to make sure it is done. Cook longer if necessary. Since this dish is flavorful and spicy, but also fairly high in fat and sugar, I like to pair this recipe with simple steamed vegetables. \u003Cb\u003EAs an appetizer:\u003C/b\u003E you can use chicken wings and make an appetizer. You will need to increase the amount of coconut oil so they are crisp.\u003C/p\u003E", "num_served": 2, "id": 46, "num_ratings": 1 } }, { "items": [ ["Small fillet of Salmon, thawed and skin removed", ["2 ", "(0.5) fillet"], 2.0, "(0.5) fillet"], ["Bread crumbs (Italian, plain, or seasoned)", ["1/4", "cup"], 0.25, "cup"], ["Dijon Mustard (Yellow mustard is OK also)", ["3 ", "tsp or 1 packet"], 3.0, "tsp or 1 packet"], ["Coconut Oil", ["3 ", "tablespoons"], 3.0, "tbsp"], ["Salt and Pepper to taste", ["1/2", "teaspoons"], 0.01, "cup"] ], "recipe": { "rating": 2.0, "name": "Fried Salmon with Dijon Mustard Breading", "directions": "\u003Cp\u003EMix bread crumbs and mustard together on a small paper plate and coat the salmon fillets with this mixture. Heat coconut oil to medium high heat (preferably in a non-stick pan). Coconut oil is excellant to fry with as its nutritional value is not much affected by heat. place salmon fillets in the hot oil and cook for about 4 minutes. Then turn heat down to medium and turn over the fish. The top side of the fish will appear more crispy because that side of the fish will have absorbed most of the coconut oil and was cooked under higher heat. Serve with the crunchy side of the fish up. \u003Ci\u003ENote: you can substitute salmon steaks for fillets.\u003C/i\u003E\u003C/p\u003E", "num_served": 2, "id": 45, "num_ratings": 1 } }, { "items": [ ["Shiitake mushrooms", ["1/2", "cup pieces"], 0.5, "cup pieces"], ["Kale (or substitute green lettuce)", ["2 ", "cup chopped"], 2.0, "cup chopped"], ["tofu (soft)", ["2/3", "cup ( 1/2"], 0.6, "cup ( 1/2"], ["cashew (nuts)", ["1/3", "cup halves and whole"], 0.3, "cup halves and whole"], ["Sesame Oil", ["1 ", "tablespoons"], 1.0, "tbsp"], ["Soy sauce", ["1 ", "tablespoons"], 1.0, "tbsp"] ], "recipe": { "rating": 2.0, "name": "Oriental Kale and Mushroom Salad", "directions": "\u003Cp\u003EYou can substitute chopped green lettuce for kale. If you are using fresh shiitake mushrooms then wash them and dry them. If you are using dried shiitake mushrooms then soak them in just enough water to cover them for about a half hour until they are soft. Mix all the ingredients and serve.\u003C/p\u003E", "num_served": 4, "id": 47, "num_ratings": 1 } }, { "items": [ ["brown rice", ["3/4", "cup"], 0.75, "cup"], ["hoison sauce", ["1 ", "tablespoons"], 1.0, "tbsp"], ["soy sauce", ["1 1/2", "teaspoons"], 0.5, "tbsp"], ["canola oil", ["1 1/2", "teaspoons"], 0.5, "tbsp"], ["sesame oil", ["1 1/2", "teaspoons"], 0.5, "tbsp"], ["raw shrimp", ["8 ", "medium"], 8.0, "medium"], ["egg", ["1 ", "large"], 1.0, "large"], ["fresh ginger", ["4 ", "tsp"], 4.0, "tsp"], ["frozen peas", ["1 ", "cup"], 1.0, "cup"], ["carrots (raw and finely chopped)", ["3/4", "cup chopped"], 0.75, "cup chopped"], ["brown onions (finely chopped)", ["1/4", "cup chopped"], 0.25, "cup chopped"] ], "recipe": { "rating": 2.0, "name": "Simple Shrimp Fried Rice", "directions": "\u003Cp\u003EThis tasty and delicious recipe has two sources of protein: shrimp and egg. I vary the ratio of shrimp and egg, depending on what I feel like. You can leave out the shrimp and double the number of eggs also. The brown rice takes a while to cook so start that in your rice cooker (or in a tightly covered pan on the stove) cooking as per the package directions. Optional: when done put the rice in a large bowl to cool off. After the rice is cooked: Put about half the sesame oil in a non-stick pan, heat, beat the eggs and fry. Set aside on a plate for later. Use the rest of the sesame oil to fry the shrimp. When they are done, put them on the plate with the cooked egg. Hopefully while frying the eggs and shrimp you have already removed the skin and chopped the onion and ginger, and finely chopped the carrots - if not do that now. Add canola oil to the non-stick pan and cook the finely sliced or chopped up ginger and carrots for two minutes - then add the onions and frozen peas and continue frying for a two minutes. Add the rice, and fry everything in the pan for another minute then add the already cooked egg and shrimp and keep frying for another minute. Then turn off the heat. Mix in the hoison and soy sauces and stir well.\u003Cp\u003E\u003Cp\u003EServe immediately.\u003C/p\u003E", "num_served": 2, "id": 49, "num_ratings": 1 } }, { "items": [ ["Olive oil", ["1 1/2", "tablespoons"], 1.5, "tbsp"], ["Butter", ["1 ", "teaspoons"], 0.02, "cup"], ["Green onions (or yellow onions) chopped", ["1/10", "cup chopped"], 0.1, "cup chopped"], ["fresh garlic (peeled and sliced)", ["3 ", "teaspoons"], 0.06, "cup"], ["white wine", ["3 ", "fl oz"], 3.0, "fl oz"], ["parsley (chopped)", ["1 2/3", "tablespoons"], 0.1, "cup"], ["mushrooms (sliced)", ["1/5", "cup pieces or slices"], 0.2, "cup pieces or slices"], ["dry pasta (Linguine, cooked. can substitute other types of pasta)", ["1 1/2", "cup"], 1.5, "cup"], ["canned clams (with juice. clams can be whole or diced)", ["1 ", "cup ( with liquid and clams)"], 1.0, "cup ( with liquid and clams)"] ], "recipe": { "rating": 2.0, "name": "Linguine with Clam Sauce", "directions": "This is a fast recipe to make, but you will be cooking with two pans at once. Add more or less clams and juice to the recipe depending on your taste for clams. If you don't use many clams then you might have to add a little water to the frying pan while cooking. Start a large pan of salted water to boil. Peel and thinly slice the garlic and chop the onions. Heat olive oil and butter in a frying pan and add the onion and cook for a minute, stirring as needed. Then add the garlic. The water should be boiling so add the Linguine pasta (or, you can substitute other types of pasta). Note: you don't want to fully cook the pasta; when you taste it it should have some slight crunch since we will re-cook it with the sauce. If the recipe for cooking the pasta indicates a 10 minute cooking time, only boil the pasta for about 8 or 9 minutes. Add the white wine, sliced mushrooms, and the clam juice (not the clams, yet!) to the frying pan and simmer for at least 5 minutes. Add the drained pasta, parsley and simmer for a few more minutes. Finally, add the clams and simmer for another 3 or 4 minutes and then immediately serve. The dish is done when the pasta is fully cooked - taste it before serving to check for doneness.\u003Cp\u003EOptional: serve with parmesan cheese\u003C/p\u003E", "num_served": 2, "id": 48, "num_ratings": 1 } } ] ================================================ FILE: cooking_recipes/data/tiny.json ================================================ {"name":"Balsamic Mushrooms", "num_served":3, "ingredients": [{"name":"mushrooms", "amount":"12", "units":"medium", "description":"Mushrooms"}, {"name":"balsamic vinegar", "amount":"1/4", "units":"cup", "description":"Balsamic vinegar"}, {"name":"red wine", "amount":"1/8", "units":"cup", "description":"Red wine"}], "directions": ["Place all ingredients in a (preferably nonstick) pan and let sit for a few minutes.", "Then cook covered over medium heat for about three minutes until they are soft.", "Remove the cover and cook until the liquid is almost gone, then serve."]} ================================================ FILE: cooking_recipes/data/vegetarian.json ================================================ [ {"name":"Balsamic Mushrooms", "num_served":3, "ingredients": [{"name":"mushrooms", "amount":"12", "units":"medium", "description":"Mushrooms"}, {"name":"balsamic vinegar", "amount":"1/4", "units":"cup", "description":"Balsamic vinegar"}, {"name":"red wine", "amount":"1/8", "units":"cup", "description":"Red wine"}], "directions": ["Place all ingredients in a (preferably nonstick) pan and let sit for a few minutes.", "Then cook covered over medium heat for about three minutes until they are soft.", "Remove the cover and cook until the liquid is almost gone, then serve."]}, {"name":"Barbecued Eggplant", "num_served":2, "ingredients": [{"name":"eggplant", "amount":"1", "units":"", "description":"eggplant"}, {"name":"barbecue sauce", "amount":"1/4", "units":"cup", "description":"Eggplant Barbecue Sauce salt"}], "directions": ["Preheat the oven to 350 degrees. Peel and cut the eggplant into 1/3-inch thick slices. Salt the slices. Place on a rack or colander and let stand for 30 minutes. Wipe off salt with a clean kitchen towel. Lay the slices out on a lightly oiled baking sheet. Brush on barbecue sauce. Bake for 15 minutes. Turn over, brush with barbecue sauce, and bake for 15 minutes more or until the eggplant is tender but not mushy."]}, {"name":"Lemon Sesame Broccoli", "num_served":4, "ingredients": [{"name":"broccoli", "amount":"2", "units":"cup", "description":"Broccoli"}, {"name":"sesame oil", "amount":"2", "units":"teaspoon", "description":"Sesame oil"}, {"name":"lemon juice (fresh)", "amount":"1/2", "units":"tablespoon", "description":"fresh lemon juice"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"black pepper"}, {"name":"salt", "amount":"1", "units":"teaspoon", "description":"Salt"}], "directions": ["Cut flowerets off of the broccoli and cut into small pieces.", "Cut the stems into very thin round pieces so they will cook quickly.", "Put the broccoli stems into boiling water in saucepan, cover and cook for 3 minutes.", "Add flowerets, cover and cook 5 minutes, and then drain all broccoli and place in a serving bowl.", "Mix broccoli well with the sesame oil, lemon juice, salt, and black pepper. Eat immediately"]}, {"name":"Cauliflower and Broccoli Pizza Crust", "num_served":4, "ingredients": [{"name":"cauliflower", "amount":"5", "units":"cup", "description":"Broccoli"}, {"name":"Optional: broccoli", "amount":"1", "units":"cup", "description":"Broccoli"}, {"name":"fresh garlic (peeled and coarsely chopped)", "amount":"1", "units":"", "description":"Cloves garlic,crushed"}, {"name":"parmesan cheese", "amount":"1/4", "units":"cup", "description":"parmesan cheese"}, {"name":"mozzarella cheese (finely chopped)", "amount":"1/4", "units":"cup", "description":"mozzarella cheese"}, {"name":"dried basil", "amount":"1", "units":"teaspoon", "description":"basil"}, {"name":"black pepper", "amount":"1/4", "units":"teaspoon", "description":"black pepper"}, {"name":"salt", "amount":"1/4", "units":"teaspoon", "description":"Salt"}, {"name":"Optional: red pepper flakes", "amount":"1/2", "units":"teaspoon", "description":"red pepper flakes"}, {"name":"egg", "amount":"1", "units":"", "description":"egg"}, {"name":"olive oil", "amount":"1/2", "units":"teaspoon", "description":"olive oil"} ], "directions": ["This crust contains no wheat or other grains: very healthy and very tasty!", "You will need parchment (baking) paper to make this recipe. Preheat oven to 425F. Place either a pizza stone or a large baking pan in the oven. Note: 1 medium large cauliflower is about 5 cups, coarsely chopped.", "This recipe is just for the pizza crust. It is delicious! The broccoli is optional; in its place you can use a little more cauliflower. However, this is a good way to get people (kids!) to eat vegetables, so sneak in a little broccoli.", "Chop up the cauliflower, broccoli, and garlic. Put in a food processor and spend a few minutes getting it all chopped to a very fine consistency. Transfer to a bowl.", "This finely chopped mixture now needs to be broken down by cooking in a microwave oven for about 3 minutes. Cover the bowl in the microwave oven.", "You will need to get the water out of the mixture: get a clean dish towel and spread it over a large cutting board. Dump the hot mixture in the center of the towel and then let it sit for about 5 minutes to cool down.", "Carefully fold up the dish towel to avoid spilling any of the mixture and over the sink \"wring out\" as much water as you can. I spend about two minutes doing this.", "Return the (almost dry) mixture to the bowel (wipe it out first if there is much moisture in it) and add the mozzarella cheese, parmesan cheese, dried basil, peper, salt, and (optional) red pepper flakes.", "Blend everything together, then add a raw egg and mix together.", "Cut a piece of parchment paper, put it on a cutting board and poor the olive oil in the center. You should have the bowl of mixed ingredients right beside the parchment paper for easy access.", "With your (washed) hands, spread out the oil on the parchment paper into abut a 10 inch circle, pick up the mixture in the bowl with your hands and place it on the paper. Push the mixture down to make a circle about 3/8 of an inch high. With your fingers, push the edges of the pizza dough back towards the center a bit if there are areas where the material is thin. Try to get the same height.", "You will carefully slide the parchment paper onto the pizza stone (or baking sheet) in the oven. I don't worry too much about letting heat out of the oven so I do this process slowly and carefully: to avoid burning myself I like to pull the oven rack abut 1/3 of the way out of the oven to make it safer to slide the parchment paper onto the pizza stone.", "Shut the oven and cook for about 10 minutes. It will be cooked more later after you put sauce on the crust.", "Take the entire pizza stone (or baking sheet) out of the oven and place it on top of the stove. Add your favorite pizza sauce and toppings and then put it back in the oven and bake the pizza for another 8 minutes.", "IDEAS FOR PIZZA TOPPING: I like to use a small amount of marinara sauce, chopped onion, and cheese. The pizza crust is very good on its own, so you can go light on the toppings."], "pictures": [ ["cauliflower_pizza_crust_1", "       Cooling crust mixture"], ["cauliflower_pizza_crust_2", "       Crust formed, in oven"], ["cauliflower_pizza_crust_3", "       Pizza topping added."], ["cauliflower_pizza_crust_4", "       Cooked pizza"] ] } ] ================================================ FILE: cooking_recipes/data.py ================================================ import json def process_json(fpath): with open(fpath, 'r') as f: data = json.load(f) for d in data: with open(f"text_data/{d['name']}.txt", 'w') as f: f.write("Recipe name: " + d['name'] + '\n\n') f.write("Number of servings: " + str(d['num_served']) + '\n\n') ingrediants = [" " + str(ii['amount']) + ' ' + ii['units'] + ' ' + ii['description'] for ii in d['ingredients']] f.write("Ingredients:\n" + "\n".join(ingrediants) + '\n\n') f.write("Directions: " + ' '.join(d['directions']) + '\n') if __name__ == "__main__": process_json('data/vegetarian.json') process_json('data/desert.json') process_json('data/fish.json') process_json('data/meat.json') process_json('data/misc.json') ================================================ FILE: cooking_recipes/recipe_generator.py ================================================ # This example uses code from https://python.langchain.com/docs/get_started # on macOS: pip install faiss-cpu from langchain_community.vectorstores import FAISS from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_openai import OpenAIEmbeddings from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI from langchain_community.document_loaders import DirectoryLoader llm = ChatOpenAI() embeddings = OpenAIEmbeddings(model="text-embedding-3-large") text_splitter = RecursiveCharacterTextSplitter() #documents = text_splitter.split_documents(docs) embeddings = OpenAIEmbeddings() loader = DirectoryLoader('./text_data/', glob="**/*.txt") documents = loader.load() vector = FAISS.from_documents(documents, embeddings) from langchain.chains import create_retrieval_chain from langchain.chains.combine_documents import create_stuff_documents_chain prompt = ChatPromptTemplate.from_template("""Answer the following question based only on the provided context: {context} Question: {input}""") document_chain = create_stuff_documents_chain(llm, prompt) retriever = vector.as_retriever() retrieval_chain = create_retrieval_chain(retriever, document_chain) response = retrieval_chain.invoke({"input": "Create a new recipe using both Broccoli"}) print(response["answer"]) response = retrieval_chain.invoke({"input": "Create a recipe using Beans, Rice, and Chicken"}) print(response["answer"]) ================================================ FILE: cooking_recipes/text_data/Aioli Sauce.txt ================================================ Recipe name: Aioli Sauce Number of servings: 8 Ingredients: 3 unit Egg yolks 4 clove Cloves garlic 1 tablespoon Lemon juice 1/3 teaspoon Salt 1/4 teaspoon Tabasco 1/4 teaspoon Worcestershire sauce 1/4 teaspoon Freshly ground black pepper 1/4 cup Mayonnaise 3/4 cup Extra virgin olive oil 3 tablespoon Boiling water Directions: Blend together the egg yolks, garlic, lemon, salt and pepper in a blender or food processor for about 2 minutes. Very slowly add the oil and mayonnaise while continuing to blend the mixture. Add the seasonings and mix together. Add the boiling water, stir well, and refrigerate for later use. ================================================ FILE: cooking_recipes/text_data/Apple Muffins.txt ================================================ Recipe name: Apple Muffins Number of servings: 10 Ingredients: 1 Egg 1/2 cup Milk 1/4 cup Vegetable oil 1/2 cup Applesauce 1 1/2 cup Flour 3/4 cup Sugar 2 teaspoon Baking powder 1/2 teaspoon Cinnamon 1/2 teaspoon Salt Directions: preheat oven to 375F. Beat egg in a bowl and then stir in milk, oil, and the applesauce. Then mix in the flour, most of the brown sugar, baking powder, cinnamon, and salt until everything is moist. Place batter in paper baking cups - about half to two thirds full. Sprinkle remainder of brown sugar top of muffins. Bake 25 to 30 minutes. ================================================ FILE: cooking_recipes/text_data/Balsamic Mushrooms.txt ================================================ Recipe name: Balsamic Mushrooms Number of servings: 3 Ingredients: 12 medium Mushrooms 1/4 cup Balsamic vinegar 1/8 cup Red wine Directions: Place all ingredients in a (preferably nonstick) pan and let sit for a few minutes. Then cook covered over medium heat for about three minutes until they are soft. Remove the cover and cook until the liquid is almost gone, then serve. ================================================ FILE: cooking_recipes/text_data/Barbecued Chicken.txt ================================================ Recipe name: Barbecued Chicken Number of servings: 2 Ingredients: 2 unit Boneless chicken breasts 2 tablespoon Soy sauce 2 tablespoon White wine 1 tablespoon Vegetable oil 1 tablespoon Cornstarch Directions: Mix together all of the sauce ingredients and pour half the sauce over chicken, coating the chicken on all sides. Let this stand for a while and then put the chicken on your barbeque (charcoal or gas grill works fine). Brush the sauce over the top of the chicken and grill for about 10 minutes, then turn over and apply more barbeque sauce on the top Be careful to not burn the chicken. Before removing from the grill, cut into a thick piece and make sure it is done. ================================================ FILE: cooking_recipes/text_data/Barbecued Eggplant.txt ================================================ Recipe name: Barbecued Eggplant Number of servings: 2 Ingredients: 1 eggplant 1/4 cup Eggplant Barbecue Sauce salt Directions: Preheat the oven to 350 degrees. Peel and cut the eggplant into 1/3-inch thick slices. Salt the slices. Place on a rack or colander and let stand for 30 minutes. Wipe off salt with a clean kitchen towel. Lay the slices out on a lightly oiled baking sheet. Brush on barbecue sauce. Bake for 15 minutes. Turn over, brush with barbecue sauce, and bake for 15 minutes more or until the eggplant is tender but not mushy. ================================================ FILE: cooking_recipes/text_data/Barbecued Salmon with Basil.txt ================================================ Recipe name: Barbecued Salmon with Basil Number of servings: 4 Ingredients: 4 unit Salmon steaks 2 tablespoon Olive oil 1 teaspoon Dried and crushed basil 1 Lemon wedges Directions: Mix the juice from half the lemon, olive oil and basil and thoroughly coat the salmon with this mixture. Cook the salmon over hot coals (or a gas grill) for about 5 minutes per side. Remove fish from barbeque and test for doneness. Serve with the remaining half lemon cut into thin wedges. ================================================ FILE: cooking_recipes/text_data/Basil Vinaigrette Salad Dressing.txt ================================================ Recipe name: Basil Vinaigrette Salad Dressing Number of servings: 12 Ingredients: 1/4 cup balsamic vinegar 1/4 teaspoon dried basil (or 1/2 tsp fresh) 1/4 teaspoon Dried oregano (or 1/2 tsp fresh) 1 tablespoon Olive Oil Directions: Mix all ingredients in a bowl. Let sit at least 2 or 3 minutes before using on a salad. Refrigerate extra dressing for future use. ================================================ FILE: cooking_recipes/text_data/Black Bean Dip.txt ================================================ Recipe name: Black Bean Dip Number of servings: 6 Ingredients: 2 cup Refried Black Beans (see rec.) 1/4 cup Sour cream 1 teaspoon Ground cumin 1/2 cup Salsa Directions: Use either a food processor or a mixing bowl and hand mixer to make this appetizer. Blend the black beans and cumin for at least one minute until the mixture is fairly smooth. Stir in salsa and sour cream and lightly mix. Serve immediately or store in the refrigerator. ================================================ FILE: cooking_recipes/text_data/Borscht.txt ================================================ Recipe name: Borscht Number of servings: 4 Ingredients: 2 cup Beets 1 Onion 2 clove Garlic clove 2 quart Water 2 teaspoon Salt 3 tablespoon Sugar 1/4 cup Lemon juice Directions: Wash and peel beets and thickly slice so they cook faster. Peel the onion and garlic cloves. Leave the onion and garlic cloves whole since we will be removing them later. Mix everything except the lemon juice and sugar in a large covered pot and cook over low heat for one hour. Add the sugar and lemon juice. Cook an additional thirty minutes, remove from heat and let cool. Discard the onion and garlic and use a hand mixer to blend into a cold soup. Optional: place a small spoonful of sour cream on top of each serving. ================================================ FILE: cooking_recipes/text_data/Brined Barbecued Chicken.txt ================================================ Recipe name: Brined Barbecued Chicken Number of servings: 2 Ingredients: 2 unit Boneless chicken breasts 4 tablespoon Soy sauce 4 tablespoon White wine 2 tablespoon Vegetable oil 2 tablespoon Cornstarch Directions: Mix together all of the sauce ingredients. Put half the sauce in a large pan of cold water, add two additional tablespoons of salt, and stir. Add the chicken and store in the refrigerator overnight. Before barbequeing, remove the chicken from the brine solution and pour half of the sauce (made the day before) over chicken, coating the chicken on all sides. Put the chicken on your barbeque (charcoal or gas grill works fine). Brush the sauce over the top of the chicken and grill for about 10 minutes, then turn over and apply more barbeque sauce on the top Be careful to not burn the chicken. Before removing from the grill, cut into a thick piece and make sure it is done. NOTE: it is important to use cold water for brining and immediately refrigerate the brine after adding the chicken. ================================================ FILE: cooking_recipes/text_data/Cauliflower and Broccoli Pizza Crust.txt ================================================ Recipe name: Cauliflower and Broccoli Pizza Crust Number of servings: 4 Ingredients: 5 cup Broccoli 1 cup Broccoli 1 Cloves garlic,crushed 1/4 cup parmesan cheese 1/4 cup mozzarella cheese 1 teaspoon basil 1/4 teaspoon black pepper 1/4 teaspoon Salt 1/2 teaspoon red pepper flakes 1 egg 1/2 teaspoon olive oil Directions: This crust contains no wheat or other grains: very healthy and very tasty! You will need parchment (baking) paper to make this recipe. Preheat oven to 425F. Place either a pizza stone or a large baking pan in the oven. Note: 1 medium large cauliflower is about 5 cups, coarsely chopped. This recipe is just for the pizza crust. It is delicious! The broccoli is optional; in its place you can use a little more cauliflower. However, this is a good way to get people (kids!) to eat vegetables, so sneak in a little broccoli. Chop up the cauliflower, broccoli, and garlic. Put in a food processor and spend a few minutes getting it all chopped to a very fine consistency. Transfer to a bowl. This finely chopped mixture now needs to be broken down by cooking in a microwave oven for about 3 minutes. Cover the bowl in the microwave oven. You will need to get the water out of the mixture: get a clean dish towel and spread it over a large cutting board. Dump the hot mixture in the center of the towel and then let it sit for about 5 minutes to cool down. Carefully fold up the dish towel to avoid spilling any of the mixture and over the sink "wring out" as much water as you can. I spend about two minutes doing this. Return the (almost dry) mixture to the bowel (wipe it out first if there is much moisture in it) and add the mozzarella cheese, parmesan cheese, dried basil, peper, salt, and (optional) red pepper flakes. Blend everything together, then add a raw egg and mix together. Cut a piece of parchment paper, put it on a cutting board and poor the olive oil in the center. You should have the bowl of mixed ingredients right beside the parchment paper for easy access. With your (washed) hands, spread out the oil on the parchment paper into abut a 10 inch circle, pick up the mixture in the bowl with your hands and place it on the paper. Push the mixture down to make a circle about 3/8 of an inch high. With your fingers, push the edges of the pizza dough back towards the center a bit if there are areas where the material is thin. Try to get the same height. You will carefully slide the parchment paper onto the pizza stone (or baking sheet) in the oven. I don't worry too much about letting heat out of the oven so I do this process slowly and carefully: to avoid burning myself I like to pull the oven rack abut 1/3 of the way out of the oven to make it safer to slide the parchment paper onto the pizza stone. Shut the oven and cook for about 10 minutes. It will be cooked more later after you put sauce on the crust. Take the entire pizza stone (or baking sheet) out of the oven and place it on top of the stove. Add your favorite pizza sauce and toppings and then put it back in the oven and bake the pizza for another 8 minutes. IDEAS FOR PIZZA TOPPING: I like to use a small amount of marinara sauce, chopped onion, and cheese. The pizza crust is very good on its own, so you can go light on the toppings. ================================================ FILE: cooking_recipes/text_data/Chicken Cacciatore.txt ================================================ Recipe name: Chicken Cacciatore Number of servings: 4 Ingredients: 2 Pieces chicken 2 Crushed tomatoes 2 teaspoon Sugar 2 teaspoon Salt 1 teaspoon Pepper 1 teaspoon Butter 2 tablespoon Oil 1 teaspoon Rosemary Directions: Wash the chicken and cook it for 5 minutes a side with butter, oil, and rosemary in a large skillet under medium heat. Then cut up the tomatoes and mix in with the cooking chicken chicken. Add the basil, sage, rosemary and parsley, sugar, salt, and pepper. Cover and cook on low to medium heat for about two hours. Check chicken for doneness before serving ================================================ FILE: cooking_recipes/text_data/Chicken Schnitzel.txt ================================================ Recipe name: Chicken Schnitzel Number of servings: 6 Ingredients: 2 pounds Chicken Breasts 4 unit Eggs 1.5 cup Flour 1 cup Bread Crumbs 5 tablespoon Vegetable oil Directions: Slice Chicken Breasts 2 parts so each piece is as large an area and thin as possible. Remove skin and any excess fat. Optional: place on a cutting board and pound flatter. Dip chicken in beaten eggs, roll in flour, then in bread crumbs. Heat oil in a (preferably nonstick) frying pan. Fry the Schnitzel on each side until golden brown and the chicken is done (cut into chicken to make sure it is cooked). ================================================ FILE: cooking_recipes/text_data/Chicken with Cream of Mushroom Soup.txt ================================================ Recipe name: Chicken with Cream of Mushroom Soup Number of servings: 2 Ingredients: 2 Pieces chicken 1 tablespoon Oil 1/2 cup Pint sour cream 1/2 teaspoon Salt 1/4 teaspoon Pepper 1 can Cream of mushroom soup (I use Campbell's) Directions: Heat oil in a non-stick frying pan with medium heat. Lightly brown the chicken, about minutes per side. Mix in the salt, pepper, and soup, then cover, and cook under low heat for about 30 minutes, stirring occasionally. Mix in the sour cream, cook for another 5 minutes. Make sure the chicken is done and tender before serving. ================================================ FILE: cooking_recipes/text_data/Chinese Shrimp with Zucchini Squash.txt ================================================ Recipe name: Chinese Shrimp with Zucchini Squash Number of servings: 2 Ingredients: 14 medium-large medium shrimp 1 tablespoon Cornstarch 1/2 teaspoon Salt 1/2 teaspoon Pepper 2 cup Zucchini 2 tablespoon Oil 1 tablespoon Sherry 1 tablespoon Soy sauce Directions: I vary the proportion of shrimp to Zucchini squash depending on both my tastes and how much shrimp and Zucchini I have on-hand that I want to use up. Shell and chop the shrimps into three or four pieces and roll in cornstarch, salt and pepper - use a small bowl for this. Wash the zucchini and coarsely chop. Heat the oil in a non-stick pan and fry Zucchini until it is mostly done before adding the shrimp and the sherry. When the shrimp are done then mix in the soy sauce and serve immediately. Note: I like to eat this dish as-is but you might want to also try serving it with cooked Chinese style noodles or even a small amount of cooked Italian pasta. ================================================ FILE: cooking_recipes/text_data/Crock Pot Lemon Honey Chicken.txt ================================================ Recipe name: Crock Pot Lemon Honey Chicken Number of servings: 4 Ingredients: 1 Roaster Chicken 1/2 cup Water 2 Lemon 1/2 teaspoon Salt 1/2 teaspoon Pepper 1/4 cup Honey Directions: Wash the Chicken and trim off excess fat. Put the washed chicken in a crock pot and squeeze the juice from one lemon over the chicken. Then sprinkle the salt and pepper over the chicken, and finally pour the honey over the chicken. Cook the chicken on low heat until done. After serving the chicken, squeeze some juice from the second lemon over each portion. ================================================ FILE: cooking_recipes/text_data/Curried Chicken Legs.txt ================================================ Recipe name: Curried Chicken Legs Number of servings: 8 Ingredients: 8 Chicken legs 4 teaspoon Curry powder 1 Cloves garlic,crushed 2 tablespoon Oil 1/2 cup Plain yogurt 3 tablespoon Lemon juice 2 teaspoon Packed brown sugar Directions: Preheat oven to 400F. Cut at joint into thighs and drumsticks. You can also but just thighs or the drumbsticks as to your prefenerence, adjusted the recipe. Trim any hanging fat and excess skin from chicken. Heat half of the oil in a small non-stick pan and slowly add in the curry powder, mixing well. Then immediately add the peeled and finely chopped garlic. Cook over medium heat for a few minutes until the garlic softens. Put the contents of the pan into a large bowl, then mixing in yogurt, lemon juice and brownsugar. Add chicken, rolling it around to thoroughly coat. Let this then sit at room temperature for at least 10 minutes. Line a baking sheet with aluminum foil (always with the shiny side up) and use the remaining half of the oil to greese the foil. Put the chicken on the sheet skin side down and cover the chcken with the remaining sauce from the large bowl. Bake for about 40 minutes. Check chicken for doneness before serving with either rice or pita bread. Optional: serve with Chutney sauce, yogurt, and/or sour cream. Pro tip: make enough for leftovers for lunch the next day! ================================================ FILE: cooking_recipes/text_data/Curried Yogurt Dip.txt ================================================ Recipe name: Curried Yogurt Dip Number of servings: 6 Ingredients: 1 cup Plain Yogurt 1.5 teaspoon Curry powder 1/2 teaspoon Hot pepper sauce 1 teaspoon Lemon juice 1/2 teaspoon Honey 1/4 teaspoon Black pepper 1/4 teaspoon Salt 3 tablespoon almonds Directions: Combine ingredients (except almonds!) stirring well. Divide into four small serving bowls. Set aside for about 15 minutes at room temperature before serving. Then, finely chop almonds are sprinkle on top of the yogurt dip. Place the small bowls containing the dip on larger plates with cut up fresh vegetables and/or chips. ================================================ FILE: cooking_recipes/text_data/Dijon Sour Cream Dip.txt ================================================ Recipe name: Dijon Sour Cream Dip Number of servings: 6 Ingredients: 1 cup Sour cream OR Plain yogurt 1/3 cup Mayonnaise 1/4 cup Dijon mustard 1 tablespoon Finely-chopped green onion 0.25 teaspoon Seasoned salt 1/4 teaspoon Black pepper Directions: Mix all ingredients, cover and store in the refrigerator for at least 30 minutes before serving. Serve dip into small bowls containing and place on larger plates with cut up fresh vegetables and/or chips. ================================================ FILE: cooking_recipes/text_data/Dijon Yogurt Dip.txt ================================================ Recipe name: Dijon Yogurt Dip Number of servings: 6 Ingredients: 1 cup Sour cream OR Plain yogurt 1/3 cup Mayonnaise 1/4 cup Dijon mustard 2 tablespoon Finely-chopped green onion 0.5 teaspoon Seasoned salt 1/4 teaspoon Black pepper Directions: Mix all ingredients, cover and store in the refrigerator for at least 30 minutes before serving. Serve dip into small bowls containing and place on larger plates with cut up fresh vegetables and/or chips. ================================================ FILE: cooking_recipes/text_data/Easy Cake.txt ================================================ Recipe name: Easy Cake Number of servings: 8 Ingredients: 1 cup Butter 2 cup Sugar 3 cup Flour 4 Eggs 5 teaspoon Baking powder 1 cup Milk 1 teaspoon Vanilla extract Directions: Preheat oven to 350F. Mix together butter, sugar, eggs and vanilla extract in a mixing bowl. Mix in milk and then baking powder. Mix in flour, stirring lightly. Bake for 30 minutes. ================================================ FILE: cooking_recipes/text_data/English Scones.txt ================================================ Recipe name: English Scones Number of servings: 6 Ingredients: 2.5 cup Flour 1 teaspoon Cream of tartar 1 teaspoon Baking soda 3 tablespoon Sugar 1/2 teaspoon Salt 1/2 cup Butter 1 cup Milk Directions: Preheat oven to 400F. Mix flour, cream of tartar, baking soda, sugar, and salt together. Slowly mix in the butter and when all of the butter is mixed in the mix in the milk. Form into three round balls on floured board and then flatten. Partially cut through each of the three portions to make four pie-like portions. Bake for 15 minutes. Cool for a few minutes then serve immediateley. ================================================ FILE: cooking_recipes/text_data/Fresh Tomato Sauce.txt ================================================ Recipe name: Fresh Tomato Sauce Number of servings: 4 Ingredients: 12 Tomatoes 2 tablespoon Sugar 1 teaspoon black pepper 1 teaspoon Salt 1 cup Fresh basil Directions: Place all ingredients in heavy saucepan or dutch oven and bring to a slow boil. Lower heat and cook covered for 40 minutes, stirring occasionally. I suggest using a small amount for a meal immediately (with cooked pasta) and freezing most of it for future meals. This is a great recipe to use up extra tomatoes from your garden or when tomatoes are in season and inexpensive to buy. ================================================ FILE: cooking_recipes/text_data/Fried Chicken.txt ================================================ Recipe name: Fried Chicken Number of servings: 3 Ingredients: 1 Frying chickens 1/4 cup Flour 1/2 teaspoon Salt 1/2 teaspoon Pepper 1/2 teaspoon Cayenne pepper 4 tablespoon Butter 8 tablespoon Vegetable oil Directions: Mix flour, salt and pepper in bag, add chicken and shake. Heat oil in a large skillet on high. Brown chicken on skin side. Turn over the chicken, reducing the heat to medium and brown other side. Turn over and cook over lower heat until the chicken is tender when stuck with a fork. Drain off oil and serve. ================================================ FILE: cooking_recipes/text_data/Homemade Salad Dressing.txt ================================================ Recipe name: Homemade Salad Dressing Number of servings: 16 Ingredients: 1 teaspoon Salt 1/4 teaspoon Black Pepper 1/2 teaspoon Paprika 1 pinch Dry Mustard 1 teaspoon Sugar 1/2 cup Olive Oil 1/4 cup Wine Vinegar 2 clove Clove Garlic Directions: Dissolve sugar, salt, pepper, paprika, and dry mustard in olive oil. Stir in vinegar. Peel and mince garlic and and add to dressing. ================================================ FILE: cooking_recipes/text_data/Honey Chinese Shrimp.txt ================================================ Recipe name: Honey Chinese Shrimp Number of servings: 4 Ingredients: 1/4 cup Honey 16 1/4 cup Red wine 2 tablespoon Sesame oil 1.5 tablespoon Soy Sauce 1 teaspoon Worcestershire 2 teaspoon Sriracha Hot Chili Sauce 1/4 cup Orange juice 1/4 teaspoon Black pepper Directions: Mix together all ingredients and marinate in the refrigerator for at least one hour. There are two ways to cook this dish: 1. Barbecue on a grill, occasionally basting with more marinade. 2. Remove shrimp from marinade sauce and fry in a hot non-stick frying pan. This is good served over brown or white rice with a side of steamed vegetables. ================================================ FILE: cooking_recipes/text_data/Honey-Curried Chicken.txt ================================================ Recipe name: Honey-Curried Chicken Number of servings: 6 Ingredients: 2 pound Chicken breasts 2 teaspoon Vegetable oil 1/4 cup Orange juice 1/4 cup Honey 1 tablespoon Dijon mustard 2 teaspoon Curry powder pinch cayenne pepper 1/4 teaspoon cayenne pepper Directions: preheat oven to 400F Grease a baking dish vegetable oil. Remove skin from chicken. Arrange chicken in a single layer bone side down if you are not using boneless chicken breasts. Mix the remaining ingredients in a small bowl and pour 2/3 over the chicken. Bake chicken covered for 10 minutes (15 minutes if bones in chicken breasts), basting once. Turn chicken over and baste with the remaining sauce. Bake, now uncovered, for 15 minutes (20 minutes if bones in chicken breasts) longer. Test chicken for doneness and tenderness before serving. ================================================ FILE: cooking_recipes/text_data/Indonesian Barbecue Sauce.txt ================================================ Recipe name: Indonesian Barbecue Sauce Number of servings: 12 Ingredients: 1/2 cup Corn syrup (dark) 1/4 cup Creamy peanut butter 1/4 cup Soy sauce 1/4 cup Cider vinegar 1/4 cup Sliced green onions 4 clove garlic 1 teaspoon Clove 2 teaspoon Ginger 1 teaspoon Crushed dried red pepper Directions: Mix together all ingredients and let sit for at least one hour before using. Refrigerate or freeze any unused barbecue sauce for future use. ================================================ FILE: cooking_recipes/text_data/Indonesian Chicken Sate.txt ================================================ Recipe name: Indonesian Chicken Sate Number of servings: 4 Ingredients: 4 Skinless, boneless chicken breast halves (about 1 1/2 pounds) 1/4 cup Reduced-sodium soy sauce 1 Fresh lemon juice 1 tablespoon Dark molasses 1 teaspoon Red Pepper Flakes 1 tablespoon Garlic Powder Granules 1 tablespoon Ginger Directions: Cut breasts into long 1 inch strips. Put the chicken and all of the other ingredients into a large bowl and mix well making sure the chicken is well coated. Cover the bowl and refrigerate for two hours or longer. Stir up the bowl a few times while the chicken is marinating. You can use either a (gas or charcoal) grill or the broiler in your oven to cook the Sate. Optional: skewer the chicken strips on wet bamboo skewers - or you can cook the chicken loose if you don't have skewers. Broil or grill about 4 minutes on each side, occasionally applying more marinade. Optional: if you have any available, serve with Indonesian or Thai peanut sauce, or chutney. ================================================ FILE: cooking_recipes/text_data/Irene's Snickerdoodle Cookies.txt ================================================ Recipe name: Irene's Snickerdoodle Cookies Number of servings: 10 Ingredients: 1 cup Shortening 1 3/4 cup Sugar 2 Eggs 3 cup Flour 2 teaspoon Cream of tartar 1 teaspoon Soda 1/4 teaspoon Salt 1 dash Cinnamon sugar Directions: preheat oven to 375F. Mix together the vegetable shortening, sugar and eggs in a small mixing bowl. Sift together flour and mix well with the cream of tartar, soda and salt. Mix together both mixtures and roll into balls about one inch in diameter and roll in cinnamon and sugar. Put on a lightly greased baking sheet, leaving about 1 1/2 inches between the cookies. Bake from 10 to 12 minutes until done. ================================================ FILE: cooking_recipes/text_data/Japanese Ginger Salad Dressing.txt ================================================ Recipe name: Japanese Ginger Salad Dressing Number of servings: 4 Ingredients: 1 tablespoon Rice vinegar 2 teaspoon Vegetable oil 1.5 tablespoon Sesame oil 1 tablespoon Grated fresh ginger 1 teaspoon Soy sauce Directions: Mix all ingredients together and let sit for at least 10 minutes before using. Some of the ingredients will settle so make sure you stir well before pouring over salad. ================================================ FILE: cooking_recipes/text_data/Lemon Sesame Broccoli.txt ================================================ Recipe name: Lemon Sesame Broccoli Number of servings: 4 Ingredients: 2 cup Broccoli 2 teaspoon Sesame oil 1/2 tablespoon fresh lemon juice 1/4 teaspoon black pepper 1 teaspoon Salt Directions: Cut flowerets off of the broccoli and cut into small pieces. Cut the stems into very thin round pieces so they will cook quickly. Put the broccoli stems into boiling water in saucepan, cover and cook for 3 minutes. Add flowerets, cover and cook 5 minutes, and then drain all broccoli and place in a serving bowl. Mix broccoli well with the sesame oil, lemon juice, salt, and black pepper. Eat immediately ================================================ FILE: cooking_recipes/text_data/Poached Salmon with Wine and Lemon.txt ================================================ Recipe name: Poached Salmon with Wine and Lemon Number of servings: 4 Ingredients: 1/4 cup Lemon juice 1/4 cup Dry white wine 4 Salmon fillets 1/4 teaspoon Salt 1/4 teaspoon Pepper 1/4 cup Water Directions: Use a heavy frying pan with a cover or small dutch oven to make this. Over medium heat bring the lemon juice and wine to a boil, adding in the salt and pepper, then water. Add salmon 'bad looking side' down and cover the pan. Poach salmon for 7 or 8 minutes. The fish should easily flake when it is done. Remove from the pan and eat immediately. ================================================ FILE: cooking_recipes/text_data/Quick Sweet and Sour Sauce.txt ================================================ Recipe name: Quick Sweet and Sour Sauce Number of servings: 8 Ingredients: 1 cup White vinegar 2/3 cup Sugar 2 tablespoon Ketchup 2 tablespoon fresh ginger 1/4 teaspoon Salt 1/4 teaspoon Tabasco sauce Directions: Use a medium size pan to combine the vinegar, sugar, ketchup, ginger, salt and tabasco sauce and bring to a boil under high heat. Cook until the sauce is reduced to a fairly thick sauce. You don't want the sauce to be runny but you also don't want it to be too thick. Pay attention while cooking the sauce! ================================================ FILE: cooking_recipes/text_data/Scottish Shortbread.txt ================================================ Recipe name: Scottish Shortbread Number of servings: 10 Ingredients: 4 cup Plain flour 2 cup Butter (nothing else will do) 1/2 cup Sugar 1 dash Salt Directions: Preheat oven to 350F Sift flour on a large board. Place the sugar in a separate area on the board and mix in the butter. Knead in flour adding small amounts at a time. Grease a baking sheet. Roll dough into small balls, about one inch in diameter. Flatten the balls and place on the baking sheet. Bake for 30 minutes. ================================================ FILE: cooking_recipes/text_data/Simple Italian Chicken.txt ================================================ Recipe name: Simple Italian Chicken Number of servings: 4 Ingredients: 2 lb Skinned chicken breasts 2 tablespoon Olive oil 2 tablespoon Lemon juice 2 Cloves garlic,crushed 1/2 teaspoon Oregano 4 tablespoon Dry white wine Directions: Preheat oven to 375F. Grease a deep baking pan with half of the olive oil. Mix all remaining ingredients except the chicken in the baking dish and stir together. Wash the chicken and place in the baking dish, rolling the chicken to coat it with the mixture. Cover the baking dish and cook for 45 minutes. Optional: uncover the baking dish the last 15 minutes. Test the chicken for doneness and tenderness before serving. ================================================ FILE: cooking_recipes/text_data/Spicy Barbecued Chicken.txt ================================================ Recipe name: Spicy Barbecued Chicken Number of servings: 4 Ingredients: 1 chicken (2 lb) 1 Juice of 1 lemon 2 Cloves garlic 2 teaspoon Fresh ground black pepper 1 teaspoon Salt 2 teaspoon Ground cayenne pepper 1 teaspoon Paprika 2 tablespoon Melted butter Directions: Cut as much extra fat and loose skin as you can from the chicken. Later when you are grilling it this will help to minimize grease flames burning the chicken. Split the chicken by cutting down the backbone and opening it to leave the breast attached - flatten out as much as possible while still keeping the chicken in one piece. Squeeze the juice from the lemon on to the chicken. Mix together the cayenne pepper, black pepper, salt, peeled and crushed garlic, paprika and add to the melted butter; pur and rub this mixture over the chicken. Refrigerate the chicken (it can be uncovered) for at least an hour or two to let the spices set. Prepare a gas grill or charcoal grill. For a gas grill heat it to medium temperature. For a charcoal grill, use a modest amount of charcoal to avoid too high of cooking heat. Put the chicken breast side up onto the grill and cover the grill with the lid. Cook chicken for 30 minutes without turning it. Turn the chicken and cook uncovered for about another 5 to 10 minutes to crisp up the skin. Remove the chicken from the grill, cut into a thick area (thigh or breast) to make sure it is done, let it cool for 5 minutes and then serve. Note: if you substitute chicken parts like legs or breasts then the cooking time will be reduced; keep an eye on the chicken and test for doneness before serving. ================================================ FILE: cooking_recipes/text_data/Spicy Braised Chicken.txt ================================================ Recipe name: Spicy Braised Chicken Number of servings: 4 Ingredients: 1 teaspoon Red peppers 1 tablespoon Oil 1 teaspoon Salt 1 pound Chicken meat 1 tablespoon Fresh ginger 1 tablespoon Brown sugar 2 teaspoon Sherry 1 teaspoon Cornstarch 2 teaspoon Soy sauce Directions: Using a small bowl, mix the cornstarch to a smooth paste with the soy sauce and set aside. Cut up the chicken into small bite-size pieces. Over medium high heat add oil and fry the chicken and minced fresh ginger for 1 minute. Add in the mixed cornstarch and soy sauce and cook for another minute, stiring often. Add the sugar and sherry and cook for another minute. Test the chicken for doneness and then serve. ================================================ FILE: cooking_recipes/text_data/Tasty Black Bean Dip.txt ================================================ Recipe name: Tasty Black Bean Dip Number of servings: 4 Ingredients: 1.5 cup 16-0z can black beans 2 tablespoon Chopped red onion 1 tablespoon Balsamic vinegar 1 Clove garlic 1/2 cup Olive Oil Directions: You can use canned black beans (each 12 ounce can is about 1 1/2 cups) or cook dry beans according to package directions and then cool. Combine ingredients in the blender or food processor and mix for about 1 minute to either a fine or course consistency depending on your tastes and preferences. I like to serve this in small individual bowls place on a larger plate so there is plenty of room on each plate for pita bread, chips, and/or cut up raw vegetables. ================================================ FILE: cooking_recipes/text_data/Whole Wheat Bread.txt ================================================ Recipe name: Whole Wheat Bread Number of servings: 10 Ingredients: 1 1/2 cup Water 1 1/3 tablespoon Vegetable oil 1/4 cup Honey 1/2 teaspoon Salt 4 cup Whole wheat bread flour 3 teaspoon Yeast Directions: Lightly grease two 9x5 inch loaf pans. Blend all ingredients and then place on a large floured surface and knead for 5 or 6 minutes. Place in a covered bowl in a warm area and let it rise for about one hour. Preheat oven to 375F. Bake for 35 to 40 minutes. ================================================ FILE: data/chemistry.txt ================================================ Amyl alcohol is an organic compound with the formula C 5 H 12 O. All eight isomers of amyl alcohol are known. The most important is isobutyl carbinol, this being the chief constituent of fermentation amyl alcohol, and consequently a constituent of fusel oil. It can be separated from fusel oil by shaking with strong brine , separating the oily layer from the brine layer and it, the portion boiling between 125 and 140 °C. being collected. For further purification it may be shaken with hot lime water, the oily layer separated, dried with calcium chloride and fractionated, the fraction boiling between 128 and 132 °C only being collected. The 1730 definition of the word "chemistry", as used by Georg Ernst Stahl, meant the art of resolving mixed, compound, or aggregate bodies into their principles; and of composing such bodies from those principles.[15] In 1837, Jean-Baptiste Dumas considered the word "chemistry" to refer to the science concerned with the laws and effects of molecular forces.[16] This definition further evolved until, in 1947, it came to mean the science of substances: their structure, their properties, and the reactions that change them into other substances - a characterization accepted by Linus Pauling.[17] More recently, in 1998, the definition of "chemistry" was broadened to mean the study of matter and the changes it undergoes, as phrased by Professor Raymond Chang. The current model of atomic structure is the quantum mechanical model.[36] Traditional chemistry starts with the study of elementary particles, atoms, molecules,[37] substances, metals, crystals and other aggregates of matter. This matter can be studied in solid, liquid, or gas states, in isolation or in combination. The interactions, reactions and transformations that are studied in chemistry are usually the result of interactions between atoms, leading to rearrangements of the chemical bonds which hold atoms together. Such behaviors are studied in a chemistry laboratory. The chemistry laboratory stereotypically uses various forms of laboratory glassware. However glassware is not central to chemistry, and a great deal of experimental (as well as applied/industrial) chemistry is done without it. The transfer of energy from one chemical substance to another depends on the size of energy quanta emitted from one substance. However, heat energy is often transferred more easily from almost any substance to another because the phonons responsible for vibrational and rotational energy levels in a substance have much less energy than photons invoked for the electronic energy transfer. Thus, because vibrational and rotational energy levels are more closely spaced than electronic energy levels, heat is more easily transferred between substances relative to light or other forms of electronic energy. For example, ultraviolet electromagnetic radiation is not transferred with as much efficacy from one substance to another as thermal or electrical energy. ================================================ FILE: data/economics.txt ================================================ The Austrian School (also known as the Vienna School or the Psychological School ) is a Schools of economic thought|school of economic thought that emphasizes the spontaneous organizing power of the price mechanism. Austrians hold that the complexity of subjective human choices makes mathematical modelling of the evolving market extremely difficult (or Undecidable and advocate a "laissez faire" approach to the economy. Austrian School economists advocate the strict enforcement of voluntary contractual agreements between economic agents, and hold that commercial transactions should be subject to the smallest possible imposition of forces they consider to be (in particular the smallest possible amount of government intervention). The Austrian School derives its name from its predominantly Austrian founders and early supporters, including Carl Menger, Eugen von Böhm-Bawerk and Ludwig von Mises. Economics is the social science that analyzes the production, distribution, and consumption of goods and services. Political economy was the earlier name for the subject, but economists in the late 19th century suggested "economics" as a shorter term for "economic science" that also avoided a narrow political-interest connotation and as similar in form to "mathematics", "ethics", and so forth.[2] A focus of the subject is how economic agents behave or interact and how economies work. Consistent with this, a primary textbook distinction is between microeconomics and macroeconomics. Microeconomics examines the behavior of basic elements in the economy, including individual agents (such as households and firms or as buyers and sellers) and markets, and their interactions. Macroeconomics analyzes the entire economy and issues affecting it, including unemployment, inflation, economic growth, and monetary and fiscal policy. The professionalization of economics, reflected in the growth of graduate programs on the subject, has been described as "the main change in economics since around 1900".[93] Most major universities and many colleges have a major, school, or department in which academic degrees are awarded in the subject, whether in the liberal arts, business, or for professional study; see Master of Economics. Economics is the social science that studies the behavior of individuals, households, and organizations (called economic actors, players, or agents), when they manage or use scarce resources, which have alternative uses, to achieve desired ends. Agents are assumed to act rationally, have multiple desirable ends in sight, limited resources to obtain these ends, a set of stable preferences, a definite overall guiding objective, and the capability of making a choice. There exists an economic problem, subject to study by economic science, when a decision (choice) is made by one or more resource-controlling players to attain the best possible outcome under bounded rational conditions. In other words, resource-controlling agents maximize value subject to the constraints imposed by the information the agents have, their cognitive limitations, and the finite amount of time they have to make and execute a decision. Economic science centers on the activities of the economic agents that comprise society.[1] They are the focus of economic analysis.[2] The traditional concern of economic analysis is to gain an understanding of the processes that govern the production, distribution and consumption of goods and services in an exchange economy.[3] An approach to understanding these processes, through the study of agent behavior under scarcity, may go as s: An interesting Economist is Pauli Blendergast who teaches at the University of Krampton Ohio and is famouse for saying economics is bullshit. ================================================ FILE: data/health.txt ================================================ which requires that you sit at a desk all day. ; If you hate to talk politics, don't associate with people who love to talk politics, etc. Learn to live one day at a time. Every day, do something you really enjoy. Add an ounce of love to everything you do. Take a hot bath or shower (or a cool one in summertime) to relieve tension. Do something for somebody else. Focus on understanding rather than on being understood; on loving rather than on being loved. Do something that will improve your appearance. ; Looking better can help you feel better. Schedule a realistic day. ; Avoid the tendency to schedule back-to-back appointments; allow time between appointments for a breathing spell. Become more flexible. ; Some things are worth not doing perfectly and some issues are fine to compromise upon. Eliminate destructive self-talking I also felt they protected me from the hard road by interposing a layer of air between the sole of my foot and the pavement. So why was I sidelined with a heel injury for over two s? I listened to the manufacturer and changed my runners every 400 miles. Come to think of it, why do I see so many runners with lower extremity injuries in my office? The traditional answer to these questions has always been overuse often compounded by an underlying mechanical abnormality such as over-pronation or flat-feet. The treatment, along with modification of training, physiotherapy, stretching etc. has always included a close look at the runner's footwear, often with recommendations about motion control, stability, cushioning, orthotics or custom molded insoles. I do not recommend that you run your next half-marathon barefoot. But certainly, I predict that sooner or later, changes will come about in both shoe design and training. From the medical establishment's point of view, the prevention and treatment of running injuries must change to incorporate the concepts outlined above. In fact I view the ideas I've presented here as a major paradigm shift in sports medicine, the likes of which I have not seen in the last fifteen years. Of course, the major shoe companies have to own up and start introducing better shoes into their lines. adaptive immunity: The ability of the body to learn to fight specific infections after being exposed to the germs that cause them. addiction: Loss of control over indulging in a substance or performing an action or behavior, and continued craving for it despite negative consequences. adenosine triphosphate: An energy-storing molecule that is found in all human cells. Usually abbreviated as ATP. adequate intake: An of the amount of a nutrient needed by healthy people. The Adequate Intake is used when there isn’t enough information to set a recommended dietary allowance (RDA). agoraphobia: Fear and avoidance of public places and open spaces. amnesia: Unusual memory loss or forgetfulness. amputation: The surgical removal of a limb or other body part. anaerobic: Any process that doesn’t require oxygen. Often refers to a form of short, high intensity exercise, known as anaerobic exercise. anaerobic exercise: Exercise that improves the efficiency of energy-producing systems that do not rely on oxygen. Examples include sprinting and weight lifting. dry eye: Stinging, burning, or irritation that occurs when the eye doesn’t produce enough moisture. duct: A tube or vessel in the body which carries the secretion of a gland; Secretion examples are tears, breast milk, etc. upper airway resistance syndrome: Inhalation that requires undue extra exertion; this extra work may cause insomnia and daytime sleepiness. urea: A waste product of protein digestion and metabolism. ureter: The tube that connects each kidney to the bladder. urethra: The tube leading from the bladder through which urine is carried from the body. ================================================ FILE: data/sports.txt ================================================ Sport is generally recognised as activities based in physical athleticism or physical dexterity.[3] Sports are usually governed by rules to ensure fair competition and consistent adjudication of the winner. "Sport" comes from the Old French desport meaning "leisure", with the oldest definition in English from around 1300 being "anything humans find amusing or entertaining".[4] Other bodies advocate widening the definition of sport to include all physical activity and exercise. For instance, the Council of Europe include all forms of physical exercise, including those completed just for fun. ================================================ FILE: data_small/sports.txt ================================================ Sport is generally recognised as activities based in physical athleticism or physical dexterity.[3] Sports are usually governed by rules to ensure fair competition and consistent adjudication of the winner. "Sport" comes from the Old French desport meaning "leisure", with the oldest definition in English from around 1300 being "anything humans find amusing or entertaining".[4] Other bodies advocate widening the definition of sport to include all physical activity and exercise. For instance, the Council of Europe include all forms of physical exercise, including those completed just for fun. ================================================ FILE: embedchain_test/.gitignore ================================================ db ================================================ FILE: embedchain_test/README.md ================================================ # Creating an index python process_pdfs.py I hardwired the directory path for PDF files for my books in the file **process_pdfs.py** - change that for your system. # Querying the processed PDF files ``` $ python app.py How can I iterate over a list in Haskell? To iterate over a list in Haskell, you can use recursion or higher-order functions like `map` or `foldl`. How can I edit my Common Lisp files? To edit Common Lisp files, you can use Emacs with the Lisp editing mode. By setting the default auto-mode-alist in Emacs, whenever you open a file with the extensions ".lisp", ".lsp", or ".cl", Emacs will automatically use the Lisp editing mode. You can search for an "Emacs tutorial" online to learn how to use the basic Emacs editing commands. How can I scrape a website using Common Lisp? One way to scrape a website using Common Lisp is to use the Drakma library. Paul Nathan has written a library using Drakma called web-trotter.lisp, which is available under the AGPL license at articulate-lisp.com/src/web-trotter.lisp. This library can be a good starting point for your scraping project. Additionally, you can use the wget utility to make local copies of a website. The command "wget -m -w 2 http:/knowledgebooks.com/" can be used to mirror a site with a two-second delay between HTTP requests for resources. The option "-m" indicates to recursively follow all links on the website, and the option "-w 2" adds a two-second delay between requests. Another option, "wget -mk -w 2 http:/knowledgebooks.com/", converts URI references to local file references on your local mirror. Concatenating all web pages into one file can also be a useful trick. ``` ================================================ FILE: embedchain_test/app.py ================================================ # https://github.com/embedchain/embedchain from embedchain import App test_chat = App() def test(q): print(q) print(test_chat.query(q), "\n") #test("What is the Blackboard Metaphor?") test("How can I iterate over a list in Haskell?") test("How can I edit my Common Lisp files?") test("How can I scrape a website using Common Lisp?") ================================================ FILE: embedchain_test/data/haskell-cookbook.txt ================================================ Haskell Tutorial and Cookbook Mark Watson This book is for sale at http://leanpub.com/haskell-cookbook This version was published on 2023-01-27 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. © 2016 - 2023 Mark Watson Contents Cover Material, Copyright, and License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Additional Material in the Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 A Request from the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Structure of the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Functional Programming Requires a Different Mind Set . . . . . . . . . . . . . . . . . . . . . 4 eBooks Are Living Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Setting Up Your Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Why Haskell? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Enjoy Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Section 1 - Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Tutorial on Pure Haskell Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Interactive GHCi Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Introduction to Haskell Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Functions Are Pure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Using Parenthesis or the Special $ Character and Operator Precedence . . . . . . . . . . . . 23 Lazy Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Understanding List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Haskell Rules for Indenting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Understanding let and where . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Conditional do Expressions and Anonymous Functions . . . . . . . . . . . . . . . . . . . . . 30 Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 More on Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Comments on Dealing With Immutable Data and How to Structure Programs . . . . . . . 40 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Testing Haskell Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Pure Haskell Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Tutorial on Impure Haskell Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 CONTENTS Hello IO () Monad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 A Note About >> and >>= Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Console IO Example with Stack Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 File IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Error Handling in Impure Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Network IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 A Haskell Game Loop that Maintains State Functionally . . . . . . . . . . . . . . . . . . . . . 61 A More Detailed Look at Monads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Using Applicative Operators <$> and <*>: Finding Common Words in Files . . . . . . . . . 65 List Comprehensions Using the do Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Dealing With Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Using Debug.Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Section 2 - Cookbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Text Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 CSV Spreadsheet Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 JSON Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Cleaning Natural Language Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Natural Language Processing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Resolve Entities in Text to DBPedia URIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Bag of Words Classification Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Text Summarization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Part of Speech Tagging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Natural Language Processing Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Linked Data and the Semantic Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 The SPARQL Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 A Haskell HTTP Based SPARQL Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Querying Remote SPARQL Endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Linked Data and Semantic Web Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Web Scraping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Using the Wreq Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Using the HandsomeSoup Library for Parsing HTML . . . . . . . . . . . . . . . . . . . . . . 111 Web Scraping Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Using Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Database Access for Sqlite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Database Access for Postgres . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Haskell Program to Play the Blackjack Card Game . . . . . . . . . . . . . . . . . . . . . . . . . 120 CONTENTS Section 3 - Larger Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Knowledge Graph Creator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Code Layout For the KGCreator Project and strategies for sharing Haskell code between projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 The Main Event: Detecting Entities in Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Utility Code for Generating RDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Utility Code for Generating Cypher Input Data for Neo4J . . . . . . . . . . . . . . . . . . . . 145 Top Level API Code for Handling Knowledge Graph Data Generation . . . . . . . . . . . . 150 Wrapup for Automating the Creation of Knowledge Graphs . . . . . . . . . . . . . . . . . . 152 Hybrid Haskell and Python Natural Language Processing . . . . . . . . . . . . . . . . . . . . . 153 Example Use of the Haskell NLP Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Setting up the Python NLP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Understanding the Haskell NLP Client Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Wrapup for Using the Python SpaCy NLP Service . . . . . . . . . . . . . . . . . . . . . . . . . 156 Hybrid Haskell and Python For Coreference Resolution . . . . . . . . . . . . . . . . . . . . . . 157 Installing the Python Coreference Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Understanding the Haskell Coreference Client Code . . . . . . . . . . . . . . . . . . . . . . . 158 Wrapup for Using the Python Coreference NLP Service . . . . . . . . . . . . . . . . . . . . . 160 Book Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Appendix A - Haskell Tools Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Emacs Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Do you want more of an IDE-like Development Environment? . . . . . . . . . . . . . . . . . 163 hlint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Cover Material, Copyright, and License Copyright 2016 Mark Watson. All rights reserved. This book may be shared using the Creative Commons “share and share alike, no modifications, no commercial reuse” license. This eBook will be updated occasionally so please periodically check the leanpub.com web page for this book¹ for updates. Please visit the author’s website². If you found a copy of this book on the web and find it of value then please consider buying a copy at leanpub.com/haskell-cookbook³ to support the author and fund work for future updates. ¹https://leanpub.com/haskell-cookbook ²http://markwatson.com ³https://leanpub.com/haskell-cookbook Preface This is the preface to the new second edition released summer of 2019. It took me over a year learning Haskell before I became comfortable with the language because I tried to learn too much at once. There are two aspects to Haskell development: writing pure functional code and writing impure code that needs to maintain state and generally deal with the world non- deterministically. I usually find writing pure functional Haskell code to be easy and a lot of fun. Writing impure code is sometimes a different story. This is why I am taking a different approach to teaching you to program in Haskell: we begin techniques for writing concise, easy to read and understand efficient pure Haskell code. I will then show you patterns for writing impure code to deal with file IO, network IO, database access, and web access. You will see that the impure code tends to be (hopefully!) a small part of your application and is isolated in the impure main program and in a few impure helper functions used by the main program. Finally, we will look at a few larger Haskell programs. Additional Material in the Second Edition In addition to updating the introduction to Haskell and tutorial material, I have added a few larger projects to the second edition. The project knowledge_graph_creator helps to automate the process of creating Knowledge Graphs from raw text input and generates data for both the Neo4J open source graph database as well as RDF data for use in semantic web and linked data applications. The project HybridHaskellPythonNlp is a hybrid project: a Python web service that provides access to the SpaCy natural language processing (NLP) library and select NLP deep learning models and a Haskell client for accessing this service. It sometimes makes sense to develop polyglot applications (i.e., applications written in multiple programming languages) to take advantage of language specific libraries and frameworks. We will also use a similar hybrid example HybridHaskellPythonCore- fAnaphoraResolution that uses another deep learning model to replace pronouns in text with the original nouns that the pronouns refer to. This is a common processing step for systems that extract information from text. A Request from the Author I spent time writing this book to help you, dear reader. I release this book under the Creative Commons “share and share alike, no modifications, no commercial reuse” license and set the minimum purchase price to $6.00 in order to reach the most readers. You can also read this (and Preface 3 all of my books) for free on my my website⁴. Under this license you can share a PDF version of this book with your friends and coworkers. If you would like to support my work please consider purchasing my books on Leanpub⁵ and star my git repositories that you find useful on GitHub⁶. You can also interact with me on social media on Mastodon⁷ and Twitter⁸. I enjoy writing and your support helps me write new editions and updates for my books and to develop new book projects. Thank you! Structure of the Book The first section of this book contains two chapters: • A tutorial on pure Haskell development: no side effects. • A tutorial on impure Haskell development: dealing with the world (I/O, network access, database access, etc.). This includes examples of file IO and network programming as well as writing short applications: a mixture of pure and impure Haskell code. After working through these tutorial chapters you will understand enough of Haskell development to understand and be able to make modifications for your own use of the cookbook examples in the second section. Some of the general topics will be covered again in the second book section that contains longer sample applications. For example, you will learn the basics for interacting with Sqlite and Postgres databases in the tutorial on impure Haskell code but you will see a much longer example later in the book when I provide code that implements a natural language processing (NLP) interface to relational databases. The second section contains the following recipes implemented as complete programs: • Textprocessing CSV Files • Textprocessing JSON Files • Natural Language Processing (NLP) interface to relational databases, including annotating English text with Wikipedia/DBPedia URIs for entities in the original text. Entities can be people, places, organizations, etc. • Accessing and Using Linked Data • Querying Semantic Web RDF Data Sources • Web scraping data on web sites • Using Sqlite and Postgres relational databases • Play a simple version of Blackjack card game A new third section (added in 2019 for the second edition) has three examples that were derived by my own work. ⁴https://markwatson.com/books ⁵https://leanpub.com/u/markwatson ⁶https://github.com/mark-watson?tab=repositories&q=&type=public ⁷https://mastodon.social/@mark_watson ⁸https://twitter.com/mark_l_watson Preface 4 Code Examples The code examples in this book are licensed under two software licenses and you can choose the license that works best for your needs: Apache 2 and GPL 3. To be clear, you can use the examples in commercial projects under the Apache 2 license and if you like to write Free (Libre) software then use the GPL 3 license. We will use stack as a build system for all code examples. The code examples are provided as 22 separate stack based projects. These examples are found on github⁹. Functional Programming Requires a Different Mind Set You will learn to look at problems differently when you write functional programs. We will use a bottom up approach in most of the examples in this book. I like to start by thinking of the problem domain and decide how I can represent the data required for the problem at hand. I prefer to use native data structures. This is the opposite approach to object oriented development where considerable analysis effort and coding effort is required to define class hierachies to represent data. In most of the code we use simple native data types like lists and maps. Once we decide how to represent data for a program we then start designing and implementing simple functions to operate on and transform data. If we find ourselves writing functions that are too long or too complex, we can break up code into simpler functions. Haskell has good language support for composing simple functions into more complex operations. I have spent many years engaged in object oriented programming starting with CLOS for Common Lisp, C++, Java, and Ruby. I now believe that in general, and I know it is sometimes a bad idea to generalize too much, functional programming is a superior paradigm to object oriented programming. Convincing you of this belief is one of my goals in writing this book! eBooks Are Living Documents I wrote printed books for publishers like Springer-Verlag, McGraw-Hill, and Morgan Kaufman before I started self-publishing my own books. I prefer eBooks because I can update already published books and update the code examples for eBooks. I encourage you to periodically check for free updates to both this book and the code examples on the leanpub.com web page for this book¹⁰. ⁹https://github.com/mark-watson/haskell_tutorial_cookbook_examples ¹⁰https://leanpub.com/haskell-cookbook Preface 5 Setting Up Your Development Environment I strongly recommend that you use the stack tool from the stack website¹¹. This web site has instructions for installing stack on OS X, Windows, and Linux. If you don’t have stack installed yet please do so now and follow the “getting started” instructions for creating a small project. Appendix A contains material to help get you set up. It is important for you to learn the basics of using stack before jumping into this book because I have set up all of the example programs using stack. The github repository for the examples in this book is located at github.com/mark-watson/haskell_- tutorial_cookbook_examples¹². Many of the example listings for code examples are partial or full listing of files in my github repository. I show the file name, the listing, and the output. To experiment with the example yourself you need to load it and execute the main function; for example, if the example file is TestSqLite1.hs in the sub-directory Database, then from the top level directory in the git repository for the book examples you would do the following: $ haskell_tutorial_cookbook_examples git:(master) > cd Database $ Database git:(master) > stack build --exec ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> :l TestSqLite1 [1 of 1] Compiling Main ( TestSqLite1.hs, interpreted ) Ok, modules loaded: Main. *Main> main "Table names in database test.db:" "test" "SQL to create table 'test' in database test.db:" "CREATE TABLE test (id integer primary key, str text)" "number of rows in table 'test':" 1 "rows in table 'test':" (1,"test string 2") *Main> If you don’t want to run the example in a REPL in order to experiment with it interactively you can then just run it via stack using: ¹¹http://docs.haskellstack.org/en/stable/README.html ¹²https://github.com/mark-watson/haskell_tutorial_cookbook_examples Preface 6 $ Database git:(master) > stack build --exec TestSqlite1 "Table names in database test.db:" "test" "SQL to create table 'test' in database test.db:" "CREATE TABLE test (id integer primary key, str text)" "number of rows in table 'test':" 1 "rows in table 'test':" (1,"test string 2") I include README.md files in the project directories with specific instructions. I now use VSCode for most of my Haskell development. With the Haskell plugins VSCode offers auto-completion while typing and highlights syntax errors. Previously I use other editor for Haskell development. If you are an Emacs user I recommend that you follow the instructions in Appendix A, load the tutorial files into an Emacs buffer, build an example and open a REPL frame. If one is not already open type control-c control-l, switch to the REPL frame, and run the main function. When you make changes to the tutorial files, doing another control-c control-l will re-build the example in less than a second. In addition to using Emacs I occasionally use the IntelliJ Community Edition (free) IDE with the Haskell plugin, the TextMate editor (OS X only) with the Haskell plugin, or the GNU GEdit editor (Linux only). Appendix A also shows you how to setup the *stack Haskell build tool. Whether you use Emacs/VSCode or run a REPL in a terminal window (command window if you are using Windows) the important thing is to get used to and enjoy the interactive style of development that Haskell provides. Why Haskell? I have been using Lisp programming languages professionally since 1982. Lisp languages are flexible and appropriate for many problems. Some might dissagree with me but I find that Haskell has most of the advantages of Lisp with the added benefit of being strongly typed. Both Lisp and Haskell support a style of development using an interactive shell (or “repl”). What does being a strongly typed language mean? In a practical sense it means that you will often encounter syntax errors caused by type mismatches that you will need to fix before your code will compile (or run in the GHCi shell interpreter). Once your code compiles it will likely work, barring a logic error. The other benefit that you can get is having to write fewer unit tests - at least that is my experience. So, using a strongly typed language is a tradeoff. When I don’t use Haskell I tend to use dynamic languages like Common Lisp or Python. Preface 7 Enjoy Yourself I have worked hard to make learning Haskell as easy as possible for you. If you are new to the Haskell programming language then I have something to ask of you, dear reader: please don’t rush through this book, rather take it slow and take time to experiment with the programming examples that most interest you. Acknowledgements I would like to thank my wife Carol Watson for editing the manuscript for this book. I would like to thank Roy Marantz, Michel Benard, and Daniel Kroni for reporting an errors. Section 1 - Tutorial The first section of this book contains two chapters: • A tutorial on pure Haskell development: no side effects. • A tutorial on impure Haskell development: dealing with the world (I/O, network access, database access, etc.) After working through these two tutorial chapters you will have sufficient knowledge of Haskell development to understand the cookbook examples in the second section and be able to modify them for your own use. Some of the general topics will be covered again in the second book section that contains longer example programs. Tutorial on Pure Haskell Programming Pure Haskell code has no side effects and if written properly is easy to read and understand. I am assuming that you have installed stack using the directions in Appendix A. It is important to keep a Haskell interactive repl open as you read the material in this book and experiment with the code examples as you read. I don’t believe that you will be able to learn the material in this chapter unless you work along trying the examples and experimenting with them in an open Haskell repl! The directory Pure in the git repository contains the examples for this chapter. Many of the examples contain a small bit of impure code in a main function. We will cover how this impure code works in the next chapter but let’s look at a short example of impure code that is contained inside a main function: main = do putStrLn ("1 + 2 = " ++ show (1 + 2)) The function main is the entry point of this short two line program. When the program is run, the main function will be executed. Here the function main uses the do notation to execute a single IO action, but do can also execute a sequence of actions. The putStrLn function prints a string to the console. The printed string is constructed by concatenating three parts: “1 + 2 = “, the result of the expression 1 + 2 (which is 3), and the string representation of this result, which is obtained by calling the function show. It’s worth noting that putStrLn writes a string to the standard output and also writes a new line character to the console. In general, the function show is used to convert any value to a string, here it is converting the result of 1+2 to string to concatenate it with the previous string. Pure Haskell code performs no I/O, network access, access to shared in-memory data structures, etc. The first time you build an example program with stack it may take a while since library dependencies need to be loaded from the web. In each example directory, after an initial stack build or stack ghci (to run the repl) then you should not notice this delay. Interactive GHCi Shell The interactive shell (often called a “repl”) is very useful for learning Haskell: understanding types and the value of expressions. While simple expressions can be typed directly into the GHCi shell, it is usually better to use an external text editor and load Haskell source files into the shell (repl). Let’s get started. Assuming that you have installed stack as described in Appendix A, please try: Tutorial on Pure Haskell Programming 10 1 ~/$ cd haskell_tutorial_cookbook_examples/Pure 2 ~/haskell_tutorial_cookbook_examples/Pure$ stack ghci 3 Using main module: Package `Pure' component exe:Simple with main-is file: /home/mark\ 4 w/BITBUCKET/haskell_tutorial_cookbook_examples/Pure/Simple.hs 5 Configuring GHCi with the following packages: Pure 6 GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help 7 [1 of 1] Compiling Main ( /home/markw/BITBUCKET/haskell_tutorial_cookboo\ 8 k_examples/Pure/Simple.hs, interpreted ) 9 Ok, modules loaded: Main. 10 *Main> 1 + 2 11 3 12 *Main> (1 + 2) 13 3 14 *Main> :t (1 + 2) 15 (1 + 2) :: Num a => a 16 *Main> :l Simple.hs 17 [1 of 1] Compiling Main ( Simple.hs, interpreted ) 18 Ok, modules loaded: Main. 19 *Main> main 20 1 + 2 = 3 21 *Main> If you are working in a repl and edit a file you just loaded with :l, you can then reload the last file loaded using :r without specifying the file name. This makes it quick and easy to edit a Haskell file with an external editor like Emacs or Vi and reload it in the repl after saving changes to the current file. Here we have evaluated a simple expression “1 + 2” in line 10. Notice that in line 12 we can always place parenthesis around an expression without changing its value. We will use parenthesis when we need to change the default orders of precedence of functions and operators and make the code more readable. In line 14 we are using the ghci :t command to show the type of the expression (1 + 2). The type Num is a type class (i.e., a more general purpose type that other types can inherit from) that contains several sub-types of numbers. As examples, two subtypes of Num are Fractional (e.g., 3.5) and Integer (e.g., 123). Type classes provide a form of function overloading since existing functions can be redefined to handle arguments that are instances of new classes. In line 16 we are using the ghci command :l to load the external file Simple.hs. This file contains a function called main so we can execute main after loading the file. The contents of Simple.hs is: Tutorial on Pure Haskell Programming 11 1 module Main where 2 3 sum2 x y = x + y 4 5 main = do 6 putStrLn ("1 + 2 = " ++ show (sum2 1 2)) Line 1 defines a module named Main. The rest of this file is the definition of the module. This form of the module do expression exports all symbols so other code loading this module has access to sum2 and main. If we only wanted to export main then we could use: module Main (main) where The function sum2 takes two arguments and adds them together. I didn’t define the type of this function so Haskell does it for us using type inference. 1 *Main> :l Simple.hs 2 [1 of 1] Compiling Main ( Simple.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> :t sum2 5 sum2 :: Num a => a -> a -> a 6 *Main> sum2 1 2 7 3 8 *Main> sum2 1.0 2 9 3.0 10 *Main> :t 3.0 11 3.0 :: Fractional a => a 12 *Main> :t 3 13 3 :: Num a => a 14 *Main> (toInteger 3) 15 3 16 *Main> :t (toInteger 3) 17 (toInteger 3) :: Integer 18 *Main> What if you want to build a standalone executable program from the example in Smple.hs? Here is an example: Tutorial on Pure Haskell Programming 12 1 $ stack ghc Simple.hs 2 [1 of 1] Compiling Main ( Simple.hs, Simple.o ) 3 Linking Simple ... 4 $ ./Simple 5 1 + 2 = 3 Most of the time we will use simple types built into Haskell: characters, strings, lists, and tuples. The type Char is a single character. One type of string is a list of characters [Char]. (Another type ByteString will be covered in later chapters.) Every element in a list must have the same type. A Tuple is like a list but elements can be different types. Here is a quick introduction to these types, with many more examples later: 1 *Main> :t 's' 2 's' :: Char 3 *Main> :t "tree" 4 "tree" :: [Char] 5 *Main> 's' : "tree" 6 "stree" 7 *Main> :t "tick" 8 "tick" :: [Char] 9 *Main> 's' : "tick" 10 "stick" 11 *Main> :t [1,2,3,4] 12 [1,2,3,4] :: Num t => [t] 13 *Main> :t [1,2,3.3,4] 14 [1,2,3.3,4] :: Fractional t => [t] 15 *Main> :t ["the", "cat", "slept"] 16 ["the", "cat", "slept"] :: [[Char]] 17 *Main> ["the", "cat", "slept"] !! 0 18 "the" 19 *Main> head ["the", "cat", "slept"] 20 "the" 21 *Main> tail ["the", "cat", "slept"] 22 ["cat","slept"] 23 *Main> ["the", "cat", "slept"] !! 1 24 "cat" 25 *Main> :t (20, 'c') 26 (20, 'c') :: Num t => (t, Char) 27 *Main> :t (30, "dog") 28 (30, "dog") :: Num t => (t, [Char]) 29 *Main> :t (1, "10 Jackson Street", 80211, 77.5) 30 (1, "10 Jackson Street", 80211, 77.5) 31 :: (Fractional t2, Num t, Num t1) => (t, [Char], t1, t2) Tutorial on Pure Haskell Programming 13 The GHCi repl command :t tells us the type of any expression or function. Much of your time developing Haskell will be spent with an open repl and you will find yourself checking types many times during a development session. In line 1 you see that the type of ’s‘ is ’s’ :: Char and in line 3 that the type of the string “tree” is [Char] which is a list of characters. The abbreviation String is defined for [Char]; you can use either. In line 9 we see the “cons” operator : used to prepend a character to a list of characters. The cons : operator works with all types contained in any lists. All elements in a list must be of the same type. The type of the list of numbers [1,2,3,4] in line 11 is [1,2,3,4] :: Num t ⇒ [t]. The type Num is a general number type. The expression Num t ⇒ [t] is read as: “t is a type variable equal to Num and the type of the list is [t], or a list of Num values”. It bears repeating: all elements in a list must be of the same type. The functions head and tail used in lines 19 and 21 return the first element of a list and return a list without the first element. You will use lists frequently but the restriction of all list elements being the same type can be too restrictive so Haskell also provides a type of sequence called tuple whose elements can be of different types as in the examples in lines 25-31. Tuples of length 2 are special because functions fst and snd are provided to access the first and second pair value: *Main> fst (1, "10 Jackson Street") 1 *Main> snd (1, "10 Jackson Street") "10 Jackson Street" *Main> :info fst fst :: (a, b) -> a -- Defined in ‘Data.Tuple’ *Main> :info snd snd :: (a, b) -> b -- Defined in ‘Data.Tuple’ Please note that fst and snd will not work with tuples that are not of length 2. Also note that if you use the function length on a tuple, the result is always one because of the way tuples are defined as Foldable types, which we will use later. Haskell provides a concise notation to get values out of long tuples. This notation is called destructuring: Tutorial on Pure Haskell Programming 14 1 *Main> let geoData = (1, "10 Jackson Street", 80211, 77.5) 2 *Main> let (_,_,zipCode,temperature) = geoData 3 *Main> zipCode 4 80211 5 *Main> temperature 6 77.5 Here, we defined a tuple geoData with values: index, street address, zip code, and temperature. In line two we extract the zip code and temperature. Another reminder: we use let in lines 1-2 because we are in a repl. Like all programming languages, Haskell has operator precedence rules as these examples show: 1 *Main> 1 + 2 * 10 2 21 3 *Main> 1 + (2 * 10) 4 21 5 *Main> length "the" 6 3 7 *Main> length "the" + 10 8 13 9 *Main> (length "the") + 10 10 13 The examples in lines 1-4 illustrate that the multiplication operator has a higher precedence than the addition operator. *Main> :t length length :: Foldable t => t a -> Int *Main> :t (+) (+) :: Num a => a -> a -> a Note that the function length starts with a lower case letter. All Haskell functions start with a lower case letter except for type constructor functions that we will get to later. A Foldable type can be iterated through and be processed with map functions (which we will use shortly). We saw that the function + acts as an infix operator. We can convert infix functions to prefix functions by enclosing them in parenthesis: Tutorial on Pure Haskell Programming 15 *Main> (+) 1 2 3 *Main> div 10 3 3 *Main> 10 `div` 3 3 In this last example we also saw how a prefix function div can be used infix by enclosing it in back tick characters. 1 *Main> let x3 = [1,2,3] 2 *Main> x3 3 [1,2,3] 4 *Main> let x4 = 0 : x3 5 *Main> x4 6 [0,1,2,3] 7 *Main> x3 ++ x4 8 [1,2,3,0,1,2,3] 9 *Main> x4 10 [0,1,2,3] 11 *Main> x4 !! 0 12 0 13 *Main> x4 !! 100 14 *** Exception: Prelude.!!: index too large 15 *Main> let myfunc1 x y = x ++ y 16 *Main> :t myfunc1 17 myfunc1 :: [a] -> [a] -> [a] 18 *Main> myfunc1 x3 x4 19 [1,2,3,0,1,2,3] Usually we define functions in files and load them as we need them. Here is the contents of the file myfunc1.hs: 1 myfunc1 :: [a] -> [a] -> [a] 2 myfunc1 x y = x ++ y The first line is a type signature for the function and is not required; here the input arguments are two lists and the output is the two lists concatenated together. In line 1 note that a is a type variable that can represent any type. However, all elements in the two function input lists and the output list are constrained to be the same type. Tutorial on Pure Haskell Programming 16 1 *Main> :l myfunc1.hs 2 [1 of 1] Compiling Main ( myfunc1.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> myfunc1 ["the", "cat"] ["ran", "up", "a", "tree"] 5 ["the","cat","ran","up","a","tree"] Please note that the stack repl auto-completes using the tab character. For example, when I was typing in “:l myfunc1.hs” I actually just typed “:l myf” and then hit the tab character to complete the file name. Experiment with auto-completion, it will save you a lot of typing. In the following example, for instance, after defining the variable sentence I can just type “se” and the tab character to auto-complete the entire variable name: 1 *Main> let sentence = myfunc1 ["the", "cat"] ["ran", "up", "a", "tree"] 2 *Main> sentence 3 ["the","cat","ran","up","a","tree"] The function head returns the first element in a list and the function tail returns all but the first elements in a list: 1 *Main> head sentence 2 "the" 3 *Main> tail sentence 4 ["cat","ran","up","a","tree"] We can create new functions from existing arguments by supplying few arguments, a process known as “currying”: 1 *Main> let p1 = (+ 1) 2 *Main> :t p1 3 p1 :: Num a => a -> a 4 *Main> p1 20 5 21 In this last example the function + takes two arguments but if we only supply one argument a function is returned as the value: in this case a function that adds 1 to an input value. We can also create new functions by composing existing functions using the infix function . that when placed between two function names produces a new function that combines the two functions. Let’s look at an example that uses . to combine the partial function (+ 1) with the function length: Tutorial on Pure Haskell Programming 17 1 *Main> let lengthp1 = (+ 1) . length 2 *Main> :t lengthp1 3 lengthp1 :: Foldable t => t a -> Int 4 *Main> lengthp1 "dog" 5 4 Note the order of the arguments to the inline function .: the argument on the right side is the first function that is applied, then the function on the left side of the . is applied. This is the second example where we have seen the type Foldable which means that a type can be mapped over, or iterated over. We will look at Haskell types in the next section. Introduction to Haskell Types This is a good time to spend more time studying Haskell types. We will see more material on Haskell types throughout this book so this is just an introduction using the data expression to define a Type MyColors defined in the file MyColors.hs: 1 data MyColors = Orange | Red | Blue | Green | Silver 2 deriving (Show) This code defines a new data type in Haskell named MyColors that has five values: Orange, Red, Blue, Green or Silver. The keyword data is used to define a new data type, and the “|” symbol is used to separate the different possible values (also known as constructors) of the type. The deriving (Show) clause at the end of the line tells the compiler to automatically generate an implementation of the Show type class for the MyColors type. In other words, we are asking the Haskell compiler to automatically generate a function show that can convert a value to a string. show is a standard function and in general we want it defined for all types. show converts an instance to a string value. This allows instances of MyColors to be converted to strings using the function show. The MyColors type defined here is an enumeration (i.e., it is a fixed set of values), it’s an algebraic data type with no associated fields. This means that the type MyColors can only take one of the five values defined: Orange, Red, Blue, Green or Silver. There is another way to think about this. This code defines a new data type called MyColors with five constructors Orange, Red, Blue, Green or Silver. Tutorial on Pure Haskell Programming 18 1 Prelude> :l colors.hs 2 [1 of 1] Compiling Main ( colors.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> show Red 5 "Red" 6 *Main> let c1 = Green 7 *Main> c1 8 Green 9 *Main> :t c1 10 c1 :: MyColors 11 *Main> Red == Green 12 13 :60:5: 14 No instance for (Eq MyColors) arising from a use of ‘==’ 15 In the expression: Red == Green 16 In an equation for ‘it’: it = Red == Green What went wrong here? The infix function == checks for equality and we did not define equality functions for our new type. Let’s fix the definition in the file colors.hs: 1 data MyColors = Orange | Red | Blue | Green | Silver 2 deriving (Show, Eq) Because we are deriving Eq we are also asking the compiler to generate code to see if two instances of this class are equal. If we wanted to be able to order our colors then we would also derive Ord. Now our new type has show, ==, and /= (inequality) defined: 1 Prelude> :l colors.hs 2 [1 of 1] Compiling Main ( colors.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> Red == Green 5 False 6 *Main> Red /= Green 7 True Let’s also now derive Ord to have the compile generate a default function compare that operates on the type MyColors: 1 data MyColors = Orange | Red | Blue | Green | Silver 2 deriving (Show, Eq, Ord) Because we are now deriving Ord the compiler will generate functions to calculate relative ordering for values of type MyColors. Let’s experiment with this: Tutorial on Pure Haskell Programming 19 1 *Main> :l MyColors.hs 2 [1 of 1] Compiling Main ( MyColors.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> :t compare 5 compare :: Ord a => a -> a -> Ordering 6 *Main> compare Green Blue 7 GT 8 *Main> compare Blue Green 9 LT 10 *Main> Orange < Red 11 True 12 *Main> Red < Orange 13 False 14 *Main> Green < Red 15 False 16 *Main> Green < Silver 17 True 18 *Main> Green > Red 19 True Notice that the compiler generates a compare function for the type MyColors that orders values by the order that they appear in the data expression. What if you wanted to order them in string sort order? This is very simple: we will remove Ord from the deriving clause and define our own function compare for type MyColors instead of letting the compiler generate it for us: 1 data MyColors = Orange | Red | Blue | Green | Silver 2 deriving (Show, Eq) 3 4 instance Ord MyColors where 5 compare c1 c2 = compare (show c1) (show c2) In line 5 I am using the function show to convert instances of MyColors to strings and then the version of compare that is called in line 5 is the version the compiler wrote for us because we derived Show. Now the ordering is in string ascending sort order because we are using the compare function that is supplied for the type String: 1 *Main> :l MyColors.hs 2 [1 of 1] Compiling Main ( MyColors.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> Green > Red 5 False Tutorial on Pure Haskell Programming 20 Our new type MyColors is a simple type. Haskell also supports hierarchies of types called Type Classes and the type we have seen earlier Foldable is an example of a type class that other types can inherit from. For now, consider sub-types of Foldable to be collections like lists and trees that can be iterated over. I want you to get in the habit of using :type and :info (usually abbreviated to :t and :i) in the GHCi repl. Stop reading for a minute now and type :info Ord in an open repl. You will get a lot of output showing you all of the types that Ord is defined for. Here is a small bit of what gets printed: 1 *Main> :i Ord 2 class Eq a => Ord a where 3 compare :: a -> a -> Ordering 4 (<) :: a -> a -> Bool 5 (<=) :: a -> a -> Bool 6 (>) :: a -> a -> Bool 7 (>=) :: a -> a -> Bool 8 max :: a -> a -> a 9 min :: a -> a -> a 10 -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 11 instance Ord MyColors -- Defined at MyColors.hs:4:10 12 instance (Ord a, Ord b) => Ord (Either a b) 13 -- Defined in ‘Data.Either’ 14 instance Ord a => Ord [a] 15 -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 16 instance Ord Word -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 17 instance Ord Ordering -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 18 instance Ord Int -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 19 instance Ord Float -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ 20 instance Ord Double -- Defined in ‘ghc-prim-0.4.0.0:GHC.Classes’ Lines 1 through 8 show you that Ord is a subtype of Eq that defines functions compare, max, and min as well as the four operators <, <=, >=, and >=. When we customized the compare function for the type MyColors, we only implemented compare. That is all that we needed to do since the other operators rely on the implementation of compare. Once again, I ask you to experiment with the example type MyColors in an open GHCi repl: Tutorial on Pure Haskell Programming 21 1 *Main> :t max 2 max :: Ord a => a -> a -> a 3 *Main> :t Green 4 Green :: MyColors 5 *Main> :i Green 6 data MyColors = ... | Green | ... -- Defined at MyColors.hs:1:39 7 *Main> max Green Red 8 Red The following diagram shows a partial type hierarchy of a few types included in the standard Haskell Prelude (this is derived from the Haskell Report at haskell.org¹³): Example Haskell Type Hierarchy Here you see that type Num and Ord are sub-types of type Eq, Real is a sub-type of Num, etc. We will see the types Monad and Functor in the next chapter. Functions Are Pure Again, it is worth pointing out that Haskell functions do not modify their inputs values. The common pattern is to pass immutable values to a function and modified values are returned. As a first example of this pattern we will look at the standard function map that takes two arguments: a function that ¹³https://www.haskell.org/onlinereport/basic.html Tutorial on Pure Haskell Programming 22 converts a value of any type a to another type b, and a list of type a. Functions that take other functions as arguments are called higher order functions. The result is another list of the same length whose elements are of type b and the elements are calulated using the function passed as the first argument. Let’s look at a simple example using the function (+ 1) that adds 1 to a value: 1 *Main> :t map 2 map :: (a -> b) -> [a] -> [b] 3 *Main> map (+ 1) [10,20,30] 4 [11,21,31] 5 *Main> map (show . (+ 1)) [10,20,30] 6 ["11","21","31"] In the first example, types a and b are the same, a Num. The second example used a composed function that adds 1 and then converts the example to a string. Remember: the function show converts a Haskell data value to a string. In this second example types a and b are different because the function is mapping a number to a string. The directory haskell_tutorial_cookbook_examples/Pure contains the examples for this chapter. We previously used the example file Simple.hs. Please note that in the rest of this book I will omit the git repository top level directory name haskell_tutorial_cookbook_examples and just specify the sub-directory name: 1 module Main where 2 3 sum2 x y = x + y 4 5 main = do 6 putStrLn ("1 + 2 = " ++ show (sum2 1 2)) For now let’s just look at the mechanics of executing this file without using the REPL (started with stack ghci). We can simply build and run this example using stack, which is covered in some detail in Appendix A: stack build --exec Simple This command builds the project defined in the configuration files Pure.cabal and stack.yaml (the format and use of these files is briefly covered in detail in Appendix A and there is more reference material here¹⁴). This example defines two functions: sum2 and main. sum2 is a pure Haskell function with no state, no interaction with the outside world like file IO, etc., and no non- determinism. main is an impure function, and we will look at impure Haskell code in some detail in the next chapter. As you might guess the output of this code snippet is ¹⁴https://docs.haskellstack.org/en/stable/yaml_configuration/ Tutorial on Pure Haskell Programming 23 1 + 2 = 3 To continue the tutorial on using pure Haskell functions, once again we will use stack to start an interactive repl during development: 1 markw@linux:~/haskell_tutorial_cookbook_examples/Pure$ stack ghci 2 *Main> :t 3 3 3 :: Num a => a 4 *Main> :t "dog" 5 "dog" :: [Char] 6 *Main> :t main 7 main :: IO () 8 *Main> In this last listing I don’t show the information about your Haskell environment and the packages that were loaded. In repl listings in the remainder of this book I will continue to edit out this Haskell environment information for brevity. Line 4 shows the use of the repl shortcut :t to print out the type of a string which is an array of [Char], and the type of the function main is of type IO Action, which we will explain in the next chapter. An IO action contains impure code where we can read and write files, perform a network operation, etc. and we will look at IO Action in the next chapter. Using Parenthesis or the Special $ Character and Operator Precedence We will look at operator and function precedence and the use of the $ character to simplify using parenthesis in expessions. By the way, in Haskell there is not much difference between operators and function calls except operators like +, etc. which are by default infix while functions are usually prefix. So except for infix functions that are enclosed in backticks (e.g., 10 div 3) Haskell usually uses prefix functions: a function followed by zero or more arguments. You can also use $ that acts as an opening parenthesis with a not-shown closing parenthesis at the end of the current expression (which may be multi-line). Here are some examples: Tutorial on Pure Haskell Programming 24 1 *Main> print (3 * 2) 2 6 3 *Main> print $ 3 * 2 4 6 5 *Main> last (take 10 [1..]) 6 10 7 *Main> last $ take 10 [1..] 8 10 9 *Main> ((take 10 [1..]) ++ (take 10 [1000..])) 10 [1,2,3,4,5,6,7,8,9,10,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009] 11 *Main> take 10 [1..] ++ take 10 [1000..] 12 [1,2,3,4,5,6,7,8,9,10,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009] 13 *Main> 1 + 2 * (4 * 5) 14 41 15 *Main> 2 * 3 + 10 * 30 16 306 I use the GHCi command :info (:i is an abbreviation) to check both operator precedence and the function signature if the operator is converted to a function by enclosing it in parenthessis: 1 *Main> :info * 2 class Num a where 3 ... 4 (*) :: a -> a -> a 5 ... 6 -- Defined in ‘GHC.Num’ 7 infixl 7 * 8 *Main> :info + 9 class Num a where 10 (+) :: a -> a -> a 11 ... 12 -- Defined in ‘GHC.Num’ 13 infixl 6 + 14 *Main> :info `div` 15 class (Real a, Enum a) => Integral a where 16 ... 17 div :: a -> a -> a 18 ... 19 -- Defined in ‘GHC.Real’ 20 infixl 7 `div` 21 *Main> :i + 22 class Num a where 23 (+) :: a -> a -> a Tutorial on Pure Haskell Programming 25 24 ... 25 -- Defined in ‘GHC.Num’ 26 infixl 6 + Notice how + has lower precedence than *. Just to be clear, understand how operators are used as functions and also how functions can be used as infix operators: 1 *Main> 2 * 3 2 6 3 *Main> (*) 2 3 4 6 5 *Main> 10 `div` 3 6 3 7 *Main> div 10 3 8 3 Especially when you are just starting to use Haskell it is a good idea to also use :info to check the type signatures of standard functions that you use. For example: 1 *Main> :info last 2 last :: [a] -> a -- Defined in ‘GHC.List’ 3 *Main> :info map 4 map :: (a -> b) -> [a] -> [b] -- Defined in ‘GHC.Base’ Lazy Evaluation Haskell is refered to as a lazy language because expressions are not evaluated until they are used. Consider the following example: 1 $ stack ghci 2 *Main> [0..10] 3 [0,1,2,3,4,5,6,7,8,9,10] 4 *Main> take 11 [0..] 5 [0,1,2,3,4,5,6,7,8,9,10] 6 *Main> let xs = [0..] 7 *Main> :sprint xs 8 xs = _ 9 *Main> take 5 xs 10 [0,1,2,3,4] Tutorial on Pure Haskell Programming 26 11 *Main> :sprint xs 12 xs = _ 13 *Main> In line 2 we are creating a list with 11 elements. In line 4 we are doing two things: • Creating an infinitely long list containing ascending integers starting with 0. • Fetching the first 11 elements of this infinitely long list. It is important to understand that in line 4 only the first 11 elements are generated because that is all the take function requires. In line 6 we are assigning another infinitely long list to the variable xs but the value of xs is unevaluated and a placeholder is stored to calculate values as required. In line 7 we use GHCi’s :sprint command to show a value without evaluating it. The output in line 8 _ indicated that the expression has yet to be evaluated. Lines 9 through 12 remind us that Haskell is a functional language: the take function used in line 9 does not change the value of its argument so xs as seen in lines 10 and 12 is still unevaluated. Understanding List Comprehensions Effectively using list comprehensions makes your code shorter, easier to understand, and easier to maintain. Let’s start out with a few GHCi repl examples. You will learn a new GHCi repl trick in this section: entering multiple line expressions by using :{ and :} to delay evaluation until an entire expression is entered in the repl (listings in this section are reformatted to fit the page width): 1 *Main> [x | x <- ["cat", "dog", "bird"]] 2 ["cat","dog","bird"] 3 *Main> :{ 4 *Main| [(x,y) | x <- ["cat", "dog", "bird"], 5 *Main| y <- [1..2]] 6 *Main| :} 7 [("cat",1),("cat",2),("dog",1),("dog",2),("bird",1),("bird",2)] The list comprehension on line 1 assigns the elements of the list [“cat”, “dog”, “bird”] one at a time to the variable x and then collects all these values of x in a list value that is the value of the list comprehension. The list comprehension in line 1 is hopefully easy to understand but when we bind and collect multiple variables the situation, as seen in the example in lines 4 and 5, is not as easy to understand. The thing to remember is that the first variable gets iterated as an “outer loop” and the second variable is iterated as the “inner loop.” List comprehensions can use many variables and the iteration ordering rule is the same: last variable iterates first, etc. Tutorial on Pure Haskell Programming 27 *Main> :{ *Main| [(x,y) | x <- [0..3], *Main| y <- [1,3..10]] *Main| :} [(0,1),(0,3),(0,5),(0,7),(0,9),(1,1),(1,3),(1,5),(1,7), (1,9),(2,1),(2,3),(2,5),(2,7),(2,9),(3,1),(3,3),(3,5), (3,7),(3,9)] *Main> [1,3..10] [1,3,5,7,9] In this last example we are generating all combinations of [0..3] and [1,3..10] and storing the combinations as two element tuples. You could also store then as lists: 1 *Main> [[x,y] | x <- [1,2], y <- [10,11]] 2 [[1,10],[1,11],[2,10],[2,11]] List comprehensions can also contain filtering operations. Here is an example with one filter: 1 *Main> :{ 2 *Main| [(x,y) | x <- ["cat", "dog", "bird"], 3 *Main| y <- [1..10], 4 *Main| y `mod` 3 == 0] 5 *Main| :} 6 [("cat",3),("cat",6),("cat",9), 7 ("dog",3),("dog",6),("dog",9), 8 ("bird",3),("bird",6),("bird",9)] Here is a similar example with two filters (we are also filtering out all possible values of x that start with the character ‘d’): 1 *Main> :{ 2 *Main| [(x,y) | x <- ["cat", "dog", "bird"], 3 *Main| y <- [1..10], 4 *Main| y `mod` 3 == 0, 5 *Main| x !! 0 /= 'd'] 6 *Main| :} 7 [("cat",3),("cat",6),("cat",9),("bird",3),("bird",6),("bird",9)] For simple filtering cases I usually use the filter function but list comprehensions are more versatile. List comprehensions are extremely useful - I use them frequently. Lists are instances of the class Monad that we will cover in the next chapter (check out the section “List Comprehensions Using the do Notation”). List comprehensions are powerful. I would like to end this section with another trick that does not use list comprehensions for building lists of tuple values: using the zip function: Tutorial on Pure Haskell Programming 28 1 *Main> let animals = ["cat", "dog", "bird"] 2 *Main> zip [1..] animals 3 [(1,"cat"),(2,"dog"),(3,"bird")] 4 *Main> :info zip 5 zip :: [a] -> [b] -> [(a, b)] -- Defined in ‘GHC.List’ The function zip is often used in this way when we have a list of objects and we want to operate on the list while knowing the index of each element. Haskell Rules for Indenting Code When a line of code is indented relative to the previous line of code, or several lines of code with additional indentation, then the indented lines act as if they were on the previous line. In other words, if code that should all be on one line must be split to multiple lines, then use indentation as a signal to the Haskell compiler. Indentation of continuation lines should be uniform, starting in the same column. Here are some examples of good code, and code that will not compile: 1 let a = 1 -- good 2 b = 2 -- good 3 c = 3 -- good 4 5 let 6 a = 1 -- good 7 b = 2 -- good 8 c = 3 -- good 9 in a + b + c -- good 10 11 let a = 1 -- will not compile (bad) 12 b = 2 -- will not compile (bad) 13 c = 3 -- will not compile (bad) 14 15 let 16 a = 1 -- will not compile (bad) 17 b = 2 -- will not compile (bad) 18 c = 3 -- will not compile (bad) 19 20 let { 21 a = 1; -- compiles but bad style (good) 22 b = 2; -- compiles but bad style (good) 23 c = 3; -- compiles but bad style (good) 24 } Tutorial on Pure Haskell Programming 29 If you use C style braces and semicolons to mark end of expressions, then indenting does not matter as seen in lines 20 through 24. Otherwise, uniform indentation is a hint to the compiler. The same indenting rules apply to other types of do expressions which we will see throughout this book for do, if, and other types of do expressions. Understanding let and where At first glance, let and where seem very similar in that they allow us to create temporary variables used inside functions. As the examples in the file LetAndWhere.hs show, there are important differences. In the following code notice that when we use let in pure code inside a function, we then use in to indicate the start of an expression to be evaluated that uses any variables defined in a let expression. Inside a do code block the in token is not needed and will cause a parse error if you use it. do code blocks are a syntactic sugar for use in impure Haskell code and we will use it frequently later in the book. You also do not use in inside a list comprehension as seen in the function testLetComprehension in the next code listing: 1 module Main where 2 3 funnySummation w x y z = 4 let bob = w + x 5 sally = y + z 6 in bob + sally 7 8 testLetComprehension = 9 [(a,b) | a <- [0..5], let b = 10 * a] 10 11 testWhereBlocks a = 12 z * q 13 where 14 z = a + 2 15 q = 2 16 17 functionWithWhere n = 18 (n + 1) * tenn 19 where 20 tenn = 10 * n 21 22 main = do Tutorial on Pure Haskell Programming 30 23 print $ funnySummation 1 2 3 4 24 let n = "Rigby" 25 print n 26 print testLetComprehension 27 print $ testWhereBlocks 11 28 print $ functionWithWhere 1 Compare the let do expressions starting on line 4 and 24. The first let occurs in pure code and uses in to define one or more do expressions using values bound in the let. In line 24 we are inside a monad, specifically using the do notation and here let is used to define pure values that can be used later in the do do expression. Loading the last code example and running the main function produces the following output: 1 *Main> :l LetAndWhere.hs 2 [1 of 1] Compiling Main ( LetAndWhere.hs, interpreted ) 3 Ok, modules loaded: Main. 4 *Main> main 5 10 6 "Rigby" 7 [(0,0),(1,10),(2,20),(3,30),(4,40),(5,50)] 8 26 9 20 This output is self explanatory except for line 7 that is the result of calling testLetComprehension that retuns an example list comprehension [(a,b)|a<-[0..5],letb=10*a] Conditional do Expressions and Anonymous Functions The examples in the next three sub-sections can be found in haskell_tutorial_cookbook_exam- ples/Pure/Conditionals.hs. You should read the following sub-sections with this file loaded (some GHCi repl output removed for brevity): 1 haskell_tutorial_cookbook_examples/Pure$ stack ghci 2 *Main> :l Conditionals.hs 3 [1 of 1] Compiling Main ( Conditionals.hs, interpreted ) 4 Ok, modules loaded: Main. 5 *Main> Tutorial on Pure Haskell Programming 31 Simple Pattern Matching We previously used the built-in functions head that returns the first element of a list and tail that returns a list with the first element removed. We will define these functions ourselves using what is called wild card pattern matching. It is common to append the single quote character ‘ to built-in functions when we redefine them so we name our new functions head’ and tail’. Remember when we used destructuring to access elements of a tuple? Wild card pattern matching is similar: head'(x:_) = x tail'(_:xs) = xs The underscore character _ matches anything and ignores the matched value. Our head and tail definitions work as expected: 1 *Main> head' ["bird","dog","cat"] 2 "bird" 3 *Main> tail' [0,1,2,3,4,5] 4 [1,2,3,4,5] 5 *Main> :type head' 6 head' :: [t] -> t 7 *Main> :t tail' 8 tail' :: [t] -> [t] Of course we frequently do not want to ignore matched values. Here is a contrived example that expects a list of numbers and doubles the value of each element. As for all of the examples in this chapter, the following function is pure: it can not modify its argument(s) and always returns the same value given the same input argument(s): 1 doubleList [] = [] 2 doubleList (x:xs) = (* 2) x : doubleList xs In line 1 we start by defining a pattern to match the empty list. It is necessary to define this terminating condition because we are using recursion in line 2 and eventually we reach the end of the input list and make the recursive call doubleList []. If you leave out line 1 you then will see a runtime error like “Non-exhaustive patterns in function doubleList.” As a Haskell beginner you probably hate Haskell error messages and as you start to write your own functions in source files and load them into a GHCi repl or compile them, you will initially probably hate compilation error messages also. I ask you to take on faith a bit of advice: Haskell error messages and warnings will end up saving you a lot of effort getting your code to work properly. Try to develop the attitude “Great! The Haskell compiler is helping me!” when you see runtime errors and compiler errors. In line 2 notice how I didn’t need to use extra parenthesis because of the operator and function application precedence rules. Tutorial on Pure Haskell Programming 32 1 *Main> doubleList [0..5] 2 [0,2,4,6,8,10] 3 *Main> :t doubleList 4 doubleList :: Num t => [t] -> [t] This function doubleList seems very unsatisfactory because it is so specific. What if we wanted to triple or quadruple the elements of a list? Do we want to write two new functions? You might think of adding an argument that is the multiplier like this: 1 bumpList n [] = [] 2 bumpList n (x:xs) = n * x : bumpList n xs is better, being more abstract and more general purpose. However, we will do much better. Before generalizing the list manipuation process further, I would like to make a comment on coding style, specifically on not using unneeded parenthesis. In the last exmple defining bumpList if you have superfluous parenthesis like this: bumpList n (x:xs) = (n * x) : bumpList (n xs) then the code still works correctly and is fairly readable. I would like you to get in the habit of avoiding extra uneeded parenthesis and one tool for doing this is running hlint (installing hlint is covered in Appendix A) on your Haskell code. Using hlint source file will provide warnings/suggestions like this: haskell_tutorial_cookbook_examples/Pure$ hlint Conditionals.hs Conditionals.hs:7:21: Warning: Redundant bracket Found: ((* 2) x) : doubleList (xs) Why not: (* 2) x : doubleList (xs) Conditionals.hs:7:43: Error: Redundant bracket Found: (xs) Why not: xs hlint is not only a tool for improving your code but also for teaching you how to better program using Haskell. Please note that hlint provides other suggestions for Conditionals.hs that I am ignoring that mostly suggest that I replace our mapping operations with using the built-in map function and use functional composition. The sample code is specifically to show examples of pattern matching and is not as concise as it could be. Tutorial on Pure Haskell Programming 33 Are you satisfied with the generality of the function bumpList? I hope that you are not! We should write a function that will apply an arbitrary function to each element of a list. We will call this function map’ to avoid confusing our map’ function with the built-in function map. The following is a simple implementation of a map function (we will see Haskell’s standard map functions in the next section): 1 map' f [] = [] 2 map' f (x:xs) = f x : map' f xs In line 2 we do not need parenthesis around f x because function application has a higher precidence than the operator : which adds an element to the beginning of a list. Are you pleased with how concise this definition of a map function is? Is concise code like map’ readable to you? Speaking as someone who has written hundreds of thousands of lines of Java code for customers, let me tell you that I love the conciseness and readability of Haskell! I appreciate the Java ecosystem with many useful libraries and frameworks and augmented like fine languages like Clojure and JRuby, but in my opinion using Haskell is a more enjoyable and generally more productive language and programming environment. Let’s experiment with our map’ function: 1 *Main> map' (* 7) [0..5] 2 [0,7,14,21,28,35] 3 *Main> map' (+ 1.1) [0..5] 4 [1.1,2.1,3.1,4.1,5.1,6.1] 5 *Main> map' (\x -> (x + 1) * 2) [0..5] 6 [2,4,6,8,10,12] Lines 1 and 3 should be understandable to you: we are creating a partial function like (* 7) and passing it to map’ to apply to the list [0..5]. The syntax for the function in line 5 is called an anonymous function. Lisp programers, like myself, refer to this as a lambda expression. In any case, I often prefer using anonymous functions when a function will not be used elsewhere. In line 5 the argement to the anonymous inline function is x and the body of the function is (x + 1) * 2. I do ask you to not get carried away with using too many anonymous inline functions because they can make code a little less readable. When we put our code in modules, by default every symbol (like function names) in the module is externally visible. However, if we explicitly export symbols in a module do expression then only the explicitly exported symbols are visible by other code that uses the module. Here is an example: Tutorial on Pure Haskell Programming 34 module Test2 (doubler) where map' f [] = [] map' f (x:xs) = (f x) : map' f xs testFunc x = (x + 1) * 2 doubler xs = map' (* 2) xs In this example map’ and testFunc are hidden: any other module that imports Test2 only has access to doubler. It might help for you to think of the exported functions roughly as an interface for a module. Pattern Matching With Guards We will cover two important concepts in this section: using guard pattern matching to make function definitions shorter and easier to read and we will look at the Maybe type and how it is used. The Maybe type is mostly used in non-pure Haskell code and we will use it heavily later. The Maybe type is a Monad (covered in the next chapter). I introduce the Maybe type here since its use fits naturally with guard patterns. Guards are more flexible than the pattern matching seen in the last section. I use pattern matching for simple cases of destructuring data and guards when I need the flexibility. You may want to revisit the examples in the last section after experimenting with and understanding the examples seen here. The examples for this section are in the file Guards.hs. As a first simple example we will implement the Ruby language “spaceship operator”: 1 spaceship n 2 | n < 0 = -1 3 | n == 0 = 0 4 | otherwise = 1 Notice on line 1 that we do not use an = in the function definition when using guards. Each guard starts with |, contains a condition, and a value on the right side of the = sign. 1 *Main> spaceship (-10) 2 -1 3 *Main> spaceship 0 4 0 5 *Main> spaceship 17 6 1 Remember that a literal negative number as seen in line 1 must be wrapped in parenthesis, otherwise the Haskell compiler will interpret - as an operator. Tutorial on Pure Haskell Programming 35 Case Expressions Case do expressions match a value against a list of possible values. It is common to use the wildcard matching value _ at the end of a case expression which can be of any type. Here is an example in the file Cases.hs: 1 module Main where 2 3 numberOpinion n = 4 case n of 5 0 -> "Too low" 6 1 -> "just right" 7 _ -> "OK, that is a number" 8 9 main = do 10 print $ numberOpinion 0 11 print $ numberOpinion 1 12 print $ numberOpinion 2 The code in lines 3-7 defines the function numberOpinion that takes a single argument “n”. We use a case expression to match the value of n against several possible cases. Each of these cases is defined using the -> operator, followed by an expression to be evaluated if the case is matched. The first case, 0 -> ‘Too low’ matches the value of n against 0, if the value of “n” is 0, the function will return the string “Too low”. The second case, 1 -> ‘just right’ matches the value of n against 1, if the value of n is 1, the function will return the string “just right”. The last case is different in that it is a catch all case using the ** as a wild card match. So, ** -> ‘OK, that is a number’ matches any other values of n: if the value of nn is not 0 or 1 the function will return the string “OK, that is a number”. If Then Else expressions Haskell has if then else syntax built into the language - if is not defined as a function. Personally I do not use if then else in Haskell very often. I mostly use simple pattern matching and guards. Here are some short examples from the file IfThenElses.hs: ageToString age = if age < 21 then "minor" else "adult" All if statements must have both a then expression and a else expression. Tutorial on Pure Haskell Programming 36 haskell_tutorial_cookbook_examples/Pure$ stack ghci *Main> :l IfThenElses.hs [1 of 1] Compiling Main ( IfThenElses.hs, interpreted ) Ok, modules loaded: Main. *Main> ageToString 15 "minor" *Main> ageToString 37 "adult" Maps Maps are simple to construct using a list of key-value tuples and are by default immutable. There is an example using mutable maps in the next chapter. We will look at the module Data.Map first in a GHCi repl, then later in a few full code examples. There is something new in line 1 of the following listing: I am assigning a short alias M to the module Data.Map. In referencing a function like fromList (which converts a list of tuples to a map) in the Data.Map module I can use M.fromList instead of Data.Map.fromList. This is a common practice so when you read someone else’s Haskell code, one of the first things you should do when reading a Haskell source file is to make note of the module name abbreviations at the top of the file. 1 haskell_tutorial_cookbook_examples/Pure$ stack ghci 2 *Main> import qualified Data.Map as M 3 *Main M> :t M.fromList 4 M.fromList :: Ord k => [(k, a)] -> M.Map k a 5 *Main M> let aTestMap = M.fromList [("height", 120), ("weight", 15)] 6 *Main M> :t aTestMap 7 aTestMap :: Num a => M.Map [Char] a 8 *Main M> :t lookup 9 lookup :: Eq a => a -> [(a, b)] -> Maybe b 10 *Main M> :t M.lookup 11 M.lookup :: Ord k => k -> M.Map k a -> Maybe a 12 *Main M> M.lookup "weight" aTestMap 13 Just 15 14 *Main M> M.lookup "address" aTestMap 15 Nothing The keys in a map must all be the same type and the values are also constrained to be of the same type. I almost always create maps using the helper function fromList in the module Data.Maps. We will only be using this method of map creation in later examples in this book so I am skipping coverage of other map building functions. I refer you to the Data.Map documentation¹⁵. ¹⁵https://www.stackage.org/haddock/lts-6.17/containers-0.5.6.2/Data-Map.html Tutorial on Pure Haskell Programming 37 The following example shows one way to use the Just and Nothing return values: 1 module MapExamples where 2 3 import qualified Data.Map as M -- from library containers 4 5 aTestMap = M.fromList [("height", 120), ("weight", 15)] 6 7 getNumericValue key aMap = 8 case M.lookup key aMap of 9 Nothing -> -1 10 Just value -> value 11 12 main = do 13 print $ getNumericValue "height" aTestMap 14 print $ getNumericValue "age" aTestMap The function getNumericValue shows one way to extract a value from an instance of type Maybe. The function lookup returns a Maybe value and in this example I use a case statement to test for a Nothing value or extract a wrapped value in a Just instance. Using Maybe in Haskell is a better alternative to checking for null values in C or Java. The output from running the main function in module MapExamples is: 1 haskell_tutorial_cookbook_examples/Pure$ stack ghci 2 *Main> :l MapExamples.hs 3 [1 of 1] Compiling MapExamples ( MapExamples.hs, interpreted ) 4 Ok, modules loaded: MapExamples. 5 *MapExamples> main 6 120 7 -1 Sets The documentation of Data.Set.Class can be found here¹⁶ and contains overloaded functions for the types of sets defined here¹⁷. For most of my work and for the examples later in this book, I create immutable sets from lists and the only operation I perform is checking to see if a value is in the set. The following examples in GHCI repl are what you need for the material in this book: ¹⁶https://www.stackage.org/haddock/lts-6.17/sets-0.0.5/Data-Set-Class.html ¹⁷https://www.stackage.org/package/sets Tutorial on Pure Haskell Programming 38 1 *Main> import qualified Data.Set as S 2 *Main S> let testSet = S.fromList ["cat","dog","bird"] 3 *Main S> :t testSet 4 testSet :: S.Set [Char] 5 *Main S> S.member "bird" testSet 6 True 7 *Main S> S.member "snake" testSet 8 False Sets and Maps are immutable so I find creating maps using a lists of key-value tuples and creating sets using lists is fine. That said, coming from the mutable Java, Ruby, Python, and Lisp programming languages, it took me a while to get used to immutability in Haskell. More on Functions In this section we will review what you have learned so far about Haskell functions and then look at a few more complex examples. We have been defining and using simple functions and we have seen that operators behave like infix functions. We can make operators act as prefix functions by wrapping them in parenthesis: *Main> 10 + 1 11 *Main> (+) 10 1 11 and we can make functions act as infix operators: *Main> div 100 9 11 *Main> 100 `div` 9 11 This back tick function to operator syntax works with functions we write also: Tutorial on Pure Haskell Programming 39 *Main> let myAdd a b = a + b *Main> :t myAdd myAdd :: Num a => a -> a -> a *Main> myAdd 1 2 3 *Main> 1 `myAdd` 2 3 Because we are working in a GHCi repl, in line 1 we use let to define the function myAdd. If you defined this function in a file and then loaded it, you would not use a let. In the map examples where we applied a function to a list of values, so far we have used functions that map input values to the same return type, like this (using both partial function evaluation and anonymous inline function): *Main> map (* 2) [5,6] [10,12] *Main> map (\x -> 2 * x) [5,6] [10,12] We can also map to different types; in this example we map from a list of Num values to a list containing sub-lists of Num values: 1 *Main> let makeList n = [0..n] 2 *Main> makeList 3 3 [0,1,2,3] 4 *Main> map makeList [2,3,4] 5 [[0,1,2],[0,1,2,3],[0,1,2,3,4]] As usual, I recommend that when you work in a GHCi repl you check the types of functions and values you are working with: 1 *Main> :t makeList 2 makeList :: (Enum t, Num t) => t -> [t] 3 *Main> :t [1,2] 4 [1,2] :: Num t => [t] 5 *Main> :t [[0,1,2],[0,1,2,3],[0,1,2,3,4]] 6 [[0,1,2],[0,1,2,3],[0,1,2,3,4]] :: Num t => [[t]] 7 *Main> In line 2 we see that for any type t the function signature is t -> [t] where the compiler determines that t is constrained to be a Num or Enum by examining how the input variable is used as a range parameter for constructing a list. Let’s make a new function that works on any type: Tutorial on Pure Haskell Programming 40 1 *Main> let make3 x = [x,x,x] 2 *Main> :t make3 3 make3 :: t -> [t] 4 *Main> :t make3 "abc" 5 make3 "abc" :: [[Char]] 6 *Main> make3 "abc" 7 ["abc","abc","abc"] 8 *Main> make3 7.1 9 [7.1,7.1,7.1] 10 *Main> :t make3 7.1 11 make3 7.1 :: Fractional t => [t] Notice in line 3 that the function make3 takes any type of input and returns a list of elements the same type as the input. We used makes3 both with a string argument and a fractional (floating point) number) argument. Comments on Dealing With Immutable Data and How to Structure Programs If you program in other programming languages that use mutable data then expect some feelings of disorientation initially when starting to use Haskell. It is common in other languages to maintain the state of a computation in an object and to mutate the value(s) in that object. While I cover mutable state in the next chapter the common pattern in Haskell is to create a data structure (we will use lists in examples here) and pass it to functions that return a new modified copy of the data structure as the returned value from the function. It is very common to keep passing the modified new copy of a data structure through a series of function calls. This may seem cumbersome when you are starting to use Haskell but quickly feels natural. The following example shows a simple case where a list is constructed in the function main and passed through two functions doubleOddElements and times10Elements: 1 module ChainedCalls where 2 3 doubleOddElements = 4 map (\x -> if x `mod` 2 == 0 then x else 2 * x) 5 6 times10Elements = map (* 10) 7 8 main = do 9 print $ doubleOddElements [0,1,2,3,4,5,6,7,8] 10 let aList = [0,1,2,3,4,5] 11 let newList = times10Elements $ doubleOddElements aList Tutorial on Pure Haskell Programming 41 12 print newList 13 let newList2 = (times10Elements . doubleOddElements) aList 14 print newList2 Notice that the expressions being evaluated in lines 11 and 13 are the same. In line 11 we are applying function doubleOddElements to the value of aList and passing this value to the outer function times10Elements. In line 13 we are creating a new function from composing two existing functions: times10Elements . doubleOddElements. The parenthesis in line 13 are required because the . operator has lower precedence than the application of function doubleOddElements so without the parenthesis line 13 would evaluate as times10Elements (doubleOddElements aList) which is not what I intended and would throw an error. The output is: 1 haskell_tutorial_cookbook_examples/Pure$ stack ghci 2 *Main> :l ChainedCalls.hs 3 [1 of 1] Compiling ChainedCalls ( ChainedCalls.hs, interpreted ) 4 Ok, modules loaded: ChainedCalls. 5 *ChainedCalls> main 6 [0,2,2,6,4,10,6,14,8] 7 [0,20,20,60,40,100] 8 [0,20,20,60,40,100] Using immutable data takes some getting used to. I am going to digress for a minute to talk about working with Haskell. The steps I take when writing new Haskell code are: • Be sure I understand the problem • How will data be represented - in Haskell I prefer using built-in types when possible • Determine which Haskell standard functions, modules, and 3rd party modules might be useful • Write and test the pure Haskell functions I think that I need for the application • Write an impure main function that fetches required data, calls the pure functions (which are no longer pure in the sense they are called from impure code), and saves the processed data. I am showing you many tiny examples but please keep in mind the entire process of writing longer programs. Error Handling We have seen examples of handling soft errors when no value can be calculated: use Maybe, Just, and Nothing. In bug free pure Haskell code, runtime exceptions should be very rare and I usually do not try to trap them. Using Maybe, Just, and Nothing is much better than, for example, throwing an error using the standard function error: Tutorial on Pure Haskell Programming 42 *Main> error "test error 123" *** Exception: test error 123 and then, in impure code catching the errors, here is the documentation¹⁸ for your reference. In impure code that performs IO or accesses network resources that could possibly run out of memory, etc., runtime errors can occur and you could use the same try catch coding style that you have probably used in other programming languages. I admit this is my personal coding style but I don’t like to catch runtime errors. I spent a long time writing Java applications and when possible I preferred using uncaught exceptions and I usually do the same when writing impure Haskell code. Because of Haskell’s type safety and excellent testing tools, it is possible to write nearly error free Haskell code. Later when we perform network IO we will rely on library support to handle errors and timeouts in a clean “Haskell like” way. Testing Haskell Code The example in this section is found in the directory haskell_tutorial_cookbook_examples/Testing- Haskell. If you use stack to create a new project then the framework for testing is generated for you: $ stack new TestingHaskell $ cd TestingHaskell $ ls -R LICENSE app test Setup.hs src TestingHaskell.cabal stack.yaml TestingHaskell//app: Main.hs TestingHaskell//src: Lib.hs TestingHaskell//test: Spec.hs $ cat test/Spec.hs main :: IO () main = putStrLn "Test suite not yet implemented" $ stack setup $ stack build ¹⁸https://wiki.haskell.org/Exception Tutorial on Pure Haskell Programming 43 This stack generated project is more complex than the project I created manually in the directory haskell_tutorial_cookbook_examples/Pure. The file Setup.hs is a placeholder and uses any module named Main in the app directory. This module, defined in app/Main.hs, imports the module Lib defined in src/Lib.hs. The generated test does not do anything, but let’s run it anyway: $ stack test Registering TestingHaskell-0.1.0.0... TestingHaskell-0.1.0.0: test (suite: TestingHaskell-test) Progress: 1/2 Test suite not yet implemented Completed 2 action(s). In the generated project, I made a few changes: • removed src/Lib.hs • added src/MyColors.hs providing the type MyColors that we defined earlier • modified app/Main.hs to use the MyColors type • added tests to test/Spec.hs Here is the contents of TestingHaskell/src/MyColors.hs: module MyColors where data MyColors = Orange | Red | Blue | Green | Silver deriving (Show, Eq) instance Ord MyColors where compare c1 c2 = compare (show c1) (show c2) And the new test/Spec.hs file: Tutorial on Pure Haskell Programming 44 1 import Test.Hspec 2 3 import MyColors 4 5 main :: IO () 6 main = hspec spec 7 8 spec :: Spec 9 spec = do 10 describe "head" $ do 11 it "test removing first list element" $ do 12 head [1,2,3,4] `shouldBe` 1 13 head ["the", "dog", "ran"] `shouldBe` "dog" -- should fail 14 describe "MyColors tests" $ do 15 it "test custom 'compare' function" $ do 16 MyColors.Green < MyColors.Red `shouldBe` True 17 Red > Silver `shouldBe` True -- should fail Notice how two of the tests are meant to fail as an example. Let’s run the tests: 1 $ stack test 2 TestingHaskell-0.1.0.0: test (suite: TestingHaskell-test) 3 4 Progress: 1/2 5 head 6 test removing first list element FAILED [1] 7 MyColors tests 8 test custom 'compare' function FAILED [2] 9 10 Failures: 11 12 test/Spec.hs:13: 13 1) head test removing first list element 14 expected: "dog" 15 but got: "the" 16 17 test/Spec.hs:17: 18 2) MyColors tests test custom 'compare' function 19 expected: True 20 but got: False 21 22 Randomized with seed 1233887367 23 Tutorial on Pure Haskell Programming 45 24 Finished in 0.0139 seconds 25 2 examples, 2 failures 26 27 Completed 2 action(s). 28 Test suite failure for package TestingHaskell-0.1.0.0 29 TestingHaskell-test: exited with: ExitFailure 1 30 Logs printed to console In line one with stack test we are asking stack to run app tests in the subdirectory test. All Haskell source files in subdirectory test are assumed to be test files. In the listing for file test/Spec.hs we have two tests that fail on purpose and you see the output for the failed tests at lines 12-15 and 17-20. Because the Haskell compiler does such a good job at finding type errors I have fewer errors in my Haskell code compared to languages like Ruby and Common Lisp. As a result I find myself writing fewer tests for my Haskell code than I would write in other languages. Still, I recommend some tests for each of your projects; decide for yourself how much relative effort you want to put into writing tests. Pure Haskell Wrap Up I hope you are starting to get an appreciation for using composition of functions and higher order functions to enable us to compose programs from smaller pieces that can be joined together. This composition is made easier when using pure functions that always return the same value when called with the same type of arguments. We will continue to see examples of how lazy evaluation simplifies code because we can use infinitely large lists with the assurance that values are not calculated until they are needed. In addition to Haskell code generally having fewer errors (after it gets by the compiler!) other advantages of functional programming include more concise code that is easy to read and understand once you get some experience with the language. Tutorial on Impure Haskell Programming One of the great things about Haskell is that the language encourages us to think of our code in two parts: • Pure functional code (functions have no side effects) that is easy to write and test. Functional code tends to be shorter and less likely to be imperative (i.e., more functional, using maps and recursion, and less use of loops as in Java or C++). • Impure code that deals with side effects like file and network IO, maintaining state in a typesafe way, and isolate imperative code that has side effects. In his excellent Functional Programming with Haskell class at eDX¹⁹ Erik Meijer described pure code as being islands in the ocean and the ocean representing impure code. He says that it is a design decision how much of your code is pure (islands) and how much is impure (the ocean). This model of looking at Haskel programs works for me. My use the word “impure” is common for refering to Haskell code with side effects. Haskell is a purely functional language and side effects like I/O are best handled in a pure functional way using by wrapping pure values in Mondads. In addition to showing you reusable examples of impure code that you will likely need in your own programs, a major theme of this chapter is handling impure code in a convenient type safe fashion. Any Monad, which wraps a single value, is used to safely manage state. I will introduce you to using Monad types as required for the examples in this chapter. This tutorial style introduction will prepare you for understanding the sample applications later. Hello IO () Monad I showed you many examples of pure code in the last chapter but most examples in source files (as opposed to those shown in a GHCi repl) had a bit of impure code in them: the main function like the following that simply writes a string of characters to standard output: main = do print "hello world" The type of function main is: ¹⁹http://edx.org Tutorial on Impure Haskell Programming 47 *Main> :t main main :: IO () The IO () monad is an IO value wrapped in a type safe way. Because Haskell is a lazy evaluation language, the value is not evaluated until it is used. Every IO () action returns exactly one value. Think of the word “mono” (or “one”) when you think of Monads because they always return one value. Monads are also used to connnect together parts of a program. What is it about the function main in the last example that makes its type an IO ()? Consider the simple main function here: module NoIO where main = do let i = 1 in 2 * i and its type: *Main> :l NoIO [1 of 1] Compiling NoIO ( NoIO.hs, interpreted ) Ok, modules loaded: NoIO. *NoIO> main 2 *NoIO> :t main main :: Integer *NoIO> OK, now you see that there is nothing special about a main function: it gets its type from the type of value returned from the function. It is common to have the return type depend on the function argument types. The first example returns a type IO () because it returns a print do expression: *Main> :t print print :: Show a => a -> IO () *Main> :t putStrLn putStrLn :: String -> IO () The function print shows the enclosing quote characters when displaying a string while putStrLn does not. In the first example, what happens when we stitch together several expressions that have type IO ()? Consider: Tutorial on Impure Haskell Programming 48 main = do print 1 print "cat" Function main is still of type IO (). You have seen do expressions frequently in examples and now we will dig into what the do expression is and why we use it. The do notation makes working with monads easier. There are alternatives to using do that we will look at later. One thing to note is that if you are doing bindings inside a do expression using a let with a in expression, you need to wrap the bindings in a new (inner) do expression if there is more than one line of code following the let statement. The way to avoid requiring a nested do expression is to not use in in a let expression inside a do block of code. Yes, this sounds complicated but let’s clear up any confusion by looking at the examples found in the file ImPure/DoLetExample.hs (you might also want to look at the similar example file ImPure/DoLetExample2.hs that uses bind operators instead of a do statement; we will look at bind operators in the next section): module DoLetExample where example1 = do -- good style putStrLn "Enter an integer number:" s <- getLine let number = (read s :: Int) + 2 putStrLn $ "Number plus 2 = " ++ (show number) example2 = do -- avoid using "in" inside a do statement putStrLn "Enter an integer number:" s <- getLine let number = (read s :: Int) + 2 in putStrLn $ "Number plus 2 = " ++ (show number) example3 = do -- avoid using "in" inside a do statement putStrLn "Enter an integer number:" s <- getLine let number = (read s :: Int) + 2 in do -- this do is required since we have two dependent statements: putStrLn "Result is:" putStrLn $ "Number plus 2 = " ++ (show number) main = do example1 example2 example3 Tutorial on Impure Haskell Programming 49 You should use the pattern in function example1 and not the pattern in example2. The do expression is syntactic sugar that allows programmers to string together a sequence of operations that can mix pure and impure code. To be clear, the left arrow <- is used when the expression on the right side is some type of IO () that needs to be lifted before being used. A let do expression is used when the right side expression is a pure value. On lines 6 and 12 we are using function read to converting a string read out of IO String () to an integer value. Remember that the value of s (from calling readLine) is an IO () so in the same way you might read from a file, in this example we are reading a value from an IO () value. A Note About >> and >>= Operators So far in this book I have been using the syntactic sugar of the do expression to work with Monads like IO () and I will usually use this syntactic sugar for the rest of this book. Even though I find it easier to write and read code using do, many Haskell programmers prefer >> and >>= so let’s go over these operators so you won’t be confused when reading Haskell code that uses them. Also, when we use do expressions in code the compiler generates similar code using these >> and >>= operators. The Monad type class defines the operators >>= and return. We turn to the GHCi repl to experiment with and learn about these operators: 1 *Main> :t (>>) 2 (>>) :: Monad m => m a -> m b -> m b 3 *Main> :t (>>=) 4 (>>=) :: Monad m => m a -> (a -> m b) -> m b 5 *Main> :t return 6 return :: Monad m => a -> m a We start with the return function type return :: Monad m ⇒ a -> m a which tells us that for a monad m the function return takes a value and wraps it in a monad. We will see examples of the return function used to return a wrapped value from a function that returns IO () values. The bind operator (>>) is used to evaluate two expressions in sequence. As an example, we can replace this do expression: main = do example1 example2 example3 with the following: Tutorial on Impure Haskell Programming 50 main = example1 >> example2 >> example3 The operator >>= is similar to >> except that it evaluates the left hand expression and pipes its value into the right hand side expression. The left hand side expression is evaluated to some type of IO () and the expression on the right hand side typically reads from the input IO (). An example will make this simpler to understand: 1 module DoLetExample3 where 2 3 example3 = putStrLn "Enter an integer number:" >> getLine 4 5 example4 mv = do 6 let number = (read mv :: Int) + 2 7 putStrLn $ "Number plus 2 = " ++ (show number) 8 9 main = example3 >>= example4 Note that I could have used a do statement to define function example3 but used a bind operator instead. Let’s run this example and look at the function types. Please don’t just quickly read through the following listing; when you understand what is happening in this example then for the rest of your life programming in Haskell things will be easier for you: 1 *DoLetExample3> main 2 Enter an integer number: 3 1 4 Number plus 2 = 3 5 *DoLetExample3> :t example3 6 example3 :: IO String 7 *DoLetExample3> :t example4 8 example4 :: String -> IO () 9 *DoLetExample3> :t main 10 main :: IO () 11 *DoLetExample3> let x = example3 12 *DoLetExample3> x 13 Enter an integer number: 14 4 15 "4" 16 *DoLetExample3> :t x 17 x :: IO String 18 *DoLetExample3> x >>= example4 19 Enter an integer number: 20 3 21 Number plus 2 = 5 Tutorial on Impure Haskell Programming 51 The interesting part starts at line 11 when we define x to be the returned value from calling example3. Remember that Haskell is a lazy language: evaluation is postponed until a value is actually used. Working inside a GHCi repl is like working interactively inside a do expression. When we evaluate x in line 12 then the code in function example3 is actually executed (notice this is where the user prompt to enter a number occurs). In line 18 we are re-evaluationg the value in x and passing the resulting IO String () value to the function example4. Haskell is a “piecemeal” programming language as are the Lisp family of languages where a repl is used to write little pieces code that are collected into programs. For simple code in Haskell (and Lisp languages) I do sometimes directly enter code into a text editor but very ofter I start in a repl, experiment, debug, refine, and then copy into an edited file. Console IO Example with Stack Configuration The directory CommandLineApps contains two simple applications that interact with STDIO, that is to write to the console and read from the keyboard. The first example can be found in file CommandLineApp/CommandLine1.hs: 1 module Main where 2 3 import System.IO 4 import Data.Char (toUpper) 5 6 main = do 7 putStrLn "Enter a line of text for test 1:" 8 s <- getLine 9 putStrLn $ "As upper case:\t" ++ (map toUpper s) 10 main Lines 3 and 4 import the entire System.IO module (that is, import all exported symbols from System.IO) and just the function toUpper from module Data.Char. System.IO is a standard Haskell module and we do not have to do anything special to import it. The Data.Char is stored in the package text. The package text is contained in the library package base which is specified in the CommandLineApp.cabal configuration file that we will look at soon. Use of the <- assignment in line 8 in the last Haskell listing is important to understand. It might occur to you to leave out line 8 and just place the getLine function call directly in line 9, like this: 1 putStrLn $ "As upper case:\t" ++ (map toUpper getLine) If you try this (please do!) you will see compilation errors like: Tutorial on Impure Haskell Programming 52 1 Couldn't match expected type ‘[Char]’ with actual type ‘IO String’ 2 In the second argument of ‘map’, namely ‘getLine’ 3 In the second argument of ‘(++)’, namely ‘(map toUpper getLine)’ The type of getLine is an IO () that is a wrapped IO call. The value is not computed until it is used. The <- assignment in line 8 evaluates the IO call and unwraps the result of the IO operation so that it can be used. I don’t spend much time covering stack project configuration files in this book but I do recommend that as you work through examples to also look for a file in each example directory ending with the file extension .cabal that specified which packages need to be loaded. For some examples it might take a while to download and configure libraries the first time you run either stack build or stack ghci in an example directory. The Haskell stack project in the CommandLineApp directory has five target applications as we can see in the CommandLineApp.cabal file. I am not going to go into much detail about the project cabal and stack.yaml files generated by stack when you create a new project except for configuration data that I had to add manually; in this case, I added two executable targets at the end of the cabal file (note: the project in the github repository for this book has more executable targets, I just show a few here): 1 executable CommandLine1 2 hs-source-dirs: . 3 main-is: CommandLine1.hs 4 default-language: Haskell2010 5 build-depends: base >= 4.7 && < 5 6 7 executable CommandLine2 8 hs-source-dirs: . 9 main-is: CommandLine2.hs 10 default-language: Haskell2010 11 build-depends: base >= 4.7 && < 5 12 13 executable ReadTextFile 14 hs-source-dirs: . 15 main-is: ReadTextFile.hs 16 default-language: Haskell2010 17 build-depends: base >= 4.7 && < 5 18 19 executable GameLoop1 20 hs-source-dirs: . 21 main-is: GameLoop1.hs 22 default-language: Haskell2010 23 build-depends: base >= 4.7 && < 5, time Tutorial on Impure Haskell Programming 53 24 25 executable GameLoop2 26 hs-source-dirs: . 27 main-is: GameLoop2.hs 28 default-language: Haskell2010 29 build-depends: base >= 4.7 && < 5, random The executable name determines the compiled and linked executable file name. For line 1, an executable file “CommandLine1” (or “CommandLine1.exe”” on Windows) will be generated. The parameter hs-source-dirs is a comma separated list of source file directories. In this simple example all Haskell source files are in the project’s top level directory “../”. The build-depends is a comma separated list of module libraries; here we only use the base built-in modules packaged with Haskell. Let’s use a GHCi repl to poke at this code and understand it better. The project defined in CommandLineApp/CommandLineApp.cabal contains many executable targets so when we enter a GHCi repl, the available targets are shown and you can choose one; in this case I am selecting the first target defined in the cabal file. In later GHCi repl listings, I will edit out this output for brevity: 1 $ stack ghci 2 3 * * * * * * * * 4 The main module to load is ambiguous. Candidates are: 5 1. Package `CommandLineApp' component exe:CommandLine1 with main-is file: /Users/mar\ 6 kw/GITHUB/haskell_tutorial_cookbook_examples/CommandLineApp/CommandLine1.hs 7 2. Package `CommandLineApp' component exe:CommandLine2 with main-is file: /Users/mar\ 8 kw/GITHUB/haskell_tutorial_cookbook_examples/CommandLineApp/CommandLine2.hs 9 3. Package `CommandLineApp' component exe:ReadTextFile with main-is file: /Users/mar\ 10 kw/GITHUB/haskell_tutorial_cookbook_examples/CommandLineApp/ReadTextFile.hs 11 You can specify which one to pick by: 12 * Specifying targets to stack ghci e.g. stack ghci CommandLineApp:exe:CommandLine1 13 * Specifying what the main is e.g. stack ghci --main-is CommandLineApp:exe:CommandL\ 14 ine1 15 * Choosing from the candidate above [1..3] 16 * * * * * * * * 17 18 Specify main module to use (press enter to load none): 1 19 Loading main module from cadidate 1, --main-is /Users/markw/GITHUB/haskell_tutorial_\ 20 cookbook_examples/CommandLineApp/CommandLine1.hs 21 22 Configuring GHCi with the following packages: CommandLineApp 23 GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help 24 Ok, modules loaded: none. 25 [1 of 1] Compiling Main ( /Users/markw/GITHUB/haskell_tutorial_cookbook_\ Tutorial on Impure Haskell Programming 54 26 examples/CommandLineApp/CommandLine1.hs, interpreted ) 27 Ok, modules loaded: Main. 28 *Main> :t main 29 main :: IO b 30 *Main> :info main 31 main :: IO b 32 -- Defined at /Users/markw/GITHUB/haskell_tutorial_cookbook_examples/CommandLineApp/\ 33 CommandLine1.hs:6:1 34 *Main> :t getLine 35 getLine :: IO String 36 *Main> :t putStrLn 37 putStrLn :: String -> IO () 38 *Main> main 39 Enter a line of text for test 1: 40 line 1 41 As upper case: LINE 1 42 Enter a line of text for test 1: 43 line 2 44 As upper case: LINE 2 45 Enter a line of text for test 1: 46 ^C Interrupted. 47 *Main> In line 36 the function getLine is of type getLine :: IO String which means that calling getLine returns a value that is a computation to get a line of text from stdio but the IO operation is not performed until the value is used. Please note that it is unusual to put five executable targets in a project’s cabal file. I am only doing so here because I wanted to group five similar examples together in this subdirectory of the github repo for this book²⁰. This repo has 16 example subdirectories, and the number would be much greater if I didn’t collect similar examples together. We will use the example in file CommandLine2.hs in the next section which is similar to this example but also appends the user input to a text file. File IO We will now look at a short example of doing file IO. We will write Haskell simple string values to a file. If you are using the more efficient Haskell Text values, the code is the same. Text values are more efficient than simple string values when dealing with a lot of data and we will later use a compiler setting to automatically convert between the underlying formats. The following listing shows CommandLineApp/CommandLine2.hs: ²⁰https://github.com/mark-watson/haskell_tutorial_cookbook_examples Tutorial on Impure Haskell Programming 55 1 module Main where 2 3 import System.IO 4 import Data.Char (toUpper) 5 6 main = do 7 putStrLn "Enter a line of text for test2:" 8 s <- getLine 9 putStrLn $ "As upper case:\t" ++ (map toUpper s) 10 appendFile "temp.txt" $ s ++ "\n" 11 main Note the use of recursion in line 11 to make this program loop forever until you use a COntrol-c to stop the program. In line 10 we are using function appendFile to open a file, append a string to it, and then close the file. appendFile is of type appendFile :: FilePath -> String -> IO (). It looks like we are passing a simple string as a file name instead of type FilePath but if you look up the definition of FilePath you will see that it is just an alias for string: type FilePath = String. Running this example in a GHCi repl, with much of the initial printout from running stack ghci not shown: 1 $ stack ghci 2 CommandLineApp-0.1.0.0: configure 3 Specify main module to use (press enter to load none): 2 4 Ok, modules loaded: Main. 5 *Main> main 6 Enter a line of text for test2: 7 line 1 8 As upper case: LINE 1 9 Enter a line of text for test2: 10 line 2 11 As upper case: LINE 2 12 Enter a line of text for test2: 13 ^C Interrupted. 14 *Main> The file temp.txt was just created. The next example used ReadTextFile.hs to read the file temp.txt and process the text by finding all words in the file: Tutorial on Impure Haskell Programming 56 1 module Main where 2 3 import System.IO 4 import Control.Monad 5 6 main = do 7 entireFileAsString <- readFile "temp.txt" 8 print entireFileAsString 9 let allWords = words entireFileAsString 10 print allWords readFile is a high-level function because it manages for you reading a file and closing the file handle it uses internally. The built in function words splits a string on spaces and returns a list of strings [String] that are printed on line 7: 1 $ stack ghci 2 CommandLineApp-0.1.0.0: build 3 Specify main module to use (press enter to load none): 3 4 Ok, modules loaded: ReadTextFile. 5 *ReadTextFile> main 6 "line 1\nline 2\n" 7 ["line","1","line","2"] 8 *ReadTextFile> 9 *ReadTextFile> :t readFile 10 readFile :: FilePath -> IO String 11 *ReadTextFile> :type words 12 words :: String -> [String] What if the function readFile encounters an error? That is the subject for the next section. Error Handling in Impure Code I know you have been patiently waiting to see how we handle errors in Haskell code. Your wait is over! We will look at several common types of runtime errors and how to deal with them. In the last section we used the function readFile to read the contents of a text file temp.txt. What if temp.txt does not exist? Well, then we get an error like the following when running the example program in ReadTextFile.hs: *Main> main *** Exception: temp.txt: openFile: does not exist (No such file or directory) Tutorial on Impure Haskell Programming 57 Let’s modify this last example in a new file ReadTextFileErrorHandling.hs that catches a file not found error. The following example is derived from the first example in Michael Snoyman’s article Catching all exceptions²¹. This example does not work inside threads; if you need to catch errors inside a thread then see the second example in Michael’s article. 1 module Main where 2 3 import System.IO 4 import Control.Exception 5 6 -- catchAny by Michael Snoyman: 7 catchAny :: IO a -> (SomeException -> IO a) -> IO a 8 catchAny = Control.Exception.catch 9 10 safeFileReader :: FilePath -> IO String 11 safeFileReader fPath = do 12 entireFileAsString <- catchAny (readFile "temp.txt") $ \error -> do 13 putStrLn $ "Error: " ++ show error 14 return "" 15 return entireFileAsString 16 17 main :: IO () 18 main = do 19 fContents <- safeFileReader "temp.txt" 20 print fContents 21 print $ words fContents I will run this twice: the first time without the file temp.txt present and a second time with temp.txt in the current durectory: *Main> :l ReadTextFileErrorHandling.hs [1 of 1] Compiling Main ( ReadTextFileErrorHandling.hs, interpreted ) Ok, modules loaded: Main. *Main> main Error: temp.txt: openFile: does not exist (No such file or directory) "" [] 1 *Main> main "line 1\nline 2\n" ["line","1","line","2"] ²¹https://www.schoolofhaskell.com/user/snoyberg/general-haskell/exceptions/catching-all-exceptions Tutorial on Impure Haskell Programming 58 Until you need to handle runtime errors in a multi-threaded Haskell program, following this example should be sufficient. In the next section we look at Network IO. Network IO We will experiment with three network IO examples in this book: • A simple socket client/server example in this section. • Reading web pages in the chapter “Web Scraping” • Querying remote RDF endpoints in the chapter “Linked Data and the Semantic Web” We start by using a high level library, network-simple for both the client and serve examples in the next two sub-sections. The client and sever examples are in the directory haskell_tutorial_- cookbook_examples/ClientServer in the files Client.hs and Server.hs. Server Using network-simple Library The Haskell Network and Network.Simple modules use strings represented as Data.ByteString.Char8 data so as seen in line 1 I set the language type OverloadedStrings. The following example in file ClientServer/Server.hs is derived from an example in the network-simple project: 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Server where 4 5 import Control.Monad 6 import qualified Data.ByteString.Char8 as B 7 import qualified Network.Simple.TCP as T 8 9 reverseStringLoop sock = do 10 mbs <- T.recv sock 4096 11 case mbs of 12 Just bs -> T.send sock (B.reverse bs) >> reverseStringLoop sock 13 Nothing -> return () 14 15 main :: IO () 16 main = T.withSocketsDo $ do -- derived from library example 17 T.listen "*" "3000" $ \(lsock, laddr) -> do 18 putStrLn $ "Listening at " ++ show laddr 19 forever . T.acceptFork lsock $ \(sock, addr) -> do 20 putStrLn $ "Connection from " ++ show addr 21 reverseStringLoop sock Tutorial on Impure Haskell Programming 59 The server accepts a string, reverses the string, and returns the reversed string to the client. I am assuming that you have done some network programming and are familiar with sockets, etc. The function reverseStringLoop defined in lines 9-13 accepts a socket as a parameter and returns a value of type MonadIO that wraps a byte-string value. In line 10 we use the T.recv function that takes two arguments: a socket and the maximum number of bytes to received from the client. The case expression reverses the received byte string, sends the reversed string back to the client, and recursively calls itself waiting for new data from the client. If the client breaks the socket connection, then the function retuns an empty MonadIO(). The main function defined in lines 15-21 listens on port 3000 for new client socket connections. In line 19, the function T.acceptFork accepts as an argument a socket value and a function to execute; the complete type is: 1 *Main> :t T.acceptFork 2 T.acceptFork 3 :: transformers-0.4.2.0:Control.Monad.IO.Class.MonadIO m => 4 T.Socket 5 -> ((T.Socket, T.SockAddr) -> IO ()) -> m GHC.Conc.Sync.ThreadId Don’t let line 3 scare you; the GHCi repl is just showing you where this type of MonadIO is defined. The return type refers to a thread ID that is passed to the function forever :: Monad m ⇒ m a -> m b that is defined in the module Control.Monad and lets the thread run until it teminates. The network-simple package is fairly high level and relatively simple to use. If you are interested you can find many client/server examples on the web that use the lower-level network package. We will develop a client application to talk with this server in the next section but if you want to immediately try the server, start it and then run telnet in another terminal window: Prelude> :l Server [1 of 1] Compiling Server ( Server.hs, interpreted ) Ok, modules loaded: Server. *Main> main Listening at 0.0.0.0:3000 And run telnet: Tutorial on Impure Haskell Programming 60 $ telnet localhost 3000 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 12345 54321 The dog ran down the street teerts eht nwod nar god ehT In the next section we write a simple client to talk with this service example. Client Using network-simple Library I want to use automatic conversion between strings represented as Data.ByteString.Char8 data and regular [Char] strings so as seen in line 1 I set the language type OverloadedStrings in the example in file Client.hs: 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Client where 4 5 import Control.Monad 6 import qualified Network.Simple.TCP as T 7 8 main = do 9 T.connect "127.0.0.1" "3000" $ \(connectionSocket, remoteAddr) -> do 10 putStrLn $ "Connection established to " ++ show remoteAddr 11 T.send connectionSocket "test123" 12 response <- T.recv connectionSocket 100 13 case response of 14 Just s -> putStrLn $ "Response: " ++ show s 15 Nothing -> putStrLn "No response from server" The function T.connect in line 9 accepts arguments for a host name, a port, and a function to call with the connection socket to the server and the server’s address. The body of this inline function, defined in in the middle on line 9 and continuing in lines 10-15, prints the server address, sends a string “test123” to the server, and waits for a response back from the server (T.recv in line 12). The server response is printed, or a warning that no response was received. While the example in file Server.hs is running in another terminal, we can run the client interactively: Tutorial on Impure Haskell Programming 61 Prelude> :l Client.hs [1 of 1] Compiling Client ( Client.hs, interpreted ) Ok, modules loaded: Client. *Main main Connection established to 127.0.0.1:3000 Response: "321tset" A Haskell Game Loop that Maintains State Functionally The example in this section can be found in the file GameLoop2.hs in the directory haskell_tuto- rial_cookbook_examples/CommandLineApp. This example uses the random package to generate a seed random number for a simple number guessing game. An alternative implementation in GameLoop1.hs, which I won’t discuss, uses the system time to generate a seed. This is an important example because it demonstrates one way to maintain state in a functional way. We have a read-only game state value that is passed to the function gameLoop which modifies the read-only game state passed as an argument and returns a newly constructed game state as the function’s returned value. This is a common pattern that we will see again later when we develop an application to play a simplified version of the card game Blackjack in the chapter “Haskell Program to Play the Blackjack Card Game.” 1 module GameLoop2 where 2 3 import System.Random 4 5 data GameState = GameState { numberToGuess::Integer, numTries::Integer} 6 deriving (Show) 7 8 gameLoop :: GameState -> IO GameState 9 gameLoop gs = do 10 print $ numberToGuess gs 11 putStrLn "Enter a number:" 12 s <- getLine 13 let num = read s :: Integer 14 if num == numberToGuess gs then 15 return gs 16 else gameLoop $ GameState (numberToGuess gs) ((numTries gs) + 1) 17 18 main = do 19 pTime <- randomRIO(1,4) Tutorial on Impure Haskell Programming 62 20 let gameState = GameState pTime 1 21 print "Guess a number between 1 and 4" 22 gameLoop gameState You notice in line 12 that since we are inside of a do expression we can lift (or unwrap) the IO String () value returned from getLine to a string value that we can use directly. This is a pattern we will use repeatedly. The value returned from getLine is not used until line 13 when we use function read to extract the value from the IO String () value getLine returned. In the if expression in lines 14-16 we check if the user has input the correct value and can then simply return the input game state to the calling main function. If the user has not guessed the correct number then in line 16 we create a new game state value and call the function gameLoop recursively with the newly constructed game state. The following listing shows a sample session playing the number guessing game. Prelude> :l GameLoop2.hs [1 of 1] Compiling GameLoop2 ( GameLoop2.hs, interpreted ) Ok, modules loaded: GameLoop2. *GameLoop2> main "Guess a number between 1 and 4" Enter a number: 1 Enter a number: 3 Enter a number: 4 GameState {numberToGuess = 4, numTries = 3} *GameLoop2> main "Guess a number between 1 and 4" Enter a number: 1 Enter a number: 2 GameState {numberToGuess = 2, numTries = 2} *GameLoop2> We will use this pattern for maintaining state in a game in the later chapter “Haskell Program to Play the Blackjack Card Game.” Efficiency of Haskell Strings Except for the Client/Server example, so far we have been mostly using simple String values where String is a list of characters [Char]. For longer strings it is much more efficient to use the module Tutorial on Impure Haskell Programming 63 Data.Text²² that is defined in package text (so text needs to be added to the dependencies in your cabal file). Many Haskell libraries use the simple String type but the use of Data.Text is also common, especially in applications handling large amounts of string data. We have already seen examples of this in the client/server example programs. Fortunately Haskell is a strongly typed language that supports a language extension for automatically handling both simple strings and the more efficient text types. This language extension, as we have seen in a previous example, is activated by adding the following near the top of a Haskell source file: {-# LANGUAGE OverloadedStrings #-} As much as possible I am going to use simple strings in this book and when we need both simple strings and byte strings I will then use OverloadedStrings for automatic conversion. This conversion is performed by knowing the type signatures of data and functions in surrounding code. The compiler figures out what type of string is expected and does the conversion for you. A More Detailed Look at Monads We have been casually using different types of IO () monads. In this section I will introduce you to the State monad and then we will take a deeper look at IO (). While we will be just skimming the surface of the topic of monads, my goal in this section is to teach you enough to work through the remaining examples in this book. Monads are types belonging to the Monad type class that specifies one operator and one function: class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a The >>= operator takes two arguments: a monad wrapping a value (type a in the above listing) and a function taking the same type a and returning a monad wrapping a new type b. The return value of >>= is a new monad wrapping a value of type b. The Monad type class function return takes any value and wraps it in a new monad. The naming of return is confusing because it does not alter the flow of execution in a program like a return statement in Java, rather, it wraps a value in a monad. State Monad The definition for the constructor of a State monad is: ²²https://www.stackage.org/nightly-2016-09-18/package/text-1.2.2.1 Tutorial on Impure Haskell Programming 64 newtype State s a = State { runState :: s -> (a, s) } So far we have been using data to define new types and newtype is similar except newtype acts during compile time and no type information is present at runtime. All monads contain a value and for the State monad this value is a function. The >>= operator is called the bind operator. The accessor function runState provides the means to access the value in the state. The following example is in the file StateMonad/State1.hs. In this example, incrementState is a state monad that increases its wrapped integer value by one when it is executed. Remember that the return function is perhaps poorly named because it does not immediately “return” from a computation block as it does in other languages; return simply wraps a value as a monad without redirecting the execution flow. In order to make the following example more clear, I implement the increment state function twice, once using the do notation that you are already familiar with and once using the >>= bind operator: 1 module Main where 2 3 import Control.Monad.State 4 5 incrementState :: State Int Int 6 incrementState = do 7 n <- get 8 put (n + 1) 9 return n 10 11 -- same state monad without using a 'do' expression: 12 incrementState2 :: State Int Int 13 incrementState2 = get >>= \a -> 14 put (a + 1) >>= \b -> 15 return a 16 17 bumpVals (a,b) = (a+1, b+2) 18 19 main = do 20 print $ runState incrementState 1 -- (1,2) == (return value, final state) 21 print $ runState incrementState2 1 -- (1,2) == (return value, final state) 22 print $ runState (mapState bumpVals incrementState) 1 -- (2,4) 23 print $ evalState incrementState 1 -- 1 == return value 24 print $ execState incrementState 1 -- 2 == final state Here we have used two very different looking, yet equivalent, styles for accessing and modifying state monad values. In lines 6-9 we are using the do notation. The function get in line 7 returns one value: the value wrapped in a state monad. Function put in line 8 replaces the wrapped value in the Tutorial on Impure Haskell Programming 65 state monad, in this example by incrementing its numeric value. Finally return wraps the value in a monad. I am using the runState function defined in lines 20-24 that returns a tuple: the first tuple value is the result of the computation performed by the function passed to runState (incrementState and incrementState2 in these examples) and the second tuple value is the final wrapped state. In lines 12-15 I reimplemented increment state using the bind function (>>=). We have seen before that >>= passes the value on its left side to the computation on its right side, that is function calls in lines 13-15: \a -> put (a + 1) \b -> return a It is a matter of personal taste whether to code using bind or do. I almost always use the do notation in my own code but I wanted to cover bind both in case you prefer that notation and so you can also read and understand Haskell code using bind. We continue looking at alternatives to the do notation in the next section. Using Applicative Operators <$> and <*>: Finding Common Words in Files My goal in this book is to show you a minimal subset of Haskell that is relatively easy to understand and use for coding. However, a big part of using a language is reading other people’s code so I do need to introduce a few more constructs that are widely used: applicative operators. Before we begin I need to introduce you to a new term: Functor which is a typeclass that defines only one method fmap. fmap is used to map a function over an IO action and has the type signature: fmap :: Functor f => (a -> b) -> f a -> f b fmap can be used to apply a pure function like (a -> b) to an IO a and return a new IO b without unwrapping the original IO (). The following short example (in file ImPure/FmapExample.hs) will let you play with this idea: Tutorial on Impure Haskell Programming 66 1 module FmapExample where 2 3 fileToWords fileName = do 4 fileText <- readFile fileName 5 return $ words fileText 6 7 main = do 8 words1 <- fileToWords "text1.txt" 9 print $ reverse words1 10 words2 <- fmap reverse $ fileToWords "text1.txt" 11 print words2 In lines 8-9 I am unwrapping the result of the IO [String] returned by the function fileToWords and then applying the pure function words to the unwrapped value. Wouldn’t it be nice to operate on the words in the file without unwrapping the [String] value? You can do this using fmap as seen in lines 10-11. Please take a moment to understand what line 10 is doing. Here is line 10: words2 <- fmap reverse $ fileToWords "text1.txt" First we read the words in a file into an IO [String] monad: fileToWords "text1.txt" Then we apply the pure function reverse to the values inside the IO [String] monad, creating a new copy: fmap reverse $ fileToWords "text1.txt" Note that from the type of the fmap function, the input monad and output monad can wrap different types. For example, if we applied the function head to an IO [String] we would get an outut of IO [Char]. Finally we unwrap the [String] value inside the monad and set words2 to this unwrapped value: words2 <- fmap reverse $ fileToWords "text1.txt" In summary, the Functor typeclass defines one method fmap that is useful for operating on data wrapped inside a monad. We will now implement a small application that finds common words in two text files, implementing the primary function three times, using: • The do notation. • The >>= bind operator. • The Applicative operators <$> and <*> Let’s look at the types for these operators: Tutorial on Impure Haskell Programming 67 (<$>) :: Functor f => (a -> b) -> f a -> f b (<*>) :: Applicative f => f (a -> b) -> f a -> f b We will use both <$> and <*> in the function commonWords3 in this example and I will explain how these operators work after the following program listing. This practical example will give you a chance to experiment more with Haskell (you do have a GHCi repl open now, right?). The source file for this example is in the file ImPure/CommonWords.hs: 1 module CommonWords where 2 3 import Data.Set (fromList, toList, intersection) 4 import Data.Char (toLower) 5 6 fileToWords fileName = do 7 fileText <- readFile fileName 8 return $ (fromList . words) (map toLower fileText) 9 10 commonWords file1 file2 = do 11 words1 <- fileToWords file1 12 words2 <- fileToWords file2 13 return $ toList $ intersection words1 words2 14 15 commonWords2 file1 file2 = 16 fileToWords file1 >>= \f1 -> 17 fileToWords file2 >>= \f2 -> 18 return $ toList $ intersection f1 f2 19 20 commonWords3 file1 file2 = 21 (\f1 f2 -> toList $ intersection f1 f2) 22 <$> fileToWords file1 23 <*> fileToWords file2 24 25 main = do 26 cw <- commonWords "text1.txt" "text2.txt" 27 print cw 28 cw2 <- commonWords "text1.txt" "text2.txt" 29 print cw2 30 cw3 <- commonWords "text1.txt" "text2.txt" 31 print cw3 The function fileToWords defined in lines 6-8 simply reads a file, as in the last example, maps contents of the file to lower case, uses words to convert a String to a [String] list of individual Tutorial on Impure Haskell Programming 68 words, and uses the function Data.Set.fromList to create a set from a list of words that in general will have duplicates. We are retuning an IO (Data.Set.Base.Set String) value so we can later perform a set intersection operation. In other applications you might want to apply Data.Set.toList before returning the value from fileToWords so the return type of the function would be IO [String]. The last listing defines three similar functions commonWords, commonWords2, and common- Words3. commonWords defined in lines 10-13 should hopefully look routine and familiar to you now. We set the local variables with the unwrapped (i.e., extracted from a monad) contents of the unique words in two files, and then return monad wrapping the intersection of the words in both files. The function commonWords2 is really the same as commonWords except that it uses the bind >>= operator instead of the do notation. The interesting function in this example is commonWords3 in lines 20-23 which uses the applicative operators <$> and <*>. Notice the pure function defined inline in line 21: it takes two arguments of type set and returns the set intersection of the arguments. The operator <$> takes a function on the left side and a monad on the right side which contains the wrapped value to be passed as the argument f1. <*> supplies the value for the inline function arguments f2. To rephrase how lines 21-23 work: we are calling fileToWords twice, both times getting a monad. These two wrapped monad values are passed as arguments to the inline function in line 21 and the result of evaluating this inline function is returned as the value of the function commonWords3. I hope that this example has at least provided you with “reading knowledge” of the Applicative operators <$> and <*> and has also given you one more example of replacing the do notation with the use of the bind >>= operator. List Comprehensions Using the do Notation We saw examples of list comprehensions in the last chapter on pure Haskell programming. We can use return to get lists values that are instances of type Monad: *Prelude> :t (return []) (return []) :: Monad m => m [t] *Prelude> :t (return [1,2,3]) (return [1,2,3]) :: (Monad m, Num t) => m [t] *Prelude> :t (return ["the","tree"]) (return ["the","tree"]) :: Monad m => m [[Char]] We can get list comprehension behavior from the do notation (here I am using the GHCi repl :{ and :} commands to enter multiple line examples): Tutorial on Impure Haskell Programming 69 1 *Main> :{ 2 *Main| do num <- [1..3] 3 *Main| animal <- ["parrot", "ant", "dolphin"] 4 *Main| return (num, animal) 5 *Main| :} 6 [(1,"parrot"),(1,"ant"),(1,"dolphin"), 7 (2,"parrot"),(2,"ant"),(2,"dolphin"), 8 (3,"parrot"),(3,"ant"),(3,"dolphin")] I won’t use this notation further but you now will recognize this pattern if you read it in other people’s code. Dealing With Time In the example in this section we will see how to time a block of code (using two different methods) and how to set a timeout for code that runs in an IO (). The first way we time a block of code uses getPOSIXTime and can be used to time pure or impure code. The second method using timeIt takes an IO () as an argument; in the following example I wrapped pure code in a print function call which returns an IO () as its value. The last example in the file TimerTest.hs shows how to run impure code wrapped in a timeout. 1 module Main where 2 3 import Data.Time.Clock.POSIX -- for getPOSIXTime 4 import System.TimeIt -- for timeIt 5 import System.Timeout -- for timeout 6 7 anyCalculationWillDo n = -- a function that can take a while to run 8 take n $ sieve [2..] 9 where 10 sieve (x:xs) = 11 x:sieve [y | y <- xs, rem y x > 0] 12 13 main = do 14 startingTime <- getPOSIXTime 15 print startingTime 16 print $ last $ take 20000001 [0..] 17 endingTime <- getPOSIXTime 18 print endingTime 19 print (endingTime - startingTime) 20 timeIt $ print $ last $ anyCalculationWillDo 2000 Tutorial on Impure Haskell Programming 70 21 22 let somePrimes = anyCalculationWillDo 3333 in 23 timeIt $ print $ last somePrimes 24 25 -- 100000 microseconds timeout tests: 26 timeout 100000 $ print "simple print **do** expression did not timeout" 27 timeout 100000 $ print $ last $ anyCalculationWillDo 4 28 timeout 100000 $ print $ last $ anyCalculationWillDo 40 29 timeout 100000 $ print $ last $ anyCalculationWillDo 400 30 timeout 100000 $ print $ last $ anyCalculationWillDo 4000 31 timeout 100000 $ print $ last $ anyCalculationWillDo 40000 32 print $ anyCalculationWillDo 5 I wanted a function that takes a while to run so for anyCalculationWillDo (lines 7 to 11) I implemented an inefficient prime number generator. When running this example on my laptop, the last two timeout calls (lines 26 and 31) are terminated for taking more than 100000 microseconds to execute. The last line 32 of code prints out the first 5 prime numbers greater than 1 so you can see the results of calling the time wasting test function anyCalculationWillDo. 1 $ stack build --exec TimerTest 2 1473610528.2177s 3 20000000 4 1473610530.218574s 5 2.000874s 6 17389 7 CPU time: 0.14s 8 30911 9 CPU time: 0.25s 10 "simple print **do** expression did not timeout" 11 7 12 173 13 2741 14 [2,3,5,7,11] The timeout function is useful for setting a maximum time that you are willing to wait for a calculation to complete. I mostly use timeout for timing out operations fetching data from the web. Using Debug.Trace Inside an IO you can use print statements to understand what is going on in your code when debugging. You can not use print statements inside pure code but the Haskell base library contains Tutorial on Impure Haskell Programming 71 the trace functions that internally perform impure writes to stdout. You do not want to use these debug tools in production code. As an example, I have rewritten the example from the last section to use Debug.Trace.trace and Debug.Trace.traceShow: 1 module Main where 2 3 import Debug.Trace (trace, traceShow) -- for debugging only! 4 5 anyCalculationWillDo n = 6 trace 7 ("+++ anyCalculationWillDo: " ++ show n) $ 8 anyCalculationWillDo' n 9 10 anyCalculationWillDo' n = 11 take n $ trace (" -- sieve n:" ++ (show n)) $ sieve [2..] 12 where 13 sieve (x:xs) = 14 traceShow (" -- inside sieve recursion") $ 15 x:sieve [y | y <- xs, rem y x > 0] 16 17 main = do 18 print $ anyCalculationWillDo 5 In line 3 we import the trace and showTrace functions: *Main> :info trace trace :: String -> a -> a -- Defined in ‘Debug.Trace’ *Main> :info traceShow traceShow :: Show a => a -> b -> b -- Defined in ‘Debug.Trace’ trace takes two arguments: the first is a string that that is written to stdout and the second is a function call to be evaluated. traceShow is like *trace except that the first argument is cnverted to a tstring. The output from running this example is: Tutorial on Impure Haskell Programming 72 +++ anyCalculationWillDo: 5 -- sieve n:5 " -- inside sieve recursion" " -- inside sieve recursion" " -- inside sieve recursion" " -- inside sieve recursion" " -- inside sieve recursion" [2,3,5,7,11] I don’t usually like using the trace functions because debugging with them involves slightly rewriting my code. My preference is to get low level code written interactively in the GHCI repl so it does not need to be debugged. I very frequently use print statement inside IOs since adding them requires no significant modification of my code. Wrap Up I tried to give you a general fast-start in this chapter for using monads and in general writing impure Haskell code. This chapter should be sufficient for you to be able to understand and experiment with the examples in the rest of this book. This is the end of the first section. We will now look at a variety of application examples using the Haskell language. While I expect you to have worked through the previous chapters in order, for the rest of the book you can skip around and read the material in any order that you wish. Section 2 - Cookbook Now that you have worked through the pure and impure Haskell coding tutorials in the first two chapters we will look at a “cookbook” of techniques and sample applications to solve some common programming tasks as well as implement a program to play the card game Blackjack. I expect you, dear reader, to have studied and absorbed the tutorial material on pure and impure Haskell programming in the first two chapters. If you are new to Haskell, or don’t have much experience yet, carefully working through these tutorial chapters is a requirement for understanding the material in the rest of this book. This section contains the following “recipe” applications: • Textprocessing CSV Files • Textprocessing JSON Files • Using sqlite and Postgres databases • REST Server Providing JSON Data • REST Client • Accessing and Using Linked Data • Querying Semantic Web RDF Data Sources • Annotating English text with Wikipedia/DBPedia URIs for entities in the original text. Entities can be people, places, organizations, etc. • Play the Blackjack card game • Machine Learning • Probabilistic Graph Models Text Processing In my work in data science and machine learning, processing text is a core activity. I am a practitioner, not a research scientist, and in a practical sense, I spend a fair amount of time collecting data (e.g., web scraping and using semantic web/linked data sources), cleaning it, and converting it to different formats. We will cover three useful techniques: parsing and using CSV (comma separated values) spreadsheet files, parsing and using JSON data, and cleaning up natural language text that contains noise characters. CSV Spreadsheet Files The comma separated values (CSV) format is a plain text format that all spreadsheet applications support. The following example illustrates two techniques that we haven’t covered yet: • Extracting values from the Either type. • Using destructuring to concisely extract parts of a list. The Either type Either a b contains either a Left a or a Right b value and is usually used to return an error in Left or a value in Right. We will using the Data.Either.Unwrap module to unwrap the Right part of a call to the Text.CSV.parseCSVFromFile function that reads a CSV file and returns a Left error or the data in the spreadsheet in a list as the Right value. The destructuring trick in line 15 in the following listing lets us separate the head and rest of a list in one operation; for example: *TestCSV> let z = [1,2,3,4,5] *TestCSV> z [1,2,3,4,5] *TestCSV> let x:xs = z *TestCSV> x 1 *TestCSV> xs [2,3,4,5] Here is how to read a CSV file: Text Processing 75 1 module TestCSV where 2 3 import Text.CSV (parseCSVFromFile, CSV) 4 import Data.Either.Unwrap (fromRight) 5 6 readCsvFile :: FilePath -> CSV 7 readCsvFile fname = do 8 c <- parseCSVFromFile fname 9 return $ fromRight c 10 11 main = do 12 c <- readCsvFile "test.csv" 13 print c -- includes header and data rows 14 print $ map head c -- print header 15 let header:rows = c -- destructure 16 print header 17 print rows Function readCsvFile reads from a file and returns a CSV. What is a CSV type? You could search the web for documentation, but dear reader, if you have worked this far learning Haskell, by now you know to rely on the GHCi repl: *TestCSV> :i CSV type CSV = [Text.CSV.Record] -- Defined in ‘Text.CSV’ *TestCSV> :i Text.CSV.Record type Text.CSV.Record = [Text.CSV.Field] -- Defined in ‘Text.CSV’ *TestCSV> :i Text.CSV.Field type Text.CSV.Field = String -- Defined in ‘Text.CSV’ So, a CSV is a list of records (rows in the spreadsheet file), each record is a list of fields (i.e., a string value). The output when reading the CVS file test.csv is: Text Processing 76 Prelude> :l TestCSV [1 of 1] Compiling TestCSV ( TestCSV.hs, interpreted ) Ok, modules loaded: TestCSV. *TestCSV> main [["name"," email"," age"],["John Smith"," jsmith@acmetools.com"," 41"],["June Jones"\ ," jj@acmetools.com"," 38"]] ["name","John Smith","June Jones"] ["name"," email"," age"] [["John Smith"," jsmith@acmetools.com"," 41"],["June Jones"," jj@acmetools.com"," 38\ "]] JSON Data JSON is the native data format for the Javascript language and JSON has become a popular serialization format for exchanging data between programs on a network. In this section I will demonstrate serializing a Haskell type to a string with JSON encoding and then perform the opposite operation of deserializing a string containing JSON encoded data back to an object. The first example uses the module Text.JSON.Generic (from the json library) and the second example uses module Data.Aeson (from the aeson library). In the first example, we set the language type to include DeriveDataTypeable so a new type definition can simply derive Typeable which allows the compiler to generate appropriate encodeJSON and decodeJSON functions for the type Person we define in the example: 1 {-# LANGUAGE DeriveDataTypeable #-} 2 3 module TestTextJSON where 4 5 import Text.JSON.Generic 6 7 data Person = Person {name::String, email::String} 8 deriving (Show, Data, Typeable) 9 10 main = do 11 let a = encodeJSON $ Person "Sam" "sam@a.com" 12 print a 13 let d = (decodeJSON a :: Person) 14 print d 15 print $ name d 16 print $ email d Text Processing 77 Notice that in line 14 that I specified the expected type in the decodeJSON call. This is not strictly required, the Haskell GHC compiler knows what to do in this case. I specified the type for code readability. The Haskell compiler wrote the name and email functions for me and I use these functions in lines 16 and 17 to extract these fields. Here is the output from running this example: 1 Prelude> :l TestTextJSON.hs 2 [1 of 1] Compiling TestTextJSON ( TestTextJSON.hs, interpreted ) 3 Ok, modules loaded: TestTextJSON. 4 *TestTextJSON> main 5 "{\"name\":\"Sam\",\"email\":\"sam@a.com\"}" 6 Person {name = "Sam", email = "sam@a.com"} 7 "Sam" 8 "sam@a.com" The next example uses the Aeson library and is similar to this example. Using Aeson, we set a language type DeriveGeneric and in this case have the Person class derive Generic. The School of Haskell has an excellent Aeson tutorial²³ that shows a trick I use in this example: letting the compiler generate required functions for types FromJSON and ToJSON as seen in lines 12-13. 1 {-# LANGUAGE DeriveGeneric #-} 2 3 module TestJSON where 4 5 import Data.Aeson 6 import GHC.Generics 7 import Data.Maybe 8 9 data Person = Person {name::String, email::String } deriving (Show, Generic) 10 11 -- nice trick from School Of Haskell tutorial on Aeson: 12 instance FromJSON Person -- DeriveGeneric language setting allows 13 instance ToJSON Person -- automatic generation of instance of 14 -- types deriving Generic. 15 16 main = do 17 let a = encode $ Person "Sam" "sam@a.com" 18 print a 19 let (Just d) = (decode a :: Maybe Person) 20 print d 21 print $ name d 22 print $ email d ²³https://www.schoolofhaskell.com/school/starting-with-haskell/libraries-and-frameworks/text-manipulation/json Text Processing 78 I use a short cut in line 19, assuming that the Maybe object returned from decode (which the compiler wrote automatically for the type FromJSON) contains a Just value instead of an empty Nothing value. So in line 19 I directly unwrap the Just value. Here is the output from running this example: 1 Prelude> :l TestAESON.hs 2 [1 of 1] Compiling TestJSON ( TestAESON.hs, interpreted ) 3 Ok, modules loaded: TestJSON. 4 *TestJSON> main 5 "{\"email\":\"sam@a.com\",\"name\":\"Sam\"}" 6 Person {name = "Sam", email = "sam@a.com"} 7 "Sam" 8 "sam@a.com" Line 5 shows the result of printing the JSON encoded string value created by the call to encode in line 17 of the last code example. Line 6 shows the decoded value of type Person, and lines 7 and 8 show the inner wrapped values in the Person data. Cleaning Natural Language Text I spend a lot of time working with text data because I have worked on NLP (natural language processing) projects for over 25 years. We will jump into some interesting NLP applications in the next chapter. I will finish this chapter with strategies for cleaning up text which is often a precursor to performing NLP. You might be asking why we would need to clean up text. Here are a few common use cases: • Text fetched from the web frequently contains garbage characters. • Some types of punctuation need to be removed. • Stop words (e.g., the, a, but, etc.) need to be removed. • Special unicode characters are not desired. • Sometimes we want white space around punctuation to make tokenizing text easier. Notice the module statement on line 1 of the following listing: I am exporting functions cleanText and removeStopWords so they will be visible and available for use by any other modules that import this module. In line 6 we import intercalate which constructs a string from a space character and an [String] (i.e., a list of strings); here is an example where instead of adding a space character between the strings joined together, I add “*” characters: Text Processing 79 *CleanText> intercalate "*" ["the", "black", "cat"] "the*black*cat" The function cleanText removes garbage characters and makes sure that any punctuation characters are surrounded by white space (this makes it easier, for example, to determine sentence boundaries). Function removeStopWords removes common words like “a”, “the”, etc. from text. 1 module CleanText (cleanText, removeStopWords) where 2 3 import Data.List.Split (splitOn) 4 import Data.List (intercalate) 5 import Data.Char as C 6 import Data.List.Utils (replace) 7 8 noiseCharacters = ['[', ']', '{', '}', '\n', '\t', '&', '^', 9 '@', '%', '$', '#', ','] 10 11 substituteNoiseCharacters :: [Char] -> [Char] 12 substituteNoiseCharacters = 13 map (\x -> if elem x noiseCharacters then ' ' else x) 14 15 cleanText s = 16 intercalate 17 " " $ 18 filter 19 (\x -> length x > 0) $ 20 splitOn " " $ substituteNoiseCharacters $ 21 (replace "." " . " 22 (replace "," " , " 23 (replace ";" " ; " s))) 24 25 stopWords = ["a", "the", "that", "of", "an"] 26 27 toLower' :: [Char] -> [Char] 28 toLower' s = map (\x -> if isLower x then x else (C.toLower x)) s 29 30 removeStopWords :: String -> [Char] 31 removeStopWords s = 32 intercalate 33 " " $ 34 filter 35 (\x -> notElem (toLower' x) stopWords) $ 36 words s Text Processing 80 37 38 main = do 39 let ct = cleanText "The[]@] cat, and all dog, escaped&^. They were caught." 40 print ct 41 let nn = removeStopWords ct 42 print nn This example should be extended with additional noise characters and stop words, depending on your application. The function cleanText simply uses substring replacements. Let’s look more closely at removeStopWords that takes a single argument s, which is expected to be a string. removeStopWords uses a combination of several functions to remove stop words from the input string. The function words is used to split the input string s into a list of words. Then, the function filter is used to remove any words that match a specific condition. Here the condition is defined as a lambda function, which is passed as the first argument to the filter function. The lambda function takes a single argument x and returns a Boolean value indicating whether the word should be included in the output or not. The lambda function uses function notElem to check whether the lowercased version of the word x is present in a predefined list of stop words. Finally, we use the function intercalate to join the remaining words back into a single string. The first argument to function ** intercalate** is the separator that should be used to join the words, in this case, it’s a single space. Here is the output from this example: 1 *TestCleanText> :l CleanText.hs 2 [1 of 1] Compiling TestCleanText ( CleanText.hs, interpreted ) 3 Ok, modules loaded: TestCleanText. 4 *TestCleanText> main 5 "The cat and all dog escaped . They were caught ." 6 "cat dog escaped . They were caught ." We will continue working with text in the next chapter. Natural Language Processing Tools The tools developed in this chapter are modules you can reuse in your programs. We will develop a command line program that reads a line of text from STDIN and writes sematic information as output to STDOUT. I have used this in a Ruby program by piping input text data to a forked process and reading the output which is a semantic representation of the input text. We will be using this example as an external dependency to a later example in the chapter Knowledge Graph Creator. A few of the data files I provide in this example are fairly large. As an example the file PeopleDb- Pedia.hs which builds a map from people’s names to the Wikipedia/DBPedia URI for information about them, is 2.5 megabytes in size. The first time you run stack build in the project directory it will take a while, so you might want to start building the project in the directory NlpTool and let it run while you read this chapter. Here are three examples using the NlpTool command line application developed in this chapter: Enter text (all on one line) Canada and England signed a trade deal. category: economics summary: Canada and England signed a trade deal. countries: [["Canada",""], ["England",""]] Enter text (all on one line) President George W Bush asked Congress for permission to invade Iraq. category: news_war summary: President George W Bush asked Congress for permission to invade Iraq. people: [["George W Bush",""]] countries: [["Iraq",""]] Enter text (all on one line) The British government is facing criticism from business groups over statements sugg\ esting the U.K. is heading for a hard divorce from the European Union — and pressu\ re from lawmakers who want Parliament to have a vote on the proposed exit terms. The\ government's repeated emphasis on controlling immigration sent out "signs that the \ door is being closed, to an extent, on the open economy, that has helped fuel invest\ ment," the head of employers' group the Confederation of British Industry, Carolyn F\ airbairn, said in comments published Monday. Prime Minister Theresa May said last we\ ek that Britain would seek to retain a close relationship with the 28-nation bloc, w\ ith continued free trade in goods and services. But she said the U.K. wouldn't cede \ control over immigration, a conflict with the EU's principle of free movement among \ Natural Language Processing Tools 82 member states. category: economics summary: Prime Minister Theresa May said last week that Britain would seek to retain\ a close relationship with the 28-nation bloc, with continued free trade in goods an\ d services. credit: news text from abcnews.com Resolve Entities in Text to DBPedia URIs The code for this application is in the directory NlpTool. The software and data in this chapter can be used under the terms of either the GPL version 3 license or the Apache 2 license. There are several automatically generated Haskell formatted data files that I created using Ruby scripts operating the Wikipedia data. For the purposes of this book I include these data-specific files for your use and enjoyment but we won’t spend much time discussing them. These files are: • BroadcastNetworkNamesDbPedia.hs • CityNamesDbpedia.hs • CompanyNamesDbpedia.hs • CountryNamesDbpedia.hs • PeopleDbPedia.hs • PoliticalPartyNamesDbPedia.hs • TradeUnionNamesDbPedia.hs • UniversityNamesDbPedia.hs As an example, let’s look at a small sample of data in PeopleDbPedia.hs: 1 module PeopleDbPedia (peopleMap) where 2 3 import qualified Data.Map as M 4 5 peopleMap = M.fromList [ 6 ("Aaron Sorkin", ""), 7 ("Bill Clinton", ""), 8 ("George W Bush", ""), There are 35,146 names in the file PeopleDbPedia.hs. I have built for eight different types of entity names: Haskell maps that take entity names (String) and maps the entity names into relevant Natural Language Processing Tools 83 DBPedia URIs. Simple in principle, but a lot of work preparing the data. As I mentioned, we will use these data-specific files to resolve entity references in text. The next listing shows the file Entities.hs. In lines 5-7 I import the entity mapping files I just described. In this example and later code I make heavy use of the Data.Map and Data.Set modules in the collections library (see the NlpTools.cabal file). The operator isSubsetOf defined in line 39 tests to see if a value is contained in a collection. The built-in function all applies a function or operator to all elements in a collection and returns a true value if the function or operator returns true applied to each element in the collection. The local utility function namesHelper defined in lines 41-53 is simpler than it looks. The function filter in line 42 applies the inline function in lines 43-45 (this function returns true for Maybe values that contain data) to a second list defined in lines 48-55. This second list is calculated by mapping an inline function over the input argument ngrams. The inline function looks up an ngram in a DBPedia map (passed as the second function argument) and returns the lookup value if it is not empty and if it is empty looks up the same ngram in a word map (last argument to this function). The utility function namesHelper is then used to define functions to recognize company names, country names, people names, city names, broadcast network names, political party names, trade union names, and university names: 1 -- Copyright 2014 by Mark Watson. All rights reserved. The software and data in this\ 2 project can be used under the terms of either the GPL version 3 license or the Apac\ 3 he 2 license. 4 5 module Entities (companyNames, peopleNames, 6 countryNames, cityNames, broadcastNetworkNames, 7 politicalPartyNames, tradeUnionNames, universityNames) where 8 9 import qualified Data.Map as M 10 import qualified Data.Set as S 11 import Data.Char (toLower) 12 import Data.List (sort, intersect, intersperse) 13 import Data.Set (empty) 14 import Data.Maybe (isJust) 15 16 import Utils (splitWords, bigram, bigram_s, splitWordsKeepCase, 17 trigram, trigram_s, removeDuplicates) 18 19 import FirstNames (firstNames) 20 import LastNames (lastNames) 21 import NamePrefixes (namePrefixes) 22 23 import PeopleDbPedia (peopleMap) Natural Language Processing Tools 84 24 25 import CountryNamesDbpedia (countryMap) 26 import CountryNames (countryNamesOneWord, countryNamesTwoWords, countryNamesThreeWor\ 27 ds) 28 29 import CompanyNamesDbpedia (companyMap) 30 import CompanyNames (companyNamesOneWord, companyNamesTwoWords, companyNamesThreeWor\ 31 ds) 32 import CityNamesDbpedia (cityMap) 33 34 import BroadcastNetworkNamesDbPedia (broadcastNetworkMap) 35 import PoliticalPartyNamesDbPedia (politicalPartyMap) 36 import TradeUnionNamesDbPedia (tradeUnionMap) 37 import UniversityNamesDbPedia (universityMap) 38 39 xs `isSubsetOf` ys = all (`elem` ys) xs 40 41 namesHelper ngrams dbPediaMap wordMap = 42 filter 43 (\x -> case x of 44 (_, Just x) -> True 45 _ -> False) $ 46 map (\ngram -> (ngram, 47 let v = M.lookup ngram dbPediaMap in 48 if isJust v 49 then return (ngram, v) 50 else if S.member ngram wordMap 51 then Just (ngram, Just "") 52 else Nothing)) 53 ngrams 54 55 helperNames1W = namesHelper 56 57 helperNames2W wrds = namesHelper (bigram_s wrds) 58 59 helperNames3W wrds = namesHelper (trigram_s wrds) 60 61 companyNames wrds = 62 let cns = removeDuplicates $ sort $ 63 helperNames1W wrds companyMap companyNamesOneWord ++ 64 helperNames2W wrds companyMap companyNamesTwoWords ++ 65 helperNames3W wrds companyMap companyNamesThreeWords in 66 map (\(s, Just (a,Just b)) -> (a,b)) cns Natural Language Processing Tools 85 67 68 countryNames wrds = 69 let cns = removeDuplicates $ sort $ 70 helperNames1W wrds countryMap countryNamesOneWord ++ 71 helperNames2W wrds countryMap countryNamesTwoWords ++ 72 helperNames3W wrds countryMap countryNamesThreeWords in 73 map (\(s, Just (a,Just b)) -> (a,b)) cns 74 75 peopleNames wrds = 76 let cns = removeDuplicates $ sort $ 77 helperNames1W wrds peopleMap Data.Set.empty ++ 78 helperNames2W wrds peopleMap Data.Set.empty ++ 79 helperNames3W wrds peopleMap Data.Set.empty in 80 map (\(s, Just (a,Just b)) -> (a,b)) cns 81 82 cityNames wrds = 83 let cns = removeDuplicates $ sort $ 84 helperNames1W wrds cityMap Data.Set.empty ++ 85 helperNames2W wrds cityMap Data.Set.empty ++ 86 helperNames3W wrds cityMap Data.Set.empty in 87 map (\(s, Just (a,Just b)) -> (a,b)) cns 88 89 broadcastNetworkNames wrds = 90 let cns = removeDuplicates $ sort $ 91 helperNames1W wrds broadcastNetworkMap Data.Set.empty ++ 92 helperNames2W wrds broadcastNetworkMap Data.Set.empty ++ 93 helperNames3W wrds broadcastNetworkMap Data.Set.empty in 94 map (\(s, Just (a,Just b)) -> (a,b)) cns 95 96 politicalPartyNames wrds = 97 let cns = removeDuplicates $ sort $ 98 helperNames1W wrds politicalPartyMap Data.Set.empty ++ 99 helperNames2W wrds politicalPartyMap Data.Set.empty ++ 100 helperNames3W wrds politicalPartyMap Data.Set.empty in 101 map (\(s, Just (a,Just b)) -> (a,b)) cns 102 103 tradeUnionNames wrds = 104 let cns = removeDuplicates $ sort $ 105 helperNames1W wrds tradeUnionMap Data.Set.empty ++ 106 helperNames2W wrds tradeUnionMap Data.Set.empty ++ 107 helperNames3W wrds tradeUnionMap Data.Set.empty in 108 map (\(s, Just (a,Just b)) -> (a,b)) cns 109 Natural Language Processing Tools 86 110 universityNames wrds = 111 let cns = removeDuplicates $ sort $ 112 helperNames1W wrds universityMap Data.Set.empty ++ 113 helperNames2W wrds universityMap Data.Set.empty ++ 114 helperNames3W wrds universityMap Data.Set.empty in 115 map (\(s, Just (a,Just b)) -> (a,b)) cns 116 117 118 main = do 119 let s = "As read in the San Francisco Chronicle, the company is owned by John Sm\ 120 ith, Bill Clinton, Betty Sanders, and Dr. Ben Jones. Ben Jones and Mr. John Smith ar\ 121 e childhood friends who grew up in Brazil, Canada, Buenos Aires, and the British Vir\ 122 gin Islands. Apple Computer relased a new version of OS X yesterday. Brazil Brazil B\ 123 razil. John Smith bought stock in ConocoPhillips, Heinz, Hasbro, and General Motors,\ 124 Fox Sports Radio. I listen to B J Cole. Awami National Party is a political party. \ 125 ALAEA is a trade union. She went to Brandeis University." 126 --print $ humanNames s 127 print $ peopleNames $ splitWordsKeepCase s 128 print $ countryNames $ splitWordsKeepCase s 129 print $ companyNames $ splitWordsKeepCase s 130 print $ cityNames $ splitWordsKeepCase s 131 print $ broadcastNetworkNames $ splitWordsKeepCase s 132 print $ politicalPartyNames $ splitWordsKeepCase s 133 print $ tradeUnionNames $ splitWordsKeepCase s 134 print $ universityNames $ splitWordsKeepCase s The following output is generated by running the test main function defined at the bottom of the file app/NlpTool.hs: 1 $ stack build --fast --exec NlpTool-exe 2 Building all executables for `NlpTool' once. After a successful build of all of them\ 3 , only specified executables will be rebuilt. 4 NlpTool> build (lib + exe) 5 Preprocessing library for NlpTool-0.1.0.0.. 6 Building library for NlpTool-0.1.0.0.. 7 Preprocessing executable 'NlpTool-exe' for NlpTool-0.1.0.0.. 8 Building executable 'NlpTool-exe' for NlpTool-0.1.0.0.. 9 [1 of 2] Compiling Main 10 [2 of 2] Compiling Paths_NlpTool 11 Linking .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/NlpTool-exe/NlpTool-exe ... 12 NlpTool> copy/register 13 Installing library in /Users/markw/GITHUB/haskell_tutorial_cookbook_examples_private\ 14 _new_edition/NlpTool/.stack-work/install/x86_64-osx/7a2928fbf8188dcb20f165f77b37045a\ Natural Language Processing Tools 87 15 5c413cc7f63913951296700a6b7e292d/8.6.5/lib/x86_64-osx-ghc-8.6.5/NlpTool-0.1.0.0-DXKb\ 16 ucyA0S0AKOAcZGDl2H 17 Installing executable NlpTool-exe in /Users/markw/GITHUB/haskell_tutorial_cookbook_e\ 18 xamples_private_new_edition/NlpTool/.stack-work/install/x86_64-osx/7a2928fbf8188dcb2\ 19 0f165f77b37045a5c413cc7f63913951296700a6b7e292d/8.6.5/bin 20 Registering library for NlpTool-0.1.0.0.. 21 Enter text (all on one line) 22 As read in the San Francisco Chronicle, the company is owned by John Smith, Bill Cli\ 23 nton, Betty Sanders, and Dr. Ben Jones. Ben Jones and Mr. John Smith are childhood f\ 24 riends who grew up in Brazil, Canada, Buenos Aires, and the British Virgin Islands. \ 25 Apple Computer relased a new version of OS X yesterday. Brazil Brazil Brazil. John S\ 26 mith bought stock in ConocoPhillips, Heinz, Hasbro, and General Motors, Fox Sports R\ 27 adio. I listen to B J Cole. Awami National Party is a political party. ALAEA is a tr\ 28 ade union. She went to Brandeis University. 29 category: news_politics 30 summary: ALAEA is a trade union. Apple Computer relased a new version of OS X yester\ 31 day. 32 people: [["B J Cole",""]] 33 companies: [["Apple",""],["ConocoPhillips",""],["Hasbro",""],["Heinz",""],["San Francisco Chronicle","\ 36 "]] 37 countries: [["Brazil",""],["Canada",""]] 39 Enter text (all on one line) Note that entities that are not recognized as Wikipedia objects don’t get recognized. Bag of Words Classification Model The file Categorize.hs contains a simple bag of words classification model. To prepare the classi- fication models, I collected a large set of labelled text. Labels were “chemistry”, “computers”, etc. I ranked words based on how often they appeared in training texts for a classification category, normalized by how often they appeared in all training texts. This example uses two auto-generated and data-specific Haskell files, one for single words and the other for two adjacent word pairs: • Category1Gram.hs • Category2Gram.hs In NLP work, single words are sometimes called 1grams and two word adjacent pairs are referred to as 2grams. Here is a small amount of data from Category1Gram.hs: Natural Language Processing Tools 88 1 module Category1Gram (**onegrams**) where 2 3 import qualified Data.Map as M 4 5 chemistry = M.fromList [("chemical", 1.15), ("atoms", 6.95), 6 ("reaction", 6.7), ("energy", 6.05), 7 ... ] 8 computers = M.fromList [("software", 4.6), ("network", 4.65), 9 ("linux", 3.6), ("device", 3.55), ("computers", 3.05), 10 ("storage", 2.7), ("disk", 2.3), 11 ... ] 12 etc. Here is a small amount of data from Category2Gram.hs: 1 module Category2Gram (**twograms**) where 2 3 import qualified Data.Map as M 4 5 chemistry = M.fromList [("chemical reaction", 1.55), 6 ("atoms molecules", 0.6), 7 ("periodic table", 0.5), 8 ("chemical reactions", 0.5), 9 ("carbon atom", 0.5), 10 ... ] 11 computers = M.fromList [("computer system", 0.9), 12 ("operating system", 0.75), 13 ("random memory", 0.65), 14 ("computer science", 0.65), 15 ("computer program", 0.6), 16 ... ] 17 etc. It is very common to use term frequencies for single words for classification models. One problem with using single words is that the evidence that any word gives for a classification is independent of the surrounding words in text being evaluated. By also using word pairs (two word combinations are often called 2grams or two-grams) we pick up patterns like “not good” giving evidence for negative sentiment even with the word “good” in text being evaluated. For my own work, I have a huge corpus of 1gram, 2gram, 3gram, and 4gram data sets. For the purposes of the following example program, I am only using 1gram and 2gram data. The following listing shows the file Categorize.hs. Before looking at the entire example, let’s focus in on some of the functions I have defined for using the word frequency data to categorized text. Natural Language Processing Tools 89 *Categorize> :t stemWordsInString stemWordsInString :: String -> [Char] *Categorize> stemWordsInString "Banking industry is sometimes known for fraud." "bank industri is sometim known for fraud" stemScoredWordList is used to create a 1gram to word relevance score for each category. The keys are word stems. *Categorize> stemScoredWordList onegrams [("chemistri",fromList [("acid",1.15),("acids",0.8),("alcohol",0.95),("atom",4.45) Notice that “chemistri” is the stemmed version of “chemistry”, “bank” for “banks”, etc. stem2 is a 2gram frequency score by category mapping where the keys are word stems: *Categorize> stem2 [("chemistry",fromList [("atom molecul",0.6),("carbon atom",0.5),("carbon carbon",0.\ 5), stem1 is like stem2, but for stemmed 1grams, not 2grams: *Categorize> stem1 [("chemistry",fromList [("acid",0.8),("chang",1.05),("charg",0.95),("chemic",1.15),(\ "chemistri",1.45), score is called with a list or words and a word value mapping. Here is an example: *Categorize> :t score score :: (Enum t, Fractional a, Num t, Ord a, Ord k) => [k] -> [(t1, M.Map k a)] -> [(t, a)] *Categorize> score ["atom", "molecule"] onegrams [(0,8.2),(25,2.4)] This output is more than a little opaque. The pair (0, 8.2) means that the input words [“atom”, “molecule”] have a score of 8.2 for category indexed at 0 and the pair (25,2.4) means that the input words have a score of 2.4 for the category at index 25. The category at index 0 is chemistry and the category at index 25 is physics as we can see by using the higher level function bestCategories1 that caluculates categories for a word sequence using 1gram word data: Natural Language Processing Tools 90 *Categorize> :t bestCategories1 bestCategories1 :: [[Char]] -> [([Char], Double)] *Categorize> bestCategories1 ["atom", "molecule"] [("chemistry",8.2),("physics",2.4)] The top level function bestCategories uses 1gram data. Here is an example for using it: *Categorize> splitWords "The chemist made a periodic table and explained a chemical \ reaction" ["the","chemist","made","a","periodic","table","and","explained","a","chemical","rea\ ction"] *Categorize> bestCategories1 $ splitWords "The chemist made a periodic table and exp\ lained a chemical reaction" [("chemistry",11.25),("health_nutrition",1.2)] Notice that these words were also classified as category “health_nutrition” but with a low score of 1.2. The score for “chemistry” is almost an order of magnitude larger. bestCategories sorts return values in “best first” order. splitWords is used to split a string into word tokens before calling bestCategories. Here is the entire example in file Categorize.hs: 1 module Categorize (bestCategories, splitWords, bigram) where 2 3 import qualified Data.Map as M 4 import Data.List (sortBy) 5 6 import Category1Gram (onegrams) 7 import Category2Gram (twograms) 8 9 import Sentence (segment) 10 11 import Stemmer (stem) 12 13 import Utils (splitWords, bigram, bigram_s) 14 15 catnames1 = map fst onegrams 16 catnames2 = map fst twograms 17 18 stemWordsInString s = init $ concatMap ((++ " ") . stem) (splitWords s) 19 20 stemScoredWordList = map (\(str,score) -> (stemWordsInString str, score)) 21 Natural Language Processing Tools 91 22 stem2 = map (\(category, swl) -> 23 (category, M.fromList (stemScoredWordList (M.toList swl)))) 24 twograms 25 26 stem1 = map (\(category, swl) -> 27 (category, M.fromList (stemScoredWordList (M.toList swl)))) 28 onegrams 29 30 scoreCat wrds amap = 31 sum $ map (\x -> M.findWithDefault 0.0 x amap) wrds 32 33 score wrds amap = 34 filter (\(a, b) -> b > 0.9) $ zip [0..] $ map (\(s, m) -> scoreCat wrds m) amap 35 36 cmpScore (a1, b1) (a2, b2) = compare b2 b1 37 38 bestCategoriesHelper wrds ngramMap categoryNames= 39 let tg = bigram_s wrds in 40 map (first (categoryNames !!)) $ sortBy cmpScore $ score wrds ngramMap 41 42 bestCategories1 wrds = 43 take 3 $ bestCategoriesHelper wrds onegrams catnames1 44 45 bestCategories2 wrds = 46 take 3 $ bestCategoriesHelper (bigram_s wrds) twograms catnames2 47 48 bestCategories1stem wrds = 49 take 3 $ bestCategoriesHelper wrds stem1 catnames1 50 51 bestCategories2stem wrds = 52 take 3 $ bestCategoriesHelper (bigram_s wrds) stem2 catnames2 53 54 bestCategories :: [String] -> [(String, Double)] 55 bestCategories wrds = 56 let sum1 = M.unionWith (+) (M.fromList $ bestCategories1 wrds) ( M.fromList $ best\ 57 Categories2 wrds) 58 sum2 = M.unionWith (+) (M.fromList $ bestCategories1stem wrds) ( M.fromList $ \ 59 bestCategories2stem wrds) 60 in sortBy cmpScore $ M.toList $ M.unionWith (+) sum1 sum2 61 62 main = do 63 let s = "The sport of hocky is about 100 years old by ahdi dates. American Footb\ 64 all is a newer sport. Programming is fun. Congress passed a new budget that might he\ Natural Language Processing Tools 92 65 lp the economy. The frontier initially was a value path. The ai research of john mcc\ 66 arthy." 67 print $ bestCategories1 (splitWords s) 68 print $ bestCategories1stem (splitWords s) 69 print $ score (splitWords s) onegrams 70 print $ score (bigram_s (splitWords s)) twograms 71 print $ bestCategories2 (splitWords s) 72 print $ bestCategories2stem (splitWords s) 73 print $ bestCategories (splitWords s) Here is the output: 1 $ stack ghci 2 :l Categorize.hs 3 *Categorize> main 4 [("computers_ai",17.900000000000002),("sports",9.75),("computers_ai_search",6.2)] 5 [("computers_ai",18.700000000000003),("computers_ai_search",8.1),("computers_ai_lear\ 6 ning",5.7)] 7 [(2,17.900000000000002),(3,1.75),(4,5.05),(6,6.2),(9,1.1),(10,1.2),(21,2.7),(26,1.1)\ 8 ,(28,1.6),(32,9.75)] 9 [(2,2.55),(6,1.0),(32,2.2)] 10 [("computers_ai",2.55),("sports",2.2),("computers_ai_search",1.0)] 11 [("computers_ai",1.6)] 12 [("computers_ai",40.75000000000001),("computers_ai_search",15.3),("sports",11.95),("\ 13 computers_ai_learning",5.7)] Given that the variable s contains some test text, line 4 of this output was generated by evaluating bestCategories1 (splitWords s), lines 5-6 by evaluating bestCategories1stem (splitWords s), lines 7-8 from score (splitWords s) onegrams, line 9 from core (bigram_s (splitWords s)) twograms, line 10 from bestCategories2 (splitWords s), line 11 from bestCategories2stem (splitWords s), and lines 12-13 from bestCategories (splitWords s). I called all of the utility fucntions in function main to demonstrate what they do but in practice I just call function bestCategories in my applications. Text Summarization This application uses both the Categorize.hs code and the 1gram data from the last section. The algorithm I devised for this example is based on a simple idea: we categorize text and keep track of which words provide the strongest evidence for the highest ranked categories. We then return a few sentences from the original text that contain the largest numbers of these important words. Natural Language Processing Tools 93 module Summarize (summarize, summarizeS) where import qualified Data.Map as M import Data.List.Utils (replace) import Data.Maybe (fromMaybe) import Categorize (bestCategories) import Sentence (segment) import Utils (splitWords, bigram_s, cleanText) import Category1Gram (onegrams) import Category2Gram (twograms) scoreSentenceHelper words scoreMap = -- just use 1grams for now sum $ map (\word -> M.findWithDefault 0.0 word scoreMap) words safeLookup key alist = fromMaybe 0 $ lookup key alist scoreSentenceByBestCategories words catDataMaps bestCategories = map (\(category, aMap) -> (category, safeLookup category bestCategories * scoreSentenceHelper words aMap)) catDataMaps scoreForSentence words catDataMaps bestCategories = sum $ map snd $ scoreSentenceByBestCategories words catDataMaps bestCategories summarize s = let words = splitWords $ cleanText s bestCats = bestCategories words sentences = segment s result1grams = map (\sentence -> (sentence, scoreForSentence (splitWords sentence) onegrams bestCats)) sentences result2grams = map (\sentence -> (sentence, scoreForSentence (bigram_s (splitWords sentence)) twograms bestCats)) sentences mergedResults = M.toList $ M.unionWith (+) (M.fromList result1grams) (M.fromList result1grams) Natural Language Processing Tools 94 c400 = filter (\(sentence, score) -> score > 400) mergedResults c300 = filter (\(sentence, score) -> score > 300) mergedResults c200 = filter (\(sentence, score) -> score > 200) mergedResults c100 = filter (\(sentence, score) -> score > 100) mergedResults c000 = mergedResults in if not (null c400) then c400 else if not (null c300) then c300 else if not (null c\ 200) then c200 else if not (null c100) then c100 else c000 summarizeS s = let a = replace "\"" "'" $ concatMap (\x -> fst x ++ " ") $ summarize s in if not (null a) then a else safeFirst $ segment s where safeFirst x | length x > 1 = head x ++ x !! 1 | not (null x) = head x | otherwise = "" main = do let s = "Plunging European stocks, wobbly bonds and grave concerns about the healt\ h of Portuguese lender Banco Espirito Santo SA made last week feel like a rerun of t\ he euro crisis, but most investors say it was no more than a blip for a resurgent re\ gion. Banco Espirito Santo has been in investors’ sights since December, when The \ Wall Street Journal first reported on accounting irregularities at the complex firm.\ Nerves frayed on Thursday when Banco Espirito Santo's parent company said it wouldn\ 't be able to meet some short-term debt obligations." print $ summarize s print $ summarizeS s Lazy evaluation allows us in function summarize to define summaries of various numbers of sentences, but not all of these possible summaries are calculated. $ stack ghci *Main ... > :l Summarize.hs *Summarize> main [("Nerves frayed on Thursday when Banco Espirito Santo's parent company said it woul\ dn't be able to meet some short-term debt obligations.",193.54500000000002)] "Nerves frayed on Thursday when Banco Espirito Santo's parent company said it wouldn\ 't be able to meet some short-term debt obligations. " Part of Speech Tagging We close out this chapter with the Haskell version of my part of speech (POS) tagger that I originally wrote in Common Lisp, then converted to Ruby and Java. The file LexiconData.hs is similar to the Natural Language Processing Tools 95 lexical data files seen earlier: I am defining a map where keys a words and map values are POS tokens like NNP (proper noun), RB (adverb), etc. The file README.md contains a complete list of POS tag definitions. The example code and data for this section is in the directory FastTag. This listing shows a tiny representative part of the POS definitions in LexiconData.hs: lexicon = M.fromList [("AARP", "NNP"), ("Clinic", "NNP"), ("Closed", "VBN"), ("Robert", "NNP"), ("West-German", "JJ"), ("afterwards", "RB"), ("arises", "VBZ"), ("attacked", "VBN"), ...] Before looking at the code example listing, let’s see how the functions defined in fasttag.hs work in a GHCi repl: *Main LexiconData> bigram ["the", "dog", "ran", "around", "the", "tree"] [["the","dog"],["dog","ran"],["ran","around"], ["around","the"],["the","tree"]] *Main LexiconData> tagHelper "car" ["car","NN"] *Main LexiconData> tagHelper "run" ["run","VB"] *Main LexiconData> substitute ["the", "dog", "ran", "around", "the", "tree"] [[["the","DT"],["dog","NN"]],[["dog","NN"],["ran","VBD"]], [["ran","VBD"],["around","IN"]],[["around","IN"],["the","DT"]], [["the","DT"],["tree","NN"]]] *Main LexiconData> fixTags $ substitute ["the", "dog", "ran", "around", "the", "tree"] ["NN","VBD","IN","DT","NN"] Function bigram takes a list or words and returns a list of word pairs. We need the word pairs because parts of the tagging algorithm needs to see a word with its preceeding word. In an imperative language, I would loop over the words and for a word at index i I would have the word at index i - 1. In a functional language, we avoid using loops and in this case create a list of adjacent word pairs to avoid having to use an explicit loop. I like this style of functional programming but if you come from years of using imperative language like Java and C++ it takes some getting used to. tagHelper converts a word into a list of the word and its likely tag. substitute applies tagHelper to a list of words, getting the most probable tag for each word. The function fixTags will occasionally override the default word tags based on a few rules that are derived from Eric Brill’s paper A Simple Rule-Based Part of Speech Tagger²⁴. ²⁴http://aclweb.org/anthology/A92-1021 Natural Language Processing Tools 96 Here is the entire example: 1 module Main where 2 3 import qualified Data.Map as M 4 import Data.Strings (strEndsWith, strStartsWith) 5 import Data.List (isInfixOf) 6 7 import LexiconData (lexicon) 8 9 bigram :: [a] -> [[a]] 10 bigram [] = [] 11 bigram [_] = [] 12 bigram xs = take 2 xs : bigram (tail xs) 13 14 containsString word substring = isInfixOf substring word 15 16 fixTags twogramList = 17 map 18 -- in the following inner function, [last,current] might be bound, 19 -- for example, to [["dog","NN"],["ran","VBD"]] 20 (\[last, current] -> 21 -- rule 1: DT, {VBD | VBP} --> DT, NN 22 if last !! 1 == "DT" && (current !! 1 == "VBD" || 23 current !! 1 == "VB" || 24 current !! 1 == "VBP") 25 then "NN" 26 else 27 -- rule 2: convert a noun to a number (CD) if "." appears in the word 28 if (current !! 1) !! 0 == 'N' && containsString (current !! 0) "." 29 then "CD" 30 else 31 -- rule 3: convert a noun to a past participle if 32 -- words.get(i) ends with "ed" 33 if (current !! 1) !! 0 == 'N' && strEndsWith (current !! 0) "ed" 34 then "VBN" 35 else 36 -- rule 4: convert any type to adverb if it ends in "ly" 37 if strEndsWith (current !! 0) "ly" 38 then "RB" 39 else 40 -- rule 5: convert a common noun (NN or NNS) to an 41 -- adjective if it ends with "al" Natural Language Processing Tools 97 42 if strStartsWith (current !! 1) "NN" && 43 strEndsWith (current !! 1) "al" 44 then "JJ" 45 else 46 -- rule 6: convert a noun to a verb if the preceeding 47 -- word is "would" 48 if strStartsWith (current !! 1) "NN" && 49 (last !! 0) == "would" -- should be case insensitive 50 then "VB" 51 else 52 -- rule 7: if a word has been categorized as a 53 -- common noun and it ends with "s", 54 -- then set its type to plural common noun (NNS) 55 if strStartsWith (current !! 1) "NN" && 56 strEndsWith (current !! 0) "s" 57 then "NNS" 58 else 59 -- rule 8: convert a common noun to a present 60 -- participle verb (i.e., a gerand) 61 if strStartsWith (current !! 1) "NN" && 62 strEndsWith (current !! 0) "ing" 63 then "VBG" 64 else (current !! 1)) 65 twogramList 66 67 substitute tks = bigram $ map tagHelper tks 68 69 tagHelper token = 70 let tags = M.findWithDefault [] token lexicon in 71 if tags == [] then [token, "NN"] else [token, tags] 72 73 tag tokens = fixTags $ substitute ([""] ++ tokens) 74 75 76 main = do 77 let tokens = ["the", "dog", "ran", "around", "the", "tree", "while", 78 "the", "cat", "snaked", "around", "the", "trunk", 79 "while", "banking", "to", "the", "left"] 80 print $ tag tokens 81 print $ zip tokens $ tag tokens Natural Language Processing Tools 98 *Main LexiconData> main ["DT","NN","VBD","IN","DT","NN","IN","DT","NN","VBD","IN","DT", "NN","IN","VBG","TO","DT","VBN"] [("the","DT"),("dog","NN"),("ran","VBD"),("around","IN"), ("the","DT"),("tree","NN"),("while","IN"),("the","DT"), ("cat","NN"),("snaked","VBD"),("around","IN"),("the","DT"), ("trunk","NN"),("while","IN"),("banking","VBG"),("to","TO"), ("the","DT"),("left","VBN")] The README.md file contains definitions of the POS definitions. Here are the ones used in this example: DT Determiner the,some NN noun dog,cat,road VBD verb, past tense ate,ran IN Preposition of,in,by Natural Language Processing Wrap Up NLP is a large topic. I have attempted to show you just the few tricks that I use often and are simple to implement. I hope that you reuse the code in this chapter in your own projects when you need to detect entities, classify text, summarize text, and assign part of speech tags to words in text. Linked Data and the Semantic Web I am going to show you how to query semantic web data sources on the web and provide examples for how you might use this data in applications. I have written two previous books on the semantic web, one covering Common Lisp and the other covering JVM languages Java, Scala, Clojure, and Ruby. You can get free PDF versions on the book page of www.markwatson.com²⁵. If you enjoy the light introduction in this chapter then please do download a free copy of my semantic web book for more material on RDF, RDFS, and SPARQL. I like to think of the semantic web and linked data resources as: • A source of structured data on the web. These resources are called SPARQL endpoints. • Data is represented by data triples: subject, predicate, and object. The subject of one triple can be the object of another triple. Predicates are relationships; a few examples: “owns”, “is part of”, “author of”, etc. • Data that is accessed via the SPARQL query language. • A source of data that may or may not be available. SPARQL endpoints are typically available for free use and they are sometimes unavailable. Although not covered here, I sometimes work around this problem by adding a caching layer to SPARQL queries (access key being a SPARQL query string, the value being the query results). This caching speeds up development and running unit tests, and sometimes saves a customer demo when a required SPARQL endpoint goes offline at an inconvenient time. DBPedia is the semantic web version of Wikipedia²⁶. The many millions of data triples that make up DBPedia are mostly derived from the structured “info boxes” on Wikipedia pages. As you are learning SPARQL use the DBPedia SPARQL endpoint²⁷ to practice. As a practitioner who uses linked data, for any new project I start by identifying SPARQL endpoints for possibly useful data. I then interactively experiment with SPARQL queries to extract the data I need. Only when I am satisfied with the choice of SPARQL endpoints and SPARQL queries do I write any code to automatically fetch linked data for my application. Pro tip: I mentioned SPARQL query caching. I sometimes cache query results in a local database, saving the returned RDF data indexed by the SPARQL query. You can also store the cache timestamp and refresh the cache every few weeks as needed. In addition to making development and unit testing faster, your applications will be more resilient. In the last chapter “Natural Language Processing Tools” we resolved entities in natural language text to DBPedia (semantic web SPAQL endpoint for Wikipedia) URIs. Here we will use some of these URIs to demonstrate fetching real world knowledge that you might want to use in applications. ²⁵http://www.markwatson.com/books/ ²⁶http://wiki.dbpedia.org/ ²⁷http://dbpedia.org/sparql Linked Data and the Semantic Web 100 The SPARQL Query Language Example RDF N3 triples (subject, predicate, object) might look like: "Mark Watson" . Element of triples can be URIs or string constants. Triples are often written all on one line; I split it to three lines to fit the page width. Here the subject is the URI for my web site, the predicate is a URI defining an ownership relationship, and the object is a string literal. If you want to see details for any property or other URI you see, then “follow your nose” and open the URI in a web browser. For example remove the brackets from the owner property URI http://dbpedia. org/ontology/owner²⁸ and open it in a web browser. For working with RDF data programatically, it is convenient using full URI. For humans reading RDF, the N3 notation is better because it supports defining URI standard prefixes for use as abbreviations; for example: prefix ontology: ontology:owner "Mark Watson" . If you wanted to find all things that I own (assuming this data was in a public RDF repository, which it isn’t) then we might think to match the pattern: prefix ontology: ?subject ontology:owner "Mark Watson" And return all URIs matching the variable ?subject as the query result. This is the basic idea of making SPARQL queries. The following SPARQL query will be implemented later in Haskell using the HSparql library: ²⁸http://dbpedia.org/ontology/owner Linked Data and the Semantic Web 101 1 prefix resource: 2 prefix dbpprop: 3 prefix foaf: 4 5 SELECT * 6 WHERE { 7 ?s dbpprop:genre resource:Web_browser . 8 ?s foaf:name ?name . 9 } LIMIT 5 In this last SPARQL query example, the triple patterns we are trying to match are inside a WHERE clause. Notice that in the two triple patterns, the subject field of each is the variable ?s. The first pattern matches all DBPedia triples with a predicate http://dbpedia.org/property/genre and an object equal to http://dbpedia.org/resource/Web_browser. We then find all triples with the same subject but with a predicate equal to http://xmlns.com/foaf/0.1/name. Each result from this query will contain two values for variables ?s and ?name: a DBPedia URI for some thing and the name for that thing. Later we will run this query using Haskell code and you can see what the output might look like. Sometimes when I am using a specific SPARQL query in an application, I don’t bother defining prefixes and just use URIs in the query. As an example, suppose I want to return the Wikipedia (or DBPedia) abstract for IBM. I might use a query such as: 1 select * where { 2 3 4 ?o . 5 FILTER langMatches(lang(?o), "EN") 6 } LIMIT 100 If you try this query using the web interface for DBPedia SPARQL queries²⁹ you get just one result because of the FILTER option that only returns English language results. You could also use FR for French results, GE for German results, etc. A Haskell HTTP Based SPARQL Client One approach to query the DBPedia SPARQL endpoint is to build a HTTP GET request, send it to the SPARQL endpoint server, and parse the returned XML response. We will start with this simple approach. You will recognize the SPARQL query from the last section: ²⁹http://dbpedia.org/sparql/ Linked Data and the Semantic Web 102 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module HttpSparqlClient where 4 5 import Network.HTTP.Conduit (simpleHttp) 6 import Network.HTTP.Base (urlEncode) 7 import Text.XML.HXT.Core 8 import Text.HandsomeSoup 9 import qualified Data.ByteString.Lazy.Char8 as B 10 11 buildQuery :: String -> [Char] 12 buildQuery sparqlString = 13 "http://dbpedia.org/sparql/?query=" ++ urlEncode sparqlString 14 15 main :: IO () 16 main = do 17 let query = buildQuery "select * where { ?o . FILTER langMatches(lang(?o), \"EN\")} LIMIT 100" 19 res <- simpleHttp query 20 let doc = readString [] (B.unpack res) 21 putStrLn "\nAbstracts:\n" 22 abstracts <- runX $ doc >>> css "binding" >>> 23 (getAttrValue "name" &&& (deep getText)) 24 print abstracts The function buildQuery defined in lined 11-13 takes any SPARQL query, URL encodes it so it can be passed as part of a URI, and builds a query string for the DBPedia SPARQL endpoint. The returned data is in XML format. In lines 23-24 I am using the XHT parsing library to extract the names (values bound to the variable ?o in the query in line 17). I covered the use of the HandsomeSoup parsing library in the chapter Web Scraping. We use runX to execute a series of operations on an XML document (the doc variable). We first select all elements in doc that have the CSS class binding using the css function. Next we extract the value of the name attribute from each selected element using getAttrValue and also extract the text inside the element using the function deep. The &&& operator is used to combine the two values for the name attribute and the element text into a tuple. In the main function, we use the utility function simpleHttp in line 20 to fetch the results as a ByteString and in line 21 we unpack this to a regular Haskell String. Linked Data and the Semantic Web 103 1 Prelude> :l HttpSparqlClient.hs 2 [1 of 1] Compiling HttpSparqlClient ( HttpSparqlClient.hs, interpreted ) 3 Ok, modules loaded: HttpSparqlClient. 4 *HttpSparqlClient> main 5 6 Abstracts: 7 8 [("o","International Business Machines Corporation (commonly referred to as IBM) is \ 9 an American multinational technology and consulting corporation, with corporate head\ 10 quarters in Armonk, New York. 11 ...)] Querying Remote SPARQL Endpoints We will write some code in this section to make the example query to get the names of web browsers from DBPedia. In the last section we made a SPARQL query using fairly low level Haskell libraries. We will be using the high level library HSparql to build SPARQL queries and call the DBPedia SPARQL endpoint. The example in this section can be found in SparqlClient/TestSparqlClient.hs. In the main function notice how I have commented out printouts of the raw query results. Because Haskell is type safe, extracting the values wrapped in query results requires knowing RDF element return types. I will explain this matching after the program listing: 1 -- simple experiments with the excellent HSparql library 2 3 module Main where 4 5 import Database.HSparql.Connection (BindingValue(Bound)) 6 7 import Data.RDF hiding (triple) 8 import Database.HSparql.QueryGenerator 9 import Database.HSparql.Connection (selectQuery) 10 11 webBrowserSelect :: Query SelectQuery 12 webBrowserSelect = do 13 resource <- prefix "dbprop" (iriRef "http://dbpedia.org/resource/") 14 dbpprop <- prefix "dbpedia" (iriRef "http://dbpedia.org/property/") 15 foaf <- prefix "foaf" (iriRef "http://xmlns.com/foaf/0.1/") 16 x <- var 17 name <- var 18 triple x (dbpprop .:. "genre") (resource .:. "Web_browser") Linked Data and the Semantic Web 104 19 triple x (foaf .:. "name") name 20 21 return SelectQuery { queryVars = [name] } 22 23 companyAbstractSelect :: Query SelectQuery 24 companyAbstractSelect = do 25 resource <- prefix "dbprop" (iriRef "http://dbpedia.org/resource/") 26 ontology <- prefix "ontology" (iriRef "http://dbpedia.org/ontology/") 27 o <- var 28 triple (resource .:. "Edinburgh_University_Press") (ontology .:. "abstract") o 29 return SelectQuery { queryVars = [o] } 30 31 companyTypeSelect :: Query SelectQuery 32 companyTypeSelect = do 33 resource <- prefix "dbprop" (iriRef "http://dbpedia.org/resource/") 34 ontology <- prefix "ontology" (iriRef "http://dbpedia.org/ontology/") 35 o <- var 36 triple (resource .:. "Edinburgh_University_Press") (ontology .:. "type") o 37 return SelectQuery { queryVars = [o] } 38 39 main :: IO () 40 main = do 41 sq1 <- selectQuery "http://dbpedia.org/sparql" companyAbstractSelect 42 --putStrLn "\nRaw results of company abstract SPARQL query:\n" 43 --print sq1 44 putStrLn "\nWeb browser names extracted from the company abstract query results:\n" 45 case sq1 of 46 Just a -> print $ map (\[Bound (LNode (PlainLL s _))] -> s) a 47 Nothing -> putStrLn "nothing" 48 sq2 <- selectQuery "http://dbpedia.org/sparql" companyTypeSelect 49 --putStrLn "\nRaw results of company type SPARQL query:\n" 50 --print sq2 51 putStrLn "\nWeb browser names extracted from the company type query results:\n" 52 case sq2 of 53 Just a -> print $ map (\[Bound (UNode s)] -> s) a 54 Nothing -> putStrLn "nothing" 55 sq3 <- selectQuery "http://dbpedia.org/sparql" webBrowserSelect 56 --putStrLn "\nRaw results of SPARQL query:\n" 57 --print sq3 58 putStrLn "\nWeb browser names extracted from the query results:\n" 59 case sq3 of 60 Just a -> print $ map (\[Bound (LNode (PlainLL s _))] -> s) a 61 Nothing -> putStrLn "nothing" Linked Data and the Semantic Web 105 Notes on matching result types of query results: You will notice how I have commented out print statements in the last example. When trying new queries you need to print out the results in order to know how to extract the wrapped query results. Let’s look at a few examples: If we print the value for sq1: Raw results of company abstract SPARQL query: Just [[Bound (LNode (PlainLL "Edinburgh University Press ... we see that inside a Just we have a list of lists. Each inner list is a Bound wrapping types defined in HSparql. We would unwrap sq1 using: 1 case sq1 of 2 Just a -> print $ map (\[Bound (LNode (PlainLL s _))] -> s) a 3 Nothing -> putStrLn "nothing" In a similar way I printed out the values of sq2 and sq3 to see the form os case statement I would need to unwrap them. The output from this example with three queries to the DBPedia SPARQL endpoint is: 1 Web browser names extracted from the company abstract query results in sq1: 2 3 ["Edinburgh University Press \195\168 una casa editrice scientifica di libri accadem\ 4 ici e riviste, con sede a Edimburgo, in Scozia.","Edinburgh University Press \195\16\ 5 9 uma editora universit\195\161ria com base em Edinburgh, Esc\195\179cia.","Edinburg\ 6 h University Press is a scholarly publisher of academic books and journals, based in\ 7 Edinburgh, Scotland."] 8 9 The type of company is extracted from the company type query results in sq2: 10 11 ["http://dbpedia.org/resource/Publishing"] 12 13 Web browser names extracted from the query results in sq3: 14 15 ["Grail","ViolaWWW","Kirix Strata","SharkWire Online","MacWeb","Camino","eww","TenFo\ 16 urFox","WiseStamp","X-Smiles","Netscape Navigator 2","SimpleTest","AWeb","IBrowse","\ 17 iCab","ANT Fresco","Netscape Navigator 9.0","HtmlUnit","ZAC Browser","ELinks","ANT G\ 18 alio","Nintendo DSi Browser","Nintendo DS Browser","Netscape Navigator","NetPositive\ 19 ","OmniWeb","Abaco","Flock","Steel","Kazehakase","GNU IceCat","FreeWRL","UltraBrowse\ 20 r","AMosaic","NetCaptor","NetSurf","Netscape Browser","SlipKnot","ColorZilla","Inter\ Linked Data and the Semantic Web 106 21 net Channel","Obigo Browser","Swiftfox","BumperCar","Swiftweasel","Swiftdove","IEs4L\ 22 inux","MacWWW","IBM Lotus Symphony","SlimBrowser","cURL","FoxyTunes","Iceweasel","Me\ 23 nuBox","Timberwolf web browser","Classilla","Rockmelt","Galeon","Links","Netscape Na\ 24 vigator","NCSA Mosaic","MidasWWW","w3m","PointerWare","Pogo Browser","Oregano","Avan\ 25 t Browser","Wget","NeoPlanet","Voyager","Amaya","Midori","Sleipnir","Tor","AOL Explo\ 26 rer"] Linked Data and Semantic Web Wrap Up If you enjoyed the material on linked data and DBPedia then please do get a free copy of one of my semantic web books on my website book page³⁰ as well as other SPARQL and linked data tutorials on the web. Structured and sematically labelled data, when it is available, is much easier to process and use effectively than raw text and HTML collected from web sites. ³⁰http://www.markwatson.com/books/ Web Scraping In my past work I usually used the Ruby scripting language for web scraping but as I use the Haskell language more often for projects both large and small I am now using Haskell for web scraping, data collection, and data cleaning tasks. If you worked through the tutorial chapter on impure Haskell programming then you already know most of what you need to understand this chapter. Here we will walk through a few short examples for common web scraping tasks. Before we start a tutorial about web scraping I want to point out that much of the information on the web is copyright and the first thing that you should do is to read the terms of service for web sites to insure that your use of web scraped data conforms with the wishes of the persons or organizations who own the content and pay to run scraped web sites. As we saw in the last chapter on linked data there is a huge amount of structured data available on the web via web services, semantic web/linked data markup, and APIs. That said, you will frequently find text (usually HTML) that is useful on web sites. However, this text is often at least partially unstructured and in a messy and frequently changing format because web pages are meant for human consumption and making them easy to parse and use by software agents is not a priority of web site owners. Note: It takes a while to fetch all of the libraries in the directory WebScraping so please do a stack build now to get these examples ready to experiment with while you read this chapter. Using the Wreq Library The Wreq library³¹ is an easy way to fetch data from the web. The example in this section fetches DBPedia (i.e., the semantic web version of Wikipedia) data in JSON and RDF N3 formats, and also fetches the index page from my web site. I will introduce you to the Lens library for extracting data from data structures, and we will also use Lens in a later chapter when writing a program to play Backjack. We will be using function get in the Network.Wreq module that has a type signature: get::String -> IO (Response Data.ByteString.Lazy.Internal.ByteString) We will be using the OverloadedStrings language extension to facilitate using both [Char] strings and ByteString data types. Note: In the GHCi repl you can use :set -XOverloadedStrings. We use function get to return JSON data; here is a bit of the JSON data returned from calling get using the URI for my web site: ³¹http://www.serpentine.com/wreq/tutorial.html Web Scraping 108 Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Date","Sat, 15 Oct 2016 16:00:59 GMT"), ("Content-Type","text/html"), ("Transfer-Encoding","chunked"), ("Connection","keep-alive")], responseBody = "\r\n\r\nMark Watson: con\ sultant specializing in artificial intelligence, natural language processing, and ma\ chine\r\n learning\r\n \r\n \r\n \r\n \r\n \r\n \r\n <\ style type=\"text/css\"> body {\r\n padding-top: 60px;\r\n }\r\n\r\n \r\n\r\nBlog\r\n
  • My Books As an example, the Lens expression for extracting the response status code is (r is the IO Response data returned from calling get): (r ^. responseStatus . statusCode) responseStatus digs into the top level response structure and statusCode digs further in to fetch the code 200. To get the actual contents of the web page we can use the responseBody function: (r ^. responseBody) Here is the code for the entire example: Web Scraping 109 1 {-# LANGUAGE OverloadedStrings #-} 2 3 -- reference: http://www.serpentine.com/wreq/tutorial.html 4 5 module HttpClientExample where 6 7 import Network.Wreq 8 import Control.Lens -- for ^. ^? 9 import Data.Maybe (fromJust) 10 11 fetchURI uri = do 12 putStrLn $ "\n\n*** Fetching " ++ uri 13 r <- get uri 14 putStrLn $ "status code: " ++ (show (r ^. responseStatus . statusCode)) 15 putStrLn $ "content type: " ++ (show (r ^? responseHeader "Content-Type")) 16 putStrLn $ "respose body: " ++ show (fromJust (r ^? responseBody)) 17 18 main :: IO () 19 main = do 20 -- JSON from DBPedia 21 fetchURI "http://dbpedia.org/data/Sedona_Arizona.json" 22 -- N3 RDF from DBPedia 23 fetchURI "http://dbpedia.org/data/Sedona_Arizona.n3" 24 -- my web site 25 fetchURI "http://markwatson.com" This example produces a lot of printout, so I a just showing a small bit here (the text from the body is not shown): 1 *Main> :l HttpClientExample 2 [1 of 1] Compiling HttpClientExample ( HttpClientExample.hs, interpreted ) 3 Ok, modules loaded: HttpClientExample. 4 *HttpClientExample> main 5 6 *** Fetching http://dbpedia.org/data/Sedona_Arizona.json 7 status code: 200 8 content type: Just "application/json" 9 respose body: "{\n \"http://en.wikipedia.org/wiki/Sedona_Arizona\" : { \"http://xml\ 10 ns.com/foaf/0.1/primaryTopic\" : [ { \"type\" : \"uri\", \"value\" : \"http://dbpedi\ 11 a.org/resource/Sedona_Arizona\" } ] } ,\n \"http://dbpedia.org/resource/Sedona_Ariz\ 12 ona\" : { \"http://www.w3.org/2002/07/owl#sameAs\" : [ { \"type\" : \"uri\", \"value\ 13 \" : \"http://dbpedia.org/resource/Sedona_Arizona\" } ] ,\n \"http://www.w3.org/2\ 14 000/01/rdf-schema#label\" : [ { \"type\" : \"literal\", \"value\" : \"Sedona Arizona\ Web Scraping 110 15 \" , \"lang\" : \"en\" } ] ,\n \"http://xmlns.com/foaf/0.1/isPrimaryTopicOf\" : [\ 16 { \"type\" : \"uri\", \"value\" : \"http://en.wikipedia.org/wiki/Sedona_Arizona\" }\ 17 ] ,\n \"http://www.w3.org/ns/prov#wasDerivedFrom\" : [ { \"type\" : \"uri\", \"v\ 18 alue\" : \"http://en.wikipedia.org/wiki/Sedona_Arizona?oldid=345939723\" } ] ,\n \ 19 \"http://dbpedia.org/ontology/wikiPageID\" : [ { \"type\" : \"literal\", \"value\" :\ 20 11034313 , \"datatype\" : \"http://www.w3.org/2001/XMLSchema#integer\" } ] ,\n \\ 21 "http://dbpedia.org/ontology/wikiPageRevisionID\" : [ { \"type\" : \"literal\", \"va\ 22 lue\" : 345939723 , \"datatype\" : \"http://www.w3.org/2001/XMLSchema#integer\" } ] \ 23 ,\n \"http://dbpedia.org/ontology/wikiPageRedirects\" : [ { \"type\" : \"uri\", \\ 24 "value\" : \"http://dbpedia.org/resource/Sedona,_Arizona\" } ] }\n}\n" 25 26 *** Fetching http://dbpedia.org/data/Sedona_Arizona.n3 27 status code: 200 28 content type: Just "text/n3; charset=UTF-8" 29 respose body: "@prefix foaf:\t .\n@prefix wikipedia-en:\\ 30 t .\n@prefix dbr:\t .\n\ 31 wikipedia-en:Sedona_Arizona\tfoaf:primaryTopic\tdbr:Sedona_Arizona .\n@prefix owl:\t\ 32 .\ndbr:Sedona_Arizona\towl:sameAs\tdbr:Sedona_Arizo\ 33 na .\n@prefix rdfs:\t .\ndbr:Sedona_Arizona\t\ 34 rdfs:label\t\"Sedona Arizona\"@en ;\n\tfoaf:isPrimaryTopicOf\twikipedia-en:Sedona_Ar\ 35 izona .\n@prefix prov:\t .\ndbr:Sedona_Arizona\tprov:was\ 36 DerivedFrom\t .\n@prefi\ 37 x dbo:\t .\ndbr:Sedona_Arizona\tdbo:wikiPageID\t110343\ 38 13 ;\n\tdbo:wikiPageRevisionID\t345939723 ;\n\tdbo:wikiPageRedirects\t ." 40 41 *** Fetching http://markwatson.com 42 status code: 200 43 content type: Just "text/html" 44 respose body: "\r\n\r\nMark Watson: consultant spe\ 45 cializing in ... You might want to experiment in the GHCi repl with the get function and Lens. If so, this will get you started: Web Scraping 111 *Main> :set -XOverloadedStrings *Main> r <- get "http://dbpedia.org/data/Sedona_Arizona.json" *Main> :t r r :: Response ByteString *Main> (r ^. responseStatus . statusCode) 200 *Main> (r ^? responseHeader "Content-Type") Just "application/json" *Main> fromJust (r ^? responseHeader "Content-Type") "application/json" *Main> (fromJust (r ^? responseBody)) "{\n \"http://en.wikipedia.org/wiki/Sedona_Arizona\" : { ... not shown ... \" In the following section we will use the HandsomeSoup library for parsing HTML. Using the HandsomeSoup Library for Parsing HTML We will now use the Handsome Soup³² library to parse HTML. Handsome Soup allows us to use CSS style selectors to extract specific elements from the HTML from a web page. The HXT lower level library provides modeling HTML (and XML) as a tree structure and an Arrow³³ style interface for traversing the tree structures and extract data. Arrows are a generalization of monads to manage calculations given a context. I will touch upon just enough material on Arrows for you to understand the examples in this chapter. Handsome Soup also provides a high level utility function fromUrl to fetch web pages; the type of fromUrl is: fromUrl :: String -> IOSArrow b (Data.Tree.NTree.TypeDefs.NTree XNode) We will not work directly with the tree structure of the returned data, we will simply use the accessor functions to extract the data we need. Before looking at the example code listing, let’s look at this extraction process (doc is the tree structured data returned from calling fromUrl): links <- runX $ doc >>> css "a" ! "href" The runX function runs arrow computations for us. doc is a tree data structure, css allows us to pattern match on specific HTML elements. Here we are using CSS style selection for all “a” anchor HTML elements and digging into the element to return the element attribute “href” value for each “a” anchor element. In a similar way, we can select all “img” image elements and dig down into the matched elements to fetch the “src” attributes: ³²https://github.com/egonSchiele/HandsomeSoup ³³https://wiki.haskell.org/Arrow Web Scraping 112 imageSrc <- runX $ doc >>> css "img" ! "src" We can get the full body text: allBodyText <- runX $ doc >>> css "body" //> getText The operator //> applied to the function getText will get all text in all nested elements inside the body element. If we had used the operator /> then we would only have fetched the text at the top level of the body element. Here is the full example source listing: 1 {-# LANGUAGE OverloadedStrings #-} 2 3 -- references: https://github.com/egonSchiele/HandsomeSoup 4 -- http://adit.io/posts/2012-04-14-working_with_HTML_in_haskell.html 5 6 module Main where 7 8 import Text.XML.HXT.Core 9 import Text.HandsomeSoup 10 11 12 main :: IO () 13 main = do 14 let doc = fromUrl "http://markwatson.com/" 15 putStrLn "\n\n ** LINKS:\n" 16 links <- runX $ doc >>> css "a" ! "href" 17 mapM_ putStrLn links 18 h2 <- runX $ doc >>> css "h2" ! "href" 19 putStrLn "\n\n ** ALL H2 ELEMENTS::\n" 20 mapM_ putStrLn h2 21 imageSrc <- runX $ doc >>> css "img" ! "src" 22 putStrLn "\n\n ** ALL IMG ELEMENTS:\n" 23 mapM_ putStrLn imageSrc 24 allBodyText <- runX $ doc >>> css "body" //> getText 25 putStrLn "\n\n ** TEXT FROM BODY ELEMENT:\n" 26 mapM_ putStrLn allBodyText 27 pText <- runX $ doc >>> css "p" //> getText -- //> gets all contained text 28 -- /> gets only directly 29 -- contained text 30 putStrLn "\n\n ** ALL P ELEMENTS:\n" 31 mapM_ putStrLn pText This example prints out several hundred lines; here is the first bit of output: Web Scraping 113 *Main> :l HandsomeSoupTest.hs [1 of 1] Compiling HandsomeSoupTest ( HandsomeSoupTest.hs, interpreted ) Ok, modules loaded: HandsomeSoupTest. *HandsomeSoupTest> main ** LINKS: / /consulting/ http://blog.markwatson.com /books/ /opensource/ /fun/ https://github.com/mark-watson https://plus.google.com/117612439870300277560 https://twitter.com/mark_l_watson https://www.wikidata.org/wiki/Q18670263 http://markwatson.com/index.rdf http://markwatson.com/index.ttl ** ALL IMG ELEMENTS: /pictures/Markws.jpg ** TEXT FROM BODY ELEMENT: ... I find HandsomeSoup to be very convenient for picking apart HTML data fetched from web pages. Writing a good spider for any given web site is a process of understanding how the HTML for the web site is structured and what information you need to collect. I strongly suggest that you work with the web page to be spider open in a web browser with “show source code” in another browser tab. Then open an interactive GHCi repl and experiment using the HandsomeSoup APIs to get the data you need. Web Scraping Wrap Up There are many Haskell library options for web scraping and cleaning data. In this chapter I showed you just what I use in my projects. The material in this chapter and the chapters on text processing and linked data should be sufficient to get you started using online data sources in your applications. Using Relational Databases We will see how to use popular libraries for accessing the sqlite and Postgres (sometimes also called PostgeSQL) databases in this chapter. I assume that you are already familiar with SQL. Database Access for Sqlite We will use the sqlite-simple³⁴ library in this section to access Sqlite databases and use the similar library postgresql-simple³⁵ in the next section for use with Postgres. There are other good libraries for database connectivity like Persistent³⁶ but I like sqlite-simple and it has a gentle learning curve so that is what we will use here. You will learn the basics of database connectivity in this and the next section. Setting up and using sqlite is easy because the sqlite- simple library includes the compiled code for sqlite so configuration requires only the file path to the database file. 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Main where 4 5 import Database.SQLite.Simple 6 7 {- 8 Create sqlite database: 9 sqlite3 test.db "create table test (id integer primary key, str text);" 10 11 This example is derived from the example at github.com/nurpax/sqlite-simple 12 -} 13 14 main :: IO () 15 main = do 16 conn <- open "test.db" 17 -- start by getting table names in database: 18 do 19 r <- query_ conn 20 "SELECT name FROM sqlite_master WHERE type='table'" :: IO [Only String] ³⁴https://hackage.haskell.org/package/sqlite-simple ³⁵https://hackage.haskell.org/package/postgresql-simple ³⁶https://www.stackage.org/package/persistent Using Relational Databases 115 21 print "Table names in database test.db:" 22 mapM_ (print . fromOnly) r 23 24 -- get the metadata for table test in test.db: 25 do 26 r <- query_ conn 27 "SELECT sql FROM sqlite_master WHERE type='table' and name='test'" :: 28 IO [Only String] 29 print "SQL to create table 'test' in database test.db:" 30 mapM_ (print . fromOnly) r 31 32 -- add a row to table 'test' and then print out the rows in table 'test': 33 do 34 execute conn "INSERT INTO test (str) VALUES (?)" 35 (Only ("test string 2" :: String)) 36 r2 <- query_ conn "SELECT * from test" :: IO [(Int, String)] 37 print "number of rows in table 'test':" 38 print (length r2) 39 print "rows in table 'test':" 40 mapM_ print r2 41 42 close conn The type Only used in line 20 acts as a container for a single value and is defined in the simple-sqlite library. It can also be used to pass values for queries like: r <- query_ conn "SELECT name FROM customers where id = ?" (Only 4::Int) To run this example start by creating a sqlite database that is stored in the file test.db: sqlite3 test.db "create table test (id integer primary key, str text);" Then build and run the example: stack build --exec TestSqLite1 Database Access for Postgres Setting up and using a database in the last section was easy because the sqlite-simple library includes the compiled code for sqlite so configuration only requires the file path the the database file. The Using Relational Databases 116 Haskel examples for Postgres will be similar to those for Sqlite. There is some complication in setting up Postgres if you do not already have it installed and configured. In any case, you will need to have Postgres installed and set up with a user account for yourself. When I am installing and configuring Postgres on my Linux laptop, I create a database role markw. You will certainly create a different role/account name so subsitute your role name for markw in the following code examples. If you are using Ubuntu you can install Postgres and create a role using: sudo apt-get update sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-9.5 sudo -u postgres createuser --interactive Enter name of role to add: markw Shall the new role be a superuser? (y/n) y We will need to install postgresql-server-dev-9.5 in order to use the Haskell Postgres bindings. Note that your version of Ubuntu Linux may have a different version of the server dev package which you can find using: aptitude search postgresql-dev If you are using Mac OS X you can then install Postgres as an application which is convenient for development. A role is automatically created with the same name as your OS X “short name.” You can use the “Open psql” button on the interface to open a command line shell that functions like the psql command on Ubuntu (or other Linux distributions). We will need to install postgresql-server-dev-9.5 in order to use the Haskell Postgres bindings. Note that your version of Ubuntu Linux may have a different version of the server dev package which you can find using: aptitude search postgresql-dev You will then want to create a database named haskell and set the password for role/account markw to test1 for running the example in this section: Using Relational Databases 117 createdb haskell sudo -u postgres psql postgres=# alter user markw encrypted password 'test1'; postgres=# \q psql -U markw haskell psql (9.5.4) Type "help" for help. haskell=# create table customers (id int, name text, email text); CREATE TABLE haskell=# insert into customers values (1, 'Acme Cement', 'info@acmecement.com'); INSERT 0 1 haskell=# \q If you are not familiar with using Postgres then take a minute to experiment with using the psql command line utility to connect to the database you just created and peform practice queries: markw=# \c haskell You are now connected to database "haskell" as user "markw". haskell=# \d List of relations Schema | Name | Type | Owner --------+-----------+-------+------- public | customers | table | markw public | links | table | markw public | products | table | markw (3 rows) haskell=# select * from customers; id | name | email ----+-----------------+--------------------- 1 | Acme Cement | info@acmecement.com 2 | Biff Home Sales | info@biff.com 3 | My Pens | info@mypens.com (3 rows) haskell=# select * from products; id | name | cost ----+---------------+------ 1 | Cement bag | 2.5 2 | Cheap Pen | 1.5 3 | Expensive Pen | 14.5 Using Relational Databases 118 (3 rows) haskell=# select * from links; id | customer_id | productid ----+-------------+----------- 1 | 1 | 1 2 | 3 | 2 3 | 3 | 3 (3 rows) haskell=# You can change default database settings using ConnectInfo: ConnectInfo connectHost :: String connectPort :: Word16 connectUser :: String connectPassword :: String connectDatabase :: String In the following example on lines 9-10 I use defaultConnectInfo that lets me override just some settings, leaving the rest set at default values. The code to access a database using simple-postgresql is similar to that in the last section, with a few API changes. 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Main where 4 5 import Database.PostgreSQL.Simple 6 7 main :: IO () 8 main = do 9 conn <- connect defaultConnectInfo { connectDatabase = "haskell", 10 connectUser = "markw" } 11 -- start by getting table names in database: 12 do 13 r <- query_ conn "SELECT name FROM customers" :: IO [(Only String)] 14 print "names and emails in table 'customers' in database haskell:" 15 mapM_ (print . fromOnly) r 16 17 -- add a row to table 'test' and then print out the rows in table 'test': Using Relational Databases 119 18 do 19 let rows :: [(Int, String, String)] 20 rows = [(4, "Mary Smith", "marys@acme.com")] 21 executeMany conn 22 "INSERT INTO customers (id, name, email) VALUES (?,?,?)" rows 23 r2 <- query_ conn "SELECT * from customers" :: IO [(Int, String, String)] 24 print "number of rows in table 'customers':" 25 print (length r2) 26 print "rows in table 'customers':" 27 mapM_ print r2 28 29 close conn The type Only used in line 20 acts as a container for a single value and is defined in the simple- postgresql library. It can also be used to pass values for queries like: r <- query_ conn "SELECT name FROM customers where id = ?" (Only 4::Int) The monad mapping function mapM_ using in line 22 is like mapM but is used when we do not need the resulting collection from executing the map operation. mapM_ is used for side effects, in this case extracting the value for a collection of Only values and printing them. I removed some output from building the example in the following listing: $ Database-postgres git:(master) > stack build --exec TestPostgres1 TestDatabase-0.1.0.0: build Preprocessing executable 'TestPostgres1' for TestDatabase-0.1.0.0... [1 of 1] Compiling Main ( TestPostgres1.hs, "names and emails in table 'customers' in database haskell:" "Acme Cement" "Biff Home Sales" "My Pens" "number of rows in table 'customers':" 4 "rows in table 'customers':" (1,"Acme Cement","info@acmecement.com") (2,"Biff Home Sales","info@biff.com") (3,"My Pens","info@mypens.com") (4,"Mary Smith","marys@acme.com") Postgres is my default database and I use it unless there is a compelling reason not to. While work for specific customers has mandated using alternative data stores (e.g., BigTable while working at Google and MongoDB at Compass Labs), Postgres supports relational tables, free text search, and structured data like JSON. Haskell Program to Play the Blackjack Card Game For much of my work using Haskell I deal mostly with pure code with smaller bits of impure code for network and file IO, etc. Realizing that my use case for using Haskell (mostly pure code) may not be typical, I wanted the last example “cookbook recipe” in this book to be an example dealing with changing state, a program to play the Blackjack card game. The game state is maintained in the type Table that holds information on a randomized deck of cards, the number of players in addition to the game user and the card dealer, the cards in the current hand, and the number of betting chips that all players own. Table data is immutable so all of the major game playing functions take a table and any other required inputs, and generate a new table as the function result. This example starts by asking how many players, besides the card dealer and the game user, should play a simulated Blackjack game. The game user controls when they want another card while the dealer and any other simulated players play automatically (they always hit when their card score is less than 17). I define the types for playing cards and an entire card deck in the file Card.hs: 1 module Card (Card, Rank, Suit, orderedCardDeck, cardValue) where 2 3 import Data.Maybe (fromMaybe) 4 import Data.List (elemIndex) 5 import Data.Map (fromList, lookup, keys) 6 7 data Card = Card { rank :: Rank 8 , suit :: Suit } 9 deriving (Eq, Show) 10 11 data Suit = Hearts | Diamonds | Clubs | Spades 12 deriving (Eq, Show, Enum, Ord) 13 14 data Rank = Two | Three | Four 15 | Five | Six | Seven | Eight 16 | Nine | Ten | Jack | Queen | King | Ace 17 deriving (Eq, Show, Enum, Ord) 18 19 rankMap = fromList [(Two,2), (Three,3), (Four,4), (Five,5), Haskell Program to Play the Blackjack Card Game 121 20 (Six,6), (Seven,7), (Eight,8), (Nine,9), 21 (Ten,10), (Jack,10), (Queen,10), 22 (King,10), (Ace,11)] 23 24 orderedCardDeck :: [Card] 25 orderedCardDeck = [Card rank suit | rank <- keys rankMap, 26 suit <- [Hearts .. Clubs]] 27 28 cardValue :: Card -> Int 29 cardValue aCard = 30 case (Data.Map.lookup (rank aCard) rankMap) of 31 Just n -> n 32 Nothing -> 0 -- should never happen As usual, the best way to understand this code is to go to the GHCi repl: 1 *Main Card RandomizedList Table> :l Card 2 [1 of 1] Compiling Card ( Card.hs, interpreted ) 3 Ok, modules loaded: Card. 4 *Card> :t orderedCardDeck 5 orderedCardDeck :: [Card] 6 *Card> orderedCardDeck 7 [Card {rank = Two, suit = Hearts},Card {rank = Two, suit = Diamonds},Card {rank = Tw\ 8 o, suit = Clubs},Card {rank = Three, suit = Hearts},Card {rank = Three, 9 ... 10 *Card> head orderedCardDeck 11 Card {rank = Two, suit = Hearts} 12 *Card> cardValue $ head orderedCardDeck 13 2 So, we have a sorted deck of cards and a utility function for returning the numerical value of a card (we always count ace cards as 11 points, deviating from standard Blackjack rules). The next thing we need to get is randomly shuffled lists. The Haskell Wiki³⁷ has a good writeup on randomizing list elements and we are borrowing their function randomizedList (you can see the source code in the file RandomizedList.hs). Here is a sample use: ³⁷https://wiki.haskell.org/Random_shuffle Haskell Program to Play the Blackjack Card Game 122 1 *Card> :l RandomizedList.hs 2 [1 of 1] Compiling RandomizedList ( RandomizedList.hs, interpreted ) 3 Ok, modules loaded: RandomizedList. 4 *RandomizedList> import Card 5 *RandomizedList Card> randomizedList orderedCardDeck 6 [Card {rank = Queen, suit = Hearts},Card {rank = Six, suit = Diamonds},Card {rank = \ 7 Five, suit = Clubs},Card {rank = Five, suit = Diamonds},Card {rank = Seven, suit = C\ 8 lubs},Card {rank = Three, suit = Hearts},Card {rank = Four, suit = Diamonds},Card {r\ 9 ank = Ace, suit = Hearts}, 10 ... Much of the complexity in this example is implemented in Table.hs which defines the type Table and several functions to deal and score hands of dealt cards: • createNewTable :: Players -> Table. Players is the integer number of other players at the table. • setPlayerBet :: Int -> Table -> Table. Given a new value to bet and a table, generate a new modified table. • showTable :: Table -> [Char]. Given a table, generate a string describing the table (in a format useful for development) • initialDeal :: [Card] -> Table -> Int -> Table. Given a randomized deck of cards, a table, and the number of other players, generate a new table. • changeChipStack :: Int -> Int -> Table -> Table. Given a player index (index order: user, dealer, and other players), a new number of betting chips for the player, and a table, then generate a new modified table. • setCardDeck :: [Card] -> Table -> Table. Given a randomized card deck and a table, generate a new table containing the new randomized card list; all other table data is unchanged. • dealCards :: Table -> [Int] -> Table. Given a table and a list of player indices for players wanting another card, generate a new modified table. • resetTable :: [Card] -> Table -> Int -> Table. Given a new randomized card deck, a table, and a new number of other players, generate a new table. • scoreHands :: Table -> Table. Given a table, score all dealt hands and generate a new table with these scores. There is no table type score data, rather, we “score” by changing the number of chips all of the players (inclding the dealer) has. • dealCardToUser :: Table -> Int -> Table. For the game user, always deal a card. For the dealer and other players, deal another card if their hand score is less than 17. • handOver :: Table -> Bool. Determine if the current hand is over. • setPlayerPasses :: Table -> Table. Call this function when the payer passes. Other players and dealer are then played out automatically. The implementation in the file Table.hs is fairly simple, with the exception of the use of Haskell lenses to access nested data in the table type. I will discuss the use of lenses after the program listing, but: as you are reading the code look out for variables starting with the underscore character _ that alerts the Lens system that it should create data accessors for these variables: Haskell Program to Play the Blackjack Card Game 123 1 {-# LANGUAGE TemplateHaskell #-} -- for makeLens 2 3 module Table (Table (..), createNewTable, setPlayerBet, showTable, initialDeal, 4 changeChipStack, setCardDeck, dealCards, resetTable, scoreHands, 5 dealCardToUser, handOver, setPlayerPasses) where 6 -- note: export dealCardToUser only required for ghci development 7 8 import Control.Lens 9 10 import Card 11 import Data.Bool 12 import Data.Maybe (fromMaybe) 13 14 data Table = Table { _numPlayers :: Int 15 , _chipStacks :: [Int] -- number of chips, 16 -- indexed by player index 17 , _dealtCards :: [[Card]] -- dealt cards for user, 18 -- dealer, and other players 19 , _currentPlayerBet :: Int 20 , _userPasses :: Bool 21 , _cardDeck :: [Card] 22 } 23 deriving (Show) 24 25 type Players = Int 26 27 createNewTable :: Players -> Table 28 createNewTable n = 29 Table n 30 [500 | _ <- [1 .. n]] -- give each player (incuding dealer) 10 chips 31 [[] | _ <- [0..n]] -- dealt cards for user and other players 32 -- (we don't track dealer's chips) 33 20 -- currentPlayerBet number of betting chips 34 False 35 [] -- placeholder for random shuffled card deck 36 37 resetTable :: [Card] -> Table -> Int -> Table 38 resetTable cardDeck aTable numberOfPlayers = 39 Table numberOfPlayers 40 (_chipStacks aTable) -- using Lens accessor 41 [[] | _ <- [0..numberOfPlayers]] 42 (_currentPlayerBet aTable) -- using Lens accessor 43 False Haskell Program to Play the Blackjack Card Game 124 44 cardDeck 45 46 -- Use lens extensions for type Table: 47 48 makeLenses ''Table 49 50 showDealtCards :: [[Card]] -> String 51 showDealtCards dc = 52 (show [map cardValue hand | hand <- dc]) 53 54 setCardDeck :: [Card] -> Table -> Table 55 setCardDeck newDeck = 56 over cardDeck (\_ -> newDeck) -- change value to new card deck 57 58 dealCards :: Table -> [Int] -> Table 59 dealCards aTable playerIndices = 60 last $ scanl dealCardToUser aTable playerIndices 61 62 initialDeal cardDeck aTable numberOfPlayers = 63 dealCards 64 (dealCards (resetTable cardDeck aTable numberOfPlayers) 65 [0 .. numberOfPlayers]) 66 [0 .. numberOfPlayers] 67 68 showTable :: Table -> [Char] 69 showTable aTable = 70 "\nCurrent table data:\n" ++ 71 " Chipstacks: " ++ 72 "\n Player: " ++ (show (head (_chipStacks aTable))) ++ 73 "\n Other players: " ++ (show (tail (_chipStacks aTable))) ++ 74 "\n User cards: " ++ (show (head (_dealtCards aTable))) ++ 75 "\n Dealer cards: " ++ (show ((_dealtCards aTable) !! 1)) ++ 76 "\n Other player's cards: " ++ (show (tail (tail(_dealtCards aTable)))) ++ 77 -- "\n Dealt cards: " ++ (show (_dealtCards aTable)) ++ 78 "\n Dealt card values: " ++ (showDealtCards (_dealtCards aTable)) ++ 79 "\n Current player bet: " ++ 80 (show (_currentPlayerBet aTable)) ++ 81 "\n Player pass: " ++ 82 (show (_userPasses aTable)) ++ "\n" 83 84 clipScore aTable playerIndex = 85 let s = score aTable playerIndex in 86 if s < 22 then s else 0 Haskell Program to Play the Blackjack Card Game 125 87 88 scoreHands aTable = 89 let chipStacks2 = _chipStacks aTable 90 playerScore = clipScore aTable 0 91 dealerScore = clipScore aTable 1 92 otherScores = map (clipScore aTable) [2..] 93 newPlayerChipStack = if playerScore > dealerScore then 94 (head chipStacks2) + (_currentPlayerBet aTable) 95 else 96 if playerScore < dealerScore then 97 (head chipStacks2) - (_currentPlayerBet aTable) 98 else (head chipStacks2) 99 newOtherChipsStacks = 100 map (\(x,y) -> if x > dealerScore then 101 y + 20 102 else 103 if x < dealerScore then 104 y - 20 105 else y) 106 (zip otherScores (tail chipStacks2)) 107 newChipStacks = newPlayerChipStack:newOtherChipsStacks 108 in 109 over chipStacks (\_ -> newChipStacks) aTable 110 111 setPlayerBet :: Int -> Table -> Table 112 setPlayerBet newBet = 113 over currentPlayerBet (\_ -> newBet) 114 115 setPlayerPasses :: Table -> Table 116 setPlayerPasses aTable = 117 let numPlayers = _numPlayers aTable 118 playerIndices = [1..numPlayers] 119 t1 = over userPasses (\_ -> True) aTable 120 t2 = dealCards t1 playerIndices 121 t3 = dealCards t2 playerIndices 122 t4 = dealCards t3 playerIndices 123 in 124 t4 125 126 127 changeChipStack :: Int -> Int -> Table -> Table 128 changeChipStack playerIndex newValue = 129 over chipStacks (\a -> a & element playerIndex .~ newValue) Haskell Program to Play the Blackjack Card Game 126 130 131 scoreOLD aTable playerIndex = 132 let scores = map cardValue ((_dealtCards aTable) !! playerIndex) 133 totalScore = sum scores in 134 if totalScore < 22 then totalScore else 0 135 136 score aTable playerIndex = 137 let scores = map cardValue ((_dealtCards aTable) !! playerIndex) 138 totalScore = sum scores in 139 totalScore 140 141 dealCardToUser' :: Table -> Int -> Table 142 dealCardToUser' aTable playerIndex = 143 let nextCard = head $ _cardDeck aTable 144 playerCards = nextCard : ((_dealtCards aTable) !! playerIndex) 145 newTable = over cardDeck (\cd -> tail cd) aTable in 146 over dealtCards (\a -> a & element playerIndex .~ playerCards) newTable 147 148 dealCardToUser :: Table -> Int -> Table 149 dealCardToUser aTable playerIndex 150 | playerIndex == 0 = dealCardToUser' aTable playerIndex -- user 151 | otherwise = if (score aTable playerIndex) < 17 then 152 dealCardToUser' aTable playerIndex 153 else aTable 154 155 handOver :: Table -> Bool 156 handOver aTable = 157 _userPasses aTable In line 48 we use the function makeLenses to generate access functions for the type Table. We will look in some detail at lines 54-56 where we use the lense over function to modify a nested value in a table, returning a new table: 1 setCardDeck :: [Card] -> Table -> Table 2 setCardDeck newDeck = 3 over cardDeck (\_ -> newDeck) The expression in line 3 evaluates to a partial function that takes another argument, a table, and returns a new table with the card deck modified. Function over expects a function as its second argument. In this example, the inline function ignores the argument it is called with, which would be the old card deck value, and returns the new card deck value which is placed in the table value. Using lenses can greatly simplify the code to manipulate complex types. Haskell Program to Play the Blackjack Card Game 127 Another place where I am using lenses is in the definition of function scoreHands (lines 88-109). On line 109 we are using the over function to replace the old player betting chip counts with the new value we have just calculated: over chipStacks (\_ -> newChipStacks) aTable Similarly, we use over in line 113 to change the current player bet. In function handOver on line 157, notice how I am using the generated function _userPasses to extract the value of the user passes boolean flag from a table. The function main, defined in the file Main.hs, uses the code we have just seen to represent a table and modify a table, is fairly simple. A main game loop repetitively accepts game user imput, and calls the appropriate functions to modify the current table, producing a new table. Remember that the table data is immutable: we always generate a new table from the old table when we need to modify it. 1 module Main where 2 3 import Card -- pure code 4 import Table -- pure code 5 import RandomizedList -- impure code 6 7 printTable :: Table -> IO () 8 printTable aTable = 9 putStrLn $ showTable aTable 10 11 randomDeck = 12 randomizedList orderedCardDeck 13 14 gameLoop :: Table -> Int -> IO b 15 gameLoop aTable numberOfPlayers = do 16 printTable aTable 17 cardDeck <- randomDeck 18 if (handOver aTable) then 19 do 20 putStrLn "\nHand over. State of table at the end of the game:\n" 21 printTable aTable 22 putStrLn "\nNewly dealt hand:\n" 23 gameLoop (initialDeal cardDeck (scoreHands aTable) 24 numberOfPlayers) 25 numberOfPlayers 26 else 27 do Haskell Program to Play the Blackjack Card Game 128 28 putStrLn "Enter command:" 29 putStrLn " h)it or set bet to 10, 20, 30; any other key to stay:" 30 command <- getLine 31 if elem command ["10", "20", "30"] then 32 gameLoop (setPlayerBet (read command) aTable) numberOfPlayers 33 else 34 if command == "h" then 35 gameLoop (dealCards aTable [0 .. numberOfPlayers]) numberOfPlayers 36 else 37 gameLoop (setPlayerPasses (dealCards aTable [1 .. numberOfPlayers])) 38 numberOfPlayers 39 -- player stays (no new cards) 40 41 main :: IO b 42 main = do 43 putStrLn "Start a game of Blackjack. Besides yourself, how many other" 44 putStrLn "players do you want at the table?" 45 s <- getLine 46 let num = (read s :: Int) + 1 47 cardDeck <- randomDeck 48 let aTable = initialDeal cardDeck (createNewTable num) num 49 gameLoop aTable num I encourage you to try playing the game yourself, but if you don’t here is a sample game: 1 *Main Card RandomizedList Table> main 2 Start a game of Blackjack. Besides yourself, how many other 3 players do you want at the table? 4 1 5 6 Current table data: 7 Chipstacks: 8 Player: 500 9 Other players: [500] 10 User cards: [Card {rank = Three, suit = Clubs},Card {rank = Two, suit = Hearts}] 11 Dealer cards: [Card {rank = Queen, suit = Diamonds},Card {rank = Seven, suit = Clu\ 12 bs}] 13 Other player's cards: [[Card {rank = King, suit = Hearts},Card {rank = Six, suit =\ 14 Diamonds}]] 15 Dealt card values: [[3,2],[10,7],[10,6]] 16 Current player bet: 20 17 Player pass: False 18 Haskell Program to Play the Blackjack Card Game 129 19 Enter command: h)it or set bet to 10, 20, 30; any other key to stay: 20 h 21 22 Current table data: 23 Chipstacks: 24 Player: 500 25 Other players: [500] 26 User cards: [Card {rank = Six, suit = Hearts},Card {rank = Three, suit = Clubs},Ca\ 27 rd {rank = Two, suit = Hearts}] 28 Dealer cards: [Card {rank = Queen, suit = Diamonds},Card {rank = Seven, suit = Clu\ 29 bs}] 30 Other player's cards: [[Card {rank = Eight, suit = Hearts},Card {rank = King, suit\ 31 = Hearts},Card {rank = Six, suit = Diamonds}]] 32 Dealt card values: [[6,3,2],[10,7],[8,10,6]] 33 Current player bet: 20 34 Player pass: False 35 36 Enter command: h)it or set bet to 10, 20, 30; any other key to stay: 37 h 38 39 Current table data: 40 Chipstacks: 41 Player: 500 42 Other players: [500] 43 User cards: [Card {rank = King, suit = Clubs},Card {rank = Six, suit = Hearts},Car\ 44 d {rank = Three, suit = Clubs},Card {rank = Two, suit = Hearts}] 45 Dealer cards: [Card {rank = Queen, suit = Diamonds},Card {rank = Seven, suit = Clu\ 46 bs}] 47 Other player's cards: [[Card {rank = Eight, suit = Hearts},Card {rank = King, suit\ 48 = Hearts},Card {rank = Six, suit = Diamonds}]] 49 Dealt card values: [[10,6,3,2],[10,7],[8,10,6]] 50 Current player bet: 20 51 Player pass: False 52 53 Enter command: h)it or set bet to 10, 20, 30; any other key to stay: 54 55 Current table data: 56 Chipstacks: 57 Player: 500 58 Other players: [500] 59 User cards: [Card {rank = King, suit = Clubs},Card {rank = Six, suit = Hearts},Car\ 60 d {rank = Three, suit = Clubs},Card {rank = Two, suit = Hearts}] 61 Dealer cards: [Card {rank = Queen, suit = Diamonds},Card {rank = Seven, suit = Clu\ Haskell Program to Play the Blackjack Card Game 130 62 bs}] 63 Other player's cards: [[Card {rank = Eight, suit = Hearts},Card {rank = King, suit\ 64 = Hearts},Card {rank = Six, suit = Diamonds}]] 65 Dealt card values: [[10,6,3,2],[10,7],[8,10,6]] 66 Current player bet: 20 67 Player pass: True 68 69 Hand over. State of table at the end of the game: 70 71 Current table data: 72 Chipstacks: 73 Player: 520 74 Other players: [520] 75 User cards: [Card {rank = King, suit = Clubs},Card {rank = Six, suit = Hearts},Car\ 76 d {rank = Three, suit = Clubs},Card {rank = Two, suit = Hearts}] 77 Dealer cards: [Card {rank = Queen, suit = Diamonds},Card {rank = Seven, suit = Clu\ 78 bs}] 79 Other player's cards: [[Card {rank = Eight, suit = Hearts},Card {rank = King, suit\ 80 = Hearts},Card {rank = Six, suit = Diamonds}]] 81 Dealt card values: [[10,6,3,2],[10,7],[8,10,6]] 82 Current player bet: 20 83 Player pass: True Here the game user has four cards with values of [10,6,3,2] for a winning score of 21. The dealer has [10,7] for a score of 17 and the other player has [8,10,6], a value greater than 21 so the player went “bust.” I hope that you enjoyed this last example that demonstrates a reasonable approach for managing state when using immutable data. Section 3 - Larger Projects This section is new for the second edition of this book. So far we have covered the basics of Haskell programming and seen many examples. In this section we look at a few new projects that I derived from my own work and these new examples will hopefully further encourage you to think of novel uses for Haskell in your own work. The project knowledge_graph_creator helps to automate the process of creating Knowledge Graphs from raw text input and generates data for both the Neo4J open source graph database as well as RDF data for use in semantic web and linked data applications. I have also implemented this same application in Common Lisp that is also a new example in the latest edition of my book Loving Common Lisp, Or The Savvy Programmer’s Secret Weapon³⁸ (released September 2019). The next two chapters in this section are similar in that they both use examples of using Python for Natural Language Processing (NLP) tasks, wrapping the Python code as a REST service, and then writing Haskell clients for these services. The project HybridHaskellPythonNlp uses web services written in Python for natural language processing. The Python web services use the SpaCy library. The project HybridHaskellPythonCorefAnaphoraResolution uses web services written in Python to allow Haskell applications to use deep learning models created with TensorFlow and Keras. In these last two examples I use REST APIs to access code written in Python. A good alternative that I don’t cover in this book is using the servant library³⁹ for generating distributed applications. ³⁸https://leanpub.com/lovinglisp ³⁹https://www.servant.dev/ Knowledge Graph Creator The large project described here processes raw text inputs and generates data for knowledge graphs in formats for both the Neo4J graph database and in RDF format for semantic web and linked data applications. This application works by identifying entities in text. Example entity types are people, companies, country names, city names, broadcast network names, political party names, and university names. We saw earlier code for detecting entities in the chapter on natural language processing (NLP) and we will reuse this code. We will discuss later three strategies for reusing code from different projects. The following figure shows part of a Neo4J Knowledge Graph created with the example code. This graph has shortened labels in displayed nodes but Neo4J offers a web browser-based console that lets you interactively explore Knowledge Graphs. We don’t cover setting up Neo4J here so please use the Neo4J documentation⁴⁰. As an introduction to RDF data, the semantic web, and linked data you can get free copies of my two books Practical Semantic Web and Linked Data Applications, Common Lisp Edition⁴¹ and Practical Semantic Web and Linked Data Applications, Java, Scala, Clojure, and JRuby Edition⁴². Part of a Knowledge Graph shown in Neo4J web application console There are two versions of this project that deal with generating duplicate data in two ways: • As either Neo4J Cypher data or RDF triples data are created, store generated data in a SQLite embedded database. Check this database before writing new output data. • Ignore the problem of generating duplicate data and filter out duplicates in the outer processing pipeline that uses the Knowledge Graph Creator as one processing step. ⁴⁰https://neo4j.com/docs/operations-manual/current/introduction/ ⁴¹http://markwatson.com/opencontentdata/book_lisp.pdf ⁴²http://markwatson.com/opencontentdata/book_java.pdf Knowledge Graph Creator 133 For my own work I choose the second method since filtering duplicates is as easy as a few Makefile targets (the following listing is in the file Makefile in the directory haskell_tutorial_cookbook_- examples/knowledge_graph_creator_pure): all: gendata rdf cypher gendata: stack build --fast --exec Dev-exe rdf: echo "Removing duplicate RDF statements" awk '!visited[$$0]++' out.n3 > output.n3 rm -f out.n3 cypher: echo "Removing duplicate Cypher statements" awk '!visited[$$0]++' out.cypher > output.cypher rm -f out.cypher The Haskell KGCreator application we develop here writes output files out.n3 (N3 is a RDF data format) and out.cypher (Cypher is the import output format and query language for the Neo4J open source and commercial graph database). The awk commands remove duplicate lines and write de- duplicated data to output.n3 and output.cypher. We will use this second approach but the next section provides sufficient information and a link to alternative code in case you are interested in using SQLite to prevent duplicate data generation. Notes for Using SQLite to Avoid Duplicates (Optional Material) We saw two methods of avoiding duplicates in generated data in the last section. If you want to use the first method for avoiding generating duplicate data, I leave it as an exercise but here are some notes to get you started: you can then modify the example code by using the utility function Blackboard.h in the directory knowledge_graph_creator_pure/src/fileutils and implement the logic seen below for checking new generated data to see if it is in the SQLite database. This first method as it also is a good example for wrapping the embedded SQLite library in an IO Monad and is left as an exercise, otherwise skip this section. Before you write either an RDF statement or a Neo4J Cypher data import statement, check to see if the statement has already been written using something like: Knowledge Graph Creator 134 check <- blackboard_check_key new_data_uri if check .... and after writing a RDF statement or a Neo4J Cypher data import statement, write it to the temportary SQLite database using something like: blackboard_write newStatementString For the rest of the chapter we will use the approach of not keeping track of generated data in SQLite and instead remove duplicates during postprocessing using the standard awk command line utility. This section is optional. In the rest of this chapter we use the example code in knowledge_graph_- creator_pure. Code Layout For the KGCreator Project and strategies for sharing Haskell code between projects We will reuse the code for finding entities that we studied in an earlier chapter. There are several ways to reuse code from multiple local Haskell projects: • In a project’s cabal file, use relative paths to the source code for other projects. This is my preferred way to work but has the drawback that the stack command sdist to make a distribution tarball will not work with relative paths. If this is a problem for you then create relative symbolic file links to the source directories in other projects. • In your project’s stack.yaml file, add the other project’s name and path as a extra-deps. • In library projects, define a packages definition and install the library globally on your system. I almost always use the first method on my projects with dependencies on other local projects I work on and this is also the approach we use here. The relevant lines in the file KGCreator.cabal are: 1 library 2 exposed-modules: 3 CorefWebClient 4 NlpWebClient 5 ClassificationWebClient 6 DirUtils 7 FileUtils 8 BlackBoard 9 GenTriples 10 GenNeo4jCypher Knowledge Graph Creator 135 11 Apis 12 Categorize 13 NlpUtils 14 Summarize 15 Entities 16 other-modules: 17 Paths_KGCreator 18 BroadcastNetworkNamesDbPedia 19 Category1Gram 20 Category2Gram 21 CityNamesDbpedia 22 CompanyNamesDbpedia 23 CountryNamesDbpedia 24 PeopleDbPedia 25 PoliticalPartyNamesDbPedia 26 Sentence 27 Stemmer 28 TradeUnionNamesDbPedia 29 UniversityNamesDbPedia 30 31 hs-source-dirs: 32 src 33 src/webclients 34 src/fileutils 35 src/sw 36 src/toplevel 37 ../NlpTool/src/nlp 38 ../NlpTool/src/nlp/data This is a standard looking cabal file except for lines 37 and 38 where the source paths reference the example code for the NlpTool application developed in a previous chapter. The exposed module BlackBoard (line 8) is not used but I leave it in the cabal file in case you want to experiment with recording generated data in SQLite to avoid data duplication. You are likely to also want to use BlackBoard if you modify this example to continuously process incoming data in a production system. This is left as an exercise. Before going into too much detail on the implementation let’s look at the layout of the project code: Knowledge Graph Creator 136 1 src/fileutils: 2 BlackBoard.hs DirUtils.hs FileUtils.hs 3 4 ../NlpTool/src/nlp: 5 Categorize.hs Entities.hs NlpUtils.hs Sentence.hs Stemmer.hs Summ 6 7 ../NlpTool/src/nlp/data: 8 BroadcastNetworkNamesDbPedia.hs CompanyNamesDbpedia.hs TradeUnionNamesDbPedia 9 Category1Gram.hs CountryNamesDbpedia.hs UniversityNamesDbPedia.hs 10 Category2Gram.hs PeopleDbPedia.hs 11 CityNamesDbpedia.hs PoliticalPartyNamesDbPedia.hs 12 13 src/sw: 14 GenNeo4jCypher.hs GenTriples.hs 15 16 src/toplevel: 17 Apis.hs As mentioned before, we are using the Haskell source fies in a relative path ../NlpTool/src/… and the local src directory. We discuss this code in the next few sections. The Main Event: Detecting Entities in Text A primary task in KGCreator is to identify entities (people, places, etc.) in text and then we will create RDF and Neo4J Cypher data statements using these entities, knowledge of the origin of text data and general relationships between entities. We will use the top level code that we developed earlier that is located in the directory ../NlpTool/s- rc/nlp (please see the chapter Natural Language Processing Tools for more detail): • Categorize.hs - categorizes text into categories like news, religion, business, politics, science, etc. • Entities.hs - identifies entities like people, companies, places, new broadcast networks, labor unions, etc. in text • Summarize.hs - creates an extractive summary of text The KGCreator Haskell application looks in a specified directory for text files to process. For each file with a .txt extension there should be a matching file with the extension .meta that contains a single line: the URI of the web location where the corresponding text was found. The reason we need this is that we want to create graph knowledge data from information found in text sources and the original location of the data is important to preserve. In other words, we want to know where the data elements in our knowledge graph came from. Knowledge Graph Creator 137 We have not looked at an example of using command line arguments yet so let’s go into some detail on how we do this. Previously when we have defined an output target executable in our .cabal file, in this case KGCreator-exe, we could use stack to build the executable and run it with: stack build --fast --exec KGCreator-exe" Now, we have an executable that requires two arguments: a source input directory and the file root for generated RDF and Cypher output files. We can pass command line arguments using this notation: stack build --fast --exec "KGCreator-exe test_data outtest" The two command line arguments are: • test_data which is the file path of a local directory containing the input files • outtest which is the root file name for generated Neo4J Cypher and RDF output files If you are using KGCreator in production, then you will want to copy the compiled and linked executable file KGCreator-exe to somewhere on your PATH like /usr/local/bin. The following listing shows the file app/Main.hs, the main program for this example that handles command line arguments and calls two top level functions in src/toplevel/Apis.hs: 1 module Main where 2 3 import System.Environment (getArgs) 4 import Apis (processFilesToRdf, processFilesToNeo4j) 5 6 main :: IO () 7 main = do 8 args <- getArgs 9 case args of 10 [] -> error "must supply an input directory containing text and meta files" 11 [_] -> error "in addition to an input directory, also specify a root file name f\ 12 or the generated RDF and Cypher files" 13 [inputDir, outputFileRoot] -> do 14 processFilesToRdf inputDir $ outputFileRoot ++ ".n3" 15 processFilesToNeo4j inputDir $ outputFileRoot ++ ".cypher" 16 _ -> error "too many arguments" Here we use getArgs in line8 to fetch a list of command line arguments and verify that at least two arguments have been provided. Then we call the functions processFilesToRdf and processFilesToNeo4j and the functions they call in the next three sections. Knowledge Graph Creator 138 Utility Code for Generating RDF The code for generating RDF and for generating Neo4J Cypher data is similar. We start with the code to generate RDF triples. Before we look at the code, let’s start with a few lines of generated RDF: <http://dbpedia.org/resource/The_Wall_Street_Journal> <http://knowledgebooks.com/schema/aboutCompanyName> "Wall Street Journal" . <https://newsshop.com/june/z902.html> <http://knowledgebooks.com/schema/containsCountryDbPediaLink> <http://dbpedia.org/resource/Canada> . The next listing shows the file src/sw/GenTriples.hs that finds entities like broadcast network names, city names, company names, people’s names, political party names, and university names in text and generates RDF triple data. If you need to add more entity types for your own applications, then use the following steps: • Look at the format of entity data for the NlpTool example and add names for the new entity type you are adding. • Add a utility function to find instances of the new entity type to NlpTools. For example, if you are adding a new entity type “park names”, then copy the code for companyNames to parkNames, modify as necessary, and export parkNames. • In the following code, add new code for the new entity helper function after lines 10, 97, 151, and 261. Use the code for companyNames as an example. The map *category_to_uri_map** created in lines 36 to 84 maps a topic name to a linked Data URI that describes the topic. For example, we would not refer to an information source as being about the topic “economics”, but would instead refer to a linked data URI like http://knowledgebooks. com/schema/topic/economics. The utility function uri_from_categor takes a text description of a topic like “economy” and converts it to an appropriate URI using the map *category_to_uri_map**. The utility function textToTriple takes a file path to a text input file and a path to meta file path, calculates the text string representing the generated triples for the input text file, and returns the result wrapped in an IO monad. Knowledge Graph Creator 139 1 module GenTriples 2 ( textToTriples 3 , category_to_uri_map 4 ) where 5 6 import Categorize (bestCategories) 7 import Entities 8 ( broadcastNetworkNames 9 , cityNames 10 , companyNames 11 , countryNames 12 , peopleNames 13 , politicalPartyNames 14 , tradeUnionNames 15 , universityNames 16 ) 17 import FileUtils 18 ( MyMeta 19 , filePathToString 20 , filePathToWordTokens 21 , readMetaFile 22 , uri 23 ) 24 import Summarize (summarize, summarizeS) 25 26 import qualified Data.Map as M 27 import Data.Maybe (fromMaybe) 28 29 generate_triple :: [Char] -> [Char] -> [Char] -> [Char] 30 generate_triple s p o = s ++ " " ++ p ++ " " ++ o ++ " .\n" 31 32 make_literal :: [Char] -> [Char] 33 make_literal s = "\"" ++ s ++ "\"" 34 35 category_to_uri_map :: M.Map [Char] [Char] 36 category_to_uri_map = 37 M.fromList 38 [ ("news_weather", "<http://knowledgebooks.com/schema/topic/weather>") 39 , ("news_war", "<http://knowledgebooks.com/schema/topic/war>") 40 , ("economics", "<http://knowledgebooks.com/schema/topic/economics>") 41 , ("news_economy", "<http://knowledgebooks.com/schema/topic/economics>") 42 , ("news_politics", "<http://knowledgebooks.com/schema/topic/politics>") 43 , ("religion", "<http://knowledgebooks.com/schema/topic/religion>") Knowledge Graph Creator 140 44 , ( "religion_buddhism" 45 , "<http://knowledgebooks.com/schema/topic/religion/buddhism>") 46 , ( "religion_islam" 47 , "<http://knowledgebooks.com/schema/topic/religion/islam>") 48 , ( "religion_christianity" 49 , "<http://knowledgebooks.com/schema/topic/religion/christianity>") 50 , ( "religion_hinduism" 51 , "<http://knowledgebooks.com/schema/topic/religion/hinduism>") 52 , ( "religion_judaism" 53 , "<http://knowledgebooks.com/schema/topic/religion/judaism>") 54 , ("chemistry", "<http://knowledgebooks.com/schema/topic/chemistry>") 55 , ("computers", "<http://knowledgebooks.com/schema/topic/computers>") 56 , ("computers_ai", "<http://knowledgebooks.com/schema/topic/computers/ai>") 57 , ( "computers_ai_datamining" 58 , "<http://knowledgebooks.com/schema/topic/computers/ai/datamining>") 59 , ( "computers_ai_learning" 60 , "<http://knowledgebooks.com/schema/topic/computers/ai/learning>") 61 , ( "computers_ai_nlp" 62 , "<http://knowledgebooks.com/schema/topic/computers/ai/nlp>") 63 , ( "computers_ai_search" 64 , "<http://knowledgebooks.com/schema/topic/computers/ai/search>") 65 , ( "computers_ai_textmining" 66 , "<http://knowledgebooks.com/schema/topic/computers/ai/textmining>") 67 , ( "computers/programming" 68 , "<http://knowledgebooks.com/schema/topic/computers/programming>") 69 , ( "computers_microsoft" 70 , "<http://knowledgebooks.com/schema/topic/computers/microsoft>") 71 , ( "computers/programming/ruby" 72 , "<http://knowledgebooks.com/schema/topic/computers/programming/ruby>") 73 , ( "computers/programming/lisp" 74 , "<http://knowledgebooks.com/schema/topic/computers/programming/lisp>") 75 , ("health", "<http://knowledgebooks.com/schema/topic/health>") 76 , ( "health_exercise" 77 , "<http://knowledgebooks.com/schema/topic/health/exercise>") 78 , ( "health_nutrition" 79 , "<http://knowledgebooks.com/schema/topic/health/nutrition>") 80 , ("mathematics", "<http://knowledgebooks.com/schema/topic/mathematics>") 81 , ("news_music", "<http://knowledgebooks.com/schema/topic/music>") 82 , ("news_physics", "<http://knowledgebooks.com/schema/topic/physics>") 83 , ("news_sports", "<http://knowledgebooks.com/schema/topic/sports>") 84 ] 85 86 uri_from_category :: [Char] -> [Char] Knowledge Graph Creator 141 87 uri_from_category key = 88 fromMaybe ("\"" ++ key ++ "\"") $ M.lookup key category_to_uri_map 89 90 textToTriples :: FilePath -> [Char] -> IO [Char] 91 textToTriples file_path meta_file_path = do 92 word_tokens <- filePathToWordTokens file_path 93 contents <- filePathToString file_path 94 putStrLn $ "** contents:\n" ++ contents ++ "\n" 95 meta_data <- readMetaFile meta_file_path 96 let people = peopleNames word_tokens 97 let companies = companyNames word_tokens 98 let countries = countryNames word_tokens 99 let cities = cityNames word_tokens 100 let broadcast_networks = broadcastNetworkNames word_tokens 101 let political_parties = politicalPartyNames word_tokens 102 let trade_unions = tradeUnionNames word_tokens 103 let universities = universityNames word_tokens 104 let a_summary = summarizeS contents 105 let the_categories = bestCategories word_tokens 106 let filtered_categories = 107 map (uri_from_category . fst) $ 108 filter (\(name, value) -> value > 0.3) the_categories 109 putStrLn "\nfiltered_categories:" 110 print filtered_categories 111 --putStrLn "a_summary:" 112 --print a_summary 113 --print $ summarize contents 114 115 let summary_triples = 116 generate_triple 117 (uri meta_data) 118 "<http://knowledgebooks.com/schema/summaryOf>" $ 119 "\"" ++ a_summary ++ "\"" 120 let category_triples = 121 concat 122 [ generate_triple 123 (uri meta_data) 124 "<http://knowledgebooks.com/schema/news/category/>" 125 cat 126 | cat <- filtered_categories 127 ] 128 let people_triples1 = 129 concat Knowledge Graph Creator 142 130 [ generate_triple 131 (uri meta_data) 132 "<http://knowledgebooks.com/schema/containsPersonDbPediaLink>" 133 (snd pair) 134 | pair <- people 135 ] 136 let people_triples2 = 137 concat 138 [ generate_triple 139 (snd pair) 140 "<http://knowledgebooks.com/schema/aboutPersonName>" 141 (make_literal (fst pair)) 142 | pair <- people 143 ] 144 let company_triples1 = 145 concat 146 [ generate_triple 147 (uri meta_data) 148 "<http://knowledgebooks.com/schema/containsCompanyDbPediaLink>" 149 (snd pair) 150 | pair <- companies 151 ] 152 let company_triples2 = 153 concat 154 [ generate_triple 155 (snd pair) 156 "<http://knowledgebooks.com/schema/aboutCompanyName>" 157 (make_literal (fst pair)) 158 | pair <- companies 159 ] 160 let country_triples1 = 161 concat 162 [ generate_triple 163 (uri meta_data) 164 "<http://knowledgebooks.com/schema/containsCountryDbPediaLink>" 165 (snd pair) 166 | pair <- countries 167 ] 168 let country_triples2 = 169 concat 170 [ generate_triple 171 (snd pair) 172 "<http://knowledgebooks.com/schema/aboutCountryName>" Knowledge Graph Creator 143 173 (make_literal (fst pair)) 174 | pair <- countries 175 ] 176 let city_triples1 = 177 concat 178 [ generate_triple 179 (uri meta_data) 180 "<http://knowledgebooks.com/schema/containsCityDbPediaLink>" 181 (snd pair) 182 | pair <- cities 183 ] 184 let city_triples2 = 185 concat 186 [ generate_triple 187 (snd pair) 188 "<http://knowledgebooks.com/schema/aboutCityName>" 189 (make_literal (fst pair)) 190 | pair <- cities 191 ] 192 let bnetworks_triples1 = 193 concat 194 [ generate_triple 195 (uri meta_data) 196 "<http://knowledgebooks.com/schema/containsBroadCastDbPediaLink>" 197 (snd pair) 198 | pair <- broadcast_networks 199 ] 200 let bnetworks_triples2 = 201 concat 202 [ generate_triple 203 (snd pair) 204 "<http://knowledgebooks.com/schema/aboutBroadCastName>" 205 (make_literal (fst pair)) 206 | pair <- broadcast_networks 207 ] 208 let pparties_triples1 = 209 concat 210 [ generate_triple 211 (uri meta_data) 212 "<http://knowledgebooks.com/schema/containsPoliticalPartyDbPediaLink>" 213 (snd pair) 214 | pair <- political_parties 215 ] Knowledge Graph Creator 144 216 let pparties_triples2 = 217 concat 218 [ generate_triple 219 (snd pair) 220 "<http://knowledgebooks.com/schema/aboutPoliticalPartyName>" 221 (make_literal (fst pair)) 222 | pair <- political_parties 223 ] 224 let unions_triples1 = 225 concat 226 [ generate_triple 227 (uri meta_data) 228 "<http://knowledgebooks.com/schema/containsTradeUnionDbPediaLink>" 229 (snd pair) 230 | pair <- trade_unions 231 ] 232 let unions_triples2 = 233 concat 234 [ generate_triple 235 (snd pair) 236 "<http://knowledgebooks.com/schema/aboutTradeUnionName>" 237 (make_literal (fst pair)) 238 | pair <- trade_unions 239 ] 240 let universities_triples1 = 241 concat 242 [ generate_triple 243 (uri meta_data) 244 "<http://knowledgebooks.com/schema/containsUniversityDbPediaLink>" 245 (snd pair) 246 | pair <- universities 247 ] 248 let universities_triples2 = 249 concat 250 [ generate_triple 251 (snd pair) 252 "<http://knowledgebooks.com/schema/aboutTradeUnionName>" 253 (make_literal (fst pair)) 254 | pair <- universities 255 ] 256 return $ 257 concat 258 [ people_triples1 Knowledge Graph Creator 145 259 , people_triples2 260 , company_triples1 261 , company_triples2 262 , country_triples1 263 , country_triples2 264 , city_triples1 265 , city_triples2 266 , bnetworks_triples1 267 , bnetworks_triples2 268 , pparties_triples1 269 , pparties_triples2 270 , unions_triples1 271 , unions_triples2 272 , universities_triples1 273 , universities_triples2 274 , category_triples 275 , summary_triples 276 ] The code in this file could be shortened but having repetitive code for each entity type hopefully makes it easier for you to understand how it works. Utility Code for Generating Cypher Input Data for Neo4J Now we will generate Neo4J Cypher data. In order to keep the implementation simple, both the RDF and Cypher generation code starts with raw text and performs the NLP analysis to find entities. This example could be refactored to perform the NLP analysis just one time but in practice you will likely be working with either RDF or NEO4J and so you will probably extract just the code you need from this example (i.e., either the RDF or Cypher generation code). Before we look at the code, let’s start with a few lines of generated Neo4J Cypher import data: Knowledge Graph Creator 146 CREATE (newsshop_com_june_z902_html_news)-[:ContainsCompanyDbPediaLink]->(Wall_Stree\ t_Journal) CREATE (Canada:Entity {name:"Canada", uri:"<http://dbpedia.org/resource/Canada>"}) CREATE (newsshop_com_june_z902_html_news)-[:ContainsCountryDbPediaLink]->(Canada) CREATE (summary_of_abcnews_go_com_US_violent_long_lasting_tornadoes_threaten_oklahom\ a_texas_storyid63146361:Summary {name:"summary_of_abcnews_go_com_US_violent_long_las\ ting_tornadoes_threaten_oklahoma_texas_storyid63146361", uri:"<https://abcnews.go.co\ m/US/violent-long-lasting-tornadoes-threaten-oklahoma-texas/story?id=63146361>", sum\ mary:"Part of the system that delivered severe weather to the central U.S. over the \ weekend is moving into the Northeast today, producing strong to severe storms -- dam\ aging winds, hail or isolated tornadoes can't be ruled out. Severe weather is foreca\ st to continue on Tuesday, with the western storm moving east into the Midwest and p\ arts of the mid-Mississippi Valley."}) The following listing shows the file src/sw/GenNeo4jCypher.hs. This code is very similar to the code for generating RDF in the last section. The same notes for adding your own new entity notes in the last section are also relevant here. Notice that we import in line 29 the map category_to_uri_map that was defined in the last section. The function neo4j_category_node_defs defined in lines 35 to 43 creates category graph nodes for each category in the map category_to_uri_map. These nodes will be referenced by graph nodes created in the functions create_neo4j_node, create_neo4j_lin, create_summary_node, and create_entity_node. The top level function is textToCypher that is similar to the function textToTriples in the last section. 1 {-# LANGUAGE OverloadedStrings #-} 2 3 module GenNeo4jCypher 4 ( textToCypher 5 , neo4j_category_node_defs 6 ) where 7 8 import Categorize (bestCategories) 9 import Data.List (isInfixOf) 10 import Data.Char (toLower) 11 import Data.String.Utils (replace) 12 import Entities 13 ( broadcastNetworkNames 14 , cityNames 15 , companyNames 16 , countryNames 17 , peopleNames 18 , politicalPartyNames Knowledge Graph Creator 147 19 , tradeUnionNames 20 , universityNames 21 ) 22 import FileUtils 23 ( MyMeta 24 , filePathToString 25 , filePathToWordTokens 26 , readMetaFile 27 , uri 28 ) 29 import GenTriples (category_to_uri_map) 30 import Summarize (summarize, summarizeS) 31 32 import qualified Data.Map as M 33 import Data.Maybe (fromMaybe) 34 import Database.SQLite.Simple 35 36 -- for debug: 37 import Data.Typeable (typeOf) 38 39 neo4j_category_node_defs :: [Char] 40 neo4j_category_node_defs = 41 replace 42 "/" 43 "_" 44 $ concat 45 [ "CREATE (" ++ c ++ ":CategoryType {name:\"" ++ c ++ "\"})\n" 46 | c <- M.keys category_to_uri_map 47 ] 48 49 uri_from_category :: p -> p 50 uri_from_category s = s -- might want the full version from GenTriples 51 52 repl :: Char -> Char 53 repl '-' = '_' 54 repl '/' = '_' 55 repl '.' = '_' 56 repl c = c 57 58 filterChars :: [Char] -> [Char] 59 filterChars = filter (\c -> c /= '?' && c /= '=' && c /= '<' && c /= '>') 60 61 create_neo4j_node :: [Char] -> ([Char], [Char]) Knowledge Graph Creator 148 62 create_neo4j_node uri = 63 let name = 64 (map repl (filterChars 65 (replace "https://" "" (replace "http://" "" uri)))) ++ 66 "_" ++ 67 (map toLower node_type) 68 node_type = 69 if isInfixOf "dbpedia" uri 70 then "DbPedia" 71 else "News" 72 new_node = 73 "CREATE (" ++ 74 name ++ ":" ++ 75 node_type ++ " {name:\"" ++ (replace " " "_" name) ++ 76 "\", uri:\"" ++ uri ++ "\"})\n" 77 in (name, new_node) 78 79 create_neo4j_link :: [Char] -> [Char] -> [Char] -> [Char] 80 create_neo4j_link node1 linkName node2 = 81 "CREATE (" ++ node1 ++ ")-[:" ++ linkName ++ "]->(" ++ node2 ++ ")\n" 82 83 create_summary_node :: [Char] -> [Char] -> [Char] 84 create_summary_node uri summary = 85 let name = 86 "summary_of_" ++ 87 (map repl $ 88 filterChars (replace "https://" "" (replace "http://" "" uri))) 89 s1 = "CREATE (" ++ name ++ ":Summary {name:\"" ++ name ++ "\", uri:\"" 90 s2 = uri ++ "\", summary:\"" ++ summary ++ "\"})\n" 91 in s1 ++ s2 92 93 create_entity_node :: ([Char], [Char]) -> [Char] 94 create_entity_node entity_pair = 95 "CREATE (" ++ (replace " " "_" (fst entity_pair)) ++ 96 ":Entity {name:\"" ++ (fst entity_pair) ++ "\", uri:\"" ++ 97 (snd entity_pair) ++ "\"})\n" 98 99 create_contains_entity :: [Char] -> [Char] -> ([Char], [Char]) -> [Char] 100 create_contains_entity relation_name source_uri entity_pair = 101 let new_person_node = create_entity_node entity_pair 102 new_link = create_neo4j_link source_uri 103 relation_name 104 (replace " " "_" (fst entity_pair)) Knowledge Graph Creator 149 105 in 106 (new_person_node ++ new_link) 107 108 entity_node_helper :: [Char] -> [Char] -> [([Char], [Char])] -> [Char] 109 entity_node_helper relation_name node_name entity_list = 110 concat [create_contains_entity 111 relation_name node_name entity | entity <- entity_list] 112 113 textToCypher :: FilePath -> [Char] -> IO [Char] 114 textToCypher file_path meta_file_path = do 115 let prelude_nodes = neo4j_category_node_defs 116 putStrLn "+++++++++++++++++ prelude node defs:" 117 print prelude_nodes 118 word_tokens <- filePathToWordTokens file_path 119 contents <- filePathToString file_path 120 putStrLn $ "** contents:\n" ++ contents ++ "\n" 121 meta_data <- readMetaFile meta_file_path 122 putStrLn "++ meta_data:" 123 print meta_data 124 let people = peopleNames word_tokens 125 let companies = companyNames word_tokens 126 putStrLn "^^^^ companies:" 127 print companies 128 let countries = countryNames word_tokens 129 let cities = cityNames word_tokens 130 let broadcast_networks = broadcastNetworkNames word_tokens 131 let political_parties = politicalPartyNames word_tokens 132 let trade_unions = tradeUnionNames word_tokens 133 let universities = universityNames word_tokens 134 let a_summary = summarizeS contents 135 let the_categories = bestCategories word_tokens 136 let filtered_categories = 137 map (uri_from_category . fst) $ 138 filter (\(name, value) -> value > 0.3) the_categories 139 putStrLn "\nfiltered_categories:" 140 print filtered_categories 141 let (node1_name, node1) = create_neo4j_node (uri meta_data) 142 let summary1 = create_summary_node (uri meta_data) a_summary 143 let category1 = 144 concat 145 [ create_neo4j_link node1_name "Category" cat 146 | cat <- filtered_categories 147 ] Knowledge Graph Creator 150 148 let pp = entity_node_helper "ContainsPersonDbPediaLink" node1_name people 149 let cmpny = entity_node_helper "ContainsCompanyDbPediaLink" node1_name companies 150 let cntry = entity_node_helper "ContainsCountryDbPediaLink" node1_name countries 151 let citys = entity_node_helper "ContainsCityDbPediaLink" node1_name cities 152 let bnet = entity_node_helper "ContainsBroadcastNetworkDbPediaLink" 153 node1_name broadcast_networks 154 let ppart = entity_node_helper "ContainsPoliticalPartyDbPediaLink" 155 node1_name political_parties 156 let tunion = entity_node_helper "ContainsTradeUnionDbPediaLink" 157 node1_name trade_unions 158 let uni = entity_node_helper "ContainsUniversityDbPediaLink" 159 node1_name universities 160 return $ concat [node1, summary1, category1, pp, cmpny, cntry, citys, bnet, 161 ppart, tunion, uni] Because the top level function is textToCypher returns a string wrapped in a monad, it is possible to add “debug”” print statements in textToCypher. I left many such debug statements in the example code to help you understand the data that is being operated on. I leave it as an exercise to remove these print statements if you use this code in your own projects and no longer need to see the debug output. Top Level API Code for Handling Knowledge Graph Data Generation So far we have looked at processing command line arguments and processing individual input files. Now we look at higher level utility APIs for processing an entire directory of input files. The following listing shows the file API.hs that contains the two top level helper functions we saw in app/Main.hs. The functions processFilesToRdf and processFilesToNeo4j both have the function type signature FilePath->FilePath->IO() and are very similar except for calling different helper functions to generate RDF triples or Cypher input graph data: Knowledge Graph Creator 151 1 module Apis 2 ( processFilesToRdf 3 , processFilesToNeo4j 4 ) where 5 6 import FileUtils 7 import GenNeo4jCypher 8 import GenTriples (textToTriples) 9 10 import qualified Database.SQLite.Simple as SQL 11 12 import Control.Monad (mapM) 13 import Data.String.Utils (replace) 14 import System.Directory (getDirectoryContents) 15 16 import Data.Typeable (typeOf) 17 18 processFilesToRdf :: FilePath -> FilePath -> IO () 19 processFilesToRdf dirPath outputRdfFilePath = do 20 files <- getDirectoryContents dirPath :: IO [FilePath] 21 let filtered_files = filter isTextFile files 22 let full_paths = [dirPath ++ "/" ++ fn | fn <- filtered_files] 23 putStrLn "full_paths:" 24 print full_paths 25 let r = 26 [textToTriples fp1 (replace ".txt" ".meta" fp1) 27 | 28 fp1 <- full_paths] :: [IO [Char]] 29 tripleL <- 30 mapM (\fp -> textToTriples fp (replace ".txt" ".meta" fp)) full_paths 31 let tripleS = concat tripleL 32 putStrLn tripleS 33 writeFile outputRdfFilePath tripleS 34 35 processFilesToNeo4j :: FilePath -> FilePath -> IO () 36 processFilesToNeo4j dirPath outputRdfFilePath = do 37 files <- getDirectoryContents dirPath :: IO [FilePath] 38 let filtered_files = filter isTextFile files 39 let full_paths = [dirPath ++ "/" ++ fn | fn <- filtered_files] 40 putStrLn "full_paths:" 41 print full_paths 42 let prelude_node_defs = neo4j_category_node_defs 43 putStrLn Knowledge Graph Creator 152 44 ("+++++ type of prelude_node_defs is: " ++ 45 (show (typeOf prelude_node_defs))) 46 print prelude_node_defs 47 cypher_dataL <- 48 mapM (\fp -> textToCypher fp (replace ".txt" ".meta" fp)) full_paths 49 let cypher_dataS = concat cypher_dataL 50 putStrLn cypher_dataS 51 writeFile outputRdfFilePath $ prelude_node_defs ++ cypher_dataS Since both of these functions return IO monads, I could add “debug” print statements that should be helpful in understanding the data being operated on. Wrapup for Automating the Creation of Knowledge Graphs The code in this chapter will provide you with a good start for creating both test knowledge graphs and for generating data for production. In practice, generated data should be reviewed before use and additional data manually generated as needed. It is good practice to document required manual changes because this documentation can be used in the requirements for updating the code in this chapter to more closely match your knowledge graph requirements. Hybrid Haskell and Python Natural Language Processing Here we will write a Haskell client for using a Natural Language Processing (NLP) server written in Python. There is some common material in this chapter and the next chapter Hybrid Haskell and Python For Coreference Resolution because I wanted both chapters to be self contained. Example Use of the Haskell NLP Client Before learning how to use the Python NLP server code and understand the code for the Haskell client code, let’s look at an example of running the client code so you understand the type of processing that we are performing: 1 $ stack build --fast --exec HybridHaskellPythonNlp-exe 2 Enter text (all on one line) 3 John Smith went to Mexico to see the Pepsi plant 4 response from NLP server: 5 NlpResponse {entities = ["John Smith/PERSON","Mexico/GPE","Pepsi/ORG"], 6 tokens = ["John","Smith","went","to","Mexico","to","see","the","Pepsi",\ 7 "plant"]} 8 Enter text (all on one line) Notice on line 5 that each of the three entities is tagged with the entity type. GPE is the tag for a country and the tag ORG can refer to an entity that is a company or a non-profit organization. There is some overlap in functionality between the Python SpaCy NLP library and my pure Haskell code in the NLP Tools chapter. SpaCy has the advantage of using state of the art deep learning models. Setting up the Python NLP Server I assume that you have some familiarity with using Python. If not, you will still be able to follow these directions assuming that you have the utilities pip, and python installed. I recommend installing Python and Pip using Anaconda⁴³. ⁴³https://anaconda.org/anaconda/conda Hybrid Haskell and Python Natural Language Processing 154 The server code is in the subdirectory HybridHaskellPythonNlp/python_spacy_nlp_server where you will work when performing a one time initialization. After the server is installed you can then run it from the command line from any directory on your laptop. I recommend that you use virtual Python environments when using Python applications to separate the dependencies required for each application or development project. Here I assume that you are running in a Python version 3.6 (or higher) version environment. First install the dependencies: 1 pip install -U spacy 2 python -m spacy download en 3 pip install falcon Then change directory to the subdirectory HybridHaskellPythonNlp/python_spacy_nlp_server and install the NLP server: 1 cd HybridHaskellPythonNlp/python_spacy_nlp_server 2 python setup.py install Once you install the server, you can run it from any directory on your laptop or server using: 1 spacynlpserver I use deep learning models written in Python using TensorFlow or PyTorch in applications I write in Haskell or Common Lisp. While it is possible to directly embed models in Haskell and Common Lisp, I find it much easier and developer friendly to wrap deep learning models I use a REST services as I have done here. Often deep learning models only require about a gigabyte of memory and using pre-trained models has lightweight CPU resource needs so while I am developing on my laptop I might have two or three models running and available as wrapped REST services. For production, I configure both the Python services and my Haskell and Common Lisp applications to start automatically on system startup. This is not a Python programming book and I will not discuss the simple Python wrapping code but if you are also a Python developer you can easily read and understand the code. Understanding the Haskell NLP Client Code The Python server returns JSON file. We saw earlier the use of the Haskell aeson library for parsing JSON data stored as a string into Haskell native data. We also used the wreq library to access remote web services. We use both of these libraries here: Hybrid Haskell and Python Natural Language Processing 155 1 {-# LANGUAGE OverloadedStrings #-} 2 {-# LANGUAGE DeriveDataTypeable #-} 3 4 -- reference: http://www.serpentine.com/wreq/tutorial.html 5 module NlpWebClient 6 ( nlpClient, NlpResponse 7 ) where 8 9 import Control.Lens 10 import Data.ByteString.Lazy.Char8 (unpack) 11 import Data.Maybe (fromJust) 12 import Network.URI.Encode as E -- encode is also in Data.Aeson 13 import Network.Wreq 14 15 import Text.JSON.Generic 16 17 data NlpResponse = NlpResponse {entities::[String], tokens::[String]} deriving (Show\ 18 , Data, Typeable) 19 20 base_url = "http://127.0.0.1:8008?text=" 21 22 nlpClient :: [Char] -> IO NlpResponse 23 nlpClient query = do 24 putStrLn $ "\n\n*** Processing " ++ query 25 r <- get $ base_url ++ (E.encode query) ++ "&no_detail=1" 26 let ret = (decodeJSON (unpack (fromJust (r ^? responseBody)))) :: NlpResponse 27 return ret The main command line program for using the client library: module Main where import NlpWebClient main :: IO () main = do putStrLn "Enter text (all on one line)" s <- getLine response <- (nlpClient s) :: IO NlpResponse putStr "response from NLP server:\n" putStrLn $ show response main Hybrid Haskell and Python Natural Language Processing 156 Wrapup for Using the Python SpaCy NLP Service The example in this chapter shows a technique that I often use for using libraries and frameworks that are not written in Haskell: wrap the service implemented in another programming language is a REST web service. While it is possible to use a foreign function interface (FFI) to call out to code written in other languages I find for my own work that I prefer calling out to a separate service especially when I run other services on remote servers so I do not need to run them on my development laptop. For production it is also useful to be able to easily scale horizontally across servers. Hybrid Haskell and Python For Coreference Resolution Here we will write a Haskell client for using a server written in Python that performs coreference resolution (more on this later). There is some common material in this chapter and the last chapter Hybrid Haskell and Python Natural Language Processing because I wanted both chapters to be self contained. The code for this chapter can be found in the subdirectory HybridHaskellPythonCore- fAnaphoraResolution. Coreference resolution is also called anaphora resolution and is the process for replacing pronouns in text with the original nouns, proper nouns, or noun phrases that the pronouns refer to. Before discussing setting up the Python library for performing coreference analysis and the Haskell client, let’s run the client so you can see and understand anaphora resolution: 1 $ stack build --fast --exec HybridHaskellPythonCorefAnaphoraResolution-exe 2 Enter text (all on one line) 3 John Smith drove a car. He liked it. 4 5 6 *** Processing John%20Smith%20drove%20a%20car.%20He%20liked%20it. 7 status code: 200 8 content type: Just "application/text" 9 response body: John Smith drove a car. John Smith liked a car. 10 response from coreference server: "John Smith drove a car. John Smith liked a car." 11 Enter text (all on one line) In this example notice that the words “He” and “it” in the second sentence are replaced by “John Smith” and “a car” which makes it easier to write information extraction applications. Installing the Python Coreference Server I recommend that you use virtual Python environments when using Python applications to separate the dependencies required for each application or development project. Here I assume that you are running in a Python version 3.6 (or higher) version environment. If you want to install the neuralcoref library using pip you must use and older version of spaCy. First install the dependencies: Hybrid Haskell and Python For Coreference Resolution 158 1 pip install spacy==2.1.0 2 pip install neuralcoref 3 pip install falcon As I write this chapter the neuralcoref model and library require a slightly older version of spaCy (the current latest version is 2.3.0). If you want to instead use the latest version of spaCy then install neuralcoref from source: 1 pip install spacy 2 git clone https://github.com/huggingface/neuralcoref.git 3 cd neuralcoref 4 python setup.py install 5 pip install falcon After installing all dependencies, then change directory to the subdirectory python_coreference_- anaphora_resolution_server and install the coref server: 1 cd python_coreference_anaphora_resolution_server 2 python setup.py install Once you install the server, you can run it from any directory on your laptop or server using: 1 corefserver I use deep learning models written in Python using TensorFlow or PyTorch in applications I write in Haskell or Common Lisp. While it is possible to directly embed models in Haskell and Common Lisp, I find it much easier and developer friendly to wrap deep learning models I use a REST services as I have done here. Often deep learning models only require about a gigabyte of memory and using pre-trained models has lightweight CPU resource needs so while I am developing on my laptop I might have two or three models running and available as wrapped REST services. For production, I configure both the Python services and my Haskell and Common Lisp applications to start automatically on system startup. This is not a Python programming book and I will not discuss the simple Python wrapping code but if you are also a Python developer you can easily read and understand the code. Understanding the Haskell Coreference Client Code The code for the library for fetching data from the Python service is in the subdirectory src in the file CorefWebClient.hs. We will use techniques for accessing remote web services using the wreq library and using the lens library for accessing the response from the Python server. Here the response is plain text with pronouns replaced by the nouns that they represent. We don’t use the aeson library to parse JSON data as we did in the previous chapter. Hybrid Haskell and Python For Coreference Resolution 159 1 {-# LANGUAGE OverloadedStrings #-} 2 3 -- reference: http://www.serpentine.com/wreq/tutorial.html 4 module CorefWebClient 5 ( corefClient 6 ) where 7 8 import Control.Lens 9 import Data.ByteString.Lazy.Char8 (unpack) 10 import Data.Maybe (fromJust) 11 import Network.URI.Encode (encode) 12 import Network.Wreq 13 14 base_url = "http://127.0.0.1:8000?text=" 15 16 corefClient :: [Char] -> IO [Char] 17 corefClient query = do 18 putStrLn $ "\n\n*** Processing " ++ (encode query) 19 r <- get $ base_url ++ (encode query) ++ "&no_detail=1" 20 putStrLn $ "status code: " ++ (show (r ^. responseStatus . statusCode)) 21 putStrLn $ "content type: " ++ (show (r ^? responseHeader "Content-Type")) 22 putStrLn $ "response body: " ++ (unpack (fromJust (r ^? responseBody))) 23 return $ unpack (fromJust (r ^? responseBody)) The code for the main application is in the subdirectory app in the file Main.hs. 1 module Main where 2 3 import CorefWebClient 4 5 main :: IO () 6 main = do 7 putStrLn "Enter text (all on one line)" 8 s <- getLine 9 response <- corefClient s 10 putStr "response from coreference server:\t" 11 putStrLn $ show response 12 main Hybrid Haskell and Python For Coreference Resolution 160 Wrapup for Using the Python Coreference NLP Service The example in this chapter is fairly simple but shows a technique that I often use for using libraries and frameworks that are not written in Haskell: wrap the service implemented in another programming language is a REST web service. While it is possible to use a foreign function interface (FFI) to call out to code written in other languages I find for my own work that I prefer calling out to a separate service, especially when I run other services on remote servers so I do not need to run them on my development laptop. For production it is also useful to be able to easily scale horizontally across servers. Book Wrap Up As I mentioned in the Preface, I had a slow start learning Haskell because I tried to learn too much at one time. In this book I have attempted to show you a subset of Haskell that is sufficient to write interesting programs - a gentle introduction. Haskell beginners often dislike the large error listings from the compiler. The correct attitude is to recognize that these error messages are there to help you. That is easier said than done, but try to be happy when the compiler points out an error - in the long run I find using Haskell’s fussy compiler saves me time and lets me refactor code knowing that if I miss something in my refactoring the compiler will immediately let me know what needs to be fixed. The other thing that I hope you learned working through this book is how effective repl based programming is. Most code I write, unless it is very trivial, starts its life in a GHCi repl. When you are working with somene else’s Haskell code it is similarly useful to have their code loaded in a repl as you read. I have been programming professionally for forty years and I use many programming languages. Once I worked my way through early difficulties using Haskell it has become a favorite program- ming language. I hope that you enjoy Haskell development as much as I do. Appendix A - Haskell Tools Setup I recommend that if you are new to Haskell that you at least do a minimal installation of stack and work through the first chapter using an interactive REPL. After experimenting with the REPL then do please come back to Appendix A and install support for the editor of your choice (or an IDE) and hlint. stack I assume that you have the Haskell package manager stack installed. If you have not installed stack yet please follow these directions⁴⁴. After installing stack and running it you will have a directory “.stack” in your home directory where stack will keep compiled libraries and configuration data. You will want to create a file “∼/.stack/config.yaml” with contents similar to my stack configuration file: 1 templates: 2 params: 3 author-email: markw@markwatson.com 4 author-name: Mark Watson 5 category: dev 6 copyright: Copyright 2016 Mark Watson. All rights reserved 7 github-username: mark-watson Replace my name and email address with yours. You might also want to install the package manager Cabal and the “lint” program hlint: $ stack install cabal-install $ stack install hlint These installs might take a while so go outside for ten minutes and get some fresh air. You should get in the habit of running hlint on your code and consider trying to remove all or at least most warnings. You can customize the types of warnings hlint shows: read the documentation for hlint⁴⁵. ⁴⁴http://docs.haskellstack.org/en/stable/README.html ⁴⁵https://github.com/ndmitchell/hlint#readme Appendix A - Haskell Tools Setup 163 Creating a New Stack Project I have already created stack projects for the examples in this book. When you have worked through them, then please refer to the stack documentation for creating projects⁴⁶. Emacs Setup There are several good alternatives to using the Emacs editor: • GEdit on Linux • TextMate on OS X • IntelliJ with the Haskell plugin (all platforms) I use all three of these alternatives on occasion, but Emacs with haskell-mode is my favorite environment. There are instructions for adding haskell-mode to Emacs on the project home page on github⁴⁷. If you follow these instructions you will have syntax hiliting and Emacs will understand Haskell indentation rules. Do you want more of an IDE-like Development Environment? I recommend and use the Intero Emacs package⁴⁸ to get auto completions and real time syntax error warnings. Intero is designed to work with stack. I add the following to the bottom of my .emacs file: (add-hook ‘haskell-mode-hook ‘intero-mode) and if Intero is too “heavy weight” for my current project, then I comment out the add-hook expression. Intero can increase the startup time for Emacs for editing Haskell files. That said, I almost always keep Intero enabled in my Emacs environment. hlint hlint is a wonderful tool for refining your knowledge and use of the Haskell language. After writing new code and checking that it works, then run hlint for suggestions on how to improve your code. Install hlint using: ⁴⁶https://docs.haskellstack.org/en/stable/README/#start-your-new-project ⁴⁷https://github.com/haskell/haskell-mode ⁴⁸https://commercialhaskell.github.io/intero/ Appendix A - Haskell Tools Setup 164 1 stack install hlint ================================================ FILE: embedchain_test/data/lovinglisp-2.txt ================================================ Loving Common Lisp, or the Savvy Programmer’s Secret Weapon Mark Watson This book is for sale at http://leanpub.com/lovinglisp This version was published on 2023-05-01 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License Contents Cover Material, Copyright, and License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Notes on the Eighth Edition Published August 2022 . . . . . . . . . . . . . . . . . . . . . . . . 2 Notes on the Seventh Edition Published March 2021 . . . . . . . . . . . . . . . . . . . . . . . 2 Notes on the Sixth Edition Published June 2020 . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Notes on the Fifth Edition Published September 2019 . . . . . . . . . . . . . . . . . . . . . . . 3 Why Use Common Lisp? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 A Request from the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Older Book Editions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Setting Up Your Common Lisp Development System and Quicklisp . . . . . . . . . . . . . . 5 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Why Did I Write this Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Free Software Tools for Common Lisp Programming . . . . . . . . . . . . . . . . . . . . . . . 8 Making Book Examples Run Portably on Most Common Lisp Implementations . . . . . . . 8 How is Lisp Different from Languages like Java and C++? . . . . . . . . . . . . . . . . . . . . 9 Advantages of Working in a Lisp Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Common Lisp Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Getting Started with SBCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Making the repl Nicer using rlwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The Basics of Lisp Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Operations on Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Using Arrays and Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Using Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Using Hash Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Using Eval to Evaluate Lisp Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Using a Text Editor to Edit Lisp Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Recovering from Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Loading your Working Environment Quickly . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 CONTENTS Functional Programming Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Quicklisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Using Quicklisp to Find Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Using Quicklisp to Configure Emacs and Slime . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Defining Lisp Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Using Lambda Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Using the Function eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Defining Common Lisp Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Example Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Using the Splicing Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Using macroexpand-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Using Common Lisp Loop Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 dolist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 dotimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Using the loop Special Form to Iterate Over Vectors or Arrays . . . . . . . . . . . . . . . . . 54 Common Lisp Package System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 The Lisp read and read-line Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Lisp Printing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Plotting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Implementing the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Packaging as a Quicklisp Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Common Lisp Object System - CLOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Example of Using a CLOS Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Implementation of the HTMLstream Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Using Defstruct or CLOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Heuristically Guided Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Network Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 An introduction to Drakma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 An introduction to Hunchentoot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Complete REST Client Server Example Using JSON for Data Serialization . . . . . . . . . . 83 Network Programming Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 CONTENTS Using the Microsoft Bing Search APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Getting an Access Key for Microsoft Bing Search APIs . . . . . . . . . . . . . . . . . . . . . . 87 Example Search Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Wrap-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Accessing Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Database Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Using MongoDB, Solr NoSQL Data Stores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 A Common Lisp Solr Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 NoSQL Wrapup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Natural Language Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Loading and Running the NLP Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Part of Speech Tagging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Categorizing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Detecting People’s Names and Place Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Summarizing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Text Mining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Information Gathering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 DBPedia Lookup Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Web Spiders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Using Apache Nutch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Using The CL Machine-Learning Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Using the CLML Data Loading and Access APIs . . . . . . . . . . . . . . . . . . . . . . . . . . 134 K-Means Clustering of Cancer Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 SVM Classification of Cancer Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 CLML Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Backpropagation Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Hopfield Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Using Python Deep Learning Models In Common Lisp With a Web Services Interface . . 161 Setting up the Python Web Services Used in this Chapter . . . . . . . . . . . . . . . . . . . . 161 Installing the spaCY NLP Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Installing the Coreference NLP Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Common Lisp Client for the spaCy NLP Web Services . . . . . . . . . . . . . . . . . . . . . . 163 Common Lisp Client for the Coreference NLP Web Services . . . . . . . . . . . . . . . . . . 165 Trouble Shooting Possible Problems - Skip if this Example Works on Your System . . . . . 166 Python Interop Wrap-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 CONTENTS Using the PY4CL Library to Embed Python in Common Lisp . . . . . . . . . . . . . . . . . . . 168 Project Structure, Building the Python Wrapper, and Running an Example . . . . . . . . . . 168 Implementation of spacy-py4cl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Trouble Shooting Possible Problems - Skip if this Example Works on Your System . . . . . 171 Wrap-up for Using Py4CL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Semantic Web and Linked Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Resource Description Framework (RDF) Data Model . . . . . . . . . . . . . . . . . . . . . . . 174 Extending RDF with RDF Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 The SPARQL Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Case Study: Using SPARQL to Find Information about Board of Directors Members of Corporations and Organizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Installing the Apache Jena Fuseki RDF Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Common Lisp Client Examples for the Apache Jena Fuseki RDF Server . . . . . . . . . . . . 187 Automatically Generating Data for Knowledge Graphs . . . . . . . . . . . . . . . . . . . . . . 190 Implementation Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Generating RDF Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Generating Data for the Neo4j Graph Database . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Implementing the Top Level Application APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Implementing The Web Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Creating a Standalone Application Using SBCL . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Augmenting RDF Triples in a Knowledge Graph Using DBPedia . . . . . . . . . . . . . . . . 204 KGCreator Wrap Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs . . . . . . . . . 207 Knowledge Graph Navigator Common Library Implementation . . . . . . . . . . . . . . . . . 212 Example Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Project Configuration and Running the Application . . . . . . . . . . . . . . . . . . . . . . . . 218 Review of NLP Utilities Used in Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Developing Low-Level SPARQL Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Implementing the Caching Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 Utilities in the Main Library File kgn-common.lisp . . . . . . . . . . . . . . . . . . . . . . . . 226 Wrap-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Knowledge Graph Navigator Text-Based User Interface . . . . . . . . . . . . . . . . . . . . . . 234 Example Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Text User Interface Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Wrap-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Knowledge Graph Navigator User Interface Using LispWorks CAPI . . . . . . . . . . . . . . 246 Project Configuration and Running the Application . . . . . . . . . . . . . . . . . . . . . . . . 247 Utilities to Colorize SPARQL and Generated Output . . . . . . . . . . . . . . . . . . . . . . . 249 CONTENTS Main Implementation File kgn-capi-ui.lisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 User Interface Utilites File user-interface.lisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 User Interface CAPI Options Panes Definition File option-pane.lisp . . . . . . . . . . . . . . 258 Using LispWorks CAPI UI Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Wrap-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Using the OpenAI APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 Using the Hugging Face Deep Learning Natural Language Processing APIs . . . . . . . . . 274 Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Overview of Local Embeddings Vector Database to Enhance the Use of GPT3 APIs With Local Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Implementing a Local Vector Database for Document Embeddings . . . . . . . . . . . . . . 278 Using Local Embeddings Vector Database With OpenAI GPT APIs . . . . . . . . . . . . . . 281 Testing Local Embeddings Vector Database With OpenAI GPT APIs . . . . . . . . . . . . . 282 Adding Chat History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Wrap Up for Using Local Embeddings Vector Database to Enhance the Use of GPT3 APIs With Local Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Prompt Engineering for Large Language Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Two Types of LLMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Prompt Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Prompt Engineering Wrapup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Using Common Lisp with Wolfram/One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Book Wrapup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 Cover Material, Copyright, and License Copyright 2011-2023 Mark Watson. All rights reserved. This book may be shared using the Creative Commons “share and share alike, no modifications, no commercial reuse” license. This eBook will be updated occasionally so please periodically check the leanpub.com web page for this book¹ for updates. This is the eighth edition released August 2022. Please visit the author’s website². If you found a copy of this book on the web and find it of value then please consider buying a copy at leanpub.com/lovinglisp³. If you would like to support my work please consider purchasing my books on Leanpub⁴ and star my git repositories that you find useful on GitHub⁵. You can also interact with me on social media on Mastodon⁶ and Twitter⁷. ¹https://leanpub.com/lovinglisp ²http://markwatson.com ³https://leanpub.com/lovinglisp ⁴https://leanpub.com/u/markwatson ⁵https://github.com/mark-watson?tab=repositories&q=&type=public ⁶https://mastodon.social/@mark_watson ⁷https://twitter.com/mark_l_watson Preface Notes on the Eighth Edition Published August 2022 The main change is splitting the Knowledge Graph Navigator (KGN) chapter that features the LispWorks CAPI UI APIs into three chapters for a library for KGN functionality, a text based (console) UI, and a CAPI based UI. I added examples using the OpenAI GPT-3 APIs. There are other small corrections and improvements. Notes on the Seventh Edition Published March 2021 I added two short chapters to the previous edition: Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs and Using Common Lisp With Wolfram/One. Notes on the Sixth Edition Published June 2020 Two examples optionally use the CAPI user interface toolkit provided with LispWorks Common Lisp⁸ and work with the free personal edition. The first CAPI application is Knowledge Graph Navigator⁹ and the second CAPI example is Knowledge Graph Creator¹⁰. Both of these examples build up utilities for working with Knowledge Graphs and the Semantic Web. I expand the Plot Library chapter to generate either PNG graphics files or if you are using the free personal edition of LispWorks you can also direct plotting output to a new window in interactive programs. I added a new chapter on using the py4cl library to embed Python libraries and application code into a Common Lisp system. I provide new examples for embedding spaCy and TensorFlow applications in Common Lisp applications. In earlier editions, I used a web services interface to wrap Python code using spaCy and TensorFlow. I am leaving that chapter intact, renaming it from “Using Python Deep Learning Models In Common Lisp” to “Using Python Deep Learning Models In Common Lisp With a Web Services Interface.” The new chapter for this edition is “Using the PY4CL Library to Embed Python in Common Lisp.” ⁸https://lispworks.com ⁹http://knowledgegraphnavigator.com ¹⁰http://kgcreator.com Preface 3 Notes on the Fifth Edition Published September 2019 There were two chapters added: • A complete application for processing text to generate data for Knowledge Graphs (targeting the open source Neo4J graph database and also support RDF semantic web/linked data). • A library for accessing the state of the art spaCy natural language processing (NLP) library and also a state of the art deep learning model. These models are implemented in thin Python wrappers that use Python libraries like spaCy, PyTorch, and TensorFlow. These examples replace a simple hybrid Java and Common Lisp example in previous editions. I have added text and explanations as appropriate throughout the book and I removed the CouchDB examples. I have made large changes to how the code for this book is packaged. I have reorganized the example code on GitHub by providing the examples as multiple Quicklisp libraries or applications. I now do this with all of my Common Lisp code and it makes it easier to write smaller libraries that can be composed into larger applications. In my own workflow, I also like to use Makefile targets to build standalone applications that can be run on other computers without installing Lisp development environments. Please follow the directions at the end of the Preface for configuring Quicklisp for easy builds and use of the example software for this book. Why Use Common Lisp? Why Common Lisp? Isn’t Common Lisp an old language? Do many people still use Common Lisp? I believe that using Lisp languages like Common Lisp, Clojure, Racket, and Scheme are all secret weapons useful in agile software development. An interactive development process and live production updates feel like a breath of fresh air if you have development on heavy weight like Java Enterprise Edition (JEE). Yes, Common Lisp is an old language but with age comes stability and extremely good compiler technology. There is also a little inconsistency between different Common Lisp systems in such things as handling threads but with a little up front knowledge you can choose which Common Lisp systems will support your requirements. A Request from the Author I spent time writing this book to help you, dear reader. I release this book under the Creative Commons License and set the minimum purchase price to $0.00 (free!) in order to reach the most readers. Under this license you can share a PDF version of this book with your friends and coworkers Preface 4 and I encourage you to do so. If you found this book on the web (or it was given to you) and if it provides value to you then please consider doing one of the following to support my future writing efforts and also to support future updates to this book: • Purchase a copy of this book leanpub.com/lovinglisp/¹¹ or any other of my leanpub books at https://leanpub.com/u/markwatson¹² • Hire me as a consultant¹³ I enjoy writing and your support helps me write new editions and updates for my books and to develop new book projects. Thank you! Older Book Editions The fourth edition of this book was released in May 2017 and the major changes were: • Added an example application KGCreator that processes text data to automatically generate data for Knowledge Graphs. This example application supports the Neo4J graph database as well as semantic web/linked data systems. The major changes were: • Added a backpropagation neural network example • Added a deep learning example using the Java based Armed Bear Common Lisp with the popular DeepLearning4j library • Added a heuristic search example • Added two machine learning examples (K-Means clustering and SVM classification) using the CLML library • A few edits to the previous text The third edition was released in October 2014. The major changes made in the 2014 edition are: • I reworked the chapter Common Lisp Basics. • I added material to the chapter on using QuickLisp. The second edition was released in 2013 and was derived from the version that I distributed on my web site and I moved production of the book to leanpub.com¹⁴. ¹¹https://leanpub.com/lovinglisp/ ¹²https://leanpub.com/u/markwatson ¹³https://markwatson.com/ ¹⁴https://leanpub.com/u/markwatson Preface 5 Acknowledgments I would like to thank Jans Aasman¹⁵ for contributing as technical editor for the fourth edition of this book. Jans is CEO of Franz.com¹⁶ which sells Allegro Common Lisp¹⁷ as well as tools for semantic web and linked data applications. I would like to thank the following people who made suggestions for improving previous editions of this book: Sam Steingold, Andrew Philpot, Kenny Tilton, Mathew Villeneuve, Eli Draluk, Erik Winkels, Adam Shimali, and Paolo Amoroso. I would like to also thank several people who pointed out typo errors in this book and for specific suggestions: Martin Lightheart, Tong-Kiat Tan, Rainer Joswig, Gerold Rupprecht, HN member rurban, David Cortesi. I would like to thank the following Reddit /r/lisp readers who pointed out mistakes in the fifth edition of this book: arnulfslayer, rpiirp, and itmuckel. I would like to thank Ted Briscoe for pointing out a problem with the spacy web client example in the 6th edition. I would like to thank Paul Graham for coining the phrase “The Secret Weapon” (in his excellent paper “Beating the Averages”) in discussing the advantages of Lisp and giving me permission to reuse his phrase. I would especially like to thank my wife Carol Watson for her fine work in editing this book. Setting Up Your Common Lisp Development System and Quicklisp These instructions assume the use of SBCL. See comments for LispWorks, Franz Common Lisp, and Closure Common List at the end of this section. I assume that you have installed SBCL and Quicklisp by following the instructions at lisp-lang.org/learn/getting-started¹⁸. These instructions also guide you through installing the Slime extensions for Emacs. I use both Emacs + Slime and VSCode with Common Lisp plugins for editing Common Lisp. If you like VSCode then I recommend Yasuhiro Matsumoto’s Lisp plugin for syntax highlighting. For both Emacs and VSCode I usually run a separate REPL in a terminal window and don’t run an editor-integrated REPL. I think that I am in the minority in using a separate REPL running in a shell. I have been using Common Lisp since about 1982 and Quicklisp (developed and maintained by Zach Beane¹⁹) has been the most revolutionary change in my Common Lisp development (even more so than getting a hardware Lisp Machine and the availability of Coral Common Lisp on the Macintosh). ¹⁵https://en.wikipedia.org/wiki/Jans_Aasman ¹⁶http://franz.com/ ¹⁷http://franz.com/products/allegro-common-lisp/ ¹⁸https://lisp-lang.org/learn/getting-started/ ¹⁹https://www.xach.com Preface 6 You can follow the directions on the main GitHub repository for this book: https://github.com/mark- watson/loving-common-lisp²⁰ to get the examples set up to run on your computer. Starting with the 8th edition, I have a new scheme for distributing the book examples on GitHub: • A few short example Common Lisp code snippets are still kept in the main repository for the book: https://github.com/mark-watson/loving-common-lisp²¹. • The longer examples are now stored in separate GitHub repositories to facilitate using them as reusable Quicklisp libraries. • Clone the main GitHub repository and copy the Makefile²² to the directory ∼/quicklisp/local- projects/ on your computer. • Change directory to ∼/quicklisp/local-projects/ and run the Makefile target make fetch to copy all separate GitHub repositories to subdirectories of ∼/quicklisp/local-projects/. • You can now load any book example using Quicklisp, for example: (ql:quickload :sparql). For example, the subdirectory loving-common-lisp/src/spacy-py4cl contains a package named spacy-py4cl that can now be accessed from any directory on your system using: 1 $ sbcl 2 (ql:quickload "spacy-py4cl") 3 * (spacy-py4cl:nlp "My sister has a dog Henry. She loves him.") 4 * (defvar x (spacy-py4cl:nlp "President Bill Clinton went to Congress. He gave a spe\ 5 ech on taxes and Mexico.")) This example uses the deep learning NLP models in spaCy which is a Python library - see the chapter on NLP for details on installing the Python dependencies. Note that only a few examples in this book require Python dependencies. I have used the SBCL implementation of Common Lisp in this book. There are many fine Common Lisp implementations from Franz, LispWorks, Clozure Common Lisp, etc. I usually use LispWorks for my professional development work. If you have any great difficulty adopting the examples to your choice of Common Lisp implementations and performing web search does not suggest a solution then you can reach me through my web site, markwatson.com²³. ²⁰https://github.com/mark-watson/loving-common-lisp ²¹https://github.com/mark-watson/loving-common-lisp ²²https://raw.githubusercontent.com/mark-watson/loving-common-lisp/master/Makefile ²³https://markwatson.com Introduction This book is intended to get you, the reader, programming quickly in Common Lisp. Although the Lisp programming language is often associated with artificial intelligence, this introduction is on general Common Lisp programming techniques. Later we will look at general example applications and artificial intelligence examples. The Common Lisp program examples are distributed on the github repo for this book²⁴. Why Did I Write this Book? Why the title “Loving Common Lisp”? Simple! I have been using Lisp for almost 40 years and seldom do I find a better match between a programming language and the programming job at hand. I am not a total fanatic on Lisp, however. I often use Python for deep learning. I like Ruby, Java and Javascript for server side programming, and the few years that I spent working on Nintendo video games and virtual reality systems for SAIC and Disney, I found C++ to be a good bet because of stringent runtime performance requirements. For some jobs, I find the logic-programming paradigm useful: I also enjoy the Prolog language. In any case, I love programming in Lisp, especially the industry standard Common Lisp. As I wrote the second edition of this book over a decade ago, I had been using Common Lisp almost exclusively for an artificial intelligence project for a health care company and for commercial product development. While working on the third edition of this book, I was not using Common Lisp professionally but since the release of the Quicklisp Common Lisp package manager I have found myself enjoying using Common Lisp more for small side projects. I use Quicklisp throughout in the third edition example code so you can easily install required libraries. For the fourth and fifth editions of this book I have added more examples using neural networks and deep learning. In this new sixth edition I have added a complete application that uses CAP for the user interface. As programmers, we all (hopefully) enjoy applying our experience and brains for tackling interesting problems. My wife and I recently watched a two-night 7-hour PBS special “Joseph Campbell, and the Power of Myths.” Campbell, a college professor for almost 40 years, said that he always advised his students to “follow their bliss” and not to settle for jobs and avocations that are not what they truly want to do. That said I always feel that when a job calls for using Java, Python or other languages besides Lisp, that even though I may get a lot of pleasure from the job I am not following my bliss. My goal in this book is to introduce you to one of my favorite programming languages, Common Lisp. I assume that you already know how to program in another language but if you are a complete beginner you can still master the material in this book with some effort. I challenge you to make this effort. ²⁴https://github.com/mark-watson/loving-common-lisp Introduction 8 Free Software Tools for Common Lisp Programming There are several Common Lisp compilers and runtime tools available for free on the web: • CLISP – licensed under the GNU GPL and is available for Windows, Macintosh, and Linux/U- nix • Clozure Common Lisp (CCL) – open source with good Mac OS X and Linux support • CMU Common Lisp – open source implementation • SBCL – derived from CMU Common Lisp • ECL – compiles using a separate C/C++ compiler • ABCL – Armed Bear Common Lisp for the JVM There are also fine commercial Common Lisp products: • LispWorks – high quality and reasonably priced system for Windows and Linux. No charge for distributing compiled applications lispworks.com²⁵ • Allegro Common Lisp - high quality, great support and higher cost. franz.com²⁶ • MCL – Macintosh Common Lisp. I used this Lisp environment in the late 1980s. MCL was so good that I gave away my Xerox 1108 Lisp Machine and switched to a Mac and MCL for my development work. Now open source but only runs on the old MacOS I currently (mostly) use SBCL, CCL, and LispWorks. The SBCL compiler produces very fast code and the compiler warning can be of great value in finding potential problems with your code. Like CCL because it compiles quickly so is often preferable for development. For working through this book, I will assume that you are using SBCL or CCL. For the example in the last chapter you will need LispWorks and the free Personal edition is fine for the purposes of experimenting with the example application and the CAPI user interface library. Making Book Examples Run Portably on Most Common Lisp Implementations Many of the book examples require making web service calls. In general when I am writing Common Lisp applications that require making REST calls I prefer using 3rd party Common Lisp libraries like Drakma or Dexador. However it is sometimes a little tricky to set up Common Lisp on different operating systems and CPU architectures with libopenssl, libcrypto, etc. Because of this, in book examples I run the external curl program using uiop:run-program and collect the output as a string that is then parsed as JSON or CSV data. The overhead of starting an external process is very small ²⁵http://www.lispworks.com ²⁶http://franz.com Introduction 9 compared to calling a web service so in your own applications you can either follow my example of using curl or use the Drakma or Dexador libraries. Using the Apple M1 processor on macOS can be particularly problematic with OpenSSL issues. I also use the excellent Common Lisp to Python bridge library py4cl in a few book examples. Usually py4cl installs without problems. How is Lisp Different from Languages like Java and C++? This is a trick question! Lisp is slightly more similar to Java than C++ because of automated memory management so we will start by comparing Lisp and Java. In Java, variables are strongly typed while in Common Lisp values are strongly typed. For example, consider the Java code: 1 Float x = new Float(3.14f); 2 String s = "the cat ran" ; 3 Object any_object = null; 4 any_object = s; 5 x = s; // illegal: generates a 6 // compilation error Here, in Java, variables are strongly typed so a variable x of type Float can’t legally be assigned a string value: the code in line 5 would generate a compilation error. Lisp code can assign a value to a variable and then reassign another value of a different type. Java and Lisp both provide automatic memory management. In either language, you can create new data structures and not worry about freeing memory when the data is no longer used, or to be more precise, is no longer referenced. Common Lisp is an ANSI standard language. Portability between different Common Lisp implemen- tations and on different platforms is very good. I have used Clozure Common Lisp, SBCL, Allegro Lisp (from Franz Inc), LispWorks, and CLISP that all run well on Windows, Mac OS X, and Linux. As a Common Lisp developer you will have great flexibility in tools and platforms. ANSI Common Lisp was the first object oriented language to become an ANSI standard language. The Common Lisp Object System (CLOS) is probably the best platform for object oriented programming. In C++ programs, a common bug that affects a program’s efficiency is forgetting to free memory that is no longer used. In a virtual memory system, the effect of a program’s increasing memory usage is usually just poorer system performance but can lead to system crashes or failures if all available virtual memory is exhausted. A worse type of C++ error is to free memory and then try to use it. Can you say “program crash”? C programs suffer from the same types of memory related errors. Introduction 10 Since computer processing power is usually much less expensive than the costs of software development, it is almost always worth while to give up a few percent of runtime efficiency and let the programming environment of runtime libraries manage memory for you. Languages like Lisp, Ruby, Python, and Java are said to perform automatic garbage collection. I have written six books on Java, and I have been quoted as saying that for me, programming in Java is about twice as efficient (in terms of my time) as programming in C++. I base this statement on approximately ten years of C++ experience on projects for SAIC, PacBell, Angel Studios, Nintendo, and Disney. I find Common Lisp and other Lisp languages like Clojure and Scheme to be about twice as efficient (again, in terms of my time) as Java. That is correct: I am claiming a four times increase in my programming productivity when using Common Lisp vs. C++. What do I mean by programming productivity? Simple: for a given job, how long does it take me to design, code, debug, and later maintain the software for a given task. Advantages of Working in a Lisp Environment We will soon see that Lisp is not just a language; it is also a programming environment and runtime environment. The beginning of this book introduces the basics of Lisp programming. In later chapters, we will develop interesting and non-trivial programs in Common Lisp that I argue would be more difficult to implement in other languages and programming environments. The big win in programming in a Lisp environment is that you can set up an environment and interactively write new code and test new code in small pieces. We will cover programming with large amounts of data in the Chapter on Natural Language Processing, but let me share a a general use case for work that I do that is far more efficient in Lisp: Much of my Lisp programming used to be writing commercial natural language processing (NLP) programs for my company www.knowledgebooks.com. My Lisp NLP code uses a large amount of memory resident data; for example: hash tables for different types of words, hash tables for text categorization, 200,000 proper nouns for place names (cities, counties, rivers, etc.), and about 40,000 common first and last names of various nationalities. If I was writing my NLP products in C++, I would probably use a relational database to store this data because if I read all of this data into memory for each test run of a C++ program, I would wait 30 seconds every time that I ran a program test. When I start working in any Common Lisp environment, I do have to load the linguistic data into memory one time, but then can code/test/code/test… for hours with no startup overhead for reloading the data that my programs need to run. Because of the interactive nature of Lisp development, I can test small bits of code when tracking down errors and when writing new code. It is a personal preference, but I find the combination of the stable Common Lisp language and an iterative Lisp programming environment to be much more productive than other languages and programming environments. Common Lisp Basics The material in this chapter will serve as an introduction to Common Lisp. I have attempted to make this book a self contained resource for learning Common Lisp and to provide code examples to perform common tasks. If you already know Common Lisp and bought this book for the code examples later in this book then you can probably skip this chapter. For working through this chapter we will be using the interactive shell, or repl, built into SBCL and other Common Lisp systems. For this chapter it is sufficient for you to download and install SBCL²⁷. Please install SBCL right now, if you have not already done so. Getting Started with SBCL When we start SBCL, we see an introductory message and then an input prompt. We will start with a short tutorial, walking you through a session using SBCL repl (other Common LISP systems are very similar). A repl is an interactive console where you type expressions and see the results of evaluating these expressions. An expression can be a large block of code pasted into the repl, using the load function to load Lisp code into the repl, calling functions to test them, etc. Assuming that SBCL is installed on your system, start SBCL by running the SBCL program: 1 % sbcl 2 (running SBCL from: /Users/markw/sbcl) 3 This is SBCL 2.0.2, an implementation of ANSI Common Lisp. 4 More information about SBCL is available at <http://www.sbcl.org/>. 5 6 SBCL is free software, provided as is, with absolutely no warranty. 7 It is mostly in the public domain; some portions are provided under 8 BSD-style licenses. See the CREDITS and COPYING files in the 9 distribution for more information. 10 11 * (defvar x 1.0) 12 13 X 14 * x 15 16 1.0 17 * (+ x 1) ²⁷http://www.sbcl.org/platform-table.html Common Lisp Basics 12 18 19 2.0 20 * x 21 22 1.0 23 * (setq x (+ x 1)) 24 25 2.0 26 * x 27 28 2.0 29 * (setq x "the dog chased the cat") 30 31 "the dog chased the cat" 32 * x 33 34 "the dog chased the cat" 35 * (quit) We started by defining a new variable x in line 11. Notice how the value of the defvar macro is the symbol that is defined. The Lisp reader prints X capitalized because symbols are made upper case (we will look at the exception later). In Lisp, a variable can reference any data type. We start by assigning a floating point value to the variable x, using the + function to add 1 to x in line 17, using the setq function to change the value of x in lines 23 and 29 first to another floating point value and finally setting x to a string value. One thing that you will have noticed: function names always occur first, then the arguments to a function. Also, parenthesis is used to separate expressions. I learned to program Lisp in 1976 and my professor half-jokingly told us that Lisp was an acronym for “Lots-of Irritating Superfluous Parenthesis.” There may be some truth in this when you are just starting with Lisp programming, but you will quickly get used to the parenthesis, especially if you use an editor like Emacs that automatically indents Lisp code for you and highlights the opening parenthesis for every closing parenthesis that you type. Many other editors support coding in Lisp but I personally use Emacs or sometimes VScode (with Common Lisp plugins) to edit Lisp code. Before you proceed to the next chapter, please take the time to install SBCL on your computer and try typing some expressions into the Lisp listener. If you get errors, or want to quit, try using the quit function: Common Lisp Basics 13 1 * (+ 1 2 3 4) 2 3 10 4 * (quit) 5 Bye. If you get an error you can enter help to get options for handling an error. When I get an error and have a good idea of what caused the error then I just enter :a: to abort out of the error). As we discussed in the introduction, there are many different Lisp programming environments that you can choose from. I recommend a free set of tools: Emacs, Quicklisp, slime, and SBCL. Emacs is a fine text editor that is extensible to work well with many programming languages and document types (e.g., HTML and XML). Slime is an Emacs extension package that greatly facilitates Lisp development. SBCL is a robust Common Lisp compiler and runtime system that is often used in production. We will cover the Quicklisp package manager and using Quicklisp to setup Slime and Emacs in a later chapter. I will not spend much time covering the use of Emacs as a text editor in this book since you can try most of the example code snippets in the book text by copying and then pasting them into a SBCL repl and by loading the book example source files directly into a repl. If you already use Emacs then I recommend that you do set up Slime sooner rather than later and start using it for development. If you are not already an Emacs user and do not mind spending the effort to learn Emacs, then search the web first for an Emacs tutorial. That said, you will easily be able to use the example code from this book using any text editor you like with a SBCL repl. I don’t use the vi or vim editors but if vi is your weapon of choice for editing text then a web search for “common lisp vi vim repl” should get you going for developing Common Lisp code with vi or vim. If you are not already an Emacs or vi user then using VSCode with a Common Lisp plugin is recommended. Here, we will assume that under Windows, Unix, Linux, or Mac OS X you will use one command window to run SBCL and a separate editor that can edit plain text files. Making the repl Nicer using rlwrap While reading the last section you (hopefully!) played with the SBCL interactive repl. If you haven’t played with the repl, I won’t get too judgmental except to say that if you do not play with the examples as you read you will not get the full benefit from this book. Did you notice that the backspace key does not work in the SBCL repl? The way to fix this is to install the GNU rlwrap utility. On OS X, assuming that you have homebrew²⁸ installed, install rlwrap with: ²⁸http://mxcl.github.io/homebrew/ Common Lisp Basics 14 1 brew install rlwrap If you are running Ubuntu Linux, install rlwrap using: 1 sudo apt-get install rlwrap You can then create an alias for bash or zsh using something like the following to define a command rsbcl: 1 alias rsbcl='rlwrap sbcl' This is fine, just remember to run sbcl if you don’t need rlwrap command line editing or run rsbcl when you do need command line editing. That said, I find that I always want to run SBCL with command line editing, so I redefine sbcl on my computers using: 1 -> ~ which sbcl 2 /Users/markw/sbcl/sbcl 3 -> ~ alias sbcl='rlwrap /Users/markw/sbcl/sbcl' This alias is different on my laptops and servers, since I don’t usually install SBCL in the default installation directory. For each of my computers, I add an appropriate alias in my .zshrc file (if I am running zsh) or my .bashrc file (if I am running bash). The Basics of Lisp Programming Although we will use SBCL in this book, any Common Lisp environment will do fine. In previous sections, we saw the top-level Lisp prompt and how we could type any expression that would be evaluated: 1 * 1 2 1 3 * 3.14159 4 3.14159 5 * "the dog bit the cat" 6 "the dog bit the cat" 7 * (defun my-add-one (x) 8 (+ x 1)) 9 MY-ADD-ONE 10 * (my-add-one -10) 11 -9 Common Lisp Basics 15 Notice that when we defined the function my-add-one in lines 7 and 8, we split the definition over two lines and on line 8 you don’t see the “*” prompt from SBCL – this lets you know that you have not yet entered a complete expression. The top level Lisp evaluator counts parentheses and considers a form to be complete when the number of closing parentheses equals the number of opening parentheses and an expression is complete when the parentheses match. I tend to count in my head, adding one for every opening parentheses and subtracting one for every closing parentheses – when I get back down to zero then the expression is complete. When we evaluate a number (or a variable), there are no parentheses, so evaluation proceeds when we hit a new line (or carriage return). The Lisp reader by default tries to evaluate any form that you enter. There is a reader macro ‘ that prevents the evaluation of an expression. You can either use the ‘ character or quote: 1 * (+ 1 2) 2 3 3 * '(+ 1 2) 4 (+ 1 2) 5 * (quote (+ 1 2)) 6 (+ 1 2) 7 * Lisp supports both global and local variables. Global variables can be declared using defvar: 1 * (defvar *x* "cat") 2 *X* 3 * *x* 4 "cat" 5 * (setq *x* "dog") 6 "dog" 7 * *x* 8 "dog" 9 * (setq *x* 3.14159) 10 3.14159 11 * *x* 12 3.14159 One thing to be careful of when defining global variables with defvar: the declared global variable is dynamically scoped. We will discuss dynamic versus lexical scoping later, but for now a warning: if you define a global variable avoid redefining the same variable name inside functions. Lisp programmers usually use a global variable naming convention of beginning and ending dynamically scoped global variables with the * character. If you follow this naming convention and also do not use the * character in local variable names, you will stay out of trouble. For convenience, I do not always follow this convention in short examples in this book. Common Lisp Basics 16 Lisp variables have no type. Rather, values assigned to variables have a type. In this last example, the variable x was set to a string, then to a floating-point number. Lisp types support inheritance and can be thought of as a hierarchical tree with the type t at the top. (Actually, the type hierarchy is a DAG, but we can ignore that for now.) Common Lisp also has powerful object oriented programming facilities in the Common Lisp Object System (CLOS) that we will discuss in a later chapter. Here is a partial list of types (note that indentation denotes being a subtype of the preceding type): 1 t [top level type (all other types are a sub-type)] 2 sequence 3 list 4 array 5 vector 6 string 7 number 8 float 9 rational 10 integer 11 ratio 12 complex 13 character 14 symbol 15 structure 16 function 17 hash-table We can use the typep function to test the type of value of any variable or expression or use type-of to get type information of any value): 1 * (setq x '(1 2 3)) 2 (1 2 3) 3 * (typep x 'list) 4 T 5 * (typep x 'sequence) 6 T 7 * (typep x 'number) 8 NIL 9 * (typep (+ 1 2 3) 'number) 10 T 11 * (type-of 3.14159) 12 single-float 13 * (type-of "the dog ran quickly") 14 (simple-array character (19)) Common Lisp Basics 17 15 * (type-of 100193) 16 (integer 0 4611686018427387903) A useful feature of all ANSI standard Common Lisp implementations’ top-level listener is that it sets * to the value of the last expression evaluated. For example: 1 * (+ 1 2 3 4 5) 2 15 3 * * 4 15 5 * (setq x *) 6 15 7 * x 8 15 All Common Lisp environments set * to the value of the last expression evaluated. This example may be slightly confusing because * is also the prompt character in the SBCL repl that indicates that you can enter a new expression for evaluation. For example in line 3, the first * character is the repl prompt and the second * we type in to see that value of the previous expression that we typed into the repl. Frequently, when you are interactively testing new code, you will call a function that you just wrote with test arguments; it is useful to save intermediate results for later testing. It is the ability to create complex data structures and then experiment with code that uses or changes these data structures that makes Lisp programming environments so effective. Common Lisp is a lexically scoped language that means that variable declarations and function definitions can be nested and that the same variable names can be used in nested let forms; when a variable is used, the current let form is searched for a definition of that variable and if it is not found, then the next outer let form is searched. Of course, this search for the correct declaration of a variable is done at compile time so there need not be extra runtime overhead. We can nest defun special form inside each other and inside let expressions but this defines the nested functions globally. We use the special forms flet and labels to define functions inside a scoped environment. Functions defined inside a labels special form can be recursive while functions defined inside a flet special form cannot be recursive. Consider the following example in the file nested.lisp (all example files are in the src directory): Common Lisp Basics 18 1 (flet ((add-one (x) 2 (+ x 1)) 3 (add-two (x) 4 (+ x 2))) 5 (format t "redefined variables: ~A ~A~%" (add-one 100) (add-two 100))) 6 7 (let ((a 3.14)) 8 (defun test2 (x) 9 (print x)) 10 (test2 a)) 11 12 (test2 50) 13 14 (let ((x 1) 15 (y 2)) 16 ;; define a test function nested inside a let statement: 17 (flet ((test (a b) 18 (let ((z (+ a b))) 19 ;; define a helper function nested inside a let/function/let: 20 (flet ((nested-function (a) 21 (+ a a))) 22 (nested-function z))))) 23 ;; call nested function 'test': 24 (format t "test result is ~A~%" (test x y)))) 25 26 (let ((z 10)) 27 (labels ((test-recursion (a) 28 (format t "test-recursion ~A~%" (+ a z)) 29 (if (> a 0) 30 (test-recursion (- a 1))))) 31 (test-recursion 5))) We define a top level flet special form in lines 1-5 that defines two nested functions add-one and add-two and then calls each nested function in the body of the flet special form. For many years I have used nested defun special forms inside let expressions for defining local functions and you will notice this use in a few later examples. However, functions defined inside defun special forms have global visibility so they are not hidden in the local context where they are defined. The example of a nested defun in lines 7-12 shows that the function test2 has global visibility inside the current package. Functions defined inside of a flet special form have access to variables defined in the outer scope containing the flet (also applies to labels). We see this in lines 14-24 where the local variables x and y defined in the let expression are visible inside the function nested-function defined inside the flet. Common Lisp Basics 19 The final example in lines 26-31 shows a recursive function defined inside a labels special form. Assuming that we started SBCL in the src directory we can then use the Lisp load function to evaluate the contents of the file nested.lisp in the sub-directory code_snippets_for_book using the load function: * (load "./code_snippets_for_book/nested.lisp") redefined variables: 101 102 3.14 50 test result is 6 test-recursion 15 test-recursion 14 test-recursion 13 test-recursion 12 test-recursion 11 test-recursion 10 T * The function load returned a value of t (prints in upper case as T) after successfully loading the file. We will use Common Lisp vectors and arrays frequently in later chapters, but will also briefly introduce them here. A singly dimensioned array is also called a vector. Although there are often more efficient functions for handling vectors, we will just look at generic functions that handle any type of array, including vectors. Common Lisp provides support for functions with the same name that take different argument types; we will discuss this in some detail when we cover this in the later chapter on CLOS. We will start by defining three vectors v1, v2, and v3: 1 * (setq v1 (make-array '(3))) 2 #(NIL NIL NIL) 3 * (setq v2 (make-array '(4) :initial-element "lisp is good")) 4 #("lisp is good" "lisp is good" "lisp is good" "lisp is good") 5 * (setq v3 #(1 2 3 4 "cat" '(99 100))) 6 #(1 2 3 4 "cat" '(99 100)) In line 1, we are defining a one-dimensional array, or vector, with three elements. In line 3 we specify the default value assigned to each element of the array v2. In line 5 I use the form for specifying array literals using the special character #. The function aref can be used to access any element in an array: Common Lisp Basics 20 * (aref v3 3) 4 * (aref v3 5) '(99 100) * Notice how indexing of arrays is zero-based; that is, indices start at zero for the first element of a sequence. Also notice that array elements can be any Lisp data type. So far, we have used the special operator setq to set the value of a variable. Common Lisp has a generalized version of setq called setf that can set any value in a list, array, hash table, etc. You can use setf instead of setq in all cases, but not vice-versa. Here is a simple example: * v1 #(NIL NIL NIL) * (setf (aref v1 1) "this is a test") "this is a test" * v1 #(NIL "this is a test" NIL) * When writing new code or doing quick programming experiments, it is often easiest (i.e., quickest to program) to use lists to build interesting data structures. However, as programs mature, it is common to modify them to use more efficient (at runtime) data structures like arrays and hash tables. Symbols We will discuss symbols in more detail the Chapter on Common Lisp Packages. For now, it is enough for you to understand that symbols can be names that refer to variables. For example: > (defvar *cat* "bowser") *CAT* * *cat* "bowser" * (defvar *l* (list *cat*)) *L* * *l* ("bowser") * Note that the first defvar returns the defined symbol as its value. Symbols are almost always converted to upper case. An exception to this “upper case rule” is when we define symbols that may contain white space using vertical bar characters: Common Lisp Basics 21 * (defvar |a symbol with Space Characters| 3.14159) |a symbol with Space Characters| * |a symbol with Space Characters| 3.14159 * Operations on Lists Lists are a fundamental data structure of Common Lisp. In this section, we will look at some of the more commonly used functions that operate on lists. All of the functions described in this section have something in common: they do not modify their arguments. In Lisp, a cons cell is a data structure containing two pointers. Usually, the first pointer in a cons cell will point to the first element in a list and the second pointer will point to another cons representing the start of the rest of the original list. The function cons takes two arguments that it stores in the two pointers of a new cons data structure. For example: * (cons 1 2) (1 . 2) * (cons 1 '(2 3 4)) (1 2 3 4) * The first form evaluates to a cons data structure while the second evaluates to a cons data structure that is also a proper list. The difference is that in the second case the second pointer of the freshly created cons data structure points to another cons cell. First, we will declare two global variables l1 and l2 that we will use in our examples. The list l1 contains five elements and the list l2 contains four elements: * (defvar l1 '(1 2 (3) 4 (5 6))) L1 * (length l1) 5 * (defvar l2 '(the "dog" calculated 3.14159)) L2 * l1 (1 2 (3) 4 (5 6)) * l2 (THE "dog" CALCULATED 3.14159) > Common Lisp Basics 22 You can also use the function list to create a new list; the arguments passed to function list are the elements of the created list: * (list 1 2 3 'cat "dog") (1 2 3 CAT "dog") * The function car returns the first element of a list and the function cdr returns a list with its first element removed (but does not modify its argument): * (car l1) 1 * (cdr l1) (2 (3) 4 (5 6)) * Using combinations of car and cdr calls can be used to extract any element of a list: * (car (cdr l1)) 2 * (cadr l1) 2 * Notice that we can combine calls to car and cdr into a single function call, in this case the function cadr. Common Lisp defines all functions of the form cXXr, cXXXr, and cXXXXr where X can be either a or d. Suppose that we want to extract the value 5 from the nested list l1. Some experimentation with using combinations of car and cdr gets the job done: * l1 (1 2 (3) 4 (5 6)) * (cadr l1) 2 * (caddr l1) (3) (car (caddr l1)) 3 * (caar (last l1)) 5 * (caar (cddddr l1)) 5 * Common Lisp Basics 23 The function last returns the last cdr of a list (i.e., the last element, in a list): * (last l1) ((5 6)) * Common list supplies alternative functions to car and cdr that you might find more readable: first, second, third, fourth, and rest. Here are some examples: * (defvar *x* '(1 2 3 4 5)) *X* * (first *x*) 1 * (rest *x*) (2 3 4 5) * (second *x*) 2 * (third *x*) 3 * (fourth *x*) 4 The function nth takes two arguments: an index of a top-level list element and a list. The first index argument is zero based: * l1 (1 2 (3) 4 (5 6)) * (nth 0 l1) 1 * (nth 1 l1) 2 * (nth 2 l1) (3) * The function cons adds an element to the beginning of a list and returns as its value a new list (it does not modify its arguments). An element added to the beginning of a list can be any Lisp data type, including another list: Common Lisp Basics 24 * (cons 'first l1) (FIRST 1 2 (3) 4 (5 6)) * (cons '(1 2 3) '(11 22 33)) ((1 2 3) 11 22 33) * The function append takes two lists as arguments and returns as its value the two lists appended together: * l1 (1 2 (3) 4 (5 6)) * l2 ('THE "dog" 'CALCULATED 3.14159) * (append l1 l2) (1 2 (3) 4 (5 6) THE "dog" CALCULATED 3.14159) * (append '(first) l1) (FIRST 1 2 (3) 4 (5 6)) * A frequent error that beginning Lisp programmers make is not understanding shared structures in lists. Consider the following example where we generate a list y by reusing three copies of the list x: * (setq x '(0 0 0 0)) (0 0 0 0) * (setq y (list x x x)) ((0 0 0 0) (0 0 0 0) (0 0 0 0)) * (setf (nth 2 (nth 1 y)) 'x) X * x (0 0 X 0) * y ((0 0 X 0) (0 0 X 0) (0 0 X 0)) * (setq z '((0 0 0 0) (0 0 0 0) (0 0 0 0))) ((0 0 0 0) (0 0 0 0) (0 0 0 0)) * (setf (nth 2 (nth 1 z)) 'x) X * z ((0 0 0 0) (0 0 X 0) (0 0 0 0)) * When we change the shared structure referenced by the variable x that change is reflected three times in the list y. When we create the list stored in the variable z we are not using a shared structure. Common Lisp Basics 25 Using Arrays and Vectors Using lists is easy but the time spent accessing a list element is proportional to the length of the list. Arrays and vectors are more efficient at runtime than long lists because list elements are kept on a linked-list that must be searched. Accessing any element of a short list is fast, but for sequences with thousands of elements, it is faster to use vectors and arrays. By default, elements of arrays and vectors can be any Lisp data type. There are options when creating arrays to tell the Common Lisp compiler that a given array or vector will only contain a single data type (e.g., floating point numbers) but we will not use these options in this book. Vectors are a specialization of arrays; vectors are arrays that only have one dimension. For efficiency, there are functions that only operate on vectors, but since array functions also work on vectors, we will concentrate on arrays. In the next section, we will look at character strings that are a specialization of vectors. We could use the generalized make-sequence function to make a singularly dimensioned array (i.e., a vector). Restart sbcl and try: * (defvar x (make-sequence 'vector 5 :initial-element 0)) X * x #(0 0 0 0 0) * In this example, notice the print format for vectors that looks like a list with a proceeding # character. As seen in the last section, we use the function make-array to create arrays: * (defvar y (make-array '(2 3) :initial-element 1)) Y * y #2A((1 1 1) (1 1 1)) > Notice the print format of an array: it looks like a list proceeded by a # character and the integer number of dimensions. Instead of using make-sequence to create vectors, we can pass an integer as the first argument of make-array instead of a list of dimension values. We can also create a vector by using the function vector and providing the vector contents as arguments: Common Lisp Basics 26 * (make-array 10) #(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) * (vector 1 2 3 'cat) #(1 2 3 CAT) * The function aref is used to access sequence elements. The first argument is an array and the remaining argument(s) are array indices. For example: * x #(0 0 0 0 0) * (aref x 2) 0 * (setf (aref x 2) "parrot") "parrot" * x #(0 0 "parrot" 0 0) * (aref x 2) "parrot" * y #2A((1 1 1) (1 1 1)) * (setf (aref y 1 2) 3.14159) 3.14159 * y #2A((1 1 1) (1 1 3.14159)) * Using Strings It is likely that even your first Lisp programs will involve the use of character strings. In this section, we will cover the basics: creating strings, concatenating strings to create new strings, for substrings in a string, and extracting substrings from longer strings. The string functions that we will look at here do not modify their arguments; rather, they return new strings as values. For efficiency, Common Lisp does include destructive string functions that do modify their arguments but we will not discuss these destructive functions here. We saw earlier that a string is a type of vector, which in turn is a type of array (which in turn is a type of sequence). A full coverage of the Common Lisp type system is outside the scope of this tutorial introduction to Common Lisp; a very good treatment of Common Lisp types is in Guy Steele’s “Common Lisp, The Language” which is available both in print and for free on the web. Many of the built in functions for handling strings are actually more general because they are defined for the Common Lisp Basics 27 type sequence. The Common Lisp Hyperspec is another great free resource that you can find on the web. I suggest that you download an HTML version of Guy Steele’s excellent reference book and the Common Lisp Hyperspec and keep both on your computer. If you continue using Common Lisp, eventually you will want to read all of Steele’s book and use the Hyperspec for reference. The following text was captured from input and output from a Common Lisp repl. First, we will declare two global variables s1 and space that contain string values: * (defvar s1 "the cat ran up the tree") S1 * (defvar space " ") SPACE * One of the most common operations on strings is to concatenate two or more strings into a new string: * (concatenate 'string s1 space "up the tree") "the cat ran up the tree up the tree" * Notice that the first argument of the function concatenate is the type of the sequence that the function should return; in this case, we want a string. Another common string operation is search for a substring: * (search "ran" s1) 8 * (search "zzzz" s1) NIL * If the search string (first argument to function search) is not found, function search returns nil, otherwise search returns an index into the second argument string. Function search takes several optional keyword arguments (see the next chapter for a discussion of keyword arguments): (search search-string a-longer-string :from-end :test :test-not :key :start1 :start2 :end1 :end2) For our discussion, we will just use the keyword argument :start2 for specifying the starting search index in the second argument string and the :from-end flag to specify that search should start at the end of the second argument string and proceed backwards to the beginning of the string: Common Lisp Basics 28 * (search " " s1) 3 * (search " " s1 :start2 5) 7 * (search " " s1 :from-end t) 18 * The sequence function subseq can be used for strings to extract a substring from a longer string: * (subseq s1 8) "ran up the tree" > Here, the second argument specifies the starting index; the substring from the starting index to the end of the string is returned. An optional third index argument specifies one greater than the last character index that you want to extract: * (subseq s1 8 11) "ran" * It is frequently useful to remove white space (or other) characters from the beginning or end of a string: * (string-trim '(#\space #\z #\a) " a boy said pez") "boy said pe" * The character #\space is the space character. Other common characters that are trimmed are #\tab and #\newline. There are also utility functions for making strings upper or lower case: * (string-upcase "The dog bit the cat.") "THE DOG BIT THE CAT." * (string-downcase "The boy said WOW!") "the boy said wow!" > We have not yet discussed equality of variables. The function eq returns true if two variables refer to the same data in memory. The function eql returns true if the arguments refer to the same data in memory or if they are equal numbers or characters. The function equal is more lenient: it returns true if two variables print the same when evaluated. More formally, function equal returns true if the car and cdr recursively equal to each other. An example will make this clearer: Common Lisp Basics 29 * (defvar x '(1 2 3)) X * (defvar y '(1 2 3)) Y * (eql x y) NIL * (equal x y) T * x (1 2 3) * y (1 2 3) * For strings, the function string= is slightly more efficient than using the function equal: * (eql "cat" "cat") NIL * (equal "cat" "cat") T * (string= "cat" "cat") T * Common Lisp strings are sequences of characters. The function char is used to extract individual characters from a string: * s1 "the cat ran up the tree" * (char s1 0) #\t * (char s1 1) #\h * Using Hash Tables Hash tables are an extremely useful data type. While it is true that you can get the same effect by using lists and the assoc function, hash tables are much more efficient than lists if the lists contain many elements. For example: Common Lisp Basics 30 * (defvar x '((1 2) ("animal" "dog"))) X * (assoc 1 x) (1 2) * (assoc "animal" x) NIL * (assoc "animal" x :test #'equal) ("animal" "dog") * The second argument to function assoc is a list of cons cells. Function assoc searches for a sub-list (in the second argument) that has its car (i.e., first element) equal to the first argument to function assoc. The perhaps surprising thing about this example is that assoc seems to work with an integer as the first argument but not with a string. The reason for this is that by default the test for equality is done with eql that tests two variables to see if they refer to the same memory location or if they are identical if they are numbers. In the last call to assoc we used “:test #’equal” to make assoc use the function equal to test for equality. The problem with using lists and assoc is that they are very inefficient for large lists. We will see that it is no more difficult to code with hash tables. A hash table stores associations between key and value pairs, much like our last example using the assoc function. By default, hash tables use eql to test for equality when looking for a key match. We will duplicate the previous example using hash tables: * (defvar h (make-hash-table)) H * (setf (gethash 1 h) 2) 2 * (setf (gethash "animal" h) "dog") "dog" * (gethash 1 h) 2 ; T * (gethash "animal" h) NIL ; NIL * Notice that gethash returns multiple values: the first value is the value matching the key passed as the first argument to function gethash and the second returned value is true if the key was found and nil otherwise. The second returned value could be useful if hash values are nil. Common Lisp Basics 31 Since we have not yet seen how to handle multiple returned values from a function, we will digress and do so here (there are many ways to handle multiple return values and we are just covering one of them): * (multiple-value-setq (a b) (gethash 1 h)) 2 * a 2 * b T * Assuming that variables a and b are already declared, the variable a will be set to the first returned value from gethash and the variable b will be set to the second returned value. If we use symbols as hash table keys, then using eql for testing for equality with hash table keys is fine: * (setf (gethash 'bb h) 'aa) AA * (gethash 'bb h) AA ; T * However, we saw that eql will not match keys with character string values. The function make- hash-table has optional key arguments and one of them will allow us to use strings as hash key values: (make-hash-table &key :test :size :rehash-size :rehash-threshold) Here, we are only interested in the first optional key argument :test that allows us to use the function equal to test for equality when matching hash table keys. For example: Common Lisp Basics 32 * (defvar h2 (make-hash-table :test #'equal)) H2 * (setf (gethash "animal" h2) "dog") "dog" * (setf (gethash "parrot" h2) "Brady") "Brady" * (gethash "parrot" h2) "Brady" ; T * It is often useful to be able to enumerate all the key and value pairs in a hash table. Here is a simple example of doing this by first defining a function my-print that takes two arguments, a key and a value. We can then use the maphash function to call our new function my-print with every key and value pair in a hash table: * (defun my-print (a-key a-value) (format t "key: ~A value: ~A~\%" a-key a-value)) MY-PRINT * (maphash #'my-print h2) key: parrot value: Brady key: animal value: dog NIL * The function my-print is applied to each key/value pair in the hash table. There are a few other useful hash table functions that we demonstrate here: * (hash-table-count h2) 2 * (remhash "animal" h2) T * (hash-table-count h2) 1 * (clrhash h2) #S(HASH-TABLE EQUAL) * (hash-table-count h2) 0 * The function hash-table-count returns the number of key and value pairs in a hash table. The function remhash can be used to remove a single key and value pair from a hash table. The function clrhash clears out a hash table by removing all key and value pairs in a hash table. Common Lisp Basics 33 It is interesting to note that clrhash and remhash are the first Common Lisp functions that we have seen so far that modify any of its arguments, except for setq and setf that are macros and not functions. Using Eval to Evaluate Lisp Forms We have seen how we can type arbitrary Lisp expressions in the Lisp repl listener and then they are evaluated. We will see in the Chapter on Input and Output that the Lisp function read evaluates lists (or forms) and indeed the Lisp repl uses function read. In this section, we will use the function eval to evaluate arbitrary Lisp expressions inside a program. As a simple example: * (defvar x '(+ 1 2 3 4 5)) X * x (+ 1 2 3 4 5) * (eval x) 15 * Using the function eval, we can build lists containing Lisp code and evaluate generated code inside our own programs. We get the effect of “data is code”. A classic Lisp program, the OPS5 expert system tool, stored snippets of Lisp code in a network data structure and used the function eval to execute Lisp code stored in the network. A warning: the use of eval is likely to be inefficient in non-compiled code. For efficiency, the OPS5 program contained its own version of eval that only interpreted a subset of Lisp used in the network. Using a Text Editor to Edit Lisp Source Files I usually use Emacs, but we will briefly discuss the editor vi also. If you use vi (e.g., enter “vi nested.lisp”) the first thing that you should do is to configure vi to indicate matching opening parentheses whenever a closing parentheses is typed; you do this by typing “:set sm” after vi is running. If you choose to learn Emacs, enter the following in your .emacs file (or your _emacs file in your home directory if you are running Windows): Common Lisp Basics 34 1 (set-default 'auto-mode-alist 2 (append '(("\\.lisp$" . lisp-mode) 3 ("\\.lsp$" . lisp-mode) 4 ("\\.cl$" . lisp-mode)) 5 auto-mode-alist)) Now, whenever you open a file with the extension of “lisp”, “lsp”, or “cl” (for “Common Lisp”) then Emacs will automatically use a Lisp editing mode. I recommend searching the web using keywords “Emacs tutorial” to learn how to use the basic Emacs editing commands - we will not repeat this information here. I do my professional Lisp programming using free software tools: Emacs, SBCL, Clozure Common Lisp, and Clojure. I will show you how to configure Emacs and Slime in the last section of the Chapter on Quicklisp. Recovering from Errors When you enter forms (or expressions) in a Lisp repl listener, you will occasionally make a mistake and an error will be thrown. Here is an example where I am not showing all of the output when entering help when an error is thrown: * (defun my-add-one (x) (+ x 1)) MY-ADD-ONE * (my-add-one 10) 11 * (my-add-one 3.14159) 4.14159 * (my-add-one "cat") debugger invoked on a SIMPLE-TYPE-ERROR: Argument X is not a NUMBER: "cat" Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL. restarts (invokable by number or by possibly-abbreviated name): 0: [ABORT] Exit debugger, returning to top level. (SB-KERNEL:TWO-ARG-+ "cat" 1) 0] help Common Lisp Basics 35 The debug prompt is square brackets, with number(s) indicating the current control stack level and, if you've entered the debugger recursively, how deeply recursed you are. ... Getting in and out of the debugger: TOPLEVEL, TOP exits debugger and returns to top level REPL RESTART invokes restart numbered as shown (prompt if not given). ERROR prints the error condition and restart cases. ... Inspecting frames: BACKTRACE [n] shows n frames going down the stack. LIST-LOCALS, L lists locals in current frame. PRINT, P displays function call for current frame. SOURCE [n] displays frame's source form with n levels of enclosing forms. Stepping: START Selects the CONTINUE restart if one exists and starts single-stepping. Single stepping affects only code compiled with under high DEBUG optimization quality. See User Manual for details. STEP Steps into the current form. NEXT Steps over the current form. OUT Stops stepping temporarily, but resumes it when the topmost frame that was stepped into returns. STOP Stops single-stepping. ... 0] list-locals SB-DEBUG::ARG-0 = "cat" SB-DEBUG::ARG-1 = 1 0] backtrace 2 Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1002AC32F3}> 0: (SB-KERNEL:TWO-ARG-+ "cat" 1) 1: (MY-ADD-ONE "cat") 0] :0 * Common Lisp Basics 36 Here, I first used the backtrace command :bt to print the sequence of function calls that caused the error. If it is obvious where the error is in the code that I am working on then I do not bother using the backtrace command. I then used the abort command :a to recover back to the top level Lisp listener (i.e., back to the greater than prompt). Sometimes, you must type :a more than once to fully recover to the top level greater than prompt. Garbage Collection Like other languages like Java and Python, Common Lisp provides garbage collection (GC) or automatic memory management. In simple terms, GC occurs to free memory in a Lisp environment that is no longer accessible by any global variable (or function closure, which we will cover in the next chapter). If a global variable *variable-1* is first set to a list and then if we later then set *variable-1* to, for example nil, and if the data referenced in the original list is not referenced by any other accessible data, then this now unused data is subject to GC. In practice, memory for Lisp data is allocated in time ordered batches and ephemeral or generational garbage collectors garbage collect recent memory allocations far more often than memory that has been allocated for a longer period of time. Loading your Working Environment Quickly When you start using Common Lisp for large projects, you will likely have many files to load into your Lisp environment when you start working. Most Common Lisp implementations have a function called defsystem that works somewhat like the Unix make utility. While I strongly recommend defsystem for large multi-person projects, I usually use a simpler scheme when working on my own: I place a file loadit.lisp in the top directory of each project that I work on. For any project, its loadit.lisp file loads all source files and initializes any global data for the project. The last two chapters of this book provide example applications that are configured to work with Quicklisp, which we will study in the next chapter. Another good technique is to create a Lisp image containing all the code and data for all your projects. There is an example of this in the first section of the Chapter on NLP. In this example, it takes a few minutes to load the code and data for my NLP (natural language processing) library so when I am working with it I like to be able to quickly load a SBCL Lisp image. All Common Lisp implementations have a mechanism for dumping a working image containing code and data. Common Lisp Basics 37 Functional Programming Concepts There are two main styles for doing Common Lisp development. Object oriented programming is well supported (see the Chapter on CLOS) as is functional programming. In a nut shell, functional programming means that we should write functions with no side effects. First let me give you a non-functional example with side effects: (defun non-functional-example (car) (set-color car "red")) This example using CLOS is non-functional because we modify the value of an argument to the function. Some functional languages like the Lisp Clojure language and the Haskell language dissuade you from modifying arguments to functions. With Common Lisp you should make a decision on which approach you like to use. Functional programming means that we avoid maintaining state inside of functions and treat data as immutable (i.e., once an object is created, it is never modified). We could modify the last example to be function by creating a new car object inside the function, copy the attributes of the car passed as an object, change the color to “red” of the new car object, and return the new car instance as the value of the function. Functional programming prevents many types of programming errors, makes unit testing simpler, and makes programming for modern multi-core CPUs easier because read-only objects are inher- ently thread safe. Modern best practices for the Java language also prefer immutable data objects and a functional approach. Quicklisp For several decades managing packages and libraries was a manual process when developing Lisp systems. I used to package the source code for specific versions of libraries as part of my Common Lisp projects. Early package management systems mk-defsystem and ASDF were very useful, but I did not totally give up my practice keeping third party library source code with my projects until Zach Beane created the Quicklisp package system²⁹. You will need to have Quicklisp installed for many of the examples later in this book so please take the time to install it now as per the instructions on the Quicklisp web site. Using Quicklisp to Find Packages We will need the Common Lisp Hunchentoot library later in the Chapter on Network Programming so we will install it now using Quicklisp as an example for getting started with Quicklisp. We already know the package name we want, but as an example of discovering packages let’s start by using Quicklisp to search for all packages with “hunchentoot” in the package name: 1 * (ql:system-apropos "hunchentoot") 2 #<SYSTEM clack-handler-hunchentoot / clack-20131111-git / quicklisp 2013-11-11> 3 #<SYSTEM hunchentoot / hunchentoot-1.2.21 / quicklisp 2013-11-11> 4 #<SYSTEM hunchentoot-auth / hunchentoot-auth-20101107-git / quicklisp 2013-11-11> 5 #<SYSTEM hunchentoot-cgi / hunchentoot-cgi-20121125-git / quicklisp 2013-11-11> 6 #<SYSTEM hunchentoot-dev / hunchentoot-1.2.21 / quicklisp 2013-11-11> 7 #<SYSTEM hunchentoot-single-signon / hunchentoot-single-signon-20131111-git / quickl\ 8 isp 2013-11-11> 9 #<SYSTEM hunchentoot-test / hunchentoot-1.2.21 / quicklisp 2013-11-11> 10 #<SYSTEM hunchentoot-vhost / hunchentoot-vhost-20110418-git / quicklisp 2013-11-11> We want the base package seen in line 3 and we can install the base package as seen in the following example: ²⁹http://www.quicklisp.org/ Quicklisp 39 1 * (ql:quickload :hunchentoot) 2 To load "hunchentoot": 3 Load 1 ASDF system: 4 hunchentoot 5 ; Loading "hunchentoot" 6 ....... 7 (:HUNCHENTOOT) In line 1, I refer to the package name using a symbol :hunchentoot but using the string “hunchentoot” would have worked the same. The first time you ql:quickload a library you may see additional printout and it takes longer to load because the source code is downloaded from the web and cached locally in the directory ∼/quicklisp/local-projects. In most of the rest of this book, when I install or use a package by calling the ql:quickload function I do not show the output from this function in the repl listings. Now, we can use the fantastically useful Common Lisp function apropos to see what was just installed: 1 * (apropos "hunchentoot") 2 3 HUNCHENTOOT::*CLOSE-HUNCHENTOOT-STREAM* (bound) 4 HUNCHENTOOT:*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT* (bound) 5 HUNCHENTOOT::*HUNCHENTOOT-STREAM* 6 HUNCHENTOOT:*HUNCHENTOOT-VERSION* (bound) 7 HUNCHENTOOT:HUNCHENTOOT-CONDITION 8 HUNCHENTOOT:HUNCHENTOOT-ERROR (fbound) 9 HUNCHENTOOT::HUNCHENTOOT-OPERATION-NOT-IMPLEMENTED-OPERATION (fbound) 10 HUNCHENTOOT::HUNCHENTOOT-SIMPLE-ERROR 11 HUNCHENTOOT::HUNCHENTOOT-SIMPLE-WARNING 12 HUNCHENTOOT::HUNCHENTOOT-WARN (fbound) 13 HUNCHENTOOT:HUNCHENTOOT-WARNING 14 HUNCHENTOOT-ASD:*HUNCHENTOOT-VERSION* (bound) 15 HUNCHENTOOT-ASD::HUNCHENTOOT 16 :HUNCHENTOOT (bound) 17 :HUNCHENTOOT-ASD (bound) 18 :HUNCHENTOOT-DEV (bound) 19 :HUNCHENTOOT-NO-SSL (bound) 20 :HUNCHENTOOT-TEST (bound) 21 :HUNCHENTOOT-VERSION (bound) 22 * As long as you are thinking about the new tool Quicklisp that is now in your tool chest, you should install most of the packages and libraries that you will need for working through the rest of this Quicklisp 40 book. I will show the statements needed to load more libraries without showing the output printed in the repl as each package is loaded: 1 (ql:quickload "clsql") 2 (ql:quickload "clsql-postgresql") 3 (ql:quickload "clsql-mysql") 4 (ql:quickload "clsql-sqlite3") 5 (ql:quickload :drakma) 6 (ql:quickload :hunchentoot) 7 (ql:quickload :cl-json) 8 (ql:quickload "clouchdb") ;; for CouchDB access 9 (ql:quickload "sqlite") You need to have the Postgres and MySQL client developer libraries installed on your system for the clsql-postgresql and clsql-mysql installations to work. If you are unlikely to use relational databases with Common Lisp then you might skip the effort of installing Postgres and MySQL. The example in the Chapter on the Knowledge Graph Navigator uses the SQLite database for caching. You don’t need any extra dependencies for the sqlite package. Using Quicklisp to Configure Emacs and Slime I assume that you have Emacs installed on your system. In a repl you can setup the Slime package that allows Emacs to connect to a running Lisp environment: (ql:quickload "quicklisp-slime-helper") Pay attention to the output in the repl. On my system the output contained the following: 1 [package quicklisp-slime-helper] 2 slime-helper.el installed in "/Users/markw/quicklisp/slime-helper.el" 3 4 To use, add this to your ~/.emacs: 5 6 (load (expand-file-name "~/quicklisp/slime-helper.el")) 7 ;; Replace "sbcl" with the path to your implementation 8 (setq inferior-lisp-program "sbcl") If you installed rlwrap and defined an alias for running SBCL, make sure you set the inferior lisp program to the absolute path of the SBCL executable; on my system I set the following in my .emacs file: Quicklisp 41 1 (setq inferior-lisp-program "/Users/markw/sbcl/sbcl") I am not going to cover using Emacs and Slime, there are many good tutorials on the web you can read. In later chapters we will write libraries and applications as Quicklisp projects so that you will be able to load your own libraries, making it easier to write small libraries that you can compose into larger applications. Defining Lisp Functions In the previous chapter, we defined a few simple functions. In this chapter, we will discuss how to write functions that take a variable number of arguments, optional arguments, and keyword arguments. The special form defun is used to define new functions either in Lisp source files or at the top level Lisp listener prompt. Usually, it is most convenient to place function definitions in a source file and use the function load to load them into our Lisp working environment. In general, it is bad form to use global variables inside Lisp functions. Rather, we prefer to pass all required data into a function via its argument list and to get the results of the function as the value (or values) returned from a function. Note that if we do require global variables, it is customary to name them with beginning and ending * characters; for example: 1 (defvar *lexical-hash-table* 2 (make-hash-table :test #'equal :size 5000)) Then in this example, if you see the variable *lexical-hash-table* inside a function definition, you will know that at least by naming convention, that this is a global variable. In Chapter 1, we saw an example of using lexically scoped local variables inside a function definition (in the example file nested.lisp). There are several options for defining the arguments that a function can take. The fastest way to introduce the various options is with a few examples. First, we can use the &aux keyword to declare local variables for use in a function definition: 1 * (defun test (x &aux y) 2 (setq y (list x x)) 3 y) 4 TEST 5 * (test 'cat) 6 (CAT CAT) 7 * (test 3.14159) 8 (3.14159 3.14159) It is considered better coding style to use the let special operator for defining auxiliary local variables; for example: Defining Lisp Functions 43 1 * (defun test (x) 2 (let ((y (list x x))) 3 y)) 4 TEST 5 * (test "the dog bit the cat") 6 ("the dog bit the cat" "the dog bit the cat") 7 * You will probably not use &aux very often, but there are two other options for specifying function arguments: &optional and &key. The following code example shows how to use optional function arguments. Note that optional arguments must occur after required arguments. 1 * (defun test (a &optional b (c 123)) 2 (format t "a=~A b=~A c=~A~%" a b c)) 3 TEST 4 * (test 1) 5 a=1 b=NIL c=123 6 NIL 7 * (test 1 2) 8 a=1 b=2 c=123 9 NIL 10 * (test 1 2 3) 11 a=1 b=2 c=3 12 NIL 13 * (test 1 2 "Italian Greyhound") 14 a=1 b=2 c=Italian Greyhound 15 NIL 16 * In this example, the optional argument b was not given a default value so if unspecified it will default to nil. The optional argument c is given a default value of 123. We have already seen the use of keyword arguments in built-in Lisp functions. Here is an example of how to specify key word arguments in your functions: Defining Lisp Functions 44 1 * (defun test (a &key b c) 2 (format t "a=~A b=~A c=~A~%" a b c)) 3 TEST 4 * (test 1) 5 a=1 b=NIL c=NIL 6 NIL 7 * (test 1 :c 3.14159) 8 a=1 b=NIL c=3.14159 9 NIL 10 * (test "cat" :b "dog") 11 a=cat b=dog c=NIL 12 NIL 13 * Using Lambda Forms It is often useful to define unnamed functions. We can define an unnamed function using lambda; for example, let’s look at the example file src/lambda1.lisp. But first, we will introduce the Common Lisp function funcall that takes one or more arguments; the first argument is a function and any remaining arguments are passed to the function bound to the first argument. For example: 1 * (funcall 'print 'cat) 2 CAT 3 CAT 4 * (funcall '+ 1 2) 5 3 6 * (funcall #'- 2 3) 7 -1 8 * In the first two calls to funcall here, we simply quote the function name that we want to call. In the third example, we use a better notation by quoting with #’. We use the #’ characters to quote a function name. Consider the following repl listing where we will look at a primary difference between quoting a symbol using ‘ and with #’: Defining Lisp Functions 45 1 $ ccl 2 Clozure Common Lisp Version 1.12 DarwinX8664 3 ? 'barfoo531 4 BARFOO531 5 ? (apropos "barfoo") 6 BARFOO531 7 ? #'bar987 8 > Error: Undefined function: BAR987 On line three we create a new symbol BARFOO531 that is interned as you can see from looking at all interned symbols containing the string “barfoo”. Line 7 throws an error because #’ does not intern a new symbol. Here is the example file src/lambda1.lisp: 1 (defun test () 2 (let ((my-func 3 (lambda (x) (+ x 1)))) 4 (funcall my-func 1))) Here, we define a function using lambda and set the value of the local variable my-func to the unnamed function’s value. Here is output from the function test: 1 * (test) 2 2 3 4 * The ability to use functions as data is surprisingly useful. For now, we will look at a simple example: 1 * (defvar f1 #'(lambda (x) (+ x 1))) 2 3 F1 4 * (funcall f1 100) 5 6 101 7 * (funcall #'print 100) 8 9 100 10 100 Notice that the second call to function testfn prints “100” twice: the first time as a side effect of calling the function print and the second time as the returned value of testfn (the function print returns what it is printing as its value). Defining Lisp Functions 46 Using Recursion Later, we will see how to use special Common Lisp macros for programming repetitive loops. In this section, we will use recursion for both coding simple loops and as an effective way to solve a variety of problems that can be expressed naturally using recursion. As usual, the example programs for this section are found in the src directory. In the file src/recursion1.lisp, we see our first example of recursion: 1 ;; a simple loop using recursion 2 3 (defun recursion1 (value) 4 (format t "entering recursion1(~A)~\%" value) 5 (if (< value 5) 6 (recursion1 (1+ value)))) This example is simple, but it is useful for discussing a few points. First, notice how the function recursion1 calls itself with an argument value of one greater than its own input argument only if the input argument “value” is less than 5. This test keeps the function from getting in an infinite loop. Here is some sample output: 1 * (load "recursion1.lisp") 2 ;; Loading file recursion1.lisp ... 3 ;; Loading of file recursion1.lisp is finished. 4 T 5 * (recursion1 0) 6 entering recursion1(0) 7 entering recursion1(1) 8 entering recursion1(2) 9 entering recursion1(3) 10 entering recursion1(4) 11 entering recursion1(5) 12 NIL 13 * (recursion1 -3) 14 entering recursion1(-3) 15 entering recursion1(-2) 16 entering recursion1(-1) 17 entering recursion1(0) 18 entering recursion1(1) 19 entering recursion1(2) 20 entering recursion1(3) 21 entering recursion1(4) Defining Lisp Functions 47 22 entering recursion1(5) 23 NIL 24 * (recursion1 20) 25 entering recursion1(20) 26 NIL 27 * Why did the call on line 24 not loop via recursion? Because the input argument is not less than 5, no recursion occurs. Closures We have seen that functions can take other functions as arguments and return new functions as values. A function that references an outer lexically scoped variable is called a closure. The example file src/closure1.lisp contains a simple example: 1 (let* ((fortunes 2 '("You will become a great Lisp Programmer" 3 "The force will not be with you" 4 "Take time for meditation")) 5 (len (length fortunes)) 6 (index 0)) 7 (defun fortune () 8 (let ((new-fortune (nth index fortunes))) 9 (setq index (1+ index)) 10 (if (>= index len) (setq index 0)) 11 new-fortune))) Here the function fortune is defined inside a let form. Because the local variable fortunes is referenced inside the function fortune, the variable fortunes exists after the let form is evaluated. It is important to understand that usually a local variable defined inside a let form “goes out of scope” and can no longer be referenced after the let form is evaluated. However, in this example, there is no way to access the contents of the variable fortunes except by calling the function fortune. At a minimum, closures are a great way to hide variables. Here is some output from loading the src/closure1.lisp file and calling the function fortune several times: Defining Lisp Functions 48 1 * (load "closure1.lisp") 2 ;; Loading file closure1.lisp ... 3 ;; Loading of file closure1.lisp is finished. 4 T 5 * (fortune) 6 "You will become a great Lisp Programmer" 7 * (fortune) 8 "The force will not be with you" 9 * (fortune) 10 "Take time for meditation" 11 * (fortune) 12 "You will become a great Lisp Programmer" 13 * Using the Function eval In Lisp languages we often say that code is data. The function eval can be used to execute code that is stored as Lisp data. Let’s look at an example: 1 $ ccl 2 Clozure Common Lisp Version 1.12 DarwinX8664 3 ? '(+ 1 2.2) 4 (+ 1 2.2) 5 ? (eval '(+ 1 2.2)) 6 3.2 7 ? (eval '(defun foo2 (x) (+ x x))) 8 FOO2 9 ? (foo2 4) 10 8 I leave it up to you, dear reader, how often you are motivated to use eval. In forty years of using Lisp languages my principle use of eval has been in modifying the standard version of the Ops5 programming language for production systems³⁰ to support things like multiple data worlds and new actions to spawn off new data worlds and to remove them. Ops5 works by finding common expressions in a set of production rules (also referred to as “expert systems”) and factoring them into a network (a Rete network if you want to look it up) with common expressions in rules stored in just a single place. eval is used a lot in Ops5 and I used it for my extensions to Ops5. ³⁰https://github.com/sharplispers/ops5 Defining Common Lisp Macros We saw in the last chapter how the Lisp function eval could be used to evaluate arbitrary Lisp code stored in lists. Because eval is inefficient, a better way to generate Lisp code automatically is to define macro expressions that are expanded inline when they are used. In most Common Lisp systems, using eval requires the Lisp compiler to compile a form on-the-fly which is not very efficient. Some Lisp implementations use an interpreter for eval which is likely to be faster but might lead to obscure bugs if the interpreter and compiled code do not function identically. The ability to add functionality and syntax to the Common Lisp language, to in effect extend the language as needed, is truly a super power of languages like Common Lisp and Scheme. Example Macro The file src/macro1.lisp contains both a simple macro and a function that uses the macro. This macro example is a bit contrived since it could be just a function definition, but it does show the process of creating and using a macro. We are using the gensym function to define a new unique symbol to reference a temporary variable: 1 ;; first simple macro example: 2 3 (defmacro double-list (a-list) 4 (let ((ret (gensym))) 5 `(let ((,ret nil)) 6 (dolist (x ,a-list) 7 (setq ,ret (append ,ret (list x x)))) 8 ,ret))) 9 10 ;; use the macro: 11 12 (defun test (x) 13 (double-list x)) The backquote character seen at the beginning of line 5 is used to quote a list in a special way: nothing in the list is evaluated during macro expansion unless it is immediately preceded by a comma character. In this case, we specify ,a-list because we want the value of the macro’s argument a-list to be substituted into the specially quoted list. We will look at dolist in some detail in the next chapter but for now it is sufficient to understand that dolist is used to iterate through the top-level elements of a list, for example: Defining Common Lisp Macros 50 1 * (dolist (x '("the" "cat" "bit" "the" "rat")) 2 (print x)) 3 "the" 4 "cat" 5 "bit" 6 "the" 7 "rat" 8 NIL 9 * Notice that the example macro double-list itself uses the macro dolist. It is common to nest macros in the same way functions can be nested. Returning to our macro example in the file src/macro1.lisp, we will try the function test that uses the macro double-list: 1 * (load "macro1.lisp") 2 ;; Loading file macro1.lisp ... 3 ;; Loading of file macro1.lisp is finished. 4 T 5 * (test '(1 2 3)) 6 (1 1 2 2 3 3) 7 * Using the Splicing Operator Another similar example is in the file src/macro2.lisp: 1 ;; another macro example that uses ,@: 2 3 (defmacro double-args (&rest args) 4 `(let ((ret nil)) 5 (dolist (x ,@args) 6 (setq ret (append ret (list x x)))) 7 ret)) 8 9 ;; use the macro: 10 11 (defun test (&rest x) 12 (double-args x)) Here, the splicing operator ,@ is used to substitute in the list args in the macro double-args. Defining Common Lisp Macros 51 Using macroexpand-1 The function macroexpand-1 is used to transform macros with arguments into new Lisp expressions. For example: 1 * (defmacro double (a-number) 2 (list '+ a-number a-number)) 3 DOUBLE 4 * (macroexpand-1 '(double n)) 5 (+ N N) ; 6 T 7 * Writing macros is an effective way to extend the Lisp language because you can control the code passed to the Common Lisp compiler. In both macro example files, when the function test was defined, the macro expansion is done before the compiler processes the code. We will see in the next chapter several useful macros included in Common Lisp. We have only “scratched the surface” looking at macros; the interested reader is encouraged to search the web using, for example, “Common Lisp macros.” There are two books in particular that I recommend that take a deep dive into Common Lisp macros: Paul Graham’s “On Lisp” and Doug Hoyte’s “Let Over Lambda.” Both are deep books and will change the way you experience software development. A good plan of study is spending a year absorbing “On Lisp” before tackling “Let Over Lambda.” Using Common Lisp Loop Macros In this chapter, we will discuss several useful macros for performing iteration (we saw how to use recursion for iteration in Chapter 2): • dolist – a simple way to process the elements of a list • dotimes – a simple way to iterate with an integer valued loop variable • do – the most general looping macro • loop – a complex looping macro that I almost never use in my own code because it does not look “Lisp like.” I don’t use the loop macro in this book. Many programmers do like the loop macro so you are likely to see it when reading other people’s code. dolist We saw a quick example of dolist in the last chapter. The arguments of the dolist macro are: (dolist (a-variable a-list [optional-result-value]) ...body... ) Usually, the dolist macro returns nil as its value, but we can add a third optional argument which will be returned as the generated expression’s value; for example: 1 * (dolist (a '(1 2) 'done) (print a)) 2 1 3 2 4 DONE 5 * (dolist (a '(1 2)) (print a)) 6 1 7 2 8 NIL 9 * The first argument to the dolist macro is a local lexically scoped variable. Once the code generated by the dolist macro finishes executing, this variable is undefined. dotimes The dotimes macro is used when you need a loop with an integer loop index. The arguments of the dotimes macro are: Using Common Lisp Loop Macros 53 (dotimes (an-index-variable max-index-plus-one [optional-result-value]) ...body... ) Usually, the dotimes macro returns nil as its value, but we can add a third optional argument that will be returned as the generated expression’s value; for example: 1 * (dotimes (i 3 "all-done-with-test-dotimes-loop") (print i)) 2 3 0 4 1 5 2 6 "all-done-with-test-dotimes-loop" 7 * As with the dolist macro, you will often use a let form inside a dotimes macro to declare additional temporary (lexical) variables. do The do macro is more general purpose than either dotimes or dolist but it is more complicated to use. Here is the general form for using the do looping macro: (do ((variable-1 variable-1-init-value variable-1-update-expression) (variable-2 variable-2-init-value variable-2-update-expression) . . (variable-N variable-N-init-value variable-N-update-expression)) (loop-termination-test loop-return-value) optional-variable-declarations expressions-to-be-executed-inside-the-loop) There is a similar macro do* that is analogous to let* in that loop variable values can depend on the values or previously declared loop variable values. As a simple example, here is a loop to print out the integers from 0 to 3. This example is in the file src/do1.lisp: ;; example do macro use Using Common Lisp Loop Macros 54 (do ((i 0 (1+ i))) ((> i 3) "value-of-do-loop") (print i)) In this example, we only declare one loop variable so we might as well as used the simpler dotimes macro. Here we load the file src/do1.lisp: 1 * (load "do1.lisp") 2 ;; Loading file do1.lisp ... 3 0 4 1 5 2 6 3 7 ;; Loading of file do1.lisp is finished. 8 T 9 * You will notice that we do not see the return value of the do loop (i.e., the string “value-of-do-loop”) because the top-level form that we are evaluating is a call to the function load; we do see the return value of load printed. If we had manually typed this example loop in the Lisp listener, then you would see the final value value-of-do-loop printed. Using the loop Special Form to Iterate Over Vectors or Arrays We previousely used dolist to iterate over elements in lists. For efficiency we will often use vectors (one dimensional arrays) and we can use loop to similarly handle vectors: (loop for td across testdata do (print td)))) where testdata is a one dimensional array (a vector) and inside the do block the local variable td is assigned to each element in the vector. Common Lisp Package System In later chapters we will see two complete applications that are defined as Quicklisp projects: the chapter on the Knowledge Graph Creator and the chapter on the Knowledge Graph Navigator. Another example for setting up a Quicklib project can be seen in the chapter Plotting Data. While these later chapters provide practical examples for bundling up your own projects in packages, the material here will give you general background information that you should know. In the simple examples that we have seen so far, all newly created Lisp symbols have been placed in the default package. You can always check the current package by evaluating the expression package: > *package* #<PACKAGE COMMON-LISP-USER> > As we will use in the following example, the package :cl is an alias for :common-lisp-user. We will define a new package :my-new-package and two functions foo1 and foo2 inside the package. Externally to this package, assuming that it is loaded, we can access foo2 using my-new- package:foo2. foo1 is not exported so it cannot be accessed this way. However, we can always start a symbol name with a package name and two colon characters if we want to use a symbol defined in another package so we can use my-new-package::foo1. Using :: allows us access to symbols not explicitly exported. When I leave package :my-new-package in line 22 and return to package :cl, and try to access my-new-package:foo1 notice that an error is thrown. On line 3 we define the alias :p1 for the package :my-new-package and we use this alias in line 44. The main point of the following example is that we define two functions in a package but only export one of these functions. By default the other function is not visible outside of the new package. 1 * (defpackage "MY-NEW-PACKAGE" 2 (:use :cl) 3 (:nicknames "P1") 4 (:export :FOO2)) 5 6 #<PACKAGE "MY-NEW-PACKAGE"> 7 * (in-package my-new-package) 8 9 #<PACKAGE "MY-NEW-PACKAGE"> 10 * (defun foo1 () "foo1") Common Lisp Package System 56 11 12 FOO1 13 * (defun foo2 () "foo2") 14 15 FOO2 16 * (foo1) 17 18 "foo1" 19 * (foo2) 20 21 "foo2" 22 * (in-package :cl) 23 24 #<PACKAGE "COMMON-LISP"> 25 * (my-new-package:foo2) 26 27 "foo2" 28 * (my-new-package:foo1) 29 30 debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread 31 #<THREAD "main thread" RUNNING {1001F1ECE3}>: 32 The symbol "FOO1" is not external in the MY-NEW-PACKAGE package. 33 34 Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {100001C343}> 35 36 Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL. 37 38 restarts (invokable by number or by possibly-abbreviated name): 39 0: [CONTINUE] Use symbol anyway. 40 1: [ABORT ] Exit debugger, returning to top level. 41 42 * 1 43 44 * (p1:foo2) 45 46 "foo2" Since we specified a nickname in the defpackage expression, Common Lisp allows the use of the nickname (in this case P1) in calling function foo2 that is exported from package :my-new-package. Near the end of the last example, we switched back to the default package COMMON-LISP-USER so we had to specify the package name for the function foo2 on line 42. What about the error on line 28 where my-new-package:foo1 is undefined because the function Common Lisp Package System 57 foo1 is not exported (see line 4)? It turns out that you can easily use symbols not exported from a package by using :: instead of a single :. Here, this would be defined: (my-new-package::foo1). When you are writing very large Common Lisp programs, it is useful to be able to break up the program into different modules and place each module and all its required data in different name spaces by creating new packages. Remember that all symbols, including variables, generated symbols, CLOS methods, functions, and macros are in some package. For small packages I sometimes put a defpackage expression at the top of the file immediately followed by an in-package expression to switch to the new package. In the general case, please properly use separate project and asdf files as I do in the later chapters Knowledge Graph Creator and Knowledge Graph Navigator. Input and Output We will see that the input and output of Lisp data is handled using streams. Streams are powerful abstractions that support common libraries of functions for writing to the terminal, files, sockets, and to strings. In all cases, if an input or output function is called without specifying a stream, the default for input stream is *standard-input* and the default for output stream is *standard-output*. These default streams are connected to the Lisp listener that we discussed in Chapter 2. In the later chapter Knowledge Graph Navigator that supports a user interface, we will again use output streams bound to different scrolling output areas of the application window to write color-hilighted text. The stream formalism is general purpose, covering many common I/O use cases. The Lisp read and read-line Functions The function read is used to read one Lisp expression. Function read stops reading after reading one expression and ignores new line characters. We will look at a simple example of reading a file test.dat using the example Lisp program in the file read-test-1.lisp. Both of these files can be found in the directory src/code_snippets_for_book that came bundled with this web book. Start your Lisp program in the src directory. The contents of the file test.dat is: 1 1 2 3 2 4 "the cat bit the rat" 3 read with-open-file In the function read-test-1, we use the macro with-open-file to read from a file. To write to a file (which we will do later), we can use the keyword arguments :direction :output. The first argument to the macro with-open-file is a symbol that is bound to a newly created input stream (or an output stream if we are writing a file); this symbol can then be used in calling any function that expects a stream argument. Notice that we call the function read with three arguments: an input stream, a flag to indicate if an error should be thrown if there is an I/O error (e.g., reaching the end of a file), and the third argument is the value that function read should return if the end of the file (or stream) is reached. When calling read with these three arguments, either the next expression from the file test.dat will be returned, or the value nil will be returned when the end of the file is reached. If we do reach the end of the file, the local variable x will be assigned the value nil and the function return will break out of the dotimes loop. One big advantage of using the macro with-open-file over using the open function (which we will not cover) is that the file stream is automatically closed when leaving the code generated by the with-open-file macro. The contents of file read-test-1.lisp is: Input and Output 59 (defun read-test-1 () "read a maximum of 1000 expressions from the file 'test.dat'" (with-open-file (input-stream "test.dat" :direction :input) (dotimes (i 1000) (let ((x (read input-stream nil nil))) (if (null x) (return)) ;; break out of the 'dotimes' loop (format t "next expression in file: ~S~%" x))))) Here is the output that you will see if you load the file read-test-1.lisp and execute the expression (read-test-1): 1 * (load "read-test-1.lisp") 2 ;; Loading file read-test-1.lisp ... 3 ;; Loading of file read-test-1.lisp is finished. 4 T 5 * (read-test-1) 6 next expression in file: 1 7 next expression in file: 2 8 next expression in file: 3 9 next expression in file: 4 10 next expression in file: "the cat bit the rat" 11 NIL Note: the string “the cat bit the rat” prints as a string (with quotes) because we used a ∼S instead of a ∼A in the format string in the call to function format. In this last example, we passed the file name as a string to the macro with-open-file. This is not generally portable across all operating systems. Instead, we could have created a pathname object and passed that instead. The pathname function can take eight different keyword arguments, but we will use only the two most common in the example in the file read-test-2.lisp in the src directory. The following listing shows just the differences between this example and the last: (let ((a-path-name (make-pathname :directory "testdata" :name "test.dat"))) (with-open-file (input-stream a-path-name :direction :input) Here, we are specifying that we want to use the file test.dat in the subdirectory testdata. Note: I almost never use pathnames. Instead, I specify files using a string and the character / as a directory delimiter. I find this to be portable for the Macintosh, Windows, and Linux operating systems using all Common Lisp implementations. Input and Output 60 The file readline-test.lisp is identical to the file read-test-1.lisp except that we call function readline instead of the function read and we change the output format message to indicate that an entire line of text has been read (defun readline-test () "read a maximum of 1000 expressions from the file 'test.dat'" (with-open-file (input-stream "test.dat" :direction :input) (dotimes (i 1000) (let ((x (read-line input-stream nil nil))) (if (null x) (return)) ;; break out of the 'dotimes' loop (format t "next line in file: ~S~%" x))))) When we execute the expression (readline-test), notice that the string contained in the second line of the input file has the quote characters escaped: 1 * (load "readline-test.lisp") 2 ;; Loading file readline-test.lisp ... 3 ;; Loading of file readline-test.lisp is finished. 4 T 5 * (readline-test) 6 next line in file: "1 2 3" 7 next line in file: "4 \"the cat bit the rat\"" 8 NIL 9 * We can also create an input stream from the contents of a string. The file read-from-string-test.lisp is very similar to the example file read-test-1.lisp except that we use the macro with-input-from- string (notice how I escaped the quote characters used inside the test string): (defun read-from-string-test () "read a maximum of 1000 expressions from a string" (let ((str "1 2 \"My parrot is named Brady.\" (11 22)")) (with-input-from-string (input-stream str) (dotimes (i 1000) (let ((x (read input-stream nil nil))) (if (null x) (return)) ;; break out of the 'dotimes' loop (format t "next expression in string: ~S~%" x)))))) We see the following output when we load the file read-from-string-test.lisp: Input and Output 61 1 * (load "read-from-string-test.lisp") 2 ;; Loading file read-from-string-test.lisp ... 3 ;; Loading of file read-from-string-test.lisp is finished. 4 T 5 * (read-from-string-test) 6 next expression in string: 1 7 next expression in string: 2 8 next expression in string: "My parrot is named Brady." 9 next expression in string: (11 22) 10 NIL 11 * We have seen how the stream abstraction is useful for allowing the same operations on a variety of stream data. In the next section, we will see that this generality also applies to the Lisp printing functions. Lisp Printing Functions All of the printing functions that we will look at in this section take an optional last argument that is an output stream. The exception is the format function that can take a stream value as its first argument (or t to indicate *standard-output*, or a nil value to indicate that format should return a string value). Here is an example of specifying the optional stream argument: 1 * (print "testing") 2 3 "testing" 4 "testing" 5 * (print "testing" *standard-output*) 6 7 "testing" 8 "testing" 9 * The function print prints Lisp objects so that they can be read back using function read. The corresponding function princ is used to print for “human consumption”. For example: Input and Output 62 1 * (print "testing") 2 3 "testing" 4 "testing" 5 * (princ "testing") 6 testing 7 "testing" 8 * Both print and princ return their first argument as their return value, which you see in the previous output. Notice that princ also does not print a new line character, so princ is often used with terpri (which also takes an optional stream argument). We have also seen many examples in this book of using the format function. Here is a different use of format, building a string by specifying the value nil for the first argument: 1 * (let ((l1 '(1 2)) 2 (x 3.14159)) 3 (format nil "~A~A" l1 x)) 4 "(1 2)3.14159" 5 * We have not yet seen an example of writing to a file. Here, we will use the with-open-file macro with options to write a file and to delete any existing file with the same name: (with-open-file (out-stream "test1.dat" :direction :output :if-exists :supersede) (print "the cat ran down the road" out-stream) (format out-stream "1 + 2 is: ~A~%" (+ 1 2)) (princ "Stoking!!" out-stream) (terpri out-stream)) Here is the result of evaluating this expression (i.e., the contents of the newly created file test1.dat in the src directory): 1 % cat test1.dat 2 3 "the cat ran down the road" 1 + 2 is: 3 4 Stoking!! Notice that print generates a new line character before printing its argument. Plotting Data We will use Zach Beane’s vecto library³¹ for plotting data with the results written to files. Ideally we would like to have interactive plotting capability but for the purposes of this book I need to support the combinations of all Common Lisp implementations on multiple operating systems. Interactive plotting libraries are usually implementation and OS dependent. We will use the plotlib example we develop in the later chapter Backpropagation Neural Networks. Implementing the Library The examples here are all contained in the directory src/plotlib and is packaged as a Quicklisp loadable library. This library will be used in later chapters. When I work on my macOS laptop, I leave the output graphics file open in the Preview App and whenever I rerun a program producing graphics in the REPL, making the preview App window active refreshes the graphics display. PNG file generated by running plotlib test The following listing shows the file plotlib.lisp that is a simple wrapper for the vecto Common Lisp plotting library. Please note that I only implemented wrappers for vecto functionality that I need for later examples in this book, so the following code is not particularly general but should be easy enough for you to extend for the specific needs of your projects. ³¹http://xach.com/lisp/vecto/ Plotting Data 64 1 ;; Misc. plotting examples using the vecto library 2 3 (ql:quickload :vecto) ;; Zach Beane's plotting library 4 (defpackage #:plotlib 5 (:use #:cl #:vecto)) 6 7 (in-package #:plotlib) 8 9 ;; the coordinate (0,0) is the lower left corner of the plotting area. 10 ;; Increasing the y coordinate is "up page" and increasing x is "to the right" 11 12 ;; fills a rectangle with a gray-scale value 13 (defun plot-fill-rect (x y width height gscale) ; 0 < gscale < 1 14 (set-rgb-fill gscale gscale gscale) 15 (rectangle x y width height) 16 (fill-path)) 17 18 ;; plots a frame rectangle 19 (defun plot-frame-rect (x y width height) 20 (set-line-width 1) 21 (set-rgb-fill 1 1 1) 22 (rectangle x y width height) 23 (stroke)) 24 25 (defun plot-line(x1 y1 x2 y2) 26 (set-line-width 1) 27 (set-rgb-fill 0 0 0) 28 (move-to x1 y1) 29 (line-to x2 y2) 30 (stroke)) 31 32 (defun plot-string(x y str) 33 (let ((font (get-font "OpenSans-Regular.ttf"))) 34 (set-font font 15) 35 (set-rgb-fill 0 0 0) 36 (draw-string x y str))) 37 38 (defun plot-string-bold(x y str) 39 (let ((font (get-font "OpenSans-Bold.ttf"))) 40 (set-font font 15) 41 (set-rgb-fill 0 0 0) 42 (draw-string x y str))) 43 Plotting Data 65 44 45 (defun test-plotlib (file) 46 (with-canvas (:width 90 :height 90) 47 (plot-fill-rect 5 10 15 30 0.2) ; black 48 (plot-fill-rect 25 30 30 7 0.7) ; medium gray 49 (plot-frame-rect 10 50 30 7) 50 (plot-line 90 5 10 5) 51 (plot-string 10 65 "test 1 2 3") 52 (plot-string-bold 10 78 "Hello") 53 (save-png file))) 54 55 ;;(test-plotlib "test-plotlib.png") This plot library is used in later examples in the chapters on search, backpropagation neural networks and Hopfield neural networks. I prefer using implementation and operating specific plotting libraires for generating interactive plots, but the advantage of writing plot data to a file using the vecto library is that the code is portable across operating systems and Common Lisp implementations. Packaging as a Quicklisp Project The two files src/plotlib/plotlib.asd src/plotlib/package.lisp configure the library. The file pack- age.lisp defines the required library vecto and lists the functions that are publicly exported from the library: (defpackage #:plotlib (:use #:cl #:vecto) (:export save-png plot-fill-rect plot-frame-rect plot-size-rect plot-line plot-string plot-string-bold pen-width)) To run the test function provided with this library you load the library and preface exported function names with the package name plotlib: as in this example: (ql:quickload "plotlib") (plotlib::test-plotlib "test-plotlib.png") In addition to a package.lisp file we also use a file with the extension .asd Plotting Data 66 (asdf:defsystem #:plotlib :description "Describe plotlib here" :author "mark.watson@gmail.com" :license "Apache 2" :depends-on (#:vecto) :components ((:file "package") (:file "plotlib"))) If you have specified a dependency that is not already downloaded to your computer, Quicklisp will install the dependency for you. Common Lisp Object System - CLOS CLOS was the first ANSI standardized object oriented programming facility. While I do not use classes and objects as often in my Common Lisp programs as I do when using Java and Smalltalk, it is difficult to imagine a Common Lisp program of any size that did not define and use at least a few CLOS classes. The example program for this chapter in the file src/loving_snippets/HTMLstream.lisp. I used this CLOS class about ten years ago in a demo for my commercial natural language processing product to automatically generate demo web pages. We are going to start our discussion of CLOS somewhat backwards by first looking at a short test function that uses the HTMLstream class. Once we see how to use this example CLOS class, we will introduce a small subset of CLOS by discussing in some detail the implementation of the HTMLstream class and finally, at the end of the chapter, see a few more CLOS programming techniques. This book only provides a brief introduction to CLOS; the interested reader is encouraged to do a web search for “CLOS tutorial”. The macros and functions defined to implement CLOS are a standard part of Common Lisp. Common Lisp supports generic functions, that is, different functions with the same name that are distinguished by different argument types. Example of Using a CLOS Class The file src/loving_snippets/HTMLstream.lisp contains a short test program at the end of the file: 1 (defun test (&aux x) 2 (setq x (make-instance 'HTMLstream)) 3 (set-header x "test page") 4 (add-element x "test text - this could be any element") 5 (add-table 6 x 7 '(("<b>Key phrase</b>" "<b>Ranking value</b>") 8 ("this is a test" 3.3))) 9 (get-html-string x)) The generic function make-instance takes the following arguments: Common Lisp Object System - CLOS 68 1 make-instance class-name &rest initial-arguments &key ... There are four generic functions used in the function test: • set-header - required to initialize class and also defines the page title • add-element - used to insert a string that defines any type of HTML element • add-table - takes a list of lists and uses the list data to construct an HTML table • get-html-string - closes the stream and returns all generated HTML data as a string The first thing to notice in the function test is that the first argument for calling each of these generic functions is an instance of the class HTMLstream. You are free to also define a function, for example, add-element that does not take an instance of the class HTMLstream as the first function argument and calls to add-element will be routed correctly to the correct function definition. We will see that the macro defmethod acts similarly to defun except that it also allows us to define many methods (i.e., functions for a class) with the same function name that are differentiated by different argument types and possibly different numbers of arguments. Implementation of the HTMLstream Class The class HTMLstream is very simple and will serve as a reasonable introduction to CLOS programming. Later we will see more complicated class examples that use multiple inheritance. Still, this is a good example because the code is simple and the author uses this class frequently (some proof that it is useful!). The code fragments listed in this section are all contained in the file src/loving_snippets/HTMLstream.lisp. We start defining a new class using the macro defclass that takes the following arguments: 1 defclass class-name list-of-super-classes 2 list-of-slot-specifications class-specifications The class definition for HTMLstream is fairly simple: 1 (defclass HTMLstream () 2 ((out :accessor out)) 3 (:documentation "Provide HTML generation services")) Here, the class name is HTMLstream, the list of super classes is an empty list (), the list of slot specifications contains only one slot specification for the slot named out and there is only one class specification: a documentation string. Slots are like instance variables in languages like Java and Smalltalk. Most CLOS classes inherit from at least one super class but we will wait until the next section to see examples of inheritance. There is only one slot (or instance variable) and we define Common Lisp Object System - CLOS 69 an accessor variable with the same name as the slot name. This is a personal preference of mine to name read/write accessor variables with the same name as the slot. The method set-header initializes the string output stream used internally by an instance of this class. This method uses convenience macro with-accessors that binds a local set of local variable to one or more class slot accessors. We will list the entire method then discuss it: 1 (defmethod set-header ((ho HTMLstream) title) 2 (with-accessors 3 ((out out)) 4 ho 5 (setf out (make-string-output-stream)) 6 (princ "<HTML><head><title>" out) 7 (princ title out) 8 (princ "" out) 9 (terpri out))) The first interesting thing to notice about the defmethod is the argument list: there are two arguments ho and title but we are constraining the argument ho to be either a member of the class HTMLstream or a subclass of HTMLstream. Now, it makes sense that since we are passing an instance of the class HTMLstream to this generic function (or method – I use the terms “generic function” and “method” interchangeably) that we would want access to the slot defined for this class. The convenience macro with-accessors is exactly what we need to get read and write access to the slot inside a generic function (or method) for this class. In the term ((out out)), the first out is local variable bound to the value of the slot named out for this instance ho of class HTMLstream. Inside the with-accessors macro, we can now use setf to set the slot value to a new string output stream. Note: we have not covered the Common Lisp type string-output-stream yet in this book, but we will explain its use on the next page. By the time a call to the method set-header (with arguments of an HTMLstream instance and a string title) finishes, the instance has its slot set to a new string-output-stream and HTML header information is written to the newly created string output stream. Note: this string output stream is now available for use by any class methods called after set-header. There are several methods defined in the file src/loving_snippets/HTMLstream.lisp, but we will look at just four of them: add-H1, add-element, add-table, and get-html-string. The remaining methods are very similar to add-H1 and the reader can read the code in the source file. As in the method set-header, the method add-H1 uses the macro with-accessors to access the stream output stream slot as a local variable out. In add-H1 we use the function princ that we discussed in Chapter on Input and Output to write HTML text to the string output stream: Common Lisp Object System - CLOS 70 1 (defmethod add-H1 ((ho HTMLstream) some-text) 2 (with-accessors 3 ((out out)) 4 ho 5 (princ "

    " out) 6 (princ some-text out) 7 (princ "

    " out) 8 (terpri out))) The method add-element is very similar to add-H1 except the string passed as the second argument element is written directly to the stream output stream slot: 1 (defmethod add-element ((ho HTMLstream) element) 2 (with-accessors 3 ((out out)) 4 ho 5 (princ element out) 6 (terpri out))) The method add-table converts a list of lists into an HTML table. The Common Lisp function princ- to-string is a useful utility function for writing the value of any variable to a string. The functions string-left-trim and string-right-trim are string utility functions that take two arguments: a list of characters and a string and respectively remove these characters from either the left or right side of a string. Note: another similar function that takes the same arguments is string-trim that removes characters from both the front (left) and end (right) of a string. All three of these functions do not modify the second string argument; they return a new string value. Here is the definition of the add-table method: 1 (defmethod add-table ((ho HTMLstream) table-data) 2 (with-accessors 3 ((out out)) 4 ho 5 (princ "" out) 6 (dolist (d table-data) 7 (terpri out) 8 (princ " " out) 9 (terpri out) 10 (dolist (w d) 11 (princ " " out) 17 (terpri out)) 18 (princ " " out) 19 (terpri out)) 20 (princ "
    " out) 12 (let ((str (princ-to-string w))) 13 (setq str (string-left-trim '(#\() str)) 14 (setq str (string-right-trim '(#\)) str)) Common Lisp Object System - CLOS 71 15 (princ str out)) 16 (princ "
    " out) 21 (terpri out))) The method get-html-string gets the string stored in the string output stream slot by using the function get-output-stream-string: 1 (defmethod get-html-string ((ho HTMLstream)) 2 (with-accessors 3 ((out out)) 4 ho 5 (princ "" out) 6 (terpri out) 7 (get-output-stream-string out))) CLOS is a rich framework for object oriented programming, providing a superset of features found in languages like Java, Ruby, and Smalltalk. I have barely scratched the surface in this short CLOS example for generating HTML. Later in the book, whenever you see calls to make-instance, that lets you know we are using CLOS even if I don’t specifically mention CLOS in the examples. Using Defstruct or CLOS You might notice from my own code that I use Common Lisp defstruct macros to define data structures more often than I use CLOS. The defclass macro used to create CLOS classes are much more flexible but for simple data structures I find that using defstruct is much more concise. In the simplest case, a defstruct can just be a name of the new type followed by slot names. For each slot like my-slot-1 accessor functions are generated automatically. Here is a simple example: 1 $ ccl 2 Clozure Common Lisp Version 1.12 DarwinX8664 3 ? (defstruct struct1 s1 s2) 4 STRUCT1 5 ? (make-struct1 :s1 1 :s2 2) 6 #S(STRUCT1 :S1 1 :S2 2) 7 ? (struct1-s1 (make-struct1 :s1 1 :s2 2)) 8 1 Common Lisp Object System - CLOS 72 We defined a struct struct1 on line3 with two slots names s1 and s2, show the use of the automatically generated constructor make-struct1 on line 5, and one of the two automatically generated accessor functions struct1-s1 on line 7. The names of accessor functions are formed with the structure name and the slot name. Heuristically Guided Search We represent search space as a graph: nodes and links between the nodes. The following figure shows the simple graph that we use as an example, finding a route from node n1 to node n11: Plot of best route using the plotlib utilities The following example code uses a heuristic for determining which node to try first from any specific location: move to the node that is closest spatially to the goal node. We see that this heuristic will not always work to produce the most efficient search but we will still get to the goal node. As an example in which the heuristic does not work, consider when we start at node n1 in the lower left corner of the figure. The search algorithm can add nodes n2 and n4 to the nodes to search list and will search using node n4 first since n4 is closer to the goal node n11 than node n2. In this case, the search will eventually need to back up trying the path n1 to n2. Despite this example of the heuristic not working to decrease search time, in general, for large search spaces (i.e., graphs with many nodes and edges) it can dramatically decrease search time. The main function A*search starting in line 5 extends to line 151 because all search utility functions are nested (lexically scoped) inside the mani function. The actual code for the main function A*search is in lines 150 and 151. Heuristically Guided Search 74 The data representing nodes in this implementation is globally scoped (see the definitions on lines 155-165 in the “throw away test code” near the bottom of the file) and we set the property path-list to store the nodes directy connected to each node (set in function init-path-list in lines 36-52). I originally wrote this code in 1990 which explains it non-functional style using globally scoped node variables. 1 ;; Perform a heuristic A* search between the start and goal nodes: 2 ;; 3 ;; Copyright 1990, 2017 by Mark Watson 4 5 (defun A*search (nodes paths start goal &aux possible-paths best) 6 7 (defun Y-coord (x) (truncate (cadr x))) 8 (defun X-coord (x) (truncate (car x))) 9 10 (defun dist-between-points (point1 point2) 11 (let ((x-dif (- (X-coord point2) (X-coord point1))) 12 (y-dif (- (Y-coord point2) (Y-coord point1)))) 13 (sqrt (+ (* x-dif x-dif) (* y-dif y-dif))))) 14 15 (setq possible-paths 16 (list 17 (list 18 (dist-between-points 19 (eval start) 20 (eval goal)) 21 0 22 (list start)))) 23 24 (defun init-network () 25 (setq paths (init-lengths paths)) 26 (init-path-list nodes paths)) 27 28 (defun init-lengths (pathlist) 29 (let (new-path-list pathlength path-with-length) 30 (dolist (path pathlist) 31 (setq pathlength (slow-path-length path)) 32 (setq path-with-length (append path (list pathlength))) 33 (setq new-path-list (cons path-with-length new-path-list))) 34 new-path-list)) 35 36 (defun init-path-list (nodes paths) 37 (dolist (node nodes) Heuristically Guided Search 75 38 (setf 39 (get node 'path-list) 40 ;; let returns all paths connected to node: 41 (let (path-list) 42 (dolist (path paths) 43 (if (equal node (start-node-name path)) 44 (setq path-list 45 (cons (list (end-node-name path) 46 (path-length path)) 47 path-list)) 48 (if (equal node (end-node-name path)) 49 (setq path-list (cons (list (start-node-name path) 50 (path-length path)) 51 path-list))))) 52 path-list )))) 53 54 (defun slow-path-length (path) 55 (dist-between-points (start-node path) (end-node path))) 56 57 (defun path-length (x) (caddr x)) 58 59 (defun start-node (path) (eval (car path))) 60 (defun end-node (path) (eval (cadr path))) 61 (defun start-node-name (x) (car x)) 62 (defun end-node-name (x) (cadr x)) 63 (defun first-on-path (x) (caddr x)) 64 (defun goal-node (x) (car x)) 65 (defun distance-to-that-node (x) (cadr x)) 66 67 (defun enumerate-children (node goal) 68 (let* ((start-to-lead-node-dist (cadr node)) ;; distance already calculated 69 (path (caddr node)) 70 (lead-node (car path))) 71 (if (get-stored-path lead-node goal) 72 (consider-best-path lead-node goal path start-to-lead-node-dist) 73 (consider-all-nodes lead-node goal path start-to-lead-node-dist)))) 74 75 (defun consider-best-path (lead-node goal path distance-to-here) 76 (let* ( 77 (first-node (get-first-node-in-path lead-node goal)) 78 (dist-to-first (+ distance-to-here 79 (get-stored-dist lead-node first-node))) 80 (total-estimate (+ distance-to-here Heuristically Guided Search 76 81 (get-stored-dist lead-node goal))) 82 (new-path (cons first-node path))) 83 (list (list total-estimate dist-to-first new-path)))) 84 85 (defun get-stored-path (start goal) 86 (if (equal start goal) 87 (list start 0) 88 (assoc goal (get start 'path-list)))) 89 90 (defun node-not-in-path (node path) 91 (if (null path) 92 t 93 (if (equal node (car path)) 94 nil 95 (node-not-in-path node (cdr path))))) 96 97 (defun consider-all-nodes (lead-node goal path start-to-lead-node-dist) 98 (let (dist-to-first total-estimate new-path new-nodes) 99 (dolist (node (collect-linked-nodes lead-node)) 100 (if (node-not-in-path node path) 101 (let () 102 (setq dist-to-first (+ start-to-lead-node-dist 103 (get-stored-dist lead-node node))) 104 (setq total-estimate (+ dist-to-first 105 (dist-between-points 106 (eval node) 107 (eval goal)))) 108 (setq new-path (cons node path)) 109 (setq new-nodes (cons (list total-estimate 110 dist-to-first 111 new-path) 112 new-nodes))))) 113 new-nodes)) 114 115 (defun collect-linked-nodes (node) 116 (let (links) 117 (dolist (link (get node 'path-list)) 118 (if (null (first-on-path link)) 119 (setq links (cons (goal-node link) links)))) 120 links)) 121 122 (defun get-stored-dist (node1 node2) 123 (distance-to-that-node (get-stored-path node1 node2))) Heuristically Guided Search 77 124 125 (defun collect-ascending-search-list-order (a l) 126 (if (null l) 127 (list a) 128 (if (< (car a) (caar l)) 129 (cons a l) 130 (cons (car l) (Collect-ascending-search-list-order a (cdr l)))))) 131 132 (defun get-first-node-in-path (start goal) 133 (let (first-node) 134 (setq first-node (first-on-path (get-stored-path start goal))) 135 (if first-node first-node goal))) 136 137 (defun a*-helper () 138 (if possible-paths 139 (let () 140 (setq best (car possible-paths)) 141 (setq possible-paths (cdr possible-paths)) 142 (if (equal (first (caddr best)) goal) 143 best 144 (let () 145 (dolist (child (enumerate-children best goal)) 146 (setq possible-paths 147 (collect-ascending-search-list-order 148 child possible-paths))) 149 (a*-helper)))))) 150 (init-network) 151 (reverse (caddr (a*-helper)))) 152 153 ;; Throw away test code: 154 155 (defvar n1 '(30 201)) 156 (defvar n2 '(25 140)) 157 (defvar n3 '(55 30)) 158 (defvar n4 '(105 190)) 159 (defvar n5 '(95 110)) 160 (defvar n6 '(140 22)) 161 (defvar n7 '(160 150)) 162 (defvar n8 '(170 202)) 163 (defvar n9 '(189 130)) 164 (defvar n10 '(200 55)) 165 (defvar n11 '(205 201)) 166 Heuristically Guided Search 78 167 (print (A*search 168 '(n1 n2 n3 n4 n5 n6 n7 n8 n9 n10 n11) ;; nodes 169 '((n1 n2) (n2 n3) (n3 n5) (n3 n6) (n6 n10) ;; paths 170 (n9 n10) (n7 n9) (n1 n4) (n4 n2) (n5 n8) 171 (n8 n4) (n7 n11)) 172 'n1 'n11)) ;; starting and goal nodes The following example in the repl shows the calculation of the path that we saw in the figure of the graph search space. 1 $ sbcl 2 * (load "astar_search.lisp") 3 4 (N1 N2 N3 N6 N10 N9 N7 N11) 5 T 6 * There are many types of search: breadth first as we used here, depth first, with heuristics to optimize search dependent on the type of search space. Network Programming Distributed computing is pervasive: you need to look no further than the World Wide Web, Internet chat, etc. Of course, as a Lisp programmer, you will want to do at least some of your network programming in Lisp! The previous editions of this book provided low level socket network programming examples. I decided that for this new edition, I would remove those examples and instead encourage you to “move further up the food chain” and work at a higher level of abstraction that makes sense for the projects you will likely be developing. Starting in the 1980s, a lot of my work entailed low level socket programming for distributed networked applications. As I write this, it is 2013, and there are better ways to structure distributed applications. Specifically, since many of the examples later in this book fetch information from the web and linked data sources, we will start be learning how to use Edi Weitz’s Drakma HTTP client library³². In order to have a complete client server example we will also look briefly at Edi Weitz’s Hunchentoot web server³³ that uses JSON as a data serialization format. I used to use XML for data serialization but JSON has many advantages: easier for a human to read and it plays nicely with Javascript code and some data stores like Postgres (new in versions 9.x), MongoDB, and CouchDB that support JSON as a native data format. The code snippets in the first two sections of this chapter are derived from examples in the Drackma and Hunchentoot documentation. An introduction to Drakma Edi Weitz’s Drakma library³⁴ supports fetching data via HTTP requests. As you can see in the Drakma documentation, you can use this library for authenticated HTTP requests (i.e., allow you to access web sites that require a login), support HTTP GET and PUT operations, and deal with cookies. The top level API that we will use is drakma:http-request that returns multiple values. In the following example, I want only the first three values, and ignore the others like the original URI that was fetched and an IO stream object. We use the built-in Common Lisp macro multiple-value- setq: ³²http://weitz.de/drakma/ ³³http://weitz.de/hunchentoot/ ³⁴http://weitz.de/drakma/ Network Programming 80 1 * (ql:quickload :drakma) 2 * (multiple-value-setq 3 (data http-response-code headers) 4 (drakma:http-request "http://markwatson.com")) I manually formatted the last statement I entered in the last repl listing and I will continue to manually edit the repl listings in the rest of this book to make them more easily readable. The following shows some of the data bound to the variables data, http-response-code, and headers: 1 * data 2 3 " 4 5 6 Mark Watson: Consultant and Author The value of http-response-code is 200 which means that there were no errors: 1 * http-response-code 2 3 200 The HTTP response headers will be useful in many applications; for fetching the home page of my web site the headers are: 1 * headers 2 3 ((:SERVER . "nginx/1.1.19") 4 (:DATE . "Fri, 05 Jul 2013 15:18:27 GMT") 5 (:CONTENT-TYPE . "text/html; charset=utf-8") 6 (:TRANSFER-ENCODING . "chunked") 7 (:CONNECTION . "close") 8 (:SET-COOKIE 9 . 10 "ring-session=cec5d7ba-e4da-4bf4-b05e-aff670e0dd10;Path=/")) We will use Drakma later in this book for several examples. In the next section we will write a web app using Hunchentoot and test it with a Drakma client. Network Programming 81 An introduction to Hunchentoot Edi Weitz’s Hunchentoot project³⁵ is a flexible library for writing web applications and web services. We will also use Edi’s CL-WHO library in this section for generating HTML from Lisp code. Hunchentoot will be installed the first time you quick load it in the example code for this section: 1 (ql:quickload "hunchentoot") I will use only easy handler framework³⁶ in the Hunchentoot examples in this section. I leave it to you to read the documentation on using custom acceptors³⁷ after you experiment with the examples in this section. The following code will work for both multi-threading installations of SBCL and single thread installations (e.g., some default installations of SBCL on OS X): 1 (ql:quickload :hunchentoot) 2 (ql:quickload :cl-who) 3 4 (in-package :cl-user) 5 (defpackage hdemo 6 (:use :cl 7 :cl-who 8 :hunchentoot)) 9 (in-package :hdemo) 10 11 (defvar *h* (make-instance 'easy-acceptor :port 3000)) 12 13 ;; define a handler with the arbitrary name my-greetings: 14 15 (define-easy-handler (my-greetings :uri "/hello") (name) 16 (setf (hunchentoot:content-type*) "text/html") 17 (with-html-output-to-string (*standard-output* nil :prologue t) 18 (:html 19 (:head (:title "hunchentoot test")) 20 (:body 21 (:h1 "hunchentoot form demo") 22 (:form 23 :method :post 24 (:input :type :text 25 :name "name" ³⁵http://weitz.de/hunchentoot/ ³⁶http://weitz.de/hunchentoot/#easy-handlers ³⁷http://weitz.de/hunchentoot/#acceptors Network Programming 82 26 :value name) 27 (:input :type :submit :value "Submit your name")) 28 (:p "Hello " (str name)))))) 29 30 (hunchentoot:start *h*) In lines 5 through 9 we create an use a new package that includes support for generating HTML in Lisp code (CL-WHO) and the Hunchentoot library). On line 11 we create an instance of an easy acceptor on port 3000 that provides useful default behaviors for providing HTTP services. The Hunchentoot macro define-easy-handler is used in lines 15 through 28 to define an HTTP request handler and add it to the easy acceptor instance. The first argument, my-greetings in this example, is an arbitrary name and the keyword :uri argument provides a URL pattern that the easy acceptor server object uses to route requests to this handler. For example, when you run this example on your computer, this URL routing pattern would handle requests like: 1 http://localhost:3000/hello In lines 17 through 28 we are using the CL-WHO library to generate HTML for a web page. As you might guess, :html generates the outer tags for a web page. Line 19 would generate HTML like: 1 2 hunchentoot test 3 Lines 22 through 27 generate an HTML input form and line 28 displays any value generated when the user entered text in the input filed and clicked the submit button. Notice the definition of the argument name in line 1 in the definition of the easy handler. If the argument name is not defined, the nil value will be displayed in line 28 as an empty string. You should run this example and access the generated web page in a web browser, and enter text, submit, etc. You can also fetch the generated page HTML using the Drakma library that we saw in the last section. Here is a code snippet using the Drakma client library to access this last example: Network Programming 83 1 * (drakma:http-request "http://127.0.0.1:3000/hello?name=Mark") 2 3 "Hello Mark" 4 200 5 ((:CONTENT-LENGTH . "10") 6 (:DATE . "Fri, 05 Jul 2013 15:57:22 GMT") 7 (:SERVER . "Hunchentoot 1.2.18") 8 (:CONNECTION . "Close") 9 (:CONTENT-TYPE . "text/plain; charset=utf-8")) 10 # 11 # 12 T 13 "OK" We will use both Drackma and Hunchentoot in the next section. Complete REST Client Server Example Using JSON for Data Serialization A reasonable way to build modern distributed systems is to write REST web services that serve JSON data to client applications. These client applications might be rich web apps written in Javascript, other web services, and applications running on smartphones that fetch and save data to a remote web service. We will use the cl-json Quicklisp package to encode Lisp data into a string representing JSON encoded data. Here is a quick example: 1 * (ql:quickload :cl-json) 2 * (defvar y (list (list '(cat . "the cat ran") '(dog . 101)) 1 2 3 4 5)) 3 4 Y 5 * y 6 7 (((CAT . "the cat ran") (DOG . 101)) 1 2 3 4 5) 8 * (json:encode-json-to-string y) 9 "[{\"cat\":\"the cat ran\",\"dog\":101},1,2,3,4,5]" The following list shows the contents of the file src/web-hunchentoot-json.lisp: Network Programming 84 1 (ql:quickload :hunchentoot) 2 (ql:quickload :cl-json) 3 4 (defvar *h* (make-instance 'hunchentoot:easy-acceptor :port 3000)) 5 6 ;; define a handler with the name animal: 7 8 (hunchentoot:define-easy-handler (animal :uri "/animal") (name) 9 (print name) 10 (setf (hunchentoot:content-type*) "text/plain") 11 (cond 12 ((string-equal name "cat") 13 (json:encode-json-to-string 14 (list 15 (list 16 '(average_weight . 10) 17 '(friendly . nil)) 18 "A cat can live indoors or outdoors."))) 19 ((string-equal name "dog") 20 (json:encode-json-to-string 21 (list 22 (list 23 '(average_weight . 40) 24 '(friendly . t)) 25 "A dog is a loyal creature, much valued by humans."))) 26 (t 27 (json:encode-json-to-string 28 (list 29 () 30 "unknown type of animal"))))) 31 32 (hunchentoot:start *h*) This example is very similar to the web application example in the last section. The difference is that this application is not intended to be viewed on a web page because it returns JSON data as HTTP responses. The easy handler definition on line 8 specifies a handler argument name. In lines 12 and 19 we check to see if the value of the argument name is “cat” or “dog” and if it is, we return the appropriate JSON example data for those animals. If there is no match, the default cond clause starting on line 26 returns a warning string as a JSON encoded string. While running this test service, in one repl, you can ue the Drakma library in another repl to test it (not all output is shown in the next listing): Network Programming 85 1 * (ql:quickload :drakma) 2 * (drakma:http-request "http://127.0.0.1:3000/animal?name=dog") 3 4 "[{\"average_weight\":40, 5 \"friendly\":true}, 6 \"A dog is a loyal creature, much valued by humans.\"]" 7 200 8 * (drakma:http-request "http://127.0.0.1:3000/animal?name=cat") 9 10 "[{\"average_weight\":10, 11 \"friendly\":null}, 12 \"A cat can live indoors or outdoors.\"]" 13 200 You can use the cl-json library to decode a string containing JSON data to Lisp data: 1 * (ql:quickload :cl-json) 2 To load "cl-json": 3 Load 1 ASDF system: 4 cl-json 5 ; Loading "cl-json" 6 . 7 (:CL-JSON) 8 * (cl-json:decode-json-from-string 9 (drakma:http-request "http://127.0.0.1:3000/animal?name=dog")) 10 11 (((:AVERAGE--WEIGHT . 40) (:FRIENDLY . T)) 12 "A dog is a loyal creature, much valued by humans.") For most of my work, REST web services are “read-only” in the sense that clients don’t modify state on the server. However, there are use cases where a client application might want to; for example, letting clients add new animals to the last example. 1 (defparameter *animal-hash* (make-hash-table)) 2 3 ;; handle HTTP POST requests: 4 (hunchentoot:define-easy-handler (some-handler :uri "/add") (json-data) 5 (setf (hunchentoot:content-type*) "text/plain") 6 (let* ((data-string (hunchentoot:raw-post-data :force-text t)) 7 (data (cl-json:decode-json-from-string json-data)) 8 ;; assume that the name of the animal is a hashed value: 9 (animal-name (gethash "name" data))) Network Programming 86 10 (setf (gethash animal-name *animal-hash*) data)) 11 "OK") In line 4 we are defining an additional easy handler with a handler argument json-data. This data is assumed to be a string encoding of JSON data which is decoded into Lisp data in lines 6 and 7. We save the data to the global variable animal-hash. In this example, we are storing data sent from a client in an in-memory hash table. In a real application new data might be stored in a database. Network Programming Wrap Up You have learned the basics for writing web services and writing clients to use web services. Later, we will use web services written in Python by writing Common Lisp clients: we will wrap retrained deep learning models and access them from Common Lisp. Using the Microsoft Bing Search APIs I have used the Bing search APIs for many years. Microsoft Bing supports several commercial search engine services, including my favorite search engine Duck Duck Go. Bing is now part of the Azure infrastructure that is branded as “Cognitive Services.” You should find the example code for this chapter relatively easy to extend to other Azure Cognitive Services that you might need to use. You will need to register with Microsoft’s Azure search service to use the material in this chapter. It is likely that you view search as a manual human-centered activity. I hope to expand your thinking to considering applications that automate search, finding information on the web, and automatically organizing information. While the example code uses only the search APIs, with some modification it can be extended to work with all REST APIs provided by Azure Cognitive Services³⁸ that include: analyzing text to get user intent, general language understanding, detecting key phrases and entity names, translate between languages, converting between speech and text, and various computer vision services. These services are generally free or very low cost for a few thousand API calls a month, with increased cost for production deployments. Microsoft spends about $1 billion a year in research and development for Azure Cognitive Services. Getting an Access Key for Microsoft Bing Search APIs You will need to set up an Azure account if you don’t already have one. I use the Bing search APIs fairly often for research but I have never spent more than about a dollar a month and usually I get no bill at all. For personal use it is a very inexpensive service. You start by going to the web page https://azure.microsoft.com/en-us/try/cognitive-services/³⁹ and sign up for an access key. The Search APIs sign up is currently in the fourth tab in this web form. When you navigate to the Search APIs tab, select the option Bing Search APIs v7. You will get an API key that you need to store in an environment variable that you will soon need: export BING_SEARCH_V7_SUBSCRIPTION_KEY=1e97834341d2291191c772b7371ad5b7 That is not my real subscription key! You also set the Bing search API as an environment variable: ³⁸https://azure.microsoft.com/en-us/services/cognitive-services/ ³⁹https://azure.microsoft.com/en-us/try/cognitive-services/ Using the Microsoft Bing Search APIs 88 export BING_SEARCH_V7_ENDPOINT=https://api.cognitive.microsoft.com/bing/v7.0/search Example Search Script Instead of using a pure Common Lisp HTTP client library I often prefer using the curl command run in a separate process. The curl utility handles all possible authentication modes, handles headers, response data in several formats, etc. We capture the output from curl in a string that in turn gets processed by a JSON library. It takes very little Common Lisp code to access the Bing search APIs. The function websearch makes a generic web search query. The function get-wikidata-uri uses the websearch function by adding “site:wikidata.org” to the query and returning only the WikiData URI for the original search term. We will later see several examples. I will list the entire library with comments to follow: 1 (in-package #:bing) 2 3 (defun get-wikidata-uri (query) 4 (let ((sr (websearch (concatenate 'string "site:wikidata.org " query)))) 5 (cadar sr))) 6 7 (defun websearch (query) 8 (let* ((key (uiop:getenv "BING_SEARCH_V7_SUBSCRIPTION_KEY")) 9 (endpoint (uiop:getenv "BING_SEARCH_V7_ENDPOINT")) 10 (command 11 (concatenate 12 'string 13 "curl -v -X GET \"" endpoint "?q=" 14 (drakma:url-encode query :utf-8) 15 "&mkt=en-US&limit=4\"" 16 " -H \"Ocp-Apim-Subscription-Key: " key "\"")) 17 (response 18 (uiop:run-program command :output :string))) 19 (with-input-from-string 20 (s response) 21 (let* ((json-as-list (json:decode-json s)) 22 (values (cdadr (cddr (nth 2 json-as-list))))) 23 (mapcar #'(lambda (x) 24 (let ((name (assoc :name x)) 25 (display-uri (assoc :display-url x)) 26 (snippet (assoc :snippet x))) 27 (list (cdr name) (cdr display-uri) (cdr snippet)))) 28 values))))) Using the Microsoft Bing Search APIs 89 We get the Bing access key and the search API endpoint in lines 8-9. Lines 10-16 create a complete call to the curl* command line utility. We spawn a process to run **curl and capture the string output in the variable response in lines 17-18. You might want to add a few print statements to see typical values for the variables command and response. The response data is JSON data encoded in a string, with straightforward code in lines 19-28 to parse out the values we want. The following repl listing shows this library in use: $ sbcl This is SBCL 2.0.2, an implementation of ANSI Common Lisp. * (ql:quickload "bing") To load "bing": Load 1 ASDF system: bing ; Loading "bing" .............. ("bing") * (bing:get-wikidata-uri "Sedona Arizona") "https://www.wikidata.org/wiki/Q80041" * (bing:websearch "Berlin") (("Berlin - Wikipedia" "https://en.wikipedia.org/wiki/Berlin" "Berlin (/ b￿￿r￿l￿n /; German: [b￿￿￿li￿n] (listen)) is the capital and largest cit\ y of Germany by both area and population. Its 3,769,495 (2019) inhabitants make it t\ he most populous city proper of the European Union. The city is one of Germany's 16 \ federal states.") ("THE 15 BEST Things to Do in Berlin - 2020 (with Photos ..." "https://www.tripadvisor.com/Attractions-g187323-Activities-Berlin.html" "Book your tickets online for the top things to do in Berlin, Germany on Tripadvis\ or: See 571,599 traveler reviews and photos of Berlin tourist attractions. Find what\ to do today, this weekend, or in August. We have reviews of the best places to see \ in Berlin. Visit top-rated & must-see attractions.") ("Berlin - Official Website of the City of Berlin, Capital ..." "https://www.berlin.de/en" "Official Website of Berlin: Information about the Administration, Events, Culture\ , Tourism, Hotels and Hotel Booking, Entertainment, Tickets, Public Transport, Polit\ ical System, Local Authorities and Business in Berlin.") ("Berlin | History, Map, Population, Attractions, & Facts ..." "https://www.britannica.com/place/Berlin" "Berlin is situated about 112 miles (180 km) south of the Baltic Sea, 118 miles (1\ 90 km) north of the Czech-German border, 110 miles (177 km) east of the former inner\ -German border, and 55 miles (89 km) west of Poland. It lies in the wide glacial val\ ley of the Spree River, which runs through the centre of the city.") ("Berlin travel | Germany - Lonely Planet" Using the Microsoft Bing Search APIs 90 "https://www.lonelyplanet.com/germany/berlin" "Welcome to Berlin Berlin's combo of glamour and grit is bound to mesmerise all th\ ose keen to explore its vibrant culture, cutting-edge architecture, fabulous food, i\ ntense parties and tangible history.") ("Berlin 2020: Best of Berlin, Germany Tourism - Tripadvisor" "https://www.tripadvisor.com/Tourism-g187323" "Berlin is an edgy city, from its fashion to its architecture to its charged polit\ ical history. The Berlin Wall is a sobering reminder of the hyper-charged postwar at\ mosphere, and yet the graffiti art that now covers its remnants has become symbolic \ of social progress.") ("Berlin 2020: Best of Berlin, OH Tourism - Tripadvisor" "https://www.tripadvisor.com/Tourism-g50087-Berlin_Ohio-Vacations.html" "Berlin Tourism: Tripadvisor has 11,137 reviews of Berlin Hotels, Attractions, and\ Restaurants making it your best Berlin resource.") ("Berlin (band) - Wikipedia" "https://en.wikipedia.org/wiki/Berlin_(band)" "Berlin is the alias for vocalist Terri Nunn, as well as the American new wave ban\ d she fronts, having been originally formed in Orange County, California. The band g\ ained mainstream-commercial success with singles including \" Sex (I'm A...) \", \" \ No More Words \" and the chart-topping \" Take My Breath Away \" from the 1986 film \ Top Gun.") ("Berlin's official travel website - visitBerlin.de" "https://www.visitberlin.de/en" "Berlin's way to a metropolis 100 Years of Greater Berlin In 1920, modern Berlin w\ as born at one fell swoop. 8 cities, 59 rural communities and 27 manor districts uni\ te to form \"Greater Berlin\"")) * I have been using the Bing search APIs for many years. They are a standard part of my application building toolkit. Wrap-up You can check out the wide range of Congitive Services⁴⁰ on the Azure site. Available APIs include: language detection, speech recognition, vision libraries for object recognition, web search, and anomaly detection in data. In addition to using automated web scraping to get data for my personal research, I often use automated web search. I find the Microsoft’s Azure Bing search APIs are the most convenient to use and I like paying for services that I use. ⁴⁰https://azure.microsoft.com/en-us/try/cognitive-services/ Accessing Relational Databases There are good options for accessing relational databases from Common Lisp. Personally I almost always use Postgres and in the past I used either native foreign client libraries or the socket interface to Postgres. Recently, I decided to switch to CLSQL⁴¹ which provides a common interface for accessing Postgres, MySQL, SQLite, and Oracle databases. There are also several recent forks of CLSQL on github. We will use CLSQL in examples in this book. Hopefully while reading the Chapter on Quicklisp you installed CLSQL and the back end for one or more databases that you use for your projects. For some database applications when I know that I will always use the embedded SQLite database (i.e., that I will never want to switch to Postgres of another database) I will just use the sqlite library as I do in chapter Knowledge Graph Navigator. If you have not installed CLSQL yet, then please install it now: (ql:quickload "clsql") You also need to install one or more CLSQL backends, depending on which relational databases you use: (ql:quickload "clsql-postgresql") (ql:quickload "clsql-mysql") (ql:quickload "clsql-sqlite3") The directory src/clsql_examples contains the standalone example files for this chapter. While I often prefer hand crafting SQL queries, there seems to be a general movement in software development towards the data mapper or active record design patterns. CLSQL provides Object Relational Mapping (ORM) functionality to CLOS. You will need to create a new database news in order to follow along with the examples in this chapter and later in this book. I will use Postgres for examples in this chapter and use the following to create a new database (my account is “markw” and the following assumes that I have Postgres configured to not require a password for this account when accessing the database from “localhost”): ⁴¹http://clsql.b9.com/ Accessing Relational Databases 92 1 -> ~ psql 2 psql (9.1.4) 3 Type "help" for help. 4 markw=# create database news; 5 CREATE DATABASE We will use three example programs that you can find in the src/clsql_examples directory in the book repository on github: • clsql_create_news_schema.lisp to create table “articles” in database “news” • clsql_write_to_news.lisp to write test data to table “articles” • clsql_read_from_news.lisp to read from the table “articles” The following listing shows the file src/clsql_examples/clsql_create_news_schema.lisp: 1 (ql:quickload :clsql) 2 (ql:quickload :clsql-postgresql) 3 4 ;; Postgres connection specification: 5 ;; (host db user password &optional port options tty). 6 ;; The first argument to **clsql:connect** is a connection 7 ;; specification list: 8 9 (clsql:connect '("localhost" "news" "markw" nil) 10 :database-type :postgresql) 11 12 (clsql:def-view-class articles () 13 ((id 14 :db-kind :key 15 :db-constraints :not-null 16 :type integer 17 :initarg :id) 18 (uri 19 :accessor uri 20 :type (string 60) 21 :initarg :uri) 22 (title 23 :accessor title 24 :type (string 90) 25 :initarg :title) 26 (text 27 :accessor text Accessing Relational Databases 93 28 :type (string 500) 29 :nulls-ok t 30 :initarg :text))) 31 32 (defun create-articles-table () 33 (clsql:create-view-from-class 'articles)) In this repl listing, we create the database table “articles” using the function create-articles-table that we just defined: 1 -> src git:(master) sbcl 2 (running SBCL from: /Users/markw/sbcl) 3 * (load "clsql_create_news_schema.lisp") 4 * (create-articles-table) 5 NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 6 "article_pk" for table "articles" 7 T 8 * The following listing shows the file src/clsql_examples/clsql_write_to_news.lisp: 1 (ql:quickload :clsql) 2 (ql:quickload :clsql-postgresql) 3 4 ;; Open connection to database and create CLOS class and database view 5 ;; for table 'articles': 6 (load "clsql_create_news_schema.lisp") 7 8 (defvar *a1* 9 (make-instance 10 'article 11 :uri "http://test.com" 12 :title "Trout Season is Open on Oak Creek" 13 :text "State Fish and Game announced the opening of trout season")) 14 15 (clsql:update-records-from-instance *a1*) 16 ;; modify a slot value and update database: 17 (setf (slot-value *a1* 'title) "Trout season is open on Oak Creek!!!") 18 (clsql:update-records-from-instance *a1*) 19 ;; warning: the last statement changes the "id" column in the table You should load the file clsql_write_to_news.lisp one time in a repl to create the test data. The following listing shows file clsql_read_from_news.lisp: Accessing Relational Databases 94 1 (ql:quickload :clsql) 2 (ql:quickload :clsql-postgresql) 3 4 ;; Open connection to database and create CLOS class and database view 5 ;; for table 'articles': 6 (load "clsql_create_news_schema.lisp") 7 8 (defun pp-article (article) 9 (format t 10 "~%URI: ~S ~%Title: ~S ~%Text: ~S ~%" 11 (slot-value article 'uri) 12 (slot-value article 'title) 13 (slot-value article 'text))) 14 15 (dolist (a (clsql:select 'article)) 16 (pp-article (car a))) Loading the file clsql_read_from_news.lisp produces the following output: 1 URI: "http://test.com" 2 Title: "Trout season is open on Oak Creek!!!" 3 Text: "State Fish and Game announced the opening of trout season" 4 5 URI: "http://example.com" 6 Title: "Longest day of year" 7 Text: "The summer solstice is on Friday." You can also embed SQL where clauses in queries: (dolist (a (clsql:select 'article :where "title like '%season%'")) (pp-article (car a))) which produces this output: 1 URI: "http://test.com" 2 Title: "Trout season is open on Oak Creek!!!" 3 Text: "State Fish and Game announced the opening of 4 trout season" In this example, I am using a SQL like expression to perform partial text matching. Accessing Relational Databases 95 Database Wrap Up You learned the basics for accessing relational databases. When I am designing new systems for processing data I like to think of my Common Lisp code as being purely functional: my Lisp functions accept arguments that they do not modify and return results. I like to avoid side effects, that is changing global state. When I do have to handle mutable state (or data) I prefer storing mutable state in an external database. I use this same approach when I use the Haskell functional programming language. Using MongoDB, Solr NoSQL Data Stores Non-relational data stores are commonly used for applications that don’t need either full relational algebra or must scale. The MongoDB example code is in the file src/loving_snippets/mongo_news.lisp. The Solr example code is in the subdirectories src/solr_examples. Note for the fifth edition: The Common Lisp cl-mongo library is now unsupported for versions of MongoDB later than 2.6 (released in 2016). You can install an old version of MongoDB for macOS⁴² or for Linux⁴³. I have left the MongoDB examples in this section but I can’t recommend that you use cl-mongo and MongoDB for any serious applications. Brewer’s CAP theorem states that a distributed data storage system comprised of multiple nodes can be robust to two of three of the following guarantees: all nodes always have a Consistent view of the state of data, general Availablity of data if not all nodes are functioning, and Partition tolerance so clients can still communicate with the data storage system when parts of the system are unavailable because of network failures. The basic idea is that different applications have different requirements and sometimes it makes sense to reduce system cost or improve scalability by easing back on one of these requirements. A good example is that some applications may not need transactions (the first guarantee) because it is not important if clients sometimes get data that is a few seconds out of date. MongoDB allows you to choose consistency vs. availability vs. efficiency. I cover the Solr indexing and search service (based on Lucene) both because a Solr indexed document store is a type of NoSQL data store and also because I believe that you will find Solr very useful for building systems, if you don’t already use it. MongoDB The following discussion of MongoDB is based on just my personal experience, so I am not covering all use cases. I have used MongoDB for: • Small clusters of MongoDB nodes to analyze social media data, mostly text mining and sentiment analysis. In all cases for each application I ran MongoDB with one write master ⁴²https://www.mongodb.org/dl/osx ⁴³https://www.mongodb.org/dl/linux Using MongoDB, Solr NoSQL Data Stores 97 (i.e., I wrote data to this one node but did not use it for reads) and multiple read-only slave nodes. Each slave node would run on the same server that was usually performing a single bit of analytics. • Multiple very large independent clusters for web advertising. Problems faced included trying to have some level of consistency across data centers. Replica sets were used within each data center. • Running a single node MongoDB instance for low volume data collection and analytics. One of the advantages of MongoDB is that it is very “developer friendly” because it supports ad- hoc document schemas and interactive queries. I mentioned that MongoDB allows you to choose consistency vs. availability vs. efficiency. When you perform MongoDB writes you can specify some granularity of what constitutes a “successful write” by requiring that a write is performed at a specific number of nodes before the client gets acknowledgement that the write was successful. This requirement adds overhead to each write operation and can cause writes to fail if some nodes are not available. The MongoDB online documentation⁴⁴ is very good. You don’t have to read it in order to have fun playing with the following Common Lisp and MongoDB examples, but if you find that MongoDB is a good fit for your needs after playing with these examples then you should read the documentation. I usually install MongoDB myself but it is sometimes convenient to use a hosting service. There are several well regarded services and I have used MongoHQ⁴⁵. At this time there is no official Common Lisp support for accessing MongoDB but there is a useful project by Alfons Haffmans’ cl-mongo⁴⁶ that will allow us to write Common Lisp client applications and have access to most of the capabilities of MongoDB. The file src/mongo_news.lisp contains the example code used in the next three sessions. Adding Documents The following repl listing shows the cl-mongo APIs for creating a new document, adding elements (attributes) to it, and inserting it in a MongoDB data store: ⁴⁴http://docs.mongodb.org/manual/ ⁴⁵https://www.mongohq.com/ ⁴⁶https://github.com/fons/cl-mongo Using MongoDB, Solr NoSQL Data Stores 98 (ql:quickload "cl-mongo") (cl-mongo:db.use "news") (defun add-article (uri title text) (let ((doc (cl-mongo:make-document))) (cl-mongo:add-element "uri" uri doc) (cl-mongo:add-element "title" title doc) (cl-mongo:add-element "text" text doc) (cl-mongo:db.insert "article" doc))) ;; add a test document: (add-article "http://test.com" "article title 1" "article text 1") In this example, three string attributes were added to a new document before it was saved. Fetching Documents by Attribute We will start by fetchng and pretty-printing all documents in the collection articles and fetching all articles a list of nested lists where the inner nested lists are document URI, title, and text: 1 (defun print-articles () 2 (cl-mongo:pp (cl-mongo:iter (cl-mongo:db.find "article" :all)))) 3 4 ;; for each document, use the cl-mongo:get-element on 5 ;; each element we want to save: 6 (defun article-results->lisp-data (mdata) 7 (let ((ret '())) 8 ;;(print (list "size of result=" (length mdata))) 9 (dolist (a mdata) 10 ;;(print a) 11 (push 12 (list 13 (cl-mongo:get-element "uri" a) 14 (cl-mongo:get-element "title" a) 15 (cl-mongo:get-element "text" a)) 16 ret))) 17 ret)) 18 19 (defun get-articles () 20 (article-results->lisp-data 21 (cadr (cl-mongo:db.find "article" :all)))) Output for these two functions looks like: Using MongoDB, Solr NoSQL Data Stores 99 1 * (print-articles) 2 3 { 4 "_id" -> objectid(99778A792EBB4F76B82F75C6) 5 "uri" -> http://test.com/3 6 "title" -> article title 3 7 "text" -> article text 3 8 } 9 10 { 11 "_id" -> objectid(D47DEF3CFDB44DEA92FD9E56) 12 "uri" -> http://test.com/2 13 "title" -> article title 2 14 "text" -> article text 2 15 } 16 17 * (get-articles) 18 19 (("http://test.com/2" "article title 2" "article text 2") 20 ("http://test.com/3" "article title 3" "article text 3")) Fetching Documents by Regular Expression Text Search By reusing the function article-results->lisp-data defined in the last section, we can also search for JSON documents using regular expressions matching attribute values: 1 ;; find documents where substring 'str' is in the title: 2 (defun search-articles-title (str) 3 (article-results->lisp-data 4 (cadr 5 (cl-mongo:iter 6 (cl-mongo:db.find 7 "article" 8 (cl-mongo:kv 9 "title" // TITLE ATTRIBUTE 10 (cl-mongo:kv "$regex" str)) :limit 10))))) 11 12 ;; find documents where substring 'str' is in the text element: 13 (defun search-articles-text (str) 14 (article-results->lisp-data 15 (cadr 16 (cl-mongo:db.find Using MongoDB, Solr NoSQL Data Stores 100 17 "article" 18 (cl-mongo:kv 19 "text" // TEXT ATTRIBUTE 20 (cl-mongo:kv "$regex" str)) :limit 10)))) I set the limit to return a maximum of ten documents. If you do not set the limit, this example code only returns one search result. The following repl listing shows the results from calling function search-articles-text: 1 * (SEARCH-ARTICLES-TEXT "text") 2 3 (("http://test.com/2" "article title 2" "article text 2") 4 ("http://test.com/3" "article title 3" "article text 3")) 5 * (SEARCH-ARTICLES-TEXT "3") 6 7 (("http://test.com/3" "article title 3" "article text 3")) I find using MongoDB to be especially effective when experimenting with data and code. The schema free JSON document format, using interactive queries using the mongo shell⁴⁷, and easy to use client libraries like clouchdb for Common Lisp will let you experiment with a lot of ideas in a short period of time. The following listing shows the use of the interactive mongo shell. The database news is the database used in the MongoDB examples in this chapter; you will notice that I also have other databases for other projects on my laptop: 1 -> src git:(master) mongo 2 MongoDB shell version: 2.4.5 3 connecting to: test 4 > show dbs 5 kbsportal 0.03125GB 6 knowledgespace 0.03125GB 7 local (empty) 8 mark_twitter 0.0625GB 9 myfocus 0.03125GB 10 news 0.03125GB 11 nyt 0.125GB 12 twitter 0.125GB 13 > use news 14 switched to db news 15 > show collections 16 article 17 system.indexes ⁴⁷http://docs.mongodb.org/manual/mongo/ Using MongoDB, Solr NoSQL Data Stores 101 18 > db.article.find() 19 { "uri" : "http://test.com/3", 20 "title" : "article title 3", 21 "text" : "article text 3", 22 "_id" : ObjectId("99778a792ebb4f76b82f75c6") } 23 { "uri" : "http://test.com/2", 24 "title" : "article title 2", 25 "text" : "article text 2", 26 "_id" : ObjectId("d47def3cfdb44dea92fd9e56") } 27 > Line 1 of this listing shows starting the mongo shell. Line 4 shows how to list all databases in the data store. In line 13 I select the database “news” to use. Line 15 prints out the names of all collections in the current database “news”. Line 18 prints out all documents in the “articles” collection. You can read the documentation for the mongo shell⁴⁸ for more options like selective queries, adding indices, etc. When you run a MongoDB service on your laptop, also try the admin interface on http://localhost:28017/⁴⁹. A Common Lisp Solr Client The Lucene project is one of the most widely used Apache Foundation projects. Lucene is a flexible library for preprocessing and indexing text, and searching text. I have personally used Lucene on so many projects that it would be difficult to count them. The Apache Solr Project⁵⁰ adds a network interface to the Lucene text indexer and search engine. Solr also adds other utility features to Lucene: • While Lucene is a library to embed in your programs, Solr is a complete system. • Solr provides good defaults for preprocessing and indexing text and also provides rich support for managing structured data. • Provides both XML and JSON APIs using HTTP and REST. • Supports faceted search, geospatial search, and provides utilities for highlighting search terms in surrounding text of search results. • If your system ever grows to a very large number of users, Solr supports scaling via replication. I hope that you will find the Common Lisp example Solr client code in the following sections helps you make Solr part of large systems that you write using Common Lisp. Installing Solr Download a binary Solr distribution⁵¹ and un-tar or un-zip this Solr distribution, cd to the distribution directory, then cd to the example directory and run: ⁴⁸http://docs.mongodb.org/manual/mongo/ ⁴⁹http://localhost:28017/ ⁵⁰https://lucene.apache.org/solr/ ⁵¹https://lucene.apache.org/solr/downloads.html Using MongoDB, Solr NoSQL Data Stores 102 1 ~/solr/example> java -jar start.jar You can access the Solr Admin Web App at http://localhost:8983/solr/#/⁵². This web app can be seen in the following screen shot: Solr Admin Web App There is no data in the Solr example index yet, so following the Solr tutorial instructions: ⁵²http://localhost:8983/solr/#/ Using MongoDB, Solr NoSQL Data Stores 103 1 ~/> cd ~/solr/example/exampledocs 2 ~/solr/example/exampledocs> java -jar post.jar *.xml 3 SimplePostTool version 1.5 4 Posting files to base url http://localhost:8983/solr/update 5 using content-type application/xml.. 6 POSTing file gb18030-example.xml 7 POSTing file hd.xml 8 POSTing file ipod_other.xml 9 POSTing file ipod_video.xml 10 POSTing file manufacturers.xml 11 POSTing file mem.xml 12 POSTing file money.xml 13 POSTing file monitor.xml 14 POSTing file monitor2.xml 15 POSTing file mp500.xml 16 POSTing file sd500.xml 17 POSTing file solr.xml 18 POSTing file utf8-example.xml 19 POSTing file vidcard.xml 20 14 files indexed. 21 COMMITting Solr index changes 22 to http://localhost:8983/solr/update.. 23 Time spent: 0:00:00.480 You will learn how to add documents to Solr directly in your Common Lisp programs in a later section. Assuming that you have a fast Internet connection so that downloading Solr was quick, you have hopefully spent less than five or six minutes getting Solr installed and running with enough example search data for the Common Lisp client examples we will play with. Solr is a great tool for storing, indexing, and searching data. I recommend that you put off reading the official Solr documentation for now and instead work through the Common Lisp examples in the next two sections. Later, if you want to use Solr then you will need to carefully read the Solr documentation. Solr’s REST Interface The Solr REST Interface Documentation⁵³ documents how to perform search using HTTP GET requests. All we need to do is implement this in Common Lisp which you will see is easy. Assuming that you have Solr running and the example data loaded, we can try searching for docu- ments with, for example, the word “British” using the URL http://localhost:8983/solr/select?q=British⁵⁴. This is a REST request URL and you can use utilities like curl or wget to fetch the XML data. I fetched ⁵³https://wiki.apache.org/solr/SolJSON ⁵⁴http://localhost:8983/solr/select?q=British Using MongoDB, Solr NoSQL Data Stores 104 the data in a web browser, as seen in the following screen shot of a Firefox web browser (I like the way Firefox formats and displays XML data): Solr Search Results as XML Data The attributes in the returned search results need some explanation. We indexed several example XML data files, one of which contained the following XML element that we just saw as a search result: 1 2 GBP 3 One British Pound 4 U.K. 5 uk 6 currency 7 Coins and notes 8 1,GBP 9 true 10 Using MongoDB, Solr NoSQL Data Stores 105 So, the search result has the same attributes as the structured XML data that was added to the Solr search index. Solr’s capability for indexing structured data is a superset of just indexing plain text. If for example we were indexing news stories, then example input data might look like: 1 2 new_story_0001 3 Fishing Season Opens 4 Fishing season opens on Friday in Oak Creek. 5 With this example, a search result that returned this document as a result would return attributes id, title, and text, and the values of these three attributes. By default the Solr web service returns XML data as seen in the last screen shot. For our examples, I prefer using JSON so we are going to always add a request parameter wt=json to all REST calls. The following screen shot shows the same data returned in JSON serialization format instead of XML format of a Chrome web browser (I like the way Chrome formats and displays JSON data with the JSONView Chrome Browser extension): Solr Search Results as JSON Data Using MongoDB, Solr NoSQL Data Stores 106 You can read the full JSON REST Solr documentation later, but for our use here we will use the following search patterns: • http://localhost:8983/solr/select?q=British+One&wt=json - search for documents with either of the words “British” or “one” in them. Note that in URIs that the “+” character is used to encode a space character. If you wanted a “+” character you would encode it with “%2B” and a space character is encoded as “%20”. The default Solr search option is an OR of the search terms, unlike, for example, Google Search. • http://localhost:8983/solr/select?q=British+AND+one&wt=json - search for documents that contain both of the words “British” and “one” in them. The search term in plain text is “British AND one”. Common Lisp Solr Client for Search As we sawearlier in Network Programming it is fairly simple to use the drakma and cl-json Common Lisp libraries to call REST services that return JSON data. The function do-search defined in the next listing (all the Solr example code is in the file src/solr-client.lisp) constructs a query URI as we saw in the last section and uses the Drackma library to perform an HTTP GET operation and the cl-json library to parse the returned string containing JSON data into Lisp data structures: (ql:quickload :drakma) (ql:quickload :cl-json) (defun do-search (&rest terms) (let ((query-string (format nil "~{~A~^+AND+~}" terms))) (cl-json:decode-json-from-string (drakma:http-request (concatenate 'string "http://localhost:8983/solr/select?q=" query-string "&wt=json"))))) This example code does return the search results as Lisp list data; for example: Using MongoDB, Solr NoSQL Data Stores 107 1 * (do-search "British" "one") 2 3 ((:RESPONSE-HEADER (:STATUS . 0) (:*Q-TIME . 1) 4 (:PARAMS (:Q . "British+AND+one") (:WT . "json"))) 5 (:RESPONSE (:NUM-FOUND . 6) (:START . 0) 6 (:DOCS 7 ((:ID . "GBP") (:NAME . "One British Pound") (:MANU . "U.K.") 8 (:MANU--ID--S . "uk") (:CAT "currency") 9 (:FEATURES "Coins and notes") 10 (:PRICE--C . "1,GBP") (:IN-STOCK . T) 11 (:--VERSION-- . 1440194917628379136)) 12 ((:ID . "USD") (:NAME . "One Dollar") 13 (:MANU . "Bank of America") 14 (:MANU--ID--S . "boa") (:CAT "currency") 15 (:FEATURES "Coins and notes") 16 (:PRICE--C . "1,USD") (:IN-STOCK . T) 17 (:--VERSION-- . 1440194917624184832)) 18 ((:ID . "EUR") (:NAME . "One Euro") 19 (:MANU . "European Union") 20 (:MANU--ID--S . "eu") (:CAT "currency") 21 (:FEATURES "Coins and notes") 22 (:PRICE--C . "1,EUR") (:IN-STOCK . T) 23 (:--VERSION-- . 1440194917626281984)) 24 ((:ID . "NOK") (:NAME . "One Krone") 25 (:MANU . "Bank of Norway") 26 (:MANU--ID--S . "nor") (:CAT "currency") 27 (:FEATURES "Coins and notes") 28 (:PRICE--C . "1,NOK") (:IN-STOCK . T) 29 (:--VERSION-- . 1440194917631524864)) 30 ((:ID . "0579B002") 31 (:NAME . "Canon PIXMA MP500 All-In-One Photo Printer") 32 (:MANU . "Canon Inc.") 33 (:MANU--ID--S . "canon") 34 (:CAT "electronics" "multifunction printer" 35 "printer" "scanner" "copier") 36 (:FEATURES "Multifunction ink-jet color photo printer" 37 "Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi" 38 "2.5\" color LCD preview screen" "Duplex Copying" 39 "Printing speed up to 29ppm black, 19ppm color" "Hi-Speed USB" 40 "memory card: CompactFlash, Micro Drive, SmartMedia, 41 Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard") 42 (:WEIGHT . 352.0) (:PRICE . 179.99) 43 (:PRICE--C . "179.99,USD") Using MongoDB, Solr NoSQL Data Stores 108 44 (:POPULARITY . 6) (:IN-STOCK . T) 45 (:STORE . "45.19214,-93.89941") 46 (:--VERSION-- . 1440194917651447808)) 47 ((:ID . "SOLR1000") 48 (:NAME . "Solr, the Enterprise Search Server") 49 (:MANU . "Apache Software Foundation") 50 (:CAT "software" "search") 51 (:FEATURES "Advanced Full-Text Search Capabilities using Lucene" 52 "Optimized for High Volume Web Traffic" 53 "Standards Based Open Interfaces - XML and HTTP" 54 "Comprehensive HTML Administration Interfaces" 55 "Scalability - Efficient Replication to other Solr Search Servers" 56 "Flexible and Adaptable with XML configuration and Schema" 57 "Good unicode support: héllo (hello with an accent over the e)") 58 (:PRICE . 0.0) (:PRICE--C . "0,USD") (:POPULARITY . 10) (:IN-STOCK . T) 59 (:INCUBATIONDATE--DT . "2006-01-17T00:00:00Z") 60 (:--VERSION-- . 1440194917671370752))))) I might modify the search function to return just the fetched documents as a list, discarding the returned Solr meta data: 1 * (cdr (cadddr (cadr (do-search "British" "one")))) 2 3 (((:ID . "GBP") (:NAME . "One British Pound") (:MANU . "U.K.") 4 (:MANU--ID--S . "uk") (:CAT "currency") (:FEATURES "Coins and notes") 5 (:PRICE--C . "1,GBP") (:IN-STOCK . T) 6 (:--VERSION-- . 1440194917628379136)) 7 ((:ID . "USD") (:NAME . "One Dollar") (:MANU . "Bank of America") 8 (:MANU--ID--S . "boa") (:CAT "currency") (:FEATURES "Coins and notes") 9 (:PRICE--C . "1,USD") (:IN-STOCK . T) 10 (:--VERSION-- . 1440194917624184832)) 11 ((:ID . "EUR") (:NAME . "One Euro") (:MANU . "European Union") 12 (:MANU--ID--S . "eu") (:CAT "currency") (:FEATURES "Coins and notes") 13 (:PRICE--C . "1,EUR") (:IN-STOCK . T) 14 (:--VERSION-- . 1440194917626281984)) 15 ((:ID . "NOK") (:NAME . "One Krone") (:MANU . "Bank of Norway") 16 (:MANU--ID--S . "nor") (:CAT "currency") 17 (:FEATURES "Coins and notes") 18 (:PRICE--C . "1,NOK") (:IN-STOCK . T) 19 (:--VERSION-- . 1440194917631524864)) 20 ((:ID . "0579B002") 21 (:NAME . "Canon PIXMA MP500 All-In-One Photo Printer") 22 (:MANU . "Canon Inc.") (:MANU--ID--S . "canon") Using MongoDB, Solr NoSQL Data Stores 109 23 (:CAT "electronics" "multifunction printer" "printer" 24 "scanner" "copier") 25 (:FEATURES "Multifunction ink-jet color photo printer" 26 "Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi" 27 "2.5\" color LCD preview screen" "Duplex Copying" 28 "Printing speed up to 29ppm black, 19ppm color" "Hi-Speed USB" 29 "memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, 30 Memory Stick Pro, SD Card, and MultiMediaCard") 31 (:WEIGHT . 352.0) (:PRICE . 179.99) (:PRICE--C . "179.99,USD") 32 (:POPULARITY . 6) (:IN-STOCK . T) (:STORE . "45.19214,-93.89941") 33 (:--VERSION-- . 1440194917651447808)) 34 ((:ID . "SOLR1000") (:NAME . "Solr, the Enterprise Search Server") 35 (:MANU . "Apache Software Foundation") (:CAT "software" "search") 36 (:FEATURES "Advanced Full-Text Search Capabilities using Lucene" 37 "Optimized for High Volume Web Traffic" 38 "Standards Based Open Interfaces - XML and HTTP" 39 "Comprehensive HTML Administration Interfaces" 40 "Scalability - Efficient Replication to other Solr Search Servers" 41 "Flexible and Adaptable with XML configuration and Schema" 42 "Good unicode support: héllo (hello with an accent over the e)") 43 (:PRICE . 0.0) (:PRICE--C . "0,USD") (:POPULARITY . 10) (:IN-STOCK . T) 44 (:INCUBATIONDATE--DT . "2006-01-17T00:00:00Z") 45 (:--VERSION-- . 1440194917671370752))) There are a few more important details if you want to add Solr search to your Common Lisp applications. When there are many search results you might want to fetch a limited number of results and then “page” through them. The following strings can be added to the end of a search query: • &rows=2 this example returns a maximum of two “rows” or two query results. • &start=4 this example skips the first 4 available results A query that combines skipping results and limiting the number of returned results looks like this: 1 http://localhost:8983/solr/select?q=British+One&wt=json&start=2&rows=2 Common Lisp Solr Client for Adding Documents In the last example we relied on adding example documents to the Solr search index using the directions for setting up a new Solr installation. In a real application, in addition to performing search requests for indexed documents you will need to add new documents from your Lisp applications. Using the Drakma we will see that it is very easy to add documents. We need to construct a bit of XML containing new documents in the form: Using MongoDB, Solr NoSQL Data Stores 110 1 2 3 123456 4 Fishing Season 5 6 You can specify whatever field names (attributes) that are required for your application. You can also pass multiple elements in one add request. We will want to specify documents in a Lisp-like way: a list of cons values where each cons value is a field name and a value. For the last XML document example we would like an API that lets us just deal with Lisp data like: (do-add '(("id" . "12345") ("title" . "Fishing Season"))) One thing to note: the attribute names and values must be passed as strings. Other data types like integers, floating point numbers, structs, etc. will not work. This is nicer than having to use XML, right? The first thing we need is a function to convert a list of cons values to XML. I could have used the XML Builder functionality in the cxml library that is available via Quicklisp, but for something this simple I just wrote it in pure Common Lisp with no other dependencies (also in the example file src/solr-client.lisp) : 1 (defun keys-values-to-xml-string (keys-values-list) 2 (with-output-to-string (stream) 3 (format stream "") 4 (dolist (kv keys-values-list) 5 (format stream "") 8 (format stream (cdr kv)) 9 (format stream "\"")) 10 (format stream ""))) The macro with-output-to-string on line 2 of the listing is my favorite way to generate strings. Everything written to the variable stream inside the macro call is appended to a string; this string is the return value of the macro. The following function adds documents to the Solr document input queue but does not actually index them: Using MongoDB, Solr NoSQL Data Stores 111 1 (defun do-add (keys-values-list) 2 (drakma:http-request 3 "http://localhost:8983/solr/update" 4 :method :post 5 :content-type "application/xml" 6 :content ( keys-values-to-xml-string keys-values-list))) You have noticed in line 3 that I am accessing a Solr server running on localhost and not a remote server. In an application using a remote Solr server you would need to modify this to reference your server; for example: 1 "http://solr.knowledgebooks.com:8983/solr/update" For efficiency Solr does not immediately add new documents to the index until you commit the additions. The following function should be called after you are done adding documents to actually add them to the index: (defun commit-adds () (drakma:http-request "http://localhost:8983/solr/update" :method :post :content-type "application/xml" :content "")) Notice that all we need is an empty element that signals the Solr server that it should index all recently added documents. The following repl listing shows everything working together (I am assuming that the contents of the file src/solr-client.lisp has been loaded); not all of the output is shown in this listing: * (do-add '(("id" . "12345") ("title" . "Fishing Season"))) 200 ((:CONTENT-TYPE . "application/xml; charset=UTF-8") (:CONNECTION . "close")) # # T "OK" * (commit-adds) 200 ((:CONTENT-TYPE . "application/xml; charset=UTF-8") Using MongoDB, Solr NoSQL Data Stores 112 (:CONNECTION . "close")) # # T "OK" * (do-search "fishing") ((:RESPONSE-HEADER (:STATUS . 0) (:*Q-TIME . 2) (:PARAMS (:Q . "fishing") (:WT . "json"))) (:RESPONSE (:NUM-FOUND . 1) (:START . 0) (:DOCS ((:ID . "12345\"") (:TITLE "Fishing Season\"") (:--VERSION-- . 1440293991717273600))))) * Common Lisp Solr Client Wrap Up Solr has a lot of useful features that we have not used here like supporting faceted search (drilling down in previous search results), geolocation search, and looking up indexed documents by attribute. In the examples I have shown you, all text fields are indexed but Solr optionally allows you fine control over indexing, spelling correction, word stemming, etc. Solr is a very capable tool for storing, indexing, and searching data. I have seen Solr used effectively on projects as a replacement for a relational database or other NoSQL data stores like CouchDB or MongoDB. There is a higher overhead for modifying or removing data in Solr so for applications that involve frequent modifications to stored data Solr might not be a good choice. NoSQL Wrapup There are more convenient languages than Common Lisp to use for accessing MongoDB. To be honest, my favorites are Ruby and Clojure. That said, for applications where the advantages of Common Lisp are compelling, it is good to know that your Common Lisp applications can play nicely with MongoDB. I am a polyglot programmer: I like to use the best programming language for any specific job. When we design and build systems with more than one programming language, there are several options to share data: • Use foreign function interfaces to call one language from another from inside one process. • Use a service architecture and send requests using REST or SOAP. • Use shared data stores, like relational databases, MongoDB, CouchDB and Solr. Hopefully this chapter and the last chapter will provide most of what you need for the last option. Natural Language Processing Natural Language Processing (NLP) is the automated processing of natural language text with several goals: • Determine the parts of speech (POS tagging) of words based on the surrounding words. • Detect if two text documents are similar. • Categorize text (e.g., is it about the economy, politics, sports, etc.) • Summarize text • Determine the sentiment of text • Detect names (e.g., place names, people’s names, product names, etc.) We will use a library that I wrote that performs POS tagging, categorization (classification), summarization, and detects proper names. My example code for this chapter is contained in separate Quicklisp projects located in the subdirectories: • src/fasttag: performs part of speech tagging and tokenizes text • src/categorize_summarize: performs categorization (e.g., detects the topic of text is news, politics, economy, etc.) and text summarization • src/kbnlp: the top level APIs for my pure Common Lisp natural language processing (NLP) code. In later chapters we will take a different approach by using Python deep learning models for NLP that we call as a web service. I use both approaches in my own work. I worked on this Lisp code, and also similar code in Java, from about 2001 to 2011, and again in 2019 for my application for generating knowledge graph data automatically (this is an example in a later chapter). I am going to begin the next section with a quick explanation of how to run the example code. If you find the examples interesting then you can also read the rest of this chapter where I explain how the code works. The approach that I used in my library for categorization (word counts) is now dated. I recommend that you consider taking Andrew Ng’s course on Machine Learning on the free online Coursera system and then take one of the Coursera NLP classes for a more modern treatment of NLP. In addition to the code for my library you might also find the linguistic data in src/linguistic_data useful. Loading and Running the NLP Library I repackaged the NLP example code into one long file. The code used to be split over 18 source files. The code should be loaded from the src/kbnlp directory: Natural Language Processing 114 1 % loving-common-lisp git:(master) > cd src/kbnlp 2 % src/kbnlp git:(master) > sbcl 3 * (ql:quickload "kbnlp") 4 5 "Startng to load data...." 6 "....done loading data." 7 * This also loads the projects in src/fasttag and src/categorize_summarize. Unfortunately, it takes about a minute using SBCL to load the required linguistic data so I recommend creating a Lisp image that can be reloaded to avoid the time required to load the data: 1 * (sb-ext:save-lisp-and-die "nlp-image" :purify t) 2 [undoing binding stack and other enclosing state... done] 3 [saving current Lisp image into nlp-image: 4 writing 5280 bytes from the read-only space at 0x0x20000000 5 writing 3088 bytes from the static space at 0x0x20100000 6 writing 80052224 bytes from the dynamic space at 0x0x1000000000 7 done] 8 % src git:(master) > ls -lh nlp-image 9 -rw-r--r-- 1 markw staff 76M Jul 13 12:49 nlp-image In line 1 in this repl listing, I use the SBCL built-in function save-lisp-and-die to create the Lisp image file. Using save-lisp-and-die is a great technique to use whenever it takes a while to set up your work environment. Saving a Lisp image for use the next time you work on a Common Lisp project is reminiscent of working in Smalltalk where your work is saved between sessions in an image file. Note: I often use Clozure-CL (CCL) instead of SBCL for developing my NLP libraries because CCL loads my data files much faster than SBCL. You can now start SBCL with the NLP library and data preloaded using the Lisp image that you just created: 1 % src git:(master) > sbcl --core nlp-image 2 * (in-package :kbnlp) 3 4 # 5 * (defvar 6 *x* 7 (make-text-object 8 "President Bob Smith talked to Congress about the economy and taxes")) 9 Natural Language Processing 115 10 *X* 11 12 * *X* 13 14 #S(TEXT 15 :URL "" 16 :TITLE "" 17 :SUMMARY "" 18 :CATEGORY-TAGS (("news_politics.txt" 0.01648) 19 ("news_economy.txt" 0.01601)) 20 :KEY-WORDS NIL 21 :KEY-PHRASES NIL 22 :HUMAN-NAMES ("President Bob Smith") 23 :PLACE-NAMES NIL 24 :TEXT #("President" "Bob" "Smith" "talked" "to" "Congress" "about" "the" 25 "economy" "and" "taxes") 26 :TAGS #("NNP" "NNP" "NNP" "VBD" "TO" "NNP" "IN" "DT" "NN" "CC" "NNS") 27 :STEMS #("presid" "bob" "smith" "talk" "to" "congress" "about" "the" 28 "economi" "and" "tax")) 29 * At the end of the file src/knowledgebooks_nlp.lisp in comments is some test code that processes much more text so that a summary is also generated; here is a bit of the output you will see if you load the test code into your repl: 1 (:SUMMARY 2 "Often those amendments are an effort to change government policy 3 by adding or subtracting money for carrying it out. The initial 4 surge in foreclosures in 2007 and 2008 was tied to subprime 5 mortgages issued during the housing boom to people with shaky 6 credit. 2 trillion in annual appropriations bills for funding 7 most government programs — usually low profile legislation that 8 typically dominates the work of the House in June and July. 9 Bill Clinton said that banking in Europe is a good business. 10 These days homeowners who got fixed rate prime mortgages because 11 they had good credit cannot make their payments because they are 12 out of work. The question is whether or not the US dollar remains 13 the world s reserve currency if not the US economy will face 14 a depression." 15 :CATEGORY-TAGS (("news_politics.txt" 0.38268) 16 ("news_economy.txt" 0.31182) 17 ("news_war.txt" 0.20174)) Natural Language Processing 116 18 :HUMAN-NAMES ("President Bill Clinton") 19 :PLACE-NAMES ("Florida")) The top-level function make-text-object takes one required argument that can be either a string containing text or an array of strings where each string is a word or punctuation. Function make- text-object has two optional keyword parameters: the URL where the text was found and a title. 1 (defun make-text-object (words &key (url "") (title "")) 2 (if (typep words 'string) (setq words (words-from-string words))) 3 (let* ((txt-obj (make-text :text words :url url :title title))) 4 (setf (text-tags txt-obj) (part-of-speech-tagger words)) 5 (setf (text-stems txt-obj) (stem-text txt-obj)) 6 ;; note: we must find human and place names before calling 7 ;; pronoun-resolution: 8 (let ((names-places (find-names-places txt-obj))) 9 (setf (text-human-names txt-obj) (car names-places)) 10 (setf (text-place-names txt-obj) (cadr names-places))) 11 (setf (text-category-tags txt-obj) 12 (mapcar 13 #'(lambda (x) 14 (list 15 (car x) 16 (/ (cadr x) 1000000.0))) 17 (get-word-list-category (text-text txt-obj)))) 18 (setf (text-summary txt-obj) (summarize txt-obj)) 19 txt-obj)) In line 2, we check if this function was called with a string containing text in which case the function words-from-string is used to tokenize the text into an array of string tokens. Line two defines the local variable txt-obj with the value of a new text object with only three slots (attributes) defined: text, url, and title. Line 4 sets the slot text-tags to the part of speech tokens using the function part- of-speech-tagger. We use the function find-names-places in line 8 to get person and place names and store these values in the text object. In lines 11 through 17 we use the function get-word-list- category to set the categories in the text object. In line 18 we similarly use the function summarize to calculate a summary of the text and also store it in the text object. We will discuss these NLP helper functions throughout the rest of this chapter. The function make-text-object returns a struct that is defined as: Natural Language Processing 117 (defstruct text url title summary category-tags key-words key-phrases human-names place-names text tags stems) Part of Speech Tagging This tagger is the Common Lisp implementation of my FastTag open source project. I based this project on Eric Brill’s PhD thesis (1995). He used machine learning on annotated text to learn tagging rules. I used a subset of the tagging rules that he generated that were most often used when he tested his tagger. I hand coded his rules in Lisp (and Ruby, Java, and Pascal). My tagger is less accurate, but it is fast - thus the name FastTag. If you just need part of speech tagging (and not summarization, categorization, and top level APIs used in the last section) you can load: 1 (ql:quickload "fasttag") You can find the tagger implementation in the function part-of-speech-tagger. We already saw sample output from the tagger in the last section: 1 :TEXT #("President" "Bob" "Smith" "talked" "to" "Congress" "about" "the" 2 "economy" "and" "taxes") 3 :TAGS #("NNP" "NNP" "NNP" "VBD" "TO" "NNP" "IN" "DT" "NN" "CC" "NNS") The following table shows the meanings of the tags and a few example words: Natural Language Processing 118 Tag Definition Example words CC Coord Conjuncn and, but, or NN Noun, sing. or mass dog CD Cardinal number one, two NNS Noun, plural dogs, cats DT Determiner the, some NNP Proper noun, sing. Edinburgh EX Existential there there NNPS Proper noun, plural Smiths FW Foreign Word mon dieu PDT Predeterminer all, both IN Preposition of, in, by POS Possessive ending ’s JJ Adjective big PP Personal pronoun I, you, she JJR Adj., comparative bigger PP$ Possessive pronoun my, one’s JJS Adj., superlative biggest RB Adverb quickly LS List item marker 1, One RBR Adverb, comparative faster MD Modal can, should RBS Adverb, superlative fastest RP Particle up, off WP$ Possessive-Wh whose SYM Symbol +, %, & WRB Wh-adverb how, where TO “to” to $ Dollar sign $ UH Interjection oh, oops # Pound sign # VB verb, base form eat, run ” quote ” VBD verb, past tense ate VBG verb, gerund eating ( Left paren ( VBN verb, past part eaten ) Right paren ) VBP Verb, present eat , Comma , VBZ Verb, present eats . Sent-final punct . ! ? WDT Wh-determiner which, that : Mid-sent punct. : ; — WP Wh pronoun who, what The function part-of-speech-tagger loops through all input words and initially assigns the most Natural Language Processing 119 likely part of speech as specified in the lexicon. Then a subset of Brill’s rules are applied. Rules operate on the current word and the previous word. As an example Common Lisp implementation of a rule, look for words that are tagged as common nouns, but end in “ing” so they should be a gerand (verb form): ; rule 8: convert a common noun to a present ; participle verb (i.e., a gerand) (if (equal (search "NN" r) 0) (let ((i (search "ing" w :from-end t))) (if (equal i (- (length w) 3)) (setq r "VBG")))) You can find the lexicon data in the file src/linguistic_data/FastTagData.lisp. This file is List code instead of plain data (that in retrospect would be better because it would load faster) and looks like: (defvar lex-hash (make-hash-table :test #'equal :size 110000)) (setf (gethash "shakeup" lex-hash) (list "NN")) (setf (gethash "Laurance" lex-hash) (list "NNP")) (setf (gethash "expressing" lex-hash) (list "VBG")) (setf (gethash "citybred" lex-hash) (list "JJ")) (setf (gethash "negative" lex-hash) (list "JJ" "NN")) (setf (gethash "investors" lex-hash) (list "NNS" "NNPS")) (setf (gethash "founding" lex-hash) (list "NN" "VBG" "JJ")) I generated this file automatically from lexicon data using a small Ruby script. Notice that words can have more than one possible part of speech. The most common part of speech for a word is the first entry in the lexicon. Categorizing Text The code to categorize text is fairly simple using a technique often called “bag of words.” I collected sample text in several different categories and for each category (like politics, sports, etc.) I calculated the evidence or weight that words contribute to supporting a category. For example, the word “president” has a strong weight for the category “politics” but not for the category “sports.” The reason is that the word “president” occurs frequently in articles and books about politics. The data file that contains the word weightings for each category is src/data/cat-data-tables.lisp. You can look at this file; here is a very small part of it: If you only need categorization and not the other libraries developed in this chapter, you can just load this library and run the example in the comment at the bottom of the file categorize_summa- rize.lisp: Natural Language Processing 120 ({lang=”lisp”,linenos=off} (ql:quickload “categorize_summarize”) (defvar x “President Bill Clinton <<2 pages text no shown>> “) (defvar words1 (myutils:words-from-string x)) (print words1) (setq cats1 (categorize_summarize:categorize words1)) (print cats1) (defvar sum1 (categorize_summa- rize:summarize words1 cats1)) (print sum1) Let’s look at the implementation, starting with creating hash tables for storing word count data for each category or topic: ;;; Starting topic: news_economy.txt (setf *h* (make-hash-table :test #'equal :size 1000)) (setf (gethash "news" *h*) 3915) (setf (gethash "debt" *h*) 3826) (setf (gethash "money" *h*) 1809) (setf (gethash "work" *h*) 1779) (setf (gethash "business" *h*) 1631) (setf (gethash "tax" *h*) 1572) (setf (gethash "poverty" *h*) 1512) This file was created by a simple Ruby script (not included with the book’s example code) that processes a list of sub-directories, one sub-directory per category. The following listing shows the implementation of function get-word-list-category that calculates category tags for input text: 1 (defun get-word-list-category (words) 2 (let ((x nil) 3 (ss nil) 4 (cat-hash nil) 5 (word nil) 6 (len (length words)) 7 (num-categories (length categoryHashtables)) 8 (category-score-accumulation-array 9 (make-array num-categories :initial-element 0))) 10 11 (defun list-sort (list-to-sort) 12 ;;(pprint list-to-sort) 13 (sort list-to-sort 14 #'(lambda (list-element-1 list-element-2) 15 (> (cadr list-element-1) (cadr list-element-2))))) 16 17 (do ((k 0 (+ k 1))) 18 ((equal k len)) 19 (setf word (string-downcase (aref words k))) Natural Language Processing 121 20 (do ((i 0 (+ i 1))) 21 ((equal i num-categories)) 22 (setf cat-hash (nth i categoryHashtables)) 23 (setf x (gethash word cat-hash)) 24 (if x 25 (setf 26 (aref category-score-accumulation-array i) 27 (+ x (aref category-score-accumulation-array i)))))) 28 (setf ss '()) 29 (do ((i 0 (+ i 1))) 30 ((equal i num-categories)) 31 (if (> (aref category-score-accumulation-array i) 0.01) 32 (setf 33 ss 34 (cons 35 (list 36 (nth i categoryNames) 37 (round (* (aref category-score-accumulation-array i) 10))) 38 ss)))) 39 (setf ss (list-sort ss)) 40 (let ((cutoff (/ (cadar ss) 2)) 41 (results-array '())) 42 (dolist (hit ss) 43 (if (> (cadr hit) cutoff) 44 (setf results-array (cons hit results-array)))) 45 (reverse results-array)))) On thing to notice in this listing is lines 11 through 15 where I define a nested function list-sort that takes a list of sub-lists and sorts the sublists based on the second value (which is a number) in the sublists. I often nest functions when the “inner” functions are only used in the “outer” function. Lines 2 through 9 define several local variables used in the outer function. The global variable categoryHashtables is a list of word weighting score hash tables, one for each category. The local variable category-score-accumulation-array is initialized to an array containing the number zero in each element and will be used to “keep score” of each category. The highest scored categories will be the return value for the outer function. Lines 17 through 27 are two nested loops. The outer loop is over each word in the input word array. The inner loop is over the number of categories. The logic is simple: for each word check to see if it has a weighting score in each category’s word weighting score hash table and if it is, increment the matching category’s score. The local variable ss is set to an empty list on line 28 and in the loop in lines 29 through 38 I am copying over categories and their scores when the score is over a threshold value of 0.01. We sort Natural Language Processing 122 the list in ss on line 39 using the inner function and then return the categories with a score greater than the median category score. Detecting People’s Names and Place Names The code for detecting people and place names is in the top level API code in the package defined in src/kbnlp. This package is loaded using: (ql:quickload "kbnlp") (kbnlp:make-text-object "President Bill Clinton ran for president of the USA") The functions that support identifying people’s names and place names in text are in the Common Lisp package kb nlp:: • find-names (words tags exclusion-list) – words is an array of strings for the words in text, tags are the parts of speech tags (from FastTag), and the exclusion list is a an array of words that you want to exclude from being considered as parts of people’s names. The list of found names records starting and stopping indices for names in the array words. • not-in-list-find-names-helper (a-list start end) – returns true if a found name is not already been added to a list for saving people’s names in text • find-places (words exclusion-list) – this is similar to find-names, but it finds place names. The list of found place names records starting and stopping indices for place names in the array words. • not-in-list-find-places-helper (a-list start end) – returns true if a found place name is not already been added to a list for saving place names in text • build-list-find-name-helper (v indices) – This converts lists of start/stop word indices to strings containing the names • find-names-places (txt-object) – this is the top level function that your application will call. It takes a defstruct text object as input and modifies the defstruct text by adding people’s and place names it finds in the text. You saw an example of this earlier in this chapter. I will let you read the code and just list the top level function: Natural Language Processing 123 1 (defun find-names-places (txt-object) 2 (let* ((words (text-text txt-object)) 3 (tags (text-tags txt-object)) 4 (place-indices (find-places words nil)) 5 (name-indices (find-names words tags place-indices)) 6 (name-list 7 (remove-duplicates 8 (build-list-find-name-helper words name-indices) :test #'equal)) 9 (place-list 10 (remove-duplicates 11 (build-list-find-name-helper words place-indices) :test #'equal))) 12 (let ((ret '())) 13 (dolist (x name-list) 14 (if (search " " x) 15 (setq ret (cons x ret)))) 16 (setq name-list (reverse ret))) 17 (list 18 (remove-shorter-names name-list) 19 (remove-shorter-names place-list)))) In line 2 we are using the slot accessor text-text to fetch the array of word tokens from the text object. In lines 3, 4, and 5 we are doing the same for part of speech tags, place name indices in the words array, and person names indices in the words array. In lines 6 through 11 we are using the function build-list-find-name-helper twice to construct the person names and place names as strings given the indices in the words array. We are also using the Common Lisp built-in function remove-duplicates to get rid of duplicate names. In lines 12 through 16 we are discarding any persons names that do not contain a space, that is, only keep names that are at least two word tokens. Lines 17 through 19 define the return value for the function: a list of lists of people and place names using the function remove-shorter-names twice to remove shorter versions of the same names from the lists. For example, if we had two names “Mr. John Smith” and “John Smith” then we would want to drop the shorter name “John Smith” from the return list. Summarizing Text The code for summarizing text is located in the directory src/categorize_summarize and can be loaded using: ({lang=”lisp”,linenos=off} (ql:quickload “categorize_summarize”) The code for summarization depends on the categorization code we saw earlier. Natural Language Processing 124 There are many applications for summarizing text. As an example, if you are writing a document management system you will certainly want to use something like Solr to provide search func- tionality. Solr will return highlighted matches in snippets of indexed document field values. Using summarization, when you add documents to a Solr (or other) search index you could create a new unindexed field that contains a document summary. Then when the users of your system see search results they will see the type of highlighted matches in snippets they are used to seeing in Google, Bing, or DuckDuckGo search results, and, they will see a summary of the document. Sounds good? The problem to solve is getting good summaries of text and the technique used may have to be modified depending on the type of text you are trying to summarize. There are two basic techniques for summarization: a practical way that almost everyone uses, and an area of research that I believe has so far seen little practical application. The techniques are sentence extraction and abstraction of text into a shorter form by combining and altering sentences. We will use sentence extraction. How do we choose which sentences in text to extract for the summary? The idea I had in 1999 was simple. Since I usually categorize text in my NLP processing pipeline why not use the words that gave the strongest evidence for categorizing text, and find the sentences with the largest number of these words. As a concrete example, if I categorize text as being “politics”, I identify the words in the text like “president”, “congress”, “election”, etc. that triggered the “politics” classification, and find the sentences with the largest concentrations of these words. Summarization is something that you will probably need to experiment with depending on your application. My old summarization code contained a lot of special cases, blocks of commented out code, etc. I have attempted to shorten and simplify my old summarization code for the purposes of this book as much as possible and still maintain useful functionality. The function for summarizing text is fairly simple because when the function summarize is called by the top level NLP library function make-text-object, the input text has already been categorized. Remember from the example at the beginning of the chapter that the category data looks like this: 1 :CATEGORY-TAGS (("news_politics.txt" 0.38268) 2 ("news_economy.txt" 0.31182) 3 ("news_war.txt" 0.20174)) This category data is saved in the local variable cats on line 4 of the following listing. Natural Language Processing 125 1 (defun summarize (txt-obj) 2 (let* ((words (text-text txt-obj)) 3 (num-words (length words)) 4 (cats (text-category-tags txt-obj)) 5 (sentence-count 0) 6 best-sentences sentence (score 0)) 7 ;; loop over sentences: 8 (dotimes (i num-words) 9 (let ((word (svref words i))) 10 (dolist (cat cats) 11 (let* ((hash (gethash (car cat) categoryToHash)) 12 (value (gethash word hash))) 13 (if value 14 (setq score (+ score (* 0.01 value (cadr cat))))))) 15 (push word sentence) 16 (if (or (equal word ".") (equal word "!") (equal word ";")) 17 (let () 18 (setq sentence (reverse sentence)) 19 (setq score (/ score (1+ (length sentence)))) 20 (setq sentence-count (1+ sentence-count)) 21 (format t "~%~A : ~A~%" sentence score) 22 ;; process this sentence: 23 (if (and 24 (> score 0.4) 25 (> (length sentence) 4) 26 (< (length sentence) 30)) 27 (progn 28 (setq sentence 29 (reduce 30 #'(lambda (x y) (concatenate 'string x " " y)) 31 (coerce sentence 'list))) 32 (push (list sentence score) best-sentences))) 33 (setf sentence nil score 0))))) 34 (setf 35 best-sentences 36 (sort 37 best-sentences 38 #'(lambda (x y) (> (cadr x) (cadr y))))) 39 (if best-sentences 40 (replace-all 41 (reduce #'(lambda (x y) (concatenate 'string x " " y)) 42 (mapcar #'(lambda (x) (car x)) best-sentences)) 43 " ." ".") Natural Language Processing 126 44 ""))) The nested loops in lines 8 through 33 look a little complicated, so let’s walk through it. Our goal is to calculate an importance score for each word token in the input text and to then select a few sentences containing highly scored words. The outer loop is over the word tokens in the input text. For each word token we loop over the list of categories, looking up the current word in each category hash and incrementing the score for the current word token. As we increment the word token scores we also look for sentence breaks and save sentences. The complicated bit of code in lines 16 through 32 where I construct sentences and their scores, and store sentences with a score above a threshold value in the list best-sentences. After the two nested loops, in lines 34 through 44 we simply sort the sentences by score and select the “best” sentences for the summary. The extracted sentences are no longer in their original order, which can have strange effects, but I like seeing the most relevant sentences first. Text Mining Text mining in general refers to finding data in unstructured text. We have covered several text mining techniques in this chapter: • Named entity recognition - the NLP library covered in this chapter recognizes person and place entity names. I leave it as an exercise for you to extend this library to handle company and product names. You can start by collecting company and product names in the files src/kbnlp/linguistic_data/names/names.companies and src/kbnlp/data/names/- names.products and extend the library code. • Categorizing text - you can increase the accuracy of categorization by adding more weighted words/terms that support categories. If you are already using Java in the systems you build, I recommend the Apache OpenNLP library that is more accurate than the simpler “bag of words” approach I used in my Common Lisp NLP library. If you use Python, then I recommend that you also try the NLTK library. • Summarizing text. In the next chapter I am going to cover another “data centric” topic: performing information gathering on the web. You will likely find some synergy between being able to use NLP to create structured data from unstructured text. Information Gathering This chapter covers information gathering on the web using data sources and general techniques that I have found useful. When I was planning this new book edition I had intended to also cover some basics for using the Semantic Web from Common Lisp, basically distilling some of the data from my previous book “Practical Semantic Web and Linked Data Applications, Common Lisp Edition” published in 2011. However since a free PDF is now available for that book⁵⁵ I decided to just refer you to my previous work if you are interested in the Semantic Web and Linked Data. You can also find the Java edition of this previous book on my web site. Gathering information from the web in realtime has some real advantages: • You don’t need to worry about storing data locally. • Information is up to date (depending on which web data resources you choose to use). There are also a few things to consider: • Data on the web may have legal restrictions on its use so be sure to read the terms and conditions on web sites that you would like to use. • Authorship and validity of data may be questionable. DBPedia Lookup Service Wikipedia is a great source of information. As you may know, you can download a data dump of all Wikipedia data⁵⁶ with or without version information and comments. When I want fast access to the entire Wikipedia set of English language articles I choose the second option and just get the current pages with no comments of versioning information. This is the direct download link for current Wikipedia articles.⁵⁷ There are no comments or user pages in this GZIP file. This is not as much data as you might think, only about 9 gigabytes compressed or about 42 gigabytes uncompressed. To load and run an example, try: (ql:quickload "dbpedia") (dbpedia:dbpedia-lookup "berlin") Wikipedia is a great resource to have on hand but I am going to show you in this section how to access the Semantic Web version or Wikipedia, DBPedia⁵⁸ using the DBPedia Lookup Service in the next code listing that shows the contents of the example file dbpedia-lookup.lisp in the directory src/dbpedia: ⁵⁵http://markwatson.com/#books/ ⁵⁶https://en.wikipedia.org/wiki/Wikipedia:Database_download ⁵⁷http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2 ⁵⁸http://dbpedia.org/ Information Gathering 128 1 (ql:quickload :drakma) 2 (ql:quickload :babel) 3 (ql:quickload :s-xml) 4 5 ;; utility from http://cl-cookbook.sourceforge.net/strings.html#manip: 6 (defun replace-all (string part replacement &key (test #'char=)) 7 "Returns a new string in which all the occurrences of the part 8 is replaced with replacement." 9 (with-output-to-string (out) 10 (loop with part-length = (length part) 11 for old-pos = 0 then (+ pos part-length) 12 for pos = (search part string 13 :start2 old-pos 14 :test test) 15 do (write-string string out 16 :start old-pos 17 :end (or pos (length string))) 18 when pos do (write-string replacement out) 19 while pos))) 20 21 (defstruct dbpedia-data uri label description) 22 23 (defun dbpedia-lookup (search-string) 24 (let* ((s-str (replace-all search-string " " "+")) 25 (s-uri 26 (concatenate 27 'string 28 "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" 29 s-str)) 30 (response-body nil) 31 (response-status nil) 32 (response-headers nil) 33 (xml nil) 34 ret) 35 (multiple-value-setq 36 (response-body response-status response-headers) 37 (drakma:http-request 38 s-uri 39 :method :get 40 :accept "application/xml")) 41 ;; (print (list "raw response body as XML:" response-body)) 42 ;;(print (list ("status:" response-status "headers:" response-headers))) 43 (setf xml Information Gathering 129 44 (s-xml:parse-xml-string 45 (babel:octets-to-string response-body))) 46 (dolist (r (cdr xml)) 47 ;; assumption: data is returned in the order: 48 ;; 1. label 49 ;; 2. DBPedia URI for more information 50 ;; 3. description 51 (push 52 (make-dbpedia-data 53 :uri (cadr (nth 2 r)) 54 :label (cadr (nth 1 r)) 55 :description 56 (string-trim 57 '(#\Space #\NewLine #\Tab) 58 (cadr (nth 3 r)))) 59 ret)) 60 (reverse ret))) 61 62 ;; (dbpedia-lookup "berlin") I am only capturing the attributes for DBPedia URI, label and description in this example code. If you uncomment line 41 and look at the entire response body from the call to DBPedia Lookup, you can see other attributes that you might want to capture in your applications. Here is a sample call to the function dbpedia:dbpedia-lookup (only some of the returned data is shown): 1 * (ql:quickload "dbpedia") 2 * (dbpedia:dbpedia-lookup "berlin") 3 4 (#S(DBPEDIA-DATA 5 :URI "http://dbpedia.org/resource/Berlin" 6 :LABEL "Berlin" 7 :DESCRIPTION 8 "Berlin is the capital city of Germany and one of the 16 states of Germany. 9 With a population of 3.5 million people, Berlin is Germany's largest city 10 and is the second most populous city proper and the eighth most populous 11 urban area in the European Union. Located in northeastern Germany, it is 12 the center of the Berlin-Brandenburg Metropolitan Region, which has 5.9 13 million residents from over 190 nations. Located in the European Plains, 14 Berlin is influenced by a temperate seasonal climate.") 15 ...) Wikipedia, and the DBPedia linked data for of Wikipedia are great sources of online data. If you Information Gathering 130 get creative, you will be able to think of ways to modify the systems you build to pull data from DPPedia. One warning: Semantic Web/Linked Data sources on the web are not available 100% of the time. If your business applications depend on having the DBPedia always available then you can follow the instructions on the DBPedia web site⁵⁹ to install the service on one of your own servers. Web Spiders When you write web spiders to collect data from the web there are two things to consider: • Make sure you read the terms of service for web sites whose data you want to use. I have found that calling or emailing web site owners explaining how I want to use the data on their site usually works to get permission. • Make sure you don’t access a site too quickly. It is polite to wait a second or two between fetching pages and other assets from a web site. We have already used the Drakma web client library in this book. See the files src/dbpedia/dbpedia- lookup.lisp (covered in the last section) and src/solr_examples/solr-client.lisp (covered in the Chapter on NoSQL). Paul Nathan has written library using Drakma to crawl a web site with an example to print out links as they are found. His code is available under the AGPL license at articulate-lisp.com/src/web-trotter.lisp⁶⁰ and I recommend that as a starting point. I find it is sometimes easier during development to make local copies of a web site so that I don’t have to use excess resources from web site hosts. Assuming that you have the wget utility installed, you can mirror a site like this: 1 wget -m -w 2 http://knowledgebooks.com/ 2 wget -mk -w 2 http://knowledgebooks.com/ Both of these examples have a two-second delay between HTTP requests for resources. The option -m indicates to recursively follow all links on the web site. The -w 2 option delays for two seconds between requests. The option -mk converts URI references to local file references on your local mirror. The second example on line 2 is more convenient. We covered reading from local files in the Chapter on Input and Output. One trick I use is to simply concatenate all web pages into one file. Assuming that you created a local mirror of a web site, cd to the top level directory and use something like this: 1 cd knowledgebooks.com 2 cat *.html */*.html > ../web_site.html You can then open the file, search for text in in p, div, h1, etc. HTML elements to process an entire web site as one file. ⁵⁹http://dbpedia.org ⁶⁰http://articulate-lisp.com/examples/trotter.html Information Gathering 131 Using Apache Nutch Apache Nutch⁶¹, like Solr, is built on Lucene search technology. I use Nutch as a “search engine in a box” when I need to spider web sites and I want a local copy with a good search index. Nutch handles a different developer’s use case over Solr which we covered in the Chapter on NoSQL. As we saw, Solr is an effective tool for indexing and searching structured data as documents. With very little setup, Nutch can be set up to automatically keep an up to date index of a list of web sites, and optionally follow links to some desired depth from these “seed” web sites. You can use the same Common Lisp client code that we used for Solr with one exception; you will need to change the root URI for the search service to: 1 http://localhost:8080/opensearch?query= So the modified client code src/solr_examples/solr-client.lisp needs one line changed: 1 (defun do-search (&rest terms) 2 (let ((query-string (format nil "~{~A~^+AND+~}" terms))) 3 (cl-json:decode-json-from-string 4 (drakma:http-request 5 (concatenate 6 'string 7 "http://localhost:8080/opensearch?query=" 8 query-string 9 "&wt=json"))))) Early versions of Nutch were very simple to install and configure. Later versions of Nutch have been more complex, more performant, and have more services, but it will take you longer to get set up than earlier versions. If you just want to experiment with Nutch, you might want to start with an earlier version. The OpenSearch.org⁶² web site contains many public OpenSearch services that you might want to try. If you want to modify the example client code in src/solr-client.lisp a good start is OpenSearch services that return JSON data and OpenSearch Community JSON formats web page⁶³ is a good place to start. Some of the services on this web page like the New York Times service require that you sign up for a developer’s API key. When I start writing an application that requires web data (no matter which programming language I am using) I start by finding services that may provide the type of data I need and do my initial development with a web browser with plugin support to nicely format XML and JSON data. I do a lot of exploring and take a lot of notes before I write any code. ⁶¹https://nutch.apache.org/ ⁶²http://www.opensearch.org/Home ⁶³http://www.opensearch.org/Community/JSON_Formats Information Gathering 132 Wrap Up I tried to provide some examples and advice in this short chapter to show you that even though other languages like Ruby and Python have more libraries and tools for gathering information from the web, Common Lisp has good libraries for information gathering also and they are easily used via Quicklisp. Using The CL Machine-Learning Library The CL Machine-Learning (CLML) library was originally developed by MSI (NTT DATA Mathemat- ical Systems Inc. in Japan) and is supported by many developers. You should visit the CLML web page⁶⁴ for project documentation and follow the installation directions and read about the project before using the examples in this chapter. However if you just want to quickly try the following CLML examples then you can install CLML using Quicklisp: 1 mkdir -p ~/quicklisp/local-projects 2 cd ~/quicklisp/local-projects 3 git clone https://github.com/mmaul/clml.git 4 sbcl --dynamic-space-size 2560 5 > (ql:quickload :clml :verbose t) The installation will take a while to run but after installation using the libraries via quickload is fast. You can now run the example Quicklisp project src/clml_examples: $ sbcl --dynamic-space-size 2560 * (ql:quickload "clmltest") * (clmltest:clml-tests-example) Please be patient the first time you run this because the first time you load the example project, the one time installation of CLML will take a while to run but after installation then the example project loads quickly. CLML installation involves downloading and installing BLAS, LAPACK, and other libraries. Other resources for CLML are the tutorials⁶⁵ and contributed extensions⁶⁶ that include support for plotting (using several libraries) and for fetching data sets. Although CLML is fairly portable we will be using SBCL and we need to increase the heap space when starting SBCL when we want to use the CLML library: sbcl --dynamic-space-size 5000 ⁶⁴https://github.com/mmaul/clml ⁶⁵https://github.com/mmaul/clml.tutorials ⁶⁶https://github.com/mmaul/clml.extras Using The CL Machine-Learning Library 134 You can refer to the documentation at https://github.com/mmaul/clml⁶⁷. This documentation lists the packages with some information for each package but realistically I keep the source code for CLML in an editor or IDE and read source code while writing code that uses CLML. I will show you with short examples how to use the KNN (K nearest neighbors) and SVM (support vector machines) APIs. We will not cover other useful CLML APIs like time series processing, Naive Bayes, PCA (principle component analysis) and general matrix and tensor operations. Even though the learning curve is a bit steep, CLML provides a lot of functionality for machine learning, dealing with time series data, and general matrix and tensor operations. Using the CLML Data Loading and Access APIs The CLML project uses several data sets and since the few that we will use are small files, they are included in the book’s repository in directory machine_learning_data under the src directory. The first few lines of labeled_cancer_training_data.csv are: Cl.thickness,Cell.size,Cell.shape,Marg.adhesion,Epith.c.size,Bare.nuclei,Bl.cromatin\ ,Normal.nucleoli,Mitoses,Class 5,4,4,5,7,10,3,2,1,benign 6,8,8,1,3,4,3,7,1,benign 8,10,10,8,7,10,9,7,1,malignant 2,1,2,1,2,1,3,1,1,benign The first line in the CSV data files specifies names for each attribute with the name of the last column being “Class” which here takes on values benign or malignant. Later, the goal will be to create models that are constructed from training data and then make predictions of the “Class” of new input data. We will look at how to build and use machine learning models later but here we concentrate on reading and using input data. The example file clml_data_apis.lisp shows how to open a file and loop over the values for each row: 1 ;; note; run SBCL using: sbcl --dynamic-space-size 2560 2 3 (ql:quickload '(:clml 4 :clml.hjs)) ; read data sets 5 6 (defpackage #:clml-data-test 7 (:use #:cl #:clml.hjs.read-data)) 8 9 (in-package #:clml-data-test) ⁶⁷https://github.com/mmaul/clml Using The CL Machine-Learning Library 135 10 11 (defun read-data () 12 (let ((train1 13 (clml.hjs.read-data:read-data-from-file 14 "./machine_learning_data/labeled_cancer_training_data.csv" 15 :type :csv 16 :csv-type-spec (append 17 (make-list 9 :initial-element 'double-float) 18 '(symbol))))) 19 (loop-over-and-print-data train1))) 20 21 (defun loop-over-and-print-data (clml-data-set) 22 (print "Loop over and print a CLML data set:") 23 (let ((testdata (clml.hjs.read-data:dataset-points clml-data-set))) 24 (loop for td across testdata 25 do 26 (print td)))) 27 28 (read-data) The function read-data defined in lines 11-19 uses the utility function clml.hjs.read-data:read- data-from-file to read a CSV (comma separated value) spreadsheet file from disk. The CSV file is expected to contain 10 columns (set in lines 17-18) with the first nine columns containing floating point values and the last column text data. The function loop-over-and-print-data defined in lines 21-26 reads the CLML data set object, looping over each data sample (i.e., each row in the original spreadsheet file) and printing it. Here is some output from loading this file: 1 $ sbcl --dynamic-space-size 2560 2 This is SBCL 1.3.16, an implementation of ANSI Common Lisp. 3 More information about SBCL is available at . 4 5 SBCL is free software, provided as is, with absolutely no warranty. 6 It is mostly in the public domain; some portions are provided under 7 BSD-style licenses. See the CREDITS and COPYING files in the 8 distribution for more information. 9 * (load "clml_data_apis.lisp") 10 11 "Loop over and print a CLML data set:" 12 #(5.0d0 4.0d0 4.0d0 5.0d0 7.0d0 10.0d0 3.0d0 2.0d0 1.0d0 |benign|) 13 #(6.0d0 8.0d0 8.0d0 1.0d0 3.0d0 4.0d0 3.0d0 7.0d0 1.0d0 |benign|) Using The CL Machine-Learning Library 136 14 #(8.0d0 10.0d0 10.0d0 8.0d0 7.0d0 10.0d0 9.0d0 7.0d0 1.0d0 |malignant|) 15 #(2.0d0 1.0d0 2.0d0 1.0d0 2.0d0 1.0d0 3.0d0 1.0d0 1.0d0 |benign|) In the next section we will use the same cancer data training file, and another test data in the same format to cluster this cancer data into similar sets, one set for non-malignant and one for malignant samples. K-Means Clustering of Cancer Data Set We will now read the same University of Wisconsin cancer data set and cluster the input samples (one sample per row of the spreadsheet file) into similar classes. We will find after training a model that the data is separated into two clusters, representing non-malignant and malignant samples. The function cancer-data-cluster-example-read-data defined in lines 33-47 is very similar to the function read-data in the last section except here we read in two data files: one for training and one for testing. The function cluster-using-k-nn defined in lines 13-30 uses the training and test data objects to first train a model and then to test it with test data that was previously used for training. Notice how we call this function in line 47: the first two arguments are the two data set objects, the third is the string “Class” that is the label for the 10th column of the original spreadsheet CSV files, and the last argument is the type of distance measurement used to compare two data samples (i.e., comparing any two rows of the training CSV data file). 1 ;; note; run SBCL using: sbcl --dynamic-space-size 2560 2 3 (ql:quickload '(:clml 4 :clml.hjs ; utilities 5 :clml.clustering)) 6 7 (defpackage #:clml-knn-cluster-example1 8 (:use #:cl #:clml.hjs.read-data)) 9 10 (in-package #:clml-knn-cluster-example1) 11 12 ;; folowing is derived from test code in CLML: 13 (defun cluster-using-k-nn (test train objective-param-name manhattan) 14 (let (original-data-column-length) 15 (setq original-data-column-length 16 (length (aref (clml.hjs.read-data:dataset-points train) 0))) 17 (let* ((k 5) 18 (k-nn-estimator 19 (clml.nearest-search.k-nn:k-nn-analyze train Using The CL Machine-Learning Library 137 20 k 21 objective-param-name :all 22 :distance manhattan :normalize t))) 23 (loop for data across 24 (dataset-points 25 (clml.nearest-search.k-nn:k-nn-estimate k-nn-estimator test)) 26 if (equal (aref data 0) (aref data original-data-column-length)) 27 do 28 (format t "Correct: ~a~%" data) 29 else do 30 (format t "Wrong: ~a~%" data))))) 31 32 ;; folowing is derived from test code in CLML: 33 (defun cancer-data-cluster-example-read-data () 34 (let ((train1 35 (clml.hjs.read-data:read-data-from-file 36 "./machine_learning_data/labeled_cancer_training_data.csv" 37 :type :csv 38 :csv-type-spec (append (make-list 9 :initial-element 'double-float) 39 '(symbol)))) 40 (test1 41 (clml.hjs.read-data:read-data-from-file 42 "./machine_learning_data/labeled_cancer_test_data.csv" 43 :type :csv 44 :csv-type-spec (append (make-list 9 :initial-element 'double-float) 45 '(symbol))))) 46 ;;(print test1) 47 (print (cluster-using-k-nn test1 train1 "Class" :double-manhattan)))) 48 49 (cancer-data-cluster-example-read-data) The following listing shows the output from running the last code example: 1 Number of self-misjudgement : 13 2 Correct: #(benign 5.0d0 1.0d0 1.0d0 1.0d0 2.0d0 1.0d0 3.0d0 1.0d0 1.0d0 benign) 3 Correct: #(benign 3.0d0 1.0d0 1.0d0 1.0d0 2.0d0 2.0d0 3.0d0 1.0d0 1.0d0 benign) 4 Correct: #(benign 4.0d0 1.0d0 1.0d0 3.0d0 2.0d0 1.0d0 3.0d0 1.0d0 1.0d0 benign) 5 Correct: #(benign 1.0d0 1.0d0 1.0d0 1.0d0 2.0d0 10.0d0 3.0d0 1.0d0 1.0d0 benign) 6 Correct: #(benign 2.0d0 1.0d0 1.0d0 1.0d0 2.0d0 1.0d0 1.0d0 1.0d0 5.0d0 benign) 7 Correct: #(benign 1.0d0 1.0d0 1.0d0 1.0d0 1.0d0 1.0d0 3.0d0 1.0d0 1.0d0 benign) 8 Wrong: #(benign 5.0d0 3.0d0 3.0d0 3.0d0 2.0d0 3.0d0 4.0d0 4.0d0 1.0d0 9 malignant) 10 Correct: #(malignant 8.0d0 7.0d0 5.0d0 10.0d0 7.0d0 9.0d0 5.0d0 5.0d0 4.0d0 Using The CL Machine-Learning Library 138 11 malignant) 12 Correct: #(benign 4.0d0 1.0d0 1.0d0 1.0d0 2.0d0 1.0d0 2.0d0 1.0d0 1.0d0 benign) 13 Correct: #(malignant 10.0d0 7.0d0 7.0d0 6.0d0 4.0d0 10.0d0 4.0d0 1.0d0 2.0d0 14 malignant) 15 ... SVM Classification of Cancer Data Set We will now reuse the same cancer data set but use a different way to classify data into non- malignant and malignant categories: Support Vector Machines (SVM). SVMs are linear classifiers which means that they work best when data is linearly separable. In the case of the cancer data, there are nine dimensions of values that (hopefully) predict one of the two output classes (or categories). If we think of the first 9 columns of data as defining a 9-dimensional space, then SVM will work well when a 8-dimensional hyperplane separates the samples into the two output classes (categories). To make this simpler to visualize, if we just had two input columns, that defines a two-dimensional space, and if a straight line can separate most of the examples into the two output categories, then the data is linearly separable so SVM is a good technique to use. The SVM algorithm is effectively determining the parameters defining this one-dimensional line (or in the cancer data case, the 9- dimensional hyperspace). What if data is not linearly separable? Then use the backpropagation neural network code in the chapter “Backpropagation Neural Networks” or the deep learning code in the chapter “Using Armed Bear Common Lisp With DeepLearning4j” to create a model. SVM is very efficient so it often makes sense to first try SVM and if trained models are not accurate enough then use neural networks, including deep learning. The following listing of file clml_svm_classifier.lisp shows how to read data, build a model and evaluate the model with different test data. In line 15 we use the function clml.svm.mu:svm that requires the type of kernel function to use, the training data, and testing data. Just for reference, we usually use Gaussian kernel functions for processing numeric data and linear kernel functions for handling text in natural language processing applications. Here we use a Gaussian kernel. The function cancer-data-svm-example-read-data defined on line 40 differs from how we read and processed data earlier because we need to separate out the positive and negative training examples. The data is split in the lexically scoped function in lines 42-52. The last block of code in lines 54-82 is just top-level test code that gets executed when the file clml_svm_classifier.lisp is loaded. Using The CL Machine-Learning Library 139 1 ;; note; run SBCL using: sbcl --dynamic-space-size 2560 2 3 (ql:quickload '(:clml 4 :clml.hjs ; utilities 5 :clml.svm)) 6 7 (defpackage #:clml-svm-classifier-example1 8 (:use #:cl #:clml.hjs.read-data)) 9 10 (in-package #:clml-svm-classifier-example1) 11 12 (defun svm-classifier-test (kernel train test) 13 "train and test are lists of lists, with first elements being negative 14 samples and the second elements being positive samples" 15 (let ((decision-function (clml.svm.mu:svm kernel (cadr train) (car train))) 16 (correct-positives 0) 17 (wrong-positives 0) 18 (correct-negatives 0) 19 (wrong-negatives 0)) 20 ;; type: # 21 (print decision-function) 22 (princ "***** NEGATIVE TESTS: calling decision function:") 23 (terpri) 24 (dolist (neg (car test)) ;; negative test examples 25 (let ((prediction (funcall decision-function neg))) 26 (print prediction) 27 (if prediction (incf wrong-negatives) (incf correct-negatives)))) 28 (princ "***** POSITIVE TESTS: calling decision function:") 29 (terpri) 30 (dolist (pos (cadr test)) ;; positive test examples 31 (let ((prediction (funcall decision-function pos))) 32 (print prediction) 33 (if prediction (incf correct-positives) (incf wrong-positives)))) 34 (format t "Number of correct negatives ~a~%" correct-negatives) 35 (format t "Number of wrong negatives ~a~%" wrong-negatives) 36 (format t "Number of correct positives ~a~%" correct-positives) 37 (format t "Number of wrong positives ~a~%" wrong-positives))) 38 39 40 (defun cancer-data-svm-example-read-data () 41 42 (defun split-positive-negative-cases (data) 43 (let ((negative-cases '()) Using The CL Machine-Learning Library 140 44 (positive-cases '())) 45 (dolist (d data) 46 ;;(print (list "* d=" d)) 47 (if (equal (symbol-name (first (last d))) "benign") 48 (setf negative-cases 49 (cons (reverse (cdr (reverse d))) negative-cases)) 50 (setf positive-cases 51 (cons (reverse (cdr (reverse d))) positive-cases)))) 52 (list negative-cases positive-cases))) 53 54 (let* ((train1 55 (clml.hjs.read-data:read-data-from-file 56 "./machine_learning_data/labeled_cancer_training_data.csv" 57 :type :csv 58 :csv-type-spec (append (make-list 9 :initial-element 'double-float) 59 '(symbol)))) 60 (train-as-list 61 (split-positive-negative-cases 62 (coerce 63 (map 'list 64 #'(lambda (x) (coerce x 'list)) 65 (coerce (clml.hjs.read-data:dataset-points train1) 'list)) 66 'list))) 67 (test1 68 (clml.hjs.read-data:read-data-from-file 69 "./machine_learning_data/labeled_cancer_test_data.csv" 70 :type :csv 71 :csv-type-spec (append (make-list 9 :initial-element 'double-float) 72 '(symbol)))) 73 (test-as-list 74 (split-positive-negative-cases 75 (coerce 76 (map 'list 77 #'(lambda (x) (coerce x 'list)) 78 (coerce (clml.hjs.read-data:dataset-points test1) 'list)) 79 'list)))) 80 81 ;; we will use a gaussian kernel for numeric data. 82 ;; note: for text classification, use a clml.svm.mu:+linear-kernel+ 83 (svm-classifier-test 84 (clml.svm.mu:gaussian-kernel 2.0d0) 85 train-as-list test-as-list))) 86 Using The CL Machine-Learning Library 141 87 (cancer-data-svm-example-read-data) The sample code prints the prediction values for the test data which I will not show here. Here are the last four lines of output showing the cumulative statistics for the test data: 1 Number of correct negatives 219 2 Number of wrong negatives 4 3 Number of correct positives 116 4 Number of wrong positives 6 CLML Wrap Up The CLML machine learning library is under fairly active development and I showed you enough to get started: understanding the data APIs and examples for KNN clustering and SVM classification. A good alternative to CLML is MGL⁶⁸ that supports backpropagation neural networks, boltzmann machines, and gaussian processes. In the next two chapters we continue with the topic of machine learning with backpropagation andf Hopfield neural networks. ⁶⁸https://github.com/melisgl/mgl Backpropagation Neural Networks Let’s start with an overview of how these networks work and then fill in more detail later. Backpropagation networks are trained by applying training inputs to the network input layer, propagate values through the network to the output neurons, compare the errors (or differences) between these propagated output values and the training data output values. These output errors are backpropagated though the network and the magnitude of backpropagated errors are used to adjust the weights in the network. The example we look at here uses the plotlib package from an earlier chapter and the source code for the example is the file loving_snippet/backprop_neural_network.lisp. We will use the following diagram to make this process more clear. There are four weights in this very simple network: • W¹,¹ is the floating point number representing the connection strength between input_neuron¹ and output_neuron¹ • W²,¹ connects input_neuron² to output_neuron¹ • W¹,² connects input_neuron¹ to output_neuron² • W²,² connects input_neuron² to output_neuron² Understanding how connection weights connect neurons in adjacent layers Backpropagation Neural Networks 143 Before any training the weight values are all small random numbers. Consider a training data element where the input neurons have values [0.1, 0.9] and the desired output neuron values are [0.9 and 0.1], that is flipping the input values. If the propagated output values for the current weights are [0.85, 0.5] then the value of the first output neuron has a small error abs(0.85 - 0.9) which is 0.05. However the propagated error of the second output neuron is high: abs(0.5 - 0.1) which is 0.4. Informally we see that the weights feeding input output neuron 1 (W¹,¹ and W²,¹) don’t need to be changed much but the neuron that feeding input neuron 2 (W¹,² and W²,²) needs modification (the value of W²,² is too large). Of course, we would never try to manually train a network like this but it is important to have at least an informal understanding of how weights connect the flow of value (we will call this activation value later) between neurons. In this neural network see in the first figure we have four weights connecting the input and output neurons. Think of these four weights forming a four-dimensional space where the range in each dimension is constrained to small positive and negative floating point values. At any point in this “weight space”, the numeric values of the weights defines a model that maps the inputs to the outputs. The error seen at the output neurons is accumulated for each training example (applied to the input neurons). The training process is finding a point in this four-dimensional space that has low errors summed across the training data. We will use gradient descent to start with a random point in the four-dimensional space (i.e., an initial random set of weights) and move the point towards a local minimum that represents the weights in a model that is (hopefully) “good enough” at representing the training data. This process is simple enough but there are a few practical considerations: • Sometimes the accumulated error at a local minimum is too large even after many training cycles and it is best to just restart the training process with new random weights. • If we don’t have enough training data then the network may have enough memory capacity to memorize the training examples. This is not what we want: we want a model with just enough memory capacity (as represented by the number of weights) to form a generalized predictive model, but not so specific that it just memorizes the training examples. The solution is to start with small networks (few hidden neurons) and increase the number of neurons until the training data can be learned. In general, having a lot of training data is good and it is also good to use as small a network as possible. In practice using backpropagation networks is an iterative process of experimenting with the size of a network. In the example program (in the file backprop_neural_network.lisp) we use the plotting library developed earlier to visualize neuron activation and connecting weight values while the network trains. The following three screen shots from running the function test3 defined at the bottom of the file backprop_neural_network.lisp illustrate the process of starting with random weights, getting Backpropagation Neural Networks 144 random outputs during initial training, and as delta weights are used to adjust the weights in a network, then the training examples are learned: At the start of the training run with random weights and large delta weights In the last figure the initial weights are random so we get random mid-range values at the output neurons. The trained weights start to produce non-random output As we start to train the network, adjusting the weights, we start to see variation in the output neurons as a function of what the inputs are. Backpropagation Neural Networks 145 After training many cycles the training examples are learned, with only small output errors In the last figure the network is trained sufficiently well to map inputs [0, 0, 0, 1] to output values that are approximately [0.8, 0.2, 0.2, 0.3] which is close to the expected value [1, 0, 0, 0]. The example source file backprop_neural_network.lisp is long so we will only look at the more interesting parts here. Specifically we will not look at the code to plot neural networks using plotlib. The activation values of individual neurons are limited to the range [0, 1] by first calculating their values based on the sum activation values of neurons in the previous layer times the values of the connecting weights and then using the Sigmoid function to map the sums to the desired range. The Sigmoid function and the derivative of the Sigmoid function (dSigmoid) look like: Sigmoid and Derivative of the Sigmid Functions Here are the definitions of these functions: Backpropagation Neural Networks 146 (defun Sigmoid (x) (/ 1.0 (+ 1.0 (exp (- x))))) (defun dSigmoid (x) (let ((temp (Sigmoid x))) (* temp (- 1.0 temp))) The function NewDeltaNetwork creates a new neual network object. This code allocates storage for input, hidden, output layers (I sometimes refer to neuron layers as “slabs”), and the connection weights. Connection weights are initialized to small random values. 1 ; (NewDeltaNetwork sizeList) 2 ; Args: sizeList = list of sizes of slabs. This also defines 3 ; the number of slabs in the network. 4 ; (e.g., '(10 5 4) ==> a 3-slab network with 10 5 ; input neurons, 5 hidden neurons, and 4 output 6 ; neurons). 7 ; 8 ; Returned value = a list describing the network: 9 ; (nLayers sizeList 10 ; (activation-array[1] .. activation-array[nLayers]) 11 ; (weight-array[2] .. weight-array[nLayers]) 12 ; (sum-of-products[2] .. sum-of-products[nLayers[nLayers]) 13 ; (back-prop-error[2] .. back-prop-error[nLayers])) 14 ; (old-delta-weights[2] .. for momentum term 15 16 :initial-element 0.0)) 17 (reverse old-dw-list))) 18 19 ;; 20 ; Initialize values for all activations: 21 ;; 22 (mapc 23 (lambda (x) 24 (let ((num (array-dimension x 0))) 25 (dotimes (n num) 26 (setf (aref x n) (frandom 0.01 0.1))))) 27 a-list) 28 29 ;; 30 ; Initialize values for all weights: 31 ;; 32 (mapc Backpropagation Neural Networks 147 33 (lambda (x) 34 (let ((numI (array-dimension x 0)) 35 (numJ (array-dimension x 1))) 36 (dotimes (j numJ) 37 (dotimes (i numI) 38 (setf (aref x i j) (frandom -0.5 0.5)))))) 39 w-list) 40 (list numLayers sizeList a-list s-list w-list dw-list 41 d-list old-dw-list alpha beta))) In the following listing the function DeltaLearn processes one pass through all of the training data. Function DeltaLearn is called repeatedly until the return value is below a desired error threshold. The main loop over each training example is implemented in lines 69-187. Inside this outer loop there are two phases of training for each training example: a forward pass propagating activation from the input neurons to the output neurons via any hidden layers (lines 87-143) and then the weight correcting backpropagation of output errors while making small adjustments to weights (lines 148- 187): 1 ;; 2 ; Utility function for training a delta rule neural network. 3 ; The first argument is the name of an output PNG plot file 4 ; and a nil value turns off plotting the network during training. 5 ; The second argument is a network definition (as returned from 6 ; NewDeltaNetwork), the third argument is a list of training 7 ; data cases (see the example test functions at the end of this 8 ; file for examples. 9 ;; 10 11 (defun DeltaLearn (plot-output-file-name 12 netList trainList) 13 (let ((nLayers (car netList)) 14 (sizeList (cadr netList)) 15 (activationList (caddr netList)) 16 (sumOfProductsList (car (cdddr netList))) 17 (weightList (cadr (cdddr netList))) 18 (deltaWeightList (caddr (cdddr netList))) 19 (deltaList (cadddr (cdddr netList))) 20 (oldDeltaWeightList (cadddr (cdddr (cdr netList)))) 21 (alpha (cadddr (cdddr (cddr netList)))) 22 (beta (cadddr (cdddr (cdddr netList)))) 23 (inputs nil) 24 (targetOutputs nil) 25 (iDimension nil) Backpropagation Neural Networks 148 26 (jDimension nil) 27 (iActivationVector nil) 28 (jActivationVector nil) 29 (n nil) 30 (weightArray nil) 31 (sumOfProductsArray nil) 32 (iDeltaVector nil) 33 (jDeltaVector nil) 34 (deltaWeightArray nil) 35 (oldDeltaWeightArray nil) 36 (sum nil) 37 (iSumOfProductsArray nil) 38 (error nil) 39 (outputError 0) 40 (delta nil) 41 (eida nil) 42 (inputNoise 0)) 43 44 ;; 45 ; Zero out deltas: 46 ;; 47 (dotimes (n (- nLayers 1)) 48 (let* ((dw (nth n deltaList)) 49 (len1 (array-dimension dw 0))) 50 (dotimes (i len1) 51 (setf (aref dw i) 0.0)))) 52 53 ;; 54 ; Zero out delta weights: 55 ;; 56 (dotimes (n (- nLayers 1)) 57 (let* ((dw (nth n deltaWeightList)) 58 (len1 (array-dimension dw 0)) 59 (len2 (array-dimension dw 1))) 60 (dotimes (i len1) 61 (dotimes (j len2) 62 (setf (aref dw i j) 0.0))))) 63 64 (setq inputNoise *delta-default-input-noise-value*) 65 66 ;; 67 ; Main loop on training examples: 68 ;; Backpropagation Neural Networks 149 69 (dolist (tl trainList) 70 71 (setq inputs (car tl)) 72 (setq targetOutputs (cadr tl)) 73 74 (if *delta-rule-debug-flag* 75 (print (list "Current targets:" targetOutputs))) 76 77 (setq iDimension (car sizeList)) ; get the size of the input slab 78 (setq iActivationVector (car activationList)) ; input activations 79 (dotimes (i iDimension) ; copy training inputs to input slab 80 (setf 81 (aref iActivationVector i) 82 (+ (nth i inputs) (frandom (- inputNoise) inputNoise)))) 83 ;; 84 ; Propagate activation through all of the slabs: 85 ;; 86 (dotimes (n-1 (- nLayers 1)) ; update layer i to layer flowing to layer j 87 (setq n (+ n-1 1)) 88 (setq jDimension (nth n sizeList)) ; get the size of the j'th layer 89 (setq jActivationVector (nth n activationList)) ; activation for slab j 90 (setq weightArray (nth n-1 weightList)) 91 (setq sumOfProductsArray (nth n-1 sumOfProductsList)) 92 (dotimes (j jDimension) ; process each neuron in slab j 93 (setq sum 0.0) ; init sum of products to zero 94 (dotimes (i iDimension) ; activation from neurons in previous slab 95 (setq 96 sum 97 (+ sum (* (aref weightArray i j) (aref iActivationVector i))))) 98 (setf (aref sumOfProductsArray j) sum) ; save sum of products 99 (setf (aref jActivationVector j) (Sigmoid sum))) 100 (setq iDimension jDimension) ; reset index for next slab pair 101 (setq iActivationVector jActivationVector)) 102 ;; 103 ; Activation is spread through the network and sum of products 104 ; calculated. Now modify the weights in the network using back 105 ; error propagation. Start by calculating the error signal for 106 ; each neuron in the output layer: 107 ;; 108 (setq jDimension (nth (- nLayers 1) sizeList)) ; size of last layer 109 (setq jActivationVector (nth (- nLayers 1) activationList)) 110 (setq jDeltaVector (nth (- nLayers 2) deltaList)) 111 (setq sumOfProductsArray (nth (- nLayers 2) sumOfProductsList)) Backpropagation Neural Networks 150 112 (setq outputError 0) 113 (dotimes (j jDimension) 114 (setq delta (- (nth j targetOutputs) (aref jActivationVector j))) 115 (setq outputError (+ outputError (abs delta))) 116 (setf 117 (aref jDeltaVector j) 118 (+ 119 (aref jDeltaVector j) 120 (* delta (dSigmoid (aref sumOfProductsArray j)))))) 121 ;; 122 ; Now calculate the backpropagated error signal for all hidden slabs: 123 ;; 124 (dotimes (nn (- nLayers 2)) 125 (setq n (- nLayers 3 nn)) 126 (setq iDimension (nth (+ n 1) sizeList)) 127 (setq iSumOfProductsArray (nth n sumOfProductsList)) 128 (setq iDeltaVector (nth n deltaList)) 129 (dotimes (i iDimension) 130 (setf (aref iDeltaVector i) 0.0)) 131 (setq weightArray (nth (+ n 1) weightList)) 132 (dotimes (i iDimension) 133 (setq error 0.0) 134 (dotimes (j jDimension) 135 (setq error 136 (+ error (* (aref jDeltaVector j) (aref weightArray i j))))) 137 (setf 138 (aref iDeltaVector i) 139 (+ 140 (aref iDeltaVector i) 141 (* error (dSigmoid (aref iSumOfProductsArray i)))))) 142 (setq jDimension iDimension) 143 (setq jDeltaVector iDeltaVector)) 144 145 ;; 146 ; Update all delta weights in the network: 147 ;; 148 (setq iDimension (car sizeList)) 149 (dotimes (n (- nLayers 1)) 150 (setq iActivationVector (nth n activationList)) 151 (setq jDimension (nth (+ n 1) sizeList)) 152 (setq jDeltaVector (nth n deltaList)) 153 (setq deltaWeightArray (nth n deltaWeightList)) 154 (setq weightArray (nth n weightList)) Backpropagation Neural Networks 151 155 (setq eida (nth n eidaList)) 156 157 (dotimes (j jDimension) 158 (dotimes (i iDimension) 159 (setq delta (* eida (aref jDeltaVector j) (aref iActivationVector i))) 160 (setf 161 (aref DeltaWeightArray i j) 162 (+ (aref DeltaWeightArray i j) delta)))) ; delta weight changes 163 164 (setq iDimension jDimension)) 165 166 ;; 167 ; Update all weights in the network: 168 ;; 169 (setq iDimension (car sizeList)) 170 (dotimes (n (- nLayers 1)) 171 (setq iActivationVector (nth n activationList)) 172 (setq jDimension (nth (+ n 1) sizeList)) 173 (setq jDeltaVector (nth n deltaList)) 174 (setq deltaWeightArray (nth n deltaWeightList)) 175 (setq oldDeltaWeightArray (nth n oldDeltaWeightList)) 176 (setq weightArray (nth n weightList)) 177 (dotimes (j jDimension) 178 (dotimes (i iDimension) 179 (setf 180 (aref weightArray i j) 181 (+ (aref weightArray i j) 182 (* alpha (aref deltaWeightArray i j)) 183 (* beta (aref oldDeltaWeightArray i j)))) 184 (setf (aref oldDeltaWeightArray i j) ; save current delta weights 185 (aref deltaWeightArray i j)))) ; ...for next momentum term. 186 (setq iDimension jDimension)) 187 188 (if plot-output-file-name 189 (DeltaPlot netList plot-output-file-name))) 190 191 (/ outputError jDimension))) The function DeltaRecall in the next listing can be used with a trained network to calculate outputs for new input values: Backpropagation Neural Networks 152 1 ;; 2 ; Utility for using a trained neural network in the recall mode. 3 ; The first argument to this function is a network definition (as 4 ; returned from NewDeltaNetwork) and the second argument is a list 5 ; of input neuron activation values to drive through the network. 6 ; The output is a list of the calculated activation energy for 7 ; each output neuron. 8 ;; 9 (defun DeltaRecall (netList inputs) 10 (let ((nLayers (car netList)) 11 (sizeList (cadr netList)) 12 (activationList (caddr netList)) 13 (weightList (cadr (cdddr netList))) 14 (iDimension nil) 15 (jDimension nil) 16 (iActivationVector nil) 17 (jActivationVector nil) 18 (n nil) 19 (weightArray nil) 20 (returnList nil) 21 (sum nil)) 22 (setq iDimension (car sizeList)) ; get the size of the input slab 23 (setq iActivationVector (car activationList)) ; get input activations 24 (dotimes (i iDimension) ; copy training inputs to input slab 25 (setf (aref iActivationVector i) (nth i inputs))) 26 (dotimes (n-1 (- nLayers 1)) ; update layer j to layer i 27 (setq n (+ n-1 1)) 28 (setq jDimension (nth n sizeList)) ; get the size of the j'th layer 29 (setq jActivationVector (nth n activationList)) ; activation for slab j 30 (setq weightArray (nth n-1 weightList)) 31 (dotimes (j jDimension) ; process each neuron in slab j 32 (setq sum 0.0) ; init sum of products to zero 33 (dotimes (i iDimension) ; get activation from each neuron in last slab 34 (setq 35 sum 36 (+ sum (* (aref weightArray i j) (aref iActivationVector i))))) 37 (if *delta-rule-debug-flag* 38 (print (list "sum=" sum))) 39 (setf (aref jActivationVector j) (Sigmoid sum))) 40 (setq iDimension jDimension) ; get ready for next slab pair 41 (setq iActivationVector jActivationVector)) 42 (dotimes (j jDimension) 43 (setq returnList (append returnList (list (aref jActivationVector j))))) Backpropagation Neural Networks 153 44 returnList)) We saw three output plots earlier that were produced during a training run using the following code: 1 (defun test3 (&optional (restart 'yes) &aux RMSerror) ; three layer network 2 (if 3 (equal restart 'yes) 4 (setq temp (newdeltanetwork '(5 4 5)))) 5 (dotimes (ii 3000) 6 (let ((file-name 7 (if (equal (mod ii 400) 0) 8 (concatenate 'string "output_plot_" (format nil "~12,'0d" ii) ".png") 9 nil))) 10 (setq 11 RMSerror 12 (deltalearn 13 file-name temp 14 '(((1 0 0 0 0) (0 1 0 0 0)) 15 ((0 1 0 0 0) (0 0 1 0 0)) 16 ((0 0 1 0 0) (0 0 0 1 0)) 17 ((0 0 0 1 0) (0 0 0 0 1)) 18 ((0 0 0 0 1) (1 0 0 0 0))))) 19 (if (equal (mod ii 50) 0) ;; print error out every 50 cycles 20 (progn 21 (princ "....training cycle \#") 22 (princ ii) 23 (princ " RMS error = ") 24 (princ RMSerror) 25 (terpri)))))) Here the function test3 defines training data for a very small test network for a moderately difficult function to learn: to rotate the values in the input neurons to the right, wrapping around to the first neuron. The start of the main loop in line calls the training function 3000 times, creating a plot of the network every 400 times through the main loop. Backpropagation networks have been used sucessfully in production for about 25 years. In the next chapter we will look at a less practical type of network, Hopfield networks, that are still interesting because the in some sense Hopfield networks model how our brains work. In the final chapter we will look at deep learning neural networks. Hopfield Neural Networks A Hopfield network⁶⁹ (named after John Hopfield) is a recurrent network since the flow of activation through the network has loops. These networks are trained by applying input patterns and letting the network settle in a state that stores the input patterns. The example code is in the file src/loving_snippets/Hopfield_neural_network.lisp. The example we look at recognizes patterns that are similar to the patterns seen in training examples and maps input patterns to a similar training input pattern. The following figure shows output from the example program showing an original training pattern, a similar pattern with one cell turned on and other off, and the reconstructed pattern: To be clear, we have taken one of the original input patterns the network has learned, slightly altered it, and applied it as input to the network. After cycling the network, the slightly scrambled input pattern we just applied will be used as an associative memory key, look up the original pattern, and rewrite to input values with the original learned pattern. These Hopfield networks are very different than backpropagation networks: neuron activation are forced to values of -1 or +1 and not be differentiable and there are no separate output neurons. The next example has the values of three cells modified from the original and the original pattern is still reconstructed correctly: ⁶⁹https://en.wikipedia.org/wiki/Hopfield_network Hopfield Neural Networks 155 This last example has four of the original cells modified: The following example program shows a type of content-addressable memory. After a Hopfield network learns a set of input patterns then it can reconstruct the original paterns when shown similar patterns. This reconstruction is not always perfecrt. The following function Hopfield-Init (in file Hopfield_neural_network.lisp) is passed a list of lists of training examples that will be remembered in the network. This function returns a list containing the data defining a Hopfield neural network. All data for the network is encapsulated in the list returned by this function, so multiple Hopfield neural networks can be used in an application program. In lines 9-12 we allocate global arrays for data storage and in lines 14-18 the training data is copied. The inner function adjustInput on lines 20-29 adjusts data values to values of -1.0 or +1.0. In lines 31-33 we are initializing all of the weights in the Hopfield network to zero. The last nested loop, on lines 35-52, calculates the autocorrelation weight matrix from the input test patterns. On lines 54-56, the function returns a representation of the Hopfield network that will be used later in the function HopfieldNetRecall to find the most similar “remembered” pattern given a new (fresh) input pattern. Hopfield Neural Networks 156 1 (defun Hopfield-Init (training-data 2 &aux temp *num-inputs* *num-training-examples* 3 *training-list* *inputCells* *tempStorage* 4 *HopfieldWeights*) 5 6 (setq *num-inputs* (length (car training-data))) 7 (setq *num-training-examples* (length training-data)) 8 9 (setq *training-list* (make-array (list *num-training-examples* *num-inputs*))) 10 (setq *inputCells* (make-array (list *num-inputs*))) 11 (setq *tempStorage* (make-array (list *num-inputs*))) 12 (setq *HopfieldWeights* (make-array (list *num-inputs* *num-inputs*))) 13 14 (dotimes (j *num-training-examples*) ;; copy training data 15 (dotimes (i *num-inputs*) 16 (setf 17 (aref *training-list* j i) 18 (nth i (nth j training-data))))) 19 20 (defun adjustInput (value) ;; this function is lexically scoped 21 (if (< value 0.1) 22 -1.0 23 +1.0)) 24 25 (dotimes (i *num-inputs*) ;; adjust training data 26 (dotimes (n *num-training-examples*) 27 (setf 28 (aref *training-list* n i) 29 (adjustInput (aref *training-list* n i))))) 30 31 (dotimes (i *num-inputs*) ;; zero weights 32 (dotimes (j *num-inputs*) 33 (setf (aref *HopfieldWeights* i j) 0))) 34 35 (dotimes (j-1 (- *num-inputs* 1)) ;; autocorrelation weight matrix 36 (let ((j (+ j-1 1))) 37 (dotimes (i j) 38 (dotimes (s *num-training-examples*) 39 (setq temp 40 (truncate 41 (+ 42 (* ;; 2 if's truncate values to -1 or 1: 43 (adjustInput (aref *training-list* s i)) Hopfield Neural Networks 157 44 (adjustInput (aref *training-list* s j))) 45 (aref *HopfieldWeights* i j)))) 46 (setf (aref *HopfieldWeights* i j) temp) 47 (setf (aref *HopfieldWeights* j i) temp))))) 48 (dotimes (i *num-inputs*) 49 (setf (aref *tempStorage* i) 0) 50 (dotimes (j i) 51 (setf (aref *tempStorage* i) 52 (+ (aref *tempStorage* i) (aref *HopfieldWeights* i j))))) 53 54 (list ;; return the value of the Hopfield network data object 55 *num-inputs* *num-training-examples* *training-list* 56 *inputCells* *tempStorage* *HopfieldWeights*)) The following function HopfieldNetRecall iterates the network to let it settle in a stable pattern which we hope will be the original training pattern most closely resembling the noisy test pattern. The inner (lexically scoped) function deltaEnergy defined on lines 9-12 calculates a change in energy from old input values and the autocorrelation weight matrix. The main code uses the inner functions to iterate over the input cells, possibly modifying the cell at index i delta energy is greater than zero. Remember that the lexically scoped inner functions have access to the variables for the number of inputs, the number of training examples, the list of training examples, the input cell values, tempoary storage, and the Hopfield network weights. 1 (defun HopfieldNetRecall (aHopfieldNetwork numberOfIterations) 2 (let ((*num-inputs* (nth 0 aHopfieldNetwork)) 3 (*num-training-examples* (nth 1 aHopfieldNetwork)) 4 (*training-list* (nth 2 aHopfieldNetwork)) 5 (*inputCells* (nth 3 aHopfieldNetwork)) 6 (*tempStorage* (nth 4 aHopfieldNetwork)) 7 (*HopfieldWeights* (nth 5 aHopfieldNetwork))) 8 9 (defun deltaEnergy (row-index y &aux (temp 0.0)) ;; lexically scoped 10 (dotimes (j *num-inputs*) 11 (setq temp (+ temp (* (aref *HopfieldWeights* row-index j) (aref y j))))) 12 (- (* 2.0 temp) (aref *tempStorage* row-index))) 13 14 (dotimes (ii numberOfIterations) ;; main code 15 (dotimes (i *num-inputs*) 16 (setf (aref *inputCells* i) 17 (if (> (deltaEnergy i *inputCells*) 0) 18 1 19 0)))))) Hopfield Neural Networks 158 Function test in the next listing uses three different patterns for each test. Note that only the last pattern gets plotted to the output graphics PNG file for the purpose of producing figures for this chapter. If you want to produce plots of other patterns, edit just the third pattern defined on line AAAAA. The following plotting functions are inner lexically scoped so they have access to the data defined in the enclosing let expression in lines 16-21: • plotExemplar - plots a vector of data • plot-original-inputCells - plots the original input cells from training data • plot-inputCells - plots the modified input cells (a few cells randomly flipped in value) • modifyInput - scrambles training inputs 1 (defun test (&aux aHopfieldNetwork) 2 (let ((tdata '( ;; sample sine wave data with different periods: 3 (1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0) 4 (0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0) 5 (0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 1))) 6 (width 300) 7 (height 180)) 8 (vecto::with-canvas (:width width :height height) 9 (plotlib:plot-string-bold 10 (- height 14) "Hopfield pattern classifier") 10 11 ;; Set up network: 12 (print tdata) 13 (setq aHopfieldNetwork (Hopfield-Init tdata)) 14 15 ;; lexically scoped variables are accesible by inner functions: 16 (let ((*num-inputs* (nth 0 aHopfieldNetwork)) 17 (*num-training-examples* (nth 1 aHopfieldNetwork)) 18 (*training-list* (nth 2 aHopfieldNetwork)) 19 (*inputCells* (nth 3 aHopfieldNetwork)) 20 (*tempStorage* (nth 4 aHopfieldNetwork)) 21 (*HopfieldWeights* (nth 5 aHopfieldNetwork))) 22 23 (defun plotExemplar (row &aux (dmin 0.0) (dmax 1.0) (x 20) (y 40)) 24 (let ((YSize (array-dimension *training-list* 1))) 25 (plotlib:plot-string (+ x 20) (- height (- y 10)) 26 "Original Training Exemplar") 27 (dotimes (j Ysize) 28 (plotlib:plot-fill-rect 29 (+ x (* j plot-size+1)) (- height y) plot-size plot-size 30 (truncate (* 31 (/ (- (aref *training-list* row j) dmin) Hopfield Neural Networks 159 32 (- dmax dmin)) 33 5))) 34 (plotlib:plot-frame-rect (+ x (* j plot-size+1)) 35 (- height y) plot-size plot-size)))) 36 37 (defun plot-original-inputCells (&aux (dmin 0.0) (dmax 1.0) (x 20) (y 80)) 38 (let ((Xsize (array-dimension *inputCells* 0))) 39 (plotlib:plot-string (+ x 20) (- height (- y 10)) "Scrambled Inputs") 40 (dotimes (j Xsize) 41 (plotlib:plot-fill-rect 42 (+ x (* j plot-size+1)) (- height y) plot-size plot-size 43 (truncate (* 44 (/ (- (aref *inputCells* j) dmin) (- dmax dmin)) 45 5))) 46 (plotlib:plot-frame-rect (+ x (* j plot-size+1)) 47 (- height y) plot-size plot-size)))) 48 49 (defun plot-inputCells (&aux (dmin 0.0) (dmax 1.0) (x 20) (y 120)) 50 (let ((Xsize (array-dimension *inputCells* 0))) 51 (plotlib:plot-string (+ x 20) (- height (- y 10)) 52 "Reconstructed Inputs") 53 (dotimes (j Xsize) 54 (plotlib:plot-fill-rect 55 (+ x (* j plot-size+1)) (- height y) plot-size plot-size 56 (truncate (* (/ 57 (- (aref *inputCells* j) dmin) 58 (- dmax dmin)) 59 5))) 60 (plotlib:plot-frame-rect 61 (+ x (* j plot-size+1)) (- height y) plot-size plot-size)))) 62 63 (defun modifyInput (arrSize arr) ;; modify input array for testing 64 (dotimes (i arrSize) 65 (if (< (random 50) 5) 66 (if (> (aref arr i) 0) 67 (setf (aref arr i) -1) 68 (setf (aref arr i) 1))))) 69 70 ;; Test network on training data that is randomly modified: 71 72 (dotimes (iter 10) ;; cycle 10 times and make 10 plots 73 (dotimes (s *num-training-examples*) 74 (dotimes (i *num-inputs*) Hopfield Neural Networks 160 75 (setf (aref *inputCells* i) (aref *training-list* s i))) 76 (plotExemplar s) 77 (modifyInput *num-inputs* *inputCells*) 78 (plot-original-inputCells) 79 (dotimes (call-net 5) ;; iterate Hopfield net 5 times 80 (HopfieldNetRecall aHopfieldNetwork 1) ;; calling with 1 iteration 81 (plot-inputCells))) 82 83 (vecto::save-png 84 (concatenate 85 'string 86 "output_plot_hopfield_nn_" (format nil "~5,'0d" iter) ".png"))))))) The plotting functions in lines 23-62 use the plotlib library to make the plots you saw earlier. The function modifyInput in lines 64-69 randomly flips the values of the input cells, taking an original pattern and slightly modifying it. Hopfield neural networks, at least to some extent, seem to model some aspects of human brains in the sense that they can function as content-addressable (also called associative) memories. Ideally a partial input pattern from a remembered input can reconstruct the complete original pattern. Another interesting feature of Hopfield networks is that these memories really are stored in a distributed fashion: some of the weights can be randomly altered and patterns are still remembered, but with more recall errors. Using Python Deep Learning Models In Common Lisp With a Web Services Interface In older editions of this book I had an example of using the Java DeepLearning4J deep learning library using Armed Bear Common Lisp, implemented in Java. I no longer use hybrid Java and Common Lisp applications in my own work and I decided to remove this example and replace it with two projects that use simple Python web services that act as wrappers for state of the art deep learning models with Common Lisp clients in the subdirectories: • src/spacy_web_client: use the spaCy deep learning models for general NLP. I sometimes use my own pure Common Lisp NLP libraries we saw in earlier chapters and sometimes I use a Common Lisp client calling deep learning libraries like spaCy and TensorFlow. • src/coref_web_client: coreference or anaphora resolution is the act of replacing pronouns in text with the original nouns that they refer to. This has traditionally been a very difficult and only partially solved problem until recent advances in deep learning models like BERT. Note: in the next chapter we will cover similar functionality but we will use the py4cl library to more directly use Python and libraries like spaCy by starting another Python process and using streams for communication. Setting up the Python Web Services Used in this Chapter You will need python and pip installed on your system. The source e code for the Python web services is found in the directory loving-common-lisp/python. Installing the spaCY NLP Services I assume that you have some familiarity with using Python. If not, you will still be able to follow these directions assuming that you have the utilities pip, and python installed. I recommend installing Python and Pip using Anaconda⁷⁰. ⁷⁰https://anaconda.org/anaconda/conda Using Python Deep Learning Models In Common Lisp With a Web Services Interface 162 The server code is in the subdirectory python/python_spacy_nlp_server where you will work when performing a one time initialization. After the server is installed you can then run it from the command line from any directory on your laptop. I recommend that you use virtual Python environments when using Python applications to separate the dependencies required for each application or development project. Here I assume that you are running in a Python version 3.6 or higher environment. First you must install the dependencies: 1 pip install -U spacy 2 python -m spacy download en 3 pip install falcon Then change directory to the subdirectory python/python_spacy_nlp_server in the git repo for this book and install the NLP server: 1 cd python/python_spacy_nlp_server 2 python setup.py install Once you install the server, you can run it from any directory on your laptop or server using: 1 spacynlpserver I use deep learning models written in Python using TensorFlow or PyTorch and provide Python web services that can be used in applications I write in Haskell or Common Lisp using web client interfaces for the services written in Python. While it is possible to directly embed models in Haskell and Common Lisp, I find it much easier and developer friendly to wrap deep learning models I use a REST services as I have done here. Often deep learning models only require about a gigabyte of memory and using pre-trained models has lightweight CPU resource needs so while I am developing on my laptop I might have two or three models running and available as wrapped REST services. For production, I configure both the Python services and my Haskell and Common Lisp applications to start automatically on system startup. This is not a Python programming book and I will not discuss the simple Python wrapping code but if you are also a Python developer you can easily read and understand the code. Installing the Coreference NLP Services I recommend that you use virtual Python environments when using Python applications to separate the dependencies required for each application or development project. Here I assume that you are running in a Python version 3.6 environment. First you should install the dependencies: Using Python Deep Learning Models In Common Lisp With a Web Services Interface 163 1 pip install spacy==2.1.0 2 pip install neuralcoref 3 pip install falcon As I write this chapter the neuralcoref model and library require a slightly older version of SpaCy (the current latest version is 2.1.4). Then change directory to the subdirectory python/python_coreference_anaphora_resolution_- server in the git repo for this book and install the coref server: 1 cd python_coreference_anaphora_resolution_server 2 python setup.py install Once you install the server, you can run it from any directory on your laptop or server using: 1 corefserver While. as we saw in the last example, it is possible to directly embed models in Haskell and Common Lisp, I find it much easier and developer friendly to wrap deep learning models I use a REST services as I have done here. Often deep learning models only require about a gigabyte of memory and using pre-trained models has lightweight CPU resource needs so while I am developing on my laptop I might have two or three models running and available as wrapped REST services. For production, I configure both the Python services and my Haskell and Common Lisp applications to start automatically on system startup. This is not a Python programming book and I will not discuss the simple Python wrapping code but if you are also a Python developer you can easily read and understand the code. Common Lisp Client for the spaCy NLP Web Services Before looking at the code, I will show you typical output from running this example: 1 $ sbcl 2 This is SBCL 1.3.16, an implementation of ANSI Common Lisp. 3 * (ql:quickload "spacy-web-client") 4 To load "spacy": 5 Load 1 ASDF system: 6 spacy-web-client 7 ; Loading "spacy-web-client" 8 ......... 9 ("spacy-web-client") 10 * (defvar x Using Python Deep Learning Models In Common Lisp With a Web Services Interface 164 11 (spacy-web-client:spacy-client 12 "President Bill Clinton went to Congress. He gave a speech on taxes and Mexico.")) 13 * (spacy-web-client:spacy-data-entities x) 14 "Bill Clinton/PERSON" 15 * (spacy-web-client:spacy-data-tokens x) 16 ("President" "Bill" "Clinton" "went" "to" "Congress" "." "He" "gave" "a" 17 "speech" "on" "taxes" "and" "Mexico" ".") The client library is implemented in the file src/spacy_web_client/spacy-web-client.lisp: 1 (in-package spacy-web-client) 2 3 (defvar base-url "http://127.0.0.1:8008?text=") 4 5 (defstruct spacy-data entities tokens) 6 7 (defun spacy-client (query) 8 (let* ((the-bytes 9 (drakma:http-request 10 (concatenate 'string 11 base-url 12 (do-urlencode:urlencode query)) 13 :content-type "application/text")) 14 (fetched-data 15 (flexi-streams:octets-to-string the-bytes :external-format :utf-8)) 16 (lists (with-input-from-string (s fetched-data) 17 (json:decode-json s)))) 18 (print lists) 19 (make-spacy-data :entities (cadar lists) :tokens (cdadr lists)))) On line 3 we define base URL for accessing the spaCy web service, assuming that it is running on your laptop and not a remote server. On line 5 we define a defstruct named spacy-data that has two fields: a list of entities in the input text and a list of word tokens in the input text. The function spacy-client builds a query string on lines 10-12 that consists of the base-url and the input query text URL encoded. The drakma library, that we used before, is used to make a HTTP request from the Python spaCy server. Lines 14-15 uses the flexi-streams package to convert raw byte data to UTF8 characters. Lines 16-17 use the json package to parse the UTF8 encoded string, getting two lists of strings. I left the debug printout expression in line 18 so that you can see the results of parsing the JSON data. The function make-spacy-data was generated for us by the defstruct statement on line 5. Using Python Deep Learning Models In Common Lisp With a Web Services Interface 165 Common Lisp Client for the Coreference NLP Web Services Let’s look at some typical output from this example, then we will look at the code: 1 $ sbcl 2 This is SBCL 1.3.16, an implementation of ANSI Common Lisp. 3 More information about SBCL is available at . 4 5 SBCL is free software, provided as is, with absolutely no warranty. 6 It is mostly in the public domain; some portions are provided under 7 BSD-style licenses. See the CREDITS and COPYING files in the 8 distribution for more information. 9 10 #P"/Users/markw/quicklisp/setup.lisp" 11 "starting up quicklisp" 12 * (ql:quickload "coref") 13 To load "coref": 14 Load 1 ASDF system: 15 coref 16 ; Loading "coref" 17 .................................................. 18 [package coref] 19 ("coref") 20 * (coref:coref-client "My sister has a dog Henry. She loves him.") 21 22 "My sister has a dog Henry. My sister loves a dog Henry." 23 * (coref:coref-client "My sister has a dog Henry. He often runs to her.") 24 25 "My sister has a dog Henry. a dog Henry often runs to My sister." Notice that pronouns in the input text are correctly replaced by the noun phrases that the pronoun refer to. The implementation for the core client is in the file src/coref_web_client/coref.lisp: Using Python Deep Learning Models In Common Lisp With a Web Services Interface 166 1 (in-package #:coref) 2 3 ;; (ql:quickload :do-urlencode) 4 5 (defvar base-url "http://127.0.0.1:8000?text=") 6 7 (defun coref-client (query) 8 (let ((the-bytes 9 (drakma:http-request 10 (concatenate 'string 11 base-url 12 (do-urlencode:urlencode query) 13 "&no_detail=1") 14 :content-type "application/text"))) 15 (flexi-streams:octets-to-string the-bytes :external-format :utf-8))) This code is similar to the example in the last section for setting up a call to http-request but is simpler: here the Python coreference web service accepts a string as input and returns a string as output with pronouns replaced by the nouns or noun phrases that they refer to. The example in the last section had to parse returned JSON data, this example does not. Trouble Shooting Possible Problems - Skip if this Example Works on Your System If you run Common Lisp in an IDE (for example in LispWorks’ IDE or VSCode with a Common Lisp plugin) make sure you start the IDE from the command line so your PATH environment variable will be set as it is in our bash or zsh shell. Make sure you are starting your Common Lisp program or running a Common Lisp repl with the same Python installation (if you have Quicklisp installed, then you also have the package uiop installed): 1 $ which python 2 /Users/markw/bin/anaconda3/bin/python 3 $ sbcl 4 This is SBCL 2.0.2, an implementation of ANSI Common Lisp. 5 * (uiop:run-program "which python" :output :string) 6 "/Users/markw/bin/anaconda3/bin/python" 7 nil 8 0 9 * Using Python Deep Learning Models In Common Lisp With a Web Services Interface 167 Python Interop Wrap-up Much of my professional work in the last five years involved deep learning models and currently most available software is written in Python. While there are available libraries for calling Python code from Common Lisp, these libraries tend to not work well for Python code using libraries like TensorFlow, spaCy, PyTorch, etc., especially if the Python code is configured to use GPUs via CUDA of special hardware like TPUs. I find it simpler to simply wrap functionality implemented in Python as a simple web service. Using the PY4CL Library to Embed Python in Common Lisp We will tackle the same problem as the previous chapter but take a different approach. Now we will use Ben Dudson’s project Py4CL⁷¹ that automatically starts a Python process and communicates with the Python process via a stream interface. The approach we took before is appropriate for large scale systems where you might want scale horizontally by having Python processes running on different servers than the servers used for the Common Lisp parts of your application. The approach we now take is much more convenient for what I call “laptop development” where the management of a Python process and communication is handled for you by the Py4CL library. If you need to build multi-server distributed systems for scaling reasons then use the examples in the last chapter. While Py4CL provides a lot of flexibility for passing primitive types between Common Lisp and Python (in both directions), I find it easiest to write small Python wrappers that only use lists, arrays, numbers, and strings as arguments and return types. You might want to experiment with the examples on the Py4CL GitHub page that let you directly call Python libraries without writing wrappers. When I write code for my own projects I try to make code as simple as possible so when I need to later revisit my own code it is immediately obvious what it is doing. Since I have been using Common Lisp for almost 40 years, I often find myself reusing bits of my own old code and I optimize for making this as easy as possible. In other words I favor readability over “clever” code. Project Structure, Building the Python Wrapper, and Running an Example The packaging of the Lisp code for my spacy-py4cl package is simple. Here is the listing of package.lisp for this project: 1 ;;;; package.lisp 2 3 (defpackage #:spacy-py4cl 4 (:use #:cl #:py4cl) 5 (:export #:nlp)) Listing of spacy-py4cl.asd: ⁷¹https://github.com/bendudson/py4cl/ Using the PY4CL Library to Embed Python in Common Lisp 169 1 ;;;; spacy-py4cl.asd 2 3 (asdf:defsystem #:spacy-py4cl 4 :description "Use py4cl to use Python spaCy library embedded in Common Lisp" 5 :author "Mark Watson " 6 :license "Apache 2" 7 :depends-on (#:py4cl) 8 :serial t 9 :components ((:file "package") 10 (:file "spacy-py4cl"))) You need to run a Python setup procedure to install the Python wrapper for space-py4cl on your system. Some output is removed for conciseness: 1 $ cd loving-common-lisp/src/spacy-py4cl 2 $ cd PYTHON_SPACY_SETUP_install/spacystub 3 $ pip install -U spacy 4 $ python -m spacy download en 5 $ python setup.py install 6 running install 7 running build 8 running build_py 9 running install_lib 10 running install_egg_info 11 Writing /Users/markw/bin/anaconda3/lib/python3.7/site-packages/spacystub-0.21-py3.7.\ 12 egg-info You only need to do this once unless you update to a later version of Python on your system. If you are not familiar with Python, it is worth looking at the wrapper implementation, otherwise skip the next few paragraphs. $ ls -R PYTHON_SPACY_SETUP_install spacystub PYTHON_SPACY_SETUP_install/spacystub: README.md setup.py spacystub PYTHON_SPACY_SETUP_install/spacystub/build/lib: spacystub PYTHON_SPACY_SETUP_install/spacystub/spacystub: parse.py Using the PY4CL Library to Embed Python in Common Lisp 170 Here is the implementation of setup.py that specifies how to build and install the wrapper globally for use on your system: 1 from distutils.core import setup 2 3 setup(name='spacystub', 4 version='0.21', 5 packages=['spacystub'], 6 license='Apache 2', 7 py_modules=['pystub'], 8 long_description=open('README.md').read()) The definition of the library in file PYTHON_SPACY_SETUP_install/spacystub/spacystub/parse.py: 1 import spacy 2 3 nlp = spacy.load("en") 4 5 def parse(text): 6 doc = nlp(text) 7 response = {} 8 response['entities'] = [(ent.text, ent.start_char, ent.end_char, ent.label_) for e\ 9 nt in doc.ents] 10 response['tokens'] = [token.text for token in doc] 11 return [response['tokens'], response['entities']] Here is a Common Lisp repl session showing you how to use the library implemented in the next section: 1 $ ccl 2 Clozure Common Lisp Version 1.12 DarwinX8664 3 4 For more information about CCL, please see http://ccl.clozure.com. 5 6 CCL is free software. It is distributed under the terms of the Apache Licence, Vers\ 7 ion 2.0. 8 ? (ql:quickload "spacy-py4cl") 9 To load "spacy-py4cl": 10 Load 1 ASDF system: 11 spacy-py4cl 12 ; Loading "spacy-py4cl" 13 [package spacy-py4cl] Using the PY4CL Library to Embed Python in Common Lisp 171 14 ("spacy-py4cl") 15 ? (spacy-py4cl:nlp "The President of Mexico went to Canada") 16 #(#("The" "President" "of" "Mexico" "went" "to" "Canada") #(("Mexico" 17 23 "GPE") (\ 17 "Canada" 32 38 "GPE"))) 18 ? (spacy-py4cl:nlp "Bill Clinton bought a red car. He drove it to the beach.") 19 #(#("Bill" "Clinton" "bought" "a" "red" "car" "." "He" "drove" "it" "to" "the" "beac\ 20 h" ".") #(("Bill Clinton" 0 12 "PERSON"))) Entities in text are identified with the starting and ending character indices that refer to the input string. For example, the entity “Mexico” starts at character position 17 and character index 23 is the character after the entity name in the input string. The entity type “GPE” refers to a country name and “PERSON” refers to a person’s name in the input text. Implementation of spacy-py4cl The Common Lisp implementation for this package is simple. In line 5 the call to py4cl:python-exec starts a process to run Python and imports the function parse from my Python wrapper. The call to py4cl:import-function in line 6 finds a function named “parse” in the attached Python process and generates a Common Lisp function with the same name that handles calling into Python and converting handling the returned values to Common Lisp values: 1 ;;;; spacy-py4cl.lisp 2 3 (in-package #:spacy-py4cl) 4 5 (py4cl:python-exec "from spacystub.parse import parse") 6 (py4cl:import-function "parse") 7 8 (defun nlp (text) 9 (parse text)) While it is possible to call Python libraries directly using Py4CL, when I need to frequently use Python libraries like spaCY, TensorFlow, fast.ai, etc. in Common Lisp, I like to use wrappers that use simple as possible data types and APIs to communicate between a Common Lisp process and the spawned Python process. Trouble Shooting Possible Problems - Skip if this Example Works on Your System When you install my wrapper library in Python on the command line whatever your shell if (bash, zsh, etc.) you should then try to import the library in a Python repl: Using the PY4CL Library to Embed Python in Common Lisp 172 1 $ python 2 Python 3.7.4 (default, Aug 13 2019, 15:17:50) 3 [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin 4 Type "help", "copyright", "credits" or "license" for more information. 5 >>> from spacystub.parse import parse 6 >>> parse("John Smith is a Democrat") 7 [['John', 'Smith', 'is', 'a', 'Democrat'], [('John Smith', 0, 10, 'PERSON'), ('Democ\ 8 rat', 16, 24, 'NORP')]] 9 >>> If this works and the Common Lisp library spacy-py4cl does not, then make sure you are starting your Common Lisp program or running a Common Lisp repl with the same Python installation (if you have Quicklisp installed, then you also have the package uiop installed): 1 $ which python 2 /Users/markw/bin/anaconda3/bin/python 3 $ sbcl 4 This is SBCL 2.0.2, an implementation of ANSI Common Lisp. 5 * (uiop:run-program "which python" :output :string) 6 "/Users/markw/bin/anaconda3/bin/python" 7 nil 8 0 9 * If you run Common Lisp in an IDE (for example in LispWorks’ IDE or VSCode with a Common Lisp plugin) make sure you start the IDE from the command line so your PATH environment variable will be set as it is in our bash or zsh shell. Wrap-up for Using Py4CL While I prefer Common Lisp for general development and also AI research, there are useful Python libraries that I want to integrate into my projects. I hope that the last chapter and this chapter provide you with two solid approaches for you to use in your own work to take advantage of Python libraries. Semantic Web and Linked Data I have written two previous books on the semantic web and linked data and most of my programming books have semantic web examples. Please note that the background material here on the semantic web standards RDF, RDFS, and SPARQL is shared with my book Practical Artificial Intelligence Programming With Java⁷² so if you have read that book then the first several pages of this chapter will seem familiar. Construction of Knowledge Graphs, as we will do in later chapters, is a core technology at many corporations and organizations to prevent data silos where different database systems are poorly connected and not as useful in combination than they could be. The use of RDF data stores is a powerful technique for data interoperability within organizations. Semantic Web standards like RDF, RDFS, and SPARQL support both building Knowledge Graphs and also key technologies for automating the collection and use of web data. I worked as a contractor at Google on an internal Knowledge Graph project and I currently work at Olive AI⁷³ on their Knowledge Graph team. The semantic web is intended to provide a massive linked set of data for use by software systems just as the World Wide Web provides a massive collection of linked web pages for human reading and browsing. The semantic web is like the web in that anyone can generate any content that they want. This freedom to publish anything works for the web because we use our ability to understand natural language to interpret what we read – and often to dismiss material that based upon our own knowledge we consider to be incorrect. Semantic web and linked data technologies are also useful for smaller amounts of data, an example being a Knowledge Graph containing information for a business. We will further explore Knowledge Graphs in the next two chapters. The core concept for the semantic web is data integration and use from different sources. As we will soon see, the tools for implementing the semantic web are designed for encoding data and sharing data from many different sources. I cover the semantic web in this book because I believe that semantic web technologies are complementary to AI systems for gathering and processing data on the web. As more web pages are generated by applications (as opposed to simply showing static HTML files) it becomes easier to produce both HTML for human readers and semantic data for software agents. There are several very good semantic web toolkits for the Java language and platform. Here we use Apache Jena because it is what I often use in my own work and I believe that it is a good starting technology for your first experiments with semantic web technologies. This chapter provides an ⁷²https://leanpub.com/javaai ⁷³https://oliveai.com Semantic Web and Linked Data 174 incomplete coverage of semantic web technologies and is intended as a gentle introduction to a few useful techniques and how to implement those techniques in Java. This chapter is the start of a journey in the technology that I think is as important as technologies like deep learning that get more public mindshare. The following figure shows a layered hierarchy of data models that are used to implement semantic web applications. To design and implement these applications we need to think in terms of physical models (storage and access of RDF, RDFS, and perhaps OWL data), logical models (how we use RDF and RDFS to define relationships between data represented as unique URIs and string literals and how we logically combine data from different sources) and conceptual modeling (higher level knowledge representation and reasoning using OWL). Originally RDF data was serialized as XML data but other formats have become much more popular because they are easier to read and manually create. The top three layers in the figure might be represented as XML, or as LD-JSON (linked data JSON) or formats like N-Triples and N3 that we will use later. Semantic Web Data Models Resource Description Framework (RDF) Data Model The Resource Description Framework (RDF) is used to encode information and the RDF Schema (RDFS) facilitates using data with different RDF encodings without the need to convert one set of schemas to another. Later, using OWL we can simply declare that one predicate is the same as another, that is, one predicate is a sub-predicate of another (e.g., a property containsCity can be declared to be a sub-property of containsPlace so if something contains a city then it also contains a place), etc. The predicate part of an RDF statement often refers to a property. Semantic Web and Linked Data 175 RDF data was originally encoded as XML and intended for automated processing. In this chapter we will use two simple to read formats called “N-Triples” and “N3.” Apache Jena can be used to convert between all RDF formats so we might as well use formats that are easier to read and understand. RDF data consists of a set of triple values: • subject • predicate • object Some of my work with semantic web technologies deals with processing news stories, extracting semantic information from the text, and storing it in RDF. I will use this application domain for the examples in this chapter and the next chapter when we implement code to automatically generate RDF for Knowledge Graphs. I deal with triples like: • subject: a URL (or URI) of a news article. • predicate: a relation like “containsPerson”. • object: a literal value like “Bill Clinton” or a URI representing Bill Clinton. In the next chapter we will use the entity recognition library we developed in an earlier chapter to create RDF from text input. We will use either URIs or string literals as values for objects. We will always use URIs for representing subjects and predicates. In any case URIs are usually preferred to string literals. We will see an example of this preferred use but first we need to learn the N-Triple and N3 RDF formats. I proposed the idea that RDF was more flexible than Object Modeling in programming languages, relational databases, and XML with schemas. If we can tag new attributes on the fly to existing data, how do we prevent what I might call “data chaos” as we modify existing data sources? It turns out that the solution to this problem is also the solution for encoding real semantics (or meaning) with data: we usually use unique URIs for RDF subjects, predicates, and objects, and usually with a preference for not using string literals. The definitions of predicates are tied to a namespace and later with OWL we will state the equivalence of predicates in different namespaces with the same semantic meaning. I will try to make this idea more clear with some examples and Wikipedia has a good writeup on RDF⁷⁴. Any part of a triple (subject, predicate, or object) is either a URI or a string literal. URIs encode namespaces. For example, the containsPerson predicate in the last example could be written as: http://knowledgebooks.com/ontology/#containsPerson The first part of this URI is considered to be the namespace for this predicate “containsPerson.” When different RDF triples use this same predicate, this is some assurance to us that all users of this ⁷⁴https://en.wikipedia.org/wiki/Resource_Description_Framework Semantic Web and Linked Data 176 predicate understand to the same meaning. Furthermore, we will see later that we can use RDFS to state equivalency between this predicate (in the namespace http://knowledgebooks.com/ontology/) with predicates represented by different URIs used in other data sources. In an “artificial intelligence” sense, software that we write does not understand predicates like “containsCity”, “containsPerson”, or “isLocation” in the way that a human reader can by combining understood common meanings for the words “contains”, “city”, “is”, “person”, and “location” but for many interesting and useful types of applications that is fine as long as the predicate is used consistently. We will see shortly that we can define abbreviation prefixes for namespaces which makes RDF and RDFS files shorter and easier to read. The Jena library supports most serialization formats for RDF: • Turtle • N3 • N-Triples • NQuads • TriG • JSON-LD • RDF/XML • RDF/JSON • TriX • RDF Binary A statement in N-Triple format consists of three URIs (two URIs and a string literals for the object) followed by a period to end the statement. While statements are often written one per line in a source file they can be broken across lines; it is the ending period which marks the end of a statement. The standard file extension for N-Triple format files is *.nt and the standard format for N3 format files is *.n3. My preference is to use N-Triple format files as output from programs that I write to save data as RDF. N-Triple files don’t use any abbreviations and each RDF statement is self-contained. I often use tools like the command line commands in Jena or RDF4J to convert N-Triple files to N3 or other formats if I will be reading them or even hand editing them. Here is an example using the N3 syntax: @prefix kb: kb:containsCountry "China" . The N3 format adds prefixes (abbreviations) to the N-Triple format. In practice it would be better to use the URI http://dbpedia.org/resource/China instead of the literal value “China.” Here we see the use of an abbreviation prefix “kb:” for the namespace for my company Knowledge- Books.com ontologies. The first term in the RDF statement (the subject) is the URI of a news article. The second term (the predicate) is “containsCountry” in the “kb:” namespace. The last item in the Semantic Web and Linked Data 177 statement (the object) is a string literal “China.” I would describe this RDF statement in English as, “The news article at URI http://news.com/201234 mentions the country China.” This was a very simple N3 example which we will expand to show additional features of the N3 notation. As another example, let’s look at the case if this news article also mentions the USA. Instead of adding a whole new statement like this we can combine them using N3 notation. Here we have two separate RDF statements: @prefix kb: . kb:containsCountry . kb:containsCountry . We can collapse multiple RDF statements that share the same subject and optionally the same predicate: @prefix kb: . kb:containsCountry , . The indentation and placement on separate lines is arbitrary - use whatever style you like that is readable. We can also add in additional predicates that use the same subject (I am going to use string literals here instead of URIs for objects to make the following example more concise but in practice prefer using URIs): @prefix kb: . kb:containsCountry "China" , "USA" . kb:containsOrganization "United Nations" ; kb:containsPerson "Ban Ki-moon" , "Gordon Brown" , "Hu Jintao" , "George W. Bush" , "Pervez Musharraf" , "Vladimir Putin" , "Mahmoud Ahmadinejad" . Semantic Web and Linked Data 178 This single N3 statement represents ten individual RDF triples. Each section defining triples with the same subject and predicate have objects separated by commas and ending with a period. Please note that whatever RDF storage system you use (we will be using Jena) it makes no difference if we load RDF as XML, N-Triple, of N3 format files: internally subject, predicate, and object triples are stored in the same way and are used in the same way. RDF triples in a data store represent directed graphs that may not all be connected. I promised you that the data in RDF data stores was easy to extend. As an example, let us assume that we have written software that is able to read online news articles and create RDF data that captures some of the semantics in the articles. If we extend our program to also recognize dates when the articles are published, we can simply reprocess articles and for each article add a triple to our RDF data store using a form like: @prefix kb: . kb:datePublished "2008-05-11" . Here we just represent the date as a string. We can add a type to the object representing a specific date: @prefix xsd: . @prefix kb: . kb:datePublished "2008-05-11"^^xsd:date . Furthermore, if we do not have dates for all news articles that is often acceptable because when constructing SPARQL queries you can match optional patterns. If for example you are looking up articles on a specific subject then some results may have a publication date attached to the results for that article and some might not. In practice RDF supports types and we would use a date type as seen in the last example, not a string. However, in designing the example programs for this chapter I decided to simplify our representation of URIs and often use string literals as simple Java strings. For many applications this isn’t a real limitation. Extending RDF with RDF Schema RDF Schema (RDFS) supports the definition of classes and properties based on set inclusion. In RDFS classes and properties are orthogonal. Let’s start with looking at an example using additional namespaces: Semantic Web and Linked Data 179 @prefix kb: . @prefix rdf: @prefix rdfs: @prefix dbo: kb:containsCountry . kb:containsCountry . rdfs:label "China"@en, rdf:type dbo:Place , rdf:type dbo:Country . Because the semantic web is intended to be processed automatically by software systems it is encoded as RDF. There is a problem that must be solved in implementing and using the semantic web: everyone who publishes semantic web data is free to create their own RDF schemas for storing data; for example, there is usually no single standard RDF schema definition for topics like news stories and stock market data. The SKOS⁷⁵ is a namespace containing standard schemas and the most widely used standard is schema.org⁷⁶. Understanding the ways of integrating different data sources using different schemas helps to understand the design decisions behind the semantic web applications. In this chapter I often use my own schemas in the knowledgebooks.com namespace for the simple examples you see here. When you build your own production systems part of the work is searching through schema.org and SKOS to use standard name spaces and schemas when possible. The use of standard schemas helps when you link internal proprietary Knowledge Graphs used in organization with public open data from sources like WikiData⁷⁷ and DBPedia⁷⁸. We will start with an example that is an extension of the example in the last section that also uses RDFS. We add a few additional RDF statements: ⁷⁵https://www.w3.org/2009/08/skos-reference/skos.html ⁷⁶https://schema.org/docs/schemas.html ⁷⁷https://www.wikidata.org/wiki/Wikidata:Main_Page ⁷⁸https://wiki.dbpedia.org/about Semantic Web and Linked Data 180 @prefix kb: . @prefix rdfs: . kb:containsCity rdfs:subPropertyOf kb:containsPlace . kb:containsCountry rdfs:subPropertyOf kb:containsPlace . kb:containsState rdfs:subPropertyOf kb:containsPlace . The last three lines declare that: • The property containsCity is a sub-property of containsPlace. • The property containsCountry is a sub-property of containsPlace. • The property containsState is a sub-property of containsPlace. Why is this useful? For at least two reasons: • You can query an RDF data store for all triples that use property containsPlace and also match triples with properties equal to containsCity, containsCountry, or containsState. There may not even be any triples that explicitly use the property containsPlace. • Consider a hypothetical case where you are using two different RDF data stores that use different properties for naming cities: cityName and city. You can define cityName to be a sub-property of city and then write all queries against the single property name city. This removes the necessity to convert data from different sources to use the same Schema. You can also use OWL to state property and class equivalency. In addition to providing a vocabulary for describing properties and class membership by properties, RDFS is also used for logical inference to infer new triples, combine data from different RDF data sources, and to allow effective querying of RDF data stores. We will see examples of all of these features of RDFS when we later start using the Jena libraries to perform SPARQL queries. The SPARQL Query Language SPARQL is a query language used to query RDF data stores. While SPARQL may initially look like SQL, we will see that there are some important differences like support for RDFS and OWL inferencing and graph-based instead of relational matching operations. We will cover the basics of SPARQL in this section and then see more examples later when we learn how to embed Jena in Java applications, and see more examples in the last chapter Knowledge Graph Navigator. We will use the N3 format RDF file test_data/news.n3 for the examples. I created this file automatically by spidering Reuters news stories on the news.yahoo.com web site and automatically extracting named entities from the text of the articles. We saw techniques for extracting named entities from text in earlier chapters. In this chapter we use these sample RDF files. You have already seen snippets of this file and I list the entire file here for reference, edited to fit line width: you may find the file news.n3 easier to read if you are at your computer and open the file in a text editor so you will not be limited to what fits on a book page: Semantic Web and Linked Data 181 @prefix kb: . @prefix rdfs: . kb:containsCity rdfs:subPropertyOf kb:containsPlace . kb:containsCountry rdfs:subPropertyOf kb:containsPlace . kb:containsState rdfs:subPropertyOf kb:containsPlace . kb:containsCity "Burlington" , "Denver" , "St. Paul" ," Chicago" , "Quincy" , "CHICAGO" , "Iowa City" ; kb:containsRegion "U.S. Midwest" , "Midwest" ; kb:containsCountry "United States" , "Japan" ; kb:containsState "Minnesota" , "Illinois" , "Mississippi" , "Iowa" ; kb:containsOrganization "National Guard" , "U.S. Department of Agriculture" , "White House" , "Chicago Board of Trade" , "Department of Transportation" ; kb:containsPerson "Dena Gray-Fisher" , "Donald Miller" , "Glenn Hollander" , "Rich Feltes" , "George W. Bush" ; kb:containsIndustryTerm "food inflation" , "food" , "finance ministers" , "oil" . kb:containsCity "Washington" , "Baghdad" , "Arlington" , "Flint" ; kb:containsCountry "United States" , "Afghanistan" , "Iraq" ; kb:containsState "Illinois" , "Virginia" , "Arizona" , "Michigan" ; kb:containsOrganization "White House" , "Obama administration" , "Iraqi government" ; Semantic Web and Linked Data 182 kb:containsPerson "David Petraeus" , "John McCain" , "Hoshiyar Zebari" , "Barack Obama" , "George W. Bush" , "Carly Fiorina" ; kb:containsIndustryTerm "oil prices" . kb:containsCity "WASHINGTON" ; kb:containsCountry "United States" , "Pakistan" , "Islamic Republic of Iran" ; kb:containsState "Maryland" ; kb:containsOrganization "University of Maryland" , "United Nations" ; kb:containsPerson "Ban Ki-moon" , "Gordon Brown" , "Hu Jintao" , "George W. Bush" , "Pervez Musharraf" , "Vladimir Putin" , "Steven Kull" , "Mahmoud Ahmadinejad" . kb:containsCity "Sao Paulo" , "Kuala Lumpur" ; kb:containsRegion "Midwest" ; kb:containsCountry "United States" , "Britain" , "Saudi Arabia" , "Spain" , "Italy" , India" , ""France" , "Canada" , "Russia" , "Germany" , "China" , "Japan" , "South Korea" ; kb:containsOrganization "Federal Reserve Bank" , "European Union" , "European Central Bank" , "European Commission" ; kb:containsPerson "Lee Myung-bak" , "Rajat Nag" , "Luiz Inacio Lula da Silva" , "Jeffrey Lacker" ; kb:containsCompany "Development Bank Managing" , "Reuters" , "Richmond Federal Reserve Bank" ; kb:containsIndustryTerm "central bank" , "food" , "energy costs" , Semantic Web and Linked Data 183 "finance ministers" , "crude oil prices" , "oil prices" , "oil shock" , "food prices" , "Finance ministers" , "Oil prices" , "oil" . In the following examples, we will use the main method in the class JenaApi (developed in the next section) that allows us to load multiple RDF input files and then to interactively enter SPARQL queries. We will start with a simple SPARQL query for subjects (news article URLs) and objects (matching countries) with the value for the predicate equal to containsCountry. Variables in queries start with a question mark character and can have any names: SELECT ?subject ?object WHERE { ?subject ?object . } It is important for you to understand what is happening when we apply the last SPARQL query to our sample data. Conceptually, all the triples in the sample data are scanned, keeping the ones where the predicate part of a triple is equal to http://knowledgebooks.com/ontology#containsCountry. In practice RDF data stores supporting SPARQL queries index RDF data so a complete scan of the sample data is not required. This is analogous to relational databases where indices are created to avoid needing to perform complete scans of database tables. In practice, when you are exploring a Knowledge Graph like DBPedia or WikiData (that are just very large collections of RDF triples), you might run a query and discover a useful or interesting entity URI in the triple store, then drill down to find out more about the entity. In a later chapter Knowledge Graph Navigator we attempt to automate this exploration process using the DBPedia data as a Knowledge Graph. We will be using the same code to access the small example of RDF statements in our sample data as we will for accessing DBPedia or WikiData. We can make this last query easier to read and reduce the chance of misspelling errors by using a namespace prefix: Semantic Web and Linked Data 184 PREFIX kb: SELECT ?subject ?object WHERE { ?subject kb:containsCountry ?object . } Later in the chapter Knowledge Graph Navigator we will write an application that automatically generates SPARQL queries for the DBPedia public knowledge Graph. These queries will be be more complex than the simpler examples here. Reading this chapter before Knowledge Graph Navigator is recommended. Case Study: Using SPARQL to Find Information about Board of Directors Members of Corporations and Organizations Before we write software to automate the process of using SPARQL queries to find information on DBPedia, let’s perform a few manual queries for finding information on board of directors of corportations. To start with, we would like to find an RDF property that indicates board membership. There is a common expression for finding information on the web using search engines and also for using SPARQL queries: “follow your nose,” that is, when you see something interesting, dig down with more queries on whatever interests you. SELECT DISTINCT ?s WHERE { ?s ?p "Board of Directors"@en . FILTER (?p IN (, ) && !regex(str(?s), "category", "i")) } We will find the property: http://dbpedia.org/resource/Board_of_Directors RDF select ?s ?p { ?s ?p } limit 6 Semantic Web and Linked Data 185 s p http://en.wikipedia.org/wiki/Board_of_Directors http://xmlns.com/foaf/0.1/primaryTop\ ic http://dbpedia.org/resource/Lynn_D._Stewart_(businessman) http://dbpedia.org/ontolog\ y/board http://dbpedia.org/resource/Advance_America_Cash_Advance http://dbpedia.org/ontology\ /keyPerson http://dbpedia.org/resource/Railways_of_Slovak_Republic http://dbpedia.org/ontology/\ keyPerson http://dbpedia.org/resource/Divine_Word_University_of_Tacloban__DWU_Jubilee_Foundati\ on,_Inc.__1 http://dbpedia.org/ontology/keyPerson http://dbpedia.org/resource/Mathys_Medical The property http://dbpedia.org/ontology/board is what we are looking for. Let’s keep “following our nose” to find examples of board members and the companies they server: select ?person ?company { ?person ?company} limi\ t 6 The results are: person company http://dbpedia.org/resource/Matthew_Buckland http://dbpedia.org/resource/Creative_Co\ mmons http://dbpedia.org/resource/Jimmy_Wales http://dbpedia.org/resource/Creative_Commons http://dbpedia.org/resource/Nabeel_Rajab http://dbpedia.org/resource/Human_Rights_Wa\ tch http://dbpedia.org/resource/Vincent_Tewson http://dbpedia.org/resource/International\ _Confederation_of_Free_Trade_Unions http://dbpedia.org/resource/William_T._Young http://dbpedia.org/resource/KFC http://dbpedia.org/resource/Colonel_Sanders http://dbpedia.org/resource/KFC Let’s see what information we can find on the founder of WikiPedi Jimmy Wales: select ?p ?o { ?p ?o } limit 200 A few of the many results are: Semantic Web and Linked Data 186 p o http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Thing http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://xmlns.com/foaf/0.1/Person http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Person http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.wikidata.org/entity/Q2156\ 27 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.wikidata.org/entity/Q2422\ 9398 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.wikidata.org/entity/Q5 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Agent http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://schema.org/Person http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/Wikica\ tAmericanComputerScientists http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/Wikica\ tAmericanExpatriatesInTheUnitedKingdom http://www.w3.org/2000/01/rdf-schema#label "Jimmy Wales"@en Installing the Apache Jena Fuseki RDF Server TBD I have a github repository mark-watson/fuseki-semantic-web-dev-setup⁷⁹mthat you shoud clone: 1 git clone https://github.com/mark-watson/fuseki-semantic-web-dev-setup.git 2 cd fuseki-semantic-web-dev-setup 3 ./fuseki-server --file RDF/sample_news.nt /news This will run the SPARQL server Fuseki locally on your laptop and the default graph is “news” and you will see output like: ⁷⁹https://github.com/mark-watson/fuseki-semantic-web-dev-setup Semantic Web and Linked Data 187 1 $ ./fuseki-server --file RDF/sample_news.nt /news 2 [2020-11-07 09:31:13] Server INFO Dataset: in-memory: load file: RDF/sample_new\ 3 s.nt 4 [2020-11-07 09:31:14] Server INFO Running in read-only mode for /news 5 [2020-11-07 09:31:14] Server INFO Apache Jena Fuseki 3.16.0 6 [2020-11-07 09:31:14] Config INFO FUSEKI_HOME=/Users/markw/GITHUB/fuseki-semant\ 7 ic-web-dev-setup/. 8 [2020-11-07 09:31:14] Config INFO FUSEKI_BASE=/Users/markw/GITHUB/fuseki-semant\ 9 ic-web-dev-setup/run 10 [2020-11-07 09:31:14] Config INFO Shiro file: file:///Users/markw/GITHUB/fuseki\ 11 -semantic-web-dev-setup/run/shiro.ini 12 [2020-11-07 09:31:15] Server INFO Dataset Type: in-memory, with files loaded 13 [2020-11-07 09:31:15] Server INFO Path = /news 14 [2020-11-07 09:31:15] Server INFO System 15 [2020-11-07 09:31:15] Server INFO Memory: 4.0 GiB 16 [2020-11-07 09:31:15] Server INFO Java: 14.0.1 17 [2020-11-07 09:31:15] Server INFO OS: Mac OS X 10.15.7 x86_64 18 [2020-11-07 09:31:15] Server INFO PID: 3855 19 [2020-11-07 09:31:15] Server INFO Started 2020/11/07 09:31:15 MST on port 3030 You can access a web interface for SPARQL queries by accessing localhost:3030 or http:127.0.0.1:3030. Common Lisp Client Examples for the Apache Jena Fuseki RDF Server Later in the chapter “Knowledge Graph Navigator” we will develop a simple Common Lisp SPARQL query library and use it for querying DBPedia. Here we will use it to query our local Fuseki server. 1 $ sbcl 2 This is SBCL 2.0.7, an implementation of ANSI Common Lisp. 3 More information about SBCL is available at . 4 5 SBCL is free software, provided as is, with absolutely no warranty. 6 It is mostly in the public domain; some portions are provided under 7 BSD-style licenses. See the CREDITS and COPYING files in the 8 distribution for more information. 9 10 #P"/Users/markw/quicklisp/setup.lisp" 11 "starting up quicklisp" 12 * (quicklisp:quickload "sparql") 13 To load "sparql": Semantic Web and Linked Data 188 14 Load 1 ASDF system: 15 sparql 16 ; Loading "sparql" 17 ............... 18 ("sparql") 19 * (sparql::fuseki "select ?s ?p ?o { ?s ?p ?o } limit 20") 20 (((:s "http://kbsportal.com/trout_season/") 21 (:p "http://knowledgebooks.com/ontology/#storyType") 22 (:o "http://knowledgebooks.com/ontology/#recreation")) 23 ((:s "http://kbsportal.com/trout_season/") 24 (:p "http://knowledgebooks.com/ontology/#storyType") 25 (:o "http://knowledgebooks.com/ontology/#sports")) 26 ((:s "http://kbsportal.com/bear_mountain_fire/") 27 (:p "http://knowledgebooks.com/ontology/#storyType") 28 (:o "http://knowledgebooks.com/ontology/#disaster")) 29 ((:s "http://kbsportal.com/bear_mountain_fire/") 30 (:p "http://knowledgebooks.com/ontology/#summary") 31 (:o "The fire on Bear Mountain was caused by lightening")) 32 ((:s "http://kbsportal.com/jc_basketball/") 33 (:p "http://knowledgebooks.com/ontology/#storyType") 34 (:o "http://knowledgebooks.com/ontology/#sports")) 35 ((:s "http://kbsportal.com/oak_creek_flooding/") 36 (:p "http://knowledgebooks.com/ontology/#storyType") 37 (:o "http://knowledgebooks.com/ontology/#disaster")) 38 ((:s "http://kbsportal.com/oak_creek_flooding/") 39 (:p "http://knowledgebooks.com/ontology/#summary") 40 (:o "Oak Creek flooded last week affecting 5 businesses"))) Here is an example of using the same library to query the public DBPedia SPARQL endpoint (most output is not shown): 1 * (sparql:dbpedia "select ?s ?p { ?s ?p \"Bill Gates\"@en }") 2 3 ("ndbpeia SPARQL:n" "select ?s ?p { ?s ?p \"Bill Gates\"@en }" "n") 4 (((:s "http://dbpedia.org/resource/Category:Bill_Gates") 5 (:p "http://www.w3.org/2000/01/rdf-schema#label")) 6 ((:s "http://www.wikidata.org/entity/Q5284") 7 (:p "http://www.w3.org/2000/01/rdf-schema#label")) 8 ((:s "http://dbpedia.org/resource/Bill_Gates") 9 (:p "http://xmlns.com/foaf/0.1/name")) 10 ) The SPARQL library in the github repository for this book also supports the commercial products Semantic Web and Linked Data 189 AllegroGraph and Stardog RDF servers. Automatically Generating Data for Knowledge Graphs We develop a complete application. The Knowledge Graph Creator (KGcreator) is a tool for automating the generation of data for Knowledge Graphs from raw text data. We will see how to create a single standalone executable file using SBCL Common Lisp. The application can also be run during development from a repl. This application also implements a web application interface. In addition to the KGcreator application we will close the chapter with a utiity library that processes a file of RDF in N-Triple format and generates an extention file with triples pulled from DBedia defining URIs found in the input data file. Data created by KGcreator generates data in two formats: • Neo4j graph database format (text format) • RDF triples suitable for loading into any linked data/semantic web data store. This example application works by identifying entities in text. Example entity types are people, companies, country names, city names, broadcast network names, political party names, and university names. We saw earlier code for detecting entities in the chapter on natural language processing (NLP) and we will reuse this code. We will discuss later three strategies for reusing code from different projects. When I originally wrote KGCreator I intended to develop a commercial product. I wrote two research prototypes, one in Common Lisp (the example in this chapter) and one in Haskell (which I also use as an example in my book Haskell Tutorial and Cookbook⁸⁰. I decided to open source both versions of KGCreator and if you work with Knowledge Graphs I hope you find KGCreator useful in your work. The following figure shows part of a Neo4j Knowledge Graph created with the example code. This graph has shortened labels in displayed nodes but Neo4j offers a web browser-based console that lets you interactively explore Knowledge Graphs. We don’t cover setting up Neo4j here so please use the Neo4j documentation⁸¹. As an introduction to RDF data, the semantic web, and linked data you can get free copies of my two books Practical Semantic Web and Linked Data Applications, Common Lisp Edition⁸² and Practical Semantic Web and Linked Data Applications, Java, Scala, Clojure, and JRuby Edition⁸³. ⁸⁰https://leanpub.com/haskell-cookbook/ ⁸¹https://neo4j.com/docs/operations-manual/current/introduction/ ⁸²http://markwatson.com/opencontentdata/book_lisp.pdf ⁸³http://markwatson.com/opencontentdata/book_java.pdf Automatically Generating Data for Knowledge Graphs 191 Part of a Knowledge Graph shown in Neo4j web application console Here is a detail view: Detail of Neo4j console Implementation Notes As seen in the file src /kgcreator/package.lisp this application uses several other packages: Automatically Generating Data for Knowledge Graphs 192 1 (defpackage #:kgcreator 2 (:use #:cl 3 #:entities_dbpedia #:categorize_summarize #:myutils 4 #:cl-who #:hunchentoot #:parenscript) 5 (:export kgcreator)) The implementation of the packages shown on line 3 were in a previous chapter. The packagemyutils are mostly miscellaneous string utilities that we won’t look at here; I leave it to you to read the source code. As seen in the configuration file src/kgcreator/kgcreator.asd we split the implementation of the application into four source files: 1 ;;;; kgcreator.asd 2 3 (asdf:defsystem #:kgcreator 4 :description "Describe plotlib here" 5 :author "Mark Watson " 6 :license "AGPL version 3" 7 :depends-on (#:entities_dbpedia #:categorize_summarize 8 #:myutils #:unix-opts #:cl-who 9 #:hunchentoot #:parenscript) 10 :components 11 ((:file "package") 12 (:file "kgcreator") 13 (:file "neo4j") 14 (:file "rdf") 15 (:file "web")) 16 ) The application is separated into four source files: • kgcreator.lisp: top level APIs and functionality. Uses the code in neo4j.lisp and rdf.lisp. Later we will generate a standalone application that uses these top level APIs • neo4j.lisp: generates Cyper text files that can be imported into Neo4j • – rdf.lisp: generates RDF text data that can be loaded or imported into RDF data stores • web.lisp: a simple web application for running KGCreator Generating RDF Data I leave it to you find a tutorial on RDF data on the web, or you can get a PDF for my book “Practical Semantic Web and Linked Data Applications, Common Lisp Edition”⁸⁴ and read the tutorial sections on RDF. ⁸⁴http://markwatson.com/opencontentdata/book_lisp.pdf Automatically Generating Data for Knowledge Graphs 193 RDF data is comprised of triples, where the value for each triple are a subject, a predicate, and an object. Subjects are URIs, predicates are usually URIs, and objects are either literal values or URIs. Here are two triples written by this example application: "Wall Street Journal" . . The following listing of the file src/kgcreator/rdf.lisp generates RDF data: 1 (in-package #:kgcreator) 2 3 (let ((*rdf-nodes-hash*)) 4 5 (defun rdf-from-files (output-file-path text-and-meta-pairs) 6 (setf *rdf-nodes-hash* (make-hash-table :test #'equal :size 200)) 7 (print (list "==> rdf-from-files" output-file-path text-and-meta-pairs )) 8 (with-open-file 9 (str output-file-path 10 :direction :output 11 :if-exists :supersede 12 :if-does-not-exist :create) 13 14 (defun rdf-from-files-handle-single-file (text-input-file meta-input-file) 15 (let* ((text (file-to-string text-input-file)) 16 (words (myutils:words-from-string text)) 17 (meta (file-to-string meta-input-file))) 18 19 (defun generate-original-doc-node-rdf () 20 (let ((node-name (node-name-from-uri meta))) 21 (if (null (gethash node-name *rdf-nodes-hash*)) 22 (let* ((cats (categorize words)) 23 (sum (summarize words cats))) 24 (print (list "$$$$$$ cats:" cats)) 25 (setf (gethash node-name *rdf-nodes-hash*) t) 26 (format str (concatenate 'string "<" meta 27 "> \"" 28 sum "\" . ~%")) 29 (dolist (cat cats) 30 (let ((hash-check (concatenate 'string node-name (car cat)))) Automatically Generating Data for Knowledge Graphs 194 31 (if (null (gethash hash-check *rdf-nodes-hash*)) 32 (let () 33 (setf (gethash hash-check *rdf-nodes-hash*) t) 34 (format str 35 (concatenate 'string "<" meta 36 "> " 38 " . ~%")))))))))) 40 41 (defun generate-dbpedia-contains-rdf (key value) 42 (generate-original-doc-node-rdf) 43 (let ((relation-name (concatenate 'string key "DbPediaLink"))) 44 (dolist (entity-pair value) 45 (let* ((node-name (node-name-from-uri meta)) 46 (object-node-name (node-name-from-uri (cadr entity-pair))) 47 (hash-check (concatenate 'string node-name object-node-name))) 48 (if (null (gethash hash-check *rdf-nodes-hash*)) 49 (let () 50 (setf (gethash hash-check *rdf-nodes-hash*) t) 51 (format str (concatenate 'string "<" meta 52 "> " (cadr entity-pair) " .~%")))))))))) 54 55 56 ;; start code for rdf-from-files (output-file-path text-and-meta-pairs) 57 (dolist (pair text-and-meta-pairs) 58 (rdf-from-files-handle-single-file (car pair) (cadr pair)) 59 (let ((h (entities_dbpedia:find-entities-in-text (file-to-string (car pair))\ 60 ))) 61 (entities_dbpedia:entity-iterator #'generate-dbpedia-contains-rdf h)))))) 62 63 64 (defvar test_files '((#P"~/GITHUB/common-lisp/kgcreator/test_data/test3.txt" 65 #P"~/GITHUB/common-lisp/kgcreator/test_data/test3.meta"))) 66 (defvar test_filesZZZ '((#P"~/GITHUB/common-lisp/kgcreator/test_data/test3.txt" 67 #P"~/GITHUB/common-lisp/kgcreator/test_data/test3.meta") 68 (#P"~/GITHUB/common-lisp/kgcreator/test_data/test2.txt" 69 #P"~/GITHUB/common-lisp/kgcreator/test_data/test2.meta") 70 (#P"~/GITHUB/common-lisp/kgcreator/test_data/test1.txt" 71 #P"~/GITHUB/common-lisp/kgcreator/test_data/test1.meta"))) 72 73 (defun test3a () Automatically Generating Data for Knowledge Graphs 195 74 (rdf-from-files "out.rdf" test_files)) You can load all of KGCreator but just execute the test function at the end of this file using: (ql:quickload "kgcreator") (in-package #:kgcreator) (kgcreator:test3a) This code works on a list of paired files for text data and the meta data for each text file. As an example, if there is an input text file test123.txt then there would be a matching meta file test123.meta that contains the source of the data in the file test123.txt. This data source will be a URI on the web or a local file URI. The top level function rdf-from-files takes an output file path for writing the generated RDF data and a list of pairs of text and meta file paths. A global variable *rdf-nodes-hash* will be used to remember the nodes in the RDF graph as it is generated. Please note that the function rdf-from-files is not re-entrant: it uses the global *rdf- nodes-hash* so if you are writing multi-threaded applications it will not work to execute the function rdf-from-files simultaneously in multiple threads of execution. The function rdf-from-files (and the nested functions) are straightforward. I left a few debug printout statements in the code and when you run the test code that I left in the bottom of the file, hopefully it will be clear what rdf.lisp is doing. Generating Data for the Neo4j Graph Database Now we will generate Neo4J Cypher data. In order to keep the implementation simple, both the RDF and Cypher generation code starts with raw text and performs the NLP analysis to find entities. This example could be refactored to perform the NLP analysis just one time but in practice you will likely be working with either RDF or NEO4J and so you will probably extract just the code you need from this example (i.e., either the RDF or Cypher generation code). Before we look at the code, let’s start with a few lines of generated Neo4J Cypher import data: CREATE (newsshop_com_june_z902_html_news)-[:ContainsCompanyDbPediaLink]->(Wall_Stree\ t_Journal) CREATE (Canada:Entity {name:"Canada", uri:""}) CREATE (newsshop_com_june_z902_html_news)-[:ContainsCountryDbPediaLink]->(Canada) CREATE (summary_of_abcnews_go_com_US_violent_long_lasting_tornadoes_threaten_oklahom\ a_texas_storyid63146361:Summary {name:"summary_of_abcnews_go_com_US_violent_long_las\ ting_tornadoes_threaten_oklahoma_texas_storyid63146361", uri:"", sum\ mary:"Part of the system that delivered severe weather to the central U.S. over the \ weekend is moving into the Northeast today, producing strong to severe storms -- dam\ Automatically Generating Data for Knowledge Graphs 196 aging winds, hail or isolated tornadoes can't be ruled out. Severe weather is foreca\ st to continue on Tuesday, with the western storm moving east into the Midwest and p\ arts of the mid-Mississippi Valley."}) The following listing of file src/kgcreator/neo4j.lisp is similar to the code that generated RDF in the last section: 1 (in-package #:kgcreator) 2 3 (let ((*entity-nodes-hash*)) 4 5 (defun cypher-from-files (output-file-path text-and-meta-pairs) 6 (setf *entity-nodes-hash* (make-hash-table :test #'equal :size 200)) 7 ;;(print (list "==> cypher-from-files"output-file-path text-and-meta-pairs )) 8 (with-open-file 9 (str output-file-path 10 :direction :output 11 :if-exists :supersede 12 :if-does-not-exist :create) 13 14 (defun generateNeo4jCategoryNodes () 15 (let* ((names categorize_summarize::categoryNames)) 16 (dolist (name names) 17 (format str 18 (myutils:replace-all 19 (concatenate 20 'string "CREATE (" name ":CategoryType {name:\"" name "\"})~%") 21 "/" "_")))) 22 (format str "~%")) 23 24 25 (defun cypher-from-files-handle-single-file (text-input-file meta-input-file) 26 (let* ((text (file-to-string text-input-file)) 27 (words (myutils:words-from-string text)) 28 (meta (file-to-string meta-input-file))) 29 30 (defun generate-original-doc-node () 31 (let ((node-name (node-name-from-uri meta))) 32 (if (null (gethash node-name *entity-nodes-hash*)) 33 (let* ((cats (categorize words)) 34 (sum (summarize words cats))) 35 (setf (gethash node-name *entity-nodes-hash*) t) 36 (format str (concatenate 'string "CREATE (" node-name ":News {name:\"" Automatically Generating Data for Knowledge Graphs 197 37 node-name "\", uri: \"" meta 38 "\", summary: \"" sum "\"})~%")) 39 (dolist (cat cats) 40 (let ((hash-check (concatenate 'string node-name (car cat)))) 41 (if (null (gethash hash-check *entity-nodes-hash*)) 42 (let () 43 (setf (gethash hash-check *entity-nodes-hash*) t) 44 (format str (concatenate 'string "CREATE (" node-name 45 ")-[:Category]->(" 46 (car cat) ")~%")))))))))) 47 48 (defun generate-dbpedia-nodes (key entity-pairs) 49 (dolist (entity-pair entity-pairs) 50 (if (null (gethash (node-name-from-uri (cadr entity-pair)) 51 *entity-nodes-hash*)) 52 (let () 53 (setf (gethash (node-name-from-uri (cadr entity-pair)) *entity-nodes-hash*) t) 54 (format str 55 (concatenate 'string "CREATE (" (node-name-from-uri (cadr entity-pair)) 56 key " {name: \"" (car entity-pair) 57 "\", uri: \"" (cadr entity-pair) "\"})~%")))))) 58 59 (defun generate-dbpedia-contains-cypher (key value) 60 (generate-original-doc-node) 61 (generate-dbpedia-nodes key value) 62 (let ((relation-name (concatenate 'string key "DbPediaLink"))) 63 (dolist (entity-pair value) 64 (let* ((node-name (node-name-from-uri meta)) 65 (object-node-name (node-name-from-uri (cadr entity-pair))) 66 (hash-check (concatenate 'string node-name object-node-name))) 67 (if (null (gethash hash-check *entity-nodes-hash*)) 68 (let () 69 (setf (gethash hash-check *entity-nodes-hash*) t) 70 (format str (concatenate 'string 71 "CREATE (" node-name ")-[:" 72 relation-name "]->(" object-node-name ")~%")))))))) 73 74 75 ;; start code for cypher-from-files (output-file-path text-and-meta-pairs) 76 (generateNeo4jCategoryNodes) ;; just once, not for every input file 77 (dolist (pair text-and-meta-pairs) 78 (cypher-from-files-handle-single-file (car pair) (cadr pair)) 79 (let ((h (entities_dbpedia:find-entities-in-text (file-to-string (car pair))))) Automatically Generating Data for Knowledge Graphs 198 80 (entities_dbpedia:entity-iterator #'generate-dbpedia-contains-cypher h)))))) 81 82 83 (defvar test_files '((#P"~/GITHUB/common-lisp/kgcreator/test_data/test3.txt" 84 #P"~/GITHUB/common-lisp/kgcreator/test_data/test3.meta") 85 (#P"~/GITHUB/common-lisp/kgcreator/test_data/test2.txt" 86 #P"~/GITHUB/common-lisp/kgcreator/test_data/test2.meta") 87 (#P"~/GITHUB/common-lisp/kgcreator/test_data/test1.txt" 88 #P"~/GITHUB/common-lisp/kgcreator/test_data/test1.meta"))) 89 90 (defun test2a () 91 (cypher-from-files "out.cypher" test_files)) You can load all of KGCreator but just execute the test function at the end of this file using: (ql:quickload "kgcreator") (in-package #:kgcreator) (kgcreator:test2a) Implementing the Top Level Application APIs The code in the file src/kgcreator/kgcreator.lisp uses both rdf.lisp and neo4j.lisp that we saw in the last two sections. The function get-files-and-meta looks at the contents of an input directory to generate a list of pairs, each pair containing the path to a text file and the meta file for the corresponding text file. We are using the opts package to parse command line arguments. This will be used when we build a single file standalone executable file for the entire KGCreator application, including the web application that we will see in a later section. 1 ;; KGCreator main program 2 3 (in-package #:kgcreator) 4 5 (ensure-directories-exist "temp/") 6 7 (defun get-files-and-meta (fpath) 8 (let ((data (directory (concatenate 'string fpath "/" "*.txt"))) 9 (meta (directory (concatenate 'string fpath "/" "*.meta")))) 10 (if (not (equal (length data) (length meta))) 11 (let () Automatically Generating Data for Knowledge Graphs 199 12 (princ "Error: must be matching *.meta files for each *.txt file") 13 (terpri) 14 '()) 15 (let ((ret '())) 16 (dotimes (i (length data)) 17 (setq ret (cons (list (nth i data) (nth i meta)) ret))) 18 ret)))) 19 20 (opts:define-opts 21 (:name :help 22 :description 23 "KGcreator command line example: ./KGcreator -i test_data -r out.rdf -c out.cyp\ 24 er" 25 :short #\h 26 :long "help") 27 (:name :rdf 28 :description "RDF output file name" 29 :short #\r 30 :long "rdf" 31 :arg-parser #'identity ;; <- takes an argument 32 :arg-parser #'identity) ;; <- takes an argument 33 (:name :cypher 34 :description "Cypher output file name" 35 :short #\c 36 :long "cypher" 37 :arg-parser #'identity) ;; <- takes an argument 38 (:name :inputdir 39 :description "Cypher output file name" 40 :short #\i 41 :long "inputdir" 42 :arg-parser #'identity)) ;; <- takes an argument 43 44 45 (defun kgcreator () ;; don't need: &aux args sb-ext:*posix-argv*) 46 (handler-case 47 (let* ((opts (opts:get-opts)) 48 (input-path 49 (if (find :inputdir opts) 50 (nth (1+ (position :inputdir opts)) opts))) 51 (rdf-output-path 52 (if (find :rdf opts) 53 (nth (1+ (position :rdf opts)) opts))) 54 (cypher-output-path Automatically Generating Data for Knowledge Graphs 200 55 (if (find :cypher opts) 56 (nth (1+ (position :cypher opts)) opts)))) 57 (format t "input-path: ~a rdf-output-path: ~a cypher-output-path:~a~%" 58 input-path rdf-output-path cypher-output-path) 59 (if (not input-path) 60 (format t "You must specify an input path.~%") 61 (locally 62 (declare #+sbcl(sb-ext:muffle-conditions sb-kernel:redefinition-warning)) 63 (handler-bind 64 (#+sbcl(sb-kernel:redefinition-warning #'muffle-warning)) 65 ;; stuff that emits redefinition-warning's 66 (let () 67 (if rdf-output-path 68 (rdf-from-files rdf-output-path (get-files-and-meta input-path))) 69 (if cypher-output-path 70 (cypher-from-files cypher-output-path (get-files-and-meta input-path)))))))) 71 (t (c) 72 (format t "We caught a runtime error: ~a~%" c) 73 (values 0 c))) 74 (format t "~%Shutting down KGcreator - done processing~%~%")) 75 76 (defun test1 () 77 (get-files-and-meta 78 "~/GITHUB/common-lisp/kgcreator/test_data")) 79 80 (defun print-hash-entry (key value) 81 (format t "The value associated with the key ~S is ~S~%" key value)) 82 83 (defun test2 () 84 (let ((h (entities_dbpedia:find-entities-in-text "Bill Clinton and George Bush wen\ 85 t to Mexico and England and watched Univision. They enjoyed Dakbayan sa Dabaw and sh\ 86 oped at Best Buy and listened to Al Stewart. They agree on República de Nicaragua a\ 87 nd support Sweden Democrats and Leicestershire Miners Association and both sent thei\ 88 r kids to Darul Uloom Deoband."))) 89 (entities_dbpedia:entity-iterator #'print-hash-entry h))) 90 91 (defun test7 () 92 (rdf-from-files "out.rdf" (get-files-and-meta "test_data"))) You can load all of KGCreator but just execute the three test functions at the end of this file using: Automatically Generating Data for Knowledge Graphs 201 (ql:quickload "kgcreator") (in-package #:kgcreator) (kgcreator:test1) (kgcreator:test2) (kgcreator:test7) Implementing The Web Interface When we build a standalone single file application for KGCreator, we include a simple web application interface that allows users to enter input text and see generated RDF and Neo4j Cypher data. The file src/kgcreator/web.lisp uses the libraries cl-who hunchentoot parenscript that we used earlier. The function write-files-run-code** (lines 8-43) takes raw text, and writes generated RDF and Neo4j Cypher data to local temporary files that are then read and formatted to HTML for display. The code in rdf.lisp and neo4j.lisp is file oriented, and I wrote web.lisp as an afterthought so it was easier writing temporary files than refactoring rdf.lisp and neo4j.lisp to write to strings. 1 (in-package #:kgcreator) 2 3 (ql:quickload '(cl-who hunchentoot parenscript)) 4 5 6 (setf (html-mode) :html5) 7 8 (defun write-files-run-code (a-uri raw-text) 9 (if (< (length raw-text) 10) 10 (list "not enough text" "not enough text") 11 ;; generate random file number 12 (let* ((filenum (+ 1000 (random 5000))) 13 (meta-name (concatenate 'string "temp/" (write-to-string filenum) ".meta")) 14 (text-name (concatenate 'string "temp/" (write-to-string filenum) ".txt")) 15 (rdf-name (concatenate 'string "temp/" (write-to-string filenum) ".rdf")) 16 (cypher-name (concatenate 'string "temp/" (write-to-string filenum) ".cypher")) 17 ret) 18 ;; write meta file 19 (with-open-file (str meta-name 20 :direction :output 21 :if-exists :supersede 22 :if-does-not-exist :create) 23 (format str a-uri)) 24 ;; write text file Automatically Generating Data for Knowledge Graphs 202 25 (with-open-file (str text-name 26 :direction :output 27 :if-exists :supersede 28 :if-does-not-exist :create) 29 (format str raw-text)) 30 ;; generate rdf and cypher files 31 (rdf-from-files rdf-name (list (list text-name meta-name))) 32 (cypher-from-files cypher-name (list (list text-name meta-name))) 33 ;; read files and return results 34 (setf ret 35 (list 36 (replace-all 37 (replace-all 38 (uiop:read-file-string rdf-name) 39 ">" ">") 40 "<" "<") 41 (uiop:read-file-string cypher-name))) 42 (print (list "ret:" ret)) 43 ret))) 44 45 (defvar *h* (make-instance 'easy-acceptor :port 3000)) 46 47 ;; define a handler with the arbitrary name my-greetings: 48 49 (define-easy-handler (my-greetings :uri "/") (text) 50 (setf (hunchentoot:content-type*) "text/html") 51 (let ((rdf-and-cypher (write-files-run-code "http://test.com/1" text))) 52 (print (list "*** rdf-and-cypher:" rdf-and-cypher)) 53 (with-html-output-to-string 54 (*standard-output* nil :prologue t) 55 (:html 56 (:head (:title "KGCreator Demo") 57 (:link :rel "stylesheet" :href "styles.css" :type "text/css")) 58 (:body 59 :style "margin: 90px" 60 (:h1 "Enter plain text for the demo to create RDF and Cypher") 61 (:p "For more information on the KGCreator product please visit the web site:" 62 (:a :href "https://markwatson.com/products/" "Mark Watson's commercial products"\ 63 )) 64 (:p "The KGCreator product is a command line tool that processes all text " 65 "web applications and files in a source directory and produces both RDF data " 66 "triples for semantic Cypher input data files for the Neo4j graph database. " 67 "For the purposes of this demo the URI for your input text is hardwired to " Automatically Generating Data for Knowledge Graphs 203 68 "<http://test.com/1> but the KGCreator product offers flexibility " 69 "for assigning URIs to data sources and further, " 70 "creates links for relationships between input sources.") 71 (:p :style "text-align: left" 72 "To try the demo paste plain text into the following form that contains " 73 "information on companies, news, politics, famous people, broadcasting " 74 "networks, political parties, countries and other locations, etc. ") 75 (:p "Do not include and special characters or character sets:") 76 (:form 77 :method :post 78 (:textarea 79 :rows "20" 80 :cols "90" 81 :name "text" 82 :value text) 83 (:br) 84 (:input :type :submit :value "Submit text to process")) 85 (:h3 "RDF:") 86 (:pre (str (car rdf-and-cypher))) 87 (:h3 "Cypher:") 88 (:pre (str (cadr rdf-and-cypher)))))))) 89 90 (defun kgcweb () 91 (hunchentoot:start *h*)) You can load all of KGCreator and start the web application using: (ql:quickload "kgcreator") (in-package #:kgcreator) (kgcweb) You can access the web app at http://localhost:3000⁸⁵. Creating a Standalone Application Using SBCL When I originally wrote KGCreator I intended to develop a commercial product so it was important to be able to create standalone single file executables. This is simple to do using SBCL: ⁸⁵http://localhost:3000 Automatically Generating Data for Knowledge Graphs 204 1 $ sbcl 2 (ql:quickload "kgcreator") 3 (in-package #:kgcreator) 4 (sb-ext:save-lisp-and-die "KGcreator" 5 :toplevel #'kgcreator :executable t) As an example, you could run the application on the command line using: 1 ./KGcreator -i test_data -r out.rdf -c out.cyper Augmenting RDF Triples in a Knowledge Graph Using DBPedia You can augment RDF-based Knowledge Graphs that you build with the KGcreator application by using the library in the directory kg-add-dbpedia-triples. As seen in the kg-add-dbpedia-triples.asd and package.lisp configuration files, we use two other libraries developed in this book: ;;;; kg-add-dbpedia-triples.asd (asdf:defsystem #:kg-add-dbpedia-triples :description "Add DBPedia triples from an input N-Triples RDF file" :author "markw@markwatson.com" :license "Apache 2" :depends-on (#:myutils #:sparql) :components ((:file "package") (:file "add-dbpedia-triples"))) ;;;; package.lisp (defpackage #:kg-add-dbpedia-triples (:use #:cl #:myutils #:sparql) (:export #:add-triples)) The library is implemented in the file kg-add-dbpedia-triples.lisp: Automatically Generating Data for Knowledge Graphs 205 1 (in-package #:kg-add-dbpedia-triples) 2 3 (defun augmented-triples (a-uri ostream) 4 (let ((results 5 (sparql:dbpedia 6 (format nil "construct { ~A ?p ?o } where { ~A ?p ?o } limit 5" a-uri a-ur\ 7 i)))) 8 (dolist (x results) 9 (dolist (sop x) 10 (let ((val (second sop))) 11 (if (and 12 (stringp val) 13 (> (length val) 9) 14 (or 15 (equal (subseq val 0 7) "http://") 16 (equal (subseq val 0 8) "https://"))) 17 (format ostream "<~A> " val) 18 (format ostream "~A " val)))) 19 (format ostream " .~%")))) 20 21 (defun add-triples (in-file-name out-file-name) 22 (let* ((nt-data (myutils:file-to-string in-file-name)) 23 (tokens (myutils:tokenize-string-keep-uri nt-data)) 24 (uris 25 (remove-duplicates 26 (mapcan #'(lambda (s) (if 27 (and 28 (stringp s) 29 (> (length s) 19) 30 (equal (subseq s 0 19) ""))) (defun find-relations (entity-uri-list &key (output-stream t)) (dolist (entity-uri1 entity-uri-list) (dolist (entity-uri2 entity-uri-list) (if (not (equal entity-uri1 entity-uri2)) (let ((possible-relations (mapcar #'cadar (sparql::dbpedia (format nil "select ?p where { ~A ?p ~A . filter(!regex(str(?p\ ), \"page\", \"i\"))} limit 50" entity-uri1 entity-uri2))))) Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs 209 (print "** possible-relations:") (print possible-relations) (dolist (pr possible-relations) (format output-stream "~A ~A ~a .~%" entity-uri1 (ensure-angle-brackets pr) entity-uri2))))))) (defun sample (entity-uri-list output-filepath) (with-open-file (ostream (pathname output-filepath) :direction :output :if-exists\ :supersede) (construct-from-dbpedia entity-uri-list :output-stream ostream) (find-relations entity-uri-list :output-stream ostream))) Let’s start by running the two helper functions interactively so you can see their output (output edited for brevity). The top level function kgsampler:sample for this example takes a list of entity URIs and an output file name, and uses the functions construct-from-dbpedia entity-uri-list and find-relations to write triples for the entities and then for the relationships discovered between entities. The following listing also calls the helper function kgsampler::find-relations to show you what its output looks like. $ sbcl * (ql:quickload "kgsampler") * (kgsampler::construct-from-dbpedia '("" \ "") :output-stream nil) "CONSTRUCT { ?p ?o } where { ?p ?o . FILTER (lang(?o) = 'en') }" "CONSTRUCT { ?o } where { ?o }" ... * (kgsampler::find-relations '("" "") :output-stream nil) ("dbpedia SPARQL:" "select ?p where { ?p . filter(!regex(str(?p), \"page\", \"i\"))} limit 50" "n") "** possible-relations:" ("http://dbpedia.org/ontology/knownFor") "http://dbpedia.org/ontology/knownFor" Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs 210 ("dbpedia SPARQL:" "select ?p where { ?p . filter(!regex(str(?p), \"page\", \"i\"))} limit 50" "n") "** possible-relations:" ("http://dbpedia.org/property/founders" "http://dbpedia.org/ontology/foundedBy") "http://dbpedia.org/property/founders" "http://dbpedia.org/ontology/foundedBy" nil We now use the main function to generate an output RDF triple file: 1 $ sbcl 2 * (ql:quickload "kgsampler") 3 * (kgsampler:sample '("" "" "") "test.nt") 5 "CONSTRUCT { ?p ?o } where { ?p ?o . FILTER (lang(?o) = 'en') }" 7 ("ndbpedia SPARQL:n" 8 "select ?p where { ?p . filter(!regex(str(?p), \"page\", \"i\"))} limit 50" 10 "n") 11 "** possible-relations:" 12 ("http://dbpedia.org/ontology/board") 13 ("dbpedia SPARQL:" 14 "select ?p where { ?p . filter(!regex(str(?p), \"page\", \"i\"))} limit 50" 16 "n") Output RDF N-Triple data is written to the file sample-KG.nt. A very small part of this file is listed here: 1 # ENTITY NAME: 2 3 "William Henry \"Bill\" Gates III (born October 28, 1955) is an American busines\ 5 s magnate,...."@en . 6 7 8 "Bill Gates"@en . 9 10 Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs 211 11 "Gates"@en . 12 13 14 "Co-Chairmanof theBill & Melinda Gates Foundation"@en . The same data in Turtle RDF format can be seen in the file sample-KG.ttl that was produced by importing the triples file into the free edition of GraphDB exporting it to the Turtle file sample- KG.ttl that I find easier to read. GraphDB has visualization tools which I use here to generate an interactive graph display of this data: GraphDB Visual graph of generated RDF triples This example is also set up for people and companies. I may expand it in the future to other types of entities as I need them. This example program takes several minutes to run since many SPARQL queries are made to DBPedia. I am a non-corporate member of the DBPedia organization. Here is a membership application⁸⁶ if you are interested in joining me there. ⁸⁶https://www.dbpedia.org/members/membership/ Knowledge Graph Navigator Common Library Implementation The Knowledge Graph Navigator (which I will often refer to as KGN) is a tool for processing a set of entity names and automatically exploring the public Knowledge Graph DBPedia⁸⁷ using SPARQL queries. I started to write KGN for my own use, to automate some things I used to do manually when exploring Knowledge Graphs, and later thought that KGN might be also useful for educational purposes. KGN shows the user the auto-generated SPARQL queries so hopefully the user will learn by seeing examples. KGN uses NLP code developed in earlier chapters and we will reuse that code with a short review of using the APIs. In previous versions of this book, this example was hard-wired to use LispWork CAPI for the user interface. This old version is in src/kgn in the main GitHub repository for this book: https://github.com/mark-watson/loving-common-lisp⁸⁸ and has a few UI components like a progress bar that I removed since the previous edition. The new version has separate GitHub repositories for: • https://github.com/mark-watson/kgn-common⁸⁹ for the Knowledge Graph Navigator common library. • https://github.com/mark-watson/kgn-text-ui⁹⁰ for a text interface for the Knowledge Graph Navigator. • https://github.com/mark-watson/kgn-capi-ui⁹¹ for a LispWorks CAPI GUI interface for the Knowledge Graph Navigator. If you followed the code example setup instructions in the book Preface or in the README file in the main repo https://github.com/mark-watson/loving-common-lisp⁹² then all three of these projects are available for loading via Quicklisp on your computer. After looking at SPARQL generated by this example for an example query, we will start a process of bottom up development, first writing low level functions to automate SPARQL queries, writing utilities we will need for the UIs developed in later chapters. Since the DBPedia SPARQL queries are time consuming, we will also implement a caching layer using SQLite that will make the app more responsive. The cache is especially helpful during development when the same queries are repeatedly used for testing. ⁸⁷http://dbpedia.org ⁸⁸https://github.com/mark-watson/loving-common-lisp ⁸⁹https://github.com/mark-watson/kgn-common ⁹⁰https://github.com/mark-watson/kgn-text-ui ⁹¹https://github.com/mark-watson/kgn-capi-ui ⁹²https://github.com/mark-watson/loving-common-lisp Knowledge Graph Navigator Common Library Implementation 213 The code for this reusable library is in the directory src/kgn-common. This is common library that will be used for user interfaces developed in later chapters. There is a lot of code in the following program listings and I hope to provide you with a roadmap overview of the code, diving in on code that you might want to reuse for your own projects and some representative code for generating SPARQL queries. Let’s start by looking at the files for the common library: • Makefile - contains development shortcuts. • data - data used to remove stop words from text. • kgn-common.lisp - main code file for library. • package.lisp - standard Common Lisp package definition. • utils.lisp - miscelanious utility functions. • README.txt • kgn-common.asd - standard Common Lisp ASDF definition. Example Output Before we get started studying the implementation, let’s look at sample output in order to help give meaning to the code we will look at later. Consider a query that a user might type into the top query field in the KGN app: 1 Steve Jobs lived near San Francisco and was 2 a founder of The system will try to recognize entities in a query. If you know the DBPedia URI of an entity, like the company Apple in this example, you can use that directly. Note that in the SPARQL URIs are surrounded with angle bracket characters. The application prints out automatically generated SPARQL queries. For the above listed example query the following output will be generated (some editing to fit page width): Trying to get entity by name = Steve Jobs using SPARQL with type: select distinct ?s ?comment { ?s ?p "Steve Jobs"@en . ?s ?comment . FILTER ( lang ( ?comment ) = 'en' ) . ?s . } LIMIT 15 Knowledge Graph Navigator Common Library Implementation 214 Trying to get entity by name = San Francisco using SPARQL with type: select distinct ?s ?comment { ?s ?p "San Francisco"@en . ?s ?comment . FILTER ( lang ( ?comment ) = 'en' ) . ?s . } LIMIT 15 SPARQL to get PERSON data for : SELECT DISTINCT ?label ?comment ( GROUP_CONCAT ( DISTINCT ?birthplace ; SEPARATOR=' | ' ) AS ?birthplace ) ( GROUP_CONCAT ( DISTINCT ?almamater ; SEPARATOR=' | ' ) AS ?almamater ) ( GROUP_CONCAT ( DISTINCT ?spouse ; SEPARATOR=' | ' ) AS ?spouse ) { ?comment . FILTER ( lang ( ?comment ) = 'en' ) . OPTIONAL { ?birthplace } . OPTIONAL { ?almamater } . OPTIONAL { ?spouse } . OPTIONAL { ?label . FILTER ( lang ( ?label ) = 'en' ) } } LIMIT 10 Remember, the SPARQL is generated by KGN from natural language queries. Some more examples: SPARQL to get CITY data for : Knowledge Graph Navigator Common Library Implementation 215 SELECT DISTINCT ?label ?comment ( GROUP_CONCAT ( DISTINCT ?latitude_longitude ; SEPARATOR=' | ' ) AS ?latitude_longitude ) ( GROUP_CONCAT ( DISTINCT ?populationDensity ; SEPARATOR=' | ' ) AS ?populationDensity ) ( GROUP_CONCAT ( DISTINCT ?country ; SEPARATOR=' | ' ) AS ?country ) { ?comment . FILTER ( lang ( ?comment ) = 'en' ) . OPTIONAL { ?latitude_longitude } . OPTIONAL { ?populationDensity } . OPTIONAL { ?country } . OPTIONAL { ?label . } } LIMIT 30 SPARQL to get COMPANY data for : SELECT DISTINCT ?label ?comment ( GROUP_CONCAT ( DISTINCT ?industry ; SEPARATOR=' | \ ' ) AS ?industry ) ( GROUP_CONCAT ( DISTINCT ?netIncome ; SEPARATOR=' | ' ) AS ?netIncome ) ( GROUP_CONCAT ( DISTINCT ?numberOfEmployees ; SEPARATOR=' | ' ) AS ?numberOfEmployees ) { ?comment . FILTER ( lang ( ?comment ) = 'en' ) . OPTIONAL { ?industry } . OPTIONAL { Knowledge Graph Navigator Common Library Implementation 216 ?netIncome } . OPTIONAL { ?numberOfEmployees } . OPTIONAL { ?label . FILTER ( lang ( ?label ) = 'en' ) } } LIMIT 30 Once KGN has identified DBPedia entire URIs, it also searches for relationships between these entities: DISCOVERED RELATIONSHIP LINKS: -> -> -> -> -> -> -> -> -> -> After listing the generated SPARQL for finding information for the entities in the query, KGN searches for relationships between these entities. These discovered relationships can be seen at the end of the last listing. Please note that this step makes SPARQL queries on O(n^2) where n is the number of entities. Local caching of SPARQL queries to DBPedia helps make processing many entities possible. In addition to showing generated SPARQL and discovered relationships in the middle text pane of the application, KGN also generates formatted results that are also displayed in the bottom text pane: Knowledge Graph Navigator Common Library Implementation 217 - - - ENTITY TYPE: PEOPLE - - - LABEL: Steve Jobs COMMENT: Steven Paul "Steve" Jobs was an American information technology entrepreneur and inventor. He was the co-founder, chairman, and chief executive officer (CEO) of Apple Inc.; CEO and majority shareholder of Pixar Animation Studios; a member of The Walt Disney Company's board of directors following its acquisition of Pixar; and founder, chairman, and CEO of NeXT Inc. Jobs is widely recognized as a pioneer of the microcomputer revolution of the 1970s and 1980s, along with Apple co-founder Steve Wozniak. Shortly after his death, Jobs's official biographer, Walter Isaacson, described him as a "creative entrepreneur whose passion for perfection and ferocious drive revolutionized six industries: personal computers, animated movies, music, phones BIRTHPLACE: http://dbpedia.org/resource/San_Francisco ALMAMATER: http://dbpedia.org/resource/Reed_College SPOUSE: http://dbpedia.org/resource/Laurene_Powell_Jobs - - - ENTITY TYPE: CITIES - - - LABEL: San Francisco COMMENT: San Francisco, officially the City and County of San Francisco, is the cultural, commercial, and financial center of Northern California and the only consolidated city-county in California. San Francisco encompasses a land area of about 46.9 square miles (121 km2) on the northern end of the San Francisco Peninsula, which makes it the smallest county in the state. It has a density of about 18,451 people per square mile (7,124 people per km2), making it the most densely settled large city (population greater than 200,000) in the state of California and the second-most densely populated major city in the United States after New York City. San Francisco is the fourth-most populous city in California, after Los Angeles, San Diego, and San Jose, and the 13th-most populous cit LATITUDE--LONGITUDE: POINT(-122.41666412354 37.783332824707) POPULATION-DENSITY: 7123.97092726667 COUNTRY: http://dbpedia.org/resource/United_States Knowledge Graph Navigator Common Library Implementation 218 - - - ENTITY TYPE: COMPANIES - - - LABEL: Apple Inc. COMMENT: Apple Inc. is an American multinational technology company headquartered in Cupertino, California, that designs, develops, and sells consumer electronics, computer software, and online services. Its hardware products include the iPhone smartphone, the iPad tablet computer, the Mac personal computer, the iPod portable media player, the Apple Watch smartwatch, and the Apple TV digital media player. Apple's consumer software includes the macOS and iOS operating systems, the iTunes media player, the Safari web browser, and the iLife and iWork creativity and productivity suites. Its online services include the iTunes Store, the iOS App Store and Mac App Store, Apple Music, and iCloud. INDUSTRY: http://dbpedia.org/resource/Computer_hardware | http://dbpedia.org/resource/Computer_software | http://dbpedia.org/resource/Consumer_electronics | http://dbpedia.org/resource/Corporate_Venture_Capital | http://dbpedia.org/resource/Digital_distribution | http://dbpedia.org/resource/Fabless_manufacturing NET-INCOME: 5.3394E10 NUMBER-OF-EMPLOYEES: 115000 Hopefully after reading through sample output and seeing the screen shot of the application, you now have a better idea what this example application does. Now we will look at project configuration and then implementation. Project Configuration and Running the Application The following listing of kgn.asd shows the ten packages this example depends on (five of these are also examples in this book, and five are in the public Quicklisp repository): Knowledge Graph Navigator Common Library Implementation 219 1 ;;;; knowledgegraphnavigator.asd 2 3 ((asdf:defsystem #:kgn-common 4 :description "common utilities for Knowledge Graph Navigator" 5 :author "Mark Watson " 6 :license "Apache 2" 7 :depends-on (#:sqlite #:cl-json #:alexandria #:drakma #:myutils #:entities #:entit\ 8 y-uris #:kbnlp #:sparql-cache) 9 :components ((:file "package") 10 (:file "utils") 11 (:file "kgn-common"))) Listing of package.lisp: 1 ;;;; package.lisp 2 3 (defpackage #:kgn-common 4 (:use #:cl #:alexandria #:myutils #:myutils #:sparql-cache 5 #:entities #:entity-uris #:kbnlp) 6 (:export #:kgn-common #:remove-stop-words 7 #:entity-results->relationship-links 8 #:get-entity-data-helper #:handle-URIs-in-query 9 #:remove-uris-from-query #:get-URIs-in-query #:display-entity-results 10 #:string-shorten #:prompt-string #:dbpedia-get-product-detail 11 #:dbpedia-get-person-detail #:dbpedia-get-country-detail 12 #:dbpedia-get-city-detail #:dbpedia-get-company-detail #:clean-results 13 #:dbpedia-get-entities-by-name #:clean-comment)) We use ql:quickload to load the KGN common library and call a few APIs (some output removed for brevity): 1 $ sbcl 2 This is SBCL 2.1.10, an implementation of ANSI Common Lisp. 3 * (ql :kgn-common) 4 To load "kgn-common": 5 Load 1 ASDF system: 6 kgn-common 7 ; Loading "kgn-common" 8 .................. 9 "Starting to load data...." 10 "....done loading data." 11 To load "sqlite": Knowledge Graph Navigator Common Library Implementation 220 12 Load 1 ASDF system: 13 sqlite 14 ; Loading "sqlite" 15 16 To load "cl-json": 17 Load 1 ASDF system: 18 cl-json 19 ; Loading "cl-json" 20 21 To load "drakma": 22 Load 1 ASDF system: 23 drakma 24 ; Loading "drakma" 25 [package kgn-common].. 26 (:kgn-common) 27 * 28 * (kgn-common::dbpedia-get-relationships ""\ 29 "") 30 ("") 31 * 32 * (kgn-common:dbpedia-get-entities-by-name "Bill Gates" "" "" :message-stream nil) 34 35 (((:s "http://dbpedia.org/resource/Bill_Gates") 36 (:comment 37 "William Henry Gates III (born October 28, 1955) is an American business magnate,\ 38 software developer, investor, author, and philanthropist. He is a co-founder of Mic\ 39 rosoft, along with his late childhood friend Paul Allen. During his career at Micros\ 40 oft, Gates held the positions of chairman, chief executive officer (CEO), president \ 41 and chief software architect, while also being the largest individual shareholder un\ 42 til May 2014. He is considered one of the best known entrepreneurs of the microcompu\ 43 ter revolution of the 1970s and 1980s.")) 44 ((:s "http://dbpedia.org/resource/Harry_R._Lewis") 45 (:comment 46 "Harry Roy Lewis (born 1947) is an American computer scientist, mathe 00ADma 00AD\ 47 ti 00ADcian, and uni 00ADver 00ADsity admin 00ADi 00ADstra 00ADtor known for his res\ 48 earch in com 00ADpu 00ADta 00ADtional logic, textbooks in theoretical computer scien\ 49 ce, and writings on computing, higher education, and technology. He is Gordon McKay \ 50 Professor of Computer Science at Harvard University, and was Dean of Harvard College\ 51 from 1995 to 2003. A new professorship in Engineering and Applied Sciences, endowed\ 52 by a former student, will be named for Lewis and his wife upon their retirements.")\ 53 ) 54 ((:s "http://dbpedia.org/resource/Cascade_Investment") Knowledge Graph Navigator Common Library Implementation 221 55 (:comment 56 "Cascade Investment, L.L.C. is an American holding company and private investment\ 57 firm headquartered in Kirkland, Washington, United States. It is controlled by Bill\ 58 Gates, and managed by Michael Larson. More than half of Gates' fortune is held in a\ 59 ssets outside his holding of Microsoft shares. Cascade is the successor company to D\ 60 ominion Income Management, the former investment vehicle for Gates' holdings, which \ 61 was managed by convicted felon Andrew Evans.")) 62 ((:s "http://dbpedia.org/resource/Jerry_Dyer") 63 (:comment 64 "Jerry P. Dyer (born May 3, 1959) is an American politician and former law enforc\ 65 ement officer. He is the 26th and current mayor of Fresno, California. Previously, h\ 66 e served as the chief of the Fresno Police Department."))) 67 68 select distinct ?s ?comment { ?s ?p "Bill Gates"@en . @@ ?s ?comment . FILTER (lang(?comment) = 'en') . @@ ?s . @@ \ 71 } LIMIT 15 72 (((:s "http://dbpedia.org/resource/Bill_Gates") 73 (:comment 74 "William Henry Gates III (born October 28, 1955) is an American business magnate,\ 75 software developer, investor, author, and philanthropist. He is a co-founder of Mic\ 76 rosoft, along with his late childhood friend Paul Allen. During his career at Micros\ 77 oft, Gates held the positions of chairman, chief executive officer (CEO), president \ 78 and chief software architect, while also being the largest individual shareholder un\ 79 til May 2014. He is considered one of the best known entrepreneurs of the microcompu\ 80 ter revolution of the 1970s and 1980s.")) 81 ((:s "http://dbpedia.org/resource/Harry_R._Lewis") 82 (:comment 83 "Harry Roy Lewis (born 1947) is an American computer scientist, mathe 00ADma 00AD\ 84 ti 00ADcian, and uni 00ADver 00ADsity admin 00ADi 00ADstra 00ADtor known for his res\ 85 earch in com 00ADpu 00ADta 00ADtional logic, textbooks in theoretical computer scien\ 86 ce, and writings on computing, higher education, and technology. He is Gordon McKay \ 87 Professor of Computer Science at Harvard University, and was Dean of Harvard College\ 88 from 1995 to 2003. A new professorship in Engineering and Applied Sciences, endowed\ 89 by a former student, will be named for Lewis and his wife upon their retirements.")\ 90 ) 91 ((:s "http://dbpedia.org/resource/Cascade_Investment") 92 (:comment 93 "Cascade Investment, L.L.C. is an American holding company and private investment\ 94 firm headquartered in Kirkland, Washington, United States. It is controlled by Bill\ 95 Gates, and managed by Michael Larson. More than half of Gates' fortune is held in a\ 96 ssets outside his holding of Microsoft shares. Cascade is the successor company to D\ 97 ominion Income Management, the former investment vehicle for Gates' holdings, which \ Knowledge Graph Navigator Common Library Implementation 222 98 was managed by convicted felon Andrew Evans.")) 99 ((:s "http://dbpedia.org/resource/Jerry_Dyer") 100 (:comment 101 "Jerry P. Dyer (born May 3, 1959) is an American politician and former law enforc\ 102 ement officer. He is the 26th and current mayor of Fresno, California. Previously, h\ 103 e served as the chief of the Fresno Police Department."))) 104 * In this last example, using :message-stream nil effectively turns off printing generated SPARQL queries used by these APIs. You can use :message-stream t to see generated SPARQL. Every time the KGN common library makes a web service call to DBPedia the query and response are cached in a SQLite database in ∼/.kgn_cache.db which can greatly speed up the program, especially in development mode when testing a set of queries. This caching also takes some load off of the public DBPedia endpoint, which is a polite thing to do. Review of NLP Utilities Used in Application Here is a quick review of NLP utilities we saw in an earlier chapter: • kbnlp:make-text-object • kbnlp::text-human-names • kbnlp::text-place-name • entity-uris:find-entities-in-text • entity-uris:pp-entities The following code snippets show example calls to the relevant NLP functions and the generated output: KGN 39 > (setf text "Bill Clinton went to Canada") "Bill Clinton went to Canada" KGN 40 > (setf txtobj (kbnlp:make-text-object text)) #S(TEXT :URL "" :TITLE "" :SUMMARY "" :CATEGORY-TAGS (("computers_micros\ oft.txt" 0.00641) ("religion_islam.txt" 0.00357)) :KEY-WORDS NIL :KEY-PHRASES NIL :H\ UMAN-NAMES ("Bill Clinton") :PLACE-NAMES ("Canada") :COMPANY-NAMES NIL :TEXT #("Bill\ " "Clinton" "went" "to" "Canada") :TAGS #("NNP" "NNP" "VBD" "TO" "NNP")) KGN 41 > (kbnlp::text-human-names txtobj) ("Bill Clinton") KGN 42 > Knowledge Graph Navigator Common Library Implementation 223 (loop for key being the hash-keys of (entity-uris:find-entities-in-text text) using (hash-value value) do (format t "key: ~S value: ~S~%" key value)) key: "people" value: (("Bill Clinton" "")) key: "countries" value: (("Canada" "")) NIL The code using loop at the end of the last repl listing that prints keys and values of a hash table is from the Common Lisp Cookbook web site⁹³ in the section “Traversing a Hash Table.” Developing Low-Level SPARQL Utilities I use the standard command line curl utility program with the Common Lisp package uiop to make HTML GET requests to the DBPedia public Knowledge Graph and the package drakma to url-encode parts of a query. The source code is in a separate Quicklisp library located in src/sparql- cache/sparql.lisp. A non-caching library is also available in src/sparql/sparql.lisp. In the following listing of src/sparql-cache/sparql.lisp, lines 8, 24, 39, and 55 I use some caching code that we will look at later. The nested replace-all statements in lines 12-13 are a kluge to remove Unicode characters that occasionally caused runtime errors in the KGN application. 1 (in-package #:kgn) 2 3 (ql:quickload "cl-json") 4 (ql:quickload "drakma") 5 6 (defun sparql-dbpedia (query) 7 (let* (ret 8 (cr (fetch-result-dbpedia query)) 9 (response 10 (or 11 cr 12 (replace-all 13 (replace-all 14 (uiop:run-program 15 (list 16 "curl" 17 (concatenate 'string 18 "https://dbpedia.org/sparql?query=" 19 (drakma:url-encode query :utf-8) 20 "&format=json")) ⁹³http://cl-cookbook.sourceforge.net/hashes.html Knowledge Graph Navigator Common Library Implementation 224 21 :output :string) 22 "\\u2013" " ") 23 "\\u" " ")))) 24 (save-query-result-dbpedia query response) 25 (ignore-errors 26 (with-input-from-string 27 (s response) 28 (let ((json-as-list (json:decode-json s))) 29 (setf 30 ret 31 (mapcar #'(lambda (x) 32 ;;(pprint x) 33 (mapcar #'(lambda (y) 34 (list (car y) (cdr (assoc :value (cdr y))))) x)) 35 (cdr (cadddr (cadr json-as-list)))))))) 36 ret)) 37 38 (defun sparql-ask-dbpedia (query) 39 (let* ((cr (fetch-result-dbpedia query)) 40 (response 41 (or 42 cr 43 (replace-all 44 (replace-all 45 (uiop:run-program 46 (list 47 "curl" 48 (concatenate 'string 49 "https://dbpedia.org/sparql?query=" 50 (drakma:url-encode query :utf-8) 51 "&format=json")) 52 :output :string) 53 "\\u2013" " ") 54 "\\u" " ")))) 55 (save-query-result-dbpedia query response) 56 (if (search "true" response) 57 t 58 nil))) The code for replacing Unicode characters is messy but prevents problems later when we are using the query results in the example application. The code (json-as-list (json:decode-json s)) on line 28 converts a deeply nested JSON response to nested Common Lisp lists. You may want to print out the list to better understand the mapcar Knowledge Graph Navigator Common Library Implementation 225 expression on lines 31-35. There is no magic to writing expressions like this, in a repl I set json-as- list to the results of one query, and I spent a minute or two experimenting with the nested mapcar expression to get it to work with my test case. The implementation for sparql-ask-dbpedia in lines 38-58 is simpler because we don’t have to fully parse the returned SPARQL query results. A SPARQL ask type query returns a true/false answer to a query. We will use this to determine the types of entities in query text. While our NLP library identifies entity types, making additional ask queries to DBPedia to verify entity types will provide better automated results. Implementing the Caching Layer While developing KGN and also using it as an end user, many SPARQL queries to DBPedia contain repeated entity names so it makes sense to write a caching layer. We use a SQLite database “∼/.kgn_- cache.db” to store queries and responses. The caching layer is implemented in the file src/sparql-cache/sparql.lisp and some of the relevant code is listed here: 1 ;;; SqList caching for SPARQL queries: 2 3 (defvar *db-path* (pathname "~/.kgn_cache.db")) 4 5 (defun create-dbpedia () 6 (sqlite:with-open-database (d *db-path*) 7 (ignore-errors 8 (sqlite:execute-single d 9 "CREATE TABLE dbpedia (query string PRIMARY KEY ASC, result string)")))) 10 11 (defun save-query-result-dbpedia (query result) 12 (sqlite:with-open-database (d *db-path*) 13 (ignore-errors 14 (sqlite:execute-to-list d 15 "insert into dbpedia (query, result) values (?, ?)" 16 query result)))) 17 (defun fetch-result-dbpedia (query) 18 (sqlite:with-open-database (d *db-path*) 19 (cadar 20 (sqlite:execute-to-list d 21 "select * from dbpedia where query = ?" query)))) This caching layer greatly speeds up my own personal use of KGN. Without caching, queries that contain many entity references simply take too long to run. The UI for the KGN applications in Knowledge Graph Navigator Common Library Implementation 226 later chapters have a menu option for clearing the local cache but I almost never use this option because growing a large cache that is tailored for the types of information I search for makes the entire system much more responsive. Utilities in the Main Library File kgn-common.lisp The utilities in the file src/kgn-common/kgn-common.lisp can be seen in this complete code listing: 1 (in-package #:kgn-common) 2 3 (defun pprint-results (results &key (stream t)) 4 (pprint results stream)) 5 6 (defun colorize-sparql-local (s &key (stream nil)) 7 "placeholder - some applications, like the kgn-capi-ui example need to 8 colorize the sparql output" 9 (princ s stream)) 10 11 (defun check-uri (uri) 12 "sloppy code fix: URIs have different forms - normalize these" 13 (if (equal (type-of uri) 'cons) (setf uri (second uri))) 14 (entity-uris:ensure-uri-brackets uri)) 15 16 (defun clean-comment (comment-string) 17 "When getting comment strings from DBPedia, there are parts 18 that I remove for display" 19 (let ((i1 (search "(" comment-string)) 20 (i2 (search ")" comment-string))) 21 (if (and i1 i2 (> i2 i1) (> i1 0)) 22 (concatenate 'string (subseq comment-string 0 (- i1 1)) 23 (subseq comment-string (+ i2 1))) 24 (let ((j1 (search " / " comment-string))) 25 (if j1 26 (let ((j2 (search "/" comment-string :start2 (+ j1 2)))) 27 (if (and j1 j2 (> j2 j1) (< (+ j2 1) (length comment-string))) 28 (concatenate 'string (subseq comment-string 0 j1) 29 (subseq comment-string (+ j2 1))) 30 comment-string)) 31 comment-string) 32 comment-string)))) 33 34 (defun clean-results (results) Knowledge Graph Navigator Common Library Implementation 227 35 "This function is replaced when we later build GUI apps" 36 results) 37 38 (defun get-name-and-description-for-uri (uri) 39 (let* ((sparql 40 (replace-all 41 (format nil 42 "select distinct ?name ?comment { @@ ~ 43 values ?nameProperty { 44 } . @@ ~ 45 ~A ?nameProperty ?name . @@ ~ 46 ~A ?comment . 47 FILTER (lang(?comment) = 'en') . @@ ~ 48 } LIMIT 1" uri uri) 49 "@@" " ")) 50 (results (sparql-cache:dbpedia sparql))) 51 (list (second (assoc :name (car results))) 52 (second (assoc :comment (car results)))))) 53 54 ;; (kgn-common::get-name-and-description-for-uri 55 ;; "") 56 57 (defun ask-is-type-of (entity-uri type-value-uri) ;; both URIs expected to use surro\ 58 unding < > brackets for SPARQL 59 (let* ((sparql 60 (format nil 61 "ASK { ~A ~A }" 62 (check-uri entity-uri) (check-uri type-value-uri))) 63 (results (sparql-cache:ask-dbpedia sparql))) 64 (print sparql) 65 results)) 66 67 ;; (kgn-common::ask-is-type-of 68 ;; "" 69 ;; "") 70 71 72 (defun dbpedia-get-entities-by-name (name dbpedia-type schema-org-type 73 &key (message-stream t) 74 (colorize-sparql-function #'colorize-sparql-local)) 75 ;; http://www.w3.org/1999/02/22-rdf-syntax-ns#type 76 (let* ((sparql 77 (format nil Knowledge Graph Navigator Common Library Implementation 228 78 "select distinct ?s ?comment { 79 ?s ?p \"~A\"@en . @@ ~ 80 ?s ?comment . FILTER (lang(?com\ 81 ment) = 'en') . @@ ~ 82 ?s ~A . @@ ~ 83 } LIMIT 15" name dbpedia-type)) 84 (results (sparql-cache:dbpedia (replace-all sparql "@@" " ")))) 85 (print results) 86 (terpri message-stream) 87 (format message-stream 88 "Trying to get entity by name = ~A using SPARQL with type:" 89 name dbpedia-type) 90 (terpri message-stream) 91 (apply colorize-sparql-function (list sparql :stream message-stream)) 92 (if (null results) 93 (let* ((sparql2 94 (format nil 95 "select distinct ?s ?comment { 96 ?s ?p \"~A\"@en . @@ ~ 97 ?s ?comment . FILTER (lang(?co\ 98 mment) = 'en') . @@ ~ 99 ?s ~A . @@ ~ 100 } LIMIT 15" name schema-org-type))) 101 (format 102 t 103 "No results for ~A for last SPARQL query using type ~A so trying type ~A"\ 104 name dbpedia-type schema-org-type) 105 (terpri message-stream) 106 (setf results (sparql-cache:dbpedia (replace-all sparql2 "@@" " "))) 107 (if (null results) 108 (format 109 t 110 "No results for ~A for last SPARQL query using type ~A" 111 name schema-org-type) 112 (let* ((filtered (remove-if 113 #'(lambda (x) 114 (or 115 (search "," (cadar x)) 116 (and 117 (not (equal (first x) :comment)) 118 (not (search "/resource/" (cadar x)))))) 119 results)) 120 (uris (remove-duplicates Knowledge Graph Navigator Common Library Implementation 229 121 (map 122 'list 123 #'(lambda (x) 124 (list (concatenate 'string "<" (cadar x) ">") (cadad\ 125 r x))) 126 filtered) :test #'equal))) 127 (format t "~%~%********** dbpedia-get-entities-by-name: uris:~%") 128 (pprint uris) (terpri) 129 uris)))) 130 results)) 131 132 ;; (kgn-common:dbpedia-get-entities-by-name 133 ;; "Bill Gates" "" 134 ;; "" :message-stream nil) 135 ;; in above, pass t for message-stream to see generated SPARQL queries 136 137 (defun dbpedia-get-person-detail (person-uri-raw 138 &key (message-stream t) 139 (colorize-sparql-function #'colorize-sparql-local)) 140 ;; http://dbpedia.org/ontology/birthPlace 141 (let* ((person-uri (check-uri person-uri-raw)) 142 (query 143 (format nil 144 "SELECT DISTINCT ?label ?comment@@ ~ 145 (GROUP_CONCAT (DISTINCT ?birthplace; SEPARATOR=' | ') AS ?birthplace) @@ ~ 146 (GROUP_CONCAT (DISTINCT ?almamater; SEPARATOR=' | ') AS ?almamater) @@ ~ 147 (GROUP_CONCAT (DISTINCT ?spouse; SEPARATOR=' | ') AS ?spouse) { @@ ~ 148 ~A ?comment .@@ 149 FILTER (lang(?comment) = 'en') . @@ ~ 150 OPTIONAL { ~A ?birthplace } . @@ ~ 151 OPTIONAL { ~A ?almamater } . @@ ~ 152 OPTIONAL { ~A ?spouse } . @@ ~ 153 OPTIONAL { ~A ?label .@@ ~ 154 FILTER (lang(?label) = 'en') } @@ ~ 155 } LIMIT 10@@" person-uri person-uri person-uri person-uri person-uri)) 156 (results (sparql-cache:dbpedia (replace-all query "@@" " ")))) 157 (format message-stream "~%SPARQL to get PERSON data for ~A:~%~%" person-uri) 158 (apply colorize-sparql-function (list query :stream message-stream)) 159 (format message-stream "~%") 160 ;;results)) 161 (clean-results results))) 162 163 ;; (kgn-common:dbpedia-get-person-detail "") Knowledge Graph Navigator Common Library Implementation 230 164 165 (defun dbpedia-get-company-detail (company-uri-raw 166 &key (message-stream t) 167 (colorize-sparql-function #'colorize-sparql-local)) 168 (let* ((company-uri (check-uri company-uri-raw)) 169 (query 170 (format nil 171 "SELECT DISTINCT ?label ?comment (GROUP_CONCAT (DISTINCT ?industry; SEPARATOR=' | ')\ 172 AS ?industry)@@ ~ 173 (GROUP_CONCAT (DISTINCT ?netIncome; SEPARATOR=' | ') AS ?netIncome)@@ ~ 174 (GROUP_CONCAT (DISTINCT ?numberOfEmployees; SEPARATOR=' | ') AS ?numberOfEmployees\ 175 ) {@@ ~ 176 ~A ?comment .@@ 177 FILTER (lang(?comment) = 'en') .@@ ~ 178 OPTIONAL { ~A ?industry } .@@ ~ 179 OPTIONAL { ~A ?netIncome } .@@ ~ 180 OPTIONAL { ~A ?numberOfEmployees }\ 181 .@@ ~ 182 OPTIONAL { ~A ?label . FILTER (lang(?\ 183 label) = 'en') } @@ ~ 184 } LIMIT 30@@" 185 company-uri company-uri company-uri company-uri company-uri)) 186 (results (sparql-cache:dbpedia (replace-all query "@@" " ")))) 187 (format message-stream "~%SPARQL to get COMPANY data for ~A:~%~%" company-uri) 188 (apply colorize-sparql-function (list query :stream message-stream)) 189 (format message-stream "~%") 190 (clean-results results))) 191 192 ;; (kgn-common:dbpedia-get-company-detail "") 193 194 (defun dbpedia-get-country-detail (country-uri-raw 195 &key (message-stream t) 196 (colorize-sparql-function #'colorize-sparql-local)) 197 (let* ((country-uri (check-uri country-uri-raw)) 198 (query 199 (format nil 200 "SELECT DISTINCT ?label ?comment (GROUP_CONCAT (DISTINCT ?areaTotal; SEPARATOR=' | '\ 201 ) AS ?areaTotal)@@ ~ 202 (GROUP_CONCAT (DISTINCT ?populationDensity; SEPARATOR=' | ') AS ?populationDensity\ 203 ) {@@ ~ 204 ~A ?comment .@@ 205 FILTER (lang(?comment) = 'en') .@@ ~ 206 OPTIONAL { ~A ?areaTotal } .@@ ~ Knowledge Graph Navigator Common Library Implementation 231 207 OPTIONAL { ~A ?populationDensity }\ 208 .@@ ~ 209 OPTIONAL { ~A ?label . }@@ ~ 210 } LIMIT 30@@" 211 country-uri country-uri country-uri country-uri country-uri)) 212 (results (sparql-cache:dbpedia (replace-all query "@@" " ")))) 213 (format message-stream "~%SPARQL to get COUNTRY data for ~A:~%~%" country-uri) 214 (apply colorize-sparql-function (list query :stream message-stream)) 215 (format message-stream "~%") 216 (clean-results results))) 217 218 ;; (kgn-common:dbpedia-get-country-detail "") 219 220 (defun dbpedia-get-city-detail (city-uri-raw 221 &key (message-stream t) 222 (colorize-sparql-function #'colorize-sparql-local)) 223 (let* ((city-uri (check-uri city-uri-raw)) 224 (query 225 (format 226 nil 227 "SELECT DISTINCT ?label ?comment @@ ~ 228 (GROUP_CONCAT (DISTINCT ?latitude_longitude; SEPARATOR=' | ') AS ?latitude_longit\ 229 ude) @@ ~ 230 (GROUP_CONCAT (DISTINCT ?populationDensity; SEPARATOR=' | ') AS ?populationDensity\ 231 ) @@ ~ 232 (GROUP_CONCAT (DISTINCT ?country; SEPARATOR=' | ') AS ?country) { @@ ~ 233 ~A ?comment . FILTER (lang(?comme\ 234 nt) = 'en') . @@ ~ 235 OPTIONAL { ~A ?latitude_longitu\ 236 de } . @@ ~ 237 OPTIONAL { ~A ?popu\ 238 lationDensity } . @@ ~ 239 OPTIONAL { ~A ?country } .@@ ~ 240 OPTIONAL { ~A ?label . } @@ ~ 241 } LIMIT 30@@" 242 city-uri city-uri city-uri city-uri city-uri)) 243 (results (sparql-cache:dbpedia (replace-all query "@@" " ")))) 244 (format message-stream "~%SPARQL to get CITY data for ~A:~%~%" city-uri) 245 (apply colorize-sparql-function (list query :stream message-stream)) 246 (format message-stream "~%") 247 (clean-results results))) 248 249 ;; (kgn-common:dbpedia-get-city-detail "") Knowledge Graph Navigator Common Library Implementation 232 250 251 (defun dbpedia-get-product-detail (product-uri-raw 252 &key (message-stream t) 253 (colorize-sparql-function #'colorize-sparql-local)) 254 (let* ((product-uri (check-uri product-uri-raw)) 255 (query 256 (format 257 nil 258 "SELECT DISTINCT ?label ?comment { @@ ~ 259 ~A ?comment . FILTER (lang(?comme\ 260 nt) = 'en') . @@ ~ 261 OPTIONAL { ~A ?label . } ~ 262 } LIMIT 30@@" 263 product-uri product-uri)) 264 (results (sparql-cache:dbpedia (replace-all query "@@" " ")))) 265 (format message-stream "~%SPARQL to get PRODUCT data for ~A:~%~%" product-uri) 266 (apply colorize-sparql-function (list query :stream message-stream)) 267 (format message-stream "~%") 268 (clean-results results))) 269 270 ;; (kgn-common:dbpedia-get-product-detail "") 271 272 273 (defun dbpedia-get-relationships (s-uri o-uri) ;; &key (message-stream t)) 274 (let* ((query 275 (format 276 nil 277 "SELECT DISTINCT ?p { ~A ?p ~A . FILTER (!regex(str(?p), 'wikiPage', 'i'))} LIMIT 5" 278 (check-uri s-uri) (check-uri o-uri))) 279 (results (sparql-cache:dbpedia query))) 280 (alexandria:flatten (map 'list 281 #'(lambda (x) 282 (format nil "~{<~A>~}" (cdar x))) 283 results)))) 284 285 ;; (kgn-common::dbpedia-get-relationships 286 ;; "" 287 ;; "") 288 289 (defun entities (text) 290 (let ((txt-obj (kbnlp:make-text-object text))) 291 (list (kbnlp::text-human-names txt-obj) (kbnlp::text-place-names txt-obj) (kbnlp\ 292 ::text-company-names txt-obj)))) Knowledge Graph Navigator Common Library Implementation 233 293 294 ;; (kgn-common::entities "Bill Clinton went to Canada") 295 296 (defun entities-dbpedia (text) 297 (let ((e-hash (entity-uris:find-entities-in-text text))) 298 (list 299 (gethash "people" e-hash) 300 (gethash "companies" e-hash) 301 (gethash "countries" e-hash) 302 (gethash "cities" e-hash)))) 303 304 ;; (kgn-common::entities-dbpedia "Bill Clinton went to Canada") Wrap-up This is a long example application for a book, split between this chapter and the next two chapters offering different user interface implementations. I got the idea for the KGN application because I was spending quite a bit of time manually setting up SPARQL queries for DBPedia (and other public sources like WikiData) and I wanted to experiment with partially automating this process. Now in the next two chapters we will write user interfaces for this KGN common library. Knowledge Graph Navigator Text-Based User Interface We developed the The Knowledge Graph Navigator (which I will often refer to as KGN) common library in the last chapter. Here we write a simple console or text-based user interface for the library. In later chapters we implement UIs using LispWorks CAPI, McCLIM, and Franz Common Graphics. This Quicklisp library can be found in a separate GitHub repository https://github.com/mark- watson/kgn-text-ui⁹⁴ and contains the files: • kgn-text-ui.asd - specifies dependencies, including the KGN common library • kgn-text-ui.lisp - Contains the complete user interface • package.lisp - specifies dependencies, including the KGN common library We start by looking at sample output using the text user interface and then look at the implementa- tion. Example Output We will look at a very simple example query Bill Gates worked at Microsoft and his competitor was IBM that only contains a few entities. In practice, I usually use queries with five to ten entities to get more discovered relationships. I remove a lot of the generated output in the following listing for brevity, especially the many generated SPARQL queries that the code generates and uses (comments on the output appear after this listing): 1 $ sbcl 2 *(ql:quickload :kgn-text-ui) 3 ; Loading "kgn-common" 4 ; Loading "sqlite" 5 ; Loading "cl-json" 6 ; Loading "drakma" 7 8 * (kgn-text-ui:kgn-text-ui) 9 10 "Enter entity names (people, places, companies, etc.": 11 Bill Gates worked at Microsoft and his competitor was IBM ⁹⁴https://github.com/mark-watson/kgn-text-ui Knowledge Graph Navigator Text-Based User Interface 235 12 13 - - - - Enter zero or more indices for your desired selections: 14 15 0 - "William Henry Gates III (born October 28, 1955) is an American business magn\ 16 ate, software developer, investor, author, and philanthropist. He is a co-founder of\ 17 Microsoft, along with his late childhood friend Paul Allen. During his career at Mi\ 18 crosoft, Gates held the positions of chairman, chief executive officer (CEO), presid\ 19 ent and chief software architect, while also being the largest individual shareholde\ 20 r until May 2014. He is considered one of the best known entrepreneurs of the microc\ 21 omputer revolution of the 1970s and 1980s." 22 23 1 - "Harry Roy Lewis (born 1947) is an American computer scientist, mathe 00ADma \ 24 00ADti 00ADcian, and uni 00ADver 00ADsity admin 00ADi 00ADstra 00ADtor known for his\ 25 research in com 00ADpu 00ADta 00ADtional logic, textbooks in theoretical computer s\ 26 cience, and writings on computing, higher education, and technology. He is Gordon Mc\ 27 Kay Professor of Computer Science at Harvard University, and was Dean of Harvard Col\ 28 lege from 1995 to 2003. A new professorship in Engineering and Applied Sciences, end\ 29 owed by a former student, will be named for Lewis and his wife upon their retirement\ 30 s." 31 32 2 - "Cascade Investment, L.L.C. is an American holding company and private invest\ 33 ment firm headquartered in Kirkland, Washington, United States. It is controlled by \ 34 Bill Gates, and managed by Michael Larson. More than half of Gates' fortune is held \ 35 in assets outside his holding of Microsoft shares. Cascade is the successor company \ 36 to Dominion Income Management, the former investment vehicle for Gates' holdings, wh\ 37 ich was managed by convicted felon Andrew Evans." 38 39 3 - "Jerry P. Dyer (born May 3, 1959) is an American politician and former law en\ 40 forcement officer. He is the 26th and current mayor of Fresno, California. Previousl\ 41 y, he served as the chief of the Fresno Police Department." 42 43 0 44 45 - - - - Enter zero or more indices for your desired selections: 46 47 0 - "Kenexa, an IBM Company, provides employment and retention services. This inc\ 48 ludes recruitment process outsourcing onboarding tools, employee assessment, abiliti\ 49 es assessment for employment candidates (Kenexa Prove It); and Kenexa Interview Buil\ 50 der, a structured interview archive with example questions." 51 52 1 - "Sequent Computer Systems was a computer company that designed and manufactur\ 53 ed multiprocessing computer systems. They were among the pioneers in high-performanc\ 54 e symmetric multiprocessing (SMP) open systems, innovating in both hardware (e.g., c\ Knowledge Graph Navigator Text-Based User Interface 236 55 ache management and interrupt handling) and software (e.g., read-copy-update). Vesti\ 56 ges of Sequent's innovations live on in the form of data clustering software from Po\ 57 lyServe (subsequently acquired by HP), various projects within OSDL, IBM contributio\ 58 ns to the Linux kernel, and claims in the SCO v. IBM lawsuit." 59 60 2 - "i2 Limited was the UK-based arm of software company i2 Group which produced \ 61 visual intelligence and investigative analysis software for military intelligence, l\ 62 aw enforcement and commercial agencies. After a number of acquisitions, in 2011 it b\ 63 ecame part of IBM." 64 65 3 - "The International Technology Alliance in Distributed Analytics and Informati\ 66 on Sciences (DAIS-ITA) is a research program initiated by the UK Ministry of Defence\ 67 (United Kingdom) (MOD) and the US Army Research Laboratory (ARL), in September 2016\ 68 . It is led by IBM Research in the U.S. and IBM Hursley in the UK. DAIS ITA is the s\ 69 econd International Technology Alliance started by the two countries, succeeding the\ 70 previous ten year alliance NIS-ITA, which was of similar nature." 71 72 4 - "The International Technology Alliance in Network and Information Sciences (N\ 73 IS-ITA) was a research program initiated by the UK Ministry of Defence (United Kingd\ 74 om) (MoD) and the US Army Research Laboratory (ARL), which was active for 10 years f\ 75 rom May 2006 to May 2016. It was led by IBM Research in the U.S. and IBM Hursley in \ 76 the UK. NIS ITA was the first International Technology Alliance started by the two c\ 77 ountries." 78 79 5 - "Applix Inc. was a computer software company founded in 1983 based in Westbor\ 80 ough, Massachusetts that published Applix TM1, a multi-dimensional online analytical\ 81 processing (MOLAP) database server, and related presentation tools, including Appli\ 82 x Web and Applix Executive Viewer. Together, Applix TM1, Applix Web and Applix Execu\ 83 tive Viewer were the three core components of the Applix Business Analytics Platform\ 84 . (Executive Viewer was subsequently discontinued by IBM.)" 85 86 6 - "Ounce Labs (an IBM company) is a Waltham, Massachusetts-based security softw\ 87 are vendor. The company was founded in 2002 and created a software analysis product \ 88 that analyzes source code to identify and remove security vulnerabilities. The secur\ 89 ity software looks for a range of vulnerabilities that leave an application open to \ 90 attack. Customers have included GMAC, Lockheed Martin, and the U.S. Navy. On July 28\ 91 , 2009, Ounce was acquired by IBM, for an undisclosed sum, with the intention of int\ 92 egrating it into IBM's Rational Software business." 93 94 7 - "IBM Watson Health is a digital tool that helps clients facilitate medical re\ 95 search, clinical research, and healthcare solutions, through the use of artificial i\ 96 ntelligence, data, analytics, cloud computing, and other advanced information techno\ 97 logy. It is a division of the International Business Machines Corporation, (IBM), an\ Knowledge Graph Navigator Text-Based User Interface 237 98 American multinational information technology company headquartered in Armonk, New \ 99 York." 100 101 8 - "International Business Machines Corporation (IBM) is an American multination\ 102 al technology corporation headquartered in Armonk, New York, with operations in over\ 103 171 countries. The company began in 1911, founded in Endicott, New York by trust bu\ 104 sinessman Charles Ranlett Flint, as the Computing-Tabulating-Recording Company (CTR)\ 105 and was renamed \"International Business Machines\" in 1924. IBM is incorporated in\ 106 New York." 107 108 9 - "Microsoft Corporation is an American multinational technology corporation wh\ 109 ich produces computer software, consumer electronics, personal computers, and relate\ 110 d services. Its best known software products are the Microsoft Windows line of opera\ 111 ting systems, the Microsoft Office suite, and the Internet Explorer and Edge web bro\ 112 wsers. Its flagship hardware products are the Xbox video game consoles and the Micro\ 113 soft Surface lineup of touchscreen personal computers. Microsoft ranked No. 21 in th\ 114 e 2020 Fortune 500 rankings of the largest United States corporations by total reven\ 115 ue; it was the world's largest software maker by revenue as of 2016. It is considere\ 116 d one of the Big Five companies in the U.S. information technology industry, along w\ 117 ith Amazon, Google (Alphabet), Apple, and Facebook (" 118 119 10 - "The CSS Working Group (Cascading Style Sheets Working Group) is a working g\ 120 roup created by the World Wide Web Consortium (W3C) in 1997, to tackle issues that h\ 121 ad not been addressed with CSS level 1. As of December 2019, the CSSWG had 142 membe\ 122 rs. The working group is co-chaired by and ." 123 124 11 - "The AMD Professional Gamers League (PGL), founded around 1997, was one of t\ 125 he first professional computer gaming eSports leagues. The PGL was run by Total Ente\ 126 rtainment Network and was sponsored by AMD. The first professional tournament they h\ 127 eld was for StarCraft in September 1997. The league was official unveiled at a press\ 128 conference at Candlestick Park in San Francisco on November 3, 1997. It was sponsor\ 129 ed by Microsoft, Nvidia, and Levi Strauss & Co. The organization raised over $1.2mil\ 130 USD in sponsorship money." 131 132 12 - "Secure Islands Technologies Ltd. was an Israeli privately held technology c\ 133 ompany headquartered in Beit Dagan which was subsequently acquired by Microsoft. The\ 134 company develops and markets Information Protection and Control (IPC) solutions." 135 136 13 - "Microsoft Innovation Centers (MICs) are local government organizations, uni\ 137 versities, industry organizations, or software or hardware vendors who partner with \ 138 Microsoft with a common goal to foster the growth of local software economies. These\ 139 are state of the art technology facilities which are open to students, developers, \ 140 IT professionals, entrepreneurs, startups and academic researchers. While each Cente\ Knowledge Graph Navigator Text-Based User Interface 238 141 r tunes its programs to local needs, they all provide similar content and services d\ 142 esigned to accelerate technology advances and stimulate local software economies thr\ 143 ough skills and professional training, industry partnerships and innovation. As of 1\ 144 0 September 2010, there are 115 Microsoft Innovation Centers worldwide, most of whic\ 145 h are open to the public. Recently it was reported th" 146 147 14 - "Press Play ApS was a Danish video game development studio based in central \ 148 Copenhagen in Denmark. Since 2006, Press Play have released five titles, including t\ 149 he Max & the Magic Marker, Max: The Curse of Brotherhood and Kalimba. On November 10\ 150 , 2016, Flashbulb acquired Press Play and its library of games to republish under th\ 151 e Flashbulb name including Kalimba, Tentacles: Enter the Mind, and Max: The Curse of\ 152 Brotherhood." 153 154 8 9 155 156 - - - ENTITY TYPE: people - - - 157 158 SPARQL to get PERSON data for : 159 160 "SELECT DISTINCT ?label ?comment@@ (GROUP_CONCAT (DISTINCT ?birthplace; SEPARATOR=' \ 161 | ') AS ?birthplace) @@ (GROUP_CONCAT (DISTINCT ?almamater; SEPARATOR=' | ') AS ?alm\ 162 amater) @@ (GROUP_CONCAT (DISTINCT ?spouse; SEPARATOR=' | ') AS ?spouse) { @@ ?\ 164 comment .@@ 165 FILTER (lang(?comment) = 'en') . @@ OPTIONAL { ?birthplace\ 167 } . @@ OPTIONAL { ?almamater } . @@ OPTIONAL { ?spouse } . @@ OPTIONAL { ?label .@@ FILTE\ 171 R (lang(?label) = 'en') } @@ } LIMIT 10@@" 172 173 174 label: Bill Gates 175 176 comment: William Henry Gates III (born October 28, 1955) is an American business mag\ 177 nate, software developer, investor, author, and philanthropist. He is a co-founder o\ 178 f Microsoft, along with his late childhood friend Paul Allen. During his career at M\ 179 icrosoft, Gates held the positions of chairman, chief executive officer (CEO), presi\ 180 dent and chief software architect, while also being the largest individual sharehold\ 181 er until May 2014. He is considered one of the best known entrepreneurs of the micro\ 182 computer revolution of the 1970s and 1980s. 183 Knowledge Graph Navigator Text-Based User Interface 239 184 birthplace: http://dbpedia.org/resource/Seattle | http://dbpedia.org/resource/Washin\ 185 gton_(state) 186 187 almamater: 188 189 spouse: http://dbpedia.org/resource/Melinda_French_Gates 190 191 - - - ENTITY TYPE: companies - - - 192 193 SPARQL to get COMPANY data for : 194 195 196 "SELECT DISTINCT ?label ?comment (GROUP_CONCAT (DISTINCT ?industry; SEPARATOR=' | ')\ 197 AS ?industry)@@ (GROUP_CONCAT (DISTINCT ?netIncome; SEPARATOR=' | ') AS ?netIncome)\ 198 @@ (GROUP_CONCAT (DISTINCT ?numberOfEmployees; SEPARATOR=' | ') AS ?numberOfEmployee\ 199 s) {@@ ?comment .@@ 201 FILTER (lang(?comment) = 'en') .@@ OPTIONAL { ?industry } .@@ OPTI\ 203 ONAL { ?ne\ 204 tIncome } .@@ OPTIONAL { ?numberOfEmployees } .@@ OPTIONAL { ?label . FILTER (lang(?label\ 207 ) = 'en') } @@ } LIMIT 30@@" 208 209 210 label: IBM 211 212 comment: International Business Machines Corporation (IBM) is an American multinatio\ 213 nal technology corporation headquartered in Armonk, New York, with operations in ove\ 214 r 171 countries. The company began in 1911, founded in Endicott, New York by trust b\ 215 usinessman Charles Ranlett Flint, as the Computing-Tabulating-Recording Company (CTR\ 216 ) and was renamed "International Business Machines" in 1924. IBM is incorporated in \ 217 New York. 218 219 industry: http://dbpedia.org/resource/Artificial_intelligence | http://dbpedia.org/r\ 220 esource/Automation | http://dbpedia.org/resource/Blockchain | http://dbpedia.org/res\ 221 ource/Cloud_computing | http://dbpedia.org/resource/Computer_hardware | http://dbped\ 222 ia.org/resource/Quantum_computing | http://dbpedia.org/resource/Robotics | http://db\ 223 pedia.org/resource/Software 224 225 net-income: 5.59E9 226 Knowledge Graph Navigator Text-Based User Interface 240 227 number-of-employees: 345900 228 229 SPARQL to get COMPANY data for : 230 231 232 "SELECT DISTINCT ?label ?comment (GROUP_CONCAT (DISTINCT ?industry; SEPARATOR=' | ')\ 233 AS ?industry)@@ (GROUP_CONCAT (DISTINCT ?netIncome; SEPARATOR=' | ') AS ?netIncome)\ 234 @@ (GROUP_CONCAT (DISTINCT ?numberOfEmployees; SEPARATOR=' | ') AS ?numberOfEmployee\ 235 s) {@@ ?comment .@@ 237 FILTER (lang(?comment) = 'en') .@@ OPTIONAL { ?industry } .@@\ 239 OPTIONAL { ?netIncome } .@@ OPTIONAL { ?numberOfEmployees } .@@ OPTIONAL { ?lab\ 243 el . FILTER (lang(?label) = 'en') } @@ } LIMIT 30@@" 244 245 246 label: Microsoft 247 248 comment: Microsoft Corporation is an American multinational technology corporation w\ 249 hich produces computer software, consumer electronics, personal computers, and relat\ 250 ed services. Its best known software products are the Microsoft Windows line of oper\ 251 ating systems, the Microsoft Office suite, and the Internet Explorer and Edge web br\ 252 owsers. Its flagship hardware products are the Xbox video game consoles and the Micr\ 253 osoft Surface lineup of touchscreen personal computers. Microsoft ranked No. 21 in t\ 254 he 2020 Fortune 500 rankings of the largest United States corporations by total reve\ 255 nue; it was the world's largest software maker by revenue as of 2016. It is consider\ 256 ed one of the Big Five companies in the U.S. information technology industry, along \ 257 with Amazon, Google (Alphabet), Apple, and Facebook ( 258 259 industry: http://dbpedia.org/resource/Cloud_computing | http://dbpedia.org/resource/\ 260 Computer_hardware | http://dbpedia.org/resource/Consumer_electronics | http://dbpedi\ 261 a.org/resource/Corporate_venture_capital | http://dbpedia.org/resource/Internet | ht\ 262 tp://dbpedia.org/resource/Social_networking_service | http://dbpedia.org/resource/So\ 263 ftware_development | http://dbpedia.org/resource/Video_game_industry 264 265 net-income: 6.06E10 266 267 number-of-employees: 182268 268 269 DISCOVERED RELATIONSHIP LINKS: Knowledge Graph Navigator Text-Based User Interface 241 270 271 272 273 . 274 275 276 277 278 . 279 280 281 282 283 . 284 285 "Enter entity names (people, places, companies, etc.": On line 10 I input a test phrase “Bill Gates worked at Microsoft and his competitor was IBM.” In lines 13-41 the test program prints out matching human entities from DBPedia that are indexed starting at 0. On line 43 I entered 0 to choose just the first entity “William Henry Gates III”. The prompt on line 45 asks the user to enter the indices for the company DBPedia entities they want to use. These companies are listed in lines 47-152. On line 154 I entered “8 9” to select two entities to use. Lines 156-171 show the automatically generated SPARQL query to get information about Bill Gates. This information is printed on lines 174-189. I list more generated SPARQL queries and results (which we will not discuss further). Lines 269-283 show discovered links found between the entities in the input text. In the LispWorks CAPI user interface developed in the next chapter I use two text output stream window panes, one for the generated SPARQL and one for the results. Text User Interface Implementation We will skip looking at the kgn-text-ui.asd and package.lisp files for this library but look at src/kgn- text-ui/kgn-text-ui.lisp in its entirety. When entities are identified in input text we find candidate DBPedia entity URIs that we present to the user. We precede each entire DBPedia description with an index starting at 0. The user enters the indices for entities to further process. For example, in the example listing in the previous section I entered “8 9” to indicate two company URIs. Knowledge Graph Navigator Text-Based User Interface 242 1 (in-package #:kgn-text-ui) 2 3 (defun pprint-results (results) 4 (dolist (result (car results)) 5 (terpri) 6 (format t "~A:" (first result)) 7 (format t " ~A~%" (second result)))) 8 9 10 (defun multiple-selections (sel-list) 11 (if (not (null sel-list)) 12 (let () 13 (pprint sel-list) 14 (format t 15 "~%- - - - Enter zero or more indices for your desired selections:~%~%") 16 (let ((count 0)) 17 (dolist (sel sel-list) 18 (format t "~A - ~S ~%~%" count (cadr (assoc :comment (car sel)))) 19 (setf count (1+ count)))) 20 (let* ((line (read-line)) 21 (indices 22 (if (> (length line) 0) 23 (mapcar 24 #'parse-integer 25 (myutils:tokenize-string line))))) 26 (print indices) 27 ;(dolist (index indices) 28 ; (setf ret (cons (nth index str-list) 29 indices)))) 30 31 ;; (kgn-text-ui::multiple-selections 32 ;; '("Option 1" "Option 2" "And yet another option 3")) 33 34 35 (defun prompt-selection-list (a-list-of-choices) 36 ;; e.g., '((:people (("11" "data1") ("22" "data2"))) (:places (("p1" "data3")))) 37 (let (ret) 38 (dolist (choice a-list-of-choices) 39 (setf choice (remove-if #'null choice)) 40 (let* ((topic-type (car choice)) 41 (choice-list-full (rest choice)) 42 (choice-list (remove-duplicates 43 (map 'list #'(lambda (z) Knowledge Graph Navigator Text-Based User Interface 243 44 (list 45 z 46 (string-shorten 47 (kgn-common:clean-comment 48 (kgn-common:clean-comment (cadr z))) 49 140 :first-remove-stop-words t))) 50 ;; top level list flatten: 51 (apply #'append choice-list-full)) 52 :test #'equal))) 53 (let (ret2 54 (dialog-results (multiple-selections choice-list))) 55 (dolist (index dialog-results) 56 (setf ret2 (cons (nth index choice-list) ret2))) 57 (if (> (length ret2) 0) 58 (setf ret (cons (list topic-type (reverse ret2)) ret)))))) 59 (reverse ret))) 60 61 ;; (kgn-text-ui::prompt-selection-list 62 ;; '((:people (("11" "data1") ("22" "data2"))) 63 ;; (:places (("p1" "data3") ("p2" "data4") ("p3" "data5"))))) 64 ;; (kgn-text-ui::prompt-selection-list 65 ;; (get-entity-data-helper "Bill Gates went to Seattle to Microsoft")) 66 67 (defun colorize-sparql (str &key (stream t)) 68 " this could be used to colorize text (as it is in kgn-capi-ui example)" 69 ;;(declare (ignore message-stream)) 70 (declare (ignore stream)) 71 (format t "~%~S~%" str)) 72 73 (defun get-string-from-user (text-prompt) 74 (format t "~%~S:~%" text-prompt) 75 (read-line)) 76 77 78 ;; Main funtion 79 80 (defun kgn-text-ui () 81 (let (prompt 82 (message-stream t) 83 (results-stream t)) 84 (loop 85 while 86 (> Knowledge Graph Navigator Text-Based User Interface 244 87 (length 88 (setf prompt 89 (get-string-from-user 90 "Enter entity names (people, places, companies, etc."))) 91 0) 92 do 93 (let* ((entity-data (get-entity-data-helper prompt :message-stream t))) 94 (let ((user-selections (prompt-selection-list entity-data))) 95 (dolist (ev user-selections) 96 (if (> (length (cadr ev)) 0) 97 (let () 98 (terpri results-stream) 99 (format results-stream "- - - ENTITY TYPE: ~A - - -" (car ev)) 100 ;;(terpri results-stream) 101 (dolist (uri (cadr ev)) 102 (setf uri (assoc :s (car uri))) 103 (case (car ev) 104 (:people 105 (pprint-results 106 (kgn-common:dbpedia-get-person-detail 107 uri 108 :message-stream message-stream 109 :colorize-sparql-function #'colorize-sparql))) 110 (:companies 111 (pprint-results 112 (kgn-common:dbpedia-get-company-detail uri 113 :message-stream message-stream 114 :colorize-sparql-function #'colorize-sparql))) 115 (:countries 116 (pprint-results 117 (kgn-common:dbpedia-get-country-detail uri 118 :message-stream message-stream 119 :colorize-sparql-function #'colorize-sparql))) 120 (:cities 121 (pprint-results 122 (kgn-common:dbpedia-get-city-detail uri 123 :message-stream message-stream 124 :colorize-sparql-function #'colorize-sparql))) 125 (:products 126 (pprint-results 127 (kgn-common:dbpedia-get-product-detail uri 128 :message-stream message-stream 129 :colorize-sparql-function #'colorize-sparql))))))))))))) Knowledge Graph Navigator Text-Based User Interface 245 130 131 ;; (kgn-text-ui:kgn-text-ui) The utility function multiple-selections listed in lines 10-29 displays a list of user choices, adding a zero-based index for each list item. The user can enter zero or more indices to indicate their choices using the function prompt-selection-list listed in lines 35-59. The commented out code in lines 61-65 can be used to test these two functions. The main function kgn-text-ui is listed in lines 80-129. Wrap-up In the previous chapter we implemented the Knowledge Graph Navigator library. Here we developed a text-based user interface. In the next chapter we use the library to develop a LispWorks specific CAPI user interface. Knowledge Graph Navigator User Interface Using LispWorks CAPI As we have seen in the last two chapters the Knowledge Graph Navigator (which I will often refer to as KGN) is a tool for processing a set of entity names and automatically exploring the public Knowledge Graph DBPedia⁹⁵ using SPARQL queries. I started to write KGN for my own use, to automate some things I used to do manually when exploring Knowledge Graphs, and later thought that KGN might also be useful for educational purposes. KGN shows the user the auto-generated SPARQL queries so hopefully the user will learn by seeing examples. KGN uses NLP code developed in earlier chapters and we will reuse that code with a short review of using the APIs. Here is a screenshot showing the application we develop here: UI for the Knowledge Graph Navigator We will use the KGN common library developed earlier. This example replaces the text bases UI from the last chapter and requires either the free or professional version of LispWorks to run. The code for the CAPI user interface is found in the GitHub repository https://github.com/mark- watson/kgn-capi-ui⁹⁶. ⁹⁵http://dbpedia.org ⁹⁶https://github.com/mark-watson/kgn-capi-ui Knowledge Graph Navigator User Interface Using LispWorks CAPI 247 Project Configuration and Running the Application The following listing of kgn.asd shows the five packages this example depends on in addition to #:kgn-common that was developed in an earlier chapter that is referenced in the file package.lisp: 1 ;;;; knowledgegraphnavigator.asd 2 3 (asdf:defsystem #:kgn-capi-ui 4 :description "top level Knowledge Graph Navigator package" 5 :author "Mark Watson " 6 :license "Apache 2" 7 :depends-on (#:kgn-common #:sparql #:kbnlp #:lw-grapher #:trivial-open-browser) 8 :components ((:file "package") 9 (:file "kgn-capi-ui") 10 (:file "option-pane") 11 (:file "colorize") 12 (:file "user-interface"))) Other dependency libraries specified in project.lisp are trivial-open-browser which we will use to open a web browser to URIs for human readable information on DBPedia and sparql that was developed in an earlier chapter. Listing of package.lisp: 1 ;;;; package.lisp 2 3 (defpackage #:kgn-capi-ui 4 (:use #:cl) 5 (:use #:kgn-common #:sparql #:lw-grapher #:trivial-open-browser) 6 (:export #:kgn-capi-ui)) The free personal edition of LispWorks does not support initialization files so you must manually load Quicklisp from the Listener Window when you first start LispWorks Personal as seen in the following repl listing (edited to remove some output for brevity). Once Quicklisp is loaded we then use ql:quickload to load the example in this chapter (some output removed for brevity): Knowledge Graph Navigator User Interface Using LispWorks CAPI 248 CL-USER 1 > (load "~/quicklisp/setup.lisp") ; Loading text file /Users/markw/quicklisp/setup.lisp ; Loading /Applications/LispWorks Personal 7.1/... ;; Creating system "COMM" #P"/Users/markw/quicklisp/setup.lisp" CL-USER 2 > (ql:quickload "kgn") To load "kgn": Load 1 ASDF system: kgn ; Loading "kgn" . "Starting to load data...." "....done loading data." "#P\"/Users/markw/GITHUB/common-lisp/entity-uris/entity-uris.lisp\"" "current directory:" "/Users/markw/GITHUB/common-lisp/entity-uris" "Starting to load data...." "....done loading data." [package kgn] To load "sqlite": Load 1 ASDF system: sqlite ; Loading "sqlite" To load "cl-json": Load 1 ASDF system: cl-json ; Loading "cl-json" To load "drakma": Load 1 ASDF system: drakma ; Loading "drakma" .To load "entity-uris": Load 1 ASDF system: entity-uris ; Loading "entity-uris" ("kgn") CL-USER 3 > (kgn:kgn) # Please note that I assume you have configured all of the examples for this book for discoverability by Quicklisp as per the section Setup for Local Quicklisp Projects in Appendix A. When the KGN application starts a sample query is randomly chosen. Queries with many entities Knowledge Graph Navigator User Interface Using LispWorks CAPI 249 can take a while to process, especially when you first start using this application. Every time KGN makes a web service call to DBPedia the query and response are cached in a SQLite database in ∼/.kgn_cache.db which can greatly speed up the program, especially in development mode when testing a set of queries. This caching also takes some load off of the public DBPedia endpoint, which is a polite thing to do. I use LispWorks Professional and add two utility functions to the bottom on my ∼/.lispworks configuration file (you can’t do this with LispWorks Personal): 1 ;;; The following lines added by ql:add-to-init-file: 2 #-quicklisp 3 (let ((quicklisp-init 4 (merge-pathnames 5 "quicklisp/setup.lisp" 6 (user-homedir-pathname)))) 7 (when (probe-file quicklisp-init) 8 (load quicklisp-init))) 9 10 (defun ql (x) (ql:quickload x)) 11 (defun qlp (x) 12 (ql:quickload x) 13 (SYSTEM::%IN-PACKAGE (string-upcase x) :NEW T)) Function ql is just a short alias to avoid frequently typing ql:quickload and qlp loads a Quicklisp project and then performs an in-package of the Common Lisp package with the same name as the Quicklisp project. Utilities to Colorize SPARQL and Generated Output When I first had the basic functionality of KGN with a CAPI UI working, I was disappointed by how the application looked as all black text on a white background. Every editor and IDE I use colorizes text in an appropriate way so I took advantage of the function capi::write-string-with-properties to easily implement color hilting SPARQL queries. The code in the following listing is in the file kgn/colorize.lisp. When I generate SPARQL queries to show the user I use the characters “@@” as placeholders for end of lines in the generated output. In line 5 I am ensuring that there are spaces around these characters so they get tokenized properly. In the loop starting at line 7 I process the tokens checking each one to see if it should have a color associated with it when it is written to the output stream. Knowledge Graph Navigator User Interface Using LispWorks CAPI 250 1 (in-package #:kgn) 2 3 (defun colorize-sparql (s &key (stream nil)) 4 (let ((tokens (tokenize-string-keep-uri 5 (replace-all s "@@" " @@ "))) 6 in-var) 7 (dolist (token tokens) 8 (if (> (length token) 0) 9 (if (or in-var (equal token "?")) 10 (capi::write-string-with-properties 11 token 12 '(:highlight :compiler-warning-highlight) 13 stream) 14 (if (find token '("where" "select" "distinct" "option" "filter" 15 "FILTER" "OPTION" "DISTINCT" 16 "SELECT" "WHERE") 17 :test #'equal) 18 (capi::write-string-with-properties 19 token 20 '(:highlight :compiler-note-highlight) 21 stream) 22 (if (equal (subseq token 0 1) "<") 23 (capi::write-string-with-properties 24 token 25 '(:highlight :bold) 26 stream) 27 (if (equal token "@@") 28 (terpri stream) 29 (if (not (equal token "~")) (write-string token stream))))))) 30 (if (equal token "?") 31 (setf in-var t) 32 (setf in-var nil)) 33 (if (and 34 (not in-var) 35 (not (equal token "?"))) 36 (write-string " " stream))) 37 (terpri stream))) Here is an example call to function colorize-sparql: Knowledge Graph Navigator User Interface Using LispWorks CAPI 251 KGN 25 > (colorize-sparql "select ?s ?p where {@@ ?s ?p \"Microsoft\" } @@ FILTER\ (lang(?comment) = 'en')") select ?s ?p where { ?s ?p "Microsoft" } FILTER ( lang ( ?comment ) = 'en' ) Main Implementation File kgn-capi-ui.lisp 1 ;;---------------------------------------------------------------------------- 2 ;; To try it, compile and load this file and then execute: 3 ;; 4 ;; (kgn::kgn) 5 ;; 6 ;;---------------------------------------------------------------------------- 7 ;; Copyright (c) 2020-2022 Mark Watson. All rights reserved. 8 ;;---------------------------------------------------------------------------- 9 10 (in-package #:kgn-capi-ui) 11 12 (defvar *width* 1370) 13 (defvar *best-width* 1020) 14 (defvar *show-info-pane* t) 15 16 (defvar *pane2-message* 17 "In order to process your query a series of SPARQL queries will be formed based on\ 18 the query. These generated SPARQL queries will be shown here and the reuslts of the\ 19 queries will be formatted and displayed in the results display pane below.") 20 21 (defvar *pane3-message* 22 "Enter a query containing entities like people's names, companys, places, etc. fol\ 23 lowing by the RETURN key to start processing your query. You can also directly use a\ 24 DBPedia URI for an entity, for example: Wh\ 25 en you start this application, a sample query is randomly chosen to get you started.\ 26 ") 27 28 (defun test-callback-click (selected-node-name) 29 (ignore-errors 30 (format nil "* user clicked on node: ~A~%" selected-node-name))) 31 32 (defun test-callback-click-shift (selected-node-name) 33 (ignore-errors Knowledge Graph Navigator User Interface Using LispWorks CAPI 252 34 (if (equal (subseq selected-node-name 0 5) "" 54 "Bill Gates and Steve Jobs visited IBM and Microsoft in Berlin, S\ 55 an Francisco, Toronto, Canada" 56 "Steve Jobs lived near San Francisco and was a founder of " 58 " visited IBM" 59 " visited " 61 "Bill Gates visited ")) 62 63 (capi:define-interface kgn-interface () 64 () 65 (:menus 66 (action-menu 67 "Actions" 68 ( 69 ("Copy generated SPARQL to clipboard" 70 :callback 71 #'(lambda (&rest x) (declare (ignore x)) 72 (let ((messages (capi:editor-pane-text text-pane2))) 73 (capi::set-clipboard text-pane2 (format nil "---- Generated SPARQL and c\ 74 omments:~%~%~A~%~%" messages) nil)))) 75 ("Copy results to clipboard" 76 :callback Knowledge Graph Navigator User Interface Using LispWorks CAPI 253 77 #'(lambda (&rest x) (declare (ignore x)) 78 (let ((results (capi:editor-pane-text text-pane3))) 79 (capi::set-clipboard text-pane2 (format nil "---- Results:~%~%~A~%" resu\ 80 lts) nil)))) 81 ("Copy generated SPARQL and results to clipboard" 82 :callback 83 #'(lambda (&rest x) (declare (ignore x)) 84 (let ((messages (capi:editor-pane-text text-pane2)) 85 (results (capi:editor-pane-text text-pane3))) 86 (capi::set-clipboard 87 text-pane2 88 (format nil "---- Generated SPARQL and comments:~%~%~A~%~%---- Results:\ 89 ~%~%~A~%" messages results) nil)))) 90 ("Visit Knowledge Graph Navigator Web Site" :callback 'website-callback) 91 ("Clear query cache" :callback 'cache-callback) 92 ((if *show-info-pane* 93 "Stop showing Grapher window for new results" 94 "Start showing Grapher window for new results") 95 :callback 'toggle-grapher-visibility) 96 ))) 97 (:menu-bar action-menu) 98 (:panes 99 (text-pane1 100 capi:text-input-pane 101 :text (nth (random (length *examples*)) *examples*) 102 :title "Query" 103 :min-height 80 104 :max-height 100 105 :max-width *width* 106 ;;:min-width (- *width* 480) 107 :width *best-width* 108 :callback 'start-background-thread) 109 110 (text-pane2 111 capi:collector-pane 112 :font "Courier" 113 :min-height 210 114 :max-height 250 115 :title "Generated SPARQL queries to get results" 116 :text "Note: to answer queries, this app makes multipe SPARQL queries to DBPedia\ 117 . These SPARQL queries will be shown here." 118 :vertical-scroll t 119 :create-callback #'(lambda (&rest x) Knowledge Graph Navigator User Interface Using LispWorks CAPI 254 120 (declare (ignore x)) 121 (setf (capi:editor-pane-text text-pane2) *pane2-message*)) 122 :max-width *width* 123 :width *best-width* 124 :horizontal-scroll t) 125 126 (text-pane3 127 capi:collector-pane ;; capi:display-pane ;; capi:text-input-pane 128 :text *pane3-message* 129 :font "Courier" 130 :line-wrap-marker nil 131 :wrap-style :split-on-space 132 :vertical-scroll :with-bar 133 :title "Results" 134 :horizontal-scroll t 135 :min-height 220 136 :width *best-width* 137 :create-callback #'(lambda (&rest x) 138 (declare (ignore x)) 139 (setf (capi:editor-pane-text text-pane3) *pane3-message*)) 140 :max-height 240 141 :max-width *width*) 142 (info 143 capi:title-pane 144 :text "Use natural language queries to generate SPARQL")) 145 (:layouts 146 (main-layout 147 capi:grid-layout 148 '(nil info 149 nil text-pane1 150 nil text-pane2 151 nil text-pane3) 152 :x-ratios '(1 99) 153 :has-title-column-p t)) 154 (:default-initargs 155 :layout 'main-layout 156 :title "Knowledge Graph Navigator" 157 :best-width *best-width* 158 :max-width *width*)) 159 160 (defun start-background-thread (query-text self) 161 (format t "~%** ** entering start-progress-bar-test-from-background-thread:~%~%sel\ 162 f=~S~%~%" self) Knowledge Graph Navigator User Interface Using LispWorks CAPI 255 163 (with-slots (text-pane2 text-pane3) self 164 (print text-pane2) 165 (mp:process-run-function "progress-bar-test-from-background-thread" 166 '() 167 'run-and-monitor-progress-background-thread 168 query-text text-pane2 text-pane3))) 169 170 ;; This function runs in a separate thread. 171 172 (defun run-and-monitor-progress-background-thread (text text-pane2 text-pane3) 173 (unwind-protect 174 (setf (capi:editor-pane-text text-pane2) "") 175 (setf (capi:editor-pane-text text-pane3) "") 176 ;;(capi:display-message "done") 177 (let ((message-stream (capi:collector-pane-stream text-pane2)) 178 (results-stream (capi:collector-pane-stream text-pane3))) 179 (format message-stream "# Starting to process query....~%") 180 (format results-stream *pane3-message*) 181 (let ((user-selections (prompt-selection-list (get-entity-data-helper text :me\ 182 ssage-stream message-stream)))) 183 (print "***** from prompt selection list:") (print user-selections) 184 (setf (capi:editor-pane-text text-pane3) "") 185 (dolist (ev user-selections) 186 (if (> (length (cadr ev)) 0) 187 (let () 188 (terpri results-stream) 189 (capi::write-string-with-properties 190 (format nil "- - - ENTITY TYPE: ~A - - -" (car ev)) 191 '(:highlight :compiler-error-highlight) results-stream) 192 ;;(terpri results-stream) 193 (dolist (uri (cadr ev)) 194 (setf uri (car uri)) 195 (case (car ev) 196 (:people 197 (pprint-results 198 (kgn-common:dbpedia-get-person-detail uri :message-stream mes\ 199 sage-stream :colorize-sparql-function #'colorize-sparql) 200 :stream results-stream)) 201 (:companies 202 (pprint-results 203 (kgn-common:dbpedia-get-company-detail uri :message-stream mes\ 204 sage-stream :colorize-sparql-function #'colorize-sparql) 205 :stream results-stream)) Knowledge Graph Navigator User Interface Using LispWorks CAPI 256 206 (:countries 207 (pprint-results 208 (kgn-common:dbpedia-get-country-detail uri :message-stream mes\ 209 sage-stream :colorize-sparql-function #'colorize-sparql) 210 :stream results-stream)) 211 (:cities 212 (pprint-results 213 (kgn-common:dbpedia-get-city-detail uri :message-stream mes\ 214 sage-stream :colorize-sparql-function #'colorize-sparql) 215 :stream results-stream)) 216 (:products 217 (pprint-results 218 (kgn-common:dbpedia-get-product-detail uri :message-stream mes\ 219 sage-stream :colorize-sparql-function #'colorize-sparql) 220 :stream results-stream))))))) 221 222 (let (links x) 223 (dolist (ev user-selections) 224 (dolist (uri (second ev)) 225 (setf uri (car uri)) 226 (if (> (length ev) 2) 227 (setf x (caddr ev))) 228 (setf links (cons (list (symbol-name (first ev)) uri x) links))) 229 230 (setf 231 links 232 (append 233 links 234 (entity-results->relationship-links 235 user-selections 236 :message-stream message-stream)))) 237 238 (if 239 *show-info-pane* 240 (lw-grapher:make-info-panel-grapher '("PEOPLE" "COMPANIES" "COUNTRIES"\ 241 "CITIES" "PRODUCTS" "PLACES") 242 links 'test-callback-click 'test-c\ 243 allback-click-shift))) ;; do not use #' !! 244 (terpri results-stream) 245 (princ "** Done wih query **" results-stream))))) 246 247 248 Knowledge Graph Navigator User Interface Using LispWorks CAPI 257 249 ;; MAIN entry point for application: 250 251 (defun kgn-capi-ui () 252 ;;(ignore-errors (create-dbpedia)) 253 (capi:display (make-instance 'kgn-interface))) User Interface Utilites File user-interface.lisp In the previous chapter, the function prompt-selection-list was defined in the file kgn-text-ui/kgn- text-ui.lisp for text based (console) UIs. Here it is implemented in a separate file user-interface.lisp in the project directory kgn-capi-ui. 1 (in-package #:kgn-capi-ui) 2 3 ;; (use-package "CAPI") 4 5 (defun prompt-selection-list (a-list-of-choices) 6 (let (ret) 7 (dolist (choice a-list-of-choices) 8 (setf choice (remove-if #'null choice)) 9 (let* ((topic-type (car choice)) 10 (choice-list-full (rest choice)) 11 (choice-list (remove-duplicates 12 (map 'list #'(lambda (z) 13 (list 14 z ;; (first z) 15 (string-shorten 16 (kgn-common:clean-comment 17 (kgn-common:clean-comment (cadr z))) 18 140 :first-remove-stop-words t))) 19 (apply #'append choice-list-full)) 20 :test #'equal))) 21 (let ((dialog-results (alexandria:flatten 22 (capi:prompt-with-list ;; SHOW SELECTION LIST 23 (map 'list #'second choice-list) 24 (symbol-name topic-type) 25 :interaction :multiple-selection 26 :choice-class 'capi:button-panel 27 :pane-args '(:visible-min-width 910 28 :layout-class capi:column-layout)))) 29 (ret2)) Knowledge Graph Navigator User Interface Using LispWorks CAPI 258 30 (dolist (x choice-list) 31 (if (find (second x) dialog-results) 32 (setf ret2 (cons (car x) ret2)))) 33 (if (> (length ret2) 0) 34 (setf ret (cons (list topic-type (reverse ret2)) ret)))))) 35 (reverse ret))) 36 37 ;; (get-entity-data-helper "Bill Gates went to Seattle to Microsoft") 38 ;; (prompt-selection-list 39 ;; (get-entity-data-helper 40 ;; "Bill Gates went to Seattle to Microsoft")) User Interface CAPI Options Panes Definition File option-pane.lisp In the following listing we define functions to implement CAPI menus: 1 (in-package #:kgn-capi-ui) 2 3 ;; options for: 4 ;; 1. programming language to generate code snippets for 5 ;; 2. colorization options (do we really need this??) 6 ;; 3. show disk space used by caching 7 ;; 4. option to remove local disk cache 8 9 (defvar *width-options-panel* 800) 10 11 (defun get-cache-disk-space () 12 (let ((x (ignore-errors 13 (floor 14 (/ 15 (with-open-file 16 (file "~/Downloads/knowledge_graph_navigator_cache.db") 17 (file-length file)) 1000))))) 18 (or x 0))) ;; units in megabytes 19 20 (defun clear-cache-callback (&rest val) 21 (declare (ignore val)) 22 (ignore-errors (delete-file "~/Downloads/knowledge_graph_navigator_cache.db"))) 23 24 (defvar *code-snippet-language* nil) Knowledge Graph Navigator User Interface Using LispWorks CAPI 259 25 (defun set-prog-lang (&rest val) 26 (format t "* set-prog-lang: val=~S~%" val) 27 (setf *code-snippet-language* (first val))) 28 29 (capi:define-interface options-panel-interface () 30 () 31 (:panes 32 #| 33 (prog-lang-pane 34 capi:option-pane 35 :items '("No language set" "Python" "Common Lisp") 36 :visible-items-count 6 37 :selection (if (equal *code-snippet-language* nil) 38 0 39 (if (equal *code-snippet-language* "No language set") 40 0 41 (if (equal *code-snippet-language* "Python") 42 1 43 (if (equal *code-snippet-language* "Common Lisp") 44 2 45 0)))) 46 :interaction :single-selection 47 :selection-callback 48 'set-prog-lang)|# 49 (disk-space-pane 50 capi:text-input-pane 51 :text (format nil "~A (megabytes)" 52 (let ((x 53 (ignore-errors 54 (floor 55 (/ 56 (with-open-file (file "~/.kgn_cache.db") 57 (file-length file)) 58 1000))))) 59 (if x 60 x 61 0))) 62 :title "Current size of cache:" 63 :min-width 170 64 :max-width *width-options-panel*) 65 (clear-disk-cache-pane 66 capi:push-button-panel 67 ;;:title "Clear local query cache:" Knowledge Graph Navigator User Interface Using LispWorks CAPI 260 68 :items 69 '("Clear local query cache") 70 :selection-callback 71 #'(lambda (&rest val) 72 (declare (ignore val)) 73 (ignore-errors (delete-file "~/.kgn_cache.db")) 74 (ignore-errors (setf (capi:text-input-pane-text disk-space-pane) 75 "0 (megabytes)")))) 76 (toggle-graph-display 77 capi:option-pane 78 :items '("Show Graph Info Pane Browser" "Hide Graph Info Pane Browser") 79 :selected-item (if *show-info-pane* 0 1) 80 ;;:title "" 81 :selection-callback 'toggle-grapher-visibility)) 82 83 (:layouts 84 (main-layout 85 capi:grid-layout 86 '(nil disk-space-pane 87 nil clear-disk-cache-pane) 88 :x-ratios '(1 99) 89 :has-title-column-p nil)) 90 (:default-initargs 91 :layout 'main-layout 92 :title "Knowledge Graph Navigator Options" 93 :max-width *width-options-panel*)) 94 95 ;; MAIN entry point for application: 96 97 98 ;; (capi:display (make-instance 'options-panel-interface)) 99 100 (defun ui2 () (capi:display (make-instance 'options-panel-interface))) The popup list in the last example looks like: Knowledge Graph Navigator User Interface Using LispWorks CAPI 261 Popup list shows the user possible entity resolutions for each entity found in the input query. The user selects the resolved entities to use. In this example there were two “Bill Gates” entities, one an early American frontiersman, the other the founder of Microsoft and I chose the latter person to continue finding information about. Using LispWorks CAPI UI Toolkit You can use the free LispWorks Personal Edition for running KGN. Using other Common Lisp implementations like Clozure-CL and SBCL will not work because the CAPI user interface library is proprietary to LispWorks. I would like to direct you to three online resources for learning CAPI: • [LispWorks’ main web page introducing CAPI⁹⁷ • LispWorks’ comprehensive CAPI documentation⁹⁸ for LispWorks version 7.1 • An older web site (last updated in 2011 but I find it useful for ideas): CAPI Cookbook⁹⁹ I am not going to spend too much time in this chapter explaining my CAPI-based code. If you use LispWorks (either the free Personal or the Professional editions) you are likely to use CAPI and spending time on the official documentation and especially the included example programs is strongly recommended. In the next section I will review the KGN specific application parts of the CAPI-based UI. The following figure shows a popup window displaying a graph of discovered entities and relationships: ⁹⁷http://www.lispworks.com/products/capi.html ⁹⁸http://www.lispworks.com/products/capi.html ⁹⁹http://capi.plasticki.com/show?O4 Knowledge Graph Navigator User Interface Using LispWorks CAPI 262 UI for info-pane-grapher Since I just showed the info-pane-grapher this is a good time to digress to its implementation. This is in a different package and you will find the source code in src/lw-grapher/info-pane-grapher.lisp. I used the graph layout algorithm from ISI-Grapher Manual (by Gabriel Robbins)¹⁰⁰. There is another utility in src/lw-grapher/lw-grapher.lisp that also displays a graph without mouse support and an attached information pane that is not used here but you might prefer it for reuse in your projects if you don’t need mouse interactions. The graph nodes are derived from the class capi:pinboard-object: 1 (defclass text-node (capi:pinboard-object) 2 ((text :initarg :text :reader text-node-text) 3 (string-x-offset :accessor text-node-string-x-offset) 4 (string-y-offset :accessor text-node-string-y-offset))) I customized how my graph nodes are drawn in a graph pane (this is derived from LispWorks example code): ¹⁰⁰http://www.cs.virginia.edu/~robins/papers/The_ISI_Grapher_Manual.pdf Knowledge Graph Navigator User Interface Using LispWorks CAPI 263 1 (defmethod capi:draw-pinboard-object (pinboard (self text-node) 2 &key &allow-other-keys) 3 (multiple-value-bind (X Y width height) 4 (capi:static-layout-child-geometry self) 5 (let* ((half-width (floor (1- width) 2)) 6 (half-height (floor (1- height) 2)) 7 (circle-x (+ X half-width)) 8 (circle-y (+ Y half-height)) 9 (background :white) 10 (foreground (if background 11 :black 12 (capi:simple-pane-foreground pinboard))) 13 (text (text-node-text self))) 14 (gp:draw-ellipse pinboard 15 circle-x circle-y 16 half-width half-height 17 :filled t 18 :foreground background) 19 (gp:draw-ellipse pinboard 20 circle-x circle-y 21 half-width half-height 22 :foreground foreground) 23 (gp:draw-string pinboard 24 text 25 (+ X (text-node-string-x-offset self)) 26 (+ Y (text-node-string-y-offset self)) 27 :foreground foreground)))) Most of the work is done in the graph layout method that uses Gabriel Robbins’ algorithm. Here I just show the signature and we won’t go into implementation. If you are interested in modifying the layout code, I include a screen shot from ISI-Grapher manual showing the algorithm in a single page; see the file src/lw-grapher/Algorithm from ISI-Grapher Manual.png. The following code snippets show the method signature for the layout algorithm function in the file src/lw-grapher/grapher.lisp. I also include the call to capi:graph-pane-nodes that is the CLOS reader method for getting the list of node objects in a graph pane: 1 (defun graph-layout (self &key force) 2 (declare (ignore force)) 3 (let* ((nodes (capi:graph-pane-nodes self)) 4 ... The CAPI graph node model uses a function that is passed a node object and returns a list of this Knowledge Graph Navigator User Interface Using LispWorks CAPI 264 node’s child node objects. There are several examples of this in the CAPI graph examples that are included with LispWorks (see the CAPI documentation). In src/lw-grapher/lw-grapher.lisp I wrote a function that builds a graph layout and instead of passing in a “return children” function I found it more convenient to wrap this process, accepting a list of graph nodes and graph edges as function arguments: 1 (in-package :lw-grapher) 2 3 ;; A Grapher (using the layout algorithm from the ISI-Grapher 4 ;; user guide) with an info panel 5 6 (defun make-info-panel-grapher (h-root-name-list h-edge-list 7 h-callback-function-click 8 h-callback-function-shift-click) 9 (let (edges roots last-selected-node node-callback-click 10 node-callback-click-shift output-pane) 11 (labels 12 ((handle-mouse-click-on-pane (pane x y) 13 (ignore-errors 14 (let ((object (capi:pinboard-object-at-position pane x y))) 15 (if object 16 (let () 17 (if last-selected-node 18 (capi:unhighlight-pinboard-object pane 19 last-selected-node)) 20 (setf last-selected-node object) 21 (capi:highlight-pinboard-object pane object) 22 (let ((c-stream (collector-pane-stream output-pane))) 23 (format c-stream 24 (funcall node-callback-click 25 (text-node-full-text object))) 26 (terpri c-stream))))))) 27 (handle-mouse-click-shift-on-pane (pane x y) 28 (ignore-errors 29 (let ((object 30 (capi:pinboard-object-at-position pane x y))) 31 (if object 32 (let () 33 (if last-selected-node 34 (capi:unhighlight-pinboard-object 35 pane last-selected-node)) 36 (setf last-selected-node object) Knowledge Graph Navigator User Interface Using LispWorks CAPI 265 37 (capi:highlight-pinboard-object pane object) 38 (let ((c-stream 39 (collector-pane-stream output-pane))) 40 (format c-stream 41 (funcall node-callback-click-shift 42 (text-node-full-text object))) 43 (terpri c-stream))))))) 44 45 (info-panel-node-children-helper (node-text) 46 (let (ret) 47 (dolist (e edges) 48 (if (equal (first e) node-text) 49 (setf ret (cons (second e) ret)))) 50 (reverse ret))) 51 52 (make-info-panel-grapher-helper 53 (root-name-list edge-list callback-function-click 54 callback-function-click-shift) 55 ;; example: root-name-list: '("n1") edge-list: 56 ;; '(("n1" "n2") ("n1" "n3")) 57 (setf edges edge-list 58 roots root-name-list 59 node-callback-click callback-function-click 60 node-callback-click-shift callback-function-click-shift) 61 (capi:contain 62 63 (make-instance 64 'column-layout 65 :title "Entity Browser" 66 :description 67 (list 68 (make-instance 'capi:graph-pane 69 :min-height 330 70 :max-height 420 71 :roots roots 72 :layout-function 'graph-layout 73 :children-function #'info-panel-node-children-helper 74 :edge-pane-function 75 #'(lambda(self from to) 76 (declare (ignore self)) 77 (let ((prop-name "")) 78 (dolist (edge edge-list) 79 (if (and Knowledge Graph Navigator User Interface Using LispWorks CAPI 266 80 (equal from (first edge)) 81 (equal to (second edge))) 82 (if (and (> (length edge) 2) (third edge)) 83 (let ((last-index 84 (search 85 "/" (third edge) 86 :from-end t))) 87 (if last-index 88 (setf prop-name 89 (subseq (third edge) 90 (1+ last-index))) 91 (setf prop-name (third edge))))))) 92 (make-instance 93 'capi:labelled-arrow-pinboard-object 94 :data (format nil "~A" prop-name)))) 95 :node-pinboard-class 'text-node 96 :input-model `(((:button-1 :release) 97 ,#'(lambda (pane x y) 98 (handle-mouse-click-on-pane 99 pane x y))) 100 ((:button-1 :release :shift) ;; :press) 101 ,#'(lambda (pane x y) 102 (handle-mouse-click-shift-on-pane 103 pane x y)))) 104 :node-pane-function 'make-text-node) 105 (setf 106 output-pane 107 (make-instance 'capi:collector-pane 108 :min-height 130 109 :max-height 220 110 :title "Message collection pane" 111 :text "..." 112 :vertical-scroll t 113 :horizontal-scroll t)))) 114 :title 115 "Info Pane Browser: mouse click for info, mouse click + shift for web browser" 116 117 :best-width 550 :best-height 450))) 118 (make-info-panel-grapher-helper h-root-name-list 119 h-edge-list h-callback-function-click 120 h-callback-function-shift-click)))) Knowledge Graph Navigator User Interface Using LispWorks CAPI 267 Wrap-up This is a long example application for a book so I did not discuss all of the code in the project. If you enjoy running and experimenting with this example and want to modify it for your own projects then I hope that I provided a sufficient road map for you to do so. I got the idea for the KGN application because I was spending quite a bit of time manually setting up SPARQL queries for DBPedia (and other public sources like WikiData) and I wanted to experiment with partially automating this process. I wrote the CAPI user interface for fun since this example application could have had similar functionality as a command line tool. Using the OpenAI APIs I have been working as an artificial intelligence practitioner since 1982 and the capability of the beta OpenAI APIs is the most impressive thing that I have seen in my career so far. These APIs use the GPT-3 model. I recommend reading the online documentation for the online documentation for the APIs¹⁰¹ to see all the capabilities of the beta OpenAI APIs. Let’s start by jumping into the example code. As seen in the package.lisp file we use the UIOP and cl-json libraries and we export three top level functions: 1 ;;;; package.lisp 2 3 (defpackage #:openai 4 (:use #:cl #:uiop #:cl-json) 5 (:export #:completions #:summarize #:answer-question)) The library that I wrote for this chapter supports three functions that are exported from the package openai: for completing text, summarizing text, and answering general questions. The single OpenAI model that the beta OpenAI APIs use is fairly general purpose and can generate cooking directions when given an ingredient list, grammar correction, write an advertisement from a product description, generate spreadsheet data from data descriptions in English text, etc. Given the examples from https://beta.openai.com¹⁰² and the Common Lisp examples here, you should be able to modify my example code to use any of the functionality that OpenAI documents. 1 ;;;; openai.asd 2 3 (asdf:defsystem #:openai 4 :description "Library for using the beta OpenAI APIs" 5 :author "Mark Watson" 6 :license "Apache 2" 7 :depends-on (#:uiop #:cl-json) 8 :components ((:file "package") 9 (:file "openai"))) We will look closely at the function completions and then just look at the small differences to the other two example functions. The definitions for all three exported functions are kept in the file openai.lisp. You need to request an API key (I had to wait a few weeks to recieve my key) and set the value of the environment variable OPENAI_KEY to your key. You can add a statement like: ¹⁰¹https://beta.openai.com/docs/introduction/key-concepts ¹⁰²https://beta.openai.com Using the OpenAI APIs 269 export OPENAI_KEY=sa-hdffds7&dhdhsdgffd to your .profile or other shell resource file. While I sometimes use pure Common Lisp libraries to make HTTP requests, I prefer running the curl utility as a separate process for these reasons: • No problems with system specific dependencies. • Use the standard library UIOP to run a shell command and capture the output as a string. • I use curl from the command line when experimenting with web services. After I get working curl options, it is very easy to translate this into Common Lisp code. An example curl command line call to the beta OpenAI APIs is: 1 curl \ 2 https://api.openai.com/v1/engines/davinci/completions \ 3 -H "Content-Type: application/json" 4 -H "Authorization: Bearer sa-hdffds7&dhdhsdgffd" \ 5 -d '{"prompt": "The President went to Congress", \ 6 "max_tokens": 22}' Here the API token “sa-hdffds7&dhdhsdgffd” on line 4 is made up - that is not my API token. All of the OpenAI APIs expect JSON data with query parameters. To use the completion API, we set values for prompt and max_tokens. The value of max_tokens is the requested number of returns words or tokens. We will look at several examples later. In the file openai.lisp we start with a helper function openai-helper that takes a string with the OpenAI API call arguments encoded as a curl command, calls the service, and then extracts the results from the returned JSON data: 1 (defun openai-helper (curl-command) 2 (let ((response 3 (uiop:run-program 4 curl-command 5 :output :string))) 6 (with-input-from-string 7 (s response) 8 (let* ((json-as-list (json:decode-json s))) 9 ;; extract text (this might change if OpenAI changes JSON return format): 10 (cdar (cadr (nth 4 json-as-list))))))) I convert JSON data to a Lisp list in line 8 and in line 10 I reach into the nested results list for the generated text string. You might want to add a debug printout statement to see the value of json-as-list. Using the OpenAI APIs 270 The three example functions all use this openai-helper function. The first example function completions sets the parameters to complete a text fragment. You have probably seen examples of the OpenAI GPT-3 model writing stories, given a starting sentence. We are using the same model and functionality here: 1 (defun completions (starter-text max-tokens) 2 (let* ((curl-command 3 (concatenate 4 'string 5 "curl " open-api-davinci-model-host 6 " -H \"Content-Type: application/json\"" 7 " -H \"Authorization: Bearer " (uiop:getenv "OPENAI_KEY") "\" " 8 " -d '{\"prompt\": \"" starter-text "\", \"max_tokens\": " 9 (write-to-string max-tokens) "}'"))) 10 (openai-helper curl-command))) Note that the OpenAI API models are stochastic. When generating output words (or tokens), the model assigns probabilities to possible words to generate and samples a word using these probabilities. As a simple example, suppose given prompt text “it fell and”, then the model could only generate three words, with probabilities for each word based on this prompt text: • the 0.9 • that 0.1 • a 0.1 The model would emit the word the 90% of the time, the word that 10% of the time, or the word a 10% of the time. As a result, the model can generate different completion text for the same text prompt. Let’s look at some examples. We request 22 output tokens (words or punctuation) in the first two examples and 100 tokens in the third example: 1 cl-user> (openai:completions "The President went to Congress" 22) 2 " yesterday and proposed a single tax rate for all corporate taxpayers, which he env\ 3 isions will be lower than what our" 4 5 cl-user> (openai:completions "The President went to Congress" 22) 6 " last month, asking for authorization of a program, which had previously been appro\ 7 ved by the Foreign Intelligence Surveillance court as" 8 9 cl-user> (openai:completions "The President went to Congress" 100) 10 " worried about what the massive unpopular bill would do to his low approvals. Democ\ 11 rats lost almost every situation to discuss any legislation about this controversial\ 12 subject. Even more so, President Obama failed and had to watch himself be attacked \ Using the OpenAI APIs 271 13 by his own party for not leading. 14 15 There were also two celebrated (in DC) pieces of student loan legislation, which aim\ 16 ed to make college cheaper. Harkin teamed up with Congressman Roddenbery on one, Stu\ 17 dent Loan Affordability Act, and Senator Jack Reed (D" 18 cl-user> The function summarize is very similar to the function completions except the JSON data passed to the API has a few additional parameters that let the API know that we want a text summary: • presence_penalty - penalize words found in the original text (we set this to zero) • temperature - higher values the randomness used to select output tokens. If you set this to zero, then the same prompt text will always yield the same results (I never use a zero value). • top_p - also affects randomness. All examples I have seen use a value of 1. • frequency_penalty - penalize using the same words repeatedly (I usually set this to zero, but you should experiment with different values) When summarizing text, try varying the number of generated tokens to get shorter or longer summaries; in the following two examples we ask for 15 output tokens and 50 output tokens: 1 (defvar s "Jupiter is the fifth planet from the Sun and the largest in the Solar Sy\ 2 stem. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-ha\ 3 lf times that of all the other planets in the Solar System combined. Jupiter is one \ 4 of the brightest objects visible to the naked eye in the night sky, and has been kno\ 5 wn to ancient civilizations since before recorded history. It is named after the Rom\ 6 an god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its ref\ 7 lected light to cast visible shadows,[20] and is on average the third-brightest natu\ 8 ral object in the night sky after the Moon and Venus.") 9 10 cl-user> (openai:summarize s 15) 11 "Jupiter is a gas giant because it is primarily composed of hydrogen" 12 13 cl-user> (openai:summarize s 50) 14 "Jupiter is a gas giant because it is predominantly composed of hydrogen and helium;\ 15 it has a solid core that is composed of heavier elements. It is the largest of the \ 16 four giant planets in the Solar System and the largest in the Solar System" The function answer-question is very similar to the function summarize except the JSON data passed to the API has one additional parameter that let the API know that we want a question answered: • stop - The OpenAI API examples use the value: [\n], which is what I use here. Additionally, the model returns a series of answers with the string “nQ:” acting as a delimiter between the answers. Using the OpenAI APIs 272 1 (let ((index (search "nQ:" answer))) 2 (if index 3 (string-trim " " (subseq answer 0 index)) 4 (string-trim " " answer))) I strongly urge you to add a debug printout to the question answering code to print the full answer before we check for the delimiter string. For some questions, the OpenAI APIs generate a series of answers that increase in generality. In the example code we just take the most specific answer. Let’s look at a few question answering examples and we will discuss possible problems and workarounds: 1 cl-user> (openai:answer-question "Where is the Valley of Kings?" 60) 2 "It's in Egypt." Let’s explore some issues with the question answering model. In the last example there is one good answer and the model works well. The next example “What rivers are in Arizona?” shows some problems because there are many rivers in Arizona. Sometimes the model misses a few rivers and often river names are repeated in the output. You also don’t necessarily get the same answer for the same input arguments. Here are three examples requesting 70, 90, and 160 output tokens: 1 cl-user> (openai:answer-question "What rivers are in Arizona?" 70) 2 "The Colorado River, the Gila River, the Little Colorado River, the Salt River, the \ 3 Verde River, the San Pedro River, the Santa Cruz River, the San Juan River, the Agua\ 4 Fria River, the Hassayampa River, the Bill Williams River, the Little Colorado Rive\ 5 r, the San Francisco River, the San Pedro River" 6 7 cl-user> (openai:answer-question "What rivers are in Arizona?" 90) 8 "The Colorado River, the Gila River, the Little Colorado River, the Salt River, the \ 9 Verde River, the San Pedro River, the Santa Cruz River, the San Juan River, the Agua\ 10 Fria River, the Hassayampa River, the Bill Williams River, the Little Colorado Rive\ 11 r, the San Francisco River, the San Pedro River, the Santa Cruz River, the San Juan \ 12 River, the Agua Fria River, the Hass" 13 cl-user> (openai:answer-question "What rivers are in Arizona?" 160) 14 "Colorado, Gila, Salt, Verde, and the Little Colorado." 15 16 cl-user> (openai:answer-question "What rivers are in Arizona?" 160) 17 "The Colorado River, the Gila River, the Little Colorado River, the Salt River, the \ 18 Verde River, the San Pedro River, the Santa Cruz River, the San Juan River, the Agua\ 19 Fria River, the Hassayampa River, the Bill Williams River, the Little Colorado Rive\ 20 r, the San Francisco River, the San Pedro River, the Santa Cruz River, the San Juan \ 21 River, the Agua Fria River, the Hassayampa River, the Bill Williams River, the Littl\ 22 e Colorado River, the San Francisco River, the San Pedro River, the Santa Cruz River\ Using the OpenAI APIs 273 23 , the San Juan River, the Agua Fria River, the Hassayampa River, the Bill Williams R\ 24 iver, the Little Colorado River, the San Francisco River, the San Pedro River, the S\ 25 anta Cruz" My library does not handle embedded single quote characters in questions so the question “Who is Bill Clinton’s wife?” will throw an error. Leaving out the single quote character works fine: 1 cl-user> (openai:answer-question "Who is Bill Clintons wife?" 120) 2 "Hillary Clinton." 3 cl-user> In addition to reading the beta OpenAI API documentation you might want to read general material on the use of OpenAI’s GPT-3 model. Since the APIs we are using are beta they may change. I will update this chapter and the source code on GitHub if the APIs change. Using the Hugging Face Deep Learning Natural Language Processing APIs TBD: this chapter is currently being written and will be completed along with other manuscript changes in Mark 2023. Accessing the HuggingFace NLP APIs is similar to the code we used previously to access the OpenAI APIs. 1 (in-package #:huggingface) 2 3 ;; define the environment variable "HF_API_TOKEN" with the value of your Hugging Fac\ 4 e API key 5 6 (defun huggingface-helper (curl-command) 7 (let ((response 8 (uiop:run-program 9 curl-command 10 :output :string))) 11 (with-input-from-string 12 (s response) 13 (let* ((json-as-list (json:decode-json s))) 14 json-as-list)))) 15 16 (defun summarize (some-text max-tokens) 17 (let* ((curl-command 18 (concatenate 19 'string 20 "curl https://api-inference.huggingface.co/models/facebook/bart-large-cnn" 21 " -H \"Content-Type: application/json\"" 22 " -H \"Authorization: Bearer " (uiop:getenv "HF_API_TOKEN") "\" " 23 " -d '{\"inputs\": \"" some-text "\", \"max_length\": " 24 (write-to-string max-tokens) " }'"))) 25 (cdaar (huggingface-helper curl-command)))) 26 27 (defun answer-question (question-text context-text) 28 (let* ((curl-command Using the Hugging Face Deep Learning Natural Language Processing APIs 275 29 (concatenate 30 'string 31 "curl https://api-inference.huggingface.co/models/deepset/roberta-base-sq\ 32 uad2" 33 " -H \"Content-Type: application/json\"" 34 " -H \"Authorization: Bearer " (uiop:getenv "HF_API_TOKEN") "\" " 35 " -d '{\"question\": \"" question-text "\", \"context\": \"" 36 context-text "\" }'")) 37 (answer (huggingface-helper curl-command))) 38 (cdar (last answer)))) 1 CL-USER> (ql:quickload :huggingface) 2 To load "huggingface": 3 Load 1 ASDF system: 4 huggingface 5 ; Loading "huggingface" 6 7 (:HUGGINGFACE) 8 CL-USER> (huggingface:summarize "Jupiter is the fifth planet from the Sun and the la\ 9 rgest in the Solar System. It is a gas giant with a mass one-thousandth that of the \ 10 Sun, but two-and-a-half times that of all the other planets in the Solar System comb\ 11 ined. Jupiter is one of the brightest objects visible to the naked eye in the night \ 12 sky, and has been known to ancient civilizations since before recorded history. It i\ 13 s named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be brig\ 14 ht enough for its reflected light to cast visible shadows,[20] and is on average the\ 15 third-brightest natural object in the night sky after the Moon and Venus." 30) 16 "Jupiter is the fifth planet from the Sun and the largest in the Solar System. When \ 17 viewed from Earth, Jupiter can be bright enough for its reflected light to cast visi\ 18 ble shadows. It is on average the third-brightest natural object in the night sky af\ 19 ter the Moon and Venus. It has been known to ancient civilizations since before reco\ 20 rded history." 21 22 "Jupiter is the fifth planet from the Sun and the largest in the Solar System. When \ 23 viewed from Earth, Jupiter can be bright enough for its reflected light to cast visi\ 24 ble shadows. It is on average the third-brightest natural object in the night sky af\ 25 ter the Moon and Venus. It has been known to ancient civilizations since before reco\ 26 rded history." 27 28 CL-USER> (huggingface:answer-question "Where were the 1992 Olympics held?" "The 1992\ 29 Summer Games were the first since the end of the Cold War, and the first unaffected\ 30 by boycotts since the 1972 Summer Games. The 1992 Olympics were in Greece. 1992 was\ 31 also the first year South Africa was re-invited to the Olympic Games by the Interna\ Using the Hugging Face Deep Learning Natural Language Processing APIs 276 32 tional Olympic Committee, after a 32-year ban from participating in international sp\ 33 ort.") 34 35 "Greece" 36 CL-USER> 1 Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data This project is inspired by the Python LangChain and LlamaIndex projects, with just the parts I need for my projects written from scratch in Common Lisp. I wrote a Python book “LangChain and LlamaIndex Projects Lab Book: Hooking Large Language Models Up to the Real World Using GPT-3, ChatGPT, and Hugging Face Models in Applications” in March 2023: https://leanpub.com/langchain¹⁰³ that you might also be interested in. The GitHub repository for this example can be found here: https://github.com/mark-watson/docs- qa¹⁰⁴. This code also requires my OpenAI Common Lisp library https://github.com/mark-wat- son/openai¹⁰⁵. Overview of Local Embeddings Vector Database to Enhance the Use of GPT3 APIs With Local Documents In this example we will use the SqLite database to store the text from documents as well as OpenAI embedding vectors for the text. Each embedding vector is 1536 floating point numbers. Two documents are semantically similar if the dot product of their embedding vectors is large. For long documents, we extract the text and create multiple chunks of text. Each chunk is stored as a row in a SqLite database table. This is an easy way to implement a vector datastore. There are many open source and commercial vector datastores if you reach performance limits with the simple techniques we use here. For each text chunk we call an OpenAI API to get an embedding vector. Later when we want to have a GPT enabled conversation or just semantically query our local documents, we take the user’s query and call an OpenAI API to get an embedding vector for the query text. We then compute the vector dot product between the query embedding vector and each chunk embedding vector. We save the text of the chunks that are semantically similar to the query embedding vector and use this text as “context text” that we pass to an OpenAI Large Language Model (LLM) API along with the user’s original query text. ¹⁰³https://leanpub.com/langchain ¹⁰⁴https://github.com/mark-watson/docs-qa ¹⁰⁵https://github.com/mark-watson/openai Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 278 What does this process really do? Normally when you query ChatGPT or similar LLMs, we are querying against knowledge gained from all the original model training text. This process can lead to so-called “model hallucinations” where the model “makes stuff up.” The advantage to the using the Python libraries LangChain and LlamaIndex is that a LLM is effectively using all original training data but is also primed with hopefully relevant context text from your local documents that might be useful for answering the user’s query. We will replicate a small amount of this functionality in Common Lisp. At the end of this chapter we will extend our code for single queries with a conversational example. Our approach to this is simple: when we pass context text and a query, we also pass previous conversational queries from the user. I am still experimenting with the ideas in this chapter so please do occasionally look for updates to the GitHub repository https://github.com/mark-watson/docs- qa¹⁰⁶ and updates to this book. Implementing a Local Vector Database for Document Embeddings In the following listing of the file docs-qa.lisp we start in lines 6-31 with a few string utility functions we will need: write-floats-to-string, read-file, concat-strings, truncate-string, and break-into- chunks. The function break-into-chunks is a work in progress. For now we simply cut long input texts into specific chunk lengths, often cutting words in half. A future improvement will be detecting sentence boundaries and breaking text on sentences. The Python libraries LangChain and LlamaIndex have multiple chunking strategies. In lines 33-37 function decode-row takes data from a SQL query to fetch a database table row and extracts the original chunk text and the embedding vector. Because of the overhead of making many calls to the OpenAI APIs the time spent running the local Common Lisp example code is very small so I have not yet worked on making my code efficient. 1 (ql:quickload :sqlite) 2 (use-package :sqlite) 3 4 ;; define the environment variable "OPENAI_KEY" with the value of your OpenAI API key 5 6 (defun write-floats-to-string (lst) 7 (with-output-to-string (out) 8 (format out "( ") 9 (loop for i in lst 10 do (format out "~f " i)) 11 (format out " )"))) ¹⁰⁶https://github.com/mark-watson/docs-qa Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 279 12 13 (defun read-file (infile) ;; from Bing+ChatGPT 14 (with-open-file (instream infile 15 :direction :input 16 :if-does-not-exist nil) 17 (when instream 18 (let ((string (make-string (file-length instream)))) 19 (read-sequence string instream) 20 string)))) 21 22 (defun concat-strings (list) 23 (apply #'concatenate 'string list)) 24 25 (defun truncate-string (string length) 26 (subseq string 0 (min length (length string)))) 27 28 (defun break-into-chunks (text chunk-size) 29 "Breaks TEXT into chunks of size CHUNK-SIZE." 30 (loop for start from 0 below (length text) by chunk-size 31 collect (subseq text start (min (+ start chunk-size) (length text))))) 32 33 (defun decode-row (row) 34 (let ((id (nth 0 row)) 35 (context (nth 1 row)) 36 (embedding (read-from-string (nth 2 row)))) 37 (list id context embedding))) The next listing shows of parts of docs-qa.lisp that contain code to use SqLite. I wrapped the calls to initialize the database inside of handler-case for convenience during development (file reloads don’t throw top level errors and the existing database is untouched). 1 (defvar *db* (connect ":memory:")) 2 ;;(defvar *db* (connect "test.db")) 3 4 (pprint *db*) 5 (handler-case 6 (progn 7 (execute-non-query 8 *db* 9 "CREATE TABLE documents (document_path TEXT, content TEXT, embedding TEXT);") 10 (execute-non-query 11 *db* 12 "CREATE INDEX idx_documents_id ON documents (document_path);") Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 280 13 (execute-non-query 14 *db* 15 "CREATE INDEX idx_documents_content ON documents (content);") 16 (execute-non-query 17 *db* 18 "CREATE INDEX idx_documents_embedding ON documents (embedding);")) 19 (error (c) 20 (print "Database and indices is already created"))) 21 22 (defun insert-document (document_path content embedding) 23 ;;(format t "insert-document:~% content:~A~% embedding: ~A~%" content embedding) 24 (format t "~%insert-document:~% content:~A~%~%" content) 25 (execute-non-query 26 *db* 27 "INSERT INTO documents (document_path, content, embedding) VALUES (?, ?, ?);" 28 document_path content (write-floats-to-string embedding))) 29 30 (defun get-document-by-document_path (document_path) 31 (mapcar #'decode-row 32 (execute-to-list *db* 33 "SELECT * FROM documents WHERE document_path = ?;" 34 document_path))) 35 36 (defun get-document-by-content (content) 37 (mapcar #'decode-row 38 (execute-to-list *db* 39 "SELECT * FROM documents WHERE content LIKE ?;" content))) 40 41 (defun get-document-by-embedding (embedding) 42 (mapcar #'decode-row 43 (execute-to-list *db* 44 "SELECT * FROM documents WHERE embedding LIKE ?;" embedding))) 45 46 (defun all-documents () 47 (mapcar #'decode-row 48 (execute-to-list *db* "SELECT * FROM documents;"))) 49 50 (defun create-document (fpath) 51 (let ((contents (break-into-chunks (read-file fpath) 200))) 52 (dolist (content contents) 53 (handler-case 54 (let ((embedding (openai::embeddings content))) 55 (insert-document fpath content embedding)) Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 281 56 (error (c) 57 (format t "Error: ~&~a~%" c)))))) Using Local Embeddings Vector Database With OpenAI GPT APIs The next listing showing of parts of docs-qa.lisp interfaces with the OpenAI APIs: 1 (defun qa (question) 2 (let ((answer (openai:answer-question question 60))) 3 (format t "~&~a~%" answer))) 4 5 (defun semantic-match (query custom-context &optional (cutoff 0.7)) 6 (let ((emb (openai::embeddings query)) 7 (ret)) 8 (dolist (doc (all-documents)) 9 (let ((context (nth 1 doc)) ;; ignore fpath for now 10 (embedding (nth 2 doc))) 11 (let ((score (openai::dot-product emb embedding))) 12 (when (> score cutoff) 13 (push context ret))))) 14 (format t "~%semantic-search: ret=~A~%" ret) 15 (let* ((context (join-strings " . " (reverse ret))) 16 (query-with-context 17 (join-strings 18 " " 19 (list context custom-context 20 "Question:" query)))) 21 (openai:answer-question query-with-context 40)))) 22 23 (defun QA (query &optional (quiet nil)) 24 (let ((answer (semantic-match query ""))) 25 (if (not quiet) 26 (format t "~%~%** query: ~A~%** answer: ~A~%~%" query answer)) 27 answer)) Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 282 Testing Local Embeddings Vector Database With OpenAI GPT APIs In the next part of the listing of docs-qa.lisp we write a test function to create two documents. The two calls to create-document actually save text and embeddings for about 20 text chunks in the database. 1 (defun test() 2 "Test code for Semantic Document Search Using 3 OpenAI GPT APIs and local vector database" 4 (create-document "data/sports.txt") 5 (create-document "data/chemistry.txt") 6 (QA "What is the history of the science of chemistry?") 7 (QA "What are the advantages of engainging in sports?")) The output is (with a lot of debug printout not shown): 1 $ sbcl 2 * (quicklisp:quickload :docs-qa) 3 To load "docs-qa": 4 Load 1 ASDF system: 5 docs-qa 6 ; Loading "docs-qa" 7 .................................................. 8 [package docs-qa]To load "sqlite": 9 Load 1 ASDF system: 10 sqlite 11 ; Loading "sqlite" 12 13 # 14 (:docs-qa) 15 * (in-package :docs-qa) 16 # 17 * (test) 18 19 ** query: What is the history of the science of chemistry? 20 ** answer: The history of chemistry as a science began in the 6th century BC, when t\ 21 he Greek philosopher Leucippus and his student Democritus posited the existence of a\ 22 n endless number of worlds 23 24 ** query: What are the advantages of engainging in sports? Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 283 25 ** answer: The advantages of engaging in sports are:n1. It helps to develop the body\ 26 and mind.n2. It helps to develop the character.n3. It helps to develop the personal\ 27 ity. Adding Chat History In the last part of the listing of docs-qa.lisp we experiment with supporting a conversation/chat of multiple semantic queries against our local documents. 1 (defun CHAT () 2 (let ((messages '("")) 3 (responses '(""))) 4 (loop 5 (format t "~%Enter chat (STOP or empty line to stop) >> ") 6 (let ((string (read-line)) 7 response) 8 (cond ((or (string= string "STOP") (< (length string) 1)) (return)) 9 (t (let (prompt 10 custom-context) 11 (setf custom-context 12 (concatenate 13 'string 14 "PREVIOUS CHAT: " 15 (join-strings " " 16 (reverse messages)))) 17 (push string messages) 18 (print messages) ;; (print responses) 19 (print prompt) 20 (setf response (semantic-match string custom-context)) 21 (push response responses) 22 (format t "~%Response: ~A~%" response)))))) 23 (list (reverse messages) (reverse responses)))) The output (with lots of debug printouts removed) looks like: Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 284 1 $ sbcl 2 * (quicklisp:quickload :docs-qa) 3 To load "docs-qa": 4 Load 1 ASDF system: 5 docs-qa 6 ; Loading "docs-qa" 7 .................................................. 8 [package docs-qa].To load "sqlite": 9 Load 1 ASDF system: 10 sqlite 11 ; Loading "sqlite" 12 # 13 * (in-package :docs-qa) 14 # 15 * (create-document "data/chemistry.txt") 16 17 insert-document: 18 content:Amyl alcohol is an organic compound with the formula C 5 H 12 O. All eight\ 19 isomers of amyl alcohol are known. The most important is isobutyl carbinol, this be\ 20 ing the chief constituent of fermentation 21 ;; output from all other document chunks is not shown 22 23 * (CHAT) 24 25 Enter chat (STOP or empty line to stop) >> what is the history of chemistry? 26 27 Response: Chemistry is the science of matter, its composition, structure and its pro\ 28 perties. Chemistry is concerned with atoms and their interactions with other atoms, \ 29 and thus is central to all other sciences. Chemistry is also concerned 30 31 Enter chat (STOP or empty line to stop) >> what is the boiling temperature? 32 33 Response: The boiling temperature of a liquid is the temperature at which the vapor \ 34 pressure of the liquid equals the pressure surrounding the liquid, and the liquid ch\ 35 anges into a vapor. At the boiling temperature, bubbles of vapor 36 37 Enter chat (STOP or empty line to stop) >> Using a Local Document Embeddings Vector Database With OpenAI GPT3 APIs for Semantically Querying Your Own Data 285 Wrap Up for Using Local Embeddings Vector Database to Enhance the Use of GPT3 APIs With Local Documents As I write this in early April 2023, I have been working almost exclusively with OpenAI APIs for the last year and using the Python libraries for LangChain and LlamaIndex for the last three months. I prefer using Common Lisp over Python when I can, so I am implementing a tiny subset of the LangChain and LlamaIndex libraries in Common Lisp for my own use. By writing about my Common Lisp experiments here I hope that I get pull requests for https://github.com/mark- watson/docs-qa¹⁰⁷ from readers who are interested in helping to extend the Common Lisp library. ¹⁰⁷https://github.com/mark-watson/docs-qa Prompt Engineering for Large Language Models We have been using prompt engineering in an informal way in the last few chapters. In this chapter we look at prompt engineering in more detail. My hope is that, dear reader, you find this chapter to be both a short reference for Large Language Models (LLMS) and a useful source of prompt examples at the end of the chapter. Two Types of LLMS In order to avoid “model hallucinations” (i.e., models making up answers with no basis in fact) when using Large Language Models (LLMS) it is important to explain in detail instructions and add context text to help the model better answer questions of solve problems. Base LLMs and Instruction Tuned LLMs are both types of advanced AI language models. While they share some similarities in their underlying architecture and training processes, they have distinct differences in terms of their fine-tuning and usage. Here, we will discuss the similarities and differences in detail. The similarities are: • Architecture: Both models are based on the Transformer architecture, which has been shown to be highly effective for various natural language processing tasks. This architecture relies on self-attention mechanisms to process input data and generate outputs. • Pretraining: Both models undergo a pretraining phase where they learn from a large corpus of text, such as websites, books, and articles. This helps the models acquire a general understanding of language, grammar, facts, and some reasoning abilities. • Transfer learning: Both models can use transfer learning, which involves fine-tuning the pretrained models on specific tasks or datasets. This process adapts the model’s general knowledge to the target application, improving its performance on the desired task. The differences are: • Fine-tuning objectives: The key difference between the two models lies in their fine-tuning process. Base Large Language Models are fine-tuned to generate human-like text with minimal explicit guidance, whereas Instruction Tuned Large Language Models are specifically optimized to follow instructions provided in the input prompt. Prompt Engineering for Large Language Models 287 • Task performance: Due to their different fine-tuning objectives, Instruction Tuned Large Language Models tend to perform better on tasks that require following explicit instructions, while Base Large Language Models may produce more diverse and creative responses that may not always adhere to the given instructions. • Usage: Base Large Language Models can be used for a wide variety of tasks, including text generation, summarization, translation, and question-answering. Instruction Tuned Large Language Models, on the other hand, are designed to be more controllable and responsive to input instructions, making them more suitable for applications that require precise output based on specific instructions. • Prompt engineering: To get the desired output from a Base Large Language Model, users often need to carefully craft prompts, which can be a trial-and-error process. With Instruction Tuned Large Language Models, users can provide more explicit instructions to achieve the desired output more consistently. In summary, both Base and Instruction Tuned Large Language Models share the same foundation in terms of architecture and pretraining but differ in their fine-tuning objectives and application strengths. While Base Large Language Models generate more diverse and creative text, Instruction Tuned Large Language Models excel at tasks that require following specific instructions and are more controllable. Prompt Examples We have used both OpenAI and Hugging Face Models so far in this book. When you practice prompt engineering and learn new techniques, your knowledge of prompt engineering can be applied to the OpenAI and Hugging Face APIs and models. As Andrew Ng and Isa Fulford point out in their one hour class ChatGPT Prompt Engineering for Developers¹⁰⁸, you can craft prompts as if you were instructing an intelligent person who is not necessarily familiar with the current problem you are trying to solve with prompt engineering. There is a bit of a tradeoff here: you pay per input and output tokens with the OpenAI APIs so you may be tempted to compress your context text, instructions, and questions when creating prompts. However, in general to more context and information you can provide increases the quality of the resulting output. The following sections show examples of prompt engineering that I use in my own work. In order to learn more techniques I recommend also performing web search for prompt engineering with a description of the problem you are working on. As an example, I asked Microsoft Bing+ChatGPT in a chat to help me with I need help with prompt engineering using the OpenAI APIs. My problem is: I have a text file that contains customer names and phone numbers. I need a prompt to list names and phone numbers. and the advice was a useful starting point. In a similar way I received useful advice when chatting with Google Bard. ¹⁰⁸https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson Prompt Engineering for Large Language Models 288 Find Entities and Relationships Prompt: 1 The task is to extract as many relevant entities and the relationships between these\ 2 entities.\n 3 When possible, return the type of an entity using the Wikipedia class system.\n 4 Extract all relevant relationships between identified entities.\n 5 The relationships should follow the Wikipedia schema type. 6 The output of a relationship should be in a form of a triple Head, Relationship, Tai\ 7 l, for example 8 Bill Gates, BORN_AT, Seatle.\n 9 As an example "Bill Gates worked at Microsoft" should have an output with the follow\ 10 ing format:\n 11 entity 12 Bill Gates, person 13 Microsoft, organization 14 15 relationships 16 Bill Gates, WORKET AT, Microsoft\n 17 Task: process this text: 18 Steve Jobes founded Apple Computer and Bill Gates started Microsoft. Seattle is in t\ 19 he state of Washington. 20 Steve lived in Palo Alto. Palo Alto is located in California. ChatGPT 4 returns: 1 entities 2 Steve Jobs, person 3 Apple Computer, organization 4 Bill Gates, person 5 Microsoft, organization 6 Seattle, city 7 Washington, administrative territorial entity 8 9 relationships 10 Steve Jobs, FOUNDED, Apple Computer 11 Bill Gates, FOUNDED, Microsoft 12 Seattle, IS_IN, Washington Disambiguate Relationship Names Prompt: Prompt Engineering for Large Language Models 289 1 Given a list of relationships like: 2 3 brother 4 located in 5 sister 6 sibling 7 found at 8 father 9 location 10 mother 11 relative 12 13 Then return a list with an index for each unique relationship, like: 14 15 brother, 1 16 located in, 2 17 sister, 1 18 sibling, 1 19 found at, 2 20 father, 1 21 location, 2 22 mother, 1 23 relative, 1 24 25 Task: process the following text: 26 27 Sam has a brother Mike. Suzy has a sister Sally. Suszy ahs a mother Jill, and a fath\ 28 er Bill. 29 Mike is in San Diego. Sam is located is Oakland. Suzy's family all live in Los Angel\ 30 es. ChatGPT 4 results are: 1 Based on the provided list of relationships, here is the processed text with an inde\ 2 x for each unique relationship: 3 4 Sam has a brother Mike. (brother, 1) 5 Suzy has a sister Sally. (sister, 1) 6 Suzy has a mother Jill, and a father Bill. (mother, 1; father, 1) 7 Mike is in San Diego. (located in, 2) 8 Sam is located in Oakland. (located in, 2) 9 Suzy's family all live in Los Angeles. (location, 2) 10 Prompt Engineering for Large Language Models 290 11 Here, relationships like "brother," "sister," "mother," and "father" are assigned an\ 12 index of 1, while relationships like "located in" and "location" are assigned an in\ 13 dex of 2. Disambiguate Relationship Names and Rewrite Text Prompt: 1 We want to disambiguate relationship names and then rewrite text using canonical rel\ 2 ationship names. 3 4 Given a list of relationships like: 5 6 brother 7 located in 8 sister 9 sibling 10 found at 11 father 12 location 13 mother 14 relative 15 16 Then generate a list with an index for each unique relationship, like: 17 18 brother, 1 19 located in, 2 20 sister, 1 21 sibling, 1 22 found at, 2 23 father, 1 24 location, 2 25 mother, 1 26 relative, 1 27 28 And then rewrite the original text with the relation indices. 29 30 Task: process the following text: 31 32 Sam has a brother Mike. Suzy has a sister Sally. Suszy ahs a mother Jill, and a fath\ 33 er Bill. 34 Mike is in San Diego. Sam is located is Oakland. Suzy's family all live in Los Angel\ 35 es. Prompt Engineering for Large Language Models 291 The ChatGPT 4 output is: 1 First, we create the indexed list of unique relationships: 2 3 brother, 1 4 located in, 2 5 sister, 1 6 sibling, 1 7 found at, 2 8 father, 1 9 location, 2 10 mother, 1 11 relative, 1 12 13 Now, we rewrite the original text using the relation indices: 14 15 Sam has a 1 Mike. Suzy has a 1 Sally. Suszy has a 1 Jill, and a 1 Bill. 16 Mike is 2 San Diego. Sam is 2 Oakland. Suzy's family all 2 Los Angeles. In the first sentence Sam has a 1 Mike the number 1 refers to brother. Disambiguate Relationship Names and Rewrite Text, Only Output Rewritten Text Here we output just results in JSON format. Prompt: 1 We want to disambiguate relationship names and then rewrite text using canonical rel\ 2 ationship names. 3 4 Given a list of relationships like: 5 6 brother 7 located in 8 sister 9 sibling 10 found at 11 father 12 location 13 mother 14 relative 15 Prompt Engineering for Large Language Models 292 16 Then generate a list with an index for each unique relationship, like: 17 18 brother, <1> 19 located in, <2> 20 sister, <1> 21 sibling, <1> 22 found at, <2> 23 father, <1> 24 location, <2> 25 mother, <1> 26 relative, <1> 27 28 And then rewrite the original text using the relation indices, and list relation nam\ 29 es with indices. Only output rewritten text and names with indices. 30 31 Task: process the following text outputing JSON format: 32 33 Sam has a brother Mike. Suzy has a sister Sally. Suzy has a mother Jill, and a fathe\ 34 r Bill. 35 Mike is in San Diego. Sam is located is Oakland. Suzy's family all live in Los Angel\ 36 es. The ChatGPT 4 output is: 1 { 2 "relationships": { 3 "brother": "<1>", 4 "located in": "<2>", 5 "sister": "<1>", 6 "sibling": "<1>", 7 "found at": "<2>", 8 "father": "<1>", 9 "location": "<2>", 10 "mother": "<1>", 11 "relative": "<1>" 12 }, 13 "rewritten_text": "Sam has a brother Mike. Suzy has a sister Sally. Suzy has a mot\ 14 her Jill, and a father Bill.\nMike is <2> San Diego. Sam is <2> Oakland. Suzy's fami\ 15 ly all live <2> Los Angeles." 16 } Prompt Engineering for Large Language Models 293 Topic Modeling for Document Classification In this example we show a complete template that includes document text. To use this in your programs, replace the document text with a token string that you can replace with the text for the document you are topic modeling. Prompt: 1 Topic modeling involves reading text and assigning a topic name (also known as a doc\ 2 ument classification). 3 The topics that you know how to classify are: 4 5 sports 6 health 7 chemistry 8 economy 9 politics 10 11 The output format will be: 12 13 Known topics: 14 Topic: 15 16 Task: what is the best topic name for the following text: 17 18 John and Sam went to the playing field yesterday. Sam sprained his ankle. The result is: 1 Known topics: sports, health, chemistry, economy, politics 2 3 Topic: sports In this prompt template, I used placeholder document text John and Sam went to the playing field yesterday. Sam sprained his ankle. that you would replace with the longer text from the document you want to determine the topic or classification of. In this template, I like to ask the LLM to repeat the list of topics (or classifications) it knows. Prompt Engineering Wrapup When you experiment with the examples in this chapter you can both use the ChatGPT web interface to modify and develop prompts and you can also revisit the chapter on OpenAI APIs and experiment Prompt Engineering for Large Language Models 294 with prompts programmatically. My personal preference is to perform initial experiments with the ChatGPT web interface but to do most of the iterative prompt development in Emacs with a SLIME REPL. I mentioned earlier Andrew Ng’s and Isa Fulford’s one hour prompt engineering class. The devote time and provide good advice on interactive developement. Their examples use the Python language. Using Common Lisp with Wolfram/One If you use Wolfram/One¹⁰⁹ then the material in this short chapter may interest you. The interface that I wrote is simple: I use uiop:run-program to spawn a new process to run the Wolfram Language command line tool that writes results to a temporary file. I then use uiop:read-file-string to read the results and parse them into a convenient form for use. Before we build and use an interface to Wolfram/One, let’s look at two screen shots of the Wolfram/One interface with examples that we will run later in Common Lisp. The first example finds entities in text: Using Wolfram/One to find entities in text The second example uses a deep learning model to answer a question given text containing the answer to the question: Using Wolfram/One to answer natural language questions Here is the package.lisp file for this example: ¹⁰⁹https://www.wolfram.com/wolfram-one/ Using Common Lisp with Wolfram/One 296 1 (defpackage #:wolfram 2 (:use #:cl #:uiop) 3 (:export #:wolfram #:cleanup-lists 4 #:find-answer-in-text #:entities)) And the wolfram.asd file: 1 (asdf:defsystem #:wolfram 2 :description "Wolfram Language interface experiments" 3 :author "Mark Watson " 4 :license "Apache 2" 5 :depends-on (#:uiop #:cl-json #:myutils) 6 :components ((:file "package") 7 (:file "wolfram"))) The implementation in Wolfram.lisp is simple enough. In lines 6-8 I create a Common Lisp path object in /tmp (and absolute pathname is required) and then use file-namestring to get just the file name as a string. In lines 8-10 we are creating an operating system shell and running the Wolfram Language command line tool with arguments to execute the query and write the results to the temporary file. In lines 11-15 we read the contents of the temporary file, delete the file, and decode the returned string as JSON data. The Data returned form calling the Wolfram Language command line tool contains excess structure that we don’t need (a sample of the raw returned data is shown later) so the function cleanup-lists shown in lines 17-19 discards heads of lists when the first value in a list or sublist is Rule or List. The function recursive-remove seen in lines 20-24 will remove all occurrences of an item from a nested list. 1 (in-package #:wolfram) 2 3 ;; General query utilities 4 5 (defun wolfram (statement) 6 (let ((temp-file-path 7 (file-namestring (uiop:tmpize-pathname "/tmp/wolfram")))) 8 (uiop:run-program (concatenate 'string "wolframscript -code 'Export[\"" 9 temp-file-path "\"," statement 10 ",\"ExpressionJSON\"]'")) 11 (let* ((ret (uiop:read-file-string temp-file-path))) 12 (delete-file temp-file-path) 13 (with-input-from-string (s (myutils:replace-all 14 (myutils:replace-all ret "\"'" "\"") "'\"" "\"")) 15 (json:decode-json s))))) Using Common Lisp with Wolfram/One 297 16 17 (defun cleanup-lists (r) 18 (cdr (recursive-remove "Rule" (recursive-remove "List" r)))) 19 20 (defun recursive-remove (item tree) 21 (if (atom tree) 22 tree 23 (mapcar (lambda (nested-list) (recursive-remove item nested-list)) 24 (remove item tree :test #'equal)))) 25 26 ;; Higher level utilities for specific types of queries 27 28 (defun entities (text) 29 (let* ((noquotes (myutils:replace-all (myutils:replace-all text "\"" " ") "'" " ")) 30 (query2 31 (concatenate 32 'string "TextCases['" noquotes 33 "', {'City', 'Country', 'Date', 'Person'} ->" 34 " {'String', 'Interpretation', 'Probability'}]")) 35 (query (myutils:replace-all query2 "'" "\""))) 36 (remove-if #'(lambda (a) (null (cadr a))) 37 (cleanup-lists (wolfram query))))) 38 39 (defun find-answer-in-text (text question) 40 (let* ((nqtext (myutils:replace-all (myutils:replace-all text "\"" " ") "'" " ")) 41 (nqquestion (myutils:replace-all 42 (myutils:replace-all question "\"" " ") "'" " ")) 43 (query2 (concatenate 'string "FindTextualAnswer['" nqtext 44 "', '" nqquestion "']")) 45 (query (myutils:replace-all query2 "'" "\""))) 46 (wolfram query))) The last two functions in the last code listing, entities and find-answer-in-text are higher level functions intended to work with the Wolfram Language procedures TextCases (see Wolfram documentation for TextCases¹¹⁰) and FindTextualAnswer (see Wolfram documentation for Find- TextualAnswer¹¹¹). The functions cleanup-lists and recursive-remove can be used to clean up results. First, we will just call function wolfram and show the raw results: ¹¹⁰https://reference.wolfram.com/language/ref/TextCases.html ¹¹¹https://reference.wolfram.com/language/ref/FindTextualAnswer.html Using Common Lisp with Wolfram/One 298 1 $ sbcl 2 * (ql:quickload "wolfram") 3 To load "wolfram": 4 Load 1 ASDF system: 5 wolfram 6 ; Loading "wolfram" 7 [package myutils]................................. 8 [package wolfram] 9 ("wolfram") 10 * (setf example "TextCases['NYC, Los Angeles, and Chicago are the largest cities in \ 11 the USA in 2018 according to Pete Wilson.', {'City', 'Country', 'Date', 'Person'} ->\ 12 {'String', 'Interpretation', 'Probability'}]") 13 "TextCases['NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018 \ 14 according to Pete Wilson.', {'City', 'Country', 'Date', 'Person'} -> {'String', 'Int\ 15 erpretation', 'Probability'}]" 16 * (setf example-str (myutils:replace-all example "'" "\"")) 17 "TextCases[\"NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018\ 18 according to Pete Wilson.\", {\"City\", \"Country\", \"Date\", \"Person\"} -> {\"St\ 19 ring\", \"Interpretation\", \"Probability\"}]" 20 * (setf results (wolfram:wolfram example-str)) 21 * (pprint results) 22 23 ("Association" 24 ("Rule" "City" 25 ("List" 26 ("List" "NYC" ("Entity" "City" ("List" "NewYork" "NewYork" "UnitedStates")) 27 0.75583166) 28 ("List" "Los Angeles" 29 ("Entity" "City" ("List" "LosAngeles" "California" "UnitedStates")) 30 0.84206486) 31 ("List" "Chicago" 32 ("Entity" "City" ("List" "Chicago" "Illinois" "UnitedStates")) 33 0.91092855))) 34 ("Rule" "Country" 35 ("List" ("List" "USA" ("Entity" "Country" "UnitedStates") 0.9285077))) 36 ("Rule" "Date" 37 ("List" 38 ("List" "2018" ("DateObject" ("List" 2018) "Year" "Gregorian" -7.0) 39 0.8364356))) 40 ("Rule" "Person" 41 ("List" 42 ("List" "Pete Wilson" ("Entity" "Person" "PeteWilson::s7259") 0.9274548)))) 43 * Using Common Lisp with Wolfram/One 299 Now we clean up the output: 1 * (defvar results-cleaned (wolfram:cleanup-lists results)) 2 * (pprint results-cleaned) 3 4 (("City" 5 (("NYC" ("Entity" "City" ("NewYork" "NewYork" "UnitedStates")) 0.75583166) 6 ("Los Angeles" ("Entity" "City" ("LosAngeles" "California" "UnitedStates")) 7 0.84206486) 8 ("Chicago" ("Entity" "City" ("Chicago" "Illinois" "UnitedStates")) 9 0.91092855))) 10 ("Country" (("USA" ("Entity" "Country" "UnitedStates") 0.9285077))) 11 ("Date" (("2018" ("DateObject" (2018) "Year" "Gregorian" -7.0) 0.8364356))) 12 ("Person" (("Pete Wilson" ("Entity" "Person" "PeteWilson::s7259") 0.9274548)))) 13 * Next we will try the two higher-level utility functions. The first example shows finding entities in text: 1 CL-USER 21 > (pprint 2 (wolfram:entities "Sedona Arizona is home to Mark Louis Watson")) 3 4 (("City" 5 (("Sedona" ("Entity" "City" ("Sedona" "Arizona" "UnitedStates")) 0.8392784))) 6 ("Person" (("Mark Louis Watson" "Mark Louis Watson" 0.9023427)))) The second example uses a Wolfram pre-trained deep learning model for question answering: 1 CL-USER 22 > (pprint 2 (wolfram::find-answer-in-text "International Business Machines Corpor\ 3 ation (IBM) is an American multinational technology company headquartered in Armonk,\ 4 New York, with operations in over 170 countries. The company began in 1911, founded\ 5 in Endicott, New York, as the Computing-Tabulating-Recording Company (CTR) and was \ 6 renamed \"International Business Machines\" in 1924. IBM is incorporated in New York\ 7 ." 8 "where is IBM is headquartered?")) 9 10 "Armonk, New York" If you use Wolfram/One then these examples should get you started wrapping other Wolfram Language functionality for use in your Common Lisp applications. Book Wrapup Congratulations for finishing this book! I love programming in Lisp languages with concise code and a bottom-up approach to development. I hope you now also share this enthusiasm with me. Common Lisp is sometimes criticised as not having as many useful libraries as some newer languages like Python and Java, and this is a valid criticism. That said, I hope the wide variety of examples in this book will convince you that Common Lisp is a good choice for many types of programming projects. I would like to thank you for reading my book and I hope that you enjoyed it. As I mentioned in the Introduction I have been using Common Lisp since the mid-1980s, and other Lisp dialects for longer than that. I have always found something almost magical developing in Lisp. Being able to extend the language with macros and using the development technique of building a mini-language in Lisp customized for an application enables programmers to be very efficient in their work. I have usually found that this bottom-up development style helps me deal with software complexity because the lower level functions tend to get well tested while the overall system being developed is not yet too complex to fully understand. Later in the development process these lower level functions and utilities almost become part of the programming language and the higher level application logic is easier to understand because you have fewer lines of code to fit inside your head during development. I think that unless a programmer works in very constrained application domains, it often makes sense to be a polyglot programmer. I have tried, especially in the new material for this fourth edition, to give you confidence that Common Lisp is good for both general software development language and also as “glue” to tie different systems together. Thank you for buying and reading my book! Mark Watson ================================================ FILE: embedchain_test/process_pdfs.py ================================================ # https://github.com/embedchain/embedchain from embedchain import App import os test_chat = App() my_books_dir = "./data/" for filename in os.listdir(my_books_dir): if filename.endswith('.pdf'): print("processing filename:", filename) test_chat.add(os.path.join(my_books_dir, filename)) ================================================ FILE: embedchain_test/requirements.txt ================================================ embedchain=0.1.123 ================================================ FILE: extraction/README.md ================================================ # Extraction from text ================================================ FILE: extraction/person_data.py ================================================ import openai from openai import OpenAI import os openai.api_key = os.getenv("OPENAI_API_KEY") client = OpenAI() # Read the prompt from a text file with open('prompt.txt', 'r') as file: prompt_template = file.read() # Substitute a string variable into the prompt input_text = "Mark Johnson enjoys living in Berkeley California at 102 Dunston Street and use mjess@foobar.com for contacting him." prompt = prompt_template.replace("input_text", input_text) # Use the OpenAI completion API to generate a response with GPT-4 completion = client.chat.completions.create( model="gpt-4", messages=[ { "role": "user", "content": prompt, }, ], ) print(completion.choices[0].message.content) ================================================ FILE: extraction/prompt.txt ================================================ Given the two examples below, extract the names, addresses, and email addresses of individuals mentioned later as Process Text. Format the extracted information in JSON, with keys for "name", "address", and "email". If any information is missing, use "null" for that field. Example 1: Text: "John Doe lives at 1234 Maple Street, Springfield. His email is johndoe@example.com." Output: { "name": "John Doe", "address": "1234 Maple Street, Springfield", "email": "johndoe@example.com" } Example 2: Text: "Jane Smith has recently moved to 5678 Oak Avenue, Anytown. She hasn't updated her email yet." Output: { "name": "Jane Smith", "address": "5678 Oak Avenue, Anytown", "email": null } Process Text: "{input_text}" Output: ================================================ FILE: from_langchain_docs/README.md ================================================ pip install -U langchain-openai pip install -U langchain-community pip install langchainhub Note: I no longer use Serp so I have not checked the search example recently. # new example using OpenAI model gpt-4o released May 13, 2024 python gpt_4o_test.py ================================================ FILE: from_langchain_docs/gpt_4o_test.py ================================================ from langchain_core.messages import HumanMessage, SystemMessage from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-4o") # gpt-4o-mini is less expensive and almost as good messages = [ SystemMessage(content="You're a helpful assistant"), HumanMessage(content="What is the purpose of model regularization? Be concise."), ] results = llm.invoke(messages) print(results.content) print("\n\n\n") print(results) ================================================ FILE: from_langchain_docs/memory_langchain_test.py ================================================ # Derived from: # https://langchain.readthedocs.io/en/latest/modules/memory/examples/adding_memory.html # with slight modifications. from langchain.chains.conversation.memory import ConversationBufferMemory from langchain import OpenAI, LLMChain, PromptTemplate template = """You are a chatbot having a conversation with a human. {chat_history} Human: {human_input} Chatbot:""" prompt = PromptTemplate( input_variables=["chat_history", "human_input"], template=template ) memory = ConversationBufferMemory(memory_key="chat_history") llm_chain = LLMChain( llm=OpenAI(), prompt=prompt, verbose=True, memory=memory, ) print(llm_chain.predict(human_input="Hi there my friend. What is your name?")) print(llm_chain.predict(human_input="My name is Mark. How are you?")) print(llm_chain.predict(human_input="What do you have planned for today?")) ================================================ FILE: from_langchain_docs/requirements.txt ================================================ langchain_core langchain_openai langchain_community ================================================ FILE: from_langchain_docs/search_simple.py ================================================ # make sure SERPER_API_KEY is set in your environment from langchain_community.utilities import GoogleSerperAPIWrapper search_helper = GoogleSerperAPIWrapper() def search(query): return search_helper.run(query) print(search("What is the capital of Arizona?")) #print(search("Sedona Arizona?")) ================================================ FILE: google_drive_llm/.gitignore ================================================ client_secrets.json clie*.json ================================================ FILE: google_drive_llm/README.md ================================================ # Setup Follow directions in the book to set up Google app authentication. # run ``` python fetch_txt_files.py python index_and_QA.py ``` Note: I added a directory langchain-book-examples/google_drive_llm/data that you can use if you don't want to set up Google auth, and ust want to try running index_and_QA.py ================================================ FILE: google_drive_llm/data/sports.txt ================================================ Sport is generally recognised as activities based in physical athleticism or physical dexterity.[3] Sports are usually governed by rules to ensure fair competition and consistent adjudication of the winner. "Sport" comes from the Old French desport meaning "leisure", with the oldest definition in English from around 1300 being "anything humans find amusing or entertaining".[4] Other bodies advocate widening the definition of sport to include all physical activity and exercise. For instance, the Council of Europe include all forms of physical exercise, including those completed just for fun. ================================================ FILE: google_drive_llm/fetch_txt_files.py ================================================ from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from pathlib import Path # good GD search docs: https://developers.google.com/drive/api/guides/search-files#all # Authenticate with Google gauth = GoogleAuth() gauth.LocalWebserverAuth() drive = GoogleDrive(gauth) drive = GoogleDrive(gauth) def get_txt_files(dir_id='root'): " get all plain text files with .txt extension in top level Google Drive directory " file_list = drive.ListFile({'q': f"'{dir_id}' in parents and trashed=false"}).GetList() for file1 in file_list: print('title: %s, id: %s' % (file1['title'], file1['id'])) return [[file1['title'], file1['id'], file1.GetContentString()] for file1 in file_list if file1['title'].endswith(".txt")] def create_test_file(): " not currently used, but useful for testing. " # Create GoogleDriveFile instance with title 'Hello.txt': file1 = drive.CreateFile({'title': 'Hello.txt'}) file1.SetContentString('Hello World!') file1.Upload() def test(): fl = get_txt_files() for f in fl: print(f) file1 = open("data/" + f[0],"w") file1.write(f[2]) file1.close() if __name__ == '__main__': test() ================================================ FILE: google_drive_llm/index_and_QA.py ================================================ # make sure you set the following environment variable is set: # OPENAI_API_KEY from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader documents = SimpleDirectoryReader('data').load_data() index = GPTSimpleVectorIndex(documents) # save to disk index.save_to_disk('index.json') # load from disk index = GPTSimpleVectorIndex.load_from_disk('index.json') # search for a document print(index.query("What is the definition of sport?")) ================================================ FILE: google_drive_llm/requirements.txt ================================================ pydrive ================================================ FILE: hugging_face/README.md ================================================ # Using local models pip install -U torch langchain transformers llama_index For CPU only, this speeds things up: pip install xformers ================================================ FILE: hugging_face/hf_transformer_local.py ================================================ # Derived from example: # https://gpt-index.readthedocs.io/en/latest/how_to/custom_llms.html import time import torch from langchain.llms.base import LLM from llama_index import SimpleDirectoryReader, LangchainEmbedding from llama_index import ListIndex, PromptHelper from llama_index import LLMPredictor from transformers import pipeline max_input_size = 512 num_output = 64 max_chunk_overlap = 0 # 10 prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap) class CustomLLM(LLM): model_name = "facebook/opt-iml-1.3b" # I am not using a GPU, but you can add device="cuda:0" # to the pipeline call if you have a local GPU or # are running this on Google Colab: pipeline = pipeline("text-generation", model=model_name, model_kwargs={"torch_dtype":torch.bfloat16}) def _call(self, prompt, stop = None): prompt_length = len(prompt) response = self.pipeline(prompt, max_new_tokens=num_output) first_response = response[0]["generated_text"] # only return newly generated tokens returned_text = first_response[prompt_length:] return returned_text @property def _identifying_params(self): return {"name_of_model": self.model_name} @property def _llm_type(self): return "custom" time1 = time.time() # define our LLM llm_predictor = LLMPredictor(llm=CustomLLM()) # Load the your data documents = SimpleDirectoryReader('../data_small').load_data() # llama_index < 0.5: #index = GPTListIndex(documents, llm_predictor=llm_predictor, # prompt_helper=prompt_helper) # llama_index >= 0.5: (not yet working) index = ListIndex.from_documents(documents=documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper) #index = index.from_documents(documents) index = index.as_query_engine(llm_predictor=llm_predictor) time2 = time.time() print(f"Time to load model from disk: {time2 - time1} seconds.") print(dir(index)) # Query and print response response = index.query("What is the definition of sport?") print(response) time3 = time.time() print(f"Time for query/prediction: {time3 - time2} seconds.") ================================================ FILE: hugging_face/requirements.txt ================================================ numpy==1.22.0 llama-index==0.10.13 sentence-transformers ================================================ FILE: hugging_face/simple_example.py ================================================ from langchain import HuggingFaceHub, LLMChain from langchain.prompts import PromptTemplate hub_llm = HuggingFaceHub( repo_id='google/flan-t5-xl', model_kwargs={'temperature':1e-6} ) prompt = PromptTemplate( input_variables=["name"], template="What year did {name} get elected as president?", ) llm_chain = LLMChain(prompt=prompt, llm=hub_llm) print(llm_chain.run("George Bush")) ================================================ FILE: hugging_face/test1.py ================================================ # pip install xformers from llama_index import ListIndex, SimpleDirectoryReader, set_global_service_context from langchain.embeddings.huggingface import HuggingFaceEmbeddings # from llama_index import LangchainEmbedding, ServiceContext from langchain.embeddings.huggingface import HuggingFaceEmbeddings from llama_index import ServiceContext from transformers import pipeline import time import torch from langchain.llms.base import LLM from llama_index import LLMPredictor class CustomLLM(LLM): model_name = "facebook/opt-iml-1.3b" # I am not using a GPU, but you can add device="cuda:0" # to the pipeline call if you have a local GPU or # are running this on Google Colab: pipeline = pipeline("text-generation", model=model_name, model_kwargs={"torch_dtype":torch.bfloat16}) def _call(self, prompt, stop = None): prompt_length = len(prompt) response = self.pipeline(prompt, max_new_tokens=200) first_response = response[0]["generated_text"] # only return newly generated tokens returned_text = first_response[prompt_length:] return returned_text @property def _identifying_params(self): return {"name_of_model": self.model_name} @property def _llm_type(self): return "custom" time1 = time.time() # define our LLM llm_predictor = LLMPredictor(llm=CustomLLM()) # load in HF embedding model from langchain embed_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embed_model) set_global_service_context(service_context) print("Done creating service context") # build index documents = SimpleDirectoryReader('../data').load_data() new_index = ListIndex.from_documents(documents, service_context=service_context) print("Done building index") # query with embed_model specified #query_engine = new_index.as_query_engine( # #retriever_mode="embedding", # retriever_mode="default", # response_mode = "simple_summarize", # verbose=True, # service_context=service_context #) query_engine = new_index.as_query_engine() print("Done creating query engine") def query(query_string): response = query_engine.query(query_string) print(response) return response query("what is the definition of Chemistry?") query("what are the benefits of sports?") query("why study economics?") ================================================ FILE: hugging_face/throwaway_test.py ================================================ from llama_index import ListIndex, SimpleDirectoryReader #from llama_index import QueryEngine # Load documents from a directory documents = SimpleDirectoryReader('../data').load_data() # Create a new index from the documents new_index = ListIndex.from_documents(documents) # Create a query engine from the new index query_engine = new_index.as_query_engine() # Query the index results = query_engine.query('what is the histry of economics?') print(f"results: {results}") ================================================ FILE: kg_search/Google_KG_helper.py ================================================ """Python client calling for Knowledge Graph Search API.""" import json import os from urllib.parse import urlencode from urllib.request import urlopen from pathlib import Path from pprint import pprint #api_key = open(str(Path.home()) + "/.google_api_key").read() api_key = os.environ.get("GOOGLE_API_KEY") # use Google search API to get information about a named entity: def get_entity_info(entity_name): service_url = "https://kgsearch.googleapis.com/v1/entities:search" params = { "query": entity_name, "limit": 1, "indent": True, "key": api_key, } url = service_url + "?" + urlencode(params) response = json.loads(urlopen(url).read()) return response def tree_traverse(a_dict): ret = [] def recur(dict_2, a_list): if isinstance(dict_2, dict): for key, value in dict_2.items(): if key in ['name', 'description', 'articleBody']: a_list += [value] recur(value, a_list) if isinstance(dict_2, list): for x in dict_2: recur(x, a_list) recur(a_dict, ret) return ret def get_context_text(entity_name): json_data = get_entity_info(entity_name) return ' '.join(tree_traverse(json_data)) if __name__ == "__main__": get_context_text("Bill Clinton") ================================================ FILE: kg_search/Google_Knowledge_Graph_Search.py ================================================ """Example of Python client calling Knowledge Graph Search API.""" from llama_index.core.schema import Document from llama_index.core import VectorStoreIndex import Google_KG_helper def kg_search(entity_name, *questions): ret = "" context_text = Google_KG_helper.get_context_text(entity_name) print(f"Context text: {context_text}") doc = Document(text=context_text) index = VectorStoreIndex.from_documents([doc]) for question in questions: response = index.as_query_engine().query(question) ret += f"QUESTION: {question}\nRESPONSE: {response}\n" return ret if __name__ == "__main__": print(kg_search("Bill Clinton", "When was Bill president?")) ================================================ FILE: kg_search/README.md ================================================ # Running the example You will need Google and OpenAI API keys (see book text). Install virtualenv if required and set up a local environment: pip install virtualenv # if not already installed python3 -m venv env # create virtual env in current directory source env/bin/activate # activate virtual environment pip install -U llama-index python Google_Knowledge_Graph_Search.py ================================================ FILE: kor/README.md ================================================ # Kor Library: a Useful Library for using LLMs to extract data from text The Kor library was written by Eugene Yurtsev. Kor is useful for using LLMs to extract structured data from unstructured text. Kor works by generating appropriate prompt text to explain to GPT-3.5 what information to extract and adding in the text to be processed. The [GitHub repository for Kor](https://github.com/eyurtsev/kor) is under active development so please check the project for updates. Here is the [documentation](https://eyurtsev.github.io/kor/). ================================================ FILE: kor/dates.py ================================================ " From documentation: https://eyurtsev.github.io/kor/" from kor.extraction import create_extraction_chain from kor.nodes import Object, Text, Number from langchain.chat_models import ChatOpenAI from pprint import pprint import warnings ; warnings.filterwarnings('ignore') llm = ChatOpenAI( model_name="gpt-3.5-turbo", temperature=0, max_tokens=2000, frequency_penalty=0, presence_penalty=0, top_p=1.0, ) schema = Object( id="date", description=( "Any dates found in the text. Should be output in the format:" " January 12, 2023" ), attributes = [ Text(id = "month", description = "The month of the date", examples=[("Someone met me on December 21, 1995", "Let's meet up on January 12, 2023 and discuss our yearly budget")]) ], ) chain = create_extraction_chain(llm, schema, encoder_or_encoder_class='json') pred = chain.predict_and_parse(text="I will go to California May 1, 2024")['data'] print("* month mentioned in text=", pred) ================================================ FILE: langchain_dbpedia_agent/QA.py ================================================ # Copyright 2021-2023 Mark Watson # This is an example I wriote and distributed in 2021. Here I am just # reusing a few functions for my LangChain Agent book chapter. # # Original Colab notebook: # https://colab.research.google.com/drive/1FX-0eizj2vayXsqfSB2ONuJYG8BaYpGO?usp=sharing # !pip install import spacy # !python -m spacy download en_core_web_sm import spacy try: nlp_model = spacy.load("en_core_web_sm") except Exception as e: print(f"Fixing error: {e}") spacy.cli.download("en_core_web_sm") nlp_model = spacy.load("en_core_web_sm") from SPARQLWrapper import SPARQLWrapper, JSON sparql = SPARQLWrapper("http://dbpedia.org/sparql") def query(query): sparql.setQuery(query) sparql.setReturnFormat(JSON) return sparql.query().convert()["results"]["bindings"] def entities_in_text(s): doc = nlp_model(s) ret = {} for [ename, etype] in [[entity.text, entity.label_] for entity in doc.ents]: if etype in ret: ret[etype] = ret[etype] + [ename] else: ret[etype] = [ename] return ret # NOTE: !! note "{{" .. "}}" double curly brackets: this is to escape for Python String format method: sparql_query_template = """ select distinct ?s ?comment where {{ ?s '{name}'@en . ?s ?comment . FILTER (lang(?comment) = 'en') . ?s {dbpedia_type} . }} limit 15 """ print(sparql_query_template) def dbpedia_get_entities_by_name(name, dbpedia_type): print(f"{name=} {dbpedia_type=}") s_query = sparql_query_template.format(name=name, dbpedia_type=dbpedia_type) print(s_query) results = query(s_query) return results entity_type_to_type_uri = { "PERSON": "", "GPE": "", "ORG": "", } def get_context_text(query_text): entities = entities_in_text(query_text) def helper(entity_type): ret = "" if entity_type in entities: for hname in entities[entity_type]: results = dbpedia_get_entities_by_name( hname, entity_type_to_type_uri[entity_type] ) for result in results: ret += ret + result["comment"]["value"] + " . " return ret context_text = helper("PERSON") + helper("ORG") + helper("GPE") #print("\ncontext text:\n", context_text, "\n") return context_text ================================================ FILE: langchain_dbpedia_agent/README.md ================================================ # LangChain Agent Tool Example Using DBPedia SPARQL Queries To run the example: python custom_func_dbpedia.py Example output: ``` select distinct ?s ?comment where {{ ?s '{name}'@en . ?s ?comment . FILTER (lang(?comment) = 'en') . ?s {dbpedia_type} . }} limit 15 > Entering new AgentExecutor chain... Invoking: `get_context_data` with `{'query_text': 'Berlin'}` name='Berlin' dbpedia_type='' select distinct ?s ?comment where { ?s 'Berlin'@en . ?s ?comment . FILTER (lang(?comment) = 'en') . ?s . } limit 15 {'context_text': "Berlin (/bɜːrˈlɪn/ bur-LIN, German: [bɛʁˈliːn]) is the capital and largest city of Germany by both area and population. Its 3.6 million inhabitants make it the European Union's most populous city, according to population within city limits. One of Germany's sixteen constituent states, Berlin is surrounded by the State of Brandenburg and contiguous with Potsdam, Brandenburg's capital. Berlin's urban area, which has a population of around 4.5 million, is the second most populous urban area in Germany after the Ruhr. The Berlin-Brandenburg capital region has around 6.2 million inhabitants and is Germany's third-largest metropolitan region after the Rhine-Ruhr and Rhine-Main regions. . "} Berlin is the capital and largest city of Germany. It is located in the northeastern part of the country. Berlin has a population of approximately 3.6 million people, making it the most populous city in the European Union. It is surrounded by the State of Brandenburg and is contiguous with Potsdam, the capital of Brandenburg. The urban area of Berlin has a population of around 4.5 million, making it the second most populous urban area in Germany after the Ruhr. The Berlin-Brandenburg capital region has a population of approximately 6.2 million, making it Germany's third-largest metropolitan region after the Rhine-Ruhr and Rhine-Main regions. > Finished chain. ``` ================================================ FILE: langchain_dbpedia_agent/custom_func_dbpedia.py ================================================ from QA import get_context_text def get_context_data(query_text): """Method to get context text for entities from DBPedia using SPARQL query""" query_text_data = get_context_text(query_text) return {"context_text": query_text_data} ## Custom function example using DBPedia from typing import Type from pydantic import BaseModel, Field from langchain.tools import BaseTool class GetContextTextFromDbPediaInput(BaseModel): """Inputs for get_context_data""" query_text: str = Field(description="query_text user supplied query text") class GetContextTextFromDbPediaTool(BaseTool): name = "get_context_data" description = """ Useful when you want to make a query and get context text from DBPedia. You should enter and text containing entity names """ args_schema: Type[BaseModel] = GetContextTextFromDbPediaInput def _run(self, query_text: str): text = get_context_data(query_text) return text def _arun(self, query_text: str): raise NotImplementedError("get_context_data does not support async") ## Create agent from langchain.agents import AgentType from langchain.chat_models import ChatOpenAI from langchain.agents import initialize_agent llm = ChatOpenAI(model="gpt-4o-mini", temperature=0) tools = [GetContextTextFromDbPediaTool()] agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True) ## Run agent agent.run( "What country is Berlin in and what other information about the city do you have?" ) ================================================ FILE: langchain_dbpedia_agent/requirements.txt ================================================ spacy==3.7.6 SPARQLWrapper==2.0.0 langchain==0.2.14 langchain-community==0.2.12 openai==1.42.0 ================================================ FILE: langchain_getting_started/.gitignore ================================================ *.log tmp tmp/* ================================================ FILE: langchain_getting_started/README.md ================================================ # LangChain Getting Started Examples Requirements: pip install langchain langchain-openai faiss-cpu chromadb unstructured pdf2image pytesseract docx See book for: country_information.py directions_template.py doc_search.py ## Examples not (yet) in my book chroma_persist_index.py chroma_use_disk_index_for_query.py Note: I sometines need to ***rm -rf ./tmp** when updating libraries to new versions. ================================================ FILE: langchain_getting_started/agent_test.py ================================================ from langchain.agents import initialize_agent, Tool from langchain.llms import OpenAI llm = OpenAI(temperature=0) def add(input: str) -> str: values = [int(x) for x in input.split("+")] return str(sum(values)) def is_prime(input: str) -> str: n = int(input) if n <= 1: return "no" if n <= 3: return "yes" if n % 2 == 0 or n % 3 == 0: return "no" i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return "no" i += 6 return "yes" tools = [ Tool( name = "Add", func=add, description="Useful for when you need to add numbers. Input should be in the form '1 + 2 + 3'." ), Tool( name = "IsPrime", func=is_prime, description="Useful to know if a number is prime." ), ] agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) print(agent.run("Add the first 10 numbers and tell me if it's prime.")) ================================================ FILE: langchain_getting_started/chroma_persist_index.py ================================================ from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings(model="text-embedding-3-large") vectorstore = Chroma(collection_name="langchain_store", embedding_function=embeddings, persist_directory="./tmp") # Add data to the vector store vectorstore.add_texts( ["Chemicals are used in the production of many products. ", "The study of Physics is important for understanding the world around us.", "Applications of Biology include the study of plants and animals."], metadatas=[{"source": "Mark"}, {"source": "Mark"}, {"source": "Mark"}], ids=["docC", "docP", "docB"]) # Persist the data to disk vectorstore.persist() ================================================ FILE: langchain_getting_started/chroma_use_disk_index_for_query.py ================================================ from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings(model="text-embedding-3-large") vectorstore = Chroma(collection_name="langchain_store", embedding_function=embeddings, persist_directory="./tmp") # Query the vector store results = vectorstore.similarity_search("the red chemical", k=1) print(results) ================================================ FILE: langchain_getting_started/country_information.py ================================================ from langchain.prompts import PromptTemplate from langchain_openai import OpenAI llm = OpenAI(temperature=0.9) def get_country_information(country_name): print(f"\nProcessing {country_name}:") global prompt if "prompt" not in globals(): print("Creating prompt...") prompt = PromptTemplate( input_variables=["country_name"], template = """ Predict the capital and population of a country. Country: {country_name} Capital: Population:""", ) prompt_text = prompt.format(country_name=country_name) print(prompt_text) return llm(prompt_text) print(get_country_information("Canada")) print(get_country_information("Germany")) ================================================ FILE: langchain_getting_started/directions_template.py ================================================ from langchain.prompts import PromptTemplate from langchain_openai import OpenAI llm = OpenAI(temperature=0.9) def get_directions(thing_to_do): prompt = PromptTemplate( input_variables=["thing_to_do"], template="How do I {thing_to_do}?", ) prompt_text = prompt.format(thing_to_do=thing_to_do) print(f"\n{prompt_text}:") return llm(prompt_text) print(get_directions("get to the store")) print(get_directions("hang a picture on the wall")) ================================================ FILE: langchain_getting_started/doc_search.py ================================================ from langchain_community.vectorstores import FAISS from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnablePassthrough from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langchain_community.document_loaders import DirectoryLoader model = ChatOpenAI() from read_text_files import read_text_files vectorstore = FAISS.from_texts(read_text_files("../data/"), embedding=OpenAIEmbeddings()) retriever = vectorstore.as_retriever() template = """Answer the question based only on the following context: {context} Question: {question} """ prompt = ChatPromptTemplate.from_template(template) chain = ( {"context": retriever, "question": RunnablePassthrough()} | prompt | model | StrOutputParser() ) print(chain.invoke("who tried to define what Chemistry is?")) print(chain.invoke("What kinds of equipment are in a chemistry laboratory?")) print(chain.invoke("What is Austrian School of Economics?")) print(chain.invoke("Why do people engage in sports?")) print(chain.invoke("What is the effect of body chemistry on exercise?")) ================================================ FILE: langchain_getting_started/read_text_files.py ================================================ import os # Generated by Perplexity def read_text_files(directory_path): """ Reads all .txt files in the specified directory and returns their contents as a list of strings. :param directory_path: The path to the directory containing .txt files :return: A list of strings where each string is the content of a .txt file """ txt_contents = [] # Check if the directory exists if not os.path.isdir(directory_path): print(f"The directory {directory_path} does not exist.") return txt_contents # Iterate over all files in the directory for filename in os.listdir(directory_path): # Check for .txt extension if filename.endswith(".txt"): # Construct full file path file_path = os.path.join(directory_path, filename) # Open and read the contents of the file try: with open(file_path, 'r') as file: txt_contents.append(file.read()) except IOError as e: print(f"Failed to read file {filename}: {e}") return txt_contents ================================================ FILE: langchain_getting_started/test.py ================================================ from langchain_community.vectorstores import FAISS from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnablePassthrough from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langchain_community.document_loaders import DirectoryLoader model = ChatOpenAI() from read_text_files import read_text_files vectorstore = FAISS.from_texts(read_text_files("../data/"), embedding=OpenAIEmbeddings()) retriever = vectorstore.as_retriever() template = """Answer the question based only on the following context: {context} Question: {question} """ prompt = ChatPromptTemplate.from_template(template) chain = ( {"context": retriever, "question": RunnablePassthrough()} | prompt | model | StrOutputParser() ) print(chain.invoke("who tried to define what Chemistry is?")) exit(0) from langchain_community.document_loaders import TextLoader, DirectoryLoader #from langchain_community.embeddings.sentence_transformer import ( # SentenceTransformerEmbeddings, #) from langchain_openai import OpenAIEmbeddings from langchain_community.vectorstores import FAISS from langchain_text_splitters import RecursiveCharacterTextSplitter from langchain.chains import VectorDBQA from langchain_community.llms import OpenAI from langchain_openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() #loader = TextLoader("../data/chemistry.txt", "../data/health.txt", show_progress=True) loader = DirectoryLoader('../data', glob="**/*.txt", show_progress=False) documents = loader.load() print("documents:", documents) text_splitter = RecursiveCharacterTextSplitter() documents = text_splitter.split_documents(documents) print("documents:", documents) vector = FAISS.from_documents(documents, embeddings) print(dir(vector)) exit(0) # split it into chunks text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) docs = text_splitter.split_documents(documents) texts = text_splitter.split_documents(documents) docsearch = Chroma.from_documents(texts, OpenAIEmbeddings()) qa = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=docsearch) def query(q): print(f"Query: {q}") print(f"Answer: {qa.run(q)}") query("What kinds of equipment are in a chemistry laboratory?") query("What is Austrian School of Economics?") query("Why do people engage in sports?") query("What is the effect of body chemistry on exercise?") exit(0) db = Chroma.from_documents(docs, SentenceTransformerEmbeddings()) # query it query = "What is the definition of chemistry?" docs = db.similarity_search(query) # print results print(docs[0].page_content) exit(0) from langchain.llms import OpenAI #from langchain.document_stores import InMemoryDocumentStore from langchain_community.vectorstores import Chroma import os # Initialize LangChain components llm = OpenAI() #document_store = InMemoryDocumentStore() document_store = Chroma() # Directory containing text files text_files_directory = "../data/" # Read text files and add them to the document store for filename in os.listdir(text_files_directory): if filename.endswith(".txt"): with open(os.path.join(text_files_directory, filename), 'r', encoding='utf-8') as file: text_content = file.read() document_store.add_documents([{"text": text_content, "metadata": {"filename": filename}}]) # Example query query = "What is the main topic discussed in the documents?" response = llm.query_document_store(query, document_store=document_store) print("Query Result:", response) ================================================ FILE: llama-index_case_study/.gitignore ================================================ index.json cache ================================================ FILE: llama-index_case_study/README.md ================================================ # LlamaIndex Examples The old example test_from_docs.py has been deprecated and removed. The new example is web_page_QA.py ================================================ FILE: llama-index_case_study/requirements.txt ================================================ llama_index trafilatura ================================================ FILE: llama-index_case_study/web_page_QA.py ================================================ # Derived from examples in llama_index documentation # pip install llama-index html2text trafilatura from pprint import pprint from llama_index.core import Document import trafilatura from llama_index.core import VectorStoreIndex def query_website(url, *questions): downloaded = trafilatura.fetch_url(url) text = trafilatura.extract(downloaded) #print(text) list_of_documents = [Document(text=text)] index = VectorStoreIndex.from_documents(list_of_documents) #.from_texts([text]) engine = index.as_query_engine() for question in questions: print(f"\n== QUESTION: {question}\n") response = engine.query(question) print(f"== RESPONSE: {response}") if __name__ == "__main__": url = "https://markwatson.com" query_website(url, "What instruments does Mark play?", "How many books has Mark written?", "list company names beginning with the letter 'C'") ================================================ FILE: llama.cpp/README.md ================================================ # llama.cpp local modes with Langchain reference: https://python.langchain.com/docs/integrations/llms/llamacpp ================================================ FILE: llama.cpp/test.py ================================================ # code example from: # https://python.langchain.com/docs/integrations/llms/llamacpp from langchain.llms import LlamaCpp from langchain.prompts import PromptTemplate from langchain.chains import LLMChain from langchain.callbacks.manager import CallbackManager from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler template = """Question: {question} Answer: Let's work this out in a step by step way to be sure we have the right answer.""" prompt = PromptTemplate(template=template, input_variables=["question"]) # Callbacks support token-wise streaming callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]) # Make sure the model path is correct for your system! llm = LlamaCpp( model_path="/Users/markw/llama.cpp/models/openassistant-llama2-13b-orca-8k-3319.Q5_K_M.gguf", temperature=0.75, max_tokens=2000, top_p=1, callback_manager=callback_manager, verbose=True, # Verbose is required to pass to the callback manager ) prompt = """ Question: If Mary is 30 years old and Bob is 25, who is older and by how much? """ print(llm(prompt)) ================================================ FILE: llm_enhanced_search_ddg_ollama/README.md ================================================ # Multi-prompt Search using LLMs, the Duckduckgo search API, and local Ollama models ## install Duckduckgo search API library docs: https://pypi.org/project/duckduckgo-search/ pip install duckduckgo_search_api I believe the Duckduckgo search API can only be used for low volume non-commercial use. I find the results very useful because they are served from Duck Duck Go's internal quick-look data. Also install: pip install llama-index html2text trafilatura ================================================ FILE: llm_enhanced_search_ddg_ollama/llm_enhanced_search.py ================================================ from ddg import Duckduckgo from langchain_community.llms.ollama import Ollama # pip install llama-index html2text trafilatura import trafilatura from pprint import pprint ddg_api = Duckduckgo() llm = Ollama( model="mistral:v0.3", verbose=False, #callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]), ) prompt1 = "return concisely either 'Y' or 'N' if this query | %s | is matched well by the following text: %s" prompt2 = "Using the query | %s | summarize the following text including only material relevant to the query:\n%s" prompt3 = "Using the query | %s | summarize in multiple paragraphs the following text including only material relevant to the query:\n%s" def llm_search(query): results = ddg_api.search(query) data = results['data'] good_results = [] good_summaries = [] for d in data: description = d['description'] p = prompt1 % (query, description) s = llm.invoke(p) print(f"Prompt: {p}\nResponse: {s}\n\n") if s.strip()[0:1] == 'Y': good_results.append(d) uri = d['url'] downloaded = trafilatura.fetch_url(uri) text = trafilatura.extract(downloaded) p2 = prompt2 % (query, text) s2 = llm.invoke(p2) good_summaries.append(s2) p3 = prompt3 % (query, "\n\n".join(good_summaries)) final_summary = llm.invoke(p3) return (good_results, good_summaries, final_summary) def test1(): (results, summaries, final_summary) = llm_search("Common Lisp and Deep Learning consultant") print(f"\n\n****** Good Results ******\n\n") print(results) print(f"\n\n****** Good Summaries ******\n\n") print(summaries) print(f"\n\n****** Final Summary ******\n\n") print(final_summary) test1() def test2(): (results, summaries, final_summary) = llm_search("Write a business plan for a new startup using LLMs and expertise in medical billing.") print(f"\n\n****** Good Results ******\n\n") print(results) print(f"\n\n****** Good Summaries ******\n\n") print(summaries) print(f"\n\n****** Final Summary ******\n\n") print(final_summary) # test2() ================================================ FILE: neo4j/README.md ================================================ # Neo4J example, not yet in my book, this directory just shows an example from LlamaIndex docs docs with this example: https://llamahub.ai/l/llama_packs-neo4j_query_engine ================================================ FILE: neo4j/credentials.json ================================================ {"username": "neo4j", "password": "demodemo", "database": "llamatest", "url": "bolt://localhost:7687"} ================================================ FILE: neo4j/test_example.py ================================================ import json from llama_index.llama_pack import download_llama_pack # download and install dependencies Neo4jQueryEnginePack = download_llama_pack( "Neo4jQueryEnginePack", "./neo4j_pack" ) # Load the docs (example of Paleo diet from Wikipedia) from llama_index import download_loader WikipediaReader = download_loader("WikipediaReader") loader = WikipediaReader() docs = loader.load_data(pages=['Paleolithic diet'], auto_suggest=False) print(f'Loaded {len(docs)} documents') # get Neo4j credentials (assume it's stored in credentials.json) with open('credentials.json') as f: neo4j_connection_params = json.load(f) username = neo4j_connection_params['username'] password = neo4j_connection_params['password'] url = neo4j_connection_params['url'] database = neo4j_connection_params['database'] print(f'username: {username}', f'password: {password}', f'url: {url}', f'database: {database}') # create the pack neo4j_pack = Neo4jQueryEnginePack( username = username, password = password, url = url, database = database, docs = docs ) response = neo4j_pack.run("Tell me about the benefits of paleo diet.") print(f"{response}\n\n") response = neo4j_pack.run("What kinds of food should I buy for a paleo diet.") print(f"{response}") ================================================ FILE: ollama_langchain/README.md ================================================ ================================================ FILE: ollama_langchain/llama3-instruct-8b.py ================================================ # requires "ollama serve" to be running in another terminal from langchain_community.llms.ollama import Ollama llm = Ollama( model="llama3:instruct", verbose=True, ) #s = llm("how much is 1 + 2?") #print(s) s = llm.invoke("If Sam is 27, Mary is 42, and Jerry is 33, what are their age differences? Be concise") print(s) ================================================ FILE: ollama_langchain/mistral-7b.py ================================================ # requires "ollama serve" to be running in another terminal from langchain_community.llms.ollama import Ollama llm = Ollama( model="mistral-nemo:latest", verbose=False, ) s = llm.invoke("how much is 1 + 2?") print(s) s = llm.invoke("If Sam is 27, Mary is 42, and Jerry is 33, what are their age differences?") print(s) ================================================ FILE: ollama_langchain/rag_test.py ================================================ # requires "ollama serve" to be running in another terminal # pip install python-docx from langchain_community.llms.ollama import Ollama from langchain_community.embeddings import OllamaEmbeddings from langchain.chains import RetrievalQA from langchain_community.vectorstores import Chroma from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_community.document_loaders import DirectoryLoader model = "mistral:v0.3" # Create index (can be reused): loader = DirectoryLoader('../data/', glob="**/*.txt", show_progress=True) data = loader.load() text_splitter = RecursiveCharacterTextSplitter( chunk_size=100, chunk_overlap=100) all_splits = text_splitter.split_documents(data) persist_directory = 'cache' vectorstore = Chroma.from_documents( documents = all_splits, embedding = OllamaEmbeddings(model=model), persist_directory=persist_directory) vectorstore.persist() # Try reloading index from disk and using for search: persist_directory = 'cache' vectorstore = Chroma(persist_directory=persist_directory, embedding_function=OllamaEmbeddings(model=model) ) llm = Ollama(base_url = "http://localhost:11434", model = model, verbose = False, ) retriever = vectorstore.as_retriever() qa_chain = RetrievalQA.from_chain_type( llm = llm, chain_type = 'stuff', retriever = retriever, verbose = True,) while True: query = input("Ask a question: ") response = qa_chain(query) print(response['result']) ================================================ FILE: ollama_langchain/requirements.txt ================================================ langchain_community langchain ================================================ FILE: prompt_examples/two-shot-2-var.txt ================================================ Given the two examples below, extract the names, addresses, and email addresses of individuals mentioned later as Process Text. Format the extracted information in JSON, with keys for "name", "address", and "email". If any information is missing, use "null" for that field. Be concise in your output by providing only the output JSON. Example 1: Text: "John Doe lives at 1234 Maple Street, Springfield. His email is johndoe@example.com." Output: { "name": "John Doe", "address": "1234 Maple Street, Springfield", "email": "johndoe@example.com" } Example 2: Text: "Jane Smith has recently moved to 5678 Oak Avenue, Anytown. She hasn't updated her email yet." Output: { "name": "Jane Smith", "address": "5678 Oak Avenue, Anytown", "email": null } Process Text: "{input_text}" Output: ================================================ FILE: prompt_examples/two-shot-2.txt ================================================ Given the two examples below, extract the names, addresses, and email addresses of individuals mentioned later as Process Text. Format the extracted information in JSON, with keys for "name", "address", and "email". If any information is missing, use "null" for that field. Be concise in your output by providing only the output JSON. Example 1: Text: "John Doe lives at 1234 Maple Street, Springfield. His email is johndoe@example.com." Output: { "name": "John Doe", "address": "1234 Maple Street, Springfield", "email": "johndoe@example.com" } Example 2: Text: "Jane Smith has recently moved to 5678 Oak Avenue, Anytown. She hasn't updated her email yet." Output: { "name": "Jane Smith", "address": "5678 Oak Avenue, Anytown", "email": null } Process Text: "Mark Johnson enjoys living in Berkeley California at 102 Dunston Street and use mjess@foobar.com for contacting him." Output: ================================================ FILE: rag/README.md ================================================ # RAG examples For my book [LangChain and LlamaIndex Projects Lab Book: Hooking Large Language Models Up to the Real World](https://leanpub.com/langchain/read) (link to read free online) pip install -U llama-index pip install torch sentence-transformers # for reranking example ================================================ FILE: rag/requirements.txt ================================================ llama-index==0.11.1 sentence-transformers==3.0.1 ================================================ FILE: rag/reranking_rag_llama_index.py ================================================ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader from llama_index.embeddings.openai import OpenAIEmbedding from llama_index.core.node_parser import SentenceSplitter from llama_index.core.extractors import TitleExtractor from llama_index.core.ingestion import IngestionPipeline from llama_index.core.postprocessor import SentenceTransformerRerank # Set up the ingestion pipeline with transformations pipeline = IngestionPipeline( transformations=[ SentenceSplitter(chunk_size=25, chunk_overlap=0), TitleExtractor(), OpenAIEmbedding(), ] ) # Load documents using a directory reader documents = SimpleDirectoryReader("../data").load_data() # Create an index from the documents index = VectorStoreIndex.from_documents(documents) # Initialize the reranker with a specific model reranker = SentenceTransformerRerank( model="cross-encoder/ms-marco-MiniLM-L-12-v2", # Example model, adjust as needed top_n=3 # Adjust the number of top documents to rerank ) # Set up the query engine with the reranker as a postprocessor query_engine = index.as_query_engine( similarity_top_k=10, # Set for how many results to retrieve before reranking node_postprocessors=[reranker] # Add the reranker to the postprocessing steps ) # Perform a query #response = query_engine.query("List a few sports") response = query_engine.query("Compare sports with the study of health issues") # Print the response print(response) ================================================ FILE: rag/simple_llama_index_retrieve_docs.py ================================================ from llama_index.core import VectorStoreIndex from llama_index.core import Document text_list = ["LlamaIndex is a powerful tool for LLM applications.", "It helps in structuring and retrieving data efficiently."] documents = [Document(text=t) for t in text_list] index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine() retrieved_docs = query_engine.retrieve("What is LlamaIndex?") print(retrieved_docs) ================================================ FILE: rag/simple_rag_llama_index.py ================================================ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader from llama_index.embeddings.openai import OpenAIEmbedding from llama_index.core.node_parser import SentenceSplitter from llama_index.core.extractors import TitleExtractor from llama_index.core.ingestion import IngestionPipeline pipeline = IngestionPipeline( transformations=[ SentenceSplitter(chunk_size=25, chunk_overlap=0), TitleExtractor(), OpenAIEmbedding(), ] ) documents = SimpleDirectoryReader("../data_small").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine() response = query_engine.query("List a few sports") print(response) ================================================ FILE: requirements.txt ================================================ llama-index>=0.10.13 ================================================ FILE: sqlite/README.md ================================================ # SqLite Chat Example We will use the SQlite sample database from the SQLite Tutorial web site: https://www.sqlitetutorial.net/sqlite-sample-database/ This database has 11 tables. The about URI has documentatiuon for this database so please take a minute to review the [table schema diagram and text description](https://www.sqlitetutorial.net/sqlite-sample-database/). ================================================ FILE: sqlite/requirements.txt ================================================ langchain==0.3.3 langchain_community==0.3.2 langchain_experimental==0.3.3 openai==1.51.2 ================================================ FILE: sqlite/sqlite_chat_test.py ================================================ from langchain.llms import OpenAI from langchain_experimental.sql import SQLDatabaseChain from langchain_experimental.sql.base import SQLDatabase # Initialize the database and LLM db = SQLDatabase.from_uri("sqlite:///chinook.db") llm = OpenAI(temperature=0) # Create a SQLDatabaseChain db_chain = SQLDatabaseChain.from_llm(llm=llm, db=db, verbose=True) # Run queries db_chain.run("How many employees are there?") db_chain.run("What is the name of the first employee?") db_chain.run("Which customer has the most invoices?") db_chain.run("List all music genres in the database") ================================================ FILE: summarization/README.md ================================================ # Text summarization ================================================ FILE: summarization/prompt.txt ================================================ Summarize the following text: "{input_text}" Output: ================================================ FILE: summarization/requirements.txt ================================================ openai ================================================ FILE: summarization/summarization_example.py ================================================ import openai from openai import OpenAI import os openai.api_key = os.getenv("OPENAI_API_KEY") client = OpenAI() # Read the prompt from a text file with open('prompt.txt', 'r') as file: prompt_template = file.read() # Substitute a string variable into the prompt with open('../data/economics.txt', 'r') as file: input_text = file.read() prompt = prompt_template.replace("input_text", input_text) # Use the OpenAI completion API to generate a response with GPT-4 completion = client.chat.completions.create( model="gpt-4o-mini", messages=[ { "role": "user", "content": prompt, }, ], ) print(completion.choices[0].message.content) ================================================ FILE: tavily_search/READMS.md ================================================ Example code from: LangChain: https://docs.tavily.com/docs/tavily-api/langchain LlamaIndex: https://docs.tavily.com/docs/tavily-api/llamaindex ================================================ FILE: tavily_search/langchain_test.py ================================================ import os from langchain.utilities.tavily_search import TavilySearchAPIWrapper from langchain.agents import initialize_agent, AgentType from langchain_openai import ChatOpenAI from langchain.tools.tavily_search import TavilySearchResults # set TAVILY_API_KEY environment variable # set up the agent llm = ChatOpenAI(model_name="gpt-4", temperature=0.5) search = TavilySearchAPIWrapper() tavily_tool = TavilySearchResults(api_wrapper=search) # initialize the agent agent_chain = initialize_agent( [tavily_tool], llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True, ) # run the agent print(agent_chain.run("What are fun things to do in Sedona Arizona?")) ================================================ FILE: tavily_search/llamaindex_test.py ================================================ from llama_hub.tools.tavily_research import TavilyToolSpec from llama_index.agent import OpenAIAgent import os # set TAVILY_API_KEY environment variable tavily_tool = TavilyToolSpec(api_key=os.environ.get("TAVILY_API_KEY")) agent = OpenAIAgent.from_tools(tavily_tool.to_tool_list()) print(agent.chat("What are fun things to do in Sedona Arizona?")) ================================================ FILE: text_db_llm/README.md ================================================ # Text Database Supporting Search and Chat-based Exploration TBD ================================================ FILE: text_db_llm/data/chemistry.txt ================================================ Amyl alcohol is an organic compound with the formula C 5 H 12 O. All eight isomers of amyl alcohol are known. The most important is isobutyl carbinol, this being the chief constituent of fermentation amyl alcohol, and consequently a constituent of fusel oil. It can be separated from fusel oil by shaking with strong brine , separating the oily layer from the brine layer and it, the portion boiling between 125 and 140 °C. being collected. For further purification it may be shaken with hot lime water, the oily layer separated, dried with calcium chloride and fractionated, the fraction boiling between 128 and 132 °C only being collected. The 1730 definition of the word "chemistry", as used by Georg Ernst Stahl, meant the art of resolving mixed, compound, or aggregate bodies into their principles; and of composing such bodies from those principles.[15] In 1837, Jean-Baptiste Dumas considered the word "chemistry" to refer to the science concerned with the laws and effects of molecular forces.[16] This definition further evolved until, in 1947, it came to mean the science of substances: their structure, their properties, and the reactions that change them into other substances - a characterization accepted by Linus Pauling.[17] More recently, in 1998, the definition of "chemistry" was broadened to mean the study of matter and the changes it undergoes, as phrased by Professor Raymond Chang. The current model of atomic structure is the quantum mechanical model.[36] Traditional chemistry starts with the study of elementary particles, atoms, molecules,[37] substances, metals, crystals and other aggregates of matter. This matter can be studied in solid, liquid, or gas states, in isolation or in combination. The interactions, reactions and transformations that are studied in chemistry are usually the result of interactions between atoms, leading to rearrangements of the chemical bonds which hold atoms together. Such behaviors are studied in a chemistry laboratory. The chemistry laboratory stereotypically uses various forms of laboratory glassware. However glassware is not central to chemistry, and a great deal of experimental (as well as applied/industrial) chemistry is done without it. The transfer of energy from one chemical substance to another depends on the size of energy quanta emitted from one substance. However, heat energy is often transferred more easily from almost any substance to another because the phonons responsible for vibrational and rotational energy levels in a substance have much less energy than photons invoked for the electronic energy transfer. Thus, because vibrational and rotational energy levels are more closely spaced than electronic energy levels, heat is more easily transferred between substances relative to light or other forms of electronic energy. For example, ultraviolet electromagnetic radiation is not transferred with as much efficacy from one substance to another as thermal or electrical energy. ================================================ FILE: text_db_llm/data/economics.txt ================================================ The Austrian School (also known as the Vienna School or the Psychological School ) is a Schools of economic thought|school of economic thought that emphasizes the spontaneous organizing power of the price mechanism. Austrians hold that the complexity of subjective human choices makes mathematical modelling of the evolving market extremely difficult (or Undecidable and advocate a "laissez faire" approach to the economy. Austrian School economists advocate the strict enforcement of voluntary contractual agreements between economic agents, and hold that commercial transactions should be subject to the smallest possible imposition of forces they consider to be (in particular the smallest possible amount of government intervention). The Austrian School derives its name from its predominantly Austrian founders and early supporters, including Carl Menger, Eugen von Böhm-Bawerk and Ludwig von Mises. Economics is the social science that analyzes the production, distribution, and consumption of goods and services. Political economy was the earlier name for the subject, but economists in the late 19th century suggested "economics" as a shorter term for "economic science" that also avoided a narrow political-interest connotation and as similar in form to "mathematics", "ethics", and so forth.[2] A focus of the subject is how economic agents behave or interact and how economies work. Consistent with this, a primary textbook distinction is between microeconomics and macroeconomics. Microeconomics examines the behavior of basic elements in the economy, including individual agents (such as households and firms or as buyers and sellers) and markets, and their interactions. Macroeconomics analyzes the entire economy and issues affecting it, including unemployment, inflation, economic growth, and monetary and fiscal policy. The professionalization of economics, reflected in the growth of graduate programs on the subject, has been described as "the main change in economics since around 1900".[93] Most major universities and many colleges have a major, school, or department in which academic degrees are awarded in the subject, whether in the liberal arts, business, or for professional study; see Master of Economics. Economics is the social science that studies the behavior of individuals, households, and organizations (called economic actors, players, or agents), when they manage or use scarce resources, which have alternative uses, to achieve desired ends. Agents are assumed to act rationally, have multiple desirable ends in sight, limited resources to obtain these ends, a set of stable preferences, a definite overall guiding objective, and the capability of making a choice. There exists an economic problem, subject to study by economic science, when a decision (choice) is made by one or more resource-controlling players to attain the best possible outcome under bounded rational conditions. In other words, resource-controlling agents maximize value subject to the constraints imposed by the information the agents have, their cognitive limitations, and the finite amount of time they have to make and execute a decision. Economic science centers on the activities of the economic agents that comprise society.[1] They are the focus of economic analysis.[2] The traditional concern of economic analysis is to gain an understanding of the processes that govern the production, distribution and consumption of goods and services in an exchange economy.[3] An approach to understanding these processes, through the study of agent behavior under scarcity, may go as s: ================================================ FILE: text_db_llm/data/health.txt ================================================ which requires that you sit at a desk all day. ; If you hate to talk politics, don't associate with people who love to talk politics, etc. Learn to live one day at a time. Every day, do something you really enjoy. Add an ounce of love to everything you do. Take a hot bath or shower (or a cool one in summertime) to relieve tension. Do something for somebody else. Focus on understanding rather than on being understood; on loving rather than on being loved. Do something that will improve your appearance. ; Looking better can help you feel better. Schedule a realistic day. ; Avoid the tendency to schedule back-to-back appointments; allow time between appointments for a breathing spell. Become more flexible. ; Some things are worth not doing perfectly and some issues are fine to compromise upon. Eliminate destructive self-talking I also felt they protected me from the hard road by interposing a layer of air between the sole of my foot and the pavement. So why was I sidelined with a heel injury for over two s? I listened to the manufacturer and changed my runners every 400 miles. Come to think of it, why do I see so many runners with lower extremity injuries in my office? The traditional answer to these questions has always been overuse often compounded by an underlying mechanical abnormality such as over-pronation or flat-feet. The treatment, along with modification of training, physiotherapy, stretching etc. has always included a close look at the runner's footwear, often with recommendations about motion control, stability, cushioning, orthotics or custom molded insoles. I do not recommend that you run your next half-marathon barefoot. But certainly, I predict that sooner or later, changes will come about in both shoe design and training. From the medical establishment's point of view, the prevention and treatment of running injuries must change to incorporate the concepts outlined above. In fact I view the ideas I've presented here as a major paradigm shift in sports medicine, the likes of which I have not seen in the last fifteen years. Of course, the major shoe companies have to own up and start introducing better shoes into their lines. adaptive immunity: The ability of the body to learn to fight specific infections after being exposed to the germs that cause them. addiction: Loss of control over indulging in a substance or performing an action or behavior, and continued craving for it despite negative consequences. adenosine triphosphate: An energy-storing molecule that is found in all human cells. Usually abbreviated as ATP. adequate intake: An of the amount of a nutrient needed by healthy people. The Adequate Intake is used when there isn’t enough information to set a recommended dietary allowance (RDA). agoraphobia: Fear and avoidance of public places and open spaces. amnesia: Unusual memory loss or forgetfulness. amputation: The surgical removal of a limb or other body part. anaerobic: Any process that doesn’t require oxygen. Often refers to a form of short, high intensity exercise, known as anaerobic exercise. anaerobic exercise: Exercise that improves the efficiency of energy-producing systems that do not rely on oxygen. Examples include sprinting and weight lifting. dry eye: Stinging, burning, or irritation that occurs when the eye doesn’t produce enough moisture. duct: A tube or vessel in the body which carries the secretion of a gland; Secretion examples are tears, breast milk, etc. upper airway resistance syndrome: Inhalation that requires undue extra exertion; this extra work may cause insomnia and daytime sleepiness. urea: A waste product of protein digestion and metabolism. ureter: The tube that connects each kidney to the bladder. urethra: The tube leading from the bladder through which urine is carried from the body. ================================================ FILE: text_db_llm/data/sports.txt ================================================ Sport is generally recognised as activities based in physical athleticism or physical dexterity.[3] Sports are usually governed by rules to ensure fair competition and consistent adjudication of the winner. "Sport" comes from the Old French desport meaning "leisure", with the oldest definition in English from around 1300 being "anything humans find amusing or entertaining".[4] Other bodies advocate widening the definition of sport to include all physical activity and exercise. For instance, the Council of Europe include all forms of physical exercise, including those completed just for fun. ================================================ FILE: text_db_llm/requirements.txt ================================================ openai==1.42.0 chromadb==0.5.5 llama-index-vector-stores-chroma==0.2.0 llama-index-embeddings-huggingface==0.3.1 llama-index==0.11.1 ================================================ FILE: text_db_llm/text_db_llm.py ================================================ # Text Database Supporting Search and Chat-based Exploration # make sure you set the following environment variable: # OPENAI_API_KEY import os from llama_index.core import VectorStoreIndex, SimpleDirectoryReader import chromadb from llama_index.vector_stores.chroma import ChromaVectorStore from llama_index.core import StorageContext from llama_index.embeddings.huggingface import HuggingFaceEmbedding chroma_client = chromadb.EphemeralClient() chroma_collection = chroma_client.create_collection("temp") embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5") vector_store = ChromaVectorStore(chroma_collection=chroma_collection) storage_context = StorageContext.from_defaults(vector_store=vector_store) documents = SimpleDirectoryReader('data').load_data() index = VectorStoreIndex.from_documents( documents, storage_context=storage_context, embed_model=embed_model ) query_engine = index.as_query_engine() print(query_engine.query("effect of body chemistry on exercise?")) exit(0) if os.path.exists("index.json") and os.path.getsize("index.json") > 0: print("Loading index from disk...") index = VectorStoreIndex.load_from_disk('index.json') else: print("Index file odes not exist, so create it...") documents = SimpleDirectoryReader('data').load_data() index = VectorStoreIndex(documents) print(dir(index)) index.save_to_disk('index.json') # search for a document print(index.query("effect of body chemistry on exercise?")) ================================================ FILE: tool_search_math_example/requirements.txt ================================================ langchain duckduckgo_search langchain-community langchain-openai ================================================ FILE: tool_search_math_example/tool_search_math_example.py ================================================ from langchain.agents import create_react_agent, Tool, AgentExecutor from langchain.agents.agent_types import AgentType from langchain_community.tools import DuckDuckGoSearchRun from langchain_openai import ChatOpenAI from langchain_core.prompts import PromptTemplate import os openai_key = os.getenv("OPENAI_API_KEY") llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.3, openai_api_key=openai_key) ddg_api = DuckDuckGoSearchRun() class DuckDuckGoSearchAPIWrapper: def __call__(self, query): results = ddg_api.invoke(query) #print(f"**** {results=}") return results if results else 'No results found' class SimpleCalculator: def __call__(self, expression): try: return eval(expression) except Exception as e: return f"Error in calculation: {e}" # Initialize the tools search_tool = Tool( name="duckduckgo_search", func=DuckDuckGoSearchAPIWrapper(), description="Searches the web using DuckDuckGo" ) calculator_tool = Tool( name="simple_calculator", func=SimpleCalculator(), description="Performs simple calculations" ) # Define the tool chain tools = [search_tool, calculator_tool] tool_names = ["duckduckgo_search", "simple_calculator"] agent_scratchpad = "thoughts: " template = '''Answer the following questions as best you can. You have access to the following tools: {tools} Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [{tool_names}] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question Begin! Question: {input} Thought:{agent_scratchpad}''' prompt = PromptTemplate.from_template(template) print(prompt) # Initialize the agent with tools agent = create_react_agent(llm, tools, prompt) agent_executor = AgentExecutor(agent=agent, tools=tools) # Example #1 input for the chain input_text = "search: What is the population of Canada?" # Run the chain result = agent_executor.invoke({"input": input_text, "chat_history": agent_scratchpad}) # Print the result print(result) # Example #2 input for the chain input_text = "calculator: 250 * 4" # Run the chain result = agent_executor.invoke({"input": input_text, "chat_history": agent_scratchpad}) # Print the result print(result) ================================================ FILE: tools_langchain/doc_example.py ================================================ # example from documentation: https://github.com/cristobalcl/LearningLangChain/blob/master/notebooks/01%20-%20Simple%20Agent.ipynb from langchain.agents import initialize_agent, Tool from langchain.llms import OpenAI llm = OpenAI(temperature=0) # define 2 tools to experiment with def add(input: str) -> str: values = [int(x) for x in input.split("+")] return str(sum(values)) def is_prime(input: str) -> str: n = int(input) if n <= 1: return "no" if n <= 3: return "yes" if n % 2 == 0 or n % 3 == 0: return "no" i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return "no" i += 6 return "yes" tools = [ Tool( name = "Add", func=add, description="Useful for when you need to add numbers. Input should be in the form '1 + 2 + 3'." ), Tool( name = "IsPrime", func=is_prime, description="Useful to know if a number is prime." ), ] # initialize the agent agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) def test1(): print(agent.run("If we add 3, 5, 19 20 and 24, is the result a prime number?")) def test2(): print(agent.run("Loop over the numbers from 10 to 30 and sum up the prime numbers")) test2() ================================================ FILE: tools_langchain/loop_collection_with_function.py ================================================ # example from documentation: https://github.com/cristobalcl/LearningLangChain/blob/master/notebooks/01%20-%20Simple%20Agent.ipynb from langchain.agents import initialize_agent, Tool from langchain_community.llms import OpenAI from typing import Callable llm = OpenAI(temperature=0) # define a looping tool def loop(a_function: Callable, a_collection: list) -> list: # needs Python 3.9 or above print(f"Function: {a_function} Collection: {a_collection}") result = [] for item in a_collection: result.append(a_function(item)) return result def loop2(input: str) -> str: values = input.split("to") start = int(values[0]) end = int(values[1]) result = 0 for i in range(start, end + 1): result += i return str(result) # define 2 tools to experiment with def add(input: str) -> str: values = [int(x) for x in input.split("+")] return str(sum(values)) def is_prime(input: str) -> str: n = int(input) if n <= 1: return "no" if n <= 3: return "yes" if n % 2 == 0 or n % 3 == 0: return "no" i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return "no" i += 6 return "yes" tools = [ Tool( name = "Loop", func=loop, description="Applies a boolean function to each element of a collection and if the function returns true then add the element to the result. Input should be in the form 'function collection'." ), Tool( name = "Add", func=add, description="Useful for when you need to add numbers. Input should be in the form '1 + 2 + 3'." ), Tool( name = "IsPrime", func=is_prime, description="Useful to know if a number is prime." ), ] # initialize the agent agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) def test1(): print(agent.run("If we add 3, 5, 19 20 and 24, is the result a prime number?")) def test2(): print(agent.run("Loop over the collection [10, 11, 12, 13, 14] and test each for being a prime number. Sum up the prime numbers")) def test3(): def foo(x): return x + 1 print(loop(foo, [1, 2, 3, 4, 5])) def test4(): print(loop("1to10")) test2()