## 2 Method
### Knowledge Graph for the Identification of Ship Illegal Behaviors
#### 2.3.4 Step 8: Ship Behavior Feature Extraction  
Based on the developed database, a ship behavior feature extraction method is proposed to identify ship behavior feature features, as shown in Figure 7.  
Figure 6: Entity construction.  
Figure 7: Ship behavior feature extraction.  
Based on the features, K-means algorithm is used to cluster this feature information of ship trajectory in the case study area [35]. The mathematical background to this process is displayed in Equations (1)-(4) below and the pseudocode of the process is summarized in Table 3. For a point \(p_{i}\) in the way of a trajectory defined as per Equation (1), the locations of the departure and destination ports are defined as in Equation (2). Then, the length of the ship trajectory is calculated as in Equations (3) and (4).  
\[p_{i}=\{MMSI,TIMEestamp,LON,LAT,SOG,COG,Draft\} \tag{1}\]  
\[T_{se}=\{(lon_{1},lat_{1}),(lon_{n},lat_{n})\} \tag{2}\]  
\[d\big{(}p_{j},p_{j+1}\big{)}=\big{(}TimeStamp_{j+1}-TimeStamp_{j}\big{)}\times \big{(}sog_{j}+sog_{j+1}\big{)}/2 \tag{3}\]  
\[T_{length}=\sum_{j=1}^{n-1}d(p_{j},p_{j+1}) \tag{4}\]  
where \((lon_{1},lat_{1})\) and \((lon_{n},lat_{n})\) denote the longitude and latitude of the departure and destination ports, respectively. \(d(p_{j},p_{j+1})\) denote the distance between \(p_{j}\) and \(p_{j+1}\) (see Figure 8). This is example 2 of an equation:Finally, the ship multi-track determination method traces through Mysql relational data and neo4j graph database fusion calculation with the following rules:  
1. Define the data set \(X=\{x_{1},x_{2},...,x_{n}\}\), where each \(x_{i}\) represents a point in the ship trajectory;
2. Preprocessing the dataset, e.g., sorting the trajectories in chronological order and representing each point as a triplet of (longitude, latitude, time);
3. Choose the number of clusters \(k\), initialize \(k\) prime centers \(c_{1},c_{2},...,c_{k}\);
4. For each point \(x_{i}\), calculate its distance \(d_{ij}\) to each center of mass \(c_{j}\) and classify it into the cluster \(s_{j}\) to which the center of mass with the closest distance belongs;
5. Update the center of mass, and for each cluster \(s_{j}\), update its center of mass \(c_{j}\) to be the average of all its points;
6. Repeating the above steps (d) and (e) until the center of mass no longer changes or reaches the specified number of iterations, obtaining the number of ship multiple trajectories, and finally labeling and refining the ship multiple trajectory feature information into the ship feature graph.  
Based on the ship entity (ship number, ship name), extract local subgraphs centering on ship attributes (such as ship name, MMSI, ship type, etc.), key monitoring relationship and certificate expiration relationship, obtain ship attributes, ship key monitoring and ship certificate expiration subgraph features and refine them into the new ship feature graph with specific markings; use Mysql aggregation and correlation query to retrieve ship reporting information. The ship characteristics are extracted and added to the ship characteristics graph by using Mysql aggregation and correlation query to retrieve the ship reporting information; the ship multiple trajectory features and the ship reporting time sequence information are fused, and the inconsistent trajectory and reporting features are inferred and added to the ship characteristics graph.