Reputation: 1331
I'm working with StanfordNLP to extract data from a parsed Tree.
I'm using Scala for coding.
val tp = TregexPattern.compile("SOME_PATTERN")
val res = tp.matcher("SOME_TREE")
to read the results of this I use
while (res.find()) {
println(res.getMatch.getLeaves.mkString(" "))
}
I want to rewrite this while-loop in for-loop.
Upvotes: 0
Views: 147
Reputation: 18859
How about this:
val tp = TregexPattern.compile("SOME_PATTERN")
val res = tp.matcher("SOME_TREE")
for(it <- Iterator.continually(res.getMatch).takeWhile(_ => res.find)) {
println(it.getLeaves.mkString(" "))
}
Upvotes: 1