JP2010061301A - Clone code detection device, clone code detection method, and program - Google Patents

Clone code detection device, clone code detection method, and program Download PDF

Info

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
Application number
JP2008225135A
Other languages
Japanese (ja)
Other versions
JP5027765B2 (en
Inventor
Daisuke Nishikawa
大亮 西川
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.)
NS Solutions Corp
Original Assignee
NS Solutions Corp
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 NS Solutions Corp filed Critical NS Solutions Corp
Priority to JP2008225135A priority Critical patent/JP5027765B2/en
Publication of JP2010061301A publication Critical patent/JP2010061301A/en
Application granted granted Critical
Publication of JP5027765B2 publication Critical patent/JP5027765B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To prevent the excessive detection of a clone code by matching the longest length of a clone code to be detected. <P>SOLUTION: A detection table creation part 102 registers the section information of each prescribed unit data in a clone detection target file in a first detection table, and registers the section information of each prescribed unit data in a comparison target file with the clone code detection target file in a detection table. When the section information between prescribed unit data in the detection table satisfies prescribed conditions, a clone simple connection part 103 combines the pieces of pertinent section information in the detection table for every file. <P>COPYRIGHT: (C)2010,JPO&INPIT

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.

特開2003−29978号公報Japanese Patent Laid-Open No. 2003-29978

しかしながら、従来からクローンコードを検出する方法が存在するが、その検出処理の計算量が多く、クローンコードの検出に多くの時間がかかってしまい、実用的と言えるものではなかった。効率的にクローンコードを検出する技術が例えば特許文献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, Patent Document 1 discloses a technique for efficiently detecting a clone code.

特許文献1には、テキストから同形パターンを検出する同形パターン検出システムが開示されている。特許文献1に開示される同形パターン検出システムでは、字句解析、規則による変形、パラメータ変換、同形検出、同形出力により対象のテキストの同形を検出する。しかしながら、特許文献1に開示される同形パターン検出システムは、計算量がO(N)〜O(NlogN)と高速であるが、抽出されたクローンコードが最長一致ではないので過検出が多くなるという問題があった。   Patent Document 1 discloses an isomorphic pattern detection system that detects isomorphic patterns from text. In the isomorphic pattern detection system disclosed in Patent Document 1, the isomorphism of the target text is detected by lexical analysis, rule transformation, parameter conversion, isomorphism detection, and isomorphism output. However, although the isomorphic pattern detection system disclosed in Patent Document 1 has a high calculation amount of O (N) to O (NlogN), the extracted clone code is not the longest match, so that overdetection increases. There was a problem.

そこで、本発明の目的は、検出するクローンコードの最長一致を図り、クローンコードの過検出を防ぐことにある。   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 code detection apparatus 100 according to the present embodiment includes a base table creation unit 101, a detection table creation unit 102, a simple clone join unit 103, a clone join unit 104, and an included clone deletion unit 105. The

基底テーブル作成部101は、最後にクローンコードの検出を行った時点における最新ファイルのソースコードをトークン列に変換し、n-gram化されたトークン列とそれらのトークン列の区間情報を基底テーブルに登録する。   The base table creation unit 101 converts the source code of the latest file at the time of the last clone code detection into a token string, and converts the token strings converted into n-grams and the interval information of those token strings into the base table. sign up.

検出テーブル作成部102は、クローンコードの検出対象となるファイルのソースコードをトークン列に変換し、n-gram化されたトークン列とそれらのトークン列の区間情報とを検出テーブルに登録する。そして、検出テーブル作成部102は、基底テーブルに登録される区間情報を後述する方法によって検出テーブルに登録する。   The detection table creation unit 102 converts the source code of the file that is the detection target of the clone code into a token string, and registers the token strings converted into n-grams and the section information of those token strings in the detection table. Then, the detection table creation unit 102 registers the section information registered in the base table in the detection table by a method described later.

クローン簡易結合部103は、検出テーブルのレコード同士の対応する区間情報を比較し、比較した区間情報が各ファイル間で同じオフセットを有するのであれば、区間情報の結合を行う。   The clone simple combining unit 103 compares the corresponding section information between the records in the detection table, and combines the section information if the compared section information has the same offset between the files.

