Within a project, we might want to see the in-between file or in-between class dependencies. This notebook showcases how to obtain either dependencies using Scitool's Understand). Note you will need a license from Scitools to use this Notebook.
rm(list = ls()) require(kaiaulu) require(visNetwork) require(XML) require(stringi) require(igraph) require(data.table) require(gt)
For this notebook, we will use Apache Helix as an example. Refer to Helix project configuration file under the conf/ folder, in particular the understand
section. For supported languages, see scitools documentation.
tool <- parse_config("../tools.yml") scitools_path <- get_tool_project("scitools", tool) conf <- parse_config("../conf/helix.yml") keep_dependencies_type <- get_understand_keep_dependencies_type(conf) project_path <- get_understand_project_path(conf) # Scitools understand_folder <- get_understand_output_path(conf) code_language <- get_understand_code_language(conf) db_path <- stringi::stri_c(understand_folder,"Understand.und") file_dependencies_path <- stringi::stri_c(understand_folder,"file_dependencies.xml") class_dependencies_path <- stringi::stri_c(understand_folder,"class_dependencies.xml")
To export dependencies, scitools require a und
database to be created:
db_path <- build_understand_project(scitools_path = scitools_path, project_path = project_path, language = code_language, output_dir = understand_folder)
Subsequently, we can make our dependencies export out of the database. We can either export XML files or class dependencies.
file_dependencies_path <- export_understand_dependencies(scitools_path = scitools_path, db_filepath = db_path, parse_type = "file", output_filepath = file_dependencies_path)
The XML files can then be parsed into tables for manipulation in Kaiaulu:
file_dependencies <- parse_understand_dependencies(dependencies_path = file_dependencies_path) head(file_dependencies[["node_list"]]) %>% gt(auto_align = FALSE)
head(file_dependencies[["edge_list"]]) %>% gt(auto_align = FALSE)
The process to export and parse class dependencies is identical, save for specifying the parse_type
to "class":
class_dependencies_path <- export_understand_dependencies(scitools_path = scitools_path, db_filepath = db_path, parse_type = "class", output_filepath = class_dependencies_path)
class_dependencies <- parse_understand_dependencies(dependencies_path = class_dependencies_path) head(class_dependencies[["node_list"]]) %>% gt(auto_align = FALSE)
head(class_dependencies[["edge_list"]]) %>% gt(auto_align = FALSE)
We can display the parsed dependencies as a network. You can use the dependency_kind parameter to subset the dependencies used. Refer to Kaiaulu wiki for the types of dependencies Scitools support.
file_graph <- transform_understand_dependencies_to_network(parsed = file_dependencies, weight_types = c(keep_dependencies_type[2], keep_dependencies_type[5])) project_function_network <- igraph::graph_from_data_frame(d=file_graph[["edge_list"]], directed = TRUE, vertices = file_graph[["node_list"]]) visIgraph(project_function_network,randomSeed = 1)
The same applies to outputting our class_dependencies, but we can visualize what our class dependency data is using the same parameters sans the parsed data table.
class_graph <- transform_understand_dependencies_to_network(parsed = class_dependencies, weight_types = c(keep_dependencies_type[2], keep_dependencies_type[5])) project_function_network <- igraph::graph_from_data_frame(d=class_graph[["edge_list"]], directed = TRUE, vertices = class_graph[["node_list"]]) visIgraph(project_function_network,randomSeed = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.