Pure Programmer
Blue Matrix


Cluster Map

Project: Frequency Table (Words)

Write a program to generate a table of word frequencies. The program should accept a stream on stdin and total the number of each word seen. Once the stream has been read the program should print a tab-delimited table with columns for the Word, Count, and Frequency. The frequency of each word is the count for that word divided by the total number of words in the file.

You can get books from the [[Project Gutenberg]] site to use in testing your program.

Output
$ swiftc FrequencyTableWords.swift -I . -L . -lUtils FrequencyTableWords.swift:18:54: error: value of type 'NSRegularExpression' has no member 'splitRegex' let words:[String] = NSRegularExpression(##"\W+"##).splitRegex(line!) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~ $ swiftc FrequencyTableWords.swift -I . -L . -lUtils FrequencyTableWords.swift:18:54: error: value of type 'NSRegularExpression' has no member 'splitRegex' let words:[String] = NSRegularExpression(##"\W+"##).splitRegex(line!) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~ $ swiftc FrequencyTableWords.swift -I . -L . -lUtils FrequencyTableWords.swift:18:54: error: value of type 'NSRegularExpression' has no member 'splitRegex' let words:[String] = NSRegularExpression(##"\W+"##).splitRegex(line!) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~

Solution