クローン結合部104は、クローン簡易結合部103により生成された検出テーブルから、ファイル毎に区間情報を取得する。そして、クローン結合部104は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが重なる、又は、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが接続される場合、それらの区間情報を結合した区間情報を新検出テーブルに登録する。   The clone combining unit 104 acquires section information for each file from the detection table generated by the clone simple combining unit 103. Then, the clone combining unit 104 overlaps the end of the section information of the preceding token string and the start of the section information of the subsequent token string, or the end information of the section information of the preceding token string and the section information of the subsequent token string Is connected to the new detection table, the section information obtained by combining the section information is registered in the new detection table.

包含クローン削除部105は、検出テーブルと新検出テーブルとを比較し、検出テーブルの区間情報が新検出テーブルの区間情報に完全に包含されている場合、即ち、検出テーブル内に過検出となっている区間情報が存在する場合、検出テーブルにおける過検出の区間情報が登録されているレコードを削除する。   The inclusion clone deletion unit 105 compares the detection table with the new detection table, and when the section information of the detection table is completely included in the section information of the new detection table, that is, the detection table is overdetected. If there is existing section information, the record in which the over-detected section information is registered in the detection table is deleted.

図2は、本実施形態に係るクローンコード検出装置100のハードウェア構成を示す図である。   FIG. 2 is a diagram illustrating a hardware configuration of the clone code detection apparatus 100 according to the present embodiment.

CPU201は、システムバスに接続される各デバイスやコントローラを統括的に制御する。ROM203又はHD(ハードディスク)207には、CPU201の制御プログラムであるBIOS(Basic Input / Output System)やオペレーティングシステムプログラム、クローンコード検出装置100が実行する例えば図3−1乃至図3−3に示す処理のプログラム等が記憶されている。   The CPU 201 comprehensively controls each device and controller connected to the system bus. The ROM 203 or the HD (hard disk) 207 stores a basic input / output system (BIOS) that is a control program for the CPU 201, an operating system program, and the processes shown in FIGS. Programs are stored.

なお、図2の例では、HD207はクローンコード検出装置100の内部に配置された構成としているが、他の実施形態としてHD207に相当する構成がクローンコード検出装置100の外部に配置された構成としてもよい。また、本実施形態に係る例えば図3−1乃至図3−3に示す処理を行うためのプログラムは、フレキシブルディスク(FD)やCD−ROM等、コンピュータ読み取り可能な記録媒体に記録され、それらの記録媒体から供給される構成としてもよいし、インターネット等の通信媒体を介して供給される構成としてもよい。   In the example of FIG. 2, the HD 207 is configured to be arranged inside the clone code detection device 100. However, as another embodiment, a configuration corresponding to the HD 207 is arranged outside the clone code detection device 100. Also good. In addition, for example, the program for performing the processing illustrated in FIGS. 3-1 to 3-3 according to the present embodiment is recorded on a computer-readable recording medium such as a flexible disk (FD) or a CD-ROM. It is good also as a structure supplied from a recording medium, and good also as a structure supplied via communication media, such as the internet.

RAM202は、CPU201の主メモリ、ワークエリア等として機能する。CPU201は、処理の実行に際して必要なプログラム等をRAM202にロードして、プログラムを実行することで各種動作を実現するものである。   The RAM 202 functions as a main memory, work area, and the like for the CPU 201. The CPU 201 implements various operations by loading a program necessary for execution of processing into the RAM 202 and executing the program.

HD207やFD206は、外部メモリとして機能する。CPU201は、処理の実行に際して必要なプログラム等をRAM202にロードして、プログラムを実行することで各種動作を実現するものである。   The HD 207 and the FD 206 function as an external memory. The CPU 201 implements various operations by loading a program necessary for execution of processing into the RAM 202 and executing the program.

ディスクコントローラ205は、HD207やFD206等の外部メモリへのアクセスを制御する。通信I/Fコントローラ204は、インターネットやLANと接続し、例えばTCP/IPによって外部との通信を制御するものである。   The disk controller 205 controls access to external memories such as the HD 207 and the FD 206. The communication I / F controller 204 is connected to the Internet or a LAN, and controls communication with the outside by, for example, TCP / IP.

ディスプレイコントローラ208は、ディスプレイ209における画像表示を制御する。   The display controller 208 controls image display on the display 209.

KBコントローラ210は、KB(キーボード)211からの操作入力を受け付け、CPU201に対して送信する。なお、図示していないが、KB211の他に、マウス等のポインティングデバイスもユーザの操作手段として本実施形態に係るクローンコード検出装置100に適用可能である。   The KB controller 210 receives an operation input from the KB (keyboard) 211 and transmits it to the CPU 201. Although not shown, in addition to the KB 211, a pointing device such as a mouse can also be applied to the clone code detection apparatus 100 according to the present embodiment as a user operation means.

図1に示す基底テーブル作成部101、検出テーブル作成部102、クローン簡易結合部103、クローン結合部104及び包含クローン削除部105は、例えばHD207内に記憶され、必要に応じてRAM202にロードされるプログラム及びそれを実行するCPU201によって実現される構成である。   The base table creation unit 101, the detection table creation unit 102, the clone simple combination unit 103, the clone combination unit 104, and the included clone deletion unit 105 shown in FIG. 1 are stored in, for example, the HD 207 and loaded into the RAM 202 as necessary. The configuration is realized by a program and a CPU 201 that executes the program.

図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 code detection apparatus 100 according to the present embodiment. The operation flow of the clone code detection apparatus 100 will be described below with reference to the flowcharts shown in FIGS. 3-1 to 3-3. Before the description, the storage status of files in the repository will be described with reference to FIG. An example will be described. The repository stores files that are targets for detection of clone codes by the clone code detection apparatus 100. The repository may be configured in a partial recording area of a recording medium such as an HDD in the clone code detection apparatus 100, or may be configured in a DB server connected to the clone code detection apparatus 100 via a communication line. Good. Note that the file storage configuration in the repository illustrated in FIG. 4 is merely an example, and the clone code detection apparatus 100 is not limited to the file illustrated in FIG. Therefore, in the following description, the operation of the clone code detection apparatus 100 will be described using the files other than those shown in FIG.
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 versions 1 to 3 are registered. The file 3 (F3) is registered in the repository with version 1, and then updated and registered with version 2, version 3, and version 4. That is, for the file 3, the files of versions 1 to 4 are registered. A broken line 401 represents the time when the clone code detection process was last performed, and a broken line 402 represents the current time. In other words, FIG. 4 shows that the latest file registered in the repository when clone code is detected last is version 1 for file 1, version 2 for file 2, and version 2 for file 3. Yes. FIG. 4 also shows that file 2 has been updated once from version 2 to version 3 and file 3 has been updated twice from version 2 to version 4 since the last clone code was detected. ing.

次に、クローンコード検出装置100の動作について説明する。図3−1において、基底テーブル作成部101は、最後にクローンコードの検出を行った時点における最新ファイルをリポジトリから読み出す(ステップS301)。即ち、基底テーブル作成部101は、ファイル1のバージョン1、ファイル2のバージョン2、ファイル3のバージョン2を読み出す。   Next, the operation of the clone code detection apparatus 100 will be described. 3A, the base table creation unit 101 reads the latest file from the repository at the time when the clone code was last detected (step S301). That is, the base table creation unit 101 reads version 1 of file 1, version 2 of file 2, and version 2 of file 3.

続いて、基底テーブル作成部101は、リポジトリから取り出した各ファイル内に記述されるソースコードを構文解析し、voidであればVといったように、ソースコードをトークン列に変換する(ステップS302)。ここでの変換ルールはad hocを用いる。   Subsequently, the base table creation unit 101 parses the source code described in each file fetched from the repository, and converts the source code into a token string such as V if void (step S302). The conversion rule here uses ad hoc.

