-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified recommender wrapping methods (created an AbstractRecommend…
…er). Related with issue #6.
- Loading branch information
Showing
10 changed files
with
95 additions
and
157 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/net/recommenders/plista/rec/AbstractRecommender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandr | ||
*/ | ||
public abstract class AbstractRecommender implements Recommender { | ||
|
||
private Recommender wrapped; | ||
|
||
public AbstractRecommender(Recommender wrapped) { | ||
this.wrapped = wrapped; | ||
} | ||
|
||
public List<Long> recommend(Message input, Integer limit) { | ||
return wrapped.recommend(input, limit); | ||
} | ||
|
||
public void init() { | ||
wrapped.init(); | ||
} | ||
|
||
public void impression(Message _impression) { | ||
wrapped.impression(_impression); | ||
} | ||
|
||
public void click(Message _feedback) { | ||
wrapped.click(_feedback); | ||
} | ||
|
||
public void update(Message _update) { | ||
wrapped.update(_update); | ||
} | ||
|
||
public void setProperties(Properties properties) { | ||
wrapped.setProperties(properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 2 additions & 31 deletions
33
src/main/java/net/recommenders/plista/rec/ContestLuceneRecommenderWithUserFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,14 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandr | ||
*/ | ||
public class ContestLuceneRecommenderWithUserFilter implements Recommender { | ||
|
||
private Recommender wrapped; | ||
public class ContestLuceneRecommenderWithUserFilter extends AbstractRecommender implements Recommender { | ||
|
||
public ContestLuceneRecommenderWithUserFilter() { | ||
this.wrapped = new UserFilterWrapper(new WrappableRecommender(new LuceneRecommender())); | ||
} | ||
|
||
public List<Long> recommend(Message input, Integer limit) { | ||
return wrapped.recommend(input, limit); | ||
} | ||
|
||
public void init() { | ||
wrapped.init(); | ||
} | ||
|
||
public void impression(Message _impression) { | ||
wrapped.impression(_impression); | ||
} | ||
|
||
public void click(Message _feedback) { | ||
wrapped.click(_feedback); | ||
} | ||
|
||
public void update(Message _update) { | ||
wrapped.update(_update); | ||
} | ||
|
||
public void setProperties(Properties properties) { | ||
wrapped.setProperties(properties); | ||
super(new UserFilterWrapper(new WrappedRecommender(new LuceneRecommender()))); | ||
} | ||
} |
33 changes: 2 additions & 31 deletions
33
src/main/java/net/recommenders/plista/rec/PRCategoryRecommenderWithUserFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,14 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandr | ||
*/ | ||
public class PRCategoryRecommenderWithUserFilter implements Recommender { | ||
|
||
private Recommender wrapped; | ||
public class PRCategoryRecommenderWithUserFilter extends AbstractRecommender implements Recommender { | ||
|
||
public PRCategoryRecommenderWithUserFilter() { | ||
this.wrapped = new UserFilterWrapper(new WrappableRecommender(new PRCategoryBasedRecommender())); | ||
} | ||
|
||
public List<Long> recommend(Message input, Integer limit) { | ||
return wrapped.recommend(input, limit); | ||
} | ||
|
||
public void init() { | ||
wrapped.init(); | ||
} | ||
|
||
public void impression(Message _impression) { | ||
wrapped.impression(_impression); | ||
} | ||
|
||
public void click(Message _feedback) { | ||
wrapped.click(_feedback); | ||
} | ||
|
||
public void update(Message _update) { | ||
wrapped.update(_update); | ||
} | ||
|
||
public void setProperties(Properties properties) { | ||
wrapped.setProperties(properties); | ||
super(new UserFilterWrapper(new WrappedRecommender(new PRCategoryBasedRecommender()))); | ||
} | ||
} |
33 changes: 2 additions & 31 deletions
33
src/main/java/net/recommenders/plista/rec/PROtherCategoryRecommenderWithUserFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,14 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandr | ||
*/ | ||
public class PROtherCategoryRecommenderWithUserFilter implements Recommender { | ||
|
||
private Recommender wrapped; | ||
public class PROtherCategoryRecommenderWithUserFilter extends AbstractRecommender implements Recommender { | ||
|
||
public PROtherCategoryRecommenderWithUserFilter() { | ||
this.wrapped = new UserFilterWrapper(new WrappableRecommender(new PROtherCategoryBasedRecommender())); | ||
} | ||
|
||
public List<Long> recommend(Message input, Integer limit) { | ||
return wrapped.recommend(input, limit); | ||
} | ||
|
||
public void init() { | ||
wrapped.init(); | ||
} | ||
|
||
public void impression(Message _impression) { | ||
wrapped.impression(_impression); | ||
} | ||
|
||
public void click(Message _feedback) { | ||
wrapped.click(_feedback); | ||
} | ||
|
||
public void update(Message _update) { | ||
wrapped.update(_update); | ||
} | ||
|
||
public void setProperties(Properties properties) { | ||
wrapped.setProperties(properties); | ||
super(new UserFilterWrapper(new WrappedRecommender(new PROtherCategoryBasedRecommender()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 5 additions & 43 deletions
48
src/main/java/net/recommenders/plista/rec/WrappableRecommender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,16 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandro | ||
* Interface to allow recommenders to be wrapped by other classes, like filters | ||
* | ||
* @author alejandr | ||
*/ | ||
public class WrappableRecommender implements Recommender, WrappableRecommenderIF { | ||
|
||
private Recommender wrapped; | ||
private int factor; | ||
|
||
public WrappableRecommender(Recommender wrapped) { | ||
this(wrapped, 10); | ||
} | ||
|
||
public WrappableRecommender(Recommender wrapped, int factor) { | ||
this.wrapped = wrapped; | ||
this.factor = factor; | ||
} | ||
|
||
@Override | ||
public List<Long> recommendAll(Message message, Integer limit) { | ||
return wrapped.recommend(message, (factor * limit)); | ||
} | ||
|
||
public List<Long> recommend(Message message, Integer limit) { | ||
return wrapped.recommend(message, limit); | ||
} | ||
|
||
public void init() { | ||
wrapped.init(); | ||
} | ||
|
||
public void impression(Message _impression) { | ||
wrapped.impression(_impression); | ||
} | ||
|
||
public void click(Message _feedback) { | ||
wrapped.click(_feedback); | ||
} | ||
|
||
public void update(Message _update) { | ||
wrapped.update(_update); | ||
} | ||
public interface WrappableRecommender extends Recommender { | ||
|
||
public void setProperties(Properties properties) { | ||
wrapped.setProperties(properties); | ||
} | ||
public List<Long> recommendAll(final Message input, final Integer limit); | ||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/net/recommenders/plista/rec/WrappableRecommenderIF.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/main/java/net/recommenders/plista/rec/WrappedRecommender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.recommenders.plista.rec; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import net.recommenders.plista.client.Message; | ||
import net.recommenders.plista.recommender.Recommender; | ||
|
||
/** | ||
* | ||
* @author alejandro | ||
*/ | ||
public class WrappedRecommender extends AbstractRecommender implements Recommender, WrappableRecommender { | ||
|
||
private Recommender wrapped; | ||
private int factor; | ||
|
||
public WrappedRecommender(Recommender wrapped) { | ||
this(wrapped, 10); | ||
} | ||
|
||
public WrappedRecommender(Recommender wrapped, int factor) { | ||
super(wrapped); | ||
this.wrapped = wrapped; | ||
this.factor = factor; | ||
} | ||
|
||
@Override | ||
public List<Long> recommendAll(Message message, Integer limit) { | ||
return wrapped.recommend(message, (factor * limit)); | ||
} | ||
|
||
public List<Long> recommend(Message message, Integer limit) { | ||
return wrapped.recommend(message, limit); | ||
} | ||
} |