Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def CYK (gram: IndGrammar) = {
- val cykMatrix = Array.fill[Array[Symbol]](numWords + 1)(Array.fill(numWords)(Symbol()))
- cykMatrix.update(0,words)
- val productions = gram.productionList
- for (i <- 1 until numWords){
- var tempRow = List.empty[Symbol]
- for (j <- 0 until numWords - (i - 1)){
- println("------[" + i + "][" + j + "]------")
- var result = Symbol()
- var resultList = List.empty[Symbol]
- for (x <- 1 to i){
- var tempFront = List.empty[Symbol]
- for (y <- 0 until x){
- print("[" + (i-x) + "][" + (j+y) + "] ")
- tempFront = tempFront :+ cykMatrix(i-x)(j+y)
- resultList = resultList :+ searchProductions(productions, tempFront)
- }
- println()
- }
- val resultFilt = resultList.filterNot(sym => sym.isEpsilon)
- if (resultFilt.length >= 1)
- result = resultFilt.head
- else
- result = Symbol()
- tempRow = tempRow :+ result
- }
- println(tempRow)
- cykMatrix.update(i, tempRow.toArray)
- }
- cykMatrix
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement