Method and system for locating field breaks within input data

Abstract: A method and system for locating field breaks within input data is provided. In a preferred embodiment, a software facility locates field breaks within input data. The facility first receives input data made of a large number of rows of text. The facility then selects a group of the received rows of text to analyze. The facility identifies field breaks within the input data by analyzing the selected group of rows of text. The facility preferably analyzes the selected rows by counting the number of substantive characters in each column of the selected rows. The facility then uses the count to determine which columns have less than a field-break threshold of substantive characters. The facility locates one field break within each series of columns that have less than the field-break threshold of substantive characters.

Description: The invention relates generally to a method and system for receiving input data, and more specifically, to a method and system for locating field breaks within input data. Computers are often used to store and process data. Computer users usually use an application program to store a particular kind of data, or to process data in a particular way. A particular type of application program, called a database application, permits users to store and process a body of related data in the form of a table. A table is composed of records, each containing data about a particular thing, such as a mechanical part needed to construct a go-cart. Each record corresponds to one "line" of data, and a line is terminated by an end-of-line character, such as a return or line feed character. Each record is divided into a set of fields, or particular pieces of data. The set of fields is the same for every record in the table. Example fields for part records include part number, part description, and part cost. A record in such table would contain the part number, part description, and part cost for a particular part. Fields usually also have a uniform length, measured in number of characters, in every record. Figure 1 is a diagram showing the contents of an example table. The table 100 contains twenty records 101-120, each specifying data for each of seven fields 131-137. The fields are a stock number field 131, a description field 132, a quantity required field 133, a responsible mechanic field 134, an item cost field 135, a total cost field 136, and a date required field 137. In order to construct a go-cart, two axles, stock number 663661, which cost $215 each, are needed by Sue by December 16, 1993, at a total cost of $430.00. Accordingly, the stock number field for record 113 contains the stock number "663661", the description field contains the description "axles", the quantity required field contains the quantity "2", the responsible mechanic field contains the name "Sue", the item cost field contains the item cost "$215.00", the total cost field contains the total cost "$430.00", and the date required field contains the date "12/16/93". These field contents would typically have been stored in the table after being inputted by a user. A user typically positions an insert cursor to a particular field and types the data the field is to contain, then instructs the database application to move the input cursor to another field using a next field key, such as the tab key. Some database applications store table data in fixed-width field format, in which the contents of every field of each record are stored together in a string of text, and the fields are delineated by absolute position within the string. Text includes alphabetic, numeric and other characters. Figure 2 is a diagram of the information shown in the table Figure 1 stored as text strings. The figure shows character position numbers 201, also called column numbers, above the text strings. The first seven characters of each string contains the contents of the stock number field, the eighth through twenty-ninth character contains the contents of the description field, etc. Field width information is often stored separately from the table data, and is therefore sometimes unavailable to other application programs, such as other database applications or spreadsheet applications, when reading the table data. When a spreadsheet or database application reads a text file containing a table in fixed-width field format for which field width information is not available, it must position field breaks within the table data. Typically, spreadsheet and database applications use one of two methods to position field breaks in such data. In a first manual method, the application program solicits the necessary information from the user, either by interactively inputting the width of each field, or by inputting a control string containing information about every field, including width. This method has the shortcoming that it requires the user to provide width information that is likely both outside of the user's knowledge and difficult to determine manually. A second single row analysis method automatically analyzes the text in a single record, usually the first, or topmost record. This usually involves positioning a field break at every location at which the analyzed record contains a non-substantive character, such as a space, that follows a substantive character, such as a letter. This method has the shortcoming of often incorrectly positioning field breaks, since a single record is seldom representative of the entire table. Figure 3 is an example of how the single row analysis method of positioning field breaks would position field breaks in the strings of text shown in Figure 2. The diagram shows field breaks 301-304. It can be readily seen that, because of idiosyncrasies of the first record, field breaks 302, 303, 304 have all been positioned improperly: each is positioned within a field, rather than between two fields. In Programmers Journal, May-June 1989, pp. 56-60, a method for converting an ASCII text file with fields separated by a unique delimiter character to a d-Base III-compatible comma-delimited file is discussed. It is an object of the invention to provide an improved method and system in a computer system for locating field breaks within input data. This object is solved by the method according to claim 1 and the system according to claim 24. Preferred embodiments of the invention are subject matter of the dependent claims. Preferred embodiments are described in the following using the accompany drawings which show: Figure 1 is a diagram showing the contents of an example table. Figure 2 is a diagram of the information shown in the table Figure 1 stored as text strings. Figure 3 is an example of how the single row analysis method of positioning field breaks would position field breaks in the strings of text shown in Figure 2. Figure 4 is a high-level block diagram of the general-purpose computer system upon which the facility preferably operates. Figure 5 is an overview flow diagram of the facility. Figure 6 is a flow diagram depicting the step of counting the number of substantive characters in each column of data in greater detail. Figure 7 is a flow diagram depicting the step of locating a field break within each series of columns having count values below a field-break threshold in greater detail. Figure 8 is a count table showing the values of the Count[] array after the data shown in Figure 2 is counted. Figure 9A is a display image of the preview window that shows the field breaks automatically located by the facility. Figure 9B is a display image of the same preview window after the user has used the user interface portion of the facility to correct the position of a field break. Figure 9C is a display image of the same preview window after the user has used the user interface portion of the facility to insert a missing field break. Figure 10 is a diagram of a table stored as text strings that contains header information. A method and system for locating field breaks within input data is provided. (Locating field breaks is also known as identifying or positioning field breaks.) In a preferred embodiment, a software facility (facility) acquires table data in fixed-width field format (input data), then locates field breaks within the input data by analyzing a group of rows of the input data. The facility selects a group of rows to analyze and counts the number of substantive, or non-space, characters in each character position, or column, of the rows in the group. The facility then uses the count to determine which columns have less than a field-break threshold of substantive characters. The facility locates one field break within each series of columns that have less than the field-break threshold of substantive characters. The facility preferably locates each established field break by first selecting an adjacent group of columns in the series that each has the smallest substantive character count in the series. This group of columns is called a contiguous minimum subset. The facility then tests each column that is adjacent to an end of the minimum subset to see whether text has been justified to that column. If just one of these columns is a justification point, then the facility locates the field break between it and the minimum subset. If neither or both of these columns is a justification point, then the facility locates the column break in the middle of the minimum subset. The facility also includes a user interface for adding, deleting, and repositioning field breaks. Figure 4 is a high-level block diagram of the general-purpose computer system upon which the facility preferably operates. The computer system 401 contains a central processing unit (CPU) 402, a computer memory (memory) 403, and input/output devices 404. Among the input/output devices is a storage device 405, such as a hard disk drive, a keyboard 406, a pointing device 407, such as a mouse and a display device 408, such as a monitor. The computer programs of the facility reside in the memory and execute on the CPU. The user preferably receives visual information from the facility through the monitor and interacts with the user interface portion of the facility using the keyboard or the mouse. Figure 5 is an overview flow diagram of the facility. In step 501, the facility selects a group of the rows that make up the input data to analyze. While the facility selects as large a group of rows as is practicable, it is generally not considered necessary to select more than a few hundred rows. Significant improvements in prior art techniques can be seen even by selecting only a few rows. In step 502, the facility counts the number of substantive characters in each column of the selected group of rows, storing the counts for all of the columns in a Count[] array. A substantive character is one that is likely part of the data, such as a letter or a numeral. On the other hand, non-substantive characters, also called separator characters, are those that usually are not part of the data, such as spaces, commas, and tab and carriage return characters. In step 503, the facility identifies columns having count values below a field-break threshold, contiguous columns meeting this requirement are identified as a series (which may include only one column), and a field break is later located in each series. The field-break threshold is a percentage of the total number of selected rows, whose value is chosen with reference to the amount of field separation expected. The larger the average number of non-substantive characters between fields expected, the lower the field-break threshold may be set, thereby reducing the chance of erroneously locating a field break. Conversely, the smaller the average number of non-substantive characters between fields, the higher the field-break threshold must be set, thereby increasing the chance of erroneously locating a field break. As an example, for ledger-type data like the data shown in Figure 2, a field-break threshold of 12.5% is preferably chosen. In a preferred embodiment, the facility permits the user to adjust the field-break threshold. For example, a user may know from experience that the facility often inserts extraneous field breaks in input data from a particular source. When processing input data from that source in the future, the user would decrease the field break threshold, thereby reducing the chance of erroneously locating a field break. Each series is preferably stored as a beginning column number and an ending column number. The facility preferably discards any series that begins in the first column or ends in the last column. In step 504, the facility locates a column break within each series identified in step 503 by selecting a contiguous minimum subset of the series, then testing for justification points, or columns to which text in each row of text of the input data is aligned, at each end of the series. In step 505, the facility displays the data in a preview window with the field breaks shown by vertical lines, and permits the user to manipulate the field breaks. The user can reposition a field break by dragging it to a new position, and can delete a field break by double-clicking on it. The user can establish a new field break by clicking on a location in the data where a field break does not exist. A user can also use scroll bars to scroll the table data in both dimensions to observe the affect on his or her changes on all the fields and rows. Figure 6 is a flow diagram depicting the counting step 502 in greater detail. In steps 601-609, the facility initializes a Count[] array indexed by column number, then sets each element equal to the number of selected rows having a substantive character in the corresponding column. In step 601, the facility initializes the Count[] array by setting each of its elements equal to zero. In step 602, the facility sets a RowIndex counter equal to the number of the first selected row. In step 603, the facility sets a ColIndex counter equal to the first column number, preferably 1. In step 604, if the current row and a column of the input data (Text[RowIndex, ColIndex]) contains a substantive character, then the facility increments the count for the current column (Count[ColIndex]) in step 605, else the facility continues at step 606. In step 607, if the current column counter (ColIndex) is less than the last column number, then the facility increments the current column counter and continues at step 604 to check the next column in the same row, else the facility continues at step 608. In step 608, if the current row counter (RowIndex) is less than the last selected row number, then the facility increments the current row counter and continues at step 603 to check the first column of the next row, else the steps shown in Figure 6 conclude. Figure 7 is a flow diagram depicting the locating step 504 in greater detail. In steps 701-704, the facility locates a column break within each series identified in step 503 by selecting a contiguous minimum subset of the series, then testing for justification points at each end of the minimum subset. These steps are executed for each series identified in step 503. In step 701, the facility selects a contiguous minimum subset is preferably stored as a beginning column value and an ending column value. In steps 702-704, the facility locates a column break either just beyond one of the ends of these contiguous minimum subsets selected in step 503, or as near to the center of the selected contiguous minimum subset as possible. The contiguous minimum subset corresponds roughly to empty columns between two fields. If a single one of the two columns is justified on the side of the blank columns, then it is most effective to locate the field break at that end of the contiguous minimum subset. On the other hand, if neither field is justified to the side of the blank columns, or they both are, then it is most effective to position the field break in the center of the contiguous minimum subset. In step 702, if exactly one of the two columns beyond an end of the contiguous minimum subset is a justification point, then the facility continues at step 703 to locate the field break between the single justification point and the contiguous minimum subset, else the facility continues at step 704 to locate the field break in the center of the contiguous minimum subset. The facility determines whether a column is a justification point by comparing its count to a justification threshold. The justification threshold, like the field-break threshold, is a percentage of the total number of selected rows, whose value is chosen with reference to the type of data expected. A justification threshold of 50% is preferably chosen for most data. In a preferred embodiment, the facility permits the user to adjust the justification threshold. For example, the user may know from experience that, when processing input from a particular source, the facility tends to erroneously detect justification points in the input data. When receiving input data in the future from the same source, the user would reduce the justification threshold to reduce the likelihood of erroneously recognizing justification points. The facility then repeats steps 701-704 for any remaining series. The following example illustrates the operation of the facility. Figure 8 is a count table showing the values of the Count[] array after step 502 is executed for the data shown in Figure 2. The lines of count table 800 each contain a column number and a count value. The count value for each line indicates the number of substantive (here, non-space) characters appearing in the numbered column. For example, the count table shows that column 10 (of Figure 2) has a count value of 18, which is equal to the number of substantive characters in column 10. Because the sample data has 20 rows, with a 12.5% field-break threshold, the nominal field-break threshold is 2.5. The count values are compared to the field break threshold in step 503, and contiguous columns having count values below the field break threshold are grouped into series. The first series in the sample data are from column 7 to column 7, from column 30 to column 31, from column 33 to column 33, from column 46 to column 50, and from column 58 to column 58. As an example of selecting a contiguous minimum subset in the series that begins with column 46 and ends with column 50, in step 504, the facility selects the contiguous minimum subset of column 46 to column 49, which has a count value of 0. The contiguous minimum subset for column 46 to column 49 is preceded by column 45, which has a count of 20, and followed by column 50, which has a count of 2. The justification threshold for the sample data is 10 (assuming a justification threshold of 50%), which is exceeded by the count of column 45, but not by the count of column 50. Because a facility recognizes a single justification point, it executes step 703 to locate the field break between the minimum subset (column 49) and the justification point (column 50). Figure 9A is a display image of the preview window that shows the field breaks automatically located by the facility. The facility displays the preview window 900 as the visual interface for the preview mode supported by the facility in step 505. The preview window contains a portion of the table data 901, and the position of each field break is shown in the data as vertical bars 902-906. The user can use scroll bars 907 and 908 to scroll the table data in both dimensions to observe the effect of his or her changes on all of the fields and rows. It can be seen in Figure 9A that the facility has mispositioned field break 903. Figure 9B is a display image of the same preview window after the user has used the user interface portion of the facility to correct the position of field break 903. The user uses the mouse to position the mouse cursor over field break 903 in its initial position, presses a button on the mouse, uses the mouse to move the mouse cursor, as well as the field break, to its destination position, and releases the button. The facility interprets these actions by the user as a field break move command and moves the field break between columns 31 and 32 to between columns 29 and 30. It can be seen in Figure 9B that the facility has also failed to locate a field break between the responsible mechanic field and the item cost field. Figure 9C is a display image of the same preview window after the user has used the user interface portion of the facility to insert a missing field break between these fields. The user uses the mouse to position the mouse cursor between columns 38 and 39 and presses a button on the mouse. The facility interprets these actions by the user as a field break: add command and locates a field break between columns 38 and 39. The facility has further features that enhance its effectiveness. In a preferred embodiment, the facility detects when it has located a field break inside a field organized in one of several common data formats that incorporates non-substantive characters, such as spaces. As an example, some data formats specify that parts of the data are separated by spaces, such as the representation "Aug 3 1993" for August 3, 1993. The facility preferably maintains a table of such formats, which include various time ("12:30 PM") and currency ("3,500,00 fr.) formats, as well as date formats, and compares them to consecutive pairs of fields in the selected rows of input data. When the facility locates a pair of fields that together comply with the format, it removes the field break separating them. When the input data contains a large number of rows, in step 501, the facility preferably skips, or omits, rows containing header information, which is often formatted differently than actual data. Figure 10 is a diagram of a table stored as text strings that contains header information. In the data 1000 shown in Figure 10, first row 1001 contains header information and should be omitted. In a preferred embodiment, the facility skips any rows at the beginning of the input data that contain obviously different formatting than the main records of the input data. In an alternate embodiment, the facility merely skips the first several rows of data, using the heuristic that most header information usually occurs in the first few rows of data. It can be difficult to identify a field break between a first field that is left justified and a second field that is right justified, because, while the fields are often separated by non-substantive characters in individual rows, the counts for the columns on either side of the intended field break often average out to nearly the same value. The field break between the responsible mechanic field 134 and the item cost field 135 in the sample data is an example of this situation. It can be seen from the count table that the last column of the responsible mechanic field (38) contains seven substantive characters, while the first column of the item cost field (39) contains ten substantive characters. Since neither one of these values is below the nominal field-break threshold of 2.5 characters, the facility would not normally identify a series between these fields, and would therefore normally not locate a field break between them. The facility is preferably able to generate a multiple-column count to address this difficulty. When the facility recognizes it, the facility increments the multiple-column count for a given column once for each row in which both the current column and the next column both contain a substantive character. The multiple-column count is then analyzed in the same way as the single-column count described above. Use of a multiple column count is effective to recognize a field break between the responsible mechanic field and the item cost field. It can also be difficult to identify a field break between two fields that are separated by few or no non-substantive characters. However, in a preferred embodiment, the facility is able to identify a field break between a first field containing mostly letters and a second field containing mostly numerals. In this embodiment, the facility produces two separate counts: one in which only letters are considered substantive characters, and one in which only numerals are considered substantive characters. The facility then compares the two counts to identify columns at which one count drops off quickly and the other increases abruptly, and inserts additional field breaks at this column. While this invention has been shown and described with reference to preferred embodiments, it will be understood by those skilled in the art that various changes or modifications in form and detail may be made without departing from the scope of the invention. For example, an aesthetically different user interface portion could be used to receive field break manipulation commands from the user. Further, the count values could be analyzed differently. For example, more than one count value at a time could be compared to relative thresholds. Also, more sophisticated forms of statistical analysis could be applied to the count values.

