## 3 Materials and Methods
Calculate inverse document frequency as given in Equation (2)
4. Compute tf-idf values for the words as given in Equation (3)
5. Set a minimum threshold value for tf-idf
6. Open a new csv file 6.1 For row_i write each word of document_i whose tf-idf > threshold
```
**Algorithm 2** TREASURE Data Preprocessing

### Generation of Relation Records Using Affinity Analysis

The preprocessed data must be integrated to derive any inference. For example, Amikacin is used in the treatment of non-tuberculous mycobacterial (NTM) disease. This sentence exhibits the relationship between amikacin and non-tuberculous mycobacteria. This kind of co-occurrence relationships can be determined by the affinity analysis technique. Algorithm 3 shows the generation of relation records using affinity analysis. In this technique, we consider each document as a transaction and each word as an item. To determine various connections between items, some formal definitions of measures like support, confidence and lift are needed [27; 28; 29]. _Support_ is a simple and yet an important metric in affinity analysis. Its equation is given in Equation (4). The support of (A \(\cup\) B), where A and B are item sets, is given as the ratio of all the transactions that contain all items of (A \(\cup\) B) to the number of transactions in the dataset. \[Support\ (\text{A}\ \rightarrow\ \text{B})=Support\ (\text{A}\ \cup\ \text{B})=\ \text{P}\ (\text{A}\ \cup\ \text{B}) \tag{4}\]

_Confidence_ denotes the likelihood of certain items to occur together. It is given in Equation (5) and is defined as the proportion of transactions containing item set A that also contain item set B.

\[Confidence\ (\text{A}\ \rightarrow\ \text{B})=\text{P}(\text{A}\ |\ \text{B})= \frac{Support\ (A\ \cup\ \text{B})}{Support\ (A)} \tag{5}\]

_Lift_ is another important measure in affinity analysis. It is the ratio of probability of A and B occurring together to the product of probabilities of A and B occurring as if there was no association between them Equation (6). \[Lift\ (\text{A}\ \rightarrow\ \text{B})=\frac{Support\ (A\ \cup\ \text{B})}{Support\ (A)\ Support\ (B)} \tag{6}\]
```
Input: Preprocessed csv file, minimum number of items in a set as min_length, minimum co-occurrence value as min_support and the minimum conditional property as min_confidence Output: A JSON file containing a list of relation records with corresponding confidence, support and lift values
1. Read each item in the file
2. Calculate support for every item as given in Equation (4)
3. Insert every item into a frequent dataset whose support \(\geq\) min_support
4. For each item in the frequent dataset calculate confidence and lift values as given in Equations (5) and (6)
5. Insert every rule into a JSON file whose confidence and items count are greater than the corresponding threshold
```
**Algorithm 3** TREASURE Relation Records Generation via Affinity Analysis

### Filtering Relation Records Based on Maximum Co-Occurrence Value and Set Intersection

The generated relation records contain interrelated words with corresponding support, confidence and lift values. However, not all the relations generated, will have a useful meaning. Therefore, we need to filter these records to extract the primary combination of words. For this purpose, the set intersection property is applied on the records. Among the intersecting sets, the one with the maximum co-occurrence value, i.e., the relation that has frequently occurred, is filtered out and added to the resultant set. This is done to prevent the repetition of same inference and to obtain as many unique inferences as possible. For example, ['capreomycin', 'injectable'], ['capreomycin', 'tuberculosis'] are the intersecting sets. The inference obtained here is that capreomycin is an injectable drug used in the treatment of TB. Among these, ['capreomycin', 'injectable'] has the maximum co-occurrence value and thus, it is added to the resultant set. Algorithm 4 shows the filtration of relation records.