# A Hybrid Ontology-Based Recommendation System in e-Commerce
## 3 The Hybrid Ontology-based Approach
Figure 3 shows that, the active user's gender is male, has spent an average of $17.95 and has purchased products in three distinct categories, namely 3 Products in Automotive, 2 Products in Video Games and 5 Products in Music Instruments. The first 3 columns in the Neighbours vector of features concerns the number of products that each neighbor has purchased in each category. The fourth column identifies the gender (1 to male, 0 to female and 0.5 when it is not possible to discover gender). The fifth column is the average money spent, and the last identifies if a Neighbour has purchased products in distinct categories from the user, meaning 1 if true and 0 if false. Our goal with the last column is to give priority to the Neighbours who have purchased in other categories. After creating all the Neighbours vector features and normalizing the columns in a range of 0 and 1, we calculate the Euclidean distance between each one of them and the user vector feature, to discover the nearest Neighbours of the user. ### Rules Approach--Algorithm 4

When the nearest Neighbours are defined, as explained in the previous subsection, it is necessary to find out whether the IDs of the products that they have purchased are new to the active user. This procedure is explained in Algorithm 4. ```
Input: List of all Products bought by the active user's neighbours Result: List of ProductsIds that active user doesn't have yet bought return IDsProducts
```

**Algorithm 5**Find IDs of products bought by neighbours that active user don't bought

Figure 3: Creation of the vector of features to each Neighbour. In Algorithm 4, we see that for each element in the list of all ProductsIds bought by Neighbours, the procedure consists of making sure that the product does not belong to the attribute ProductsIds of the active User. Only those that meet the above condition are stored and for each of them a respective Product class is created, as explained earlier in Section 3.2. ### KNN algorithm to find Products

After selecting the Ids of Products that the user has not yet bought, we create a Product class for each one, as explained in Section 3.2. As previously mentioned, we include the text revisions in our recommendation system. Therefore, we create a new database that contains, for each category of products, the 200 most common words used in the revisions which have an overall rating of 4 and 5. In order to process the text revision, we split them into unique words and remove any punctuation or characters. After that, we remove the stop words, which are words that appear frequently in any document and do not add meaning to a sentence [20]. We also apply Lemmatization, which is the process that obtains the \"lemma\" of a word by understanding the part of speech and the context of the word in the respective sentence [26]. We choose Lemmatization over Stemming due to the fact that Lemmatization produces better results [27]. Finally, we select only the 200 most common words and save them in the new database. Although the Products relate to Neighbours, we also want to consider the opinion of all persons that have purchased the product. Therefore, the TopFiveWords attribute of Product, consists in the extraction of the 5 most common words used in all the revisions of this Product. The process for picking these words is similar to the one described in the previous paragraph. The last step of our ontology-based recommendation system consists of applying the KNN algorithm in order to find the nearest Products to recommend to the user. For each Product, we create a vector of features with three columns (see Figure 4). The first column is a value that will be given the value of 1 if the Product Price is between User MinPrice and User MaxPrice, and 0 if not. The second column identifies the overall rating given by the respective Neighbour, which can be a value between 1 and 5. The third column is a number between 0 and 5. This attribute is 0 if no word of the TopFiveWords is among in the 200 most common words of the product category and 5 if all words are.