Snippets are short pieces of code that might come from different public sources such as GitHub, GitLab or Stack Overflow. The snippet match percentage is a key metric in Software Composition Analysis (SCA) that indicates how much of your scanned file matches known open source code in the knowledge base.
The match percentage is calculated using the following formula:Matched Percentage = (Matched Snippet Lines / Total File Lines) × 100Example Calculation:Consider a file with the following characteristics:
Total file lines: 2,557
Matched snippet lines: 2,335
The snippet match percentage would be:(2,335 ÷ 2,557) × 100 = 91%This means that SCANOSS was able to match 91% of the scanned file against known open source code in the knowledge base.
After scanning, the results are stored in a results.json file. Within this file, each matched snippet includes a lines field that specifies the range of lines matched in the original file.For example:"lines": "36-1082"This indicates that lines 36 through 1082 of the file were matched against open source components in the SCANOSS knowledge base.To calculate the total number of matched lines for this snippet:Matched Snippet Lines = End Line - Start Line + 1
The +1 is required because the range is inclusive of both the start and end lines. In the example above:
Example calculation:1082 - 36 + 1 = 1047 Matched LinesThese matched lines are then used to calculate the match percentage:Matched Percentage = (1047/1083) × 100 = 96%Snippet match percentages help you assess how much of your code aligns with known open source.