-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve dataset structure #175
Merged
SpirinEgor
merged 10 commits into
JetBrains-Research:master-dev
from
illided:dataset_structure
Aug 7, 2021
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d78a3fc
holdout prototype added
illided 122cc1d
tests fixed
illided b8a9eac
code style fixes
illided d5c1e49
little improvements in config and docs
illided 968ad32
Merge branch 'master-dev' into dataset_structure
illided b7eb5f3
conflicts resolved and some refactoring done
illided 175d7a2
code style issues fixed
illided 2e30fcf
spacing around curly
illided de26ca0
small improvements and test fix
illided d30f321
unused import removed
illided File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
package astminer.pipeline | ||
|
||
import astminer.common.getProjectFilesWithExtension | ||
import astminer.common.model.FileLabelExtractor | ||
import astminer.common.model.FunctionLabelExtractor | ||
import astminer.common.model.Storage | ||
import astminer.common.model.* | ||
import astminer.config.FileExtension | ||
import astminer.config.PipelineConfig | ||
import astminer.parse.getParsingResultFactory | ||
import astminer.pipeline.branch.FilePipelineBranch | ||
import astminer.pipeline.branch.FunctionPipelineBranch | ||
import astminer.pipeline.branch.IllegalLabelExtractorException | ||
import me.tongfei.progressbar.ProgressBar | ||
import java.io.Closeable | ||
import java.io.File | ||
|
||
/** | ||
|
@@ -24,6 +23,9 @@ class Pipeline(private val config: PipelineConfig) { | |
private val filters = config.filters.map { it.filterImpl } | ||
private val labelExtractor = config.labelExtractor.labelExtractorImpl | ||
|
||
private val holdoutMap = findDatasetHoldouts(inputDirectory) | ||
private val isDataset = holdoutMap.size > 1 | ||
|
||
private val branch = when (labelExtractor) { | ||
is FileLabelExtractor -> FilePipelineBranch(filters, labelExtractor) | ||
is FunctionLabelExtractor -> FunctionPipelineBranch(filters, labelExtractor) | ||
|
@@ -41,32 +43,45 @@ class Pipeline(private val config: PipelineConfig) { | |
return config.storage.createStorage(storagePath) | ||
} | ||
|
||
private fun <T : Closeable, R> T.useSynchronously(callback: (T) -> R) = | ||
this.use { | ||
synchronized(this) { | ||
callback(this) | ||
} | ||
} | ||
|
||
private fun parseLanguage(language: FileExtension) { | ||
val parsingResultFactory = getParsingResultFactory(language, config.parser.name) | ||
createStorage(language).useSynchronously { storage -> | ||
for ((holdoutType, holdoutDir) in holdoutMap) { | ||
val holdoutFiles = getProjectFilesWithExtension(holdoutDir, language.fileExtension) | ||
printHoldoutStat(holdoutFiles, holdoutType) | ||
val progressBar = ProgressBar("", holdoutFiles.size.toLong()) | ||
parsingResultFactory.parseFilesInThreads(holdoutFiles, config.numOfThreads) { parseResult -> | ||
val labeledResults = branch.process(parseResult) | ||
storage.store(labeledResults, holdoutType) | ||
progressBar.step() | ||
} | ||
progressBar.close() | ||
} | ||
} | ||
} | ||
|
||
private fun printHoldoutStat(files: List<File>, holdoutType: DatasetHoldout) { | ||
var output = "${files.size} file(s) found" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use StringBuilder for manipulation with strings to avoid using mutable strings |
||
if (isDataset) { output += " in ${holdoutType.name}" } | ||
println(output) | ||
} | ||
|
||
/** | ||
* Runs the pipeline that is defined in the [config]. | ||
*/ | ||
fun run() { | ||
println("Working in ${config.numOfThreads} thread(s)") | ||
if (isDataset) { println("Dataset structure found") } | ||
for (language in config.parser.languages) { | ||
println("Parsing $language") | ||
val parsingResultFactory = getParsingResultFactory(language, config.parser.name) | ||
|
||
println("Collecting files...") | ||
val files = getProjectFilesWithExtension(inputDirectory, language.fileExtension) | ||
println("${files.size} files retrieved") | ||
|
||
val progressBar = ProgressBar("", files.size.toLong()) | ||
|
||
createStorage(language).use { storage -> | ||
synchronized(storage) { | ||
parsingResultFactory.parseFilesInThreads(files, config.numOfThreads) { parseResult -> | ||
for (labeledResult in branch.process(parseResult)) { | ||
storage.store(labeledResult) | ||
} | ||
progressBar.step() | ||
} | ||
} | ||
} | ||
progressBar.close() | ||
parseLanguage(language) | ||
} | ||
println("Done!") | ||
} | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks complicated ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add in storage interface
syncronizedStore
: