-
Notifications
You must be signed in to change notification settings - Fork 107
How to build your own Grader?
Graders are plain old ruby class that returns a probability number between 0
and 1
which represent the likely hood of the description being rated to be considered good or not. The probability returned by each grader will be multiplied together to generate a final probability in order for LinkThumbnailer to sort the description candidates between each other.
Here is an example of a "random" grader that return a 100% probability or a 0% probability randomly:
module LinkThumbnailer
module Graders
class Random < ::LinkThumbnailer::Graders::Base
def call
if rand(2) == 0
1.0
else
0.0
end
end
end
end
end
There are a couple things to notice here:
- Graders should live in
LinkThumbnailer::Graders
namespace - Graders must inherit from
LinkThumbnailer::Graders::Base
- Graders must respond to one public method called
call
- Graders must return a
Float
number between0
and1
representing a probability. - Graders have access to global and runtime configurations using a private method called
config
- Graders have access to the description being rated using a private method called
text
When instantiating a new grader, it should receive a LinkThumbnailer::Models::Description
instance. The LinkThumbnailer::Graders::Base
class from which all graders should inherit give you access to the description string
with the text
private method. You can also access the Nokogiri
node using the private node
method.
Note: Since each graders can specify a probability weight, you don't have to worry about it here. It will be automatically applied to the computation of the final score.