-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Hindi tokenization issues with \u200D that should not break a w…
…ord.
- Loading branch information
Showing
8 changed files
with
118 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## v0.9.0 | ||
|
||
- Fixed Hindi tokenization issues with \u200D that should not break a word. | ||
- http://unicode.scarfboy.com/?s=%E0%A4%B8%E0%A4%A8%E0%A5%8D%E2%80%8D%E0%A4%A4%E0%A4%BE%E0%A4%A8 | ||
- Extracted Occurrences functions to separate file for better organization. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-env jest */ | ||
import * as occurrences from '../occurrences'; | ||
|
||
const { | ||
occurrenceInString, | ||
occurrencesInString, | ||
} = occurrences; | ||
|
||
|
||
describe('occurrenceInString', function() { | ||
it('should return occurrence for first of two', function() { | ||
const string = 'a ab a'; | ||
const substring = 'a'; | ||
const index = 0; | ||
const expected = 1; | ||
const output = occurrenceInString(string, index, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
it('should return occurrence for second of two', function() { | ||
const string = 'a ab a'; | ||
const substring = 'a'; | ||
const index = 2; | ||
const expected = 2; | ||
const output = occurrenceInString(string, index, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
it('should return occurrence for second of three', function() { | ||
const string = 'a ab a bac a'; | ||
const substring = 'a'; | ||
const index = 2; | ||
const expected = 2; | ||
const output = occurrenceInString(string, index, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('occurrencesInString', function() { | ||
it('should return occurrences for none', function() { | ||
const string = 'ab'; | ||
const substring = 'a'; | ||
const expected = 0; | ||
const output = occurrencesInString(string, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
it('should return occurrences for one', function() { | ||
const string = 'a ab'; | ||
const substring = 'a'; | ||
const expected = 1; | ||
const output = occurrencesInString(string, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
it('should return occurrences for two', function() { | ||
const string = 'a ab a'; | ||
const substring = 'a'; | ||
const expected = 2; | ||
const output = occurrencesInString(string, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
it('should return occurrences for three', function() { | ||
const string = 'a ab a bac a'; | ||
const substring = 'a'; | ||
const expected = 3; | ||
const output = occurrencesInString(string, substring); | ||
expect(output).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as tokenizers from './tokenizers'; | ||
|
||
/** | ||
* Gets the occurrence of a subString in a string by using the subString index in the string. | ||
* @param {String} string | ||
* @param {Number} currentWordIndex | ||
* @param {String} subString | ||
* @return {Object} | ||
*/ | ||
export const occurrenceInString = (string, currentWordIndex, subString) => { | ||
let occurrence = 0; | ||
const tokens = tokenizers.tokenize(string); | ||
for (let i = 0; i <= currentWordIndex; i++) { | ||
if (tokens[i] === subString) occurrence ++; | ||
} | ||
return occurrence; | ||
}; | ||
/** | ||
* Function that count occurrences of a substring in a string | ||
* @param {String} string - The string to search in | ||
* @param {String} subString - The sub string to search for | ||
* @return {Integer} - the count of the occurrences | ||
*/ | ||
export const occurrencesInString = (string, subString) => { | ||
let occurrences = 0; | ||
const tokens = tokenizers.tokenize(string); | ||
tokens.forEach((token) => { | ||
if (token === subString) occurrences ++; | ||
}); | ||
return occurrences; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters