Word Counting
No preview image
Model was written in NetLogo 5.0.5
•
Viewed 279 times
•
Downloaded 20 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
extensions [mapreduce] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Mapper ;;;; Read the line of a file, split it into words, emit word ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to read-file [file-name words] ;;; Loop over all words foreach words [ ;;; emit:mapreduce:emit ? "1" ; ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Reducer ;;;; Sum up the occurrences of a word ;;;; key the word ;;;; accum current count ;;;; value next value ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report word-count [key acum value] report acum + read-from-string value end to server mapreduce:acceptworkers end to node mapreduce:node.connect "127.0.0.1" 9173 end to count-words let words [] let runit true reset-ticks ;;; Tell MapReduce that a line has words, separated by spaces mapreduce:config.valueseparator " " ;;; Start the MapReduce computation let res mapreduce:mapreduce "read-file" "word-count" 0 data-set ;;; Wait or the computation to finish and display the progress while [mapreduce:running?] [ every 0.5 [ print mapreduce:map-progress print mapreduce:reduce-progress ; plot 1 tick ] ] tick print "done" ;;; Print the result show mapreduce:result res tick end
There is only one version of this model, created over 10 years ago by Martin Dobiasch.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
datasets.tar.gz | data | Some sample data sets for Word Counting | over 10 years ago, by Martin Dobiasch | Download |
This model does not have any ancestors.
This model does not have any descendants.