2024-06-07 20:17:03 +03:00
|
|
|
/**
|
|
|
|
|
* Module: Natural language model declarations.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-02-15 15:33:37 +03:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
/**
|
|
|
|
|
* Represents single unit of language Morphology.
|
|
|
|
|
*/
|
|
|
|
|
// prettier-ignore
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Grammeme = {
|
2024-06-07 20:17:03 +03:00
|
|
|
// Части речи
|
2025-03-14 20:43:30 +03:00
|
|
|
NOUN: 'NOUN', ADJF: 'ADJF', ADJS: 'ADJS', COMP: 'COMP',
|
|
|
|
|
VERB: 'VERB', INFN: 'INFN', PRTF: 'PRTF', PRTS: 'PRTS',
|
|
|
|
|
GRND: 'GRND', NUMR: 'NUMR', ADVB: 'ADVB', NPRO: 'NPRO',
|
|
|
|
|
PRED: 'PRED', PREP: 'PREP', CONJ: 'CONJ', PRCL: 'PRCL',
|
|
|
|
|
INTJ: 'INTJ',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Одушевленность
|
2025-03-14 20:43:30 +03:00
|
|
|
anim: 'anim', inan: 'inan',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Род
|
2025-03-14 20:43:30 +03:00
|
|
|
masc: 'masc', femn: 'femn', neut: 'neut',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Число
|
2025-03-14 20:43:30 +03:00
|
|
|
sing: 'sing', plur: 'plur',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Падеж (основные)
|
2025-03-14 20:43:30 +03:00
|
|
|
nomn: 'nomn', gent: 'gent', datv: 'datv',
|
|
|
|
|
accs: 'accs', ablt: 'ablt', loct: 'loct',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Совершенный / несовершенный вид
|
2025-03-14 20:43:30 +03:00
|
|
|
perf: 'perf', impf: 'impf',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Переходность
|
2025-03-14 20:43:30 +03:00
|
|
|
tran: 'tran', intr: 'intr',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Время
|
2025-03-14 20:43:30 +03:00
|
|
|
pres: 'pres', past: 'past', futr: 'futr',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Лицо
|
2025-03-14 20:43:30 +03:00
|
|
|
per1: '1per', per2: '2per', per3: '3per',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Наклонение
|
2025-03-14 20:43:30 +03:00
|
|
|
indc: 'indc', impr: 'impr',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Включение говорящего в действие
|
2025-03-14 20:43:30 +03:00
|
|
|
incl: 'incl', excl: 'excl',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Залог
|
2025-03-14 20:43:30 +03:00
|
|
|
actv: 'actv', pssv: 'pssv',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Стиль речи
|
2025-03-14 20:43:30 +03:00
|
|
|
Infr: 'Infr', // Неформальный
|
|
|
|
|
Slng: 'Slng', // Жаргон
|
|
|
|
|
Arch: 'Arch', // Устаревший
|
|
|
|
|
Litr: 'Litr', // Литературный
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
// Аббревиатура
|
2025-03-14 20:43:30 +03:00
|
|
|
Abbr: 'Abbr'
|
|
|
|
|
} as const;
|
|
|
|
|
export type Grammeme = (typeof Grammeme)[keyof typeof Grammeme];
|
|
|
|
|
export const schemaGrammeme = z.enum(Object.values(Grammeme) as [Grammeme, ...Grammeme[]]);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents part of speech language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const PartOfSpeech: Grammeme[] = [
|
2024-06-07 20:17:03 +03:00
|
|
|
Grammeme.NOUN,
|
|
|
|
|
Grammeme.ADJF,
|
|
|
|
|
Grammeme.ADJS,
|
|
|
|
|
Grammeme.COMP,
|
|
|
|
|
Grammeme.VERB,
|
|
|
|
|
Grammeme.INFN,
|
|
|
|
|
Grammeme.PRTF,
|
|
|
|
|
Grammeme.PRTS,
|
|
|
|
|
Grammeme.GRND,
|
|
|
|
|
Grammeme.ADVB,
|
|
|
|
|
Grammeme.NPRO,
|
|
|
|
|
Grammeme.PRED,
|
|
|
|
|
Grammeme.PREP,
|
|
|
|
|
Grammeme.CONJ,
|
|
|
|
|
Grammeme.PRCL,
|
|
|
|
|
Grammeme.INTJ
|
2025-03-14 20:43:30 +03:00
|
|
|
] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents gender language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Gender: Grammeme[] = [Grammeme.masc, Grammeme.femn, Grammeme.neut] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents case language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Case: Grammeme[] = [
|
|
|
|
|
Grammeme.nomn,
|
|
|
|
|
Grammeme.gent,
|
|
|
|
|
Grammeme.datv,
|
|
|
|
|
Grammeme.accs,
|
|
|
|
|
Grammeme.ablt,
|
|
|
|
|
Grammeme.loct
|
|
|
|
|
] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents plurality language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Plurality: Grammeme[] = [Grammeme.sing, Grammeme.plur] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb perfectivity language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Perfectivity: Grammeme[] = [Grammeme.perf, Grammeme.impf] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb transitivity language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Transitivity: Grammeme[] = [Grammeme.tran, Grammeme.intr] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb mood language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Mood: Grammeme[] = [Grammeme.indc, Grammeme.impr] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb self-inclusion language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Inclusion: Grammeme[] = [Grammeme.incl, Grammeme.excl] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb voice language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Voice: Grammeme[] = [Grammeme.actv, Grammeme.pssv] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb tense language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Tense: Grammeme[] = [Grammeme.pres, Grammeme.past, Grammeme.futr] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents verb person language concept.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of mutually exclusive {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const Person: Grammeme[] = [Grammeme.per1, Grammeme.per2, Grammeme.per3] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents complete list of language concepts.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of lists of {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const GrammemeGroups: Grammeme[][] = [
|
2024-06-07 20:17:03 +03:00
|
|
|
PartOfSpeech,
|
|
|
|
|
Gender,
|
|
|
|
|
Case,
|
|
|
|
|
Plurality,
|
|
|
|
|
Perfectivity,
|
|
|
|
|
Transitivity,
|
|
|
|
|
Mood,
|
|
|
|
|
Inclusion,
|
|
|
|
|
Voice,
|
|
|
|
|
Tense,
|
|
|
|
|
Person
|
2025-03-14 20:43:30 +03:00
|
|
|
] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents NOUN-ish list of language concepts.
|
|
|
|
|
*
|
|
|
|
|
* Represented concepts can be target of inflection or coalition in a sentence.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of lists of {@link Grammeme}s.
|
|
|
|
|
*/
|
2025-03-14 20:43:30 +03:00
|
|
|
export const NounGrams: Grammeme[] = [Grammeme.NOUN, Grammeme.ADJF, Grammeme.ADJS, ...Case, ...Plurality] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents VERB-ish list of language concepts.
|
|
|
|
|
*
|
|
|
|
|
* Represented concepts can be target of inflection or coalition in a sentence.
|
|
|
|
|
*
|
|
|
|
|
* Implemented as a list of lists of {@link Grammeme}s.
|
|
|
|
|
*/
|
|
|
|
|
export const VerbGrams = [
|
|
|
|
|
Grammeme.VERB,
|
|
|
|
|
Grammeme.INFN,
|
|
|
|
|
Grammeme.PRTF,
|
|
|
|
|
Grammeme.PRTS,
|
|
|
|
|
...Perfectivity,
|
|
|
|
|
...Transitivity,
|
|
|
|
|
...Mood,
|
|
|
|
|
...Inclusion,
|
|
|
|
|
...Voice,
|
|
|
|
|
...Tense,
|
|
|
|
|
...Person
|
2025-03-14 20:43:30 +03:00
|
|
|
] as const;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents specific wordform attached to {@link Grammeme}s.
|
|
|
|
|
*/
|
|
|
|
|
export interface IWordForm {
|
|
|
|
|
text: string;
|
2025-03-14 20:43:30 +03:00
|
|
|
grams: Grammeme[];
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
/**
|
|
|
|
|
* Represents list of {@link Grammeme}s available in reference construction.
|
|
|
|
|
*/
|
|
|
|
|
// prettier-ignore
|
|
|
|
|
export const supportedGrammemes = [
|
|
|
|
|
Grammeme.sing, Grammeme.plur,
|
|
|
|
|
Grammeme.nomn, Grammeme.gent, Grammeme.datv,
|
|
|
|
|
Grammeme.accs, Grammeme.ablt, Grammeme.loct,
|
2025-03-14 20:43:30 +03:00
|
|
|
] as const;
|
2025-02-10 01:32:16 +03:00
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
// ====== Reference resolution =====
|
|
|
|
|
|
2025-03-14 20:43:30 +03:00
|
|
|
/** Represents text reference type. */
|
|
|
|
|
export const ReferenceType = {
|
|
|
|
|
ENTITY: 'entity',
|
|
|
|
|
SYNTACTIC: 'syntax'
|
|
|
|
|
} as const;
|
|
|
|
|
export type ReferenceType = (typeof ReferenceType)[keyof typeof ReferenceType];
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-03-14 20:43:30 +03:00
|
|
|
/** Represents entity reference payload. */
|
2024-06-07 20:17:03 +03:00
|
|
|
export interface IEntityReference {
|
|
|
|
|
entity: string;
|
|
|
|
|
form: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 20:43:30 +03:00
|
|
|
/** Represents syntactic reference payload. */
|
2024-06-07 20:17:03 +03:00
|
|
|
export interface ISyntacticReference {
|
|
|
|
|
offset: number;
|
|
|
|
|
nominal: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 20:43:30 +03:00
|
|
|
export const schemaReferenceType = z.enum(Object.values(ReferenceType) as [ReferenceType, ...ReferenceType[]]);
|
|
|
|
|
|
2025-03-02 19:07:12 +03:00
|
|
|
export const schemaReference = z.strictObject({
|
2025-03-14 20:43:30 +03:00
|
|
|
type: schemaReferenceType,
|
2025-02-15 15:33:37 +03:00
|
|
|
data: z.union([
|
2025-03-02 19:07:12 +03:00
|
|
|
z.strictObject({ entity: z.string(), form: z.string() }),
|
|
|
|
|
z.strictObject({ offset: z.number(), nominal: z.string() })
|
2025-02-15 15:33:37 +03:00
|
|
|
])
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-14 20:43:30 +03:00
|
|
|
/** Represents abstract reference data. */
|
2025-02-15 15:33:37 +03:00
|
|
|
export type IReference = z.infer<typeof schemaReference>;
|