Magic operation now shows matching ops even if they are not run.
This commit is contained in:
parent
6624f25a64
commit
23bdfd04a2
@ -277,7 +277,7 @@ const FlowControl = {
|
|||||||
style='table-layout: fixed;'>
|
style='table-layout: fixed;'>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Recipe (click to load)</th>
|
<th>Recipe (click to load)</th>
|
||||||
<th>Data snippet</th>
|
<th>Result snippet</th>
|
||||||
<th>Properties</th>
|
<th>Properties</th>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
@ -290,24 +290,27 @@ const FlowControl = {
|
|||||||
recipeURL = "recipe=" + Utils.encodeURIFragment(Utils.generatePrettyRecipe(recipeConfig));
|
recipeURL = "recipe=" + Utils.encodeURIFragment(Utils.generatePrettyRecipe(recipeConfig));
|
||||||
|
|
||||||
const bestLanguage = option.languageScores[0];
|
const bestLanguage = option.languageScores[0];
|
||||||
let language = "Unknown",
|
let language = "",
|
||||||
fileType = "Unknown";
|
fileType = "",
|
||||||
|
matchingOps = "",
|
||||||
|
validUTF8 = option.isUTF8 ? "Valid UTF8\n" : "";
|
||||||
|
|
||||||
if (bestLanguage.probability > 0.00005) {
|
if (bestLanguage.probability > 0.00001) {
|
||||||
language = Magic.codeToLanguage(bestLanguage.lang) + " " +
|
language = `Language: ${Magic.codeToLanguage(bestLanguage.lang)} ${(bestLanguage.probability * 100).toFixed(2)}%\n`;
|
||||||
(bestLanguage.probability * 100).toFixed(2) + "%";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option.fileType) {
|
if (option.fileType) {
|
||||||
fileType = `${option.fileType.mime} (${option.fileType.ext})`;
|
fileType = `File type: ${option.fileType.mime} (${option.fileType.ext})\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.matchingOps.length) {
|
||||||
|
matchingOps = `Matching ops: ${[...new Set(option.matchingOps.map(op => op.op))].join(", ")}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
output += `<tr>
|
output += `<tr>
|
||||||
<td><a href="#${recipeURL}">${Utils.generatePrettyRecipe(option.recipe, true)}</a></td>
|
<td><a href="#${recipeURL}">${Utils.generatePrettyRecipe(option.recipe, true)}</a></td>
|
||||||
<td>${Utils.escapeHtml(Utils.printable(Utils.truncate(option.data, 99)))}</td>
|
<td>${Utils.escapeHtml(Utils.printable(Utils.truncate(option.data, 99)))}</td>
|
||||||
<td>Language: ${language}
|
<td>${language}${fileType}${matchingOps}${validUTF8}</td>
|
||||||
File type: ${fileType}
|
|
||||||
Valid UTF8: ${option.isUTF8}</td>
|
|
||||||
</tr>`;
|
</tr>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,6 +174,9 @@ class Magic {
|
|||||||
async speculativeExecution(depth = 0, recipeConfig = []) {
|
async speculativeExecution(depth = 0, recipeConfig = []) {
|
||||||
if (depth < 0) return [];
|
if (depth < 0) return [];
|
||||||
|
|
||||||
|
// Find any operations that can be run on this data
|
||||||
|
const matchingOps = this.findMatchingOps();
|
||||||
|
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
||||||
// Record the properties of the current data
|
// Record the properties of the current data
|
||||||
@ -182,12 +185,10 @@ class Magic {
|
|||||||
data: this.inputStr.slice(0, 100),
|
data: this.inputStr.slice(0, 100),
|
||||||
languageScores: this.detectLanguage(),
|
languageScores: this.detectLanguage(),
|
||||||
fileType: this.detectFileType(),
|
fileType: this.detectFileType(),
|
||||||
isUTF8: this.isUTF8()
|
isUTF8: this.isUTF8(),
|
||||||
|
matchingOps: matchingOps
|
||||||
});
|
});
|
||||||
|
|
||||||
// Find any operations that can be run on this data
|
|
||||||
const matchingOps = this.findMatchingOps();
|
|
||||||
|
|
||||||
// Execute each of those operations, then recursively call the speculativeExecution() method
|
// Execute each of those operations, then recursively call the speculativeExecution() method
|
||||||
// on the resulting data, recording the properties of each option.
|
// on the resulting data, recording the properties of each option.
|
||||||
await Promise.all(matchingOps.map(async op => {
|
await Promise.all(matchingOps.map(async op => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user