{"id":61442,"date":"2022-05-16T00:36:00","date_gmt":"2022-05-16T00:36:00","guid":{"rendered":"https:\/\/assignmenttutors.net\/blog\/erlang-program-computer-science-homework-help\/"},"modified":"2022-05-16T00:36:00","modified_gmt":"2022-05-16T00:36:00","slug":"erlang-program-computer-science-homework-help","status":"publish","type":"post","link":"https:\/\/assignmenttutors.net\/blog\/erlang-program-computer-science-homework-help\/","title":{"rendered":"Erlang program | Computer Science homework help"},"content":{"rendered":"<div>\n<p>\u00a0<\/p>\n<p>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.<\/p>\n<ol>\n<li>This function has a string file name parameter and returns a list of words in the file. Open the file with <code>file:open<\/code>. The file <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/Giacalone-CECS\/functional-programming-with-erlang-deanchen95\/blob\/main\/lab3-part2.txt\">lab3-part2.txt<\/a> was written in a text editor as one line, so <code>io:get_line<\/code> will read the whole file. <code>string:tokens<\/code> will separate it into words. Its second argument specifies all the delimiters.\n<ul>\n<li><code>file:open(lab3-part2.txt\u201d,read).<\/code><\/li>\n<li><code>L1= io:get_line(S, '').<\/code><\/li>\n<\/ul>\n<\/li>\n<li>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 <code>lists:keyfind<\/code> method will find a tuple if it exists and return false if it does not. If the word is not found use <code>lists:append<\/code> to add a tuple with the word as key and <code>1<\/code> as the frequency. If the word is found use <code>lists:replace<\/code> to replace the tuple with a new tuple with frequency increased by one.<\/li>\n<li>This function has a list of words as parameter and returns a hash table of tuples of words and their frequencies. The <code>string:to_lower<\/code> method will make a word lower case to provided the desired case insensitivity. Use the <code>lists:foldl<\/code> method to build the answer using the function <code>2<\/code>.<\/li>\n<li>This function outputs the final hash table sorted by frequency from high to low using the <code>lists:sort<\/code> function. Its one parameter is the file name. It uses functions <code>3<\/code> and <code>1<\/code>.<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 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. 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-61442","post","type-post","status-publish","format-standard","hentry","category-education"],"_links":{"self":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/61442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/comments?post=61442"}],"version-history":[{"count":0,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/61442\/revisions"}],"wp:attachment":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/media?parent=61442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/categories?post=61442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/tags?post=61442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}