Claims: A method in a computer system for locating field breaks (301, 302, 303, 304) within input data, the method comprising the steps of: receiving input data comprising a multiplicity of rows of data, the multiplicity of rows of data having ordered columns, each containing a character that may be either substantive or non-substantive; substantive characters being those characters allowed within data fields; selecting (501) a plurality of rows of data of the multiplicity of rows of data; and characterized by the further steps of: identifying field breaks within the input data by analyzing the selected rows of data by counting (502) the number of substantive characters in each column of the selected rows of data, wherein a count value is produced for each column, and wherein the count values are ordered to correspond to the order of the columns; and positioning field breaks (503, 504) at columns proximate to columns having a relative minimum number of substantive characters with respect to surrounding columns. The method of claim 1 wherein the multiplicity of rows of data is ordered, such that one of the rows of data is the top row of data, wherein the selecting step includes the step of omitting a contiguous group of one or more rows of data that includes the top row of data. The method of claim 1 wherein the count values are ordered to correspond to the order of the columns, and wherein the rows of data include header rows that contain header information for describing the contents of other rows of data, and wherein the selecting step includes the step of omitting the header rows. The method of claim 1 wherein the step of identifying field breaks within the input data based upon the count values includes the steps of identifying (503) one or more series of columns for which the count values are below a field-break threshold; and locating (504) a field break within each series of columns identified. The method of claim 4 wherein the step of identifying one or more series of columns for which the count values are below a field-break threshold includes the step of omitting a series of columns for which the count values that are below the field-break threshold that appears in the order of the columns before the first column for which the count value is greater than the field-break threshold. The method of claim 4 wherein the input data may contain one or more justification points, each of which is a column within the input data to which data in each row of data of the input data is aligned, and wherein the locating step includes the steps of, for each series of columns: selecting (701) a contiguous minimum subset of the series of columns, such that the contiguous minimum subset of the series of columns have counts that are generally not larger than any of the series of columns not within the contiguous minimum subset of the series of series of columns; determining (702) whether zero, one, or two of the two count values that are immediately adjacent to the contiguous minimum subset of the series of columns are justification points within the input data; if one of the columns that is immediately contiguous to the contiguous minimum subset of the series of columns is a justification point, locating the field break (703) between the column that is a justification point and the contiguous minimum subset of the series of columns; and if zero or two of the count values that are immediately contiguous to the contiguous minimum subset of the series of columns are justification points, locating the field break (704) within the contiguous minimum subset of the series off columns. The method of claim 6 wherein the step of, if zero or two of the count values that are immediately contiguous to the contiguous minimum subset of the series of columns are justification points, locating the field break (704) within the contiguous minimum subset of the series of columns locates the field break as near to the center of the contiguous minimum subset of the series of columns as is possible. The method of claim 6 wherein the step of determining whether zero, one, or two of the two count values that are immediately adjacent to the contiguous minimum subset of the series of columns are justification points includes the steps of determining whether the count value for the column immediately preceding the first column of the contiguous minimum subset of the series of columns exceeds a justification threshold; and determining whether the count value for the column immediately following the last column of the contiguous minimum subset of the series of columns exceeds the justification threshold. The method of claim 4 wherein the input data contains data organized in one of a predefined multiplicity of data formats, a plurality of the data formats specifying organizing the data using non-substantive characters, further including the steps of, after the step of locating a field break: recognizing that a field break (903) has been located within a field containing data organized in a data format specifying organizing the data using non substantive characters; and removing the field break recognized in the recognizing step. The method of claim 1 wherein the selected rows of data have ordered columns, each containing a character that may either be non-substantive or substantive, and wherein the step of identifying field breaks within the input data by analyzing the selected rows of data, includes the further steps of: for each column, counting the number of selected rows in which there is a substantive character in both the column and in an adjacent column; and identifying field breaks within the input data based upon the count values produced by said counting step. The method of claim 1 wherein the plurality of rows of data is ordered, such that one of the rows of data is the top row of data, wherein the selecting step includes the step of omitting a contiguous group of one or more rows of data that includes the top row of data. The method of claim 1 wherein the rows of data include header rows that contain header information for describing the contents of other rows of data, and wherein the selecting step includes the step of omitting the header rows. The method of claim 1 wherein the step of counting the number of substantive characters in each column only counts characters contained in a first predefined group of characters; and comprising the further steps of counting the number of substantive characters contained in a second predefined group of characters in each column of the selected rows of text, such that a second character group count value is produced for each column, and such that the second character group count values are ordered to correspond to the order of the columns; and identifying fields within the input data based upon the first character group count values and second character group count values produced by the counting steps. The method of claim 13 wherein the first predefined group of characters and the second predefined group of characters are mutually exclusive, and wherein the step of counting the number of substantive characters contained in a first predefined group of characters in each column of the selected rows of text counts only characters not counted by the step of counting the number of substantive characters contained in a second predefined group of characters in each column of the selected rows of text. The method of claim 14 wherein some characters are letters, and wherein the first predefined group of characters contains letters and the second predefined group of characters contains non-letters, and wherein the step of counting the number of substantive characters contained in a second predefined group of characters in each column of the selected rows of text counts only nonletters. The method of claim 14 wherein some characters are numerals, and wherein the first predefined group of characters contains numerals and the second predefined group of characters contains non-numerals, and wherein the step of counting the number of substantive characters contained in a second predefined group of characters in each column of the selected rows of text counts only nonnumerals. The method of claim 1, comprising the further step of: manipulating the field breaks positioned in the identifying step in response to receiving input from a user. The method of claim 17 wherein the manipulating step includes the steps of: receiving a relocate instruction from the user; and relocating a field break identified in the identifying step in response to receiving the relocate instruction from the user. The method of claim 18 wherein the step of receiving a relocate instruction from the user includes the step of receiving an indication of which field break to relocate and an indication of the position to which to relocate the field break, and wherein the relocating step relocates the field break in accordance with the indications. The method of claim 17 wherein the manipulating step includes the steps of receiving a delete instruction from the user; and deleting a field break identified in the identifying step in response to receiving the delete instruction from the user. The method of claim 20 wherein the step of receiving a delete instruction from the user includes the step of receiving an indication of which field break to delete, and wherein the deleting step deletes the field break in accordance with the indication. The method of claim 17 wherein the manipulating step includes the steps of receiving an add instruction from the user; and adding a field break to those identified in the identifying step in response to receiving the add instruction from the user. The method of claim 22 wherein the step of receiving an add instruction from the user includes the step of receiving an indication of the position at which a field break is to be added, and wherein the adding step adds the field break at the position indicated by the indication. A computer-based field break locator (401) for identifying field breaks within input data, the input data having rows of fields, each field having characters, the rows of the input data being logically divided into one-character columns, each character being either substantive or non-substantive, substantive characters being those characters allowed within data fields, the computer-based field break locator comprising: a receiver (404) for receiving the input data; a selector for selecting a plurality of rows of the received input data; and an analyzer (402) for identifying the fields within the input data based on the selected rows, itself characterized by a counter for determining the number of substantive characters in each column of the selected rows of the input data, a counter memory (403) for storing the number of substantive characters in each column of the selected rows of the input data, and a field break positioner (402) for positioning a field break at a column proximate to a column having a relative minimum number of substantive characters with respect to surrounding columns. The field break locator of claim 24 wherein the field break positioner includes a data justification detector for detecting whether data in columns adjacent to the column having the smallest number of substantive characters is justified to the columns adjacent to the column having the smallest number of non-substantive characters, and wherein the field break positioner positions the field break based upon the results realized by the detector. The field break locator of claim 24 wherein one or more rows of data contain header information for identifying portions of the remainder of the rows of data, and wherein the selector includes a discriminator for detecting and omitting one or more rows of data containing header information.

Inventors: COMER ROSS W, SOLOMON CYNTHIA ANN, COMER, ROSS W., SOLOMON, CYNTHIA ANN
Applicants: MICROSOFT CORP, MICROSOFT CORPORATION
Application year: 1994
Main classification: G06F17
IPC codes: G06F17, G06F12