@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData();
Attributes attributes = exampleSet.getAttributes();
boolean OU = getParameterAsBoolean("Online updates");
if (exampleSet.getAttributes().getSpecial("user identification") == null) {
throw new UserError(this,105);
}
if (exampleSet.getAttributes().getSpecial("item identification") == null) {
throw new UserError(this, 105);
}
Attributes Att = exampleSet.getAttributes();
AttributeRole ur=Att.getRole("user identification");
Attribute u=ur.getAttribute();
AttributeRole ir=Att.getRole("item identification");
Attribute i=ir.getAttribute();
Attribute label=null;
if(OU==true){
if(Att.getLabel()!=null)
label=Att.getLabel();
}
RatingPredictor model = exampleSetInput1.getData();
ExampleSet out=exampleSet;
ArrayList<Integer> new_users=new ArrayList<Integer>();
ArrayList<Integer> new_items=new ArrayList<Integer>();
com.rapidminer.data.CompactHashSet<Integer> s2=new com.rapidminer.data.CompactHashSet<Integer>();
com.rapidminer.data.CompactHashSet<Integer> s3=new com.rapidminer.data.CompactHashSet<Integer>();
ArrayList<Integer> r_users=null;
ArrayList<Integer> r_items=null;
ArrayList<Double> ratings=null;
Attribute pred = AttributeFactory.createAttribute("prediction",
Ontology.REAL);
if(!attributes.contains(pred)){
attributes.addRegular(pred);
ExampleTable a=exampleSet.getExampleTable();
a.addAttribute(pred);
}
else pred=attributes.get("prediction");
int useRatingUpdate=0;
if(OU==true && Att.getLabel()!=null){
r_users=new ArrayList<Integer>();
r_items=new ArrayList<Integer>();
ratings=new ArrayList<Double>();
for (Example example : out) {
int us=model.user_mapping.ToInternalID((int)example.getValue(u));
int it=model.item_mapping.ToInternalID((int)example.getValue(i));
if(us>model.MaxUserID){
new_users.add(us);
model.MaxUserID=us;
}
if(it>model.MaxItemID){
new_items.add(it);
model.MaxItemID=it;
}
s2.add(us);
s3.add(it);
double r=example.getValue(label);
if(model.AddRatings(null, null, null)==1){
r_users.add(us);
r_items.add(it);
ratings.add(r);
useRatingUpdate=1;
}
}
}
ArrayList<Integer> query_users=new ArrayList<Integer>(s2);
ArrayList<Integer> query_items=new ArrayList<Integer>(s3);
if(OU==true && Att.getLabel()!=null){
if(new_items.size()!=0)
model.AddItems(new_items);
if(new_users.size()!=0)
model.AddUsers(new_users);