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

295 lines
6.3 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.
*/
export interface ITextResult {
result: string
}
2023-09-21 23:09:51 +03:00
/**
* Represents single unit of language Morphology.
*/
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.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-14 16:53:38 +03:00
export const PartOfSpeech = [
2023-09-19 17:55:17 +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,
2023-09-21 14:58:01 +03:00
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.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-14 16:53:38 +03:00
export const Gender = [
2023-09-19 17:55:17 +03:00
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.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-14 16:53:38 +03:00
export const Case = [
2023-09-19 17:55:17 +03:00
Grammeme.nomn, Grammeme.gent, Grammeme.datv,
Grammeme.accs, Grammeme.ablt, Grammeme.loct
];
2023-09-21 23:09:51 +03:00
/**
* Represents plurality language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Plurality = [ Grammeme.sing, Grammeme.plur ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb perfectivity language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Perfectivity = [ Grammeme.perf, Grammeme.impf ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb transitivity language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Transitivity = [ Grammeme.tran, Grammeme.intr ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb mood language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Mood = [ Grammeme.indc, Grammeme.impr ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb self-inclusion language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Inclusion = [ Grammeme.incl, Grammeme.excl ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb voice language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Voice = [ Grammeme.actv, Grammeme.pssv ];
2023-09-21 23:09:51 +03:00
/**
* Represents verb tense language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Tense = [
Grammeme.pres,
Grammeme.past,
Grammeme.futr
];
2023-09-21 23:09:51 +03:00
/**
* Represents verb person language concept.
*
* Implemented as a list of mututally exclusive {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const Person = [
Grammeme.per1,
Grammeme.per2,
Grammeme.per3
];
2023-09-21 23:09:51 +03:00
/**
* Represents complete list of language concepts.
*
* Implemented as a list of lists of {@link Grammeme}s.
*/
2023-09-21 14:58:01 +03:00
export const GrammemeGroups = [
PartOfSpeech, Gender, Case, Plurality, Perfectivity,
Transitivity, Mood, Inclusion, Voice, Tense, Person
];
2023-09-21 23:09:51 +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.
*/
2023-09-21 14:58:01 +03:00
export const NounGrams = [
Grammeme.NOUN, Grammeme.ADJF, Grammeme.ADJS,
...Case,
...Plurality
];
2023-09-21 23:09:51 +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.
*/
2023-09-21 14:58:01 +03:00
export const VerbGrams = [
Grammeme.VERB, Grammeme.INFN, Grammeme.PRTF, Grammeme.PRTS,
...Perfectivity,
...Transitivity,
...Mood,
...Inclusion,
...Voice,
...Tense,
...Person
];
2023-09-21 23:09:51 +03:00
/**
* Represents {@link Grammeme} parse data.
*/
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.
*/
export interface IWordForm {
text: string
2023-09-27 23:36:51 +03:00
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.
*/
export interface IWordFormPlain {
text: string
grams: string
}
/**
* Represents lexeme response containing multiple {@link Wordform}s.
*/
export interface ILexemeData {
items: IWordFormPlain[]
}
2023-09-19 17:55:17 +03:00
// ====== Reference resolution =====
2023-09-25 14:17:52 +03:00
/**
* Represents text request.
*/
export interface ITextRequest {
2023-09-19 17:55:17 +03:00
text: string
}
2023-09-25 14:17:52 +03:00
/**
* Represents text reference type.
*/
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-09-19 17:55:17 +03:00
export interface IEntityReference {
entity: string
form: string
}
2023-09-25 14:17:52 +03:00
/**
* Represents syntactic reference payload.
*/
2023-09-19 17:55:17 +03:00
export interface ISyntacticReference {
offset: number
nominal: string
}
2023-09-25 14:17:52 +03:00
/**
* Represents text 0-indexed position inside another text.
*/
2023-09-19 17:55:17 +03:00
export interface ITextPosition {
start: number
finish: number
}
2023-09-25 14:17:52 +03:00
/**
2023-09-29 15:33:32 +03:00
* Represents abstract reference data.
2023-09-25 14:17:52 +03:00
*/
2023-09-29 15:33:32 +03:00
export interface IReference {
2023-09-19 17:55:17 +03:00
type: ReferenceType
data: IEntityReference | ISyntacticReference
2023-09-29 15:33:32 +03:00
}
/**
* Represents single resolved reference data.
*/
export interface IResolvedReference extends IReference {
2023-09-19 17:55:17 +03:00
pos_input: ITextPosition
pos_output: ITextPosition
}
2023-09-25 14:17:52 +03:00
/**
* Represents resolved references data for the whole text.
*/
export interface IResolutionData {
2023-09-19 17:55:17 +03:00
input: string
output: string
refs: IResolvedReference[]
}