Skip to content

Commit

Permalink
Adjust the algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Dec 5, 2024
1 parent 2ff6b05 commit 680d8e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
34 changes: 17 additions & 17 deletions packages/cspell-lib/src/lib/textValidation/isRandomString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ describe('isRandomString', () => {
${'hello'} | ${0.2}
${'café'} | ${0.25}
${'café'.normalize('NFD')} | ${0.2}
${'Hello'} | ${0.4}
${'expectCategorizeStringStrToBeExpected'} | ${0.35}
${'expect categorizeString str .toBe expected'} | ${0.33}
${'H4sIAAAAAAAAA72d3ZLjNpK276X6O6ztFX4lWxnPN5whD3jsGd3DzomHGqJVa21StLqp9uOibn3LwgIKiD5AkyQ7Dpyu0QmkmQy'} | ${0.65}
${'izfrNTmQLnfsLzi2Wb9xPz2Qj9fQYGgeug3N2MkDuVHwpPcgkhHkJgCQuuvT+qZI'} | ${0.65}
${'sampleOldFalsePositivesBase64'} | ${0.34}
${'residencyStandard2DMultisampleBlockShape'} | ${0.25}
${'myNameSpace1/MyNameSpace2/mynamespace3/myserviceName'} | ${0.4}
${'PxTransform12transformInvERKS0_'} | ${0.32}
${'_ZNK5physx11PxTransform12transformInvERKNS_6PxVec3E'} | ${0.39}
${'_ZNK5physx11PxERKNS_6PxVec3E'} | ${0.5}
${'To_EntityDto_And_To_DrivedEntityDto'} | ${0.45}
${'Hello'} | ${0.2}
${'expectCategorizeStringStrToBeExpected'} | ${0.18}
${'expect categorizeString str .toBe expected'} | ${0.28}
${'H4sIAAAAAAAAA72d3ZLjNpK276X6O6ztFX4lWxnPN5whD3jsGd3DzomHGqJVa21StLqp9uOibn3LwgIKiD5AkyQ7Dpyu0QmkmQy'} | ${0.53}
${'izfrNTmQLnfsLzi2Wb9xPz2Qj9fQYGgeug3N2MkDuVHwpPcgkhHkJgCQuuvT+qZI'} | ${0.51}
${'sampleOldFalsePositivesBase64'} | ${0.2}
${'residencyStandard2DMultisampleBlockShape'} | ${0.17}
${'myNameSpace1/MyNameSpace2/mynamespace3/myserviceName'} | ${0.28}
${'PxTransform12transformInvERKS0_'} | ${0.22}
${'_ZNK5physx11PxTransform12transformInvERKNS_6PxVec3E'} | ${0.29}
${'_ZNK5physx11PxERKNS_6PxVec3E'} | ${0.39}
${'To_EntityDto_And_To_DrivedEntityDto'} | ${0.22}
`('isRandomString $str', ({ str, expected }) => {
expect(scoreRandomString(str))
.greaterThanOrEqual(expected)
Expand All @@ -57,11 +57,11 @@ describe('isRandomString', () => {
str | expected
${''} | ${''}
${'hello'} | ${'1'}
${'Hello'} | ${'21'}
${'expectCategorizeStringStrToBeExpected'} | ${'1212121212121'}
${'expect categorizeString str .toBe expected'} | ${'1 121 1 3121 1'}
${'H4sIAAAAAAAAA72d3ZLjNpK276X6O6ztFX4l+WxnPN5whD3jsGd3DzomHGqJVa21StLqp9uOibn3LwgIKiD5AkyQ7Dpyu0QmkmQy'} | ${'201201021212020201201+21201201210212121021210121021212021202102121'}
${'izfrNTmQLnfsLzi2Wb9xPz2Qj9fQYGgeug3N2MkDuVHwpPcgkhHkJgCQuuvT+qZI'} | ${'121212102101210210121020212121212121212+12'}
${'Hello'} | ${'1'}
${'expectCategorizeStringStrToBeExpected'} | ${'1111111'}
${'expect categorizeString str .toBe expected'} | ${'1 11 1 311 1'}
${'H4sIAAAAAAAAA72d3ZLjNpK276X6O6ztFX4l+WxnPN5whD3jsGd3DzomHGqJVa21StLqp9uOibn3LwgIKiD5AkyQ7Dpyu0QmkmQy'} | ${'20120102112020201201+120120110121210110110121201201011'}
${'izfrNTmQLnfsLzi2Wb9xPz2Qj9fQYGgeug3N2MkDuVHwpPcgkhHkJgCQuuvT+qZI'} | ${'121211010110101210201121111212+12'}
`('categorizeString $str', ({ str, expected }) => {
expect(categorizeString(str)).toBe(expected);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/textValidation/isRandomString.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const maxRadio = 0.55;
const maxRadio = 0.5;

/**
* Try to detect if a string is a random string of characters or is it camel case / snake case words.
Expand All @@ -24,8 +24,8 @@ export function categorizeString(s: string): string {
.replaceAll(/\d+/g, '0')
.replaceAll(/\p{Ll}\p{M}+/gu, 'a')
.replaceAll(/\p{Lu}\p{M}+/gu, 'A')
.replaceAll(/\p{Lu}?\p{Ll}+/gu, '1')
.replaceAll(/\p{Lu}+/gu, '2')
.replaceAll(/\p{Ll}+/gu, '1')
.replaceAll(/\p{M}/gu, '4')
.replaceAll('_', '')
.replaceAll(/[-_.']+/g, '3');
Expand Down

0 comments on commit 680d8e3

Please sign in to comment.