Skip to content

Commit

Permalink
Update logic to find repeated words (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfheij-sil authored Aug 28, 2024
2 parents f414e0a + 8c5760e commit b10502e
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 256 deletions.
11 changes: 5 additions & 6 deletions extensions/src/platform-scripture/src/inventory-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ export const extractRepeatedWords = (
text: string,
target: string | undefined = undefined,
): string[] => {
const repeatedWords: string[] = [];
const words = split(text, /[\s]+/);
words.forEach((word, index, allWords) => {
if (target && word !== target) return;
if (index + 1 < allWords.length && word === allWords[index + 1]) repeatedWords.push(word);
});
// Finds repeated words, and captures the first occurrence of the word
const repeatedWords = text.match(/\b(\p{L}+)\b(?= \b\1\b)/gu) || [];

if (target) return repeatedWords?.filter((word) => word === target);

return repeatedWords;
};
236 changes: 118 additions & 118 deletions lib/platform-bible-react/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.cjs.map

Large diffs are not rendered by default.

242 changes: 120 additions & 122 deletions lib/platform-bible-react/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Inventory, {
Scope,
Status,
} from '@/components/advanced/inventory/inventory.component';
import { ScriptureReference } from 'platform-bible-utils';
import { ScriptureReference, split } from 'platform-bible-utils';
import { useState } from 'react';
import scriptureSnippet from './scripture-snippet';

Expand Down Expand Up @@ -41,13 +41,9 @@ const createColumns = (
];

const extractItems = (text: string, target: string | undefined = undefined): string[] => {
const repeatedWords: string[] = [];
const words = text.split(/[\s]+/);
words.forEach((word, index, allWords) => {
if (target && word !== target) return;
if (index + 1 < allWords.length && word === allWords[index + 1]) repeatedWords.push(word);
});
return repeatedWords;
let characters: string[] = split(text, '');
if (target) characters = characters.filter((character) => character === target);
return characters;
};

function InventoryExample() {
Expand Down

0 comments on commit b10502e

Please sign in to comment.