Embed arguments in typification

update pyconcept to 1.3.0
This commit is contained in:
IRBorisov 2023-08-06 23:13:45 +03:00
parent 254499daa4
commit 6e81c13be5
8 changed files with 55 additions and 23 deletions

View File

@ -3,9 +3,9 @@
# Application settings # Application settings
SECRET_KEY=django-insecure-)rq@!&v7l2r%2%q#n!uq+zk@=&yc0^&ql^7%2!%9u)vt1x&j=d SECRET_KEY=django-insecure-)rq@!&v7l2r%2%q#n!uq+zk@=&yc0^&ql^7%2!%9u)vt1x&j=d
ALLOWED_HOSTS=rs.acconcept.ru;localhost ALLOWED_HOSTS=rs.acconcept.ru;localhost;portal.acconcept.ru
CSRF_TRUSTED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000 CSRF_TRUSTED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000;http://portal.acconcept.ru:3000
CORS_ALLOWED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000 CORS_ALLOWED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000;http://portal.acconcept.ru:3000
# File locations # File locations

View File

@ -34,6 +34,7 @@ class TestIntegrations(TestCase):
schema = self._default_schema() schema = self._default_schema()
out1 = json.loads(pc.check_expression(schema, 'X1=X1')) out1 = json.loads(pc.check_expression(schema, 'X1=X1'))
self.assertTrue(out1['parseResult']) self.assertTrue(out1['parseResult'])
self.assertEqual(len(out1['args']), 0)
out2 = json.loads(pc.check_expression(schema, 'X1=X2')) out2 = json.loads(pc.check_expression(schema, 'X1=X2'))
self.assertFalse(out2['parseResult']) self.assertFalse(out2['parseResult'])

View File

@ -9,7 +9,7 @@ import TextArea from '../../components/Common/TextArea';
import { DumpBinIcon, HelpIcon, SaveIcon, SmallPlusIcon } from '../../components/Icons'; import { DumpBinIcon, HelpIcon, SaveIcon, SmallPlusIcon } from '../../components/Icons';
import { useRSForm } from '../../context/RSFormContext'; import { useRSForm } from '../../context/RSFormContext';
import { type CstType, EditMode, ICstUpdateData, SyntaxTree } from '../../utils/models'; import { type CstType, EditMode, ICstUpdateData, SyntaxTree } from '../../utils/models';
import { getCstTypeLabel, mapStatusInfo } from '../../utils/staticUI'; import { getCstTypeLabel, getCstTypificationLabel, mapStatusInfo } from '../../utils/staticUI';
import EditorRSExpression from './EditorRSExpression'; import EditorRSExpression from './EditorRSExpression';
import ViewSideConstituents from './elements/ViewSideConstituents'; import ViewSideConstituents from './elements/ViewSideConstituents';
@ -64,7 +64,7 @@ function EditorConstituenta({ activeID, onShowAST, onCreateCst, onOpenEdit, onDe
setTerm(activeCst.term?.raw ?? ''); setTerm(activeCst.term?.raw ?? '');
setTextDefinition(activeCst.definition?.text?.raw ?? ''); setTextDefinition(activeCst.definition?.text?.raw ?? '');
setExpression(activeCst.definition?.formal ?? ''); setExpression(activeCst.definition?.formal ?? '');
setTypification(activeCst?.parse?.typification || 'N/A'); setTypification(activeCst ? getCstTypificationLabel(activeCst) : 'N/A');
} else if (schema && schema?.items.length > 0) { } else if (schema && schema?.items.length > 0) {
onOpenEdit(schema.items[0].id); onOpenEdit(schema.items[0].id);
} }

View File

