_TITLE "Ngrams 1" 'started 2019-04-20 B+ ' ref: Daniel Shiffman Coding Challenge #42.1 Markov Chains Part 1
' [youtube]https://www.youtube.com/watch?v=eGFJ8vugIWA&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH[/youtube]&index=52
' Basically take some text, collect all unique nGrams of a certain length, the gram.
' Collect all the letters that follow a gram in the text in nextChar string.
' Create a new random text with same nGrams based on random selection of following chars.
'setup the grams
nextGI = 1
'get some text, this might be fun
txt$ = txt$ + t$
'PRINT txt$
'Load the grams array
ngCandidate$
= MID$(txt$
, i
, ngLen
) 'PRINT "ngCandidate$ "; ngCandidate$
found = find(ngCandidate$)
'PRINT "found "; found
'add to grams
grams(nextGI).gram = ngCandidate$
grams
(nextGI
).nextChar
= MID$(txt$
, i
+ ngLen
, 1) 'sort grams
QSort 1, nextGI
'FOR i = 1 TO nextGI
' PRINT grams(i).gram, grams(i).nextChar
'NEXT
nextGI = nextGI + 1
grams
(found
).nextChar
= grams
(found
).nextChar
+ "~" + MID$(txt$
, i
+ ngLen
, 1) 'INPUT "OK press enter..."; wate$
'check load
'FOR i = 1 TO nextGI
' PRINT grams(i).gram, grams(i).nextChar
' IF i MOD 20 = 0 THEN
' PRINT: INPUT "OK, press enter...", wate$
' CLS
' END IF
'NEXT
'generate random text
'find a gram that starts with a Capital letter, dang it's always the same start!
i
= INT(RND * (nextGI
- 1)) + 1 rtxt$ = grams(i).gram
rtxt$ = rtxt$ + grams(i).nextChar
Split1000 grams
(i
).nextChar
, "~", select$
() i = i + 1
'PRINT rtxt$, LEN(rtxt$)
g$
= MID$(rtxt$
, LEN(rtxt$
) - ngLen
+ 1) found = find(g$)
rtxt$ = rtxt$ + grams(found).nextChar
Split1000 grams
(found
).nextChar
, "~", select$
() rtxt$ = rtxt$ + " "
SUB QSort
(Start
, Finish
) 'shownK needs to be shared array i = Start
j = Finish
m$
= grams
(INT((i
+ j
) / 2)).gram
i = i + 1
j = j - 1
i = i + 1
j = j - 1
IF j
> Start
THEN QSort Start
, j
IF i
< Finish
THEN QSort i
, Finish
low = 1: hi = nextGI - 1
test = (low + hi) \ 2
IF grams
(test
).gram
< x$
THEN low
= test
+ 1 ELSE hi
= test
- 1
'notes: REDIM the array(0) to be loaded before calling Split '<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT!!!!
' bplus modifications of Galleon fix of Bulrush Split reply #13
' http://xmaxw.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1612.0
' this sub further developed and tested here: \test\Strings\Split test.bas
copy = mystr 'make copy since we are messing with mystr when the delimiter is a space
'special case if delim is space, probably want to remove all excess space
copy
= MID$(copy
, 1, p
- 1) + MID$(copy
, p
+ 1) curpos = 1
arrpos = 0
dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
)
"Pete replies.txt" file, copy and paste into file or find your own text to play with.
I'm just glad I can count on The Rho to fill in for me when I'm too busy not being a misogynist to reply to a post. Men and women are different biologically and psychologically, period. Women don't gravitate to programming like men do Probably math has something to do with that, but it probably goes deeper. It's just fun to point out the obvious math part. I ran into this same question when I coached golf. How can we get more girls interested in the game? Well, it's simple, change the game. Girls wanted it to be more a social outing. Guys, on the other hand, play real golf! Kidding aside, guys like playing more to compete. They socialize, too, but to a lesser degree. It's more about shot-making than. I mean you could probably pick 10 similarities men and women golfers have in common, but they would rank radically different in importance. If any girls or women want to post or visit the forums, great, but be advised it is male dominate, period. That's not going to change unless more females get interested in coding. Frankly, if enough females wee coding back in the QBasic age, I would have put one in charge of a ladies sub-forum. I wouldn't exclude males from posting, but I would want to see it develop in a way that was somehow different than the predominately, nearly all male forum. It's a bit of a tangent, but all this parity BS of today is not for the sake of equality, it's so liberals can suck votes out of simpletons to keep their liberal communist dream for power alive and moving forward. It's a lot less less work than coming up with actual beneficial ideas for a free society, because then there would be less pathetic losers looking for handouts. In the U.S., already more than 50% of the workforce is female; so now Bolsheviks want to try and make people believe there is income inequality. Well duh. If most of the workforce was male before, there is this little thing called seniority that means males, who have been at the job longer, are being paid higher. When that changes, either something else will replace it like women aren't getting enough respect, or some other BS "inequality" topic will be all the fake news talks about 24/7. Anyway, my gut tells me Qwerkey is just asking about ways to get more females interested in coding, for non-political reasons. Men and women are different, and it's nice to have a larger number of your gender to relate to on social platforms. There are other good reasons, too, such as the practical aspects of knowing how to program, including good jobs. What's cool about places today that are free capitalistic governments is that all of these opportunities are available, but if psychological makeup (not made by the Covergirl corporation) has anything to say about it, you'd probably have to get pretty inventive with the Woman's club concept I touched on, earlier, to make it happen. Well then so much for the fake news bozos, who would love women to think they should get involved with programming. My take on it is even if more women did, they'd be too high maintenance for most companies, requiring way too much FORTRAN before any real coding got done.
PS for creative word creation try setting
the gram length to a shorter 3 or 4.