Created
March 19, 2013 20:25
-
-
Save jimregan/5199780 to your computer and use it in GitHub Desktop.
Translation iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalac transiter.scala | |
scala TranslationIterator input.txt > output.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^test/test<n><sg>/test<vblex><pri><p3><sg>$ ^file/file<n><sg>/file<vblex><pri><p3><sg>$ | |
^test/test<n><sg>/test<vblex><pri><p3><sg>$ ^file/file<n><sg>/file<vblex><pri><p3><sg>$ ^test/test<n><sg>/test<vblex><pri><p3><sg>$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1.0]^test<n><sg>$ ^file<n><sg>$ | |
[1.1]^test<n><sg>$ ^file<vblex><pri><p3><sg>$ | |
[1.2]^test<vblex><pri><p3><sg>$ ^file<n><sg>$ | |
[1.3]^test<vblex><pri><p3><sg>$ ^file<vblex><pri><p3><sg>$ | |
[2.0]^test<n><sg>$ ^file<n><sg>$ ^test<n><sg>$ | |
[2.1]^test<n><sg>$ ^file<n><sg>$ ^test<vblex><pri><p3><sg>$ | |
[2.2]^test<n><sg>$ ^file<vblex><pri><p3><sg>$ ^test<n><sg>$ | |
[2.3]^test<n><sg>$ ^file<vblex><pri><p3><sg>$ ^test<vblex><pri><p3><sg>$ | |
[2.4]^test<vblex><pri><p3><sg>$ ^file<n><sg>$ ^test<n><sg>$ | |
[2.5]^test<vblex><pri><p3><sg>$ ^file<n><sg>$ ^test<vblex><pri><p3><sg>$ | |
[2.6]^test<vblex><pri><p3><sg>$ ^file<vblex><pri><p3><sg>$ ^test<n><sg>$ | |
[2.7]^test<vblex><pri><p3><sg>$ ^file<vblex><pri><p3><sg>$ ^test<vblex><pri><p3><sg>$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TranslationIterator { | |
def wrap(s: String): String = "^" + s + "$" | |
def cart(l: List[List[String]]): List[List[String]] = l match { | |
case Nil => List(Nil) | |
case h :: t => for(e <- h; rest <- cart(t)) yield e :: rest | |
} | |
def splitter(s: String) = s.split("\\/").toList.filter{_.contains("<") } | |
def main(args: Array[String]) { | |
val lines = io.Source.fromFile(args(0)).getLines.toList | |
var counter = 1 | |
for(line <- lines) { | |
val words = line.split("\\$|\\^").filter{ _ contains("/") } | |
val list = words.toList.map{splitter} | |
val joined = cart(list) | |
for ((e, n) <- joined.zipWithIndex) { | |
println("[" + counter + "." + n + "]" + e.map{wrap}.mkString(" ")) | |
} | |
counter += 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment