## 4 Methodology
### Logical Rules-Guided in-Context Triples Retrieval and Extractor Pre-Training
#### 4.1.1 Logical Rules-Guided in-Context Triples Retrieval  
Knowledge graphs contain a vast amount of frequency patterns, which can be expressed in the form of logical rules. These logical rules can serve as explicit reasoning bases for reasoning. Based on this, for a given query triple, the in-context triples can be retrieved from the knowledge graph by searching for those that support the relevant logical rules associated with the query triple.  
For example, assuming that a query triple is \"(Zuckerberg, nationality,?)\", then two logical rules about \"nationality\" can be obtained by the logical rule learning models (logical rule learning models generally take the given knowledge graph as input and mine a series of logical rules through analyzing the frequency patterns. Meanwhile, the confidence can be measured for each logical rule to reflect the degree of support for the corresponding logical rule within the existing knowledge graph data. There are various logical rule learning models, such as AMIE [22], AMIE3 [24], and AnyBURL [27], see Section 2.1 for more details.): \"(x, nationality, _y_)\(\leftarrow\)(x, works in, z)\(\wedge\)(z, located in state, _w_)\(\wedge\)(_w_, state in country, _y_)\", and \"(x, nationality, _y_)\(\leftarrow\)(x, born in, z)\(\wedge\)(z, located in state, _w_)\(\wedge\)(_w_, state in country, _y_)\". Then, the triples which support each logical rule can be extracted from knowledge graph \(\mathcal{G}\) (see more examples of this part in Appendix A). These in-context triples can provide crucial in-context clues for LLMs to reason on this given query triple. Therefore, we can construct the training data by retrieving triples from the given knowledge graph that can support the corresponding logical rules, and further pre-train the in-context triple extractor.  
Formally, for a relation \(r_{i}\), the logical rules learning models can be employed on the knowledge graph \(\mathcal{G}\), and the set of logical rules \(\mathbb{U}_{i}\) specific to the relation \(r_{i}\) can be obtained, where \(\mathbb{U}_{i}=\{u_{j}\}_{j=1}^{|\mathbb{U}_{i}|}\), and \(u_{j}\) is a logical rule about the relation \(r_{i}\). Based on a logical rule \(u_{j}\), a set of triplets that support the reasoning of \((h_{i},r_{i},t_{i})\) can be retrieved from the knowledge  
Figure 2: Framework of the proposed rule-and-reinforce in-context triple extraction method.  
graph, which is denoted by \(I_{j}\). Subsequently, we merge the sets of triples that support the rules in \(\mathbb{U}_{i}\), denoted as \(\mathcal{I}_{i}=I_{1}\cup I_{2}\cup\cdots\cup I_{|\mathbb{U}_{i}|}\). If the number of in-context triples of \(\mathcal{I}_{i}\) is greater than \(M\), then these in-context triples are sorted in descending order according to the confidence and order of the logical rules they support, and select the top \(M\) triples. Finally, for each query triple \((h_{i},r_{i},t_{i})\), the logical rules set \(\mathbb{U}_{i}\) can be obtained, and then the in-context triples \(\mathcal{I}_{i}\) which support the reasoning of \((h_{i},r_{i},t_{i})\) are retrieved according to \(\mathbb{U}_{i}\). Together, they constitute the pre-training data for the in-context triple extractor:  
\[D_{\text{rule}}=\{(h_{i},r_{i},?),\mathcal{I}_{i}\}. \tag{1}\]