-
Notifications
You must be signed in to change notification settings - Fork 0
AnalysisResult Class
Represents the result of an analysis, including the set of definitions and their associated metadata such as file extensions and MIME types.
Namespace: Rheo.Storage.Analyzing.Models.Result
Assembly: Rheo.Storage.dll
public class AnalysisResult| Property | Type | Description |
|---|---|---|
| IsEmpty | Boolean | Gets a value indicating whether the result contains no definitions. |
| Definitions | ConfidenceStack<Definition> | Gets the collection of definitions along with their associated confidence scores. |
| Extensions | ConfidenceStack<String> | Gets a stack containing all unique file extensions defined in the current set of definitions. |
| MimeTypes | ConfidenceStack<String> | Gets a stack of unique MIME types defined in the current set of definitions. |
Use this class to access the analyzed definitions along with their unique file extensions and MIME types. The properties provide convenient access to distinct metadata derived from the underlying definitions. The collections exposed by this class are read-only after initialization.
The AnalysisResult is typically returned by the FileAnalyzer class after analyzing a file or stream. It provides confidence-scored results, allowing you to determine the most likely file type.
Gets a value indicating whether the result contains no definitions.
public bool IsEmpty { get; }true if the result contains no definitions; otherwise, false.
This property is useful for quickly checking whether the file analysis produced any matches before attempting to access the definitions.
Gets the collection of definitions along with their associated confidence scores.
public ConfidenceStack<Definition> Definitions { get; init; }A confidence stack containing all matched definitions, ordered by confidence score.
Use this property to access all available definitions, each paired with a confidence value indicating the reliability or relevance of the definition. The collection is read-only after initialization.
The definitions are automatically sorted by confidence score in descending order, with the most confident match first.
Gets a stack containing all unique file extensions defined in the current set of definitions.
public ConfidenceStack<string> Extensions { get; }A confidence stack of unique file extensions.
The returned stack includes each extension only once, regardless of how many definitions reference it. The order of extensions in the stack reflects the order in which they are encountered when enumerating the definitions.
This property is computed dynamically each time it is accessed by extracting extensions from all definitions in the result.
Gets a stack of unique MIME types defined in the current set of definitions.
public ConfidenceStack<string> MimeTypes { get; }A confidence stack of unique MIME types.
The returned stack contains one entry for each distinct MIME type present in the definitions, with the most recently added types on top. The order of MIME types in the stack reflects the order in which they are encountered during enumeration.
This property is computed dynamically each time it is accessed.
The following example demonstrates how to analyze a file and work with the results:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\image.png";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
if (!result.IsEmpty)
{
// Get the most confident match
var topMatch = result.Definitions.Peek();
Console.WriteLine($"File Type: {topMatch.Subject.FileType}");
Console.WriteLine($"Confidence: {topMatch.Value:F2}%");
Console.WriteLine($"MIME Type: {topMatch.Subject.MimeType}");
}
else
{
Console.WriteLine("No file type could be determined.");
}The following example shows how to display all matched definitions with their confidence scores:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\file.dat";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
Console.WriteLine($"Found {result.Definitions.Count} possible file types:");
foreach (var confidence in result.Definitions)
{
Console.WriteLine($" {confidence.Subject.FileType}: {confidence.Value:F2}%");
}The following example demonstrates how to access unique extensions and MIME types:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\archive.zip";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
// Display possible extensions
Console.WriteLine("Possible extensions:");
foreach (var ext in result.Extensions)
{
Console.WriteLine($" {ext.Subject}");
}
// Display possible MIME types
Console.WriteLine("\nPossible MIME types:");
foreach (var mime in result.MimeTypes)
{
Console.WriteLine($" {mime.Subject}");
}The following example shows how to handle cases where no match is found:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\unknown.bin";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
if (result.IsEmpty)
{
Console.WriteLine("Unable to identify file type.");
}
else
{
var topMatch = result.Definitions.Peek();
if (topMatch.Value < 50.0)
{
Console.WriteLine($"Low confidence match: {topMatch.Subject.FileType} ({topMatch.Value:F2}%)");
Console.WriteLine("Manual verification recommended.");
}
else
{
Console.WriteLine($"High confidence match: {topMatch.Subject.FileType} ({topMatch.Value:F2}%)");
}
}The following example demonstrates how to filter results by confidence score:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\file.bin";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
const double confidenceThreshold = 60.0;
var highConfidenceMatches = result.Definitions
.Where(c => c.Value >= confidenceThreshold)
.ToList();
if (highConfidenceMatches.Any())
{
Console.WriteLine($"High confidence matches (>= {confidenceThreshold}%):");
foreach (var match in highConfidenceMatches)
{
Console.WriteLine($" {match.Subject.FileType}: {match.Value:F2}%");
}
}
else
{
Console.WriteLine($"No matches with confidence >= {confidenceThreshold}%");
}This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress