home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / mir / 14analyz < prev    next >
Text File  |  1992-07-01  |  34KB  |  868 lines

  1.  
  2.  
  3.             ════════════════════════════════════════
  4.  
  5.               4.    FIRST STEPS IN DATA ANALYSIS
  6.  
  7.             ════════════════════════════════════════
  8.  
  9.  
  10.         ══════════════════════
  11. 4.1           Objectives
  12.         ══════════════════════
  13.  
  14.             Let's imagine that you have been assigned an indexing
  15. project.  You are to prepare an indexed version of a large
  16. database, ready for other people to search in it for information.
  17. How shall you proceed?  In this topic, we deal with first steps in
  18. hands-on analysis of machine-readable databases.
  19.  
  20.             You may have to start by fending off shortcuts.  Some
  21. managers and clients want work completed yesterday.  The first
  22. question you are asked is: "How long is it going to take?"  "The
  23. data is the same as last time; we want only a few minor changes. 
  24. This won't take very long, will it?"  Refuse any time estimate
  25. until your analysis is complete.  The ultimate objective is a
  26. satisfied user.  Shortcuts at the analysis and specification stage
  27. rarely (make that "never") serve that objective.  The best strategy
  28. is to write time estimates once the project is fully specified in
  29. writing and the data has been analyzed.
  30.  
  31.             Analysis logically comes before data preparation; we
  32. can't prepare something for indexing until we know what we have. 
  33. If we are dealing with familiar data, we still have to watch for
  34. data quality problems... inconsistencies or unexpected patterns
  35. that are common within large accumulations of data.
  36.  
  37.             The analysis stage provides information that is needed
  38. to prepare the data.  After analyzing the data, we should have
  39. enough information so that we will be able to:
  40.  
  41.         »   extract searchable content, that is, separate out
  42.             displayable text with punctuation and each search term
  43.             (word, phrase, numeric value, etc.) intact, at the same
  44.             time screening out all material that is not part of the
  45.             intended display;
  46.  
  47.         »   recognize record separations, that is, identify
  48.             divisions between units in cases where data is
  49.             logically divided into units which are meaningful to
  50.             the searcher (a property in a real estate file, a
  51.             person in a personnel file, a subsection in a manual of
  52.             regulations, a heading in a book or magazine article,
  53.             etc.);
  54.  
  55.         »   recognize field separations, that is, identify
  56.             divisions between elements of data that take on
  57.             different meaning according to where they occur within
  58.             a record.  Examples of fields... purchase order number,
  59.             street address, city, postal code, quantity, item
  60.             description, cost per unit, etc.
  61.  
  62.         »   recognize formatting aids, that is, identify bytes
  63.             within the data that are intended to control display of
  64.             data... indents from the margin, shifts to different
  65.             fonts (e.g., italics), table spacing, etc.
  66.  
  67.             This may strike you as simply finding out what is
  68. needed to reduce data to formatted printable text.  In a sense, it
  69. is.  But there are some pitfalls along the way.  The trick is to be
  70. able to recognize the pitfalls early in the indexing process while
  71. the costs are still low.  It's quite discouraging to index a
  72. billion bytes and then find the index list contains large numbers
  73. of false or meaningless search terms.
  74.  
  75.  
  76.         ══════════════════════════════════════════════
  77. 4.2           Learn how the data was accumulated
  78.         ══════════════════════════════════════════════
  79.  
  80.             Ask questions.  The data came from somewhere.  How was
  81. the data put together?  Specifically:
  82.  
  83.         »   Was the same method used consistently to assemble all
  84.             the data?  Or were there changes along the way?  (If
  85.             methods or programs changed, then each subset of data
  86.             must be separately analyzed.)  If possible, find out
  87.             why the data-gathering method changed.  Was the change
  88.             prompted by a quality control problem, or the
  89.             introduction of new technology?  In either case, check
  90.             the first part of the new data carefully for errors. 
  91.             Starting up in unfamiliar surroundings can lead to
  92.             extra errors for a while.  If the change was made on
  93.             account of quality control problems, re-check the
  94.             portion of data created just before the change.
  95.  
  96.         »   Was the data scanned from print media?  Which scanning
  97.             technology and software were used?  What was the
  98.             release date of that software?  What was the quality of
  99.             the print media?  Was the layout regular?  How
  100.             thoroughly has the result been checked for reliability?
  101.  
  102.         »   If keypunching was used as a low cost substitute for
  103.             scanning printed material, were the keypunchers and
  104.             their supervisors familiar with the subject matter? 
  105.             Were they working in their own language?  What methods
  106.             of verification were used?  (For example, keying by a
  107.             second operator is not always reliable.)  How much
  108.             pressure were the keyers under?  Were they being
  109.             monitored and paid by the kilo-keystroke as has often
  110.             been the case?  People under pressure tend to make more
  111.             errors than those working "at their own pace".
  112.  
  113.         »   Has the data been used and updated in ways that would
  114.             sift out errors?
  115.  
  116.  
  117.         ═══════════════════════════════════════════
  118. 4.3           Learn how the data will be used
  119.         ═══════════════════════════════════════════
  120.  
  121.             Put yourself in the position of a person searching
  122. within this database.  Don't settle for educated guesses; find out
  123. for whom the data is being indexed and ask questions:  What are the
  124. needs of prospective searchers?  How do they look for information
  125. now: manually, using a mainframe computer, not at all?  In what
  126. ways can the indexing setup add to the value of the data for their
  127. needs?  (For example, a computerized phone book can be organized
  128. one way to create mailing lists, in quite another to optimize the
  129. speed of looking up individual names.)  What kinds of search term
  130. combinations are typically used?   Perhaps some forms of search
  131. were deemed impractical in the past.  If searchers were invited to
  132. imagine away all restrictions, what would they like to be able to
  133. do?
  134.  
  135.             Marketing questions are often outside the interests of
  136. technical people.  That's unfortunate, since all sorts of technical
  137. side trips to nowhere might be avoided by interviewing even a few
  138. potential end users.
  139.  
  140.  
  141.         ═══════════════════════════════════════════
  142. 4.4           Access to samples and hard copy
  143.         ═══════════════════════════════════════════
  144.  
  145.             After acquiring technical background re the data and
  146. marketing information on potential users, the key issues are:
  147.  
  148.         »   access to the data on media that can be handled by your
  149.             computer.  Non-standard media still exist.  ("I just
  150.             received the diskettes from the first volume on 8 inch
  151.             disks"... letter in February 1992).  And there are
  152.             standard media that may not be useful to you... nine
  153.             track 6250 BPI tape doesn't feed the average personal
  154.             computer;  1.2 megabyte floppies aren't worth much on
  155.             a 360K floppy drive.
  156.  
  157.         »   ability to extract samples that are representative. 
  158.             This depends in part on the degree of consistency of
  159.             the data.  Pay particular attention to the first
  160.             several thousand bytes, and the very last several
  161.             thousand bytes.  If the data set is large, extract
  162.             randomly selected portions in between.  If there are
  163.             known changes in how the data was accumulated, put
  164.             together samples from each variation.
  165.  
  166.         »   access to hard copy.  If at all possible, get paper
  167.             printouts that match the samples.  The paper version is
  168.             helpful for identifying format and typesetting codes. 
  169.             The way the hard copy is laid out also tells volumes
  170.             about the search philosophy used to date.  Ask users
  171.             how well the printed layout served their needs.
  172.  
  173.  
  174.         ════════════════════════════════════
  175. 4.5           Access to software tools
  176.         ════════════════════════════════════
  177.  
  178.             A variety of programs (software tools) are supplied
  179. with each tutorial, in source code and in executable form.  Source
  180. code has the extension ".C" and the DOS executable normally has the
  181. extension ".EXE".  There is also the occasional batch file, a
  182. series of commands in a simple text file that can be interpreted by
  183. DOS.  If you have not already done so, include the directory that
  184. has the executable version in the series of PATH names in the
  185. AUTOEXEC.BAT file on your computer.  Each program has a
  186. description, or help screen, which is displayed when you input the
  187. command (the program name without the extension) followed by /U
  188. (for Usage) or ? (for help).  Normally we will include the help
  189. screen in the tutorial the first time a program is mentioned.
  190.  
  191.  
  192.         ════════════════════════════════════════════════
  193. 4.6           Extracting samples from larger files
  194.         ════════════════════════════════════════════════
  195.  
  196.         The program CPB (copy bytes) is useful for extracting
  197. samples from larger files.  Here is its help screen description:
  198.  
  199. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  200. Usage   cpb  byte_count  start_byte  input_file  output_file
  201.  
  202.         Copy bytes...  Copy any portion of any file to a new file.
  203.         Start at a specified byte, copy a specified byte count.
  204.         Standard output may not be used because DOS drops carriage
  205.         returns and CTL-Z.
  206.  
  207. input:  Any file whatsoever.
  208.  
  209. output: Portion of the same file.
  210.  
  211. writeup: MIR TUTORIAL ONE, topic 4
  212. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  213.  
  214.             Suppose you wish to separate out the first 10,000 bytes
  215. of a file named BIG_DATA into a file called SAMPLE.000.  The
  216. command would be:
  217.  
  218.                 CPB 10000 0 BIG_DATA SAMPLE.000
  219.  
  220. To isolate 7,500 bytes from the middle of a 200,000 byte file, the
  221. command takes the form:
  222.  
  223.                 CPB 7500 100000 BIG_ONE MY_SAMPL
  224.  
  225. CPB (copy bytes) is particularly useful for massive files.  Here's
  226. how to call out a sample between 4,000 and 5,000 bytes in length
  227. from the end of a file that is 248,885,237 bytes long:
  228.  
  229.                 CPB 5000 248881000 BIGGER.YET BIGGER.END
  230.  
  231. The file BIGGER.END in this case would be 4,237 bytes long.  CPB
  232. simply stops copying when it reaches the end of the input file.
  233.  
  234.             Sampling is one of many uses of CPB.  We will use it in
  235. a variety of ways further along.
  236.  
  237.             If you wish to make a UNIX version of CPB, consider
  238. removing the input and output file names and using standard input
  239. and output instead.  That is safe since UNIX does not quietly mess
  240. up on carriage returns and CTL-Z characters.  The advantage of
  241. standard input and output is the convenience of piping from one
  242. program to another without the clutter of intervening files.
  243.  
  244.  
  245.  
  246.         ═══════════════════════════════════════════
  247. 4.7           Byte surveys - a worked example
  248.         ═══════════════════════════════════════════
  249.  
  250.             We start the analysis with a byte survey of each
  251. sample, or of one file that combines all your data samples.  If you
  252. choose to combine samples, use the DOS COPY command to join them
  253. together, being very sure to use the "/b" binary flag:
  254.  
  255.                 COPY /B HEADER + BATCH1 + BATCH2 + TAIL  BIG_ONE
  256.  
  257. The destination file BIG_ONE has the four source files concatenated
  258. together in order: HEADER, BATCH1, BATCH2, TAIL.
  259.  
  260.             If you have a series of files named SAMPLE.001,
  261. SAMPLE.002, SAMPLE.003, etc.,
  262.  
  263.                 COPY /B SAMPLE.* BIG_ONE
  264.  
  265.             Included among the MIR support files supplied with
  266. TUTORIAL ONE is a 238,312 byte file SVP_TXT.  This file contains
  267. English translation of some 17th century correspondence of the
  268. French priest and reformer, Vincent de Paul, who founded the
  269. "Congregation of the Mission".  The Vincentians, generous as
  270. always, have given permission to use the correspondence for an
  271. example in demonstrating indexing and retrieval methods.
  272.  
  273.             The file SVP_TXT is used here to introduce tools and
  274. first steps in data analysis.  The file's quarter megabyte size is
  275. no problem.  For example, the program A_BYTES classifies and counts
  276. every one of the 238,312 bytes in only four seconds on a slow
  277. machine (AT 80286 at 12 Megahertz).
  278.  
  279.             The character survey is produced by the program A_BYTES
  280. ("analyze bytes")...
  281.  
  282. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  283. usage:  a_bytes [ /L ] file_name[s]
  284.  
  285.         Analyze the bytes (characters) used within any file, report
  286.         the frequency of each byte present.  If the location flag
  287.         /L is set, include offsets of the first 8 occurrences of
  288.         each byte pattern present.
  289.  
  290. input:  Any file[s] whatsoever.
  291.  
  292. output: file_name.BYT which contains up to 256 lines, one line for
  293.         each different byte present.  The byte is shown first in
  294.         printable OR octal form, then the hexadecimal equivalent.
  295.         The third column is frequency.  The fourth column shows
  296.         percentage of total occurrences within the file.
  297.  
  298.         If the /L locations option is selected, the output file is
  299.         name file_name.LOC and the offsets of the first up to 8
  300.         occurrences follow at the end of each line.
  301.  
  302. writeup: MIR TUTORIAL ONE, topic 4
  303. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  304.  
  305.                 A_BYTES SVP_TXT
  306.  
  307. creates a report file SVP_TXT.BYT which is a byte analysis of the
  308. entire file..  Here is that report:
  309.  
  310. \012 [0A]   4117   1.7%
  311. \015 [0D]   4117   1.7%
  312. \032 [1A]      1   0.0%
  313. \040 [20]  38883  16.3%
  314. !    [21]    173   0.1%
  315. '    [27]     87   0.0%
  316. (    [28]     38   0.0%
  317. )    [29]     38   0.0%
  318. ,    [2C]   2754   1.2%
  319. -    [2D]    266   0.1%
  320. .    [2E]   1922   0.8%
  321. 0    [30]    258   0.1%
  322. 1    [31]    560   0.2%
  323. 2    [32]    168   0.1%
  324. 3    [33]    117   0.0%
  325. 4    [34]    485   0.2%
  326. 5    [35]    170   0.1%
  327. 6    [36]    771   0.3%
  328. 7    [37]    174   0.1%
  329. 8    [38]    198   0.1%
  330. 9    [39]     85   0.0%
  331. :    [3A]     87   0.0%
  332. ;    [3B]    158   0.1%
  333. <    [3C]   1511   0.6%
  334. =    [3D]    935   0.4%
  335. >    [3E]   1511   0.6%
  336. ?    [3F]     62   0.0%
  337. @    [40]    935   0.4%
  338. A    [41]    658   0.3%
  339. B    [42]    225   0.1%
  340. C    [43]    403   0.2%
  341. D    [44]    962   0.4%
  342. E    [45]   1357   0.6%
  343. F    [46]    124   0.1%
  344. G    [47]    388   0.2%
  345. H    [48]    501   0.2%
  346. I    [49]   1715   0.7%
  347. J    [4A]     90   0.0%
  348. K    [4B]      5   0.0%
  349. L    [4C]    519   0.2%
  350. M    [4D]   1029   0.4%
  351. N    [4E]    466   0.2%
  352. O    [4F]    536   0.2%
  353. P    [50]    476   0.2%
  354. Q    [51]      9   0.0%
  355. R    [52]    234   0.1%
  356. S    [53]    534   0.2%
  357. T    [54]   2364   1.0%
  358. U    [55]    161   0.1%
  359. V    [56]    166   0.1%
  360. W    [57]    132   0.1%
  361. X    [58]    841   0.4%
  362. Y    [59]    106   0.0%
  363. Z    [5A]      2   0.0%
  364. [    [5B]     67   0.0%
  365. ]    [5D]     67   0.0%
  366. ^    [5E]    479   0.2%
  367. a    [61]  11934   5.0%
  368. b    [62]   2128   0.9%
  369. c    [63]   3465   1.5%
  370. d    [64]   6330   2.7%
  371. e    [65]  21212   8.9%
  372. f    [66]   3581   1.5%
  373. g    [67]   2899   1.2%
  374. h    [68]   9818   4.1%
  375. i    [69]  11036   4.6%
  376. j    [6A]    121   0.1%
  377. k    [6B]    897   0.4%
  378. l    [6C]   5929   2.5%
  379. m    [6D]   4209   1.8%
  380. n    [6E]  10777   4.5%
  381. o    [6F]  15224   6.4%
  382. p    [70]   2305   1.0%
  383. q    [71]     96   0.0%
  384. r    [72]  10071   4.2%
  385. s    [73]  10261   4.3%
  386. t    [74]  15670   6.6%
  387. u    [75]   5655   2.4%
  388. v    [76]   1945   0.8%
  389. w    [77]   3214   1.3%
  390. x    [78]    273   0.1%
  391. y    [79]   3891   1.6%
  392. z    [7A]     76   0.0%
  393. |    [7C]     28   0.0%
  394. é    [82]     43   0.0%
  395. â    [83]      1   0.0%
  396. à    [85]      1   0.0%
  397. ç    [87]      7   0.0%
  398. è    [8A]      4   0.0%
  399. î    [8C]      4   0.0%
  400. ô    [93]     10   0.0%
  401.  
  402.             The report (actually a single set of four columns) can
  403. be anywhere up to 256 lines long, one line for each possible
  404. arrangement among 8 off-and-on bits within one byte.  The program
  405. deliberately omits a heading line and shows only one byte pattern
  406. per line.  This enables us to get a clean result when we sort the
  407. report:
  408.  
  409.                 SORT /+10 /R < SVP_TXT.BYT > SVP_TXT.BYS
  410.  
  411. This is the standard DOS SORT routine.  The /+10 causes the sort to
  412. start at the tenth column, that is, sort by the frequency.  The /R
  413. makes it a reverse frequency sort.  The top end of the output looks
  414. like this:
  415.  
  416. \040 [20]  38883  16.3%
  417. e    [65]  21212   8.9%
  418. t    [74]  15670   6.6%
  419. o    [6F]  15224   6.4%
  420. a    [61]  11934   5.0%
  421. i    [69]  11036   4.6%
  422. n    [6E]  10777   4.5%
  423.  
  424.             If we include the "locations" flag when analyzing
  425. bytes, each line of the output contains more information. 
  426. Processing is only two thirds as fast.  The command would be:
  427.  
  428.                 A_BYTES -L SVP_TXT
  429.  
  430. The top end of the resulting SVP_TXT.LOC (note the changed report
  431. name) looks like this:
  432.  
  433. \012 [0A]   4117   1.7%   31 56 120 154 178 244 309 374
  434. \015 [0D]   4117   1.7%   30 55 119 153 177 243 308 373
  435. \032 [1A]      1   0.0%   238311
  436. \040 [20]  38883  16.3%   6 8 14 22 25 38 40 63
  437. !    [21]    173   0.1%   2098 2477 2800 3527 3671 6419 8389 8395
  438.  
  439. The report including locations may be sorted in precisely the same
  440. manner as the BYT report:
  441.  
  442.                 SORT /+10 /R < SVP_TXT.LOC > SVP_TXT.LOS
  443.  
  444.             If a file already exists with the target name, A_BYTES
  445. replaces the last character with a digit.  BYT becomes BY0 or BY1,
  446. etc., up to BY9.  The variations on LOC are LO0 through LO9.
  447.  
  448.             One final note: A_BYTES can be run on a series of files
  449. with a single command:
  450.  
  451.                 A_BYTES -L  MYFILE HERFILE FILE.WHO WHATEVER
  452.  
  453.  
  454.         ══════════════════════
  455. 4.8           Data types
  456.         ══════════════════════
  457.  
  458.             With a byte survey in hand, we can begin to answer two
  459. questions about a file:
  460.  
  461.             »    What is in it?
  462.  
  463.             »    How is it presented?
  464.  
  465. The two questions are answered simultaneously during the analysis. 
  466. In the next section, we will look at how data is presented.  Let's
  467. focus on the first question.  A file may contain one (or possibly
  468. more) of these data types:
  469.  
  470.                 ASCII text / extended ASCII text
  471.                 text with ASCII markup codes
  472.                 text with binary markup codes
  473.                 text with BCD (binary coded decimal) packed numbers
  474.                 text with BASIC packed numbers
  475.                 text with compression substitutions
  476.                 EBCDIC
  477.                 binary (compression, encryption, GIF graphic
  478.                     interchange files, sound, etc.)
  479.  
  480.             ASCII (American Standard Code for Information
  481. Interchange) is an agreed-upon assignment of bit patterns to
  482. letters, digits, punctuation, control characters, etc.  ASCII text
  483. consists of the letters of the printable alphabet, numeric digits,
  484. punctuation characters and space (hex 20 through 76) plus tab,
  485. vertical tab and new page (hex 09, 0B and 0c respectively).  The
  486. newline character (hex 0A) is normally present (except in line
  487. records and some fixed length records... see below).  If the file
  488. has been processed using a PC, for each newline character, there is
  489. normally exactly one carriage return (hex 0D), immediately
  490. following.  PC ASCII text files often have exactly one hex 1A or
  491. CTL-Z as the last character (EOF or end of file marker).
  492.  
  493.             Extended ASCII text for our purposes is ASCII text in
  494. which accented characters appear within French, German, Spanish and
  495. other foreign language words.  If we allow also for punctuation
  496. common in Spanish, the extra characters are in the ranges hex 80 to
  497. 9A and A0 to A8.  These are all "high-bit-set" characters, specific
  498. to PC compatible ASCII data.  ("High-bit-set" means that the
  499. leading bit is turned on; hence the value is hex 80 or higher.) The
  500. count of these characters when they are part of extended ASCII text
  501. is generally lower than the count of regular vowels in the same
  502. distribution.   Greek and mathematical characters (hex AB, AC, E0
  503. to FD) may also occur in extended ASCII text.  We will look later
  504. at how to check context in order to verify whether high-bit-set
  505. characters are valid text, errors within text or indications of a
  506. different file type.
  507.  
  508.             Text with ASCII markup codes uses the same characters
  509. as in ASCII or extended ASCII text.  It is common practice to
  510. insert special bytes or series of bytes within data to signal how
  511. the data should be displayed.  This practice is called markup. 
  512. Examples of items marked:
  513.  
  514.                 justify text (left, center, right)
  515.                 select font (courier, etc.), font subsets (italics)
  516.                 select type size (pica, elite, with a count)
  517.                 change to/from bold
  518.                 underline
  519.                 protect against "widows" and "orphans"
  520.                             (ensuring paragraphs stay together)
  521.                 respond to new heading level
  522.  
  523. The first indicator of ASCII markup is that some characters (often
  524. "<" and ">") are present in unusually high proportion.
  525.  
  526.             Text with binary markup codes may contain virtually all
  527. 256 characters.  Null bytes (hex 00) do not occur in ASCII text,
  528. but are common in files with binary content.  If you have Microsoft
  529. Word or WordPerfect files handy, try the command A_BYTES on one of
  530. them and look at the listing that results.  Notice that lower case
  531. alphabetic letters still figure prominently in the distribution.
  532.  
  533.             Text with packed numbers is found most often in COBOL
  534. style fixed length fielded records.  Distribution is like that of
  535. ASCII text except that a sprinkling of other values shows up. 
  536. Binary Coded Decimal (BCD) shows up in COBOL records.  BASIC
  537. language data files have their own variation of packed numbers.
  538.  
  539.             Text with compression substitutions has binary series
  540. in the midst of normal text.  This is notoriously difficult to work
  541. with unless you have access to the decompression table.
  542.  
  543.             EBCDIC data warrants special treatment the moment it is
  544. identified.  Work stations or mini computers that receive data on
  545. nine track tape often deal with non-ASCII data.  (The problem is
  546. rare with personal computers.)  If there are many '@' symbols and
  547. no recognizable text, it is possible that you are working with
  548. EBCDIC and not ASCII.  (The reason for lots of '@' characters is
  549. that the EBCDIC space character is the same as the ASCII '@'.)  
  550. Try the EBC_ASC program on a portion of the data:
  551.  
  552.  
  553. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  554. usage:  ebc_asc  ebcdic_input  ascii_output
  555.  
  556.         Converts an EBCDIC file to ASCII.  EBCDIC (Extended Binary
  557.         Coded Decimal Interchange Code) data is commonly produced
  558.         by IBM mainframe computers.  ASCII (American Standard Code
  559.         for Information Interchange) is used on personal computers
  560.         and computers produced by the majority of manufacturers.
  561.  
  562. input:  Any EBCDIC file
  563.  
  564. output: ASCII equivalent
  565.  
  566. writeup: MIR TUTORIAL ONE, topic 4
  567. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  568.  
  569.             If samples start to make sense when filtered through an
  570. EBCDIC to ASCII conversion, process all samples through EBC_ASC
  571. before continuing analysis.  Later you will need to process all the
  572. data through the same conversion.
  573.  
  574.             Binary data:  Suppose you find in every sample that the
  575. data looks completely meaningless.  There are many reasons that
  576. data dumps appear to be a jumble.  Among them are:
  577.  
  578.                     binary compression
  579.                     encryption
  580.                     binary numeric data
  581.                     graphics content
  582.                     sound files
  583.                     non-ASCII data
  584.  
  585. Attempts to decipher binary data are time consuming and expensive. 
  586. The process is called reverse engineering.  It is not always legal.
  587.  
  588. Go back to asking people questions (the people providing the data,
  589. and maybe a lawyer) before getting too deep!
  590.  
  591.  
  592.         ═════════════════════════════
  593. 4.9           Data presentation
  594.         ═════════════════════════════
  595.  
  596.             A byte survey is also used as part of the analysis of
  597. how the data is presented.  Main options are:
  598.  
  599.  
  600.                 byte stream
  601.                 line records
  602.                 fixed length records
  603.                 blocked records with ASCII lengths
  604.                 blocked records with binary lengths
  605.  
  606. Here we simply describe the options.  The topic on deblocking data
  607. will describe the programs used.  Deblocking, like EBCDIC to ASCII
  608. conversion, may have to be carried out before analysis can be
  609. completed.
  610.  
  611.             One stage of the indexing process will be to create a
  612. byte stream equivalent of the file to be indexed.  A byte stream is
  613. the crudest form of file... simply a series of bytes in the order
  614. in which they would be displayed if sent to a screen.  The ASCII
  615. source code file for each MIR program is a byte stream.
  616.  
  617.             Line records are blocks of text or other data, padded
  618. with blanks out to some fixed length, very often 80.  This form of
  619. data storage goes back to punch cards (remember them?) in which as
  620. many English (or other natural language) words as possible were
  621. fitted into one 80 column card.  When the next word would cause
  622. overflow, it was placed at the beginning of the next card.  A
  623. telltale sign of line records is a disproportionately high number
  624. of blanks and few if any linefeeds in the byte distribution.
  625.  
  626.             Fixed length records also date back to punch cards. 
  627. One or more cards would be divided into groups of columns, with one
  628. group assigned to each field.  Sizes of fields are fixed according
  629. to the amount of data that the file designer expects... perhaps
  630. eight columns/bytes for a purchase order number, 30 for a street
  631. address, 10 for a quantity, 55 for an item description, etc. 
  632. Unused fields and unused spaces within fields are left blank.  Text
  633. fields are normally left justified (extra spaces at the end), and
  634. numeric fields are right justified (leading bytes either blank or
  635. zero padded).  Line feeds are rare, and would occur only within a
  636. long text field.  The essence of fixed length records is that
  637. location determines meaning.  Like line records, fixed length
  638. records show a very high frequency of blanks (hex 20).  They are
  639. likely to have more numeric digits than line records.  Alternately,
  640. if the records contain Binary Coded Decimal packed numbers, there
  641. will be a near random assortment of high-bit-set bytes.
  642.  
  643.             Blocked records with ASCII lengths are series of byte
  644. streams of variable length, with a measure of length at the front
  645. of each block.  This length is typically 4 digits with zero padding
  646. (for example, 0032 or 3217 or 0539).  The byte survey of this data
  647. shows high frequencies of digits, especially the digit zero.  Line
  648. feeds show up less often than normal, or are non-existent. 
  649. Otherwise, the content is fairly typical of ASCII text.
  650.  
  651.             Blocked records with binary lengths have been common in
  652. library data (so called "MARC" records) and in the publishing
  653. business.  They are often more sophisticated than blocked records
  654. with ASCII lengths; there may be field sub-lengths within larger
  655. blocks.  Byte surveys show a small percentage of randomly
  656. distributed binary characters.  Those that have the high bit set
  657. are noticeable.  High-bit-off binary bytes are hidden in the
  658. frequencies of normal text characters.
  659.  
  660.  
  661.         ══════════════════════════════
  662. 4.10          Byte distributions
  663.         ══════════════════════════════
  664.  
  665.             Here is the distribution of alphabetical characters in
  666. a sample of English text (actually drafts of seven MIR topics). 
  667. The 79,657 characters were as follows:
  668.  
  669.  
  670. A   312
  671. B   101
  672. C   288
  673. D   220
  674. E   288
  675. F   152
  676. G   108
  677. H   112
  678. I   406
  679. J     7
  680. K    17
  681. L   175
  682. M   190
  683. N   187
  684. O   292
  685. P   219
  686. Q    17
  687. R   281
  688. S   331
  689. T   447
  690. U   109
  691. V    38
  692. W   117
  693. X    15
  694. Y    81
  695. Z     5
  696. a  6018
  697. b   920
  698. c  2764
  699. d  2775
  700. e  9658
  701. f  1766
  702. g  1482
  703. h  2959
  704. i  5478
  705. j    49
  706. k   378
  707. l  2523
  708. m  1996
  709. n  5194
  710. o  6008
  711. p  1899
  712. q   126
  713. r  5433
  714. s  4975
  715. t  6966
  716. u  2189
  717. v   834
  718. w  1010
  719. x   337
  720. y  1319
  721. z    86
  722.             Here is the same data again, arranged from most
  723. frequent to least frequent:
  724.  
  725. e  9658
  726. t  6966
  727. a  6018
  728. o  6008
  729. i  5478
  730. r  5433
  731. n  5194
  732. s  4975
  733. h  2959
  734. d  2775
  735. c  2764
  736. l  2523
  737. u  2189
  738. m  1996
  739. p  1899
  740. f  1766
  741. g  1482
  742. y  1319
  743. w  1010
  744. b   920
  745. v   834
  746. T   447
  747. I   406
  748. k   378
  749. x   337
  750. S   331
  751. A   312
  752. O   292
  753. E   288
  754. C   288
  755. R   281
  756. D   220
  757. P   219
  758. M   190
  759. N   187
  760. L   175
  761. F   152
  762. q   126
  763. W   117
  764. H   112
  765. U   109
  766. G   108
  767. B   101
  768. z    86
  769. Y    81
  770. j    49
  771. V    38
  772. Q    17
  773. K    17
  774. X    15
  775. J     7
  776. Z     5
  777.  
  778.             Frequency patterns in English text vary with the
  779. subject matter, but never to a large degree.  Letters j and z are
  780. little used; letters e and t together with the space character
  781. almost assuredly account for one quarter to one third of all
  782. alphabetic bytes present.  Percentages of course are lower when we
  783. include the space character and punctuation.  Spaces (blanks) lead
  784. the frequency distribution in virtually all text files.
  785.  
  786.             European languages use the high-bit-set accented
  787. characters.  In French, the frequency of unaccented letter e drops
  788. somewhat in favor of è with grave accent (infrequent) and é with
  789. acute accent (common).  Spanish uses more of the letter l, the
  790. tilde form of ñ and Ñ, and of course the interrogative and
  791. exclamatory symbols ¿ and ¡ at the beginning of sentences.  The PC
  792. high-bit-set accented characters apply as well in Scandinavian
  793. languages, German, and so forth.  But no language based on the
  794. roman character set departs altogether from the basic patterns --
  795. frequent use of vowels, certain consonants highly favored and
  796. others marginal across all languages.
  797.  
  798.             Treat each departure from typical distributions as a
  799. prompt to analyze each exceptional byte in its contexts.
  800.  
  801.             To illustrate, let's examine what significance we can
  802. attach to the example byte survey of the file SVP_TXT above.  Start
  803. by making your own complete copy with the command:
  804.  
  805.                 A_BYTES SVP_TXT
  806.  
  807. What further analysis should we do?
  808.  
  809.         »   The lower case letters have a typical English text
  810.             distribution... j, z and q infrequent; e, a, t and o
  811.             with very high frequency.
  812.  
  813.         »   Upper case letters are also normally distributed for
  814.             English text... Q and Z lowest, K very low (rarely the
  815.             first letter in a sentence), M appearing together with
  816.             the normally high vowels and T.  M is frequent at the
  817.             beginning of names, and in French greetings (Monsieur,
  818.             Madame).
  819.  
  820.         »   There are only 70 characters out of 238,312 that have
  821.             the high bit set (hex 80 or higher) and all can be
  822.             verified to be valid accented French characters that
  823.             might appear in names of people and places in French
  824.             correspondence.
  825.  
  826.         »   The line feed (hex 0A) and carriage return (hex 0D)
  827.             each appear 4117 times, normal in an ASCII text file
  828.             with 4117 lines.  The locations report shows that the
  829.             first eight occurrences of 0A 0D are paired right
  830.             together.
  831.  
  832.         »   The only other non-printing characters are hex 20
  833.             (space) and hex 1A (CTL-Z or end of file in DOS).  At
  834.             16.3% of occurrences, the space is the most frequent
  835.             character.  The CTL-Z occurs once only, in the very
  836.             last byte of the file. Byte number 238311 is the last.
  837.             (Offsets count from zero upward and SVP_TXT is a 238312
  838.             byte file.)  CTL-Z is the standard end of file marker
  839.             for ASCII text files.
  840.  
  841.         »   We therefore have cumulative evidence that this is an
  842.             extended ASCII file.  We have not yet established
  843.             whether it contains markup.
  844.  
  845.         »   Round and square parentheses probably are matched sets
  846.             ... 38 of ( and ), 67 of [ and ].  The latter are worth
  847.             checking whether they occur in normal ways within text.
  848.  
  849.         »   The sort by frequency reveals that < and > each appear
  850.             1511 times... a tip that they might be used as matching
  851.             angle brackets.  The location data shows that the first
  852.             eight are indeed paired only two or three bytes apart. 
  853.             Together the < and > bytes comprise 1.2% of the file...
  854.             abnormally high for correspondence, and therefore
  855.             likely part of some sort of markup code.
  856.  
  857.         »   The sort by frequency also shows @ and = occurring 935
  858.             times each.  Are they matched also and part of a code? 
  859.             The first eight appearances are within 7 bytes of each
  860.             other, with the @ symbol coming first each time.
  861.  
  862.         »   We should investigate why ^ shows up 479 times and | is
  863.             present 28 times. Neither is normal for correspondence.
  864.  
  865.             The next topic explains how to examine bytes in context
  866. and how to survey patterns across an entire file.  Following this
  867. are topics on analysis of detail within each of the data types.
  868.