# Towards Domain-Specific Knowledge Graph Construction for Flight Control Aided Maintenance
## 4 Knowledge Graph Construction for Flight Control System
### Named Entity Recognition and Relation Extraction  
In this section, we elaborate on the way of named entity recognition and relation extraction. As a flight control system is domain-specific, few referential experiences could be referred to. We adopt the basic pipeline paradigm to reach a milestone. By careful study of the annotated text, we note that different entity classes have different features. The entity class _Power_ is special: entities of this class always appear regularly such that the appearance can be described by specific rules. Unfortunately, not all entity classes show such properties. Hence, we adopt a hybrid method that first leverages a rule-based algorithm to recognize the entities belonging to _Power_ and then an algorithm to recognize the remaining entities. Figure 3: Overview of ontology. The rule-based entity recognition method is designed based on regular expression which is a logical formula for string operations. Regular expression uses predefined specific characters and their combinations to form a pattern string. The pattern string is indeed a filter used to retrieve or replace the text conforming to the pattern. Figure 5 is the pseudo-code of the rule-based entity recognition algorithm dedicated to the _Power_ class. For each input sentence, we first obtain POS (part of speech) of each token (line 3) by NLTK (natural language toolkit) [42], a famous toolkit for natural language processing. We then leverage regular expression to identify all noun phrases (line 4). The \(rule\) appears in line 4 and is defined to be \(rule=\)\(\text{<NN.*}\)\(\text{|J>*}\)\(\text{<NN.*>}\)\(\vee\)\(\text{<JJ>*}\)\(\text{<CC><JJ>}\)\(\text{<NN. *>}\), where \"NN\" means a noun, \".\" represents any character except \(\backslash n\) and \(\backslash r\), \"*\" means the token or the token sequence in \(\text{<>}\) before \"*\" can appear multiple times, \".1\" expresses logic or, \"JJ\" means an adjective and \"CC\" refers to a conjunction. The first regular expression is used for the case that a sequence of nouns or a sequence of adjectives describe a key noun phrase, while the second one handles the scenario that two sequences of adjectives concatenated by a conjunction and describe a key noun phrase. The two rules are mutually exclusive, i.e., matching any one of them is enough. Finally, we apply a simple matching that ends with \"motor\" or \"actuator\" to differentiate whether there is a noun phrase belonging to the _Power_ class (lines 6-9). Let us consider the sentence \"One valve block is given for each hydraulic motor\" as an example. The set of noun phrases \(Seq_{noun}\) returned from line 4 is (\"valve block\", \"hydraulic motor\"). It can be seen that \"hydraulic motor\" ends with motor such that it is an entity of _Power_. The entity classes beyond _Power_ are not easy to recognize with manual-defined rules, so we propose a machine-learning-based algorithm to handle them. Entity recognition is now modeled as a sequence annotation problem. Let us use a set \(S=\{w_{1},w_{2},w_{3},\dots,w_{n}\}\) to express a sentence, where \(w_{i}\) is a token (word). Our target is to build a model \(f\) such that \(f(S)=y_{label}\), where \(f(S)\) is the annotation sequence output by the model \(f\) and \(y_{label}\) is the real annotation sequence. Figure 4: An example of entity and relation annotation. Figure 5: Extract entities belonging to _Power_. The entity recognition model \(f\) we designed is based on a popular strategy combining Transformer encoder with a CRF (conditional random field) layer [24; 43]. Figure 6 provides an overview of the recognition model. The Transformer encoder includes a position encoding layer and an encoder that mainly consists of multi-head self-attention and a feed-forward fully connected layer. Meanwhile, residual connection and normalization are used to connect the outputs of different hidden layers. When achieving output from the Transformer encoder, we leverage a linear and CRF layer to output the sequence of predicated labels.