-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from JetBrains-Research/code2seq_meta
Code2seq metadata
- Loading branch information
Showing
12 changed files
with
252 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package astminer.storage | ||
|
||
import astminer.common.model.* | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import java.io.PrintWriter | ||
import kotlin.io.path.Path | ||
|
||
@Serializable | ||
data class TreeMetaData(val label: String, val path: String, val range: NodeRange?) { | ||
constructor(labeledResult: LabeledResult<out Node>) : this( | ||
labeledResult.label, | ||
labeledResult.filePath, | ||
labeledResult.root.range | ||
) | ||
} | ||
|
||
class MetaDataStorage(override val outputDirectoryPath: String) : Storage { | ||
private val metadataWriters = mutableMapOf<DatasetHoldout, PrintWriter>() | ||
|
||
private fun DatasetHoldout.resolveHoldout(): PrintWriter { | ||
val newOutputFile = this.createDir(Path(outputDirectoryPath)).resolve(METADATA_FILENAME) | ||
newOutputFile.createNewFile() | ||
return PrintWriter(newOutputFile.outputStream(), true) | ||
} | ||
|
||
private fun PrintWriter.writeMetadata(labeledResult: LabeledResult<out Node>) { | ||
this.println(Json.encodeToString(TreeMetaData(labeledResult))) | ||
} | ||
|
||
override fun store(labeledResult: LabeledResult<out Node>, holdout: DatasetHoldout) { | ||
val writer = metadataWriters.getOrPut(holdout) { holdout.resolveHoldout() } | ||
writer.writeMetadata(labeledResult) | ||
} | ||
|
||
override fun close() { | ||
metadataWriters.values.forEach { it.close() } | ||
} | ||
|
||
companion object { | ||
const val METADATA_FILENAME = "metadata.jsonl" | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.