-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve intelligibility reports
- Loading branch information
Showing
7 changed files
with
354 additions
and
8,312 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,85 @@ | ||
import { IntelligibilityReport } from './IntelligibilityReport'; | ||
import { | ||
IntelligibilityLevel, | ||
IntelligibilityLevelDescription, | ||
SlavicLanguage, | ||
} from '../types'; | ||
|
||
describe('IntelligibilityReport', () => { | ||
it.each([ | ||
['be'], | ||
['bg'], | ||
['bs'], | ||
['cnr'], | ||
['cs'], | ||
['csb'], | ||
['cu'], | ||
['dsb'], | ||
['hr'], | ||
['hsb'], | ||
['mk'], | ||
['pl'], | ||
['ru'], | ||
['rue'], | ||
['sk'], | ||
['sl'], | ||
['sr'], | ||
['szl'], | ||
['uk'], | ||
])('should have autogenerated unknown for %s', (rawLang) => { | ||
const lang = rawLang as SlavicLanguage; | ||
const report = new IntelligibilityReport(); | ||
|
||
expect(report[lang].tag).toBe(lang); | ||
expect(report[lang].level).toBe(''); | ||
expect(report[lang].autogenerated).toBe(true); | ||
}); | ||
|
||
describe('toString()', () => { | ||
it('should generate an empty string', () => { | ||
expect(`${new IntelligibilityReport()}`).toBe(''); | ||
}); | ||
|
||
it.each([ | ||
['!be+', SlavicLanguage.Belarusian, 'DirectMatch', true], | ||
['bs*', SlavicLanguage.Bosnian, 'HelperMatch', false], | ||
['!bg?', SlavicLanguage.Bulgarian, 'AmbiguousDirectMatch', true], | ||
['hr~', SlavicLanguage.Croatian, 'AmbiguousHelperMatch', false], | ||
['!cs#', SlavicLanguage.Czech, 'FalseFriend', true], | ||
['csb-', SlavicLanguage.Kashubian, 'NoMatch', false], | ||
['!dsb+', SlavicLanguage.LowerSorbian, 'DirectMatch', true], | ||
['mk*', SlavicLanguage.Macedonian, 'HelperMatch', false], | ||
['!cnr?', SlavicLanguage.Montenegrin, 'AmbiguousDirectMatch', true], | ||
['cu~', SlavicLanguage.ChurchSlavonic, 'AmbiguousHelperMatch', false], | ||
['!pl#', SlavicLanguage.Polish, 'FalseFriend', true], | ||
['ru-', SlavicLanguage.Russian, 'NoMatch', false], | ||
['!rue+', SlavicLanguage.Rusyn, 'DirectMatch', true], | ||
['sr*', SlavicLanguage.Serbian, 'HelperMatch', false], | ||
['!szl?', SlavicLanguage.Silesian, 'AmbiguousDirectMatch', true], | ||
['sk~', SlavicLanguage.Slovak, 'AmbiguousHelperMatch', false], | ||
['!sl#', SlavicLanguage.Slovenian, 'FalseFriend', true], | ||
['uk-', SlavicLanguage.Ukrainian, 'NoMatch', false], | ||
['!hsb+', SlavicLanguage.UpperSorbian, 'DirectMatch', true], | ||
] as [string, SlavicLanguage, IntelligibilityLevelDescription, boolean][])( | ||
'should generate %s', | ||
(expected, lang, level, autogenerated) => { | ||
const report = new IntelligibilityReport(); | ||
report[lang].level = IntelligibilityLevel[level]; | ||
report[lang].autogenerated = autogenerated; | ||
expect(`${report}`).toBe(expected); | ||
}, | ||
); | ||
}); | ||
|
||
it('should display multiple tags', () => { | ||
const report = new IntelligibilityReport(); | ||
|
||
report.uk.autogenerated = report.ru.autogenerated = false; | ||
report.uk.level = IntelligibilityLevel.DirectMatch; | ||
report.be.level = IntelligibilityLevel.DirectMatch; | ||
report.ru.level = IntelligibilityLevel.HelperMatch; | ||
report.pl.level = IntelligibilityLevel.DirectMatch; | ||
|
||
expect(`${report}`).toBe('!be+ !pl+ ru* uk+'); | ||
}); | ||
}); |
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,135 @@ | ||
import { IntelligibilityLevel, SlavicLanguage } from '../types'; | ||
|
||
export class IntelligibilityAssessment { | ||
public tag: SlavicLanguage; | ||
public level: IntelligibilityLevel; | ||
public autogenerated: boolean; | ||
|
||
constructor( | ||
tag: SlavicLanguage, | ||
level = IntelligibilityLevel.Unknown, | ||
autogenerated = true, | ||
) { | ||
this.tag = tag; | ||
this.level = level; | ||
this.autogenerated = autogenerated; | ||
} | ||
|
||
toString(): string { | ||
if (this.level === IntelligibilityLevel.Unknown) { | ||
return ''; | ||
} | ||
|
||
return `${this.autogenerated ? '!' : ''}${this.tag}${this.level}`; | ||
} | ||
} | ||
|
||
export class IntelligibilityReport | ||
implements Readonly<Record<SlavicLanguage, IntelligibilityAssessment>> | ||
{ | ||
private _data: Record<SlavicLanguage, IntelligibilityAssessment> = { | ||
be: new IntelligibilityAssessment(SlavicLanguage.Belarusian), | ||
bg: new IntelligibilityAssessment(SlavicLanguage.Bulgarian), | ||
bs: new IntelligibilityAssessment(SlavicLanguage.Bosnian), | ||
cnr: new IntelligibilityAssessment(SlavicLanguage.Montenegrin), | ||
cs: new IntelligibilityAssessment(SlavicLanguage.Czech), | ||
csb: new IntelligibilityAssessment(SlavicLanguage.Kashubian), | ||
cu: new IntelligibilityAssessment(SlavicLanguage.ChurchSlavonic), | ||
dsb: new IntelligibilityAssessment(SlavicLanguage.LowerSorbian), | ||
hr: new IntelligibilityAssessment(SlavicLanguage.Croatian), | ||
hsb: new IntelligibilityAssessment(SlavicLanguage.UpperSorbian), | ||
mk: new IntelligibilityAssessment(SlavicLanguage.Macedonian), | ||
pl: new IntelligibilityAssessment(SlavicLanguage.Polish), | ||
ru: new IntelligibilityAssessment(SlavicLanguage.Russian), | ||
rue: new IntelligibilityAssessment(SlavicLanguage.Rusyn), | ||
sk: new IntelligibilityAssessment(SlavicLanguage.Slovak), | ||
sl: new IntelligibilityAssessment(SlavicLanguage.Slovenian), | ||
sr: new IntelligibilityAssessment(SlavicLanguage.Serbian), | ||
szl: new IntelligibilityAssessment(SlavicLanguage.Silesian), | ||
uk: new IntelligibilityAssessment(SlavicLanguage.Ukrainian), | ||
}; | ||
|
||
get be(): IntelligibilityAssessment { | ||
return this._data.be; | ||
} | ||
|
||
get bg(): IntelligibilityAssessment { | ||
return this._data.bg; | ||
} | ||
|
||
get bs(): IntelligibilityAssessment { | ||
return this._data.bs; | ||
} | ||
|
||
get cnr(): IntelligibilityAssessment { | ||
return this._data.cnr; | ||
} | ||
|
||
get cs(): IntelligibilityAssessment { | ||
return this._data.cs; | ||
} | ||
|
||
get csb(): IntelligibilityAssessment { | ||
return this._data.csb; | ||
} | ||
|
||
get cu(): IntelligibilityAssessment { | ||
return this._data.cu; | ||
} | ||
|
||
get dsb(): IntelligibilityAssessment { | ||
return this._data.dsb; | ||
} | ||
|
||
get hr(): IntelligibilityAssessment { | ||
return this._data.hr; | ||
} | ||
|
||
get hsb(): IntelligibilityAssessment { | ||
return this._data.hsb; | ||
} | ||
|
||
get mk(): IntelligibilityAssessment { | ||
return this._data.mk; | ||
} | ||
|
||
get pl(): IntelligibilityAssessment { | ||
return this._data.pl; | ||
} | ||
|
||
get ru(): IntelligibilityAssessment { | ||
return this._data.ru; | ||
} | ||
|
||
get rue(): IntelligibilityAssessment { | ||
return this._data.rue; | ||
} | ||
|
||
get sk(): IntelligibilityAssessment { | ||
return this._data.sk; | ||
} | ||
|
||
get sl(): IntelligibilityAssessment { | ||
return this._data.sl; | ||
} | ||
|
||
get sr(): IntelligibilityAssessment { | ||
return this._data.sr; | ||
} | ||
|
||
get szl(): IntelligibilityAssessment { | ||
return this._data.szl; | ||
} | ||
|
||
get uk(): IntelligibilityAssessment { | ||
return this._data.uk; | ||
} | ||
|
||
toString(): string { | ||
return Object.values(this._data).map(String).filter(Boolean).join(' '); | ||
} | ||
|
||
toJSON(): Record<SlavicLanguage, IntelligibilityAssessment> { | ||
return this._data; | ||
} | ||
} |
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
Oops, something went wrong.