25 else |
24 else |
26 (verticalBar above corner) beside (space above sp) |
25 (verticalBar above corner) beside (space above sp) |
27 } |
26 } |
28 } |
27 } |
29 val alphabet = ("""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:"=()\;-+*!<>\/%{} """+"\n\t").toSet//Set('a','b','c') |
28 val alphabet = ("""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:"=()\;-+*!<>\/%{} """+"\n\t").toSet//Set('a','b','c') |
30 def bregx_tree(r: BRexp): Element = regx_tree(berase(r)) |
|
31 def regx_tree(r: Rexp): Element = aregx_tree(internalise(r)) |
29 def regx_tree(r: Rexp): Element = aregx_tree(internalise(r)) |
32 def annotated_tree(r: ARexp): Element = { |
30 def annotated_tree(r: ARexp): Element = { |
33 r match { |
31 r match { |
34 case ACHAR(bs, d) => { |
32 case ACHAR(bs, d) => { |
35 //val Some(d) = alphabet.find(f) |
33 //val Some(d) = alphabet.find(f) |
369 "STAR(" + regx_print(r) + ")" |
367 "STAR(" + regx_print(r) + ")" |
370 } |
368 } |
371 } |
369 } |
372 } |
370 } |
373 val mkst = "abcdefghijklmnopqrstuvwxyz" |
371 val mkst = "abcdefghijklmnopqrstuvwxyz" |
374 def weak_sub_check(r: Rexp, s: String, i: Int, f: (List[Rexp], Set[Rexp]) => Boolean){ |
372 |
375 //we first compute pders over the set of all strings on the alphabet |
|
376 val pd = pderas(Set(r), i + 4) |
|
377 //then "b-internalise" the regular expression into a brexp(this is essentially |
|
378 //attaching a bit Z to every alts to signify that they come from the original regular expression) |
|
379 var old = brternalise(r) |
|
380 //this is for comparison between normal simp and the weakened version of simp |
|
381 //normal simp will be performed on syncold |
|
382 //weakend simp will be performed on old |
|
383 var syncold = internalise(r) |
|
384 val all_chars = s.toList |
|
385 for (i <- 0 to s.length - 1){ |
|
386 val syncder_res = bder(all_chars(i), syncold) |
|
387 val syncsimp_res = super_bsimp(syncder_res) |
|
388 //see brder for detailed explanation |
|
389 //just changes bit Z to S when deriving an ALTS, |
|
390 //signifying that the structure has been "touched" and |
|
391 //therefore able to be spilled in the bspill function |
|
392 val der_res = brder(all_chars(i), old) |
|
393 val simp_res = br_simp(der_res) |
|
394 val anatomy = bspill(simp_res) |
|
395 //track if the number of regular expressions exceeds those in the PD set(remember PD means the pders over A*) |
|
396 if(f(List(berase(simp_res)), pd) == false ){ |
|
397 println(size(erase(syncsimp_res))) |
|
398 println(size(berase(simp_res))) |
|
399 println(bregx_tree(simp_res)) |
|
400 println(s) |
|
401 println(i) |
|
402 println(r) |
|
403 println(anatomy.map(size).sum) |
|
404 println(pd.map(size).sum) |
|
405 } |
|
406 old = simp_res |
|
407 syncold = syncsimp_res |
|
408 } |
|
409 } |
|
410 def inclusion_truth(anatomy: List[Rexp], pd: Set[Rexp]): Boolean = { |
373 def inclusion_truth(anatomy: List[Rexp], pd: Set[Rexp]): Boolean = { |
411 val aset = anatomy.toSet |
374 val aset = anatomy.toSet |
412 if(aset subsetOf pd){ |
375 if(aset subsetOf pd){ |
413 true |
376 true |
414 } |
377 } |
425 case c::cs => ders_simp(bsimp(bder(c, r)), cs) |
388 case c::cs => ders_simp(bsimp(bder(c, r)), cs) |
426 } |
389 } |
427 } |
390 } |
428 val big_panda = STAR(STAR(STAR(ALTS(List(ALTS(List(CHAR('c'), CHAR('b'))), SEQ(CHAR('c'),CHAR('c'))))))) |
391 val big_panda = STAR(STAR(STAR(ALTS(List(ALTS(List(CHAR('c'), CHAR('b'))), SEQ(CHAR('c'),CHAR('c'))))))) |
429 val str_panda = "ccccb" |
392 val str_panda = "ccccb" |
430 def check_all(){ |
393 |
431 |
|
432 weak_sub_check(big_panda, str_panda, 6, size_expansion_rate) |
|
433 |
|
434 } |
|
435 def bstostick(bs: List[Bit]): Element = bs match { |
394 def bstostick(bs: List[Bit]): Element = bs match { |
436 //case b::Nil => elem(b.toString) |
395 //case b::Nil => elem(b.toString) |
437 case b::bs1 => elem(b.toString) beside bstostick(bs1) |
396 case b::bs1 => elem(b.toString) beside bstostick(bs1) |
438 case Nil => elem(' ', 1, 1) |
397 case Nil => elem(' ', 1, 1) |
439 } |
398 } |