@ -10,7 +10,7 @@ import { useRSForm } from '../../context/RSFormContext';
import { useConceptTheme } from '../../context/ThemeContext'; import { useConceptTheme } from '../../context/ThemeContext';
import { prefixes } from '../../utils/constants'; import { prefixes } from '../../utils/constants';
import { CstType, IConstituenta, ICstMovetoData } from '../../utils/models' import { CstType, IConstituenta, ICstMovetoData } from '../../utils/models'
import { getCstTypePrefix, getCstTypeShortcut, getTypeLabel, mapStatusInfo } from '../../utils/staticUI'; import { getCstTypePrefix, getCstTypeShortcut, getCstTypificationLabel, mapStatusInfo } from '../../utils/staticUI';
interface EditorItemsProps { interface EditorItemsProps {
onOpenEdit: (cstID: number) => void onOpenEdit: (cstID: number) => void
@ -192,7 +192,7 @@ function EditorItems({ onOpenEdit, onCreateCst, onDeleteCst }: EditorItemsProps)
{ {
name: 'Тип', name: 'Тип',
id: 'type', id: 'type',
cell: (cst: IConstituenta) => <div style={{ fontSize: 12 }}>{getTypeLabel(cst)}</div>, cell: (cst: IConstituenta) => <div style={{ fontSize: 12 }}>{getCstTypificationLabel(cst)}</div>,
width: '140px', width: '140px',
minWidth: '100px', minWidth: '100px',
maxWidth: '140px', maxWidth: '140px',

View File

@ -8,7 +8,7 @@ import { useRSForm } from '../../context/RSFormContext';
import useCheckExpression from '../../hooks/useCheckExpression'; import useCheckExpression from '../../hooks/useCheckExpression';
import { TokenID } from '../../utils/enums'; import { TokenID } from '../../utils/enums';
import { IConstituenta, IRSErrorDescription, SyntaxTree } from '../../utils/models'; import { IConstituenta, IRSErrorDescription, SyntaxTree } from '../../utils/models';
import { getCstExpressionPrefix } from '../../utils/staticUI'; import { getCstExpressionPrefix, getTypificationLabel } from '../../utils/staticUI';
import ParsingResult from './elements/ParsingResult'; import ParsingResult from './elements/ParsingResult';
import RSLocalButton from './elements/RSLocalButton'; import RSLocalButton from './elements/RSLocalButton';
import RSTokenButton from './elements/RSTokenButton'; import RSTokenButton from './elements/RSTokenButton';
@ -67,7 +67,11 @@ function EditorRSExpression({
} }
expressionCtrl.current!.focus(); expressionCtrl.current!.focus();
setIsModified(false); setIsModified(false);
setTypification(parse.typification); setTypification(getTypificationLabel({
isValid: parse.parseResult,
resultType: parse.typification,
args: parse.args
}));
}); });
} }

View File

