@interslavic/database-engine-core
Advanced tools
Comparing version
@@ -6,2 +6,3 @@ import type { Language } from '../../constants'; | ||
synsets: MultilingualSynset$Synsets; | ||
steen?: MultilingualSynset$Steen; | ||
} | ||
@@ -11,1 +12,4 @@ export type MultilingualSynset$Synsets = { | ||
} & Partial<Record<Language, Synset | undefined>>; | ||
export type MultilingualSynset$Steen = { | ||
debated?: Set<'id' | 'isv' | 'addition' | 'partOfSpeech' | 'type' | 'sameInLanguages' | 'genesis' | 'frequency' | 'en' | 'ru' | 'be' | 'uk' | 'pl' | 'cs' | 'sk' | 'bg' | 'mk' | 'sr' | 'hr' | 'sl' | 'cu' | 'de' | 'nl' | 'eo' | 'intelligibility' | 'using_example'>; | ||
}; |
export declare function isAutogenerated(str: string): boolean; | ||
export declare function isVerified(str: string): boolean; | ||
export declare function isDebatable(str: string): boolean; | ||
export declare function stripMetacharacters(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stripMetacharacters = exports.isDebatable = exports.isVerified = exports.isAutogenerated = void 0; | ||
exports.stripMetacharacters = exports.isVerified = exports.isAutogenerated = void 0; | ||
function isAutogenerated(str) { | ||
const exclamationIndex = str.indexOf('!'); | ||
if (exclamationIndex === 0) { | ||
return true; | ||
} | ||
if (exclamationIndex === 1) { | ||
return str.startsWith('#'); | ||
} | ||
return false; | ||
return str.indexOf('!') === 0; | ||
} | ||
@@ -19,28 +12,5 @@ exports.isAutogenerated = isAutogenerated; | ||
exports.isVerified = isVerified; | ||
function isDebatable(str) { | ||
const hashIndex = str.indexOf('#'); | ||
if (hashIndex === 0) { | ||
return true; | ||
} | ||
if (hashIndex === 1) { | ||
return str.startsWith('!'); | ||
} | ||
return false; | ||
} | ||
exports.isDebatable = isDebatable; | ||
function stripMetacharacters(str) { | ||
const hashIndex = str.indexOf('#'); | ||
const exclamationIndex = str.indexOf('!'); | ||
const hasBoth = (hashIndex === 0 && exclamationIndex === 1) || | ||
(hashIndex === 1 && exclamationIndex === 0); | ||
if (hasBoth) { | ||
return str.slice(2); | ||
} | ||
else if (hashIndex === 0 || exclamationIndex === 0) { | ||
return str.slice(1); | ||
} | ||
else { | ||
return str; | ||
} | ||
return isAutogenerated(str) ? str.slice(1) : str; | ||
} | ||
exports.stripMetacharacters = stripMetacharacters; |
@@ -9,12 +9,6 @@ "use strict"; | ||
[false, ''], | ||
[false, '#'], | ||
[true, '!'], | ||
[true, '!#'], | ||
[true, '#!'], | ||
[false, 'a'], | ||
[false, '#a'], | ||
[false, 'a!'], | ||
[true, '!a'], | ||
[true, '!#a'], | ||
[true, '#!a'], | ||
])('should return %j for %j', (expected, input) => { | ||
@@ -24,32 +18,8 @@ expect(metacharacters.isAutogenerated(input)).toBe(expected); | ||
}); | ||
describe('.isDebatable()', () => { | ||
test.each([ | ||
[false, ''], | ||
[true, '#'], | ||
[false, '!'], | ||
[true, '!#'], | ||
[true, '#!'], | ||
[false, 'a'], | ||
[true, '#a'], | ||
[false, 'a#'], | ||
[true, '#a'], | ||
[true, '!#a'], | ||
[true, '#!a'], | ||
])('should return %j for %j', (expected, input) => { | ||
expect(metacharacters.isDebatable(input)).toBe(expected); | ||
}); | ||
}); | ||
describe('.stripMetacharacters()', () => { | ||
test.each([ | ||
['', ''], | ||
['#', ''], | ||
['!', ''], | ||
['!#', ''], | ||
['#!', ''], | ||
['a', 'a'], | ||
['#a', 'a'], | ||
['!a', 'a'], | ||
['#!a', 'a'], | ||
['!#a', 'a'], | ||
['a#', 'a#'], | ||
['a!', 'a!'], | ||
@@ -56,0 +26,0 @@ ])('should convert %j into %j', (input, expected) => { |
import { Lemma } from '../lemma'; | ||
export declare function parseSynset(rawStr: string): { | ||
verified: boolean; | ||
debatable: boolean; | ||
lemmas: Lemma[]; | ||
}; |
@@ -8,3 +8,2 @@ "use strict"; | ||
const verified = (0, metacharacters_1.isVerified)(rawStr); | ||
const debatable = (0, metacharacters_1.isDebatable)(rawStr); | ||
const annotations = rawStr.includes('(') | ||
@@ -21,3 +20,2 @@ ? new AnnotationHelper() | ||
verified, | ||
debatable, | ||
lemmas, | ||
@@ -24,0 +22,0 @@ }; |
@@ -7,3 +7,2 @@ import { Lemma as LemmaBase } from '../lemma'; | ||
verified?: boolean; | ||
debatable?: boolean; | ||
}; | ||
@@ -13,3 +12,2 @@ type EqualityPredicate<T> = (a: T, b: T) => boolean; | ||
verified: boolean; | ||
debatable: boolean; | ||
readonly lemmas: Lemma[]; | ||
@@ -16,0 +14,0 @@ constructor(options?: Partial<SynsetOptions<Lemma>>); |
@@ -9,6 +9,5 @@ "use strict"; | ||
constructor(options = {}) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
this.verified = (_a = options.verified) !== null && _a !== void 0 ? _a : false; | ||
this.debatable = (_b = options.debatable) !== null && _b !== void 0 ? _b : false; | ||
this.lemmas = (_c = options.lemmas) !== null && _c !== void 0 ? _c : []; | ||
this.lemmas = (_b = options.lemmas) !== null && _b !== void 0 ? _b : []; | ||
} | ||
@@ -18,3 +17,2 @@ clone() { | ||
verified: this.verified, | ||
debatable: this.debatable, | ||
lemmas: this.lemmas.map((g) => g.clone()), | ||
@@ -52,3 +50,2 @@ }); | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}); | ||
@@ -72,3 +69,2 @@ for (const l1 of this.lemmas) { | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}).add(this.lemmas); | ||
@@ -92,3 +88,2 @@ for (const l2 of other.lemmas) { | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}); | ||
@@ -115,4 +110,3 @@ for (const l1 of this.lemmas) { | ||
const hasCommas = this.lemmas.some((l) => l.value.includes(',')); | ||
return ((this.debatable ? '#' : '') + | ||
(this.verified ? '' : '!') + | ||
return ((this.verified ? '' : '!') + | ||
this.lemmas.map(String).join(hasCommas ? '; ' : ', ')); | ||
@@ -119,0 +113,0 @@ } |
@@ -14,5 +14,2 @@ "use strict"; | ||
}); | ||
it('should not report itself as debatable', () => { | ||
expect(anEmptySynset().debatable).toBe(false); | ||
}); | ||
it('should be empty', () => { | ||
@@ -31,6 +28,2 @@ expect(anEmptySynset().isEmpty()).toBe(true); | ||
}); | ||
it('should have .debatable property', () => { | ||
const { synset, meta } = aComplexSynset(); | ||
expect(synset.debatable).toBe(meta.debatable); | ||
}); | ||
it('should be not empty', () => { | ||
@@ -120,5 +113,4 @@ const { synset } = aComplexSynset(); | ||
synset1.verified = false; | ||
synset1.debatable = true; | ||
const union = synset1.union(synset2); | ||
expect(union.toString()).toBe('#!a, b'); | ||
expect(union.toString()).toBe('!a, b'); | ||
}); | ||
@@ -139,5 +131,4 @@ }); | ||
synset1.verified = false; | ||
synset1.debatable = true; | ||
const union = synset1.difference(synset2); | ||
expect(union.toString()).toBe('#!a, b'); | ||
expect(union.toString()).toBe('!a, b'); | ||
}); | ||
@@ -155,5 +146,10 @@ }); | ||
s1.verified = s2.verified = true; | ||
s2.debatable = true; | ||
expect(s1.intersection(s2).toString()).toBe('#lemma'); | ||
expect(s1.intersection(s2).toString()).toBe('lemma'); | ||
}); | ||
it('should take the worst metadata if there is an intersection', () => { | ||
const s1 = anEmptySynset().add(['this', 'lemma']); | ||
const s2 = anEmptySynset().add(['that', 'lemma']); | ||
s1.verified = true; | ||
expect(s1.intersection(s2).toString()).toBe('!lemma'); | ||
}); | ||
}); | ||
@@ -170,3 +166,2 @@ describe('.lemmas()', () => { | ||
synset.verified = false; | ||
synset.debatable = false; | ||
expect(`${synset}`).toMatch(/^!/); | ||
@@ -177,23 +172,4 @@ }); | ||
synset.verified = true; | ||
synset.debatable = false; | ||
expect(`${synset}`).not.toMatch(/^!/); | ||
}); | ||
it('should prepend # if it is debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.debatable = true; | ||
synset.verified = true; | ||
expect(`${synset}`).toMatch(/^#[^!]/); | ||
}); | ||
it('should not prepend # if it is not debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.debatable = false; | ||
synset.verified = false; | ||
expect(`${synset}`).not.toMatch(/^#/); | ||
}); | ||
it('should prepend both #! if it is verified and debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.verified = false; | ||
synset.debatable = true; | ||
expect(`${synset}`).toMatch(/^#!/); | ||
}); | ||
it('should separate lemmas with (;) and lemmas with (,) inside', () => { | ||
@@ -211,9 +187,4 @@ const synset = anEmptySynset(); | ||
['!', void 0], | ||
['#', void 0], | ||
['#!', void 0], | ||
['!#', '#!'], | ||
['!#course', '#!course'], | ||
['!U-Boot', void 0], | ||
['#co-worker', void 0], | ||
['#!only, ĝuste nun', void 0], | ||
['!only, ĝuste nun', void 0], | ||
["з'явитися", void 0], | ||
@@ -237,8 +208,6 @@ ['сей (устар.; местоим.)', void 0], | ||
const verified = true; | ||
const debatable = true; | ||
return { | ||
synset: new Synset_1.Synset({ lemmas, debatable, verified }), | ||
synset: new Synset_1.Synset({ lemmas, verified }), | ||
meta: { | ||
verified, | ||
debatable, | ||
}, | ||
@@ -245,0 +214,0 @@ lemmas, |
{ | ||
"name": "@interslavic/database-engine-core", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"repository": { | ||
@@ -19,9 +19,10 @@ "type": "git", | ||
"lint:ci": "eslint .", | ||
"test": "jest" | ||
"test": "jest", | ||
"test:update": "jest -u" | ||
}, | ||
"devDependencies": { | ||
"@interslavic/eslint-config-database-engine": "1.0.3", | ||
"@interslavic/jest-config-database-engine": "1.0.3", | ||
"@interslavic/prettier-config-database-engine": "1.0.3", | ||
"@interslavic/typescript-config-database-engine": "1.0.3", | ||
"@interslavic/eslint-config-database-engine": "1.0.4", | ||
"@interslavic/jest-config-database-engine": "1.0.4", | ||
"@interslavic/prettier-config-database-engine": "1.0.4", | ||
"@interslavic/typescript-config-database-engine": "1.0.4", | ||
"ts-node": "^10.9.1", | ||
@@ -43,3 +44,3 @@ "typescript": "^4.9.5" | ||
}, | ||
"gitHead": "e7fab075021f347bdcfa569f677494bf87c2f57b" | ||
"gitHead": "4e40b33d89e4824b7aa1a654cc0c596eb6249677" | ||
} |
@@ -40,2 +40,3 @@ import type { Language } from '../../constants'; | ||
}; | ||
public steen?: MultilingualSynset$Steen; | ||
} | ||
@@ -46,1 +47,32 @@ | ||
} & Partial<Record<Language, Synset | undefined>>; | ||
export type MultilingualSynset$Steen = { | ||
debated?: Set< | ||
| 'id' | ||
| 'isv' | ||
| 'addition' | ||
| 'partOfSpeech' | ||
| 'type' | ||
| 'sameInLanguages' | ||
| 'genesis' | ||
| 'frequency' | ||
| 'en' | ||
| 'ru' | ||
| 'be' | ||
| 'uk' | ||
| 'pl' | ||
| 'cs' | ||
| 'sk' | ||
| 'bg' | ||
| 'mk' | ||
| 'sr' | ||
| 'hr' | ||
| 'sl' | ||
| 'cu' | ||
| 'de' | ||
| 'nl' | ||
| 'eo' | ||
| 'intelligibility' | ||
| 'using_example' | ||
>; | ||
}; |
@@ -7,12 +7,6 @@ import * as metacharacters from './metacharacters'; | ||
[false, ''], | ||
[false, '#'], | ||
[true, '!'], | ||
[true, '!#'], | ||
[true, '#!'], | ||
[false, 'a'], | ||
[false, '#a'], | ||
[false, 'a!'], | ||
[true, '!a'], | ||
[true, '!#a'], | ||
[true, '#!a'], | ||
])('should return %j for %j', (expected, input) => { | ||
@@ -23,33 +17,8 @@ expect(metacharacters.isAutogenerated(input)).toBe(expected); | ||
describe('.isDebatable()', () => { | ||
test.each([ | ||
[false, ''], | ||
[true, '#'], | ||
[false, '!'], | ||
[true, '!#'], | ||
[true, '#!'], | ||
[false, 'a'], | ||
[true, '#a'], | ||
[false, 'a#'], | ||
[true, '#a'], | ||
[true, '!#a'], | ||
[true, '#!a'], | ||
])('should return %j for %j', (expected, input) => { | ||
expect(metacharacters.isDebatable(input)).toBe(expected); | ||
}); | ||
}); | ||
describe('.stripMetacharacters()', () => { | ||
test.each([ | ||
['', ''], | ||
['#', ''], | ||
['!', ''], | ||
['!#', ''], | ||
['#!', ''], | ||
['a', 'a'], | ||
['#a', 'a'], | ||
['!a', 'a'], | ||
['#!a', 'a'], | ||
['!#a', 'a'], | ||
['a#', 'a#'], | ||
['a!', 'a!'], | ||
@@ -56,0 +25,0 @@ ])('should convert %j into %j', (input, expected) => { |
export function isAutogenerated(str: string): boolean { | ||
const exclamationIndex = str.indexOf('!'); | ||
if (exclamationIndex === 0) { | ||
return true; | ||
} | ||
if (exclamationIndex === 1) { | ||
return str.startsWith('#'); | ||
} | ||
return false; | ||
return str.indexOf('!') === 0; | ||
} | ||
@@ -18,30 +9,4 @@ | ||
export function isDebatable(str: string): boolean { | ||
const hashIndex = str.indexOf('#'); | ||
if (hashIndex === 0) { | ||
return true; | ||
} | ||
if (hashIndex === 1) { | ||
return str.startsWith('!'); | ||
} | ||
return false; | ||
} | ||
export function stripMetacharacters(str: string): string { | ||
const hashIndex = str.indexOf('#'); | ||
const exclamationIndex = str.indexOf('!'); | ||
const hasBoth = | ||
(hashIndex === 0 && exclamationIndex === 1) || | ||
(hashIndex === 1 && exclamationIndex === 0); | ||
if (hasBoth) { | ||
return str.slice(2); | ||
} else if (hashIndex === 0 || exclamationIndex === 0) { | ||
return str.slice(1); | ||
} else { | ||
return str; | ||
} | ||
return isAutogenerated(str) ? str.slice(1) : str; | ||
} |
import { Lemma } from '../lemma'; | ||
import { isDebatable, isVerified, stripMetacharacters } from './metacharacters'; | ||
import { isVerified, stripMetacharacters } from './metacharacters'; | ||
export function parseSynset(rawStr: string) { | ||
const verified = isVerified(rawStr); | ||
const debatable = isDebatable(rawStr); | ||
const annotations = rawStr.includes('(') | ||
@@ -22,3 +21,2 @@ ? new AnnotationHelper() | ||
verified, | ||
debatable, | ||
lemmas, | ||
@@ -25,0 +23,0 @@ }; |
@@ -16,6 +16,2 @@ import { Lemma } from '../lemma'; | ||
it('should not report itself as debatable', () => { | ||
expect(anEmptySynset().debatable).toBe(false); | ||
}); | ||
it('should be empty', () => { | ||
@@ -37,7 +33,2 @@ expect(anEmptySynset().isEmpty()).toBe(true); | ||
it('should have .debatable property', () => { | ||
const { synset, meta } = aComplexSynset(); | ||
expect(synset.debatable).toBe(meta.debatable); | ||
}); | ||
it('should be not empty', () => { | ||
@@ -153,6 +144,5 @@ const { synset } = aComplexSynset(); | ||
synset1.verified = false; | ||
synset1.debatable = true; | ||
const union = synset1.union(synset2); | ||
expect(union.toString()).toBe('#!a, b'); | ||
expect(union.toString()).toBe('!a, b'); | ||
}); | ||
@@ -176,6 +166,5 @@ }); | ||
synset1.verified = false; | ||
synset1.debatable = true; | ||
const union = synset1.difference(synset2); | ||
expect(union.toString()).toBe('#!a, b'); | ||
expect(union.toString()).toBe('!a, b'); | ||
}); | ||
@@ -197,6 +186,13 @@ }); | ||
s1.verified = s2.verified = true; | ||
s2.debatable = true; | ||
expect(s1.intersection(s2).toString()).toBe('#lemma'); | ||
expect(s1.intersection(s2).toString()).toBe('lemma'); | ||
}); | ||
it('should take the worst metadata if there is an intersection', () => { | ||
const s1 = anEmptySynset().add(['this', 'lemma']); | ||
const s2 = anEmptySynset().add(['that', 'lemma']); | ||
s1.verified = true; | ||
expect(s1.intersection(s2).toString()).toBe('!lemma'); | ||
}); | ||
}); | ||
@@ -215,3 +211,2 @@ | ||
synset.verified = false; | ||
synset.debatable = false; | ||
@@ -224,3 +219,2 @@ expect(`${synset}`).toMatch(/^!/); | ||
synset.verified = true; | ||
synset.debatable = false; | ||
@@ -230,26 +224,2 @@ expect(`${synset}`).not.toMatch(/^!/); | ||
it('should prepend # if it is debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.debatable = true; | ||
synset.verified = true; | ||
expect(`${synset}`).toMatch(/^#[^!]/); | ||
}); | ||
it('should not prepend # if it is not debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.debatable = false; | ||
synset.verified = false; | ||
expect(`${synset}`).not.toMatch(/^#/); | ||
}); | ||
it('should prepend both #! if it is verified and debatable', () => { | ||
const { synset } = aComplexSynset(); | ||
synset.verified = false; | ||
synset.debatable = true; | ||
expect(`${synset}`).toMatch(/^#!/); | ||
}); | ||
it('should separate lemmas with (;) and lemmas with (,) inside', () => { | ||
@@ -269,9 +239,4 @@ const synset = anEmptySynset(); | ||
['!', void 0], | ||
['#', void 0], | ||
['#!', void 0], | ||
['!#', '#!'], | ||
['!#course', '#!course'], | ||
['!U-Boot', void 0], | ||
['#co-worker', void 0], | ||
['#!only, ĝuste nun', void 0], | ||
['!only, ĝuste nun', void 0], | ||
["з'явитися", void 0], | ||
@@ -297,9 +262,7 @@ ['сей (устар.; местоим.)', void 0], | ||
const verified = true; | ||
const debatable = true; | ||
return { | ||
synset: new Synset({ lemmas, debatable, verified }), | ||
synset: new Synset({ lemmas, verified }), | ||
meta: { | ||
verified, | ||
debatable, | ||
}, | ||
@@ -306,0 +269,0 @@ lemmas, |
@@ -13,3 +13,2 @@ import { isIterable } from '../../utils'; | ||
verified?: boolean; | ||
debatable?: boolean; | ||
}; | ||
@@ -21,3 +20,2 @@ | ||
public verified: boolean; | ||
public debatable: boolean; | ||
public readonly lemmas: Lemma[]; | ||
@@ -27,3 +25,2 @@ | ||
this.verified = options.verified ?? false; | ||
this.debatable = options.debatable ?? false; | ||
this.lemmas = options.lemmas ?? []; | ||
@@ -35,3 +32,2 @@ } | ||
verified: this.verified, | ||
debatable: this.debatable, | ||
lemmas: this.lemmas.map((g) => g.clone()), | ||
@@ -79,3 +75,2 @@ }); | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}); | ||
@@ -106,3 +101,2 @@ | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}).add(this.lemmas); | ||
@@ -133,3 +127,2 @@ | ||
verified: this.verified && other.verified, | ||
debatable: this.debatable || other.debatable, | ||
}); | ||
@@ -163,3 +156,2 @@ | ||
return ( | ||
(this.debatable ? '#' : '') + | ||
(this.verified ? '' : '!') + | ||
@@ -166,0 +158,0 @@ this.lemmas.map(String).join(hasCommas ? '; ' : ', ') |
Sorry, the diff of this file is not supported yet
93639
-6.31%1669
-9.1%