Advertisement
Guest User

CYK

a guest
Mar 27th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.02 KB | None | 0 0
  1. def CYK (gram: IndGrammar) = {
  2.             val cykMatrix = Array.fill[Array[Symbol]](numWords + 1)(Array.fill(numWords)(Symbol()))
  3.             cykMatrix.update(0,words)
  4.  
  5.             val productions = gram.productionList
  6.  
  7.             for (i <- 1 until numWords){
  8.                 var tempRow = List.empty[Symbol]
  9.                 for (j <- 0 until numWords - (i - 1)){
  10.                     println("------[" + i + "][" + j + "]------")
  11.                     var result = Symbol()
  12.                     var resultList = List.empty[Symbol]
  13.                     for (x <- 1 to i){
  14.                         var tempFront = List.empty[Symbol]
  15.                         for (y <- 0 until x){
  16.                             print("[" + (i-x) + "][" + (j+y) + "] ")
  17.                             tempFront = tempFront :+ cykMatrix(i-x)(j+y)
  18.                             resultList = resultList :+ searchProductions(productions, tempFront)
  19.                         }
  20.                         println()
  21.                     }
  22.                     val resultFilt = resultList.filterNot(sym => sym.isEpsilon)
  23.                     if (resultFilt.length >= 1)
  24.                         result = resultFilt.head
  25.                     else
  26.                         result = Symbol()
  27.                     tempRow = tempRow :+ result
  28.                 }
  29.                 println(tempRow)
  30.                 cykMatrix.update(i, tempRow.toArray)
  31.             }
  32.  
  33.         cykMatrix
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement