Skip to content

Commit

Permalink
seq2parse comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jun 16, 2023
1 parent 1abc4ac commit bbbd668
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import edu.mcgill.cstk.utils.*
import org.apache.datasketches.frequencies.ErrorType
import org.kosat.round
import java.io.*
import java.net.URL
import java.net.*
import java.util.regex.Pattern
import kotlin.math.*
import kotlin.streams.asStream
Expand Down Expand Up @@ -72,7 +72,6 @@ fun stackOverflowEval() {
readContents("parse_errors.json") to
readContents("parse_fixes.json")

TIMEOUT_MS = 60_000
val deck = P_stackoverflow.topK(200).map { it.first }.toSet() + "ε"
println("Deck size: $deck")

Expand Down Expand Up @@ -153,11 +152,39 @@ fun stackOverflowEval() {
"#" + repairs.indexOfFirst { it.result == coarseFixedStr }
println("Minimized repair was $minRepairState in repair proposals!")

compareSeq2ParseFix(humanError, coarseFixedStr, repairs)

updateRankingStats(repairs, coarseFixedStr, timedMRR, timedPAK, samplesEvaluated++)
}
}
}

private fun compareSeq2ParseFix(
humanError: Σᐩ,
coarseBrokeStr: String,
ourRepairs: List<Repair>
) {
val seq2parseFix = seq2parseFix(humanError)
val parseable = seq2parseFix.isValidPython()
val seq2parseFixCoarse =
seq2parseFix.lexToStrTypesAsPython().joinToString(" ", "", " NEWLINE")

val idx = ourRepairs.indexOfFirst { it.result == seq2parseFixCoarse }
println(
"seq2parse fix (parseable=$parseable, idx=$idx):" +
prettyDiffNoFrills(coarseBrokeStr, seq2parseFixCoarse)
)
println("seq2parse fix (parseable=$parseable) is the same as the coarse fix!")
}

fun seq2parseFix(
brokenCode: String,
prefix: String = "http://127.0.0.1:5000/api/text?seq2parse="
) =
try {
URL("$prefix${URLEncoder.encode(brokenCode,"UTF-8")}").readText()
} catch (e: Exception) { "ERROR (${e.message}):\n$brokenCode" }

private fun updateRankingStats(
repairs: List<Repair>,
coarseFixedStr: String,
Expand Down

0 comments on commit bbbd668

Please sign in to comment.