Recommender System execution - UCM-GAIA/RecoLibry-Core GitHub Wiki

After creating an instance of the recommender system, we explain the classes and steps to perform recommendations using our recommender system. There are 3 instances that we will use during the execution of our recommender system:

  • RecommenderSystem: the instance of the recommender systems created.
  • Query: this instance stores all information about the query needed to execute in the recommender system.
  • RecommenderResult: an instance that stores the result of a recommendation performed using our recommender system. This result contains the item recommended and a rating value.

The first step is to create a new recommender system and save it in a variable:

RecommenderSystem recSys = getRecommenderSystem();

When we have our recommender system object, we can work with the elements defined before. Next, we explain how to work with each element.

Query

As mentioned before, a Query type object stores the information that we will send to the recommendation system as a query. For example, in a collaborative filtering recommendation system, it could be the user's identifier.

The recommendation system returns the correct instance of Query. To do this, we will execute the getQuery() method in the recommender system:

Query query = recSys.getQuery();

When the system returns the query object, its attributes are not initialized. To initialize these attributes is necessary to execute the initialize() method of our query:

query.initialize();

When we initialized our query object, we can work with the attributes of our query. The actions we can execute are:

  • getAttributeNames(): it returns the name and data type of all query´s attributes.

  • setAttributeName(name,value): it sets the value sent in the value parameter in the attribute with the corresponding name. For example, to set the user identifier in our query, we must execute these instructions:

    long user = 414;
    query.setAttributeValue("userId", user);
    
  • getAttributeValue(name): it returns the value that contains the attribute with the corresponding name.

When we want to clean all the information in the query object, we can execute the initialize() method. After filling in the query, we can send it to our recommender system. You can visit [https://github.com/UCM-GAIA/RecoLibry-Core/wiki/Implement-new-algorithm#new-query](recommender system execution) to know all methods included in a Query class.

RecommenderSystem

To execute the recommender system, we need to execute the following steps:

  • Initialize: The first step is to initialize the recommender system. This method executes all the previous actions needed to set up the recommender system. For example, in a content-based recommender system, this step will load item information in the recommender system. We need to execute this step once.
  • Recommend: Next, we execute the query to obtain a recommendation. We can execute this step as we want. In every execution, the recommender system returns a list of RecommenderResult.
  • Close: It is necessary to close the recommender system correctly before shutting it down. We execute it when we stop using the recommender system.

An example to execute a query in the recommender system is:

recSys.initRecommender();

List<RecommenderResult> results = recSys.recommend(Query);

recSys.closeRecommender();

Next, we explain the information contained in the results.

RecommenderResult

A recommender system result is saved in a RecommenderResult object. It contains 2 attributes:

  • Recommended Item: The item returned as a recommendation by the system. The item class depends on the recommender system type.
  • Rating value: It is a numeric value that represents the rating predicted of the corresponding item. The range of this value will depend on the recommender system built.

In addition, it contains a method get for each element and a method toString() that return both elements in text format.