home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / txtutl / fig.arc / FIG.BAS next >
Encoding:
BASIC Source File  |  1988-04-29  |  4.4 KB  |  128 lines

  1. 1010 ' Initialization
  2. 1020 DEFINT A-Z
  3. 1030 OPTION BASE 1
  4. 1040 '
  5. 1050 ' Integers
  6. 1060 LC = 0 ' line counter
  7. 1070 WC = 0 ' word counter
  8. 1080 SC = 0 ' sentence counter
  9. 1090 INWORD = 0 ' currently building a word? (true/false)
  10. 1100 WORPART = 0 ' part of a word? (true/false)
  11. 1110 ENOUGH = 0 ' over 400 words and at end of sentence? (true/false)
  12. 1120 '
  13. 1130 ' Strings
  14. 1140 A$ = "" ' most frequently manipulated string
  15. 1150 AN$ = "abcdefghijklmnopqrstuvwxyz'1234567890" ' alpha-numerics (kinda)
  16. 1160 ST$ = ".!?" ' sentence terminators
  17. 1170 AP$ = ";,)-" + CHR$(34) ' other anotated punctuation
  18. 1180 '
  19. 1190 ' Integer Arrays
  20. 1200 DIM STC(3) ' sentence type counters.  Note 3 = LEN(ST$)
  21. 1210 DIM APC(5) ' other annotated punctuation counters.  Note 5 = LEN(AP$)  
  22. 1220 '
  23. 1230 ' String Arrays
  24. 1240 DIM TEXT$(100) ' storage for text lines
  25. 1250 DIM WORD$(500) ' word list
  26. 1260 '
  27. 1270 ' Get Filename
  28. 1280 INPUT "File to analyze"; F$
  29. 1290 OPEN "I", 1, F$ ' open requested file for input
  30. 1300 '
  31. 1310 ' Read the file
  32. 1320 PRINT "Reading " F$ ", ";
  33. 1330 WHILE (NOT EOF(1)) AND (LC<100)
  34. 1340 LC=LC+1
  35. 1350 LINE INPUT #1, TEXT$(LC)
  36. 1360 WEND
  37. 1370 CLOSE
  38. 1380 '
  39. 1390 ' build word list
  40. 1400 PRINT "counting words/punctuation, ";
  41. 1410 FOR CL = 1 TO LC
  42. 1420 IF ENOUGH THEN 1610 ' to: @ENDLINE
  43. 1430 FOR CP = 1 TO LEN(TEXT$(CL))
  44. 1440 A$ = MID$(TEXT$(CL),CP,1) ' point to current character
  45. 1450 ' punctuation checks
  46. 1460 ST = INSTR(ST$,A$) ' sentence termination
  47. 1470 IF ST<>0 THEN SC=SC+1:STC(ST)=STC(ST)+1:IF WC>450 THEN ENOUGH=-1:ELSE INWORD=0
  48. 1480 IF ENOUGH THEN 1560 ' to: @ENDWORD
  49. 1490 PC = INSTR(AP$,A$) ' othar annotated punctuation
  50. 1500 IF PC<>0 THEN APC(PC)=APC(PC)+1 : INWORD = 0
  51. 1510 'word build and counter
  52. 1520 WORDPART = INSTR(AN$,A$) <> 0 ' is this part of a word?
  53. 1530 IF NOT WORDPART THEN INWORD = 0
  54. 1540 IF WORDPART AND NOT INWORD THEN WC = WC + 1 : INWORD = -1
  55. 1550 IF INWORD THEN WORD$(WC)=WORD$(WC)+A$
  56. 1560 '@ENDWORD
  57. 1570 NEXT CP
  58. 1580 ' at end of line, bump word counter
  59. 1590 IF INWORD AND (NOT ENOUGH) THEN WC=WC+1
  60. 1600 IF WC=500 THEN ENOUGH=-1
  61. 1610 '@ENDLINE
  62. 1620 NEXT CL
  63. 1630 '
  64. 1640 ' word lengths calculations
  65. 1650 PRINT "calculating:"
  66. 1660 FOR I=1 TO WC
  67. 1670 IF LEN(WORD$(I))=>5 AND LEN(WORD$(I))=<9 THEN MD=MD+1
  68. 1680 IF LEN(WORD$(I))=>10 THEN SF=SF+1
  69. 1690 IF LEN(WORD$(I))=8 THEN MW=MW+1
  70. 1700 IF LEN(WORD$(I))=9 THEN LW=LW+1
  71. 1710 NEXT I
  72. 1720 '
  73. 1730 ' other calculations
  74. 1740 AV=INT((WC/SC)+.5)
  75. 1750 SF=INT((SF+(.8*LW)+(.45*MW))+.5)
  76. 1760 SW=INT((((WC-(SF+MD))*100)/WC)+.5)
  77. 1770 MW=INT(((MD*100)/WC)+.5)
  78. 1780 LW=INT(((SF*100)/WC)+.5)
  79. 1790 ML=INT((((MD+SF)/WC)*100)+.5)
  80. 1800 FI=INT((((AV)+((SF*100)/WC))*.4)+.5)
  81. 1810 '
  82. 1820 '@REPORT
  83. 1830 ' report word and sentence count, average length
  84. 1840 PRINT
  85. 1850 PRINT "Scanned" WC "words in" SC "sentences."
  86. 1860 PRINT "Average sentence length:" AV "words."
  87. 1870 IF AV>19 THEN PRINT " ->  Sentences may be too wordy."
  88. 1880 '
  89. 1890 ' report sentence type, usage
  90. 1900 PRINT
  91. 1910 PRINT STC(1) "direct statement(s)"
  92. 1920 PRINT APC(3) "parenenthetical remarks"
  93. 1930 IF APC(3)*4 > SC THEN PRINT " ->  Could some of these `asides' stand alone?"
  94. 1940 PRINT STC(2) "exclamation(s)"
  95. 1950 IF STC(2)*8 > SC THEN PRINT " ->  Calm down.  Why are you shouting?"
  96. 1960 PRINT STC(3) "question(s)"
  97. 1970 IF STC(3)*5 > SC THEN PRINT " ->  Is this some kind of test?  Or rhetorical?"
  98. 1980 '
  99. 1990 ' report subordinate clause usage
  100. 2000 PRINT APC(1) "semicolons"
  101. 2010 IF APC(1)*3 > SC THEN PRINT " ->  Try making clauses into separate sentences."
  102. 2020 PRINT APC(2) "commas"
  103. 2030 IF APC(2) > SC THEN PRINT " ->  Try making clauses into separate sentences."
  104. 2040 '
  105. 2050 ' report other punctuation notes
  106. 2060 PRINT
  107. 2070 PRINT "Miscellaneous: "APC(4) "hyphen(s); " INT((APC(5)/2)+.5) "quote(s)."
  108. 2080 '
  109. 2090 ' word length and usage notes
  110. 2100 PRINT
  111. 2110 PRINT "% Short words:   "; SW; "(all figures rounded)"
  112. 2120 PRINT "% Medium words:  "; MW
  113. 2130 PRINT "% Long words:    "; LW
  114. 2140 PRINT "% Medium & Long: "; ML
  115. 2150 IF ML > 50 THEN PRINT "->  Try to use shorter words"
  116. 2160 PRINT
  117. 2170 PRINT " ->  FOG Index:  "; FI
  118. 2180 '
  119. 2190 '
  120. 2200 ' make sure user got a chance to read it all
  121. 2210 PRINT
  122. 2220 PRINT "Repeat display (Y/n)?  ";
  123. 2230 A$=INPUT$(1)
  124. 2240 IF INSTR("Nn",A$)=0 THEN PRINT "Yes" : GOTO 1820 ' to: @REPORT
  125. 2250 PRINT "No";
  126. 2260 '
  127. 2270 END
  128.