JP4565064B2 - Fast matching method - Google Patents

Fast matching method Download PDF

Info

Publication number
JP4565064B2
JP4565064B2 JP2003428585A JP2003428585A JP4565064B2 JP 4565064 B2 JP4565064 B2 JP 4565064B2 JP 2003428585 A JP2003428585 A JP 2003428585A JP 2003428585 A JP2003428585 A JP 2003428585A JP 4565064 B2 JP4565064 B2 JP 4565064B2
Authority
JP
Japan
Prior art keywords
search
character
character string
text
skip table
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP2003428585A
Other languages
Japanese (ja)
Other versions
JP2005190032A (en
Inventor
英恒 小林
秀男 鈴木
▲躍▼彬 白
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nihon University
Original Assignee
Nihon University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nihon University filed Critical Nihon University
Priority to JP2003428585A priority Critical patent/JP4565064B2/en
Publication of JP2005190032A publication Critical patent/JP2005190032A/en
Application granted granted Critical
Publication of JP4565064B2 publication Critical patent/JP4565064B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

本発明は、高速マッチング法に関し、特に、テキストから検索文字列に一致する文字列を検索するための高速マッチング法に関する。   The present invention relates to a high-speed matching method, and more particularly to a high-speed matching method for searching a character string that matches a search character string from text.

従来の文字列検索方法としては、単純法、KMP(Knuth-Morris-Pratt)法、BM(Boyer-Moore)法、BMH(Boyer-Moore-Horspool)法などがある。単純法は、図10(a)に示すように、テキストと検索文字列を1文字ずつ比較して、不一致なら、検索文字列を1文字右にずらす方法である。単純法でも、実用的に見てそれほどの問題点はないが、最悪の場合の計算量は(検索文字列長m×テキスト文字列長n)に比例する。文字列照合の速度を上げるには、一致または不一致がわかっている無駄な比較をできるだけ避けることが望ましい。   Conventional string search methods include a simple method, a KMP (Knuth-Morris-Pratt) method, a BM (Boyer-Moore) method, and a BMH (Boyer-Moore-Horspool) method. In the simple method, as shown in FIG. 10A, the text and the search character string are compared one by one, and if they do not match, the search character string is shifted to the right by one character. Even in the simple method, there is not so much problem in practical use, but the calculation amount in the worst case is proportional to (search character string length m × text character string length n). In order to increase the speed of character string matching, it is desirable to avoid as many unnecessary comparisons as possible when a match or mismatch is known.

KMP法は、文字列パターン照合問題が線形時間で解けることを最初に示したアルゴリズムである。テキストと検索文字列の一致文字数に応じたシフト量を求めてスキップテーブルにし、スキップテーブルを参照しながらシフトする方法である。テキストを走査する前に、前処理として、検索文字列からスキップテーブルを構成する。検索文字列のうちk文字だけ一致した後で不一致が見つかったときに、テキストのどの文字と検索文字列のどの文字の比較から照合を続ければよいかをあらかじめ調べておく。不一致となった位置から左側k文字がわかっていることを利用して、無駄な比較を避けるように設定するのである。図10(b)に示すように、これをスキップテーブルの形で記録する。このスキップテーブルを求める計算においては、調べる対象は検索文字列のみである。スキップテーブルは、検索文字列長をmとするとサイズ(m+1)×3の配列により表現できる。スキップテーブルの構成に要する時間は、O(m)時間である。テキスト長をnとするとき、文字比較の回数は高々2n回である。したがって、テキスト走査時間はO(n)時間である。しかし、BM法による文字列照合アルゴリズムに比べると、実用上の性能で劣る。   The KMP method is the first algorithm that shows that the string pattern matching problem can be solved in linear time. This is a method of obtaining a shift amount according to the number of matching characters between a text and a search character string, making it a skip table, and shifting while referring to the skip table. Before scanning the text, a skip table is constructed from the search character string as preprocessing. When a mismatch is found after matching only k characters in the search character string, it is checked in advance which character in the search character string should be compared with which character in the search character string. Using the fact that the left k characters are known from the mismatched position, settings are made so as to avoid unnecessary comparisons. As shown in FIG. 10 (b), this is recorded in the form of a skip table. In the calculation for obtaining the skip table, only the search character string is examined. The skip table can be represented by an array of size (m + 1) × 3, where m is the search character string length. The time required for the configuration of the skip table is O (m) time. When the text length is n, the number of character comparisons is at most 2n. Therefore, the text scanning time is O (n) time. However, it is inferior in practical performance compared to the string matching algorithm by the BM method.

BM法は、KMP法よりもさらに高速な照合アルゴリズムである。スキップテーブル1とスキップテーブル2を設けて、シフト量の多い方を選択する方法である。検索文字列がある程度以上(普通5文字以上くらい)の長さをもつ場合には、最も速い文字列照合アルゴリズムだといわれている。KMP法と同様、計算量は最悪の場合でもO(n)である。KMP法と同様に、照合を進めるにあたっては、それ以前に行った比較の結果として得られた情報をできるだけ活用して、比較の回数を減らす。BM法の長所は、テキスト中の文字の大部分を調べずにすむ可能性があることである。単純法やKMP法では、テキストの中の文字をそれぞれ1回は調べなければならない。比較は最低でもn回になる。これに対して、BM法ではn/m個(nはテキストの長さ、mは検索文字列の長さを表す)の文字とだけ比較すればよいことがある。これによって、特に検索文字列が長いときに、計算時間の大幅な短縮が期待できる。この特徴から、BM法は、実用上きわめて重要なアルゴリズムと見なされている。   The BM method is a collation algorithm that is even faster than the KMP method. This is a method in which a skip table 1 and a skip table 2 are provided to select the one with the larger shift amount. If the search character string is longer than a certain length (usually about 5 characters or more), it is said to be the fastest character string matching algorithm. Similar to the KMP method, the computational complexity is O (n) at worst. As with the KMP method, when collating, the information obtained as a result of the comparison performed before that is used as much as possible to reduce the number of comparisons. The advantage of the BM method is that you may not have to examine most of the characters in the text. In simple and KMP methods, each character in the text must be examined once. There are at least n comparisons. On the other hand, in the BM method, it may be necessary to compare only with n / m characters (where n is the length of the text and m is the length of the search character string). This can be expected to greatly reduce the calculation time, especially when the search character string is long. Due to this feature, the BM method is regarded as an extremely important algorithm for practical use.

BM法ではテキストを走査する前に、検索文字列の中の文字成分と文字の配列を調べ、スキップテーブル1とスキップテーブル2を用意する。スキップテーブル1の作成においては、検索文字列の最後の位置からの部分文字列が、検索文字列の前のほうに含まれていないかを調べ、繰返しのある部分文字列に対するシフト量を計算しておく。スキップテーブル1は、KMP法の場合と同じように計算され、検索文字列に一致しないテキスト文字を全く考慮しない。スキップテーブル1は、検索文字列の中の文字構成だけから計算される。検索文字列に部分マッチしたテキスト文字列が、検索文字列の他の位置に含まれたかどうかでシフト量が決まる。スキップテーブル1の構成に要する時間は、検索文字列長をmとし、使用文字数をqとするとき、O(q+m)時間である。   In the BM method, before scanning the text, the character component and the character arrangement in the search character string are examined, and the skip table 1 and the skip table 2 are prepared. In creating the skip table 1, it is checked whether the partial character string from the last position of the search character string is included before the search character string, and the shift amount for the repeated partial character string is calculated. Keep it. The skip table 1 is calculated in the same manner as in the KMP method, and does not consider any text characters that do not match the search character string. The skip table 1 is calculated only from the character configuration in the search character string. The shift amount is determined by whether or not the text character string partially matched with the search character string is included in another position of the search character string. The time required for the configuration of the skip table 1 is O (q + m) time when the search character string length is m and the number of characters used is q.

スキップテーブル2は、検索文字列に一致しないテキスト文字が検索文字列に含まれるか否かを考慮する。スキップテーブル2の作成においては、検索文字列の成分文字を求め、各成分文字の検索文字列内での最後部位置からの最短文字数を、シフト量として計算しておく。スキップテーブル2では、検索文字列との文字比較でマッチしなかったテキスト側の文字によって、シフト量を決める。スキップテーブル2を作成するためには、テキストの中に含まれる可能性のあるすべての文字に対して、シフト量を計算しておく必要がある。したがって、BM法では、スキップテーブル作成が複雑になる。スキップテーブル2の構成に要する時間はO(m)時間である。スキップテーブルの例を、図11(a)に示す。   The skip table 2 considers whether the search character string includes text characters that do not match the search character string. In creating the skip table 2, the component characters of the search character string are obtained, and the shortest number of characters from the last position in the search character string of each component character is calculated as the shift amount. In the skip table 2, the shift amount is determined by the text-side character that does not match in the character comparison with the search character string. In order to create the skip table 2, it is necessary to calculate the shift amount for all the characters that may be included in the text. Therefore, the BM method complicates skip table creation. The time required for the configuration of the skip table 2 is O (m) time. An example of the skip table is shown in FIG.

BM法も単純法と同様、テキストを左から順に調べていく。しかし、いったんテキスト上の位置がきまったら、検索文字列については、逆に右から左に向かって調べる。検索文字列を逆向きに調べることがBM法の要点である。検索文字列の右端から文字比較を行うアイデアによって、多くの場合、テキストの文字のいくつかを読み飛ばすことができ、最も高速なアルゴリズムとして知られている。テキストの文字の参照回数で効率を評価するとき、平均時の参照回数はテキスト長より小さい。最悪時には、O(m×n)回の参照を行う。   As with the simple method, the BM method examines text in order from the left. However, once the position on the text is determined, the search string is examined from right to left. Examining the search string in the reverse direction is the main point of the BM method. The idea of comparing characters from the right end of the search string can often skip some of the characters in the text and is known as the fastest algorithm. When evaluating the efficiency with the number of text character references, the average number of references is less than the text length. At worst, O (m × n) times of reference is performed.

文字列照合の際に、検索文字列に対面したテキスト文字列を、検索文字列の最後部から比較する。不一致があると、テキスト側の不一致文字からスキップテーブル2のシフト量を得る。一致する部分文字列の長さまたは不一致文字位置から、スキップテーブル1のシフト量を得る。大きいほうを選んで、テキスト文字列をシフトする。図11(a)に示す例では、最初は0文字一致で、不一致文字がaである。スキップテーブル1のシフト量は1であり、スキップテーブル2のシフト量は2であるので、2文字シフトする。2番目の照合においては、4文字一致で、不一致文字がbである。スキップテーブル1のシフト量は5であり、スキップテーブル2のシフト量は1であるので、5文字シフトする。その後は、同じように、文字比較を検索文字列の最後部から繰り返す。文字列照合に必要な文字比較回数が、ほとんどのケースで、比較回数がO(n+m)回より少なくなる。   In the character string matching, the text character string facing the search character string is compared from the last part of the search character string. If there is a mismatch, the shift amount of the skip table 2 is obtained from the mismatched character on the text side. The shift amount of the skip table 1 is obtained from the length of the matching partial character string or the mismatched character position. Select the larger one and shift the text string. In the example shown in FIG. 11 (a), 0 characters are initially matched and the mismatched character is a. Since the shift amount of the skip table 1 is 1 and the shift amount of the skip table 2 is 2, the character is shifted by two characters. In the second collation, four characters match and the mismatch character is b. Since the shift amount of the skip table 1 is 5, and the shift amount of the skip table 2 is 1, the character is shifted by 5 characters. Thereafter, similarly, the character comparison is repeated from the last part of the search character string. In most cases, the number of character comparisons required for character string matching is less than O (n + m) times.

BMH法は、スキップテーブル2のみを使うように単純化したものである。図11(b)に示すように、部分文字列の右端の文字でスキップテーブルを引いて、シフト量を求める。図11(b)に示す例では、最初は右端の文字がhであるので、シフト量は6である。2番目の照合においては、右端の文字がgであるので、シフト量は6である。   The BMH method is simplified to use only the skip table 2. As shown in FIG. 11B, the shift amount is obtained by drawing the skip table with the rightmost character of the partial character string. In the example shown in FIG. 11B, since the rightmost character is initially h, the shift amount is 6. In the second collation, since the rightmost character is g, the shift amount is 6.

上記従来の文字列検索方法のうち、高速なBM法ではスキップテーブルの作成方法が複雑である。簡単な方法では検索速度が遅い。より単純で高速な方法を、本発明者は非特許文献1で提案した。この方法は、BMH法を改良したものである。これをBK法とよぶことにし、簡単に説明する。図12のフローチャートに示すように、テキストの文字が検索文字列にあれば、検索文字の先頭文字のシフト量を(検索文字数m)とする。その次の文字のシフト量を(検索文字数m−1)とする。検索文字の末尾文字のシフト量を1とする。検索文字列に無いテキスト文字については、シフト量を(検索文字数m+1)とする。   Of the conventional character string search methods described above, the method for creating a skip table is complicated in the high-speed BM method. The simple method is slow to search. The present inventor proposed a simpler and faster method in Non-Patent Document 1. This method is an improvement of the BMH method. This is called the BK method and will be briefly explained. As shown in the flowchart of FIG. 12, if the character of the text is in the search character string, the shift amount of the first character of the search character is set to (number of search characters m). The shift amount of the next character is set to (number of search characters m-1). The shift amount of the last character of the search character is set to 1. For text characters that are not in the search character string, the shift amount is (number of search characters m + 1).

文字列検索は、図13のフローチャートに示すように実行する。検索文字列と比較するテキストの部分文字列の次を指すように、ポインタを設定する。検索文字列と部分文字列を比較して不一致の場合、ポインタの指すテキストの文字を引数として、スキップテーブルを引き、シフト量を求め、検索文字列と比較する部分文字列の位置をシフトして検索を繰り返す。スキップテーブルと検索の例を図14に示す。
Yuebin Bai, Hidetsune Kobayashi: "New String Matching Technology for Network Security", Proceedings of 17th International Conference on Advanced Information Networking and Applications(AINA'03), Mrch 27-29, 2003, Xi'an, China, pp.198-201.
The character string search is executed as shown in the flowchart of FIG. Set the pointer to point to the next of the substring of the text to be compared with the search string. If the search character string and the partial character string do not match, the character of the text pointed to by the pointer is used as an argument, the skip table is drawn, the shift amount is obtained, and the position of the partial character string to be compared with the search character string is shifted. Repeat the search. An example of the skip table and search is shown in FIG.
Yuebin Bai, Hidetsune Kobayashi: "New String Matching Technology for Network Security", Proceedings of 17th International Conference on Advanced Information Networking and Applications (AINA'03), Mrch 27-29, 2003, Xi'an, China, pp.198- 201.

しかし、従来の高速マッチング法(BK法)では、テキスト文字数の回数に比例して、スキップテーブル作成の時間がかかり、十分高速ではないという問題があった。テキスト中に同じ文字があった場合、同じことを繰り返しており、むだがある。本発明は、上記従来の問題を解決して、簡単な方法でスキップテーブルを作成できる高速マッチング法を実現することを目的とする。   However, the conventional high-speed matching method (BK method) has a problem that it takes time to create a skip table in proportion to the number of text characters and is not sufficiently fast. If the same character is found in the text, the same thing is repeated and there is a waste. An object of the present invention is to solve the above-mentioned conventional problems and to realize a high-speed matching method capable of creating a skip table by a simple method.

上記の課題を解決するために、本発明では、高速マッチング法を以下のように構成した。使用文字セットの各文字のうちテキストと検索文字列とにある文字に対応するシフト量を検索文字列逆順番号数とし、テキストに無い文字と検索文字列に無い文字に対応するシフト量を(検索文字数+1)としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の直近右側の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較する。   In order to solve the above problems, in the present invention, the high-speed matching method is configured as follows. The shift amount corresponding to the character in the text and the search string in each character of the used character set is the reverse number of the search string, and the shift amount corresponding to the character not in the text and the character not in the search string is (search Create a skip table as the number of characters + 1), subtract the skip table using the rightmost character of the partial character string in the text to be compared with the search character string as an argument, obtain the shift amount, and then compare the next character in the text to be compared with the search character string. Is determined, and the partial character string is compared with the search character string.

また、高速マッチング法を以下のように構成した。検索文字列のうち最も右のワイルドカードより右にある文字に対応するシフト量を検索文字列逆順番号数とし、最も右のワイルドカードを含めてそれより左にある文字に対応するシフト量を、最も右のワイルドカードの検索文字列逆順番号数としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の直近右側の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較する。   Moreover, the high-speed matching method was comprised as follows. The shift amount corresponding to the character to the right of the rightmost wild card in the search character string is set as the reverse number of the search character string, and the shift amount corresponding to the character to the left including the rightmost wild card is Create a skip table as the number of reverse search numbers for the rightmost wild card, subtract the skip table from the right-most character of the substring in the text to be compared with the search string, find the shift amount, and search Determine the next substring in the text to be compared with the string and compare the substring with the search string.

本発明では、上記のように構成したことにより、テキスト中の同じ文字について繰り返し同じ操作をする必要がなくなるので、スキップテーブルの作成が短時間ででき、検索に要する時間が短縮される。検索文字列さえ決まればシフト量を計算でき、スキップテーブルを作成することができるので、リアルタイム性を要求されるネットワークのプロトコル等をリアルタイムに検索でき、検索文字列毎の解析が可能となる。ネットワーク上を流れる信号の中から特定のウィルスパターンをリアルタイムに検索したり、特定の検索文字列で与えられる不法なパケットをリアルタイムに検索することができる。また、特定IPを発見したときには、ただちにそのパケットを削除し、通過させないこともできる。あいまい性を考慮して類似の画像(動画、静止画)を検出できる。   In the present invention, the configuration as described above eliminates the need to repeatedly perform the same operation on the same character in the text, so that the skip table can be created in a short time and the time required for the search is shortened. Since the shift amount can be calculated and the skip table can be created as long as the search character string is determined, it is possible to search in real time for a network protocol or the like that requires real-time performance, and analysis for each search character string becomes possible. A specific virus pattern can be searched in real time from signals flowing on the network, or illegal packets given by a specific search character string can be searched in real time. In addition, when a specific IP is discovered, the packet can be deleted immediately and not passed. Similar images (moving images, still images) can be detected in consideration of ambiguity.

以下、本発明を実施するための最良の形態について、図1〜図9を参照しながら詳細に説明する。   Hereinafter, the best mode for carrying out the present invention will be described in detail with reference to FIGS.

本発明の実施例1は、使用文字セットの各文字のうちテキストと検索文字列とにある文字に対応するシフト量を検索文字列逆順番号数とし、テキストに無い文字と検索文字列に無い文字に対応するシフト量を(検索文字数+1)としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の直近右側の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較する高速マッチング法である。   In the first embodiment of the present invention, the shift amount corresponding to the character in the text and the search character string among the characters of the used character set is set as the reverse number of the search character string, and the character not in the text and the character not in the search character string Create a skip table with the shift amount corresponding to (number of search characters + 1), subtract the skip table using the rightmost character of the partial character string in the text to be compared with the search character string as the argument, and obtain the shift amount. This is a fast matching method in which the next partial character string in the text to be compared with the sequence is determined and the partial character string is compared with the search character string.

本発明の実施例1における高速マッチング法を実行する装置の構成を説明する。図1は、本発明の実施例1における高速マッチング法を実行する装置の概念図である。図1において、入力装置1は、各種データとコマンドなどを入力する手段であり、キーボードやマウスなどの入力手段と、モデムやCDROM装置などの大量のデータを取り込むことができる入力手段である。使用文字セット記憶部2は、使用文字セットを格納しておくメモリである。テキスト記憶部3は、検索対象テキストを格納しておくメモリである。検索文字列記憶部4は、検索文字列を格納しておくメモリである。スキップテーブル作成部5は、使用文字セットとテキストと検索文字列を参照しながらスキップテーブルを作成する演算部である。スキップテーブル記憶部6は、スキップテーブルを格納しておくメモリである。文字列検索部7は、スキップテーブルを参照しながらテキストから検索文字列をサーチする演算部である。検索結果記憶部8は、検索文字列に一致するテキストの部分文字列の位置を格納しておくメモリである。出力装置9は、検索結果を出力する表示装置などである。   A configuration of an apparatus that executes the high-speed matching method according to the first embodiment of the present invention will be described. FIG. 1 is a conceptual diagram of an apparatus that executes a high-speed matching method in Embodiment 1 of the present invention. In FIG. 1, an input device 1 is a means for inputting various data and commands, and is an input means such as a keyboard and a mouse and an input means capable of taking in a large amount of data such as a modem and a CDROM device. The used character set storage unit 2 is a memory for storing a used character set. The text storage unit 3 is a memory for storing search target text. The search character string storage unit 4 is a memory for storing a search character string. The skip table creation unit 5 is a calculation unit that creates a skip table while referring to the used character set, text, and search character string. The skip table storage unit 6 is a memory for storing a skip table. The character string search unit 7 is a calculation unit that searches for a search character string from text while referring to a skip table. The search result storage unit 8 is a memory that stores the position of the partial character string of the text that matches the search character string. The output device 9 is a display device that outputs search results.

本発明の実施例1における高速マッチング法の動作手順を説明する。図2は、高速マッチング法のスキップテーブル作成手順を示すフローチャートである。図3は、高速マッチング法の検索手順を示すフローチャートである。図4は、本発明の実施例1における高速マッチング法のスキップテーブルと検索例を示す図である。図5は、高速マッチング法の実験結果を示す表である。   The operation procedure of the high-speed matching method in Embodiment 1 of the present invention will be described. FIG. 2 is a flowchart showing a skip table creation procedure of the fast matching method. FIG. 3 is a flowchart showing a search procedure of the fast matching method. FIG. 4 is a diagram illustrating a skip table and a search example of the fast matching method according to the first embodiment of the present invention. FIG. 5 is a table showing experimental results of the high-speed matching method.

動作手順の概略を説明する。最初に使用文字セットを決める。例えば、ASCII半角英小文字の26字とする。「a」から1文字ずつ調べる。その文字がテキスト中と検索文字列中との両方にあれば、スキップテーブルにシフト量を登録する。シフト量は検索文字列逆順番号数とする。すなわち、検索文字数がmであれば、検索文字の先頭文字に対応するシフト量はmであり、次の文字に対応するシフト量は(m−1)であり、最後の文字に対応するシフト量は1である。テキスト中にあって検索文字列中になければ、スキップテーブルにその他の文字として登録する。シフト量は(検索文字数+1)とする。その文字がテキスト中になければ無視して、スキップテーブルには何も登録しない。スキップテーブル中に、シフト量が登録されていない検索文字があれば、テキスト中に検索文字列は存在しないことが、サーチをしなくてもわかる。このスキップテーブルを使って、従来のBK法と同様にサーチする。   An outline of the operation procedure will be described. First determine the character set to use. For example, it is assumed that there are 26 ASCII single-byte lowercase letters. Check one character at a time from "a". If the character is in both the text and the search character string, the shift amount is registered in the skip table. The shift amount is the number of reverse search string numbers. That is, if the number of search characters is m, the shift amount corresponding to the first character of the search character is m, the shift amount corresponding to the next character is (m−1), and the shift amount corresponding to the last character. Is 1. If it is in the text but not in the search character string, it is registered as another character in the skip table. The shift amount is (number of search characters + 1). If the character is not in the text, it is ignored and nothing is registered in the skip table. If there is a search character in which no shift amount is registered in the skip table, it can be understood that there is no search character string in the text without performing a search. Search using this skip table in the same way as the conventional BK method.

図2を参照しながら、高速マッチング法のスキップテーブル作成手順を説明する。ステップ1で、テキストの長さと検索文字列の長さを比較して、検索文字列が長ければマッチすることはありえないので終了とする。ステップ2で、使用文字セットから1文字ずつ取り出し、ステップ3で、テキスト中にあるかどうか調べる。テキスト中になければ何もしなし。ステップ4で、検索文字列中にあるかどうか調べ、あればステップ5でスキップテーブルに登録する。なければ、ステップ6でその他の文字として登録する。ステップ7でテキスト終了かどうか調べ、終了でなければステップ2に戻り、次の使用文字について処理を行う。   The skip table creation procedure of the high-speed matching method will be described with reference to FIG. In step 1, the length of the text is compared with the length of the search character string, and if the search character string is long, no match can be made, so the process ends. In step 2, one character is extracted from the character set to be used, and in step 3, it is checked whether it is in the text. Nothing if not in the text. In step 4, it is checked whether or not it is in the search character string. If there is, it is registered in the skip table in step 5. If not, it is registered in step 6 as other characters. In step 7, it is checked whether or not the text ends. If not, the process returns to step 2 to process the next used character.

使用文字セットの文字がテキスト中にあるか否かの検査を省略してもよい。使用文字セットの文字が検索文字列中にあれば、スキップテーブルに登録する。検索文字列中になければ、スキップテーブルにその他の文字として登録する。使用文字セットの文字がテキスト中にない場合でも、スキップテーブルに登録されるが、サーチ段階ではマッチングしないので、エラーにはならない。処理時間は条件により大差ない場合もあるが、短縮される場合もある。この方法であれば、テキストが無くてもスキップテーブルを作成できるので、テキストを受信しながら検索文字をサーチすることもできる。   You may omit the check whether the character of a character set to be used exists in a text. If the character set used is in the search string, it is registered in the skip table. If it is not in the search string, it is registered as other characters in the skip table. Even if there is no character in the used character set in the text, it is registered in the skip table, but no matching occurs at the search stage, so no error occurs. The processing time may not vary greatly depending on conditions, but may be shortened. With this method, it is possible to create a skip table without text, so it is possible to search for a search character while receiving text.

図3を参照しながら、高速マッチング法の検索手順を説明する。ステップ11で、検索文字列をテキストの先頭に合わせ、ポインタをその次の文字にセットする。ステップ12で、検索文字列とテキストの部分文字列を比較する。ステップ13で一致すれば、ステップ14で一致結果を出力する。ステップ15でテキストが終わりでなければ、ステップ16で、ポインタの指す文字を引数として、スキップテーブルを引き、シフト量を求める。ステップ17で、検索文字列をシフトして、ポインタも移動する。これをテキストが終わるまで繰り返す。   The search procedure of the fast matching method will be described with reference to FIG. In step 11, the search character string is set to the head of the text, and the pointer is set to the next character. In step 12, the search character string is compared with the partial character string of the text. If there is a match in step 13, a match result is output in step 14. If the text does not end in step 15, in step 16, the skip table is drawn using the character pointed to by the pointer as an argument to obtain the shift amount. In step 17, the search character string is shifted and the pointer is moved. Repeat this until the text ends.

図4を参照しながら、高速マッチング法のスキップテーブルと検索例を説明する。図4(a)に示すように、使用文字セットをASCII英小文字の「a〜z」26文字とする。検索文字列を「string」とする。スキップテーブルは、図示のようになる。最初の比較の時には、ポインタが「s」を指しているので、シフト量は6となる。次には、ポインタが「f」を指しているので、シフト量は7となる。図4(b)に示すように、検索文字列が「strong」であって、テキスト中に「o」がないとすると、スキップテーブルに「o」は登録されない。サーチの前にスキップテーブルと検索文字列を比較すれば、マッチしないことがわかる。図4(c)に示すように、検索文字列が「start」であり同じ文字を2つ以上含んでいる場合は、シフト量が小さい方の数が1つだけ登録される。実際のスキップテーブルにおける「t」の欄は1つだけである。   With reference to FIG. 4, a skip table and a search example of the fast matching method will be described. As shown in FIG. 4A, the character set to be used is 26 ASCII lower-case letters “az”. The search character string is “string”. The skip table is as shown in the figure. At the time of the first comparison, since the pointer points to “s”, the shift amount is 6. Next, since the pointer points to “f”, the shift amount is 7. As shown in FIG. 4B, if the search character string is “strong” and there is no “o” in the text, “o” is not registered in the skip table. If you compare the skip table with the search string before the search, you can see that there is no match. As shown in FIG. 4C, when the search character string is “start” and includes two or more of the same characters, only one with the smaller shift amount is registered. There is only one “t” column in the actual skip table.

図5を参照しながら、高速マッチング法の実験結果を説明する。この実験は、乱数を発生してテキストと検索文字列を生成し、スキップテーブルの作成とテキスト検索を繰り返したものである。表(a)は、最大テキスト長と最大検索文字列長を変えて実験したものである。本発明1は、スキップテーブルの作成において、テキストを参照したものであり、本発明2は、テキストを参照しないで作成したものである。テキストが長い場合には、BK法と比較してはるかに高速になっている。表(b)は、最大検索文字列長のみを変えて実験したものである。検索文字列が長い場合には、BK法と比較してはるかに高速になっている。表(c)は、最大テキスト長を短い一定値にして最大検索文字列長を短い範囲で変えて実験したものである。BK法と比較するとかえって低速になっている。本発明は、テキストと検索文字列が長い場合に有効であることがわかる。   The experimental results of the high-speed matching method will be described with reference to FIG. In this experiment, random numbers were generated to generate text and search strings, and skip table creation and text search were repeated. Table (a) shows an experiment in which the maximum text length and the maximum search character string length are changed. In the present invention 1, text is referred to in the creation of the skip table, and in the present invention 2, the text is not referred to. When the text is long, it is much faster than the BK method. Table (b) shows an experiment with only the maximum search character string length changed. If the search string is long, it is much faster than the BK method. Table (c) shows an experiment in which the maximum text length is set to a short constant value and the maximum search character string length is changed within a short range. Compared to the BK method, it is rather slow. It can be seen that the present invention is effective when the text and the search character string are long.

上記のように、本発明の実施例1では、高速マッチング法を、使用文字セットの各文字のうちテキストと検索文字列とにある文字に対応するシフト量を検索文字列逆順番号数とし、テキストに無い文字と検索文字列に無い文字に対応するシフト量を(検索文字数+1)としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の直近右側の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較する構成としたので、テキスト中の同じ文字について繰り返し同じ操作をする必要がなくなり、スキップテーブルの作成が短時間ででき、前処理時間が短縮されて検索時間との合計時間が短くなる。   As described above, in the first embodiment of the present invention, the fast matching method uses the shift amount corresponding to the characters in the text and the search character string among the characters of the used character set as the search character string reverse order number, Create a skip table with the shift amount corresponding to characters not in the search string and characters not in the search string as (number of search characters + 1), and use the right-most character of the substring in the text to be compared with the search string as a skip table Since the shift amount is obtained by subtracting, the next partial character string in the text to be compared with the search character string is determined, and the partial character string is compared with the search character string, the same operation is repeated for the same character in the text. The skip table can be created in a short time, the preprocessing time is shortened, and the total time with the search time is shortened.

本発明の実施例2は、検索文字列のうち、最も右のワイルドカードより右にある文字に対応するシフト量を検索文字列逆順番号数とし、最も右のワイルドカードを含めてそれより左の文字に対応するシフト量を、最も右のワイルドカードの検索文字列逆順番号数としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の右側直近の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較することにより、ワイルドカードを用いてあいまい検索ができる高速マッチング法である。   In the second embodiment of the present invention, the shift amount corresponding to the character to the right of the rightmost wild card in the search character string is set as the reverse number of the search character string, and the leftmost character including the rightmost wild card is included. Create a skip table with the shift amount corresponding to the character as the number of reverse search numbers of the rightmost wildcard search character, and use the skip table with the character immediately to the right of the substring in the text to be compared with the search character string as an argument Subtracts the shift amount, determines the next partial character string in the text to be compared with the search character string, and compares the partial character string with the search character string, enabling a fuzzy search using wildcards. It is.

図6は、本発明の実施例2における高速マッチング法を実行する装置の概念図である。文字列検索部10は、スキップテーブルを参照して減分幅を変えながらテキストから検索文字列をサーチする演算部である。実施例2における高速マッチング法を実行する装置の構成は、図1に示した実施例1の装置と同じである。異なるところは、スキップテーブルと検索文字列に関する部分である。図7は、本発明の実施例2における高速マッチング法のスキップテーブル作成手順を示すフローチャートである。図8は、高速マッチング法の検索手順を示すフローチャートである。図9は、高速マッチング法のスキップテーブルと検索例を示す図である。   FIG. 6 is a conceptual diagram of an apparatus that executes the high-speed matching method according to the second embodiment of the present invention. The character string search unit 10 is an arithmetic unit that searches a search character string from text while changing a decrement width with reference to a skip table. The configuration of the apparatus that executes the high-speed matching method in the second embodiment is the same as the apparatus of the first embodiment shown in FIG. The difference is the part related to the skip table and the search character string. FIG. 7 is a flowchart showing a skip table creation procedure of the fast matching method according to the second embodiment of the present invention. FIG. 8 is a flowchart showing the search procedure of the fast matching method. FIG. 9 is a diagram illustrating a skip table and a search example of the fast matching method.

実施例2における高速マッチング法の処理手順を説明する。検索文字列の一部の文字を、すべての文字に一致するワイルドカードとする。検索文字列中でワイルドカードの右側にある文字のシフト量は、検索文字列逆順番号数とする。最も右の文字のシフト量は1であり、次の文字のシフト量は2である。ワイルドカードがなければ、先頭の文字のシフト量は検索文字列数である。検索文字列中の最も右のワイルドカードが、右から数えて3番目にあるとすると、そのワイルドカードのシフト量は3である。最も右のワイルドカードより左にある文字とワイルドカードのシフト量は、最も右のワイルドカードのシフト量と同じである。   A processing procedure of the high-speed matching method in the second embodiment will be described. Some characters in the search string are wildcards that match all characters. The shift amount of the character on the right side of the wild card in the search character string is the number of reverse search character string numbers. The shift amount of the rightmost character is 1, and the shift amount of the next character is 2. If there is no wild card, the shift amount of the first character is the number of search character strings. If the rightmost wild card in the search character string is third from the right, the wild card shift amount is three. The shift amount between the character on the left side of the rightmost wild card and the wild card is the same as the shift amount of the rightmost wild card.

さらに、テキストと検索文字列を順番に比較するときの減分幅を変える。テキストと検索文字列の添字を減少させる幅は、通常は1であるが、ワイルドカードを含む場合は、ワイルドカードを比較しないて飛び越すので、その場合は2以上となる。検索文字列のある文字の左にワイルドカードが1つあれば、その文字に対応する減分幅は2である。連続して2つあれば3である。検索文字列が(*tring)ならば、各文字に対応する減分幅は(121111)である。以下同様に、
(s*ring,112111), (st*ing,111211), (str*ng,111121), (stri*g,111112),
(strin*,111111), (**ring,113111), (s**ing,111311), (st**ng,111131),
(str**g,111113), (stri**,111111), (s*r*ng,112121), (s*r**g,112113)
となる。
Furthermore, the decrement width when comparing the text and the search string in order is changed. The width for reducing the subscripts of the text and the search character string is normally 1. However, if a wild card is included, it is skipped without comparing the wild card. If there is one wildcard to the left of a character in the search character string, the decrement width corresponding to that character is 2. If there are two consecutive, it is 3. If the search character string is (* tring), the decrement width corresponding to each character is (121111). Similarly,
(s * ring, 112111), (st * ing, 111211), (str * ng, 111121), (stri * g, 111112),
(strin *, 111111), (** ring, 113111), (s ** ing, 111311), (st ** ng, 111131),
(str ** g, 111113), (stri **, 111111), (s * r * ng, 112121), (s * r ** g, 112113)
It becomes.

実施例2における高速マッチング法のアルゴリズムを説明する。テキストと検索文字列を与え、テキストの中に検索文字列が現れるかどうか調べ、現れれば、その位置をすべて求めるアルゴリズムである。最初に、使用文字セットを定義し、配列に格納し、使用文字の個数を求める。使用文字セットとは、テキストを構成する個個の文字のことであり、例えばアルファベットの小文字から構成されているテキストならば,'a'から'z'までの26個の文字となる。テキストや検索文字列が不明でも、通常、テキストを構成する文字を限定することは可能である。検索文字列入力時は、ワイルドカードに目印をつける。例えば、ワイルドカードを「*」とする。検索文字列からワイルドカードが最後に現れる位置を求め、減分幅を求めて配列に格納する。入力したテキストと検索文字列の長さを求め、検索文字列長がテキスト長より長ければ、テキストの中に検索文字列は現れないので、この場合は何もせずに終了する。   An algorithm of the fast matching method in the second embodiment will be described. This is an algorithm that gives a text and a search character string, checks whether the search character string appears in the text, and if it appears, finds all the positions. First, a used character set is defined and stored in an array, and the number of used characters is obtained. The character set used is the number of characters that make up the text. For example, if the text consists of lowercase letters of the alphabet, there are 26 characters from 'a' to 'z'. Even if the text and the search character string are unknown, it is usually possible to limit the characters constituting the text. When entering a search string, place a mark on the wildcard. For example, the wild card is “*”. The position where the wild card appears last is obtained from the search character string, and the decrement width is obtained and stored in the array. The length of the input text and the search character string is obtained. If the search character string length is longer than the text length, the search character string does not appear in the text. In this case, the process ends without doing anything.

前処理では、スキップテーブルを作成する。使用文字セットから1文字ずつ取り出し、文字が尽きるまで、以下の操作を行う。取り出した文字が検索文字列に含まれるか調べる。検索文字列に含まれていれば、その文字に対応するシフト量を配列に格納する。シフト量は、その文字(2文字以上あれば最も右の文字)の検索文字列逆順番号数か、最も右のワイルドカードの検索文字列逆順番号数か、いずれか小さい方とする。検索文字列に含まれていなければ、シフト量は最も右のワイルドカードの検索文字列逆順番号数とする。配列の添字は、取り出した文字の内部コードを利用する。すなわち、文字コードでスキップテーブルを引いて、シフト量を求めることができるようにする。   In the preprocessing, a skip table is created. Take out one character at a time from the used character set and perform the following operations until the characters are exhausted. Check if the retrieved character is included in the search string. If it is included in the search character string, the shift amount corresponding to the character is stored in the array. The shift amount is the smaller of the number of search character string reverse order numbers of the character (the rightmost character if there are two or more characters) or the number of search character string reverse order numbers of the rightmost wild card. If it is not included in the search character string, the shift amount is the number of reverse search numbers of the rightmost wild card search character string. The array subscript uses the internal code of the extracted character. That is, the shift amount can be obtained by subtracting the skip table with the character code.

図7を参照しながら、スキップテーブル作成手順を説明する。ステップ21で、使用文字セットから1文字ずつ取り出し、ステップ22で、検索文字列中にあるかどうか調べる。なければステップ25で、ワイルドカードシフト量を登録する。
あればステップ23で、最右のワイルドカードより右かどうか調べる。最右のワイルドカードより左ならば、ステップ25で、ワイルドカードシフト量を登録する。最右のワイルドカードより右ならば、スキップテーブルにシフト量を登録する。ステップ26で、使用文字セット終了かどうか調べ、終了でなければステップ21に戻り、次の使用文字について処理を行う。
The skip table creation procedure will be described with reference to FIG. Step 21 extracts characters one by one from the character set used, and step 22 checks whether they are in the search character string. If not, in step 25, the wild card shift amount is registered.
If there is, step 23 checks whether it is right from the rightmost wild card. If it is to the left of the rightmost wild card, in step 25, the wild card shift amount is registered. If it is to the right of the rightmost wild card, the shift amount is registered in the skip table. In step 26, it is checked whether the used character set has been completed. If not, the process returns to step 21 to process the next used character.

後処理では、検索を行う。実際の検索では、テキスト中の検索開始位置を決める。テキスト中のこの位置から前方へ向かって1文字ずつ取り出し、検索文字列の最後部の文字から前方へ向かって1文字ずつ取り出し、1文字ずつ比較をして行く。すなわち、テキスト中及び検索文字列中の添字は減少して行く。このため、テキスト中の先頭の検索文字列文字数未満の部分に検索文字列が存在することはないので、検索開始位置の初期値を(検索文字列文字数−1)とする。ただし、先頭位置を0とする。   In post-processing, a search is performed. In the actual search, the search start position in the text is determined. One character is extracted forward from this position in the text, one character is extracted forward from the last character of the search character string, and the characters are compared one by one. That is, the subscripts in the text and the search character string decrease. For this reason, since there is no search character string in the portion less than the number of first search character string characters in the text, the initial value of the search start position is set to (number of search character string characters-1). However, the head position is 0.

テキスト中を移動する検索初期値を表す添字kがテキスト長より短い間、以下の操作を繰り返す。検索文字列中を移動する添字jが最後部の文字を指すように初期化する。テキスト中を移動するための添字iの初期値を検索初期値kとする。スキップテーブルを引く文字を指すポインタは、(k+1)の位置にある。添字jが検索文字列中を移動でき、かつテキストのi番目と検索文字列のj番目が等しい間、それぞれの添字を減分幅だけ減少させる。このループを抜けたとき、検索文字列の添字jが負であれば、検索文字列を構成する全ての文字と一致したことになり、文字列が発見されたことになる。文字列発見後のテキスト中の検索初期値kがテキスト長より短いか調べる。短かければ、次の検索初期値の候補を計算する。短くなければ、一連の検索処理を終了する。   The following operation is repeated while the subscript k representing the initial search value moving in the text is shorter than the text length. Initialize the subscript j that moves through the search string to point to the last character. The initial value of the subscript i for moving through the text is set as the search initial value k. The pointer pointing to the character that draws the skip table is at the position (k + 1). While the subscript j can be moved in the search character string and the i-th of the text is equal to the j-th of the search character string, each subscript is decreased by a decrement. If the subscript j of the search character string is negative when exiting this loop, it means that all characters constituting the search character string are matched, and the character string has been found. It is checked whether the initial search value k in the text after finding the character string is shorter than the text length. If shorter, the next search initial value candidate is calculated. If it is not short, a series of search processing is terminated.

図8を参照しながら、高速マッチング法の検索手順を説明する。基本的な手順は、図3に示した実施例1の手順と同じである。ステップ31で、検索文字列をテキストの先頭に合わせ、ポインタをその次の文字にセットする。ステップ32で、ワイルドカードをスキップしながら、検索文字列とテキストの部分文字列を比較する。ステップ33で一致すれば、ステップ34で一致結果を出力する。ステップ35でテキストが終わりでなければ、ステップ36で、ポインタの指す文字を引数として、スキップテーブルを引き、ワイルドカードを考慮したシフト量を求める。ステップ37で、検索文字列をシフトして、ポインタも移動する。これをテキストが終わるまで繰り返す。   The search procedure of the fast matching method will be described with reference to FIG. The basic procedure is the same as that of the first embodiment shown in FIG. In step 31, the search character string is aligned with the beginning of the text, and the pointer is set to the next character. In step 32, the search character string is compared with the partial character string of the text while skipping the wild card. If they match at step 33, a match result is output at step 34. If the text does not end in step 35, then in step 36, the skip table is subtracted using the character pointed to by the pointer as an argument, and the shift amount considering the wild card is obtained. In step 37, the search character string is shifted and the pointer is moved. Repeat this until the text ends.

図9に示す例題を使って、あいまい検索の例を説明する。テキスト
"stringstryzgsearchstringsfindstrings"
の中から検索文字列"str**gs"をすべて検索する場合を考える。使用文字セットはアルファベット小文字とする。スキップテーブルnext[]は、
next['a']←3 next['b']←3 next['c']←3 next['d']←3 next['e']←3
next['f']←3 next['g']←2 next['h']←3 next['i']←3 next['j']←3
next['k']←3 next['l']←3 next['m']←3 next['n']←3 next['o']←3
next['p']←3 next['q']←3 next['r']←3 next['s']←1 next['t']←3
next['u']←3 next['v']←3 next['w']←3 next['x']←3 next['y']←3
next['z']←3
となる。
An example of fuzzy search will be described using the example shown in FIG. text
"stringstryzgsearchstringsfindstrings"
Consider a case where all the search character strings “str ** gs” are searched from among the search strings. Use lower-case alphabetic character set. The skip table next []
next ['a'] ← 3 next ['b'] ← 3 next ['c'] ← 3 next ['d'] ← 3 next ['e'] ← 3
next ['f'] ← 3 next ['g'] ← 2 next ['h'] ← 3 next ['i'] ← 3 next ['j'] ← 3
next ['k'] ← 3 next ['l'] ← 3 next ['m'] ← 3 next ['n'] ← 3 next ['o'] ← 3
next ['p'] ← 3 next ['q'] ← 3 next ['r'] ← 3 next ['s'] ← 1 next ['t'] ← 3
next ['u'] ← 3 next ['v'] ← 3 next ['w'] ← 3 next ['x'] ← 3 next ['y'] ← 3
next ['z'] ← 3
It becomes.

テキストの先頭の7文字と検索文字列を比較すると、テキストは「strings」であるので、一致したことを出力する。このときのポインタ先の文字は「t」であるので、スキップテーブルを引くと、シフト量は3となる。検索文字列を3文字右にシフトしてテキストと比較する。テキストは「ingstry」で不一致であるので、ポインタ先の文字「z」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「stryzgs」であるので、一致したことを出力する。ポインタ先の文字「e」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「yzgsear」で不一致であるので、ポインタ先の文字「c」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「searchs」で不一致であるので、ポインタ先の文字「t」のシフト量3文字だけ右にシフトしてテキストと比較する。   When the first seven characters of the text are compared with the search character string, since the text is “strings”, a match is output. Since the character at the pointer destination at this time is “t”, the shift amount is 3 when the skip table is drawn. Shift the search string three characters to the right and compare with the text. Since the text does not match with “ingstry”, the text is shifted to the right by the shift amount of 3 characters of the character “z” at the pointer destination and compared with the text. Since the text is “stryzgs”, a match is output. The character “e” at the pointer destination is shifted to the right by the shift amount of 3 characters and compared with the text. Since the text does not match with “yzgsear”, it is shifted to the right by the shift amount of 3 characters of the character “c” at the pointer destination and compared with the text. Since the text does not match “searchs”, it is shifted to the right by the shift amount of 3 characters of the character “t” at the pointer destination and compared with the text.

テキストは「rchstri」で不一致であるので、ポインタ先の文字「n」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「strings」であるので、一致したことを出力する。ポインタ先の文字「f」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「ingsfin」で不一致であるので、ポインタ先の文字「d」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「sfindst」で不一致であるので、ポインタ先の文字「r」のシフト量3文字だけ右にシフトしてテキストと比較する。テキストは「ndstrin」で不一致であるので、ポインタ先の文字「g」のシフト量2文字だけ右にシフトしてテキストと比較する。テキストは「strings」であるので、一致したことを出力する。   Since the text does not match with “rchstri”, the character “n” at the pointer destination is shifted to the right by the shift amount of 3 characters and compared with the text. Since the text is “strings”, a match is output. The character “f” at the pointer destination is shifted to the right by the shift amount of 3 characters and compared with the text. Since the text does not match with “ingsfin”, it is shifted to the right by the shift amount of 3 characters of the character “d” at the pointer destination and compared with the text. Since the text does not match with “sfindst”, the character “r” at the pointer destination is shifted to the right by the shift amount of 3 characters and compared with the text. Since the text is inconsistent with “ndstrin”, it is shifted to the right by the shift amount of the character “g” at the pointer destination and compared with the text. Since the text is “strings”, a match is output.

上記のように、本発明の実施例2では、高速マッチング法を、検索文字列のうち、最も右のワイルドカードより右にある文字に対応するシフト量を検索文字列逆順番号数とし、最も右のワイルドカードを含めてそれより左の文字に対応するシフト量を、最も右のワイルドカードの検索文字列逆順番号数としてスキップテーブルを作成し、検索文字列と比較するテキスト中の部分文字列の右側直近の文字を引数としてスキップテーブルを引いてシフト量を求め、検索文字列と比較するテキスト中の次の部分文字列を決定し、部分文字列を検索文字列と比較する構成としたので、ワイルドカードを用いて高速にあいまい検索ができる。   As described above, in the second embodiment of the present invention, the fast matching method uses the shift amount corresponding to the character to the right of the rightmost wild card in the search character string as the search character reverse number, and the rightmost Create a skip table with the shift amount corresponding to the left character including the wild card as the number of reverse search numbers of the rightmost wild card, and compare the search string with the substring in the text Since the rightmost character on the right side is used as an argument to calculate the shift amount by subtracting the skip table, the next partial character string in the text to be compared with the search character string is determined, and the partial character string is compared with the search character string. A fuzzy search can be performed at high speed using wildcards.

本発明の高速マッチング法は、データから特定のパターンを検索する方法として最適である。さらに、ネットワーク上でのウィルスパターンや不法パケットのリアルタイム検索や、人物特定や形状特定や場面特定や動作特定など画像処理への応用も可能である。   The fast matching method of the present invention is optimal as a method for retrieving a specific pattern from data. Furthermore, it can be applied to image processing such as real-time search for virus patterns and illegal packets on the network, person identification, shape identification, scene identification, and action identification.

本発明の実施例1における高速マッチング法を実行する装置の概念図、The conceptual diagram of the apparatus which performs the high-speed matching method in Example 1 of this invention, 本発明の実施例1における高速マッチング法のスキップテーブル作成手順を示すフローチャート、The flowchart which shows the skip table creation procedure of the high-speed matching method in Example 1 of this invention, 本発明の実施例1における高速マッチング法の検索手順を示すフローチャート、The flowchart which shows the search procedure of the high-speed matching method in Example 1 of this invention, 本発明の実施例1における高速マッチング法のスキップテーブルと検索例の説明図、Explanatory drawing of the skip table and search example of the high-speed matching method in Example 1 of this invention, 本発明の実施例1における高速マッチング法の実験結果表、Experimental result table of high-speed matching method in Example 1 of the present invention, 本発明の実施例2における高速マッチング法を実行する装置の概念図、The conceptual diagram of the apparatus which performs the high-speed matching method in Example 2 of this invention, 本発明の実施例2における高速マッチング法のスキップテーブル作成手順を示すフローチャート、The flowchart which shows the skip table creation procedure of the high-speed matching method in Example 2 of this invention, 本発明の実施例2における高速マッチング法の検索手順を示すフローチャート、The flowchart which shows the search procedure of the high-speed matching method in Example 2 of this invention, 本発明の実施例2における高速マッチング法のスキップテーブルと検索例を示す図、The figure which shows the skip table and search example of the high-speed matching method in Example 2 of this invention, 従来の文字列検索方法の説明図、Explanatory drawing of the conventional character string search method, 従来の文字列検索方法の説明図、Explanatory drawing of the conventional character string search method, 従来の高速マッチング法のスキップテーブル作成手順を示すフローチャート、A flowchart showing a skip table creation procedure of a conventional fast matching method, 従来の高速マッチング法の検索手順を示すフローチャート、A flowchart showing a conventional high-speed matching method search procedure, 従来の高速マッチング法による検索例の説明図である。It is explanatory drawing of the example of a search by the conventional high-speed matching method.

符号の説明Explanation of symbols

1 入力装置
2 使用文字セット記憶部
3 テキスト記憶部
4 検索文字列記憶部
5 スキップテーブル作成部
6 スキップテーブル記憶部
7 文字列検索部
8 検索結果記憶部
9 出力装置
10 文字列検索部
1 Input Device 2 Used Character Set Storage Unit 3 Text Storage Unit 4 Search Character String Storage Unit 5 Skip Table Creation Unit 6 Skip Table Storage Unit 7 Character String Search Unit 8 Search Result Storage Unit 9 Output Device
10 String search part

Claims (1)

各種データとコマンドなどを入力する入力装置と、前記入力装置から入力した使用文字セットを格納しておく使用文字セット記憶部と、前記入力装置から入力した検索対象テキストを格納しておくテキスト記憶部と、特定文字であるワイルドカードを含む検索文字列を前記入力装置から入力して格納しておく検索文字列記憶部と、前記使用文字セットと前記検索対象テキストと前記検索文字列を参照しながらスキップテーブルを作成するスキップテーブル作成部と、前記スキップテーブルを格納しておくスキップテーブル記憶部と、前記スキップテーブルを参照して減分幅を変えながら前記検索対象テキストから前記検索文字列をサーチする文字列検索部と、前記検索文字列に一致するテキストの部分文字列の位置を格納しておく検索結果記憶部と、検索結果を出力する出力装置とを具備する文字列検索装置において実行する高速マッチング法であって、前記使用文字セット記憶部に前記使用文字セットを格納し、前記スキップテーブル作成部で、前記使用文字セットから検査文字として1文字を取り出し、当該検査文字が前記検索文字列にあるかどうかを調べ、当該検査文字が前記検索文字列にないか、あっても前記検索文字列中の最右のワイルドカードより右でなければ、前記検索文字列中における最右のワイルドカードが右端から何番目の位置にあるかという順序数を当該検査文字に対応するシフト量として前記スキップテーブルに登録し、当該検査文字が前記検索文字列中における最右のワイルドカードより右にあれば、前記検索文字列中における当該検査文字が右端から何番目の位置にあるかという順序数を当該検査文字に対応するシフト量として前記スキップテーブルに登録し、この処理を前記使用文字セットが終了するまで繰り返し、前記使用文字セットが終了すれば前記スキップテーブルの完成とし、前記文字列検索部で、前記検索対象テキストの先頭にあって前記検索文字列と同数である文字列を最初の比較部分文字列とし、前記比較部分文字列の次にポインタを設定し、前記ワイルドカードをスキップしながら前記比較部分文字列と前記検索文字列を比較し、前記比較部分文字列と前記検索文字列の対応する位置の文字がすべて一致したら検索文字列発見とし、不一致の文字があって前記検索対象テキスト文字の終了でなければ、前記検索対象テキスト中の前記ポインタの指す文字で前記スキップテーブルを引いてシフト量を得て、前記比較部分文字列の位置を前記シフト量だけシフトして前記ポインタを新しい比較部分文字列の次に設定するように更新して、前記検索対象テキストの文字が終了するまで繰り返すことを特徴とする高速マッチング法。 An input device for inputting various data and commands, a used character set storage unit for storing a used character set input from the input device, and a text storage unit for storing a search target text input from the input device A search character string storage unit that stores a search character string including a wildcard that is a specific character by inputting from the input device, while referring to the used character set, the search target text, and the search character string A skip table creation unit that creates a skip table, a skip table storage unit that stores the skip table, and the search character string is searched from the search target text while referring to the skip table while changing a decrement. Search result record that stores the position of the character string search part and the partial character string of the text that matches the search character string And a fast matching method executed in a character string search device comprising an output device for outputting a search result, storing the used character set in the used character set storage unit, and in the skip table creating unit, One character is extracted as a check character from the character set to be used, and it is checked whether the check character is in the search character string. If the check character is not in the search character string, even if it is present, If it is not right than the right wild card, the order number indicating the position of the rightmost wild card in the search character string from the right end is registered in the skip table as the shift amount corresponding to the check character. If the inspection character is on the right side of the rightmost wild card in the search character string, the inspection character in the search character string is The order number indicating whether the character is in the th position is registered in the skip table as a shift amount corresponding to the check character, and this process is repeated until the use character set is completed. In the character string search unit, a character string that is at the beginning of the search target text and has the same number as the search character string is set as the first comparison partial character string, and a pointer is set next to the comparison partial character string. The comparison partial character string is compared with the search character string while skipping the wild card, and if all the characters in the corresponding positions of the comparison partial character string and the search character string are matched, the search character string is found and mismatched. If there is a character that is not the end of the search target text character, the skip table is used for the character indicated by the pointer in the search target text. A shift amount is obtained by pulling a bull, the position of the comparison partial character string is shifted by the shift amount, and the pointer is updated to be set next to the new comparison partial character string. A high-speed matching method that repeats until the end of .
JP2003428585A 2003-12-25 2003-12-25 Fast matching method Expired - Fee Related JP4565064B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2003428585A JP4565064B2 (en) 2003-12-25 2003-12-25 Fast matching method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2003428585A JP4565064B2 (en) 2003-12-25 2003-12-25 Fast matching method

Publications (2)

Publication Number Publication Date
JP2005190032A JP2005190032A (en) 2005-07-14
JP4565064B2 true JP4565064B2 (en) 2010-10-20

Family

ID=34787500

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2003428585A Expired - Fee Related JP4565064B2 (en) 2003-12-25 2003-12-25 Fast matching method

Country Status (1)

Country Link
JP (1) JP4565064B2 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9825841B2 (en) 2012-06-29 2017-11-21 Telefonaktiebolaget Lm Ericsson (Publ) Method of and network server for detecting data patterns in an input data stream
US9870502B2 (en) 2012-09-28 2018-01-16 Telefonaktiebolaget Lm Ericsson (Publ) Apparatus for, a method of, and a network server for detecting data patterns in a data stream

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP5523191B2 (en) 2010-04-30 2014-06-18 株式会社ジャパンディスプレイ Display device with touch detection function
CN112733524A (en) * 2020-12-31 2021-04-30 浙江省方大标准信息有限公司 Method, system and device for automatically correcting standard serial numbers and batch checking standard states

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9825841B2 (en) 2012-06-29 2017-11-21 Telefonaktiebolaget Lm Ericsson (Publ) Method of and network server for detecting data patterns in an input data stream
US9870502B2 (en) 2012-09-28 2018-01-16 Telefonaktiebolaget Lm Ericsson (Publ) Apparatus for, a method of, and a network server for detecting data patterns in a data stream

Also Published As

Publication number Publication date
JP2005190032A (en) 2005-07-14

Similar Documents

Publication Publication Date Title
JP2683870B2 (en) Character string search system and method
US10552699B2 (en) Robust string text detection for industrial optical character recognition
US7240048B2 (en) System and method of parallel pattern matching
JP3689455B2 (en) Information processing method and apparatus
JP2726568B2 (en) Character recognition method and device
US8032479B2 (en) String matching system and program therefor
US8200646B2 (en) Efficient retrieval of variable-length character string data
CN106959962B (en) A kind of multi-pattern match method and apparatus
US20140372477A1 (en) Conditional string search
JP2005025763A (en) Division program, division device and division method for structured document
JP3480404B2 (en) Vocabulary major classification device, its major category classification method, and recording medium recording its control program
EP2093700A2 (en) Pattern recognition method, and storage medium which stores pattern recognition program
Clifford et al. Dictionary matching in a stream
US8701162B1 (en) Method and system for detecting and countering malware in a computer
JP4565064B2 (en) Fast matching method
KR100959244B1 (en) High-speed string pattern matching method using layered SHIFT tables
US9690873B2 (en) System and method for bit-map based keyword spotting in communication traffic
JP2022103676A (en) Information processing device, information processing method and program
JP3852757B2 (en) Character string matching method, document processing apparatus and program using the same
KR101245631B1 (en) Approximate collation device, approximate collation method, program, and recording medium
KR102146625B1 (en) Apparatus and method for computing incrementally infix probabilities based on automata
JP7172343B2 (en) Document retrieval program
Zhang An improved Wu-Manber multiple patterns matching algorithm
CN113010882B (en) Custom position sequence pattern matching method suitable for cache loss attack
JP2006163830A (en) Character recognizing device, character recognizing method, and character recognizing program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20061219

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20090825

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20091021

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20100112

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20100215

A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20100316

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20100419

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130813

Year of fee payment: 3

LAPS Cancellation because of no payment of annual fees