Skip to content

Commit

Permalink
Merge branch 'master' into storyq-2
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmartin committed Oct 3, 2024
2 parents 8926f59 + 0dfdde6 commit 3ae5bd3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/stores/feature_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export class FeatureStore {
if (iFeature.info.kind === 'search') {
const tDetails = iFeature.info.details as SearchDetails,
tFirstPart = namingAbbreviations[tDetails.where],
tMatch = tDetails.freeFormText.match( /\w+/),
tSecondPart = tDetails.freeFormText !== '' ? `"${tMatch ? tMatch[0] : ''}"` :
tSecondPart = tDetails.freeFormText !== '' ? `"${tDetails.freeFormText.trim()}"` :
tDetails.punctuation !== '' ? tDetails.punctuation :
tDetails.wordList && tDetails.wordList.datasetName !== '' ? tDetails.wordList.datasetName :
tDetails.what === 'any number' ? 'anyNumber' : ''
Expand Down
25 changes: 24 additions & 1 deletion src/stores/target_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,30 @@ export class TargetStore {
const option = (iNewFeature.info.details as SearchDetails).where;
const tBegins = option === featureDescriptors.containsOptions[2] ? '^' : '';
const tEnds = option === featureDescriptors.containsOptions[3] ? '$' : '';
const tParamString = `${tTargetAttr},"${tBegins}\\\\\\\\b${(iNewFeature.info.details as SearchDetails).freeFormText}\\\\\\\\b${tEnds}"`;
const text = (iNewFeature.info.details as SearchDetails).freeFormText.trim();
// note: the multiple slash escaping is due to all the layers between this code and the CODAP formula evaluator
const escapedText = text
.replace(/[.*+?^${}()|[\]\\]/g, '\\\\\\\\$&') // escape regex modifiers
.replace(/\s+/g, '\\\\\\\\s+') // allow multiple spaces between words
.replace(/['"“”‘’]/g, (match) => { // allow both regular and smart quotes to match each other
switch (match) {
case '"':
case '“':
case '”':
return `["“”]`;
case "'":
case '‘':
case '’':
return `['‘’]`;
default:
return match;
}
});
// don't add word boundaries when the user input starts/ends with non-word characters, like ! or , as that would fail matching
const wordBoundary = `\\\\\\\\b`;
const maybeStartingWordBoundary = /^\w/.test(text) ? wordBoundary : '';
const maybeEndingWordBoundary = /\w$/.test(text) ? wordBoundary : '';
const tParamString = `${tTargetAttr},"${tBegins}${maybeStartingWordBoundary}${escapedText}${maybeEndingWordBoundary}${tEnds}"`;
let tResult = '';
switch (option) {//['contain', 'not contain', 'start with', 'end with']
case featureDescriptors.containsOptions[0]: // contain
Expand Down
12 changes: 10 additions & 2 deletions src/utilities/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {wordTokenizer} from "../lib/one_hot";
// import {wordTokenizer} from "../lib/one_hot";

/**
*
Expand All @@ -7,7 +7,7 @@ import {wordTokenizer} from "../lib/one_hot";
* @param iSpecialFeatures - an array of features that don't appear in the text but may appear in iSelectedWords
*/
export function textToObject( iText:string, iSelectedWords:any, iSpecialFeatures:string[]):any {
let segment = '';
// let segment = '';
let tResultArray:any = [];
iSpecialFeatures.forEach( iFeature => {
if( iSelectedWords.indexOf( iFeature) >= 0)
Expand All @@ -16,6 +16,12 @@ export function textToObject( iText:string, iSelectedWords:any, iSpecialFeatures
});
});

// do not highlight text for now
tResultArray.push({text: iText});

/*
NOTE: this code is broken and doesn't match phrases or match lists like personal pronoun lists
let words:string[] = wordTokenizer(iText, false, false);
words.forEach((iWord) => {
let tRawWord = iWord.toLowerCase();
Expand All @@ -39,6 +45,8 @@ export function textToObject( iText:string, iSelectedWords:any, iSpecialFeatures
});
if( segment !== '')
tResultArray.push({ text: segment });
*/

return tResultArray;
}

Expand Down

0 comments on commit 3ae5bd3

Please sign in to comment.