JP2010061301A - Clone code detection device, clone code detection method, and program - Google Patents
Clone code detection device, clone code detection method, and program Download PDFInfo
- Publication number
- JP2010061301A JP2010061301A JP2008225135A JP2008225135A JP2010061301A JP 2010061301 A JP2010061301 A JP 2010061301A JP 2008225135 A JP2008225135 A JP 2008225135A JP 2008225135 A JP2008225135 A JP 2008225135A JP 2010061301 A JP2010061301 A JP 2010061301A
- Authority
- JP
- Japan
- Prior art keywords
- section information
- detection
- clone
- detection table
- file
- 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.)
- Granted
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
- Stored Programmes (AREA)
Abstract
Description
本発明は、ファイル間のクローンコードの検出処理に適用される技術に関するものである。 The present invention relates to a technique applied to a process for detecting a clone code between files.
近年、コンピュータシステムの開発において、大量のソースコードを多人数で記述することが行われている。コンピュータシステム開発のプロジェクトでは、プロジェクトを評価することも行われている。このような開発の場面では、あるメンバが作成したソースコードを他のメンバがコピー(クローン)して使うことが行われる場合もある。 In recent years, a large amount of source code has been described by a large number of people in the development of computer systems. In computer system development projects, projects are also evaluated. In such a development situation, the source code created by one member may be copied (clone) by another member and used.
フレームワークの自動生成コードの可能性や手法によっては過検出の場合があるため、単純にクローンが多いことだけでは良し悪しを評価できないが、クローンコードは多くの場合、不具合や機能変更時の修正コストを増大させるため、クローンが多いことは望ましいことではなく、クローンを検出することはプロジェクトを評価する上で重要な指標である。 Depending on the possibility and method of automatically generated code of the framework, there are cases where over-detection may occur, so it is not possible to evaluate whether it is simply a large number of clones, but the clone code is often corrected when there are defects or function changes To increase costs, having a large number of clones is not desirable, and detecting clones is an important indicator in evaluating a project.
なお、クローンコードは次のようにして発生することが考えられる。第1に、作業者が自分自身や他者のソースコードをコピー&ペーストを行ってクローンコードが発生する場合が挙げられる。第2に、アプリケーションフレームワーク等で同じようなコードが自動生成される場合が挙げられる。 The clone code can be generated as follows. First, there is a case where a clone code is generated when an operator copies and pastes the source code of himself or another person. Secondly, there is a case where similar code is automatically generated by an application framework or the like.
しかしながら、従来からクローンコードを検出する方法が存在するが、その検出処理の計算量が多く、クローンコードの検出に多くの時間がかかってしまい、実用的と言えるものではなかった。効率的にクローンコードを検出する技術が例えば特許文献1に開示されている。
However, there is a conventional method for detecting a clone code, but the calculation amount of the detection process is large, and it takes a lot of time to detect the clone code, which is not practical. For example,
特許文献1には、テキストから同形パターンを検出する同形パターン検出システムが開示されている。特許文献1に開示される同形パターン検出システムでは、字句解析、規則による変形、パラメータ変換、同形検出、同形出力により対象のテキストの同形を検出する。しかしながら、特許文献1に開示される同形パターン検出システムは、計算量がO(N)〜O(NlogN)と高速であるが、抽出されたクローンコードが最長一致ではないので過検出が多くなるという問題があった。
そこで、本発明の目的は、検出するクローンコードの最長一致を図り、クローンコードの過検出を防ぐことにある。 Therefore, an object of the present invention is to achieve the longest match of the clone codes to be detected and to prevent overdetection of the clone codes.
本発明のクローンコード検出装置は、クローンコード検出対象のファイルにおける所定の単位のデータ毎の区間情報を第1の検出テーブルに登録するとともに、クローンコード検出対象のファイルとの比較対象となるファイルにおける前記所定の単位のデータ毎の区間情報を前記第1の検出テーブルに登録する第1の検出テーブル生成手段と、前記第1の検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記第1の検出テーブルにおける該当する区間情報をファイル毎に結合させる第1の結合手段と、前記第1の検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成手段とを有することを特徴とする。
本発明のクローンコード検出方法は、クローンコード検出装置によるクローンコード検出方法であって、クローンコード検出対象のファイルにおける所定の単位のデータ毎の区間情報を検出テーブルに登録するとともに、クローンコード検出対象のファイルとの比較対象となるファイルにおける前記所定の単位のデータ毎の区間情報を前記検出テーブルに登録する検出テーブル生成ステップと、前記検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記検出テーブルにおける該当する区間情報をファイル毎に結合させる結合ステップと、前記検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成ステップとを含むことを特徴とする。
本発明のプログラムは、クローンコード検出対象のファイルにおける所定の単位のデータ毎の区間情報を検出テーブルに登録するとともに、クローンコード検出対象のファイルとの比較対象となるファイルにおける前記所定の単位のデータ毎の区間情報を前記検出テーブルに登録する検出テーブル生成ステップと、前記検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記検出テーブルにおける該当する区間情報をファイル毎に結合させる結合ステップと、前記検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成ステップとをコンピュータに実行させることを特徴とする。
The clone code detection apparatus of the present invention registers the section information for each predetermined unit of data in the clone code detection target file in the first detection table, and in the file to be compared with the clone code detection target file. First detection table generating means for registering section information for each predetermined unit of data in the first detection table, and section information between the predetermined unit of data in the first detection table is a predetermined condition. When satisfying, the first combining means for combining the corresponding section information in the first detection table for each file, and the clone code that extracts the section information in the first detection table and registers it in the clone code table And a table generation means.
The clone code detection method of the present invention is a clone code detection method by a clone code detection device, and registers the section information for each predetermined unit of data in a clone code detection target file in the detection table, and the clone code detection target A detection table generating step for registering, in the detection table, section information for each data of the predetermined unit in the file to be compared with the file, and section information between the data of the predetermined unit in the detection table is predetermined. If the condition is satisfied, the method includes a combining step of combining corresponding section information in the detection table for each file, and a clone code table generating step of extracting the section information in the detection table and registering the information in the clone code table. Features.
The program of the present invention registers the section information for each predetermined unit of data in the clone code detection target file in the detection table, and the predetermined unit of data in the file to be compared with the clone code detection target file A detection table generating step for registering each section information in the detection table, and when section information between the predetermined unit data in the detection table satisfies a predetermined condition, the corresponding section information in the detection table is stored for each file. And a clone code table generation step of extracting section information in the detection table and registering it in the clone code table.
本発明においては、クローンコード検出対象のファイルと当該ファイルの比較対象となるファイルとの間の区間情報をファイル毎に結合し、結合した区間情報をクローンコードテーブルに登録するように構成している。従って、本発明によれば、検出するクローンコードの最長一致を図ることが可能となり、クローンコードの過検出を防ぐことができる。 In the present invention, section information between a clone code detection target file and a file to be compared with the file is combined for each file, and the combined section information is registered in the clone code table. . Therefore, according to the present invention, it is possible to achieve the longest match between the clone codes to be detected, and it is possible to prevent over-detection of the clone codes.
以下、本発明を適用した好適な実施形態を、添付図面を参照しながら詳細に説明する。 DESCRIPTION OF EXEMPLARY EMBODIMENTS Hereinafter, preferred embodiments to which the invention is applied will be described in detail with reference to the accompanying drawings.
図1は、本発明の実施形態に係るクローンコード検出装置の機能的な構成を示すブロック図である。図1に示すように、本実施形態に係るクローンコード検出装置100は、基底テーブル作成部101、検出テーブル作成部102、クローン簡易結合部103、クローン結合部104及び包含クローン削除部105により構成される。
FIG. 1 is a block diagram showing a functional configuration of a clone code detection apparatus according to an embodiment of the present invention. As shown in FIG. 1, the clone
基底テーブル作成部101は、最後にクローンコードの検出を行った時点における最新ファイルのソースコードをトークン列に変換し、n-gram化されたトークン列とそれらのトークン列の区間情報を基底テーブルに登録する。
The base
検出テーブル作成部102は、クローンコードの検出対象となるファイルのソースコードをトークン列に変換し、n-gram化されたトークン列とそれらのトークン列の区間情報とを検出テーブルに登録する。そして、検出テーブル作成部102は、基底テーブルに登録される区間情報を後述する方法によって検出テーブルに登録する。
The detection
クローン簡易結合部103は、検出テーブルのレコード同士の対応する区間情報を比較し、比較した区間情報が各ファイル間で同じオフセットを有するのであれば、区間情報の結合を行う。
The clone simple combining
クローン結合部104は、クローン簡易結合部103により生成された検出テーブルから、ファイル毎に区間情報を取得する。そして、クローン結合部104は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが重なる、又は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが接続される場合、それらの区間情報を結合した区間情報を新検出テーブルに登録する。
The
包含クローン削除部105は、検出テーブルと新検出テーブルとを比較し、検出テーブルの区間情報が新検出テーブルの区間情報に完全に包含されている場合、即ち、検出テーブル内に過検出となっている区間情報が存在する場合、検出テーブルにおける過検出の区間情報が登録されているレコードを削除する。
The inclusion
図2は、本実施形態に係るクローンコード検出装置100のハードウェア構成を示す図である。
FIG. 2 is a diagram illustrating a hardware configuration of the clone
CPU201は、システムバスに接続される各デバイスやコントローラを統括的に制御する。ROM203又はHD(ハードディスク)207には、CPU201の制御プログラムであるBIOS(Basic Input / Output System)やオペレーティングシステムプログラム、クローンコード検出装置100が実行する例えば図3−1乃至図3−3に示す処理のプログラム等が記憶されている。
The
なお、図2の例では、HD207はクローンコード検出装置100の内部に配置された構成としているが、他の実施形態としてHD207に相当する構成がクローンコード検出装置100の外部に配置された構成としてもよい。また、本実施形態に係る例えば図3−1乃至図3−3に示す処理を行うためのプログラムは、フレキシブルディスク(FD)やCD−ROM等、コンピュータ読み取り可能な記録媒体に記録され、それらの記録媒体から供給される構成としてもよいし、インターネット等の通信媒体を介して供給される構成としてもよい。
In the example of FIG. 2, the
RAM202は、CPU201の主メモリ、ワークエリア等として機能する。CPU201は、処理の実行に際して必要なプログラム等をRAM202にロードして、プログラムを実行することで各種動作を実現するものである。
The RAM 202 functions as a main memory, work area, and the like for the
HD207やFD206は、外部メモリとして機能する。CPU201は、処理の実行に際して必要なプログラム等をRAM202にロードして、プログラムを実行することで各種動作を実現するものである。
The
ディスクコントローラ205は、HD207やFD206等の外部メモリへのアクセスを制御する。通信I/Fコントローラ204は、インターネットやLANと接続し、例えばTCP/IPによって外部との通信を制御するものである。
The
ディスプレイコントローラ208は、ディスプレイ209における画像表示を制御する。
The
KBコントローラ210は、KB(キーボード)211からの操作入力を受け付け、CPU201に対して送信する。なお、図示していないが、KB211の他に、マウス等のポインティングデバイスもユーザの操作手段として本実施形態に係るクローンコード検出装置100に適用可能である。
The
図1に示す基底テーブル作成部101、検出テーブル作成部102、クローン簡易結合部103、クローン結合部104及び包含クローン削除部105は、例えばHD207内に記憶され、必要に応じてRAM202にロードされるプログラム及びそれを実行するCPU201によって実現される構成である。
The base
図3−1乃至図3−3は、本実施形態に係るクローンコード検出装置100の動作の流れを示すフローチャートである。以下、図3−1乃至図3−3に示すフローチャートを参照しながらクローンコード検出装置100の動作の流れについて説明するが、その説明の前に、図4を用いてリポジトリにおけるファイルの格納状況の一例について説明する。リポジトリには、クローンコード検出装置100によるクローンコードの検出対象となるファイルが格納されている。リポジトリは、クローンコード検出装置100内部におけるHDD等の記録媒体の一部記録領域に構成されてもよいし、クローンコード検出装置100と通信回線を介して接続されるDBサーバ等に構成されてもよい。なお、図4に示すリポジトリにおけるファイルの格納構成は飽くまでも一例であり、クローンコード検出装置100が処理の対象は図4に示すファイルのみではない。従って、以下の説明においては、説明の容易のため、図4に示すファイル以外も適宜使用してクローンコード検出装置100の動作を説明する。
するものとする。
FIGS. 3A to 3C are flowcharts illustrating the operation flow of the clone
It shall be.
図4は、リポジトリにおける各ファイルの各バージョンの格納状況とともにバージョンの更新状況を示す図である。図4では、時間の経過を図面の上方から下方に表している。図4において、ファイル1(F1)は、バージョン1(V1)でリポジトリに登録され、それ以降の更新はない。ファイル2(F2)は、バージョン1(V1)でリポジトリに登録され、その後、バージョン2(V2)、バージョン3(V3)と2度更新されて登録されている。即ち、ファイル2については、バージョン1〜3のファイルが夫々登録されている。ファイル3(F3)は、バージョン1でリポジトリに登録され、その後、バージョン2、バージョン3、バージョン4と3度更新されて登録されている。即ち、ファイル3については、バージョン1〜4のファイルが夫々登録されている。401の破線は、最後にクローンコードの検出処理が行われた時点を表しており、402の破線は、現在時刻を表している。即ち、図4では、最後にクローンコードの検出が行われた時点でリポジトリに登録される最新ファイルは、ファイル1ではバージョン1、ファイル2ではバージョン2、ファイル3ではバージョン2であることを表している。また、図4では、最後のクローンコードの検出が行われた時点からファイル2がバージョン2からバージョン3に1度更新され、ファイル3がバージョン2からバージョン4まで2度更新されたことが示されている。
FIG. 4 is a diagram showing the update status of each version together with the storage status of each version of each file in the repository. In FIG. 4, the passage of time is shown from the top to the bottom of the drawing. In FIG. 4, file 1 (F1) is registered in the repository with version 1 (V1), and there is no subsequent update. File 2 (F2) is registered in the repository with version 1 (V1), and then updated and registered twice with version 2 (V2) and version 3 (V3). That is, as for the file 2, files of
次に、クローンコード検出装置100の動作について説明する。図3−1において、基底テーブル作成部101は、最後にクローンコードの検出を行った時点における最新ファイルをリポジトリから読み出す(ステップS301)。即ち、基底テーブル作成部101は、ファイル1のバージョン1、ファイル2のバージョン2、ファイル3のバージョン2を読み出す。
Next, the operation of the clone
続いて、基底テーブル作成部101は、リポジトリから取り出した各ファイル内に記述されるソースコードを構文解析し、voidであればVといったように、ソースコードをトークン列に変換する(ステップS302)。ここでの変換ルールはad hocを用いる。
Subsequently, the base
図5は、ソースコードからトークン列への変換例と基底テーブルの構成例とを示す図である。図5の501、502に示すように、void(ソースコード)はV(トークン)に、method1(ソースコード)は$(トークン)に、int(ソースコード)はI(トークン)に、arg(ソースコード)は%(トークン)に、long(ソースコード)はL(トークン)に、I(ソースコード)は%(トークン)に、10L(ソースコード)は&(トークン)に変換されている。 FIG. 5 is a diagram illustrating a conversion example from a source code to a token string and a configuration example of a base table. As shown in 501 and 502 of FIG. 5, void (source code) is V (token), method1 (source code) is $ (token), int (source code) is I (token), arg (source) Code () is converted to% (token), long (source code) is converted to L (token), I (source code) is converted to% (token), and 10L (source code) is converted to & (token).
続いて、基底テーブル作成部101は、トークン列をn-gram(n=1,2,3,・・・、図5では、n=10)化し、n-gram化されたトークン列とファイル内におけるトークン列の区間情報とを基底テーブルに登録する(ステップS303)。図5の503に示すように、基底テーブルにおいて、トークン列v$(I%)[L%=がファイル1の2行目の2列目(2,1)から3行目の4列目(3,4)まで((2,1)−(3,4))、トークン列v$(I%)[L%=がファイル2の10行目の1列目から10行目の9列目まで((10,1)−(10,9))、トークン列v$(I%)[L%=がファイル3の1行目の1列目から1行目の9列目まで((1,1)−(1,9))存在することが区間情報として登録されている。
Subsequently, the base
また、トークン列$(I%)[L%=&がファイル1の2行目の2列目から3行目の5列目まで((2,2)−(3,5))、トークン列$(I%)[L%=&がファイル3の1行目の2列目から1行目の10列目まで((1,2)−(1,10))存在することが区間情報として登録されている。 Also, the token string $ (I%) [L% = & is from the second column of the second row to the fifth column of the third row ((2, 2)-(3, 5)), Section information indicates that $ (I%) [L% = & exists from the second column of the first row to the tenth column of the first row ((1,2)-(1,10)). It is registered.
また、トークン列(I%)[L%=&;がファイル3の1行目の3列目から1行目の11列目まで((1,3)−(1,11))存在することが区間情報として登録されている。また、トークン列=$(%,%,%);がファイル1の12行目の1列目から12行目の12列目まで((12,1)−(12,12))存在することが区間情報として登録されている。
Further, the token string (I%) [L% = &; exists from the third column of the first row of the
図6は、検出テーブル作成部102による検出テーブルの作成処理を説明するための図である。図6においては、ファイル3のバージョン3をクローンコードの検出対象とした場合に作成される検出テーブルの構成例を示している。
FIG. 6 is a diagram for explaining detection table creation processing by the detection
続いて、検出テーブル作成部102は、基底テーブルに検出対象のファイル3の旧バージョンが存在するか否かを判定する(ステップS304)。ファイル3の旧バージョンが存在する場合、検出テーブル作成部102は、図6の601に示すように、基底テーブルから検出対象のファイル3の旧バージョンの区間情報を削除する(ステップS305)。これは、バージョン違いの同一種類のファイルである場合、新バージョンのファイルは旧バージョンのファイルが部分的に更新されて共通部分が多いため、その共通部分をクローンコードとして検出するのは適切ではないからである。一方、ファイル3の旧バージョンが存在しない場合、処理はステップS305を実行せずにステップS306に移行する。
Subsequently, the detection
続いて、検出テーブル作成部102は、ファイル3のバージョン3をリポジトリから読み出す(ステップS306)。そして、検出テーブル作成部102は、ファイル3のバージョン3内に記述されるソースコードを構文解析し、トークン列に変換する(ステップS307)。
Subsequently, the detection
続いて、検出テーブル作成部102は、トークン列をn-gram化し、n-gram化されたトークン列と該当するトークン列のファイル内における区間情報とを検出テーブルに登録する(ステップS308)。図6の602に示すように、クローン列v$(I%)[L%=がファイルF3のバージョンv3の2行目の5列目から2行目の13行目まで((2,5)−(2,13))、クローン列$(I%)[L%=&がファイルF3のバージョンv3の2行目の6行目から2行目の14行目まで((2,6)−(2,14))、クローン列(I%)[L%=&;がファイルF3のバージョンv3の2行目の7列目から2行目の15列目まで((2,7)−(2,15))存在することが区間情報として登録されている。
Subsequently, the detection
続いて、検出テーブル作成部102は、検出テーブルに区間情報が登録されているトークン列と同じトークン列に区間情報が基底テーブルにおいて登録されている場合、基底テーブルにおける該当するトークン列の区間情報を検出テーブルに登録する(ステップS309)。
Subsequently, when the section information is registered in the base table in the same token string as the token string in which the section information is registered in the detection table, the detection
図6の603に示すように、検出テーブルにおいて、3つのトークン列v$(I%)[L%=、$(I%)[L%=&、(I%)[L%=&;の区間情報が登録されているが、基底テーブルでは、そのうちの2つのトークン列v$(I%)[L%=、$(I%)[L%=&の区間情報が登録された状態となっている。従って、検出テーブル作成部102は、基底テーブルにおける2つのトークン列v$(I%)[L%=、$(I%)[L%=&の区間情報を検出テーブルに登録する。
As indicated by
続いて、図3−2において、検出テーブル作成部102は、ファイル間において区間情報が1つしか登録されていないトークン列のレコードが存在するか否かを判定する(ステップS310)。ファイル間において区間情報が1つしか登録されていない場合、検出テーブル作成部102は、該当するレコードを削除する(ステップS311)。これは、ファイル間において区間情報が1つしか登録されていないトークン列は、その時点でクローンコードではないことが明らかなためである。図6の例では、トークン列(I%)[L%=&;のレコードにはファイル3の区間情報しか登録されない。従って、トークン列(I%)[L%=&;のレコードが削除されることになる。以上により、図6の603に示す検出テーブルが作成される。一方、ファイル間において区間情報が1つしか登録されていないトークン列のレコードが存在しない場合、処理はステップS311を実行せずにステップS312に移行する。
Subsequently, in FIG. 3B, the detection
続いて、クローン簡易結合部103は、検出テーブルの各レコードを区間情報の数毎に分類する(ステップS312)。図7の例においては、4つの区間情報を登録しているトークン列V$(I%)[L%=のレコードとトークン列(I%)[L%=&;のレコードとの分類と、3つの区間情報を登録しているトークン列$(I%)[L%=&のレコードとトークン列I%)[L%=&;%のレコードとの分類になる。
Subsequently, the clone
続いて、クローン簡易結合部103は、クローン簡易結合処理を行う(ステップS313)。即ち、クローン簡易結合部103は、分類毎に、レコード同士の対応する区間情報を比較し、比較した区間情報が各ファイル間で同じオフセットを有するのであれば、区間情報の結合を行う。
Subsequently, the clone
図7は、クローン簡易結合部103によるクローン簡易結合の処理を説明するための図である。ここでは、図7の701に示すように、検出テーブルにおいて4つのトークン列について区間情報が登録されている場合を例示している。即ち、検出テーブルにおいて、4つのファイル4〜7にトークン列V$(I%)[L%=の区間情報が登録され、4つのファイル4〜7にトークン列(I%)[L%=&;の区間情報が登録されている。また、3つのファイル4〜6にトークン列$(I%)[L%=&の区間情報が登録され、3つのファイル4〜6にトークン列I%)[L%=&;%の区間情報が登録されている。
FIG. 7 is a diagram for explaining the process of simple clone combining by the clone
図7の例では、トークン列V$(I%)[L%=の区間情報として、ファイル4、ファイル5、ファイル6、ファイル7について夫々、(2,1)−(3,3)、(3,2)−(4,4)、(4,5)−(5,7)、(6,2)−(7,4)が登録され、トークン列(I%)[L%=&;の区間情報として、(2,2)−(3,4)、(3,3)−(4,5)、(4,6)−(5,8)、(6,3)−(7,5)が登録されている。比較する区間情報は全て同じオフセット(横軸方向の1座標分)を有する。従って、この場合には区間情報の結合が行われる。即ち、検出テーブル作成部102は、比較したトークン列のうちの前段のトークン列の始端から後段のトークン列の終端までを結合した区間情報を生成する。このとき、クローン簡易結合部103は、分類毎に分けられたレコードのうちの1つのレコードのトークン列を結合後のトークン列に更新するとともに、当該レコードの各区間情報を結合後の区間情報に更新する。そして、クローン簡易結合部103は、当該分類に属する他のレコードを全て削除する。このようにクローン簡易結合処理の後は、図7の702に示す検出テーブルが生成される。
In the example of FIG. 7, as the section information of the token string V $ (I%) [L% =, (2, 1)-(3, 3), ( 3,2)-(4,4), (4,5)-(5,7), (6,2)-(7,4) are registered, and a token string (I%) [L% = &; (2, 2)-(3,4), (3, 3)-(4, 5), (4, 6)-(5, 8), (6, 3)-(7, 5) is registered. All section information to be compared has the same offset (one coordinate in the horizontal axis direction). Therefore, in this case, the section information is combined. In other words, the detection
ファイル毎に各区間情報を結合させた場合、結合後の区間情報に該当するトークン列は複数のファイル間に亘って同一のトークン列であると看做せる。従って、上述したクローン簡易結合処理は、レコード間において、複数のファイルに亘って或るトークン列の区間情報が同じ数だけ登録され、且つ同一分類のレコード間において、夫々のトークン列の区間情報が複数のファイルに亘って同じオフセットで登録されている場合に行われる。 When the section information is combined for each file, the token string corresponding to the combined section information can be regarded as the same token string across a plurality of files. Therefore, in the above-described clone simple combination process, the same number of section information of a certain token string is registered across a plurality of files between records, and the section information of each token string is recorded between records of the same classification. This is performed when a plurality of files are registered with the same offset.
続いて、クローン結合部104は、クローン結合処理を行う(ステップS314)。即ち、クローン結合部104は、クローン簡易結合部103により生成された検出テーブルから、ファイル毎に区間情報を取得する。そして、クローン結合部104は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが重なる、又は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが接続される場合、それらの区間情報を結合した区間情報を新検出テーブルに登録する。これにより、n-gram化されたトークン列を結合させた一連のトークン列に対応する区間情報が登録された新検出テーブルが作成される。
Subsequently, the
図8は、クローン結合部104によるクローン結合処理を説明するための図である。図8の801は、検出テーブルであり、図8の802は、検出テーブルに対してクローン結合処理を行うことにより生成される新検出テーブルである。検出テーブルは、トークン列$();(L%=N;のファイル9の区間情報が(10,3)−(11,5)であり、トークン列$();[L%=$(のファイル9の区間情報が(9,5)−(10,7)である。従って、前段のトークン列の区間情報((9,5)−(10,7))の終端と後段のトークン列の区間情報((10,3)−(11,5))の始端とが重なる。よって、それらの区間情報を結合した区間情報(9,5)−(11,5)が算出される。
FIG. 8 is a diagram for explaining clone joining processing by the
また、トークン列$(%,%,%,%)のファイル9の区間情報が(11,5)−(12,7)であるため、トークン列$();(L%=N;のファイル9の区間情報((10,3)−(11,5))の終端と接続する。従って、それらの区間情報を結合した区間情報(10,3)−(12,7)が算出される。他のファイル10〜12についても同様に区間情報の結合が行われる。なお、ファイル13については、トークン列$();[L%=N;にのみ区間情報が登録されているため、区間情報の結合は行われない。 Further, since the section information of the file 9 of the token sequence $ (%,%,%,%) is (11, 5)-(12, 7), the file of the token sequence $ (); (L% = N; 9 is connected to the end of the section information ((10, 3)-(11, 5)), so section information (10, 3)-(12, 7) is calculated by combining the section information. The section information is similarly combined for the other files 10 to 12. Since section information is registered only in the token string $ (); [L% = N; Are not combined.
続いて、クローン結合部104は、クローン結合処理により結合された区間情報が存在したか否かを判定する(ステップS315)。クローン結合処理により結合された区間情報が存在する場合、クローン結合部104は、新検出テーブルにおいて、結合後のトークン列に結合後の区間情報を対応付けて登録する(ステップS316)。一方、クローン結合処理により結合された区間情報が存在しない場合、処理はステップS316を実行せずに図3−3のステップS317に移行する。
Subsequently, the
続いて、クローン結合部104は、新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在するか否かを判定する(ステップS317)。新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在する場合、クローン結合部104は、該当するレコードを削除する(ステップS318)。これは、ファイル間で1つの区間情報しか登録されていないトークン列はクローンではないためである。図8の例では、トークン列$();[L%=$();[L%=$(のレコードが削除されることになる。一方、新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在しない場合、処理はステップS318を実行せずにステップS319に移行する。上述したステップS314〜S318の処理によって、図8の801に示す検出テーブルから図8の802に示す新検出テーブルが生成される。
Subsequently, the
図9及び図10は、包含クローン削除部105の動作を説明するための図である。包含クローン削除部105は、検出テーブルに登録されるファイルをグループに分離するとともに、新検出テーブルに登録されるファイルをグループに分離する(ステップS319)。このグループ分けは、同一のトークン列で区間情報が登録されているファイルを同じグループにする。このようにグループ分けするのは、後述するクローンの過検出処理をファイル毎に行うより、より高くクローンの可能性を有するグループ毎に過検出処理を行った方が処理量を軽減させることができるためである。図9の901は、検出テーブルのグループ分けの状況を示し、図9の902は、新検出テーブルのグループ分けの状況を示している。検出テーブル及び新検出テーブルはともに、ファイル9とファイル10のグループA、ファイル11とファイル12のグループBに分けられる。
9 and 10 are diagrams for explaining the operation of the inclusion
続いて、包含クローン削除部105は、検出テーブルと新検出テーブルとの間でグループ毎に区間情報を比較し、結合テーブルの区間情報が新結合テーブルの区間情報に完全に包含されているか否かを判定する(ステップS320)。即ち、ステップS320では、検出テーブル内に過検出となっている区間情報が存在するか否かを判定している。例えば、新検出テーブル内にトークン列ABABAが登録され、検出テーブル内にトークン列BABがトークン列ABABAの区間情報に包含される区間情報で登録されているような場合、最長のトークン列ABABAだけを検出すればよく、そのトークン列に含まれるトークン列BABは検出する必要はない。このような場合、トークン列BABを検出することは過検出であり、ステップS320ではこの過検出の判定を行っている。
Subsequently, the inclusion
結合テーブルの区間情報が新結合テーブルの区間情報に完全に包含されている場合、包含クローン削除部105は、結合テーブルの該当するレコードを削除する(ステップS321)。即ち、包含クローン削除部105は、結合テーブルにおける過検出の区間情報が登録されているレコードを削除する。
If the section information of the combined table is completely included in the section information of the new combined table, the included
図10の1001に示すように、結合テーブルのトークン列$(%,%,%,%)のファイル9の区間情報が(11,5)−(12,7)、同じく結合テーブルのトークン列$(%,%,%,%)のファイル10の区間情報が(12,5)−(13,7)である。また、図10の1002に示すように、新結合テーブルのトークン列$();[L%=N;$(%,%,%,%)のファイル9の区間情報が(10,3)−(12,7)、同じく新結合テーブルのトークン列$();[L%=N;$(%,%,%,%)のファイル10の区間情報が(11,3)−(13,7)である。このように、結合テーブルのトークン$(%,%,%,%)の区間情報は、新結合テーブルのトークン$();[L%=N;$(%,%,%,%)の区間情報に完全に包含されているため、結合テーブルのトークン$(%,%,%,%)のレコードは削除される。一方、新結合テーブルの区間情報に結合テーブルの区間情報が完全に包含されていない場合、処理はステップS321を実行せずにステップS322に移行する。 As indicated by 1001 in FIG. 10, the section information of the file 9 of the token sequence $ (%,%,%,%) of the join table is (11,5)-(12,7), and the token sequence $ of the join table is also the same. The section information of the file 10 of (%,%,%,%) is (12, 5)-(13, 7). Further, as indicated by 1002 in FIG. 10, the section information of the file 9 in the token string $ (); [L% = N; $ (%,%,%,%) of the new join table is (10, 3) − (12, 7), similarly, the section information of the file 10 in the token sequence $ (); [L% = N; $ (%,%,%,%) of the new join table is (11, 3)-(13, 7 ). In this way, the interval information of token $ (%,%,%,%) in the join table is the interval of token $ (); [L% = N; $ (%,%,%,%) in the new join table Since it is completely included in the information, the record of token $ (%,%,%,%) in the join table is deleted. On the other hand, when the section information of the join table is not completely included in the section information of the new join table, the process proceeds to step S322 without executing step S321.
続いて、包含クローン削除部105は、検出テーブルの全レコードを抽出し、クローンテーブルを生成する(ステップS322)。従って、図10の1001に示すように、クローンテーブルは、トークン列$();[L%=N;のレコード、及び、トークン列$();[L%=$(のレコードで構成されることになる。
Subsequently, the included
続いて、包含クローン削除部105は、新検出テーブルが生成されたか否かを判定する(ステップS323)。図10の例では、新検出テーブルが生成されたため、処理は図3−2のステップS324に移行する。クローン簡易結合部103は、新検出テーブルを検出テーブルに置き換える(ステップS324)。一方、新検出テーブルが生成されなかった場合、処理は終了する。
Subsequently, the included
包含クローン削除部105は、包含クローン削除部105で新検出テーブルから置き替えられた検出テーブルに対してステップS313のクローン簡易結合処理を実行する。即ち、図11の1101に示す新検出テーブルから置き替えられた検出テーブルは、ファイル9、ファイル10について、トークン列$();[L%=$();[L%=N;の区間情報として(9,5)−(11,5)、(10,5)−(12,5)が登録され、トークン列$();[L%=N;$(%,%,%,%)の区間情報として(10,3)−(12,7)、(11,3)−(13,7)が登録されている。従って、比較する区間情報は、全て同じオフセット(縦軸方向の1座標分、横軸方向の2座標分)を有することになり、区間情報の結合が行われる。図11の1102に示すように、区間情報の結合が行われた後の検出テーブルは、トークン列$();[L%=$();[L%=N;$(%,%,%,%)のレコードには、ファイル9について(9、5)−(12,7)の区間情報が登録され、ファイル10について(10,5)−(13,7)の区間情報が登録される。
The inclusion
続いて、クローン結合部104は、図11の1102に示す検出テーブルに対してステップS314のクローン結合処理を実行するが、図11の1102に示す検出テーブルでは、前段のトークン列の区間情報と後段のトークン列の区間情報の始端とが重なっておらず、また、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが接続されていない。従って、今回のクローン結合処理では、区間情報の結合は行われず、新検出テーブルへのレコードの登録は行われない。このように新検出テーブルが生成されなかった場合、処理はステップS316、S318及びS321をスキップし、ステップS322に移行する。
Subsequently, the
ステップS322では、包含クローン削除部105は、検出テーブルの全レコードを抽出し、クローンテーブルに追加する。即ち、図11の1102に示す検出テーブルの全レコードが抽出され、図10の1001に示すクローンテーブルに追加される。その結果、図12に示すクローンテーブルが生成される。図12に示すクローンテーブルには、最終的なクローンコードの検出結果が登録される。即ち、トークン列$();[L%=N;、$();[L%=$(、$();[L%=$();[L%=N;$(%,%,%,%)のクローンコードがファイル9、10の間で存在し、トークン列$();[L%=N;$();[L%=$(のクローンコードがファイル11、12の間で存在する。クローンテーブルに登録される区間情報はクローン簡易結合部103及びクローン結合部104による区間情報の結合処理によって最長一致の区間情報となっている。
In step S322, the included
続いて、包含クローン削除部105は、新検出テーブルが生成されたか否かを判定する(ステップS323)。今回、新検出テーブルは生成されなかったため、処理は終了する。
Subsequently, the included
上述した実施形態においては、クローンコード検出対象のファイルと当該ファイルの比較対象となるファイル(本実施形態では、最後にクローンコード検出が行われた時点のファイル)との間の区間情報をファイル毎に結合し、結合した区間情報をクローンテーブルに登録するように構成している。従って、検出するクローンコードの最長一致を図ることが可能となり、クローンコードの過検出を防ぐことができる。 In the embodiment described above, the section information between the clone code detection target file and the file to be compared with the file (in this embodiment, the file at the time of the last clone code detection) is stored for each file. And the combined section information is registered in the clone table. Therefore, it is possible to achieve the longest match between the clone codes to be detected, and it is possible to prevent over-detection of the clone codes.
なお、図5に示した例では、n=10でn-gram化を行っているが、実際の処理においては計算の効率化の観点からn=56前後でn-gram化を行うことが好ましい。 In the example shown in FIG. 5, n-gram conversion is performed at n = 10. However, in actual processing, it is preferable to perform n-gram conversion at around n = 56 from the viewpoint of calculation efficiency. .
100 クローン検出装置
101 検出テーブル作成部
102 クローン簡易結合部
103 クローン結合部
104 包含クローン削除部
DESCRIPTION OF
Claims (6)
前記第1の検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記第1の検出テーブルにおける該当する区間情報をファイル毎に結合させる第1の結合手段と、
前記第1の検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成手段とを有することを特徴とするクローンコード検出装置。 Section information for each predetermined unit of data in the clone code detection target file is registered in the first detection table, and the section for each predetermined unit of data in the file to be compared with the clone code detection target file First detection table generating means for registering information in the first detection table;
A first combining unit that combines corresponding section information in the first detection table for each file when section information between the predetermined units of data in the first detection table satisfies a predetermined condition;
A clone code detection device, comprising: clone code table generation means for extracting section information in the first detection table and registering it in the clone code table.
前記第1の結合手段は、前記第2の検出テーブルを前記第1の検出テーブルに置き換え、前記第2の検出テーブルから置き換えられることにより生成された前記第1の検出テーブルにおける前記所定の単位のデータ間の区間情報が前記所定の条件を満たす場合、前記第1の検出テーブルにおける該当する区間情報を結合させることを特徴とする請求項2に記載のクローンコード検出装置。 When the section information between the data of the predetermined unit in the first detection table after the combining process by the first combining means overlaps or is connected, the section information obtained by combining the corresponding section information is A second combined table generating means for registering in the two detection tables;
The first combining means replaces the second detection table with the first detection table and replaces the second detection table with the predetermined unit in the first detection table generated by replacing the second detection table with the first detection table. 3. The clone code detection apparatus according to claim 2, wherein, when section information between data satisfies the predetermined condition, corresponding section information in the first detection table is combined.
前記クローンコードテーブル生成手段は、前記削除手段により区間情報が削除された後の前記第1のテーブル内の区間情報を抽出して前記クローンコードテーブルに登録することを特徴とする請求項3に記載のクローンコード検出装置。 When the section information of the first combined table is included in the section information of the second combined table, further includes a deleting unit that deletes the corresponding section information in the first combined table,
The said clone code table production | generation means extracts the section information in the said 1st table after the section information was deleted by the said deletion means, and registers it in the said clone code table, The said code | cord | chord code | symbol table is characterized by the above-mentioned. Clone code detector.
クローンコード検出対象のファイルにおける所定の単位のデータ毎の区間情報を検出テーブルに登録するとともに、クローンコード検出対象のファイルとの比較対象となるファイルにおける前記所定の単位のデータ毎の区間情報を前記検出テーブルに登録する検出テーブル生成ステップと、
前記検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記検出テーブルにおける該当する区間情報をファイル毎に結合させる結合ステップと、
前記検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成ステップとを含むことを特徴とするクローンコード検出方法。 A clone code detection method using a clone code detection apparatus,
The section information for each data of a predetermined unit in the clone code detection target file is registered in the detection table, and the section information for each predetermined unit of data in the file to be compared with the clone code detection target file is A detection table generation step to be registered in the detection table;
When section information between the predetermined units of data in the detection table satisfies a predetermined condition, a combining step of combining corresponding section information in the detection table for each file;
A clone code table generating step of extracting section information in the detection table and registering it in the clone code table.
前記検出テーブルにおける前記所定の単位のデータ間の区間情報が所定の条件を満たす場合、前記検出テーブルにおける該当する区間情報をファイル毎に結合させる結合ステップと、
前記検出テーブル内の区間情報を抽出してクローンコードテーブルに登録するクローンコードテーブル生成ステップとをコンピュータに実行させるためのプログラム。 The section information for each data of a predetermined unit in the clone code detection target file is registered in the detection table, and the section information for each predetermined unit of data in the file to be compared with the clone code detection target file is A detection table generation step to be registered in the detection table;
When section information between the predetermined units of data in the detection table satisfies a predetermined condition, a combining step of combining corresponding section information in the detection table for each file;
A program for causing a computer to execute a clone code table generation step of extracting section information in the detection table and registering it in the clone code table.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008225135A JP5027765B2 (en) | 2008-09-02 | 2008-09-02 | Clone code detection device, clone code detection method and program |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008225135A JP5027765B2 (en) | 2008-09-02 | 2008-09-02 | Clone code detection device, clone code detection method and program |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2010061301A true JP2010061301A (en) | 2010-03-18 |
JP5027765B2 JP5027765B2 (en) | 2012-09-19 |
Family
ID=42188045
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2008225135A Active JP5027765B2 (en) | 2008-09-02 | 2008-09-02 | Clone code detection device, clone code detection method and program |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP5027765B2 (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2011048639A (en) * | 2009-08-27 | 2011-03-10 | Ns Solutions Corp | Apparatus and method for detecting and evaluating clone code, and program |
CN102681835A (en) * | 2010-12-20 | 2012-09-19 | 微软公司 | Code clone notification and architectural change visualization |
WO2014136611A1 (en) * | 2013-03-08 | 2014-09-12 | Necソリューションイノベータ株式会社 | Cost computation device, cost computation method, and computer-readable recording medium |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2003029978A (en) * | 2001-07-13 | 2003-01-31 | Japan Science & Technology Corp | Isomorphic pattern detection system |
-
2008
- 2008-09-02 JP JP2008225135A patent/JP5027765B2/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2003029978A (en) * | 2001-07-13 | 2003-01-31 | Japan Science & Technology Corp | Isomorphic pattern detection system |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2011048639A (en) * | 2009-08-27 | 2011-03-10 | Ns Solutions Corp | Apparatus and method for detecting and evaluating clone code, and program |
CN102681835A (en) * | 2010-12-20 | 2012-09-19 | 微软公司 | Code clone notification and architectural change visualization |
WO2014136611A1 (en) * | 2013-03-08 | 2014-09-12 | Necソリューションイノベータ株式会社 | Cost computation device, cost computation method, and computer-readable recording medium |
US20160019609A1 (en) * | 2013-03-08 | 2016-01-21 | Nec Solution Innovators, Ltd. | Cost computation device, cost computation method, and computer-readable recording medium |
Also Published As
Publication number | Publication date |
---|---|
JP5027765B2 (en) | 2012-09-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP5350428B2 (en) | Automatic program generation apparatus, method and computer program | |
JP5779077B2 (en) | Apparatus and method for supporting program generation | |
CN1755647A (en) | Test automation stack layering | |
WO2016084336A1 (en) | Iterative training device, iterative training method, and storage medium | |
CN1118473A (en) | Tool and method for diagnosing and correcting errors in a computer program | |
CN106469116B (en) | Test scene generates auxiliary device and test scene generates householder method | |
JP5345020B2 (en) | Clone code detection evaluation apparatus, clone code detection evaluation method and program | |
JP5027765B2 (en) | Clone code detection device, clone code detection method and program | |
JP2007025497A (en) | Educational assistance program and educational assistant device | |
JP2009230618A (en) | Specification creating program, device therefor, and method thereof | |
JP2011096082A (en) | Program analyzing method, program analyzing program and program analyzer | |
WO2004051470A1 (en) | Program automatic converting method and program automatic converting device | |
US20080103752A1 (en) | Apparatus, method, and program for conversion of application program | |
CN104636050A (en) | Method and system for nested drag and drop enablement | |
JP4767309B2 (en) | Information processing apparatus, information processing method, and computer program | |
JP2018124901A (en) | Program analyzing apparatus, program analyzing method, and program analyzing program | |
CN101051268A (en) | System and method for determining whether screen displayed by program satisfies specification | |
JP2013105286A (en) | Automatic program generation device and automatic program generation method | |
JP2009163566A (en) | Job analysis support apparatus | |
US20140089741A1 (en) | Data transition tracing apparatus, data transition tracing method and storage medium storing data transition tracing program | |
JP2008009859A (en) | Retrieval index creating device and retrieval index creating method | |
Bau | Integrating Droplet into Applab—Improving the usability of a blocks-based text editor | |
JPWO2005086033A1 (en) | Verification support device, verification support method, verification support program, and recording medium | |
WO2015030016A1 (en) | System for processing unstructured data, method for processing unstructured data, and recording medium | |
JP2007164708A (en) | Conversion data generator, data conversion system, method therefor, and program therefor |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20111121 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20111220 |
|
A521 | Request for written amendment filed |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20120217 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20120612 |
|
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20120622 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20150629 Year of fee payment: 3 |
|
R150 | Certificate of patent or registration of utility model |
Free format text: JAPANESE INTERMEDIATE CODE: R150 Ref document number: 5027765 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |