## 6 Extraction of System Information and Division of Subsystems and Second-Level Subsystems
### Division of Second-Level Subsystems  
There may be multiple classes associated with the same pattern role in a subsystem or a subsystem containing multiple instances of the same pattern. Therefore, after the subsystems are divided, the colored UML images of the subsystems cannot be directly input into the classification model for prediction. In addition, there may be some classes in subsystems belonging to pattern instances that are not associated with any pattern role. When a subsystem is fed directly into a classification model for prediction, most of the time, the subsystem is identified as a non-pattern instance. Therefore, on the basis of the divided subsystems, this paper further divides each subsystem into several second-level subsystems with clearer targets and more precise scope. In this paper, by combining the classes in the subsystem, the subsystem is further divided into several second-level subsystems with the number of classes ranging from the minimum number of classes required by the pattern to be recognized to the number of classes contained in the subsystem minus 1. The algorithm for constructing the second-level subsystems of the pattern \(p\) for a subsystem \(s\) is as follows:  
**Step 1:** Let \(C_{\text{subsystem}}=\{C_{1},C_{2},\cdots,C_{n}\}\) as the set composed of all classes of the subsystem \(s\), where \(n\) is the number of classes in the subsystem \(s\).  
**Step 2:** Every time, take \(t\) classes from the set \(C_{\text{subsystem}}\) to form a new set, where \(t\) is the minimum number of roles in the pattern \(p\), and a total of \(C_{n}^{t}=\frac{nt}{t!\cdot(n-t)!}\) different subsets could be formed.  
**Step 3:** Each subset corresponds to a second-level subsystem. The classes in the second-level subsystem are the classes in this subset, and the relationship of classes in the second-level subsystem is the relationship of classes in the original subsystem. Operations in a class only retain operations that have a call/callee relationship with other classes in the second-level subsystem (or indirectly have a call/callee relationship with other classes in the second-level subsystem through other operations in the class), and properties hold only created objects of other classes in the second-level subsystem.  
**Step 4:** The second-level subsystems containing no generalization and second-level subsystems with two classes that have no relationship (and are not related through other classes, such as the second-level composed of the classes ActionTool, BorderTool and PolygonTool in the subsystem \(s_{1}\), of which BorderTool and PolygonTool are not related) are removed, and the other second-level subsystems are the final second-level subsystems.  
**Step 5:** The above process is repeated, and \(t,t+1,\cdots,n-1\) classes are sequentially taken from the set \(C_{\text{subsystem}}\) to build second-level subsystems.  
The Singleton pattern contains only one role, so a second-level subsystem contains only one class.  
Here, 4 second-level subsystems for the State pattern of the subsystem \(s_{1}\) of JHotDraw 5.1 shown in Figure 15 were considered, which were marked as \(s_{11}^{\prime}\), \(s_{12}^{\prime}\), \(s_{13}^{\prime}\) and \(s_{14}^{\prime}\), respectively. Among them, the second-level subsystem \(s_{11}^{\prime}\) is composed of the classes Tool, AbstractTool, CreationTool and DragTracker in the subsystem \(s_{1}\), \(s_{12}^{\prime}\) is composed of the classes Tool, AbstractTool, DragTracker, HandleTracker and SelectionTool, \(s_{13}^{\prime}\) is composed of the classes Tool, AbstractTool, HandleTracker, SelectAreaTracker and SelectionTool, and \(s_{14}^{\prime}\) is composed of the classes Tool, AbstractTool, DragTracker, HandleTracker, SelectAreaTracker and SelectionTool. The UML class diagrams of the four second-level subsystems are shown in Figure 3.