Add Output Filter option to Magic operation

master
j433866 2018-12-18 10:40:18 +00:00
parent 79b9b63982
commit 283d7f2159
2 changed files with 13 additions and 5 deletions

View File

@ -267,7 +267,7 @@ class Magic {
* @param {boolean} [useful=false] - Whether the current recipe should be scored highly * @param {boolean} [useful=false] - Whether the current recipe should be scored highly
* @returns {Object[]} - A sorted list of the recipes most likely to result in correct decoding * @returns {Object[]} - A sorted list of the recipes most likely to result in correct decoding
*/ */
async speculativeExecution(depth=0, extLang=false, intensive=false, recipeConfig=[], useful=false) { async speculativeExecution(depth=0, extLang=false, intensive=false, recipeConfig=[], useful=false, filter=null) {
if (depth < 0) return []; if (depth < 0) return [];
// Find any operations that can be run on this data // Find any operations that can be run on this data
@ -305,7 +305,7 @@ class Magic {
const magic = new Magic(output, this.opPatterns), const magic = new Magic(output, this.opPatterns),
speculativeResults = await magic.speculativeExecution( speculativeResults = await magic.speculativeExecution(
depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful); depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful, filter);
results = results.concat(speculativeResults); results = results.concat(speculativeResults);
})); }));
@ -331,7 +331,10 @@ class Magic {
r.fileType || // A file was found r.fileType || // A file was found
r.isUTF8 || // UTF-8 was found r.isUTF8 || // UTF-8 was found
r.matchingOps.length // A matching op was found r.matchingOps.length // A matching op was found
) ) &&
(
filter == null || // Either no filter was passed, or
new RegExp(filter).test(r.data)) // the filter matches the result data
); );
// Return a sorted list of possible recipes along with their properties // Return a sorted list of possible recipes along with their properties

View File

@ -43,6 +43,11 @@ class Magic extends Operation {
"name": "Extensive language support", "name": "Extensive language support",
"type": "boolean", "type": "boolean",
"value": false "value": false
},
{
"name": "Output Filter (Regex)",
"type": "string",
"value": ""
} }
]; ];
} }
@ -56,10 +61,10 @@ class Magic extends Operation {
*/ */
async run(state) { async run(state) {
const ings = state.opList[state.progress].ingValues, const ings = state.opList[state.progress].ingValues,
[depth, intensive, extLang] = ings, [depth, intensive, extLang, filter] = ings,
dish = state.dish, dish = state.dish,
magic = new MagicLib(await dish.get(Dish.ARRAY_BUFFER)), magic = new MagicLib(await dish.get(Dish.ARRAY_BUFFER)),
options = await magic.speculativeExecution(depth, extLang, intensive); options = await magic.speculativeExecution(depth, extLang, intensive, [], false, filter);
// Record the current state for use when presenting // Record the current state for use when presenting
this.state = state; this.state = state;