Recommender System Configuration - UCM-GAIA/RecoLibry-Core GitHub Wiki
There are 2 techniques to create a recommender system in RecoLibry-Core. The first one is creating a new class that extends the RecSysConfiguration
class. The second technique is creating a configuration file in JSON format.
The first method is the best option for users who prefer to work with JAVA. In this case, we define each binding using Google's framework called Guice. It is the best option if we want to implement components not included in RecoLibry-Core.
On the other hand, the configuration file simplifies the way to define a recommender system. It is the best way to make a recommender system using components of RecoLibry-Core. This method is recommended to people that do not know JAVA.
Next, we explain how to configure a recommender system with both methods.
RecSysConfiguration
Extending As we explained before, the first method consists on implementing a class that extends the RecSysConfiguration
class. This class must implement 2 methods from RecSysConfiguration
: generateClass
and configure
.
public class TestConfiguration extends RecSysConfiguration {
@Override
protected void generateClass() {
}
@Override
protected void configure() {
}
}
The main goal of generateClass()
is building an auxiliary class for the recommender system. For example, we can implement this function to build a bean class that saves the items' descriptions. It is usefully in content-based recommender systems. On the other hand, in configure()
method we declare the components to bind for the recommender system.
If we need to implement a new class, the first instructions to add in configure is: compile()
to build the class, compile()
to compile the new class, and save the new class in a variable. The compile function is inherited from RecSysConfiguration
class. If we implemented the generated class function, our configure method should start as follow:
protected void configure() {
//Build defined class
generateClass();
//Compile the new class
compile();
//Save the class object
Class<?> clazz = Class.forName(PACKAGE_AND_CLASS_NAME);
}
The next steps to add in configure is to define all bindings between components used in our recommender systems. In RecoLibry-Core we use the library Guice to build the recommender systems. It uses bindings to define which components uses. A binding is an instruction to inject a class in a constructor. For example, RecoLibry-Core has an interface called RecommenderAlgorithm. We use the bindings to set the corresponding implementation, for example, RecommenderJColibri.
There are two binding types, depending on the component requirement: class binding and instance binding. The first one is used to define that one class will substitute a parent class. For example, this is used to specify the algorithm of the recommender system:
bind(RecommenderAlgorithm.class)
.to(RecommenderJColibri.class);
On the other hand, if we want to bind a concrete object or value, we will use the instance binding as follow:
Object instance = new Object()
bind(Object.class)
.annotatedWith(Names.named(ANNOTATION_OF_COMPONENT))
.toInstance(instance);
As we can observe, these bindings type contains an annotation. The reason for that is because many of these bindings are the same type, for example, String
type. For this reason, we tagged all instance bindings to difference each binding in RecoLibry-Core. We should read the documentation to know the type and annotation of each binding because it depends on each component of the recommender system.
In addition, some components could need other components. It depends on the recommender algorithm selected. The best way is looking up the documentation of each component that we want to add.
Create a configuration file
Another option to configure a recommender system is using a json
file. The configuration file should contain two elements to define the functions explained before:
generateClass
: it contains the information of the auxiliary class to create.configure
: it contains a list of all component bindings to build the recommender system.
In case to build a new class, the generateClass
object will be a JSON object with the following attributes:
packageName
: package name where will be created the new auxiliary class.className
: class name of the auxiliary class to create.attributes
: a list that contains all attributes with a simple type (Integer
,Double
,Float
,String
,Boolean
) included in the auxiliary class. Each attribute will contain aname
value and atype
value.attributesList
: a list that contains all attributes withList<>
type. Just like simple attributes, the list attributes has aname
value, with the name of the attribute, andtype
value with the type of theList<>
.
"generateClass": {
"packageName": "NAME_OF_THE_PACKAGE",
"className": "NAME_OF_THE_CLASS",
"attributes": [
{
"name": "ATTRIBUTE_1",
"type": "SIMPLE_TYPE"
}
],
"attributesList": [
{
"name": "ATTRIBUTE_LIST_1",
"type": "LIST_TYPE_1"
}
]
}
Next, we define all bindings to build the recommender system. These bindings are defining in configure object. Every binding is included in a list:
"configure": [
{
"type": "TYPE_OF_BINDING",
"bind": "CLASS_TO_REPLACE",
"annotated": "BINDING_ANNOTATION",
"to": "CLASS_TO_BIND"
},
...
]
Each binding is an object with the following attributes:
type
: binding type. Its value can beClass
to define a class binding orInstance
if define an instance binding.bind
: package and class that will be replaced.annotated
: binding annotation. If the binding hasn't got an annotation, the value must benull
.to
: class or instance that we will set to thebind
element.
There are some bindings that contain more properties, for example, bindings to define similarity functions in content-based recommender systems. To know what attributes are in a component, you should review this component in the Javadoc.