-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i #314 Added exec/annotate.R and exec/query.R
- annotate.R generates the XML file - query.R calls the query functions, depending on options Note: may have to revisit output format after getting into the fasttext notebook Signed-off-by: Dao McGill <[email protected]>
- Loading branch information
Showing
2 changed files
with
77 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/local/bin/Rscript | ||
|
||
require(yaml, quietly = TRUE) | ||
require(cli, quietly = TRUE) | ||
require(docopt, quietly = TRUE) | ||
require(kaiaulu, quietly = TRUE) | ||
require(data.table, quietly = TRUE) | ||
require(stringi, quietly = TRUE) | ||
require(XML, quietly = TRUE) | ||
|
||
doc <- " | ||
USAGE: | ||
query.R query <tools.yml> <project_conf.yml> <srcml_filepath> [--namespace | --file-docs | --class-docs | --variables | --packages | --functions | --imports] | ||
DESCRIPTION: | ||
Runs a specified query on the annotated XML file and saves the output to the appropriate path. | ||
OPTIONS: | ||
--namespace Run the namespace query. | ||
--file-docs Run the file-level documentation query. | ||
--class-docs Run the class-level documentation query. | ||
--variables Run the variables query. | ||
--packages Run the packages query. | ||
--functions Run the functions query. | ||
--imports Run the imports query. | ||
" | ||
|
||
arguments <- docopt::docopt(doc, version = 'Kaiaulu 0.0.0.9600') | ||
|
||
tools_path <- arguments[["<tools.yml>"]] | ||
conf_path <- arguments[["<project_conf.yml>"]] | ||
srcml_filepath <- arguments[["<srcml_filepath>"]] | ||
|
||
tool <- yaml::read_yaml(tools_path) | ||
conf <- yaml::read_yaml(conf_path) | ||
srcml_path <- path.expand(tool[["srcml"]]) | ||
|
||
# Set output folder path | ||
output_folder <- "../../analysis/maven/queries" | ||
if (!dir.exists(output_folder)) { | ||
dir.create(output_folder, recursive = TRUE) | ||
} | ||
|
||
# Determine which query to run and save output | ||
if (arguments[["--namespace"]]) { | ||
output_file <- file.path(output_folder, "namespace_output.csv") | ||
query_result <- query_src_text_namespace(srcml_path, srcml_filepath) | ||
} else if (arguments[["--file-docs"]]) { | ||
output_file <- file.path(output_folder, "file_docs_output.csv") | ||
query_result <- query_src_text_file_docs(srcml_path, srcml_filepath) | ||
} else if (arguments[["--class-docs"]]) { | ||
output_file <- file.path(output_folder, "class_docs_output.csv") | ||
query_result <- query_src_text_class_docs(srcml_path, srcml_filepath) | ||
} else if (arguments[["--variables"]]) { | ||
output_file <- file.path(output_folder, "variables_output.csv") | ||
query_result <- query_src_text_variables(srcml_path, srcml_filepath) | ||
} else if (arguments[["--packages"]]) { | ||
output_file <- file.path(output_folder, "packages_output.csv") | ||
query_result <- query_src_text_packages(srcml_path, srcml_filepath) | ||
} else if (arguments[["--functions"]]) { | ||
output_file <- file.path(output_folder, "functions_output.csv") | ||
query_result <- query_src_text_functions(srcml_path, srcml_filepath) | ||
} else if (arguments[["--imports"]]) { | ||
output_file <- file.path(output_folder, "imports_output.csv") | ||
query_result <- query_src_text_imports(srcml_path, srcml_filepath) | ||
} else { | ||
stop("No valid query option provided.") | ||
} | ||
|
||
# Transform each row into a single line of text | ||
plain_text_output <- apply(query_result, 1, function(row) paste(row, collapse = " ")) | ||
|
||
# Save to file | ||
writeLines(plain_text_output, output_file) | ||
cli_alert_success(paste0("Query results saved for fastText at: ", output_file)) | ||
|