Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word repetition issue #9

Open
yurkor opened this issue Mar 26, 2013 · 0 comments
Open

Word repetition issue #9

yurkor opened this issue Mar 26, 2013 · 0 comments

Comments

@yurkor
Copy link

yurkor commented Mar 26, 2013

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
      }
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant