cleo icon indicating copy to clipboard operation
cleo copied to clipboard

Word repetition issue

Open yurkor opened this issue 11 years ago • 0 comments

PrefixSelector doesnt properly works with word repetition. I.e. you can type same word(or even short prfix) several times and get same suggestion.

You can use something like this to solve the problem: (scala code)

  class MySelector(terms: Array[String]) extends PrefixSelector[MyElement](terms: _*) {
    val storage = new Array[Boolean](20)

    def startWith(child: Array[String], parent: Array[String]):Boolean = {
      val pi = parent.toIterator.zipWithIndex
      for (i <- 0 until parent.size) storage(i) = false
      child.forall {
        cw => pi.exists {
          case (w, i) => if (w.startsWith(cw) && !storage(i)) {
            storage(i) = true;
            true
          } else false
        }
      }
    }

    override def select(element: MyElement, ctx: SelectorContext): Boolean = {
        val select = startWith(terms,element.getTerms)
        select
      }
    }
  }

yurkor avatar Mar 26 '13 01:03 yurkor