Skip to content

Commit

Permalink
fix(regex): matching issues (#70)
Browse files Browse the repository at this point in the history
Claiyc authored Dec 13, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 62244ff commit a16ae9c
Showing 5 changed files with 19 additions and 96 deletions.
89 changes: 1 addition & 88 deletions docs/proc-uml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/components/MainVideoStream.vue
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
v-if="isRerendering"
v-for="captureArea in captureAreas"
:key="captureArea.getId()"
:stickSize="10"
:stickSize="7"
:minw="10"
:minh="10"
contentClass="draggable-capture-area"
:w="captureArea.getWidth()"
:h="captureArea.getHeight()"
2 changes: 2 additions & 0 deletions src/proc/Vigad.ts
Original file line number Diff line number Diff line change
@@ -114,6 +114,8 @@ export class Vigad {
this.regexHandler.findValue(value.data, regexGrp.getValueRegex(), regexGrp.getConstraintRegex()[1]);
} else if (regexGrp.getConstraintRegex()[1].getRegex().toString() === "/(?:)/") {
this.regexHandler.findValue(value.data, regexGrp.getValueRegex(), regexGrp.getConstraintRegex()[0]);
} else {
this.regexHandler.findValue(value.data, regexGrp.getValueRegex(), regexGrp.getConstraintRegex()[0], regexGrp.getConstraintRegex()[1]);
}
});
}, this.previewWidth, this.previewHeight);
3 changes: 3 additions & 0 deletions src/proc/regex/Regex.ts
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ export abstract class Regex {
this.substrings = this.getAllSubstrings(data!);
break;
case Slicing.SPACES:
this.substrings = [];
data.split(' ').forEach((element) => {
this.substrings.push({
index: this.indexOfFirst(data),
@@ -109,6 +110,7 @@ export abstract class Regex {
});
break;
case Slicing.ENTIRE_STR:
this.substrings = [];
this.substrings.push({ index: 0, element: data });
break;
}
@@ -198,6 +200,7 @@ export abstract class Regex {
},
};
}
return true;
});
break;
case Matching.APPROX:
17 changes: 10 additions & 7 deletions src/proc/regex/RegexHandler.ts
Original file line number Diff line number Diff line change
@@ -31,6 +31,10 @@ export class RegexHandler {
* @return {rating: number, match: {index: number, element: string}}
*/
public findValue(data:string, valueRegex: ValueRegex, cRegexBefore?: ConstraintRegex, cRegexAfter?: ConstraintRegex): {rating: number, match: {index: number, element: string}} {

// replace all occurences of \n in data with spaces
data = data.replace(/\n/g, " ");

let constraintRegex: ConstraintRegex[] = [];
if (typeof cRegexBefore !== 'undefined') {
constraintRegex.push(cRegexBefore);
@@ -66,13 +70,15 @@ export class RegexHandler {
}

// determine constraint indexes
let lowestHighIndex = 0;
let highestLowIndex = 0;
let hLIPlus = 0; // highestLowIndex plus length of match
let lowestHighIndex = data.length;
constraintRegex.forEach(regex => {
switch (regex.getLocation()) {
case "Before":
if (regex.getLastBestMatch().match.index > highestLowIndex) {
if (regex.getLastBestMatch().match.index >= highestLowIndex) {
highestLowIndex = regex.getLastBestMatch().match.index;
hLIPlus = highestLowIndex + regex.getLastBestMatch().match.element.length;
}
break;
case "After":
@@ -82,10 +88,6 @@ export class RegexHandler {
break;
}
});
if (lowestHighIndex === 0) {
lowestHighIndex = data.length;
}

// set required substrings for value regex & apply similarity conversion
if (highestLowIndex === 0 && lowestHighIndex === data.length) { // if no constraint regex
if (valueRegex.getSlicing() === Slicing.SUBSTR && allSubstrings.length !== 0) {
@@ -96,7 +98,8 @@ export class RegexHandler {
valueRegex.genSubstrings(data);
}
} else {
valueRegex.genSubstrings(data.slice(highestLowIndex, lowestHighIndex));
// this may be cached as well in the future, however performance optimization won't be as high
valueRegex.genSubstrings(data.slice(hLIPlus, lowestHighIndex));
}

valueRegex.applySimilarity();

0 comments on commit a16ae9c

Please sign in to comment.