Write an Erlang program that counts the word frequencies in

 

Write an Erlang program that counts the word frequencies in the file assign3-part2.txt. Erlang uses a list of tuples as a hash table. Write four Erlang functions.

  1. This function has a string file name parameter and returns a list of words in the file. Open the file with file:open. The file lab3-part2.txt was written in a text editor as one line, so io:get_line will read the whole file. string:tokens will separate it into words. Its second argument specifies all the delimiters.
    • file:open(lab3-part2.txt”,read).
    • L1= io:get_line(S, '').
  2. This function has two parameters, a string word and a list of tuples, and returns a list of tuples with the word added appropriately. Each tuple is a word key and a frequency value. The lists:keyfind method will find a tuple if it exists and return false if it does not. If the word is not found use lists:append to add a tuple with the word as key and 1 as the frequency. If the word is found use lists:replace to replace the tuple with a new tuple with frequency increased by one.
  3. This function has a list of words as parameter and returns a hash table of tuples of words and their frequencies. The string:to_lower method will make a word lower case to provided the desired case insensitivity. Use the lists:foldl method to build the answer using the function 2.
  4. This function outputs the final hash table sorted by frequency from high to low using the lists:sort function. Its one parameter is the file name. It uses functions 3 and 1.

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Attached to this question will be attachments with the topic

Attached to this question will be attachments with the topic and rubric of the assignment. Any sources cited must be in APA format. You can use the template or a word document in times new roman, 12-point font, double spacing, and a 1-inch margin. Once the bid has been accepted,

This week you will continue to work on your final

  This week you will continue to work on your final project/presentation that examines in detail one of the major infectious diseases (and the associated microbes) that challenge our world today. By this time, you should have been doing a lot of research on your topic. This Annotated Bibliography assignment

Instructions In this assignment, you will create a presentation for

Instructions In this assignment, you will create a presentation for your organization explaining how successful collaboration can improve success and provide competitive advantages. Scenario: Your organization has used a variety of collaboration systems developed by some project managers. Some of these systems were successful while others were not. Your organization

You have been hired to lead a project (for example,

  You have been hired to lead a project (for example, a relocation of a corporate HQ office), similar to this project, Reliving the past with Marriott deal. As the project manager, you know it is important to get the project  off to a good start. You are working with

     Discussion 5 Gastrointestinal Function: R.H. is a 74-year-old

     Discussion 5 Gastrointestinal Function: R.H. is a 74-year-old black woman, who presents to the family practice clinic for a scheduled appointment. She complains of feeling bloated and constipated for the past month, some-times going an entire week with only one bowel movement. Until this episode, she has been

The internet can be a valuable tool for research and

The internet can be a valuable tool for research and finding information. However, as the notes in previous units showed, teachers many times frown on students using the internet as a research tool because there is the potential that some web pages could contain false or misleading information. Still, the

please describe 3 lessons that can be learned about conflict

please describe 3 lessons that can be learned about conflict resolution with young children. You MUST cite where you exactly you found the information. You MUST also use a minimum of 6 sentences also explain 2 reasons how do you resolve conflict when working in groups with classmates or co-workers.

Report for Health Promotion

-this assignment is in report format, please include executive summary and a very good conclusion -identify and explain the origins of health promotion (extra reading Berridge, V. (2011) Public Health in the 20th century, Gorsky, M., Mold, A., and Berridge, V., (2011), Mold, A. and Berridge, V. (2013) The history

The invention of inductors and the discovery of Lenz’s law

  The invention of inductors and the discovery of Lenz’s law allowed us to  expand our mechanical and electrical systems to perform automatic  physical movements that respond to sensors and transmitters. As we  learned last week, motors and generators are inductive components that  provide physical movement and energy generation. Inductors also

Discussion area a brief description of the organization you selected

  Discussion area a brief description of the organization you selected without revealing the name of the organization and explain the strategic issue that compelled the organization to add or reduce services. Next, describe how the organization bridged the gap between the idea and actual implementation. Then, describe the organization’s key

Progress Report Think of this assignment as a follow-up for

 Progress Report Think of this assignment as a follow-up for your proposal.  Your proposal has been approved.  A contract has been awarded to your organization.  You are now approaching the half way point of the proposed program. Write a progress report in which you give a clear and complete assessment

Review the Congress website and identify one recent (within the

Premium Paper Help is a professional writing service that provides original papers. Our products include academic papers of varying complexity and other personalized services, along with research materials for assistance purposes only. All the materials from our website should be used with proper references.

African History

Abriel Prosser’s Rebellion  Do some Internet research on Gabriel Prosser’s Rebellion (do NOT use Wikipedia or Ask.com or any other non-scholarly website). After you have found and read enough information, develop a ONE-page, double-spaced comparison (in your words) between the Stono Rebellion in South Carolina in 1739 and Prosser’s rebellion. A

Review the following two video transcripts: “Bad Sugar” which explores

  Review the following two video transcripts: “Bad Sugar” which explores the causes and effects of diabetes within two Native American communities. • https://www-tc.pbs.org/unnaturalcauses/assets/resources/badsugar_transcript.pdf and “Place Matters” which connects the dots between health, wealth, and zip codes. • https://www-tc.pbs.org/unnaturalcauses/assets/resources/place_matters_transcript.pdf After reviewing both video transcripts, discuss how the factors listed below can

The SITREP (Situation Report) Sample Report is provided so that

  The SITREP (Situation Report) Sample Report is provided so that you can understand what Cyber Command is expecting in your report. Your report will vary depending on the problem and tool selected. Select one of the seven network problems and develop a troubleshooting and tool report that details the solution.

J.L., a 27-year-old account executive, presents to the family medicine

  J.L., a 27-year-old account executive, presents to the family medicine office for her annual checkup with her primary care provider. She has no significant past medical history except heavy menses. Her medications include calcium carbonate 500 mg orally twice a day and a multivitamin daily. She exercises regularly. Her

Response # 1: Carefully read the initial posts made by

  Response # 1: Carefully read the initial posts made by the other students in your small group. Respond to the initial post of one of your peers in your discussion group. Identify 1 differential diagnosis for the case study presented. Identify the underlying pathophysiology and clinical presentation of the