Author Topic: Make a word list  (Read 4248 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Make a word list
« on: June 15, 2019, 02:27:43 pm »
I started this for Hangman but could come in handy for many things:
Code: QB64: [Select]
  1. _TITLE "Make a word list" 'for QB64 B+ 2019-06-15
  2. DEFINT A-Z
  3. REDIM wordlist(0 TO 0) AS STRING
  4. DIM PetesSpeech$, text$, i, k$, outputFile$
  5.  
  6.  
  7. ' VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV name your output file here  VVVVVVVVVVVVVVVVVVVVVVVVV
  8. outputFile$ = "TestLoad.txt"
  9.  
  10.  
  11. ' default word data for testing
  12. 'PetesSpeech$ = "Interesting age we live in. We now have machines to access information with just a little more time than if we knew (learned) how to do something ourselves. It makes me wonder how often students use these device resources. I hope not to the point where, without a machine backing them up, they'd be nearly uneducated. I mean if a pilot had to land an airliner in the Hudson, I'd rather he know his job and fly the plane in than be Googling how to crash land it while it's going down. Sure, there's always been ways to game the system, frat notes, old tests, etc., but never as much as today. It's just a shame that making our devices smarter makes us go in the opposite direction. The proof of that is a person today is considered an idiot if they don't know how to 'Google' it. You'd think the pride would be in not having to 'Google' it, but no."
  13. 'PetesSpeech$ = PetesSpeech$ + "If this person doesn't return it's a pretty good bet he spent most of what could have been educational time on signing up for as many BASIC programming site as he could find, in hopes someone would post a working code example. Honestly, since coding isn't a core course, I wonder why anyone who would want to learn coding would try so hard not to learn how to code. In a weird way, that's similar to the pilot analogy, except there is a whole different set of consequences when it comes to the crash part."
  14. 'PetesSpeech$ = PetesSpeech$ + "OK, now that I Murphy lawed it, the OP can come back, post some code, get some help, become the next Steve on the forum, and tell me to go shove my CPU where the Sun Microsystems doesn't shine."
  15. '
  16. ' VVVVVVVVVVVVVVVVVVVVVVV  to test above for word list un comment next line  VVVVVVVVVVVVVVVVVVVVV
  17. 'text$ = PetesSpeech$ '
  18.  
  19. '' VVVVVVVVVVVVVVVVVVVV paste in here your own text here and uncomment text$  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  20. 'text$ =
  21.  
  22.  
  23. 'VVVVVVVVVVVVVVVVVVVVVVV  if you want to load text from a file, have file ready named Paste_Into_File.txt VVVVVVVVVVVVVVV
  24. OPEN "Paste_Into_File.txt" FOR BINARY AS #1
  25. text$ = SPACE$(LOF(1))
  26. GET #1, , text$
  27.  
  28.  
  29.  
  30. ' start processing the text$
  31. SpaceOut CHR$(10) + CHR$(13) + ",.!?(){}[]-/_", text$ ' SpaceOut replaces chars with a space
  32. Split1000 text$, " ", wordlist() '                      Split1000 replaces all double spaces to single if " " is delimiter
  33. NoDupeStr wordlist() '                                  remove repeated words
  34. DIM keepers(LBOUND(wordlist) TO UBOUND(wordlist)) '     scanning the list decide what to keep or not
  35. FOR i = LBOUND(wordlist) TO UBOUND(wordlist)
  36.     PRINT wordlist(i);
  37.     PRINT "    <<< press k to keep, spacebar to skip..."
  38.     DO
  39.         k$ = INKEY$
  40.         _LIMIT 60
  41.     LOOP UNTIL k$ = "k" OR k$ = " "
  42.     IF k$ = "k" THEN keepers(i) = -1 ELSE keepers(i) = 0
  43. OPEN outputFile$ FOR OUTPUT AS #1 '                    OK make the file
  44. FOR i = LBOUND(wordlist) TO UBOUND(wordlist)
  45.     IF keepers(i) THEN PRINT #1, wordlist(i)
  46. PRINT: PRINT outputFile$ + " is ready. Goodbye"
  47.  
  48. SUB SpaceOut (Remove$, source$) '    replace undesirable chars with a space
  49.     DIM b$, c$, i
  50.     FOR i = 1 TO LEN(source$)
  51.         c$ = MID$(source$, i, 1)
  52.         IF INSTR(Remove$, c$) = 0 THEN b$ = b$ + c$ ELSE b$ = b$ + " "
  53.     NEXT
  54.     source$ = b$
  55.  
  56. 'a() must be initialized as redim a(lb to ub)
  57. SUB NoDupeStr (a() AS STRING) 'make all the items in the a array unique like a proper set
  58.     DIM i AS LONG, ti AS LONG, j AS LONG, u AS _BIT, lba AS LONG, m
  59.     lba = LBOUND(a)
  60.     REDIM t(lba TO lba) AS STRING
  61.     m = lba
  62.     WHILE a(m) = ""
  63.         m = m + 1
  64.     WEND
  65.     t(lba) = a(m): ti = lba
  66.     FOR i = m + 1 TO UBOUND(a)
  67.         u = -1
  68.         IF a(i) <> "" THEN 'get rid of blanks
  69.             FOR j = 1 TO ti
  70.                 IF a(i) = t(j) THEN u = 0: EXIT FOR
  71.             NEXT
  72.             IF u THEN
  73.                 ti = ti + 1
  74.                 REDIM _PRESERVE t(LBOUND(a) TO ti)
  75.                 t(ti) = a(i)
  76.             END IF
  77.         END IF
  78.     NEXT
  79.     REDIM _PRESERVE a(lba TO ti)
  80.     FOR i = lba TO ti
  81.         a(i) = t(i)
  82.     NEXT
  83.  
  84. 'notes: REDIM the array(0) to be loaded before calling Split '<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT!!!!
  85. SUB Split1000 (mystr AS STRING, delim AS STRING, arr() AS STRING)
  86.     ' bplus modifications of Galleon fix of Bulrush Split reply #13
  87.     ' http://xmaxw.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1612.0
  88.     ' this sub further developed and tested here: \test\Strings\Split test.bas
  89.     DIM copy AS STRING, p AS LONG, curpos AS LONG, arrpos AS LONG, dpos AS LONG, LD AS INTEGER
  90.  
  91.     copy = mystr 'make copy since we are messing with mystr when the delimiter is a space
  92.  
  93.     'special case if delim is space, probably want to remove all excess space
  94.     IF delim = " " THEN
  95.         copy = RTRIM$(LTRIM$(copy))
  96.         p = INSTR(copy, "  ")
  97.         WHILE p > 0
  98.             copy = MID$(copy, 1, p - 1) + MID$(copy, p + 1)
  99.             p = INSTR(copy, "  ")
  100.         WEND
  101.     END IF
  102.  
  103.     curpos = 1
  104.     arrpos = 0
  105.     LD = LEN(delim) 'mod
  106.     dpos = INSTR(curpos, copy, delim)
  107.     DO UNTIL dpos = 0
  108.         arr(arrpos) = MID$(copy, curpos, dpos - curpos)
  109.         arrpos = arrpos + 1
  110.         IF arrpos > UBOUND(arr) THEN REDIM _PRESERVE arr(UBOUND(arr) + 1000) AS STRING
  111.         curpos = dpos + LD
  112.         dpos = INSTR(curpos, copy, delim)
  113.     LOOP
  114.     arr(arrpos) = MID$(copy, curpos)
  115.     REDIM _PRESERVE arr(arrpos) AS STRING 'need this line? YES to get the ubound correct
  116.  
  117.  

I copied text from here:
https://www.qb64.org/forum/index.php?topic=1395.0

And made up this list:
Code: [Select]
month
Outdoor
Sometimes
think
difference
between
people
digress
issues
realize
decide
about
speech
point
where
simple
unified
against
country
bunch
around
because
thought
caught
message
truth
anyone
equality
really
whatever
today
cowardly
cross
their
afraid
considered
idiots
rather
little
better
perfect
planet
someone
decisions
beyond
figure
reason
period
common

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Make a word list
« Reply #1 on: June 15, 2019, 02:42:07 pm »
You left out all my really "good" words! :D

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Make a word list
« Reply #2 on: June 15, 2019, 03:01:09 pm »
You left out all my really "good" words! :D

Pete

LOL, yeah I guess people will have to become members to read Off-Topic words :D
« Last Edit: June 15, 2019, 03:18:13 pm by bplus »

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: Make a word list
« Reply #3 on: June 15, 2019, 05:57:13 pm »
Now I can have words with Pete! Its like Eliza but with Pete. Nice.
QB64 is the best!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Make a word list
« Reply #4 on: June 15, 2019, 06:01:47 pm »
Just remember.... I'm up here!!!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Make a word list
« Reply #5 on: June 15, 2019, 06:11:48 pm »
Here’s where I did something similar, to generate a word list and even word count, from a text source: http://qb64.freeforums.net/thread/41/word-count-list-generator
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!