Repository: incubator-predictionio-template-similar-product Updated Branches: refs/heads/master b6ae68dc0 -> d75189b1d
adding category blacklist Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/commit/1b1eeecf Tree: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/tree/1b1eeecf Diff: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/diff/1b1eeecf Branch: refs/heads/master Commit: 1b1eeecf3a16dcce1a1f837f254ecb17707fdca0 Parents: 7e635ae Author: alex9311 <[email protected]> Authored: Sat Mar 26 17:00:15 2016 +0100 Committer: alex9311 <[email protected]> Committed: Sat Mar 26 17:00:15 2016 +0100 ---------------------------------------------------------------------- src/main/scala/ALSAlgorithm.scala | 8 ++++++++ src/main/scala/Engine.scala | 1 + 2 files changed, 9 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/blob/1b1eeecf/src/main/scala/ALSAlgorithm.scala ---------------------------------------------------------------------- diff --git a/src/main/scala/ALSAlgorithm.scala b/src/main/scala/ALSAlgorithm.scala index 7c0ddb9..62f87a3 100644 --- a/src/main/scala/ALSAlgorithm.scala +++ b/src/main/scala/ALSAlgorithm.scala @@ -158,6 +158,7 @@ class ALSAlgorithm(val ap: ALSAlgorithmParams) i = i, items = model.items, categories = query.categories, + categoryBlackList = query.categoryBlackList, queryList = queryList, whiteList = whiteList, blackList = blackList @@ -218,6 +219,7 @@ class ALSAlgorithm(val ap: ALSAlgorithmParams) i: Int, items: Map[Int, Item], categories: Option[Set[String]], + categoryBlackList: Option[Set[String]], queryList: Set[Int], whiteList: Option[Set[Int]], blackList: Option[Set[Int]] @@ -232,6 +234,12 @@ class ALSAlgorithm(val ap: ALSAlgorithmParams) // keep this item if has ovelap categories with the query !(itemCat.toSet.intersect(cat).isEmpty) }.getOrElse(false) // discard this item if it has no categories + }.getOrElse(true) && + categoryBlackList.map { cat => + items(i).categories.map { itemCat => + // discard this item if has ovelap categories with the query + (itemCat.toSet.intersect(cat).isEmpty) + }.getOrElse(true) // keep this item if it has no categories }.getOrElse(true) } http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-similar-product/blob/1b1eeecf/src/main/scala/Engine.scala ---------------------------------------------------------------------- diff --git a/src/main/scala/Engine.scala b/src/main/scala/Engine.scala index 766f7d8..034935a 100644 --- a/src/main/scala/Engine.scala +++ b/src/main/scala/Engine.scala @@ -7,6 +7,7 @@ case class Query( items: List[String], num: Int, categories: Option[Set[String]], + categoryBlackList: Option[Set[String]], whiteList: Option[Set[String]], blackList: Option[Set[String]] ) extends Serializable
