ConceptPortal-public/rsconcept/frontend/src/models/language.ts

294 lines
6.2 KiB
TypeScript
Raw Normal View History

2023-09-27 23:36:51 +03:00
/**
* Module: Natural language model declarations.
*/
2023-09-11 20:31:54 +03:00
2023-09-25 14:17:52 +03:00
/**
* Represents API result for text output.
2023-12-28 14:04:44 +03:00
*/
2023-09-25 14:17:52 +03:00
export interface ITextResult {
2023-12-28 14:04:44 +03:00
result: string;
2023-09-25 14:17:52 +03:00
}
2023-09-21 23:09:51 +03:00
/**
* Represents single unit of language Morphology.
2023-12-28 14:04:44 +03:00
*/
// prettier-ignore
2023-09-19 17:55:17 +03:00
export enum Grammeme {
2023-09-14 16:53:38 +03:00
// Части речи
2023-09-21 23:09:51 +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',
2023-09-14 16:53:38 +03:00
INTJ = 'INTJ',
// Одушевленность
2023-09-21 23:09:51 +03:00
anim = 'anim', inan = 'inan',
2023-09-14 16:53:38 +03:00
// Род
2023-09-21 23:09:51 +03:00
masc = 'masc', femn = 'femn', neut = 'neut',
2023-09-14 16:53:38 +03:00
// Число
2023-09-21 23:09:51 +03:00
sing = 'sing', plur = 'plur',
2023-09-14 16:53:38 +03:00
// Падеж (основные)
2023-09-21 23:09:51 +03:00
nomn = 'nomn', gent = 'gent', datv = 'datv',
accs = 'accs', ablt = 'ablt', loct = 'loct',
2023-09-14 16:53:38 +03:00
// Совершенный / несовершенный вид
2023-09-21 23:09:51 +03:00
perf = 'perf', impf = 'impf',
2023-09-14 16:53:38 +03:00
// Переходность
2023-09-21 23:09:51 +03:00
tran = 'tran', intr = 'intr',
2023-09-14 16:53:38 +03:00
// Время
2023-09-21 23:09:51 +03:00
pres = 'pres', past = 'past', futr = 'futr',
2023-09-14 16:53:38 +03:00
// Лицо
2023-09-21 23:09:51 +03:00
per1 = '1per', per2 = '2per', per3 = '3per',
2023-09-14 16:53:38 +03:00
// Наклонение
2023-09-21 23:09:51 +03:00
indc = 'indc', impr = 'impr',
2023-09-14 16:53:38 +03:00
// Включение говорящего в действие
2023-09-21 23:09:51 +03:00
incl = 'incl', excl = 'excl',
2023-09-14 16:53:38 +03:00
// Залог
2023-09-21 23:09:51 +03:00
actv = 'actv', pssv = 'pssv',
2023-09-14 16:53:38 +03:00
// Стиль речи
Infr = 'Infr', // Неформальный
Slng = 'Slng', // Жаргон
Arch = 'Arch', // Устаревший
Litr = 'Litr', // Литературный
// Аббревиатура
Abbr = 'Abbr'
}
2023-09-21 23:09:51 +03:00
/**
* Represents part of speech language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
2023-09-14 16:53:38 +03:00
export const PartOfSpeech = [
2023-12-28 14:04:44 +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
2023-09-19 17:55:17 +03:00
];
2023-09-14 16:53:38 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents gender language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Gender = [Grammeme.masc, Grammeme.femn, Grammeme.neut];
2023-09-14 16:53:38 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents case language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Case = [Grammeme.nomn, Grammeme.gent, Grammeme.datv, Grammeme.accs, Grammeme.ablt, Grammeme.loct];
2023-09-19 17:55:17 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents plurality language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Plurality = [Grammeme.sing, Grammeme.plur];
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents verb perfectivity language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Perfectivity = [Grammeme.perf, Grammeme.impf];
2023-09-21 23:09:51 +03:00
/**
* Represents verb transitivity language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Transitivity = [Grammeme.tran, Grammeme.intr];
2023-09-21 23:09:51 +03:00
/**
* Represents verb mood language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Mood = [Grammeme.indc, Grammeme.impr];
2023-09-21 23:09:51 +03:00
/**
* Represents verb self-inclusion language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Inclusion = [Grammeme.incl, Grammeme.excl];
2023-09-21 23:09:51 +03:00
/**
* Represents verb voice language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Voice = [Grammeme.actv, Grammeme.pssv];
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents verb tense language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Tense = [Grammeme.pres, Grammeme.past, Grammeme.futr];
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents verb person language concept.
2023-12-28 14:04:44 +03:00
*
2023-12-26 14:23:51 +03:00
* Implemented as a list of mutually exclusive {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const Person = [Grammeme.per1, Grammeme.per2, Grammeme.per3];
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents complete list of language concepts.
2023-12-28 14:04:44 +03:00
*
2023-09-21 23:09:51 +03:00
* Implemented as a list of lists of {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
2023-09-21 14:58:01 +03:00
export const GrammemeGroups = [
2023-12-28 14:04:44 +03:00
PartOfSpeech,
Gender,
Case,
Plurality,
Perfectivity,
Transitivity,
Mood,
Inclusion,
Voice,
Tense,
Person
2023-09-21 14:58:01 +03:00
];
2023-09-21 23:09:51 +03:00
/**
* Represents NOUN-ish list of language concepts.
2023-12-28 14:04:44 +03:00
*
2023-09-21 23:09:51 +03:00
* Represented concepts can be target of inflection or coalition in a sentence.
2023-12-28 14:04:44 +03:00
*
2023-09-21 23:09:51 +03:00
* Implemented as a list of lists of {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
export const NounGrams = [Grammeme.NOUN, Grammeme.ADJF, Grammeme.ADJS, ...Case, ...Plurality];
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents VERB-ish list of language concepts.
2023-12-28 14:04:44 +03:00
*
2023-09-21 23:09:51 +03:00
* Represented concepts can be target of inflection or coalition in a sentence.
2023-12-28 14:04:44 +03:00
*
2023-09-21 23:09:51 +03:00
* Implemented as a list of lists of {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
2023-09-21 14:58:01 +03:00
export const VerbGrams = [
2023-12-28 14:04:44 +03:00
Grammeme.VERB,
Grammeme.INFN,
Grammeme.PRTF,
Grammeme.PRTS,
2023-09-21 14:58:01 +03:00
...Perfectivity,
...Transitivity,
...Mood,
...Inclusion,
...Voice,
...Tense,
...Person
];
2023-09-21 23:09:51 +03:00
/**
* Represents {@link Grammeme} parse data.
2023-12-28 14:04:44 +03:00
*/
2023-09-27 23:36:51 +03:00
export type GramData = Grammeme | string;
2023-09-21 14:58:01 +03:00
2023-09-21 23:09:51 +03:00
/**
* Represents specific wordform attached to {@link Grammeme}s.
2023-12-28 14:04:44 +03:00
*/
2023-09-21 23:09:51 +03:00
export interface IWordForm {
2023-12-28 14:04:44 +03:00
text: string;
grams: GramData[];
2023-09-21 23:09:51 +03:00
}
2023-09-25 14:17:52 +03:00
/**
* Represents wordform data used for backend communication.
2023-12-28 14:04:44 +03:00
*/
2023-09-25 14:17:52 +03:00
export interface IWordFormPlain {
2023-12-28 14:04:44 +03:00
text: string;
grams: string;
2023-09-25 14:17:52 +03:00
}
/**
* Represents lexeme response containing multiple {@link Wordform}s.
2023-12-28 14:04:44 +03:00
*/
2023-09-25 14:17:52 +03:00
export interface ILexemeData {
2023-12-28 14:04:44 +03:00
items: IWordFormPlain[];
2023-09-25 14:17:52 +03:00
}
2023-09-19 17:55:17 +03:00
// ====== Reference resolution =====
2023-09-25 14:17:52 +03:00
/**
* Represents text request.
2023-12-28 14:04:44 +03:00
*/
2023-09-25 14:17:52 +03:00
export interface ITextRequest {
2023-12-28 14:04:44 +03:00
text: string;
2023-09-19 17:55:17 +03:00
}
2023-09-25 14:17:52 +03:00
/**
* Represents text reference type.
2023-12-28 14:04:44 +03:00
*/
2023-09-19 17:55:17 +03:00
export enum ReferenceType {
ENTITY = 'entity',
SYNTACTIC = 'syntax'
}
2023-09-21 14:58:01 +03:00
2023-09-25 14:17:52 +03:00
/**
* Represents entity reference payload.
2023-12-28 14:04:44 +03:00
*/
2023-09-19 17:55:17 +03:00
export interface IEntityReference {
2023-12-28 14:04:44 +03:00
entity: string;
form: string;
2023-09-19 17:55:17 +03:00
}
2023-09-25 14:17:52 +03:00
/**
* Represents syntactic reference payload.
2023-12-28 14:04:44 +03:00
*/
2023-09-19 17:55:17 +03:00
export interface ISyntacticReference {
2023-12-28 14:04:44 +03:00
offset: number;
nominal: string;
2023-09-19 17:55:17 +03:00
}
2023-09-25 14:17:52 +03:00
/**
* Represents text 0-indexed position inside another text.
2023-12-28 14:04:44 +03:00
*/
2023-09-19 17:55:17 +03:00
export interface ITextPosition {
2023-12-28 14:04:44 +03:00
start: number;
finish: number;
2023-09-19 17:55:17 +03:00
}
2023-09-25 14:17:52 +03:00
/**
2023-09-29 15:33:32 +03:00
* Represents abstract reference data.
2023-12-28 14:04:44 +03:00
*/
2023-09-29 15:33:32 +03:00
export interface IReference {
2023-12-28 14:04:44 +03:00
type: ReferenceType;
data: IEntityReference | ISyntacticReference;
2023-09-29 15:33:32 +03:00
}
/**
* Represents single resolved reference data.
2023-12-28 14:04:44 +03:00
*/
2023-09-29 15:33:32 +03:00
export interface IResolvedReference extends IReference {
2023-12-28 14:04:44 +03:00
pos_input: ITextPosition;
pos_output: ITextPosition;
2023-09-19 17:55:17 +03:00
}