Core Functions

This page defines all boilerplate functions to be used when analyzing sboms. To see these functions in action please view the following pages.

Many of the queries seen on this page were written with the help of ChatGPT. To repeat this simply prompt ChatGPT as follows: Write me a SPARQL query to select X, Y, and Z

Basic Queries

These functions perform basic queries and return metadata about a given knowledge graph


source

show_metadata

 show_metadata (kg:kglab.kglab.KnowledgeGraph, dataframe:bool=False)

Return total number of triples, distict entities, and properties to a pandas dataframe.

Type Default Details
kg KnowledgeGraph Knowledge graph to query from
dataframe bool False Optionally, return result to dataframe

source

show_entity_types

 show_entity_types (kg:kglab.kglab.KnowledgeGraph, dataframe:bool=False)

Show counts of entity types

Type Default Details
kg KnowledgeGraph Knowledge graph to query from
dataframe bool False Optionally, return result to dataframe

source

show_top_n_props

 show_top_n_props (kg:kglab.kglab.KnowledgeGraph, n:int=10,
                   dataframe:bool=False)

Display the top N properties from a knowledge graph

Type Default Details
kg KnowledgeGraph Knowledge graph to query from
n int 10 Top n results to display
dataframe bool False Optionally, return result to dataframe

source

show_measures

 show_measures (kg:kglab.kglab.KnowledgeGraph)

Display number of nodes and edges for knowledge graph

Type Details
kg KnowledgeGraph Knowledge graph to query from

Files

These functions peform queries on a SBOM’s files


source

file_schema

 file_schema (kg:kglab.kglab.KnowledgeGraph)

Display all properties for a file

Type Details
kg KnowledgeGraph Knowledge graph to query from

source

get_files_data

 get_files_data (kg:kglab.kglab.KnowledgeGraph)

Return all files and their properties

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns DataFrame Return result to dataframe

source

get_files_graph

 get_files_graph (kg:kglab.kglab.KnowledgeGraph)

Return a subgraph of the files and their properties

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns KnowledgeGraph Return result to knowledge graph

Packages


source

package_schema

 package_schema (kg:kglab.kglab.KnowledgeGraph)

Return the schema for the package

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns DataFrame Return result to dataframe

source

get_package_data

 get_package_data (kg:kglab.kglab.KnowledgeGraph)

Construct a dataframe of package data

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns DataFrame Return result to dataframe

source

get_package_graph

 get_package_graph (kg:kglab.kglab.KnowledgeGraph)

Construct a subgraph of the package data

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns KnowledgeGraph Return result to knowledge graph

Relationships


source

relationship_schema

 relationship_schema (kg:kglab.kglab.KnowledgeGraph)

Return the schema for the relationships

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns DataFrame Return result to dataframe

source

get_relationship_data

 get_relationship_data (kg:kglab.kglab.KnowledgeGraph)
Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns DataFrame Return result to dataframe

source

get_relationship_graph

 get_relationship_graph (kg:kglab.kglab.KnowledgeGraph)

Construct a subgraph of the relationship data

Type Details
kg KnowledgeGraph Knowledge graph to query from
Returns KnowledgeGraph Return result to knowledge graph

Quality Metrics


source

sbomqs_scores

 sbomqs_scores (sbomqs_dir:str)

Create DataFrame with quality scores for the SBOM generation tools.

Type Details
sbomqs_dir str Directory for the json files generated by the sbomqs tool
Returns typing.Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame] Return two DataFrames, one with the information about each file in sbomqs_dir and another with scores for each feature in the SBOM quality categories for all files

source

sbomqs_score_by_cat

 sbomqs_score_by_cat (feature_qscores:pandas.core.frame.DataFrame)

Create a DataFrame with the average score by category for each SBOM generation tool

Type Details
feature_qscores DataFrame It is a DataFrame with the quality scores for each feature in each category for all tools.
Returns DataFrame Return a DataFrame with the average scores by categories for the SBOM generation tools.

Visualization

Functions to visualize graph results


source

visualize_graph

 visualize_graph (kg:kglab.kglab.KnowledgeGraph, VIS_STYLE:str={})

Visualize the knowledge graph

Type Default Details
kg KnowledgeGraph Knowledge graph to query from
VIS_STYLE str {} Optional, visualization style

source

visualize_relationship_graph

 visualize_relationship_graph (kg:kglab.kglab.KnowledgeGraph,
                               hideTypeFile:str=False)

Construct a Network object for representing the SBOMs components relationship graph. The returned graph is ready to be visualized using .show().

Type Default Details
kg KnowledgeGraph Knowledge graph to query from
hideTypeFile str False Flag for showing SPDX:File type components in the graph
Returns Network Return a Network object representing the SBOMs relationship graph

source

display_relationship_graph_legend

 display_relationship_graph_legend ()

Display the legend of the SBOMs components relationship graph that can be visualized by visualize_relationship_graph().

display_relationship_graph_legend()
SPDX Type Node Color
0 File Yellow
1 Package Blue
2 SPDXDocument Red

source

display_qscores_with_descriptions

 display_qscores_with_descriptions
                                    (feature_qscores:pandas.core.frame.Dat
                                    aFrame, category_list:list=None,
                                    tool_list:list=None)
Type Default Details
feature_qscores DataFrame DataFrame with the quality scores for each feature in each category for all tools.
category_list list None List of categories to be displayed. If None, all categories are displayed.
tool_list list None List of tools to be displayed. If None, all tools are displayed.
Returns None

source

display_category_qscores_heatmap

 display_category_qscores_heatmap
                                   (feature_qscores:pandas.core.frame.Data
                                   Frame, category_list:list=None)

This function displays a heatmap for each SBOM quality category showing scores by tools for each category feature.

Type Default Details
feature_qscores DataFrame DataFrame with the quality scores for each feature in each category for all tools.
category_list list None List of categories to be displayed. If None, all categories are displayed.
Returns None

source

display_qscores_heatmap

 display_qscores_heatmap (feature_qscores)

This function display a heatmap showing scores by tools for each SBOM quality category.

Type Details
feature_qscores DataFrame with the quality scores for each feature in each category for all tools.
Returns None

source

sbomqs_radar_chart

 sbomqs_radar_chart (feature_qscores)

Construct a radar chart for the quality scores of the SBOMs categories for each tool.

Type Details
feature_qscores DataFrame with the quality scores for each feature in each category for all tools.
Returns None