@ -1,6 +1,6 @@
import ConceptTooltip from '../../../components/Common/ConceptTooltip'; import ConceptTooltip from '../../../components/Common/ConceptTooltip';
import { IConstituenta } from '../../../utils/models'; import { IConstituenta } from '../../../utils/models';
import { getTypeLabel } from '../../../utils/staticUI'; import { getCstTypificationLabel } from '../../../utils/staticUI';
interface ConstituentaTooltipProps { interface ConstituentaTooltipProps {
data: IConstituenta data: IConstituenta
@ -14,7 +14,7 @@ function ConstituentaTooltip({ data, anchor }: ConstituentaTooltipProps) {
className='max-w-[25rem] min-w-[25rem]' className='max-w-[25rem] min-w-[25rem]'
> >
<h1>Конституента {data.alias}</h1> <h1>Конституента {data.alias}</h1>
<p><b>Типизация: </b>{getTypeLabel(data)}</p> <p><b>Типизация: </b>{getCstTypificationLabel(data)}</p>
<p><b>Термин: </b>{data.term.resolved || data.term.raw}</p> <p><b>Термин: </b>{data.term.resolved || data.term.raw}</p>
{data.definition.formal && <p><b>Выражение: </b>{data.definition.formal}</p>} {data.definition.formal && <p><b>Выражение: </b>{data.definition.formal}</p>}
{data.definition.text.resolved && <p><b>Определение: </b>{data.definition.text.resolved}</p>} {data.definition.text.resolved && <p><b>Определение: </b>{data.definition.text.resolved}</p>}

View File

@ -64,6 +64,11 @@ export interface ISyntaxTreeNode {
} }
export type SyntaxTree = ISyntaxTreeNode[] export type SyntaxTree = ISyntaxTreeNode[]
export interface IFunctionArg {
alias: string
typification: string
}
export interface IExpressionParse { export interface IExpressionParse {
parseResult: boolean parseResult: boolean
syntax: Syntax syntax: Syntax
@ -72,6 +77,7 @@ export interface IExpressionParse {
errors: IRSErrorDescription[] errors: IRSErrorDescription[]
astText: string astText: string
ast: SyntaxTree ast: SyntaxTree
args: IFunctionArg[]
} }
export interface IRSExpression { export interface IRSExpression {
@ -113,6 +119,7 @@ export interface IConstituenta {
valueClass: ValueClass valueClass: ValueClass
typification: string typification: string
syntaxTree: string syntaxTree: string
args: IFunctionArg[]
} }
} }

View File

@ -1,7 +1,10 @@
import { LayoutTypes } from 'reagraph'; import { LayoutTypes } from 'reagraph';
import { resolveErrorClass,RSErrorClass, RSErrorType, TokenID } from './enums'; import { resolveErrorClass,RSErrorClass, RSErrorType, TokenID } from './enums';
import { CstMatchMode,CstType, DependencyMode,ExpressionStatus, type IConstituenta, IRSErrorDescription,type IRSForm, ISyntaxTreeNode,ParsingStatus, ValueClass } from './models'; import { CstMatchMode, CstType, DependencyMode,ExpressionStatus, IConstituenta,
IFunctionArg,IRSErrorDescription, IRSForm,
ISyntaxTreeNode, ParsingStatus, ValueClass
} from './models';
export interface IRSButtonData { export interface IRSButtonData {
text: string text: string
@ -14,16 +17,6 @@ export interface IStatusInfo {
tooltip: string tooltip: string
} }
export function getTypeLabel(cst: IConstituenta): string {
if (cst.parse?.typification) {
return cst.parse.typification;
}
if (cst.parse?.status !== ParsingStatus.VERIFIED) {
return 'N/A';
}
return 'Логический';
}
export function getCstDescription(cst: IConstituenta): string { export function getCstDescription(cst: IConstituenta): string {
if (cst.cstType === CstType.STRUCTURED) { if (cst.cstType === CstType.STRUCTURED) {
return ( return (
@ -381,7 +374,8 @@ export function getMockConstituenta(id: number, alias: string, type: CstType, co
status: ParsingStatus.INCORRECT, status: ParsingStatus.INCORRECT,
valueClass: ValueClass.INVALID, valueClass: ValueClass.INVALID,
typification: 'N/A', typification: 'N/A',
syntaxTree: '' syntaxTree: '',
args: []
} }
}; };
} }
@ -394,6 +388,32 @@ export function getCloneTitle(schema: IRSForm): string {
} }
} }
export function getTypificationLabel({isValid, resultType, args}: {
isValid: boolean,
resultType: string,
args: IFunctionArg[]
}): string {
if (!isValid) {
return 'N/A';
}
if (resultType === '') {
resultType = 'Логический'
}
if (args.length === 0) {
return resultType;
}
const argsText = args.map(arg => arg.typification).join(', ');
return `${resultType} 🠔 [${argsText}]`;
}
export function getCstTypificationLabel(cst: IConstituenta): string {
return getTypificationLabel({
isValid: cst.parse.status === ParsingStatus.VERIFIED,
resultType: cst.parse.typification,
args: cst.parse.args
});
}
export function getRSErrorPrefix(error: IRSErrorDescription): string { export function getRSErrorPrefix(error: IRSErrorDescription): string {
const id = error.errorType.toString(16) const id = error.errorType.toString(16)
switch(resolveErrorClass(error.errorType)) { switch(resolveErrorClass(error.errorType)) {