図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 table creation unit 101 converts the token string into an n-gram (n = 1, 2, 3,..., N = 10 in FIG. 5), and converts the token string into the n-gram and the file And the token sequence section information in step S303. As indicated by reference numeral 503 in FIG. 5, in the base table, the token string v $ (I%) [L% = is changed from the second column (2, 1) of the second row of the file 1 to the fourth column of the third row ( 3, 4) ((2,1)-(3,4)), token sequence v $ (I%) [L% = is the first column of the 10th row of the file 2 to the ninth column of the 10th row. ((10,1)-(10,9)), token sequence v $ (I%) [L% = is from the first column of the first row to the ninth column of the first row ((1 , 1)-(1, 9)) is registered as section information.

また、トークン列$(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 file 3 to the eleventh column of the first row ((1,3)-(1,11)). Is registered as section information. Further, the token string = $ (%,%,%); exists from the first column of the 12th row to the 12th column of the 12th row ((12,1)-(12,12)). Is registered as section information.

図6は、検出テーブル作成部102による検出テーブルの作成処理を説明するための図である。図6においては、ファイル3のバージョン3をクローンコードの検出対象とした場合に作成される検出テーブルの構成例を示している。   FIG. 6 is a diagram for explaining detection table creation processing by the detection table creation unit 102. FIG. 6 shows a configuration example of a detection table created when version 3 of the file 3 is a clone code detection target.

続いて、検出テーブル作成部102は、基底テーブルに検出対象のファイル3の旧バージョンが存在するか否かを判定する(ステップS304)。ファイル3の旧バージョンが存在する場合、検出テーブル作成部102は、図6の601に示すように、基底テーブルから検出対象のファイル3の旧バージョンの区間情報を削除する(ステップS305)。これは、バージョン違いの同一種類のファイルである場合、新バージョンのファイルは旧バージョンのファイルが部分的に更新されて共通部分が多いため、その共通部分をクローンコードとして検出するのは適切ではないからである。一方、ファイル3の旧バージョンが存在しない場合、処理はステップS305を実行せずにステップS306に移行する。   Subsequently, the detection table creation unit 102 determines whether or not an old version of the file 3 to be detected exists in the base table (step S304). When the old version of the file 3 exists, the detection table creation unit 102 deletes the section information of the old version of the detection target file 3 from the base table as indicated by 601 in FIG. 6 (step S305). If this is a file of the same type with a different version, it is not appropriate to detect the common part as a clone code because the new version file is partially updated from the old version file and there are many common parts. Because. On the other hand, if the old version of the file 3 does not exist, the process proceeds to step S306 without executing step S305.

続いて、検出テーブル作成部102は、ファイル3のバージョン3をリポジトリから読み出す(ステップS306)。そして、検出テーブル作成部102は、ファイル3のバージョン3内に記述されるソースコードを構文解析し、トークン列に変換する(ステップS307)。   Subsequently, the detection table creation unit 102 reads version 3 of the file 3 from the repository (step S306). Then, the detection table creation unit 102 parses the source code described in the version 3 of the file 3 and converts it into a token string (step S307).

続いて、検出テーブル作成部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 table creation unit 102 converts the token string into an n-gram, and registers the token string converted into an n-gram and section information in the file of the corresponding token string in the detection table (step S308). As indicated by 602 in FIG. 6, the clone column v $ (I%) [L% = is from the fifth column of the second row of the version v3 of the file F3 to the thirteenth row of the second row ((2, 5) -(2,13)), clone string $ (I%) [L% = & is the second line of file F3 version v3 from the 6th line to the 14th line ((2,6)- (2,14)), the clone column (I%) [L% = &; is from the seventh row of the second row to the fifteenth column of the second row of version v3 of the file F3 ((2,7)-( 2, 15)) Existence is registered as section information.

続いて、検出テーブル作成部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 table creation unit 102 displays the section information of the corresponding token string in the base table. Register in the detection table (step S309).

図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 reference numeral 603 in FIG. 6, in the detection table, three token sequences v $ (I%) [L% =, $ (I%) [L% = &, (I%) [L% = &; Section information is registered, but in the base table, section information of two token sequences v $ (I%) [L% =, $ (I%) [L% = & is registered. ing. Therefore, the detection table creation unit 102 registers the section information of the two token strings v $ (I%) [L% =, $ (I%) [L% = &] in the base table in the detection table.

続いて、図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 table creation unit 102 determines whether or not there is a token string record in which only one section information is registered between files (step S310). When only one section information is registered between files, the detection table creation unit 102 deletes the corresponding record (step S311). This is because it is clear that a token string in which only one piece of section information is registered between files is not a clone code at that time. In the example of FIG. 6, only the section information of the file 3 is registered in the record of the token string (I%) [L% = &;. Therefore, the record of the token string (I%) [L% = &; is deleted. As described above, the detection table indicated by reference numeral 603 in FIG. 6 is created. On the other hand, if there is no token sequence record in which only one section information is registered between files, the process proceeds to step S312 without executing step S311.

続いて、クローン簡易結合部103は、検出テーブルの各レコードを区間情報の数毎に分類する(ステップS312)。図7の例においては、4つの区間情報を登録しているトークン列V$(I%)[L%=のレコードとトークン列(I%)[L%=&;のレコードとの分類と、3つの区間情報を登録しているトークン列$(I%)[L%=&のレコードとトークン列I%)[L%=&;%のレコードとの分類になる。   Subsequently, the clone simple combining unit 103 classifies each record of the detection table according to the number of section information (step S312). In the example of FIG. 7, the classification of the record of token sequence V $ (I%) [L% = and the record of token sequence (I%) [L% = &; The token sequence $ (I%) [L% = & record and the token sequence I%) [L% = &;% record in which three pieces of section information are registered are classified.

続いて、クローン簡易結合部103は、クローン簡易結合処理を行う(ステップS313)。即ち、クローン簡易結合部103は、分類毎に、レコード同士の対応する区間情報を比較し、比較した区間情報が各ファイル間で同じオフセットを有するのであれば、区間情報の結合を行う。   Subsequently, the clone simple combining unit 103 performs a clone simple combining process (step S313). That is, the simple clone combining unit 103 compares corresponding section information between records for each classification, and combines the section information if the compared section information has the same offset between files.

図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 simple combining unit 103. Here, as shown by reference numeral 701 in FIG. 7, an example is shown in which section information is registered for four token strings in the detection table. That is, in the detection table, the section information of the token string V $ (I%) [L% = is registered in the four files 4 to 7, and the token string (I%) [L% = & is stored in the four files 4 to 7. ; Section information is registered. In addition, the section information of token sequence $ (I%) [L% = & is registered in the three files 4 to 6, and the token sequence I%) [L% = &;% section information is stored in the three files 4 to 6. Is registered.

図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 table creation unit 102 generates section information in which the beginning token end of the preceding token string to the end of the latter token string of the compared token strings are combined. At this time, the clone simple combining unit 103 updates the token string of one record among the records divided for each classification to the combined token string, and converts each section information of the record to the combined section information. Update. Then, the clone simple combination unit 103 deletes all other records belonging to the classification. As described above, after the clone simple combining process, a detection table indicated by 702 in FIG. 7 is generated.

ファイル毎に各区間情報を結合させた場合、結合後の区間情報に該当するトークン列は複数のファイル間に亘って同一のトークン列であると看做せる。従って、上述したクローン簡易結合処理は、レコード間において、複数のファイルに亘って或るトークン列の区間情報が同じ数だけ登録され、且つ同一分類のレコード間において、夫々のトークン列の区間情報が複数のファイルに亘って同じオフセットで登録されている場合に行われる。   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 clone combining unit 104 performs a clone combining process (step S314). That is, the clone combining unit 104 acquires section information for each file from the detection table generated by the clone simple combining unit 103. Then, the clone combining unit 104 overlaps the end of the section information of the preceding token string and the start of the section information of the subsequent token string, or the end information of the section information of the preceding token string and the section information of the subsequent token string Is connected to the new detection table, the section information obtained by combining the section information is registered in the new detection table. As a result, a new detection table is created in which section information corresponding to a series of token strings obtained by combining token strings converted into n-grams is created.

図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 clone joining unit 104. Reference numeral 801 in FIG. 8 is a detection table, and reference numeral 802 in FIG. 8 is a new detection table generated by performing clone combination processing on the detection table. In the detection table, the section information of the file 9 of the token sequence $ (); (L% = N; is (10, 3)-(11, 5), and the token sequence $ (); [L% = $ ( The section information of the file 9 is (9,5)-(10,7) Therefore, the end of the section information ((9,5)-(10,7)) of the preceding token string and the token information of the latter stage Section information ((10,3)-(11,5)) overlaps with the beginning of the section information, and section information (9,5)-(11,5) obtained by combining these section information is calculated.

また、トークン列$(%,%,%,%)のファイル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 clone combining unit 104 determines whether there is section information combined by the clone combining process (step S315). If there is section information combined by the clone combining process, the clone combining unit 104 registers the combined section information in association with the combined token string in the new detection table (step S316). On the other hand, when there is no section information joined by the clone joining process, the process proceeds to step S317 in FIG. 3-3 without executing step S316.

続いて、クローン結合部104は、新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在するか否かを判定する(ステップS317)。新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在する場合、クローン結合部104は、該当するレコードを削除する(ステップS318)。これは、ファイル間で1つの区間情報しか登録されていないトークン列はクローンではないためである。図8の例では、トークン列$();[L%=$();[L%=$(のレコードが削除されることになる。一方、新検出テーブルにおいてファイル間で1つの区間情報の登録しかないレコードが存在しない場合、処理はステップS318を実行せずにステップS319に移行する。上述したステップS314〜S318の処理によって、図8の801に示す検出テーブルから図8の802に示す新検出テーブルが生成される。   Subsequently, the clone combining unit 104 determines whether there is a record that has only one piece of section information registered between files in the new detection table (step S317). If there is a record that has only one section information registered between files in the new detection table, the clone combining unit 104 deletes the corresponding record (step S318). This is because a token string in which only one section information is registered between files is not a clone. In the example of FIG. 8, the record of token string $ (); [L% = $ (); [L% = $ (will be deleted. If there is no record that can only be registered, the process proceeds to step S319 without executing step S318, and the process in steps S314 to S318 described above is performed to detect the new table 802 in FIG. A detection table is generated.

図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 clone deletion unit 105. FIG. The included clone deletion unit 105 separates the files registered in the detection table into groups, and separates the files registered in the new detection table into groups (step S319). In this grouping, files in which section information is registered with the same token string are grouped into the same group. Grouping in this way can reduce the amount of processing by performing overdetection processing for each group having a higher possibility of clones than performing clone overdetection processing described later for each file. Because. 901 in FIG. 9 indicates the status of grouping in the detection table, and 902 in FIG. 9 indicates the status of grouping in the new detection table. Both the detection table and the new detection table are divided into group A of file 9 and file 10 and group B of file 11 and file 12.

続いて、包含クローン削除部105は、検出テーブルと新検出テーブルとの間でグループ毎に区間情報を比較し、結合テーブルの区間情報が新結合テーブルの区間情報に完全に包含されているか否かを判定する(ステップS320)。即ち、ステップS320では、検出テーブル内に過検出となっている区間情報が存在するか否かを判定している。例えば、新検出テーブル内にトークン列ABABAが登録され、検出テーブル内にトークン列BABがトークン列ABABAの区間情報に包含される区間情報で登録されているような場合、最長のトークン列ABABAだけを検出すればよく、そのトークン列に含まれるトークン列BABは検出する必要はない。このような場合、トークン列BABを検出することは過検出であり、ステップS320ではこの過検出の判定を行っている。   Subsequently, the inclusion clone deletion unit 105 compares the section information for each group between the detection table and the new detection table, and whether or not the section information of the combined table is completely included in the section information of the new combined table. Is determined (step S320). That is, in step S320, it is determined whether or not there is section information that is over-detected in the detection table. For example, when the token string ABABA is registered in the new detection table and the token string BAB is registered in the detection table with section information included in the section information of the token string ABABA, only the longest token string ABABA is stored. The token string BAB included in the token string need not be detected. In such a case, detecting the token string BAB is overdetection, and in step S320, this overdetection is determined.

結合テーブルの区間情報が新結合テーブルの区間情報に完全に包含されている場合、包含クローン削除部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 clone deletion unit 105 deletes the corresponding record from the combined table (step S321). That is, the included clone deletion unit 105 deletes a record in which overdetected section information is registered in the combined table.

図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 clone deletion unit 105 extracts all the records in the detection table and generates a clone table (step S322). Therefore, as indicated by 1001 in FIG. 10, the clone table is composed of records of token sequence $ (); [L% = N; and records of token sequence $ (); [L% = $ ( It will be.

続いて、包含クローン削除部105は、新検出テーブルが生成されたか否かを判定する(ステップS323)。図10の例では、新検出テーブルが生成されたため、処理は図3−2のステップS324に移行する。クローン簡易結合部103は、新検出テーブルを検出テーブルに置き換える(ステップS324)。一方、新検出テーブルが生成されなかった場合、処理は終了する。   Subsequently, the included clone deletion unit 105 determines whether or not a new detection table has been generated (step S323). In the example of FIG. 10, since a new detection table is generated, the process proceeds to step S324 in FIG. The clone simple combining unit 103 replaces the new detection table with the detection table (step S324). On the other hand, if a new detection table has not been generated, the process ends.

包含クローン削除部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 clone deletion unit 105 executes the clone simple combination process of step S313 on the detection table replaced from the new detection table by the inclusion clone deletion unit 105. That is, the detection table replaced from the new detection table 1101 in FIG. 11 is the section information of token strings $ (); [L% = $ (); [L% = N; (9,5)-(11,5), (10,5)-(12,5) are registered as token strings $ (); [L% = N; $ (%,%,%,%) (10,3)-(12,7), (11,3)-(13,7) are registered as the section information. Therefore, all the section information to be compared has the same offset (one coordinate in the vertical axis direction and two coordinates in the horizontal axis direction), and the section information is combined. As shown in 1102 of FIG. 11, the detection table after the combination of the section information is the token string $ (); [L% = $ (); [L% = N; $ (%,%,% ,%) Records the section information (9, 5)-(12, 7) for the file 9 and the section information (10, 5)-(13, 7) for the file 10. .

続いて、クローン結合部104は、図11の1102に示す検出テーブルに対してステップS314のクローン結合処理を実行するが、図11の1102に示す検出テーブルでは、前段のトークン列の区間情報と後段のトークン列の区間情報の始端とが重なっておらず、また、前段のトークン列の区間情報の終端と後段のトークン列の区間情報の始端とが接続されていない。従って、今回のクローン結合処理では、区間情報の結合は行われず、新検出テーブルへのレコードの登録は行われない。このように新検出テーブルが生成されなかった場合、処理はステップS316、S318及びS321をスキップし、ステップS322に移行する。   Subsequently, the clone combining unit 104 executes the clone combining process in step S314 on the detection table illustrated in FIG. 11 in 1102. In the detection table illustrated in FIG. The beginning of the section information of the token sequence of the previous token string does not overlap, and the end of the section information of the preceding token string is not connected to the beginning of the section information of the subsequent token string. Therefore, in this clone combining process, the section information is not combined and the record is not registered in the new detection table. When the new detection table is not generated in this way, the process skips steps S316, S318, and S321, and proceeds to step S322.

ステップ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 clone deletion unit 105 extracts all the records in the detection table and adds them to the clone table. That is, all the records in the detection table indicated by 1102 in FIG. 11 are extracted and added to the clone table indicated by 1001 in FIG. As a result, the clone table shown in FIG. 12 is generated. In the clone table shown in FIG. 12, the final clone code detection result is registered. That is, token sequence $ (); [L% = N ;, $ (); [L% = $ (, $ (); [L% = $ (); [L% = N; $ (%,%, %,%) Clone code exists between files 9 and 10, and token string $ (); [L% = N; $ (); [L% = $ (clone code between files 11 and 12 The section information registered in the clone table is the longest matching section information by the section information combining process by the clone simple combining unit 103 and the clone combining unit 104.

続いて、包含クローン削除部105は、新検出テーブルが生成されたか否かを判定する(ステップS323)。今回、新検出テーブルは生成されなかったため、処理は終了する。   Subsequently, the included clone deletion unit 105 determines whether or not a new detection table has been generated (step S323). Since the new detection table has not been generated this time, the process ends.

上述した実施形態においては、クローンコード検出対象のファイルと当該ファイルの比較対象となるファイル(本実施形態では、最後にクローンコード検出が行われた時点のファイル)との間の区間情報をファイル毎に結合し、結合した区間情報をクローンテーブルに登録するように構成している。従って、検出するクローンコードの最長一致を図ることが可能となり、クローンコードの過検出を防ぐことができる。   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. .

本発明の実施形態に係るクローンコード検出装置の機能的な構成を示すブロック図である。It is a block diagram which shows the functional structure of the clone code detection apparatus which concerns on embodiment of this invention. 本発明の実施形態に係るクローンコード検出装置のハードウェア構成を示す図である。It is a figure which shows the hardware constitutions of the clone code detection apparatus which concerns on embodiment of this invention. 本発明の実施形態に係るクローンコード検出装置の動作の流れを示すフローチャートである。It is a flowchart which shows the flow of operation | movement of the clone code detection apparatus which concerns on embodiment of this invention. 本発明の実施形態に係るクローンコード検出装置の動作の流れを示すフローチャートである。It is a flowchart which shows the flow of operation | movement of the clone code detection apparatus which concerns on embodiment of this invention. 本発明の実施形態に係るクローンコード検出装置の動作の流れを示すフローチャートである。It is a flowchart which shows the flow of operation | movement of the clone code detection apparatus which concerns on embodiment of this invention. リポジトリにおける各ファイルの各バージョンの格納状況とともにバージョンの更新状況を示す図である。It is a figure which shows the update condition of a version with the storage condition of each version of each file in a repository. ソースコードからトークン列への変換例と基底テーブルの構成例とを示す図である。It is a figure which shows the example of a conversion from a source code to a token sequence, and the structural example of a base table. 検出テーブル作成部による検出テーブルの作成処理を説明するための図である。It is a figure for demonstrating the creation process of the detection table by a detection table preparation part. クローン簡易結合処理を説明するための図である。It is a figure for demonstrating a clone simple joining process. クローン結合処理を説明するための図である。It is a figure for demonstrating a clone joint process. 包含クローン削除部の動作を説明するための図である。It is a figure for demonstrating operation | movement of an inclusion clone deletion part. 包含クローン削除部の動作を説明するための図である。It is a figure for demonstrating operation | movement of an inclusion clone deletion part. クローン簡易結合処理を説明するための図である。It is a figure for demonstrating a clone simple joining process. クローンテーブルの構成例を示す図である。It is a figure which shows the structural example of a clone table.

符号の説明Explanation of symbols

100 クローン検出装置
101 検出テーブル作成部
102 クローン簡易結合部
103 クローン結合部
104 包含クローン削除部
DESCRIPTION OF SYMBOLS 100 Clone detection apparatus 101 Detection table preparation part 102 Clone simple coupling | bond part 103 Clone coupling | bond part 104 Inclusion clone deletion part

Claims (6)

クローンコード検出対象のファイルにおける所定の単位のデータ毎の区間情報を第1の検出テーブルに登録するとともに、クローンコード検出対象のファイルとの比較対象となるファイルにおける前記所定の単位のデータ毎の区間情報を前記第1の検出テーブルに登録する第1の検出テーブル生成手段と、
前記第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の結合手段は、前記第1の検出テーブルに登録されるファイル間に亘って、前記所定の単位のデータ間の区間情報が同じオフセットを有する場合、前記第1の検出テーブルにおける前記所定の単位のデータ間の区間情報を結合させることを特徴とする請求項1に記載のクローンコード検出装置。   When the section information between the data of the predetermined unit has the same offset across files registered in the first detection table, the first combining unit is configured to perform the predetermined in the first detection table. The clone code detection apparatus according to claim 1, wherein section information between data of the unit is combined. 前記第1の結合手段による結合処理後の前記第1の検出テーブル内における前記所定の単位のデータ間の区間情報が重なる、又は接続される場合、該当する区間情報を結合させた区間情報を第2の検出テーブルに登録する第2の結合テーブル生成手段を更に有し、
前記第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の結合テーブルの区間情報が前記第2の結合テーブルの区間情報に包含される場合、前記第1の結合テーブルにおける該当する区間情報を削除する削除手段を更に有し、
前記クローンコードテーブル生成手段は、前記削除手段により区間情報が削除された後の前記第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.
JP2008225135A 2008-09-02 2008-09-02 Clone code detection device, clone code detection method and program Active JP5027765B2 (en)

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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003029978A (en) * 2001-07-13 2003-01-31 Japan Science & Technology Corp Isomorphic pattern detection system

Patent Citations (1)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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
CN1118473A (en) Tool and method for diagnosing and correcting errors in a computer program
WO2016084336A1 (en) Iterative training device, iterative training method, and storage medium
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
JP2011145996A (en) Reviewer evaluation apparatus, reviewer evaluation method and program
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
US8140305B2 (en) Conversion of an application program
JP5702265B2 (en) Program automatic generation apparatus and program automatic generation method
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
JP4116660B2 (en) Verification support device, verification support method, verification support program, and recording medium
JP2010128908A (en) Information processing apparatus, control method for the same, and program
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
JP5600826B1 (en) Unstructured data processing system, unstructured data processing method and program
JP4963633B2 (en) Information processing apparatus and information processing method
JP2007164708A (en) Conversion data generator, data conversion system, method therefor, and program therefor
JP5585145B2 (en) Correction location discrimination device, correction location discrimination program, and correction location discrimination method

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