Skip to content

Commit

Permalink
Fix indexOf bracket instance
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Dec 23, 2023
1 parent eaed52a commit 0e7a8a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/readingParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ function getReadingFromDefinition(definition, term) {
// Remove spaces from definition and term
definition = definition.replace(/ /g, '');
term = term.replace(/ /g, '');
const bracketRegex = /[((]([^))]*)/g;
const bracketRegex = /([((]([^))]*))/g;
const bracketMatches = bracketRegex.exec(definition);
// @ts-ignore
if (bracketMatches?.length >= 1) {

if (bracketMatches && bracketMatches.length >= 2) {
// @ts-ignore
const bracketContent = bracketMatches[1];
const outerBracketContent = bracketMatches[1];
const bracketContent = bracketMatches[2];
// Check if the bracket is at the beginning of the definition or closely following the term
const bracketIndex = definition.indexOf(bracketContent);
const bracketIndex = definition.indexOf(outerBracketContent);
const termIndex = definition.indexOf(term) ?? 0;
const termEndIndex = termIndex + term.length;
if (bracketIndex - termEndIndex > leewayAfterTerm) {
Expand Down
2 changes: 1 addition & 1 deletion src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const testCases = [
},
{
line: `<http://ja.dbpedia.org/resource/Hagenuk_MT-2000> <http://www.w3.org/2000/01/rdf-schema#comment> "Hagenuk MT-2000は1994年に発売された携帯電話である。この端末はデンマークStøvringにあるHagenukの開発センターで設計・製造された。この端末は前身である1992年のHagenuk MT-900とともに (en) の機能を導入した最初期の携帯電話製品の一つである。また、MT-2000は従来の外付けアンテナではなく内蔵アンテナを組み込んだ世界初の製品でもある。さらに、Hagenuk MT-2000はテトリス系のゲームを組み込んだ世界初の携帯電話でもある。"@ja .`,
term: 'Hagenuk_MT-2000',
term: 'Hagenuk MT-2000',
expectedReading:
'',
},
Expand Down

0 comments on commit 0e7a8a7

Please sign in to comment.