Spiral.scala
author Chengsong
Fri, 15 Mar 2019 10:46:46 +0000
changeset 3 f15dccc42c7b
parent 2 cf169411b771
child 4 7a349fe58bf4
permissions -rwxr-xr-x
removing PRED why should it still be there after so many rounds of experiments? It should have been removed long ago since its existence will always make the compiler report errors. mysterious.:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Chengsong
parents:
diff changeset
     1
import Element.elem
Chengsong
parents:
diff changeset
     2
import RexpRelated._
Chengsong
parents:
diff changeset
     3
import RexpRelated.Rexp._
Chengsong
parents:
diff changeset
     4
import Partial._
Chengsong
parents:
diff changeset
     5
import BRexp._
Chengsong
parents:
diff changeset
     6
import scala.collection.mutable.ListBuffer
Chengsong
parents:
diff changeset
     7
object Spiral{
Chengsong
parents:
diff changeset
     8
Chengsong
parents:
diff changeset
     9
  val space = elem(" ")
Chengsong
parents:
diff changeset
    10
  val corner = elem("+")
Chengsong
parents:
diff changeset
    11
Chengsong
parents:
diff changeset
    12
  def spiral(nEdges: Int, direction: Int): Element = {
Chengsong
parents:
diff changeset
    13
    if(nEdges == 1)
Chengsong
parents:
diff changeset
    14
      elem("+")
Chengsong
parents:
diff changeset
    15
    else {
Chengsong
parents:
diff changeset
    16
      val sp = spiral(nEdges - 1, (direction + 3) % 4)
Chengsong
parents:
diff changeset
    17
      def verticalBar = elem('|', 1, sp.height)
Chengsong
parents:
diff changeset
    18
      def horizontalBar = elem('-', sp.width, 1)
Chengsong
parents:
diff changeset
    19
      if(direction == 0)
Chengsong
parents:
diff changeset
    20
        (corner beside horizontalBar) above sp//(sp beside space)
Chengsong
parents:
diff changeset
    21
      else if (direction == 1)
Chengsong
parents:
diff changeset
    22
        sp beside (corner above verticalBar)
Chengsong
parents:
diff changeset
    23
      else if (direction == 2)
Chengsong
parents:
diff changeset
    24
        (space beside sp) above (horizontalBar beside corner)
Chengsong
parents:
diff changeset
    25
      else
Chengsong
parents:
diff changeset
    26
        (verticalBar above corner) beside (space above sp)
Chengsong
parents:
diff changeset
    27
    }
Chengsong
parents:
diff changeset
    28
  }
Chengsong
parents:
diff changeset
    29
  val alphabet = ("""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:"=()\;-+*!<>\/%{} """+"\n\t").toSet//Set('a','b','c')
Chengsong
parents:
diff changeset
    30
  def bregx_tree(r: BRexp): Element = regx_tree(berase(r))
Chengsong
parents:
diff changeset
    31
  def regx_tree(r: Rexp): Element = aregx_tree(internalise(r))
Chengsong
parents:
diff changeset
    32
  def aregx_tree(r: ARexp): Element = {
Chengsong
parents:
diff changeset
    33
    r match {
Chengsong
parents:
diff changeset
    34
      case ACHAR(bs, d) => {
Chengsong
parents:
diff changeset
    35
        //val Some(d) = alphabet.find(f)
Chengsong
parents:
diff changeset
    36
        d match {
Chengsong
parents:
diff changeset
    37
          case '\n' => elem("\\n")
Chengsong
parents:
diff changeset
    38
          case '\t' => elem("\\t")
Chengsong
parents:
diff changeset
    39
          case ' ' => elem("space")
Chengsong
parents:
diff changeset
    40
          case d => elem(d.toString)
Chengsong
parents:
diff changeset
    41
        }   
Chengsong
parents:
diff changeset
    42
      }
Chengsong
parents:
diff changeset
    43
      case AONE(bs) => {
Chengsong
parents:
diff changeset
    44
        elem("ONE")
Chengsong
parents:
diff changeset
    45
      }
Chengsong
parents:
diff changeset
    46
      case AZERO => {
Chengsong
parents:
diff changeset
    47
        elem("ZERO")
Chengsong
parents:
diff changeset
    48
      }
Chengsong
parents:
diff changeset
    49
      case ASEQ(bs, r1, r2) => {
Chengsong
parents:
diff changeset
    50
        binary_print("SEQ", r1, r2)
Chengsong
parents:
diff changeset
    51
      }
Chengsong
parents:
diff changeset
    52
      case AALTS(bs, rs) => {
Chengsong
parents:
diff changeset
    53
        //elem("Awaiting completion")
Chengsong
parents:
diff changeset
    54
        list_print("ALT", rs)
Chengsong
parents:
diff changeset
    55
      }
Chengsong
parents:
diff changeset
    56
      case ASTAR(bs, r) => {
Chengsong
parents:
diff changeset
    57
        list_print("STA", List(r))
Chengsong
parents:
diff changeset
    58
      }
Chengsong
parents:
diff changeset
    59
    }
Chengsong
parents:
diff changeset
    60
  }
Chengsong
parents:
diff changeset
    61
  val port = elem(" └-")
Chengsong
parents:
diff changeset
    62
  def list_print(name: String, rs: List[ARexp]): Element = {
Chengsong
parents:
diff changeset
    63
    rs match {
Chengsong
parents:
diff changeset
    64
      case r::Nil => {
Chengsong
parents:
diff changeset
    65
        val pref = aregx_tree(r)
Chengsong
parents:
diff changeset
    66
        val head = elem(name)
Chengsong
parents:
diff changeset
    67
        (head left_align (port up_align pref) ) 
Chengsong
parents:
diff changeset
    68
      }
Chengsong
parents:
diff changeset
    69
      case r2::r1::Nil => {
Chengsong
parents:
diff changeset
    70
        binary_print(name, r2, r1)
Chengsong
parents:
diff changeset
    71
      }
Chengsong
parents:
diff changeset
    72
      case r::rs1 => {
Chengsong
parents:
diff changeset
    73
        val pref = aregx_tree(r)
Chengsong
parents:
diff changeset
    74
        val head = elem(name)
Chengsong
parents:
diff changeset
    75
        if (pref.height > 1){
Chengsong
parents:
diff changeset
    76
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
    77
          (head left_align ((port above link) beside pref)) left_align tail_print(rs1)    
Chengsong
parents:
diff changeset
    78
        }
Chengsong
parents:
diff changeset
    79
        else{
Chengsong
parents:
diff changeset
    80
          (head left_align (port beside pref) ) left_align tail_print(rs1)
Chengsong
parents:
diff changeset
    81
        }
Chengsong
parents:
diff changeset
    82
      }
Chengsong
parents:
diff changeset
    83
    }
Chengsong
parents:
diff changeset
    84
  }
Chengsong
parents:
diff changeset
    85
  def tail_print(rs: List[ARexp]): Element = {
Chengsong
parents:
diff changeset
    86
    rs match {
Chengsong
parents:
diff changeset
    87
      case r2::r1::Nil => {
Chengsong
parents:
diff changeset
    88
        val pref = aregx_tree(r2)
Chengsong
parents:
diff changeset
    89
        val suff = aregx_tree(r1)
Chengsong
parents:
diff changeset
    90
        if (pref.height > 1){
Chengsong
parents:
diff changeset
    91
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
    92
          ((port above link) beside pref) left_align (port up_align suff)
Chengsong
parents:
diff changeset
    93
        }
Chengsong
parents:
diff changeset
    94
        else{
Chengsong
parents:
diff changeset
    95
          (port beside pref) left_align (port up_align suff)
Chengsong
parents:
diff changeset
    96
        } 
Chengsong
parents:
diff changeset
    97
      }
Chengsong
parents:
diff changeset
    98
      case r2::rs1 => {
Chengsong
parents:
diff changeset
    99
        val pref = aregx_tree(r2)
Chengsong
parents:
diff changeset
   100
        
Chengsong
parents:
diff changeset
   101
        if (pref.height > 1){
Chengsong
parents:
diff changeset
   102
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   103
          ((port above link) beside pref) left_align tail_print(rs1)//(port up_align tail_print(rs1) )
Chengsong
parents:
diff changeset
   104
        }
Chengsong
parents:
diff changeset
   105
        else{
Chengsong
parents:
diff changeset
   106
          (port beside pref) left_align tail_print(rs1)//(port up_align tail_print(rs1))
Chengsong
parents:
diff changeset
   107
        } 
Chengsong
parents:
diff changeset
   108
        //pref left_align tail_print(rs1)
Chengsong
parents:
diff changeset
   109
      }
Chengsong
parents:
diff changeset
   110
    }
Chengsong
parents:
diff changeset
   111
  }
Chengsong
parents:
diff changeset
   112
Chengsong
parents:
diff changeset
   113
  def binary_print(name: String, r1: ARexp, r2: ARexp): Element = {
Chengsong
parents:
diff changeset
   114
    val pref = aregx_tree(r1)
Chengsong
parents:
diff changeset
   115
    val suff = aregx_tree(r2)
Chengsong
parents:
diff changeset
   116
    val head = elem(name)
Chengsong
parents:
diff changeset
   117
    if (pref.height > 1){
Chengsong
parents:
diff changeset
   118
      val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   119
      (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   120
    }
Chengsong
parents:
diff changeset
   121
    else{
Chengsong
parents:
diff changeset
   122
      (head left_align (port beside pref) ) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   123
    }
Chengsong
parents:
diff changeset
   124
  }
Chengsong
parents:
diff changeset
   125
  val arr_of_size = ListBuffer.empty[Int]
2
cf169411b771 more comments
Chengsong
parents: 1
diff changeset
   126
0
Chengsong
parents:
diff changeset
   127
  def pC(r: Rexp): Set[Rexp] = {//PD's companion
Chengsong
parents:
diff changeset
   128
    r match {
Chengsong
parents:
diff changeset
   129
      case SEQ(r1, r2) => pC(r2)
Chengsong
parents:
diff changeset
   130
      case ALTS(rs) => rs.flatMap(a => pC(a) ).toSet
Chengsong
parents:
diff changeset
   131
      case CHAR(c) => Set(r)
Chengsong
parents:
diff changeset
   132
      case r => Set()
Chengsong
parents:
diff changeset
   133
    }
Chengsong
parents:
diff changeset
   134
  }
Chengsong
parents:
diff changeset
   135
  def illustration(r: Rexp, s: String){
Chengsong
parents:
diff changeset
   136
    var i_like_imperative_style = internalise(r)
Chengsong
parents:
diff changeset
   137
    val all_chars = s.toList
Chengsong
parents:
diff changeset
   138
    for (i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   139
      val der_res =  bder(all_chars(i), i_like_imperative_style)
Chengsong
parents:
diff changeset
   140
      val simp_res = bsimp(der_res)
Chengsong
parents:
diff changeset
   141
      println("The original regex, the regex after derivative w.r.t " + all_chars(i) + " and the simplification of the derivative.")
Chengsong
parents:
diff changeset
   142
      println(aregx_tree(i_like_imperative_style) up_align aregx_tree(der_res) up_align aregx_tree(simp_res))
Chengsong
parents:
diff changeset
   143
      //println(asize(i_like_imperative_style), asize(der_res), asize(simp_res))
Chengsong
parents:
diff changeset
   144
      arr_of_size += asize(i_like_imperative_style)
Chengsong
parents:
diff changeset
   145
      //println(asize(simp_res), asize(simp_res) / arr_of_size(0) )
Chengsong
parents:
diff changeset
   146
      i_like_imperative_style = simp_res
Chengsong
parents:
diff changeset
   147
    }
Chengsong
parents:
diff changeset
   148
    arr_of_size += asize(i_like_imperative_style)
Chengsong
parents:
diff changeset
   149
  }
Chengsong
parents:
diff changeset
   150
  val ran = scala.util.Random
Chengsong
parents:
diff changeset
   151
  var alphabet_size = 3
Chengsong
parents:
diff changeset
   152
  def balanced_seq_star_gen(depth: Int, star: Boolean): Rexp = {
Chengsong
parents:
diff changeset
   153
    if(depth == 1){
Chengsong
parents:
diff changeset
   154
      ((ran.nextInt(4) + 97).toChar).toString
Chengsong
parents:
diff changeset
   155
    }
Chengsong
parents:
diff changeset
   156
    else if(star){
Chengsong
parents:
diff changeset
   157
      STAR(balanced_seq_star_gen(depth - 1, false))
Chengsong
parents:
diff changeset
   158
    }
Chengsong
parents:
diff changeset
   159
    else{
Chengsong
parents:
diff changeset
   160
      SEQ(balanced_seq_star_gen(depth - 1, true), balanced_seq_star_gen(depth - 1, true))
Chengsong
parents:
diff changeset
   161
    }
Chengsong
parents:
diff changeset
   162
  }
Chengsong
parents:
diff changeset
   163
  def max(i: Int, j: Int): Int = {
Chengsong
parents:
diff changeset
   164
    if(i > j)
Chengsong
parents:
diff changeset
   165
      i
Chengsong
parents:
diff changeset
   166
    else 
Chengsong
parents:
diff changeset
   167
      j
Chengsong
parents:
diff changeset
   168
  }
Chengsong
parents:
diff changeset
   169
  def random_struct_gen(depth:Int): Rexp = {
Chengsong
parents:
diff changeset
   170
    val dice = ran.nextInt(3)
Chengsong
parents:
diff changeset
   171
    val dice2 = ran.nextInt(3)
Chengsong
parents:
diff changeset
   172
    (dice, depth) match {
Chengsong
parents:
diff changeset
   173
      case (_, 0) => ((ran.nextInt(3) + 97).toChar).toString
Chengsong
parents:
diff changeset
   174
      case (0, i) => STAR(random_struct_gen(max(0, i - 1 - dice2)))
Chengsong
parents:
diff changeset
   175
      case (1, i) => SEQ(random_struct_gen(max(0, i - 1 - dice2)), random_struct_gen(max(0, i - 1 - dice2)))
Chengsong
parents:
diff changeset
   176
      case (2, i) => ALTS( List(random_struct_gen(max(0, i - 1 - dice2)), random_struct_gen(max(0, i - 1 - dice2))) )
Chengsong
parents:
diff changeset
   177
    }
Chengsong
parents:
diff changeset
   178
  }
Chengsong
parents:
diff changeset
   179
  def balanced_struct_gen(depth: Int): Rexp = {
Chengsong
parents:
diff changeset
   180
    val dice = ran.nextInt(3)
Chengsong
parents:
diff changeset
   181
    (dice, depth) match {
Chengsong
parents:
diff changeset
   182
      case (_, 0) => ((ran.nextInt(3) + 97).toChar).toString
Chengsong
parents:
diff changeset
   183
      case (0, i) => STAR(random_struct_gen(depth - 1))
Chengsong
parents:
diff changeset
   184
      case (1, i) => SEQ(random_struct_gen(depth - 1), random_struct_gen(depth - 1))
Chengsong
parents:
diff changeset
   185
      case (2, i) => ALTS( List(random_struct_gen(depth - 1), random_struct_gen(depth - 1) ) )
Chengsong
parents:
diff changeset
   186
    }
Chengsong
parents:
diff changeset
   187
  }
Chengsong
parents:
diff changeset
   188
  def rd_string_gen(alp_size: Int, len: Int): String = {
Chengsong
parents:
diff changeset
   189
    if( len > 0)
Chengsong
parents:
diff changeset
   190
      ((ran.nextInt(alp_size) + 97).toChar).toString + rd_string_gen(alp_size, len - 1)
Chengsong
parents:
diff changeset
   191
    else
Chengsong
parents:
diff changeset
   192
      ((ran.nextInt(alp_size) + 97).toChar).toString
Chengsong
parents:
diff changeset
   193
  }
Chengsong
parents:
diff changeset
   194
  def plot(b: List[Int]){
Chengsong
parents:
diff changeset
   195
    println(b(0),b.max)
Chengsong
parents:
diff changeset
   196
Chengsong
parents:
diff changeset
   197
  }
Chengsong
parents:
diff changeset
   198
  def dep_exp(depth: List[Int]){
Chengsong
parents:
diff changeset
   199
    for(i <- depth){
Chengsong
parents:
diff changeset
   200
      arr_of_size.clear()
Chengsong
parents:
diff changeset
   201
      val s = rd_string_gen(alphabet_size, (i-8)*(i-8)+10)
Chengsong
parents:
diff changeset
   202
      val r = random_struct_gen(i)
Chengsong
parents:
diff changeset
   203
      println("depth: "+i)
Chengsong
parents:
diff changeset
   204
      illustration(r, s) //"abcabadaaadcabdbabcdaadbabbcbbdabdabbcbdbabdbcdb") 
Chengsong
parents:
diff changeset
   205
      //println("depth: " + i + " general stats:"+ arr_of_size(0), arr_of_size.max, arr_of_size.max/arr_of_size(0))
Chengsong
parents:
diff changeset
   206
      //println("x y label alignment")
Chengsong
parents:
diff changeset
   207
      /*for(i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   208
        if(s(i) == '\n')
Chengsong
parents:
diff changeset
   209
          println(i+" "+arr_of_size(i)+" "+"nl"+" -140")
Chengsong
parents:
diff changeset
   210
        else if(s(i) ==  ' ')
Chengsong
parents:
diff changeset
   211
          println(i+" "+arr_of_size(i)+" "+"sp"+" -140")
Chengsong
parents:
diff changeset
   212
        else
Chengsong
parents:
diff changeset
   213
          println(i+" "+arr_of_size(i)+" "+s(i)+" -140")
Chengsong
parents:
diff changeset
   214
      }*/
Chengsong
parents:
diff changeset
   215
      //println(s.length + " " + arr_of_size(s.length) + " ]" + " -140")
Chengsong
parents:
diff changeset
   216
    }
Chengsong
parents:
diff changeset
   217
  }
Chengsong
parents:
diff changeset
   218
  def case_study(ss: List[String], r: Rexp){
Chengsong
parents:
diff changeset
   219
    for(s <- ss){
Chengsong
parents:
diff changeset
   220
      arr_of_size.clear()
Chengsong
parents:
diff changeset
   221
      illustration(r, s)
Chengsong
parents:
diff changeset
   222
      println("x y label alignment")
Chengsong
parents:
diff changeset
   223
      for(i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   224
        if(s(i) == '\n')
Chengsong
parents:
diff changeset
   225
          println(i+" "+arr_of_size(i)+" "+"nl"+" -140")
Chengsong
parents:
diff changeset
   226
        else if(s(i) ==  ' ')
Chengsong
parents:
diff changeset
   227
          println(i+" "+arr_of_size(i)+" "+"sp"+" -140")
Chengsong
parents:
diff changeset
   228
        else
Chengsong
parents:
diff changeset
   229
          println(i+" "+arr_of_size(i)+" "+s(i)+" -140")
Chengsong
parents:
diff changeset
   230
      }
Chengsong
parents:
diff changeset
   231
    }
Chengsong
parents:
diff changeset
   232
  }
Chengsong
parents:
diff changeset
   233
  def star_gen(dp: Int): Rexp = {
Chengsong
parents:
diff changeset
   234
    if(dp > 0)
Chengsong
parents:
diff changeset
   235
      STAR(star_gen(dp - 1))
Chengsong
parents:
diff changeset
   236
    else
Chengsong
parents:
diff changeset
   237
      "a"
Chengsong
parents:
diff changeset
   238
  }
Chengsong
parents:
diff changeset
   239
  def strs_gen(len: Int, num: Int): List[String] = {
Chengsong
parents:
diff changeset
   240
    if(num > 0){
Chengsong
parents:
diff changeset
   241
      rd_string_gen(3, len)::strs_gen(len, num - 1)
Chengsong
parents:
diff changeset
   242
    }
Chengsong
parents:
diff changeset
   243
    else{
Chengsong
parents:
diff changeset
   244
      Nil
Chengsong
parents:
diff changeset
   245
    }
Chengsong
parents:
diff changeset
   246
  }
Chengsong
parents:
diff changeset
   247
  def regx_print(r: Rexp): String = {
Chengsong
parents:
diff changeset
   248
    r match {
Chengsong
parents:
diff changeset
   249
      case ZERO =>
Chengsong
parents:
diff changeset
   250
        "ZERO"
Chengsong
parents:
diff changeset
   251
      case CHAR(c) => {
Chengsong
parents:
diff changeset
   252
         //val Some(c) = alphabet.find(f)
Chengsong
parents:
diff changeset
   253
         "\"" + c.toString + "\""
Chengsong
parents:
diff changeset
   254
      }
Chengsong
parents:
diff changeset
   255
      case ONE => {
Chengsong
parents:
diff changeset
   256
        "ONE"
Chengsong
parents:
diff changeset
   257
      }
Chengsong
parents:
diff changeset
   258
      case ALTS(rs) => {
Chengsong
parents:
diff changeset
   259
        "ALTS(List("+(rs.map(regx_print)).foldLeft("")((a, b) => if(a == "") b else a + "," + b)+"))"
Chengsong
parents:
diff changeset
   260
      }
Chengsong
parents:
diff changeset
   261
      case SEQ(r1, r2) => {
Chengsong
parents:
diff changeset
   262
        "SEQ(" + regx_print(r1) + "," + regx_print(r2) + ")"
Chengsong
parents:
diff changeset
   263
      }
Chengsong
parents:
diff changeset
   264
      case STAR(r) => {
Chengsong
parents:
diff changeset
   265
        "STAR(" + regx_print(r) + ")"
Chengsong
parents:
diff changeset
   266
      }
Chengsong
parents:
diff changeset
   267
    }
Chengsong
parents:
diff changeset
   268
  }
Chengsong
parents:
diff changeset
   269
  val mkst = "abcdefghijklmnopqrstuvwxyz"
Chengsong
parents:
diff changeset
   270
  def weak_sub_check(r: Rexp, s: String, i: Int, f: (List[Rexp], Set[Rexp]) => Boolean){
Chengsong
parents:
diff changeset
   271
    //we first compute pders over the set of all strings on the alphabet
Chengsong
parents:
diff changeset
   272
    val pd = pderas(Set(r), i + 4)
Chengsong
parents:
diff changeset
   273
    //then "b-internalise" the regular expression into a brexp(this is essentially 
Chengsong
parents:
diff changeset
   274
    //attaching a bit Z to every alts to signify that they come from the original regular expression)
Chengsong
parents:
diff changeset
   275
    var old = brternalise(r)
Chengsong
parents:
diff changeset
   276
    //this is for comparison between normal simp and the weakened version of simp
Chengsong
parents:
diff changeset
   277
    //normal simp will be performed on syncold
Chengsong
parents:
diff changeset
   278
    //weakend simp will be performed on old
Chengsong
parents:
diff changeset
   279
    var syncold = brternalise(r)
Chengsong
parents:
diff changeset
   280
    val all_chars = s.toList
Chengsong
parents:
diff changeset
   281
    for (i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   282
      val syncder_res = brder(all_chars(i), syncold)
Chengsong
parents:
diff changeset
   283
      val syncsimp_res = strong_br_simp(syncder_res)
Chengsong
parents:
diff changeset
   284
      //see brder for detailed explanation
Chengsong
parents:
diff changeset
   285
      //just changes bit Z to S when deriving an ALTS, 
Chengsong
parents:
diff changeset
   286
      //signifying that the structure has been "touched" and
Chengsong
parents:
diff changeset
   287
      //therefore able to be spilled in the bspill function
Chengsong
parents:
diff changeset
   288
      val der_res =  brder(all_chars(i), old)
Chengsong
parents:
diff changeset
   289
      val simp_res = br_simp(der_res)
Chengsong
parents:
diff changeset
   290
      val anatomy = bspill(simp_res)
Chengsong
parents:
diff changeset
   291
      //track if the number of regular expressions exceeds those in the PD set(remember PD means the pders over A*)
3
f15dccc42c7b removing PRED
Chengsong
parents: 2
diff changeset
   292
      if(f(anatomy, pd)  == false || i == 1){
0
Chengsong
parents:
diff changeset
   293
        println(size(berase(syncsimp_res)))
Chengsong
parents:
diff changeset
   294
        println(size(berase(simp_res)))
3
f15dccc42c7b removing PRED
Chengsong
parents: 2
diff changeset
   295
        println(bregx_tree(simp_res))
0
Chengsong
parents:
diff changeset
   296
        println(anatomy.map(size).sum)
Chengsong
parents:
diff changeset
   297
        println(pd.map(size).sum)
Chengsong
parents:
diff changeset
   298
      }  
Chengsong
parents:
diff changeset
   299
      old = simp_res
Chengsong
parents:
diff changeset
   300
      syncold = syncsimp_res
Chengsong
parents:
diff changeset
   301
    }
Chengsong
parents:
diff changeset
   302
  }
Chengsong
parents:
diff changeset
   303
  def inclusion_truth(anatomy: List[Rexp], pd: Set[Rexp]): Boolean = {
Chengsong
parents:
diff changeset
   304
    val aset = anatomy.toSet
Chengsong
parents:
diff changeset
   305
    if(aset subsetOf pd){
Chengsong
parents:
diff changeset
   306
      true
Chengsong
parents:
diff changeset
   307
    }
Chengsong
parents:
diff changeset
   308
    else{
Chengsong
parents:
diff changeset
   309
      println("inclusion not true")
Chengsong
parents:
diff changeset
   310
      false
Chengsong
parents:
diff changeset
   311
    }
Chengsong
parents:
diff changeset
   312
  }
Chengsong
parents:
diff changeset
   313
  def size_comp(anatomy: List[Rexp], pd: Set[Rexp]):Boolean = {println("size of PD and bspilled simp regx: ", pd.size, anatomy.size); true}
Chengsong
parents:
diff changeset
   314
  def size_expansion_rate(anatomy: List[Rexp], pd: Set[Rexp]): Boolean = if(anatomy.size > (pd.size)*2 ) {println("size of PD and bspilled simp regx: ", pd.size, anatomy.size); inclusion_truth(anatomy, pd); false }else {true}
Chengsong
parents:
diff changeset
   315
  
Chengsong
parents:
diff changeset
   316
  def check_all(){
Chengsong
parents:
diff changeset
   317
    for(i <- 1 to 1)
Chengsong
parents:
diff changeset
   318
    {
3
f15dccc42c7b removing PRED
Chengsong
parents: 2
diff changeset
   319
        val s = "bb"//rd_string_gen(alphabet_size, 5)//"ac"//rd_string_gen(alphabet_size, 5)
0
Chengsong
parents:
diff changeset
   320
        val r = STAR(STAR(ALTS(List(SEQ(CHAR('b'),CHAR('b')), ALTS(List(CHAR('a'), CHAR('b')))))))//balanced_struct_gen(4)//SEQ(ALTS(List(STAR("a"),ALTS(List("a","c")))),SEQ(ALTS(List("c","a")),ALTS(List("c","b")))) //random_struct_gen(7)
Chengsong
parents:
diff changeset
   321
        //subset_check(r, s)
Chengsong
parents:
diff changeset
   322
        weak_sub_check(r, s, 5, size_expansion_rate)
Chengsong
parents:
diff changeset
   323
    }
Chengsong
parents:
diff changeset
   324
  }
Chengsong
parents:
diff changeset
   325
  def main(args: Array[String]) {
Chengsong
parents:
diff changeset
   326
    check_all()   
Chengsong
parents:
diff changeset
   327
  } 
Chengsong
parents:
diff changeset
   328
}
Chengsong
parents:
diff changeset
   329