
![]() |
nop_90
-module( markov ![]() -export([load/1,make_sentence/1]). clean_unicode([]) -> []; clean_unicode([H|T]) when H >= 127;H < 32 -> clean_unicode(T); clean_unicode([H|T]) -> [H|clean_unicode(T)]. %{key,total,word_list} load_sentence(MTable,[W1|[]]) -> W2 = stop, case ets:lookup(MTable,W1) of [] -> ets:insert(MTable,{W1,1,dict:update_counter(W2,1,dict:new())}); [{_,Total,NextDict}] -> ets:insert(MTable, {W1,Total+1, dict:update_counter(W2,1,NextDict)}) end; load_sentence(MTable,[W1,W2|Rest]) -> case ets:lookup(MTable,W1) of [] -> ets:insert(MTable,{W1,1,dict:update_counter(W2,1,dict:new())}); [{_,Total,NextDict}] -> ets:insert(MTable, {W1,Total+1, dict:update_counter(W2,1,NextDict)}) end, load_sentence(MTable,[W2|Rest]). load_lines(H,MTable,eof) -> file:close(H), ok; load_lines(H,MTable,Sentence) -> load_sentence(MTable,[start|string:tokens(clean_unicode(Sentence)," " ![]() load_lines(H,MTable,io:get_line(H,'')). load(FileName) -> MTable = ets:new( markov,[set]),{ok,H} = file ![]() load_lines(H,MTable,io:get_line(H,'')), MTable . walk_next([{Key,Value}|[]],_,_) -> Key ; walk_next([{Key,Value}|Rest],Height,Sum) when Height =< Sum -> Key markov:make_sentence(M).; walk_next([{Key,Value}|Rest],Height,Sum)-> %io:format("~s ~w ~n", [Key,Value]), walk_next(Rest,Height,Sum+Value) . make_sentence(MTable,Seed) -> [{_,Total,NextDict}] = ets:lookup(MTable,Seed), Height = random:uniform(Total)-1, case walk_next(dict:to_list(NextDict),Height,0) of stop -> " "; NextSeed -> NextSeed ++ " " ++ make_sentence(MTable,NextSeed) end . make_sentence(MTable) -> try make_sentence(MTable,start) catch error:X -> error end. perkiset
Shittah man... you told me you were still just "looking" at
Erlang... that's a helluva view![]() Erlangas an exercise? I can't read it very well yet, but it doesn't look to be taking advantage of the multithreadedness... ?Guess I'm, gonna haveta get the Beta of the book you pointed me towards just to read that... Aside: hows the performance as opposed to straight up PythonorPHP?/p nop_90
Yah just an exercise. But way to test something is to push it until it busts
![]() ![]() ![]() Salesmen in stores love me ![]() Basically it is an in memory hashtable which points to a hash for each word. (except this inmemory hashtable is part of the language). structure looks like this hashtable[firstword]-> innerhashtable[secondword] = count. To load a 5MB file of sentences takes over 5 mins. But once the markovtree is build you can pickle (i am stealingpythonteminology) and dump it to disk.That is vey quick 5 secs. Also to load from disk is very quick. You can not really compare to php/pythonsince they do not have whaterlangcalls an <>ets> structure.http://www. erlang.org/doc/doc-5.5.4/lib/stdlib-1.14.4/doc/html/index.html docs about this ets structure.This structure from what i read ap pears to be very fast (that is why i am makingmarkovwith it).I have not done timing on making the sentences. I am going to make a static site generator and see how that works. You can not really compare to python/phpsince they do not have similar structure.Language is quirky, a wierd cross between prolog,lisp and python![]() Anyway still exploring. You making me crack the books. The book saids that to make use of multiple CPU u have to use multiple process. (process in erlangis like a thread i think![]() So Basically once the markovstructure is build, it is safe to access from many process at once, so have like 10 process making text, according to the book if u have 10 cpuerlangmake it use them properly![]() Have not gotten to that part of book yet about process ![]() KaptainKrayola
quote author=perkiset link=topic=170.msg1009#msg1009 date=1178509187 Shittah man... you told me you were still just "looking" at Erlang... that's a helluva view![]() nop is a high powered mutant of some kind never even considered for mass production, crazy. |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads