Skip to content

Commit

Permalink
1952 validation label language missing pos missing (#1995)
Browse files Browse the repository at this point in the history
* add basic api client nodejs -> python

* add server validation for empty ConceptPartOfSpeech/ActionPartOfSpeech

* add validation of empty language in entity + test

* remove pos/lang check from isValid method

* add PSM/LM entity warnings + tests

* clean imports

* add warnings to entity section

---------

Co-authored-by: Petr Hanak <[email protected]>
Co-authored-by: Adam Mertel <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent cb02214 commit 3041ea1
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/client/src/components/basic/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export const Message: React.FC<Message> = ({ warning, entities }) => {
);
case WarningTypeEnums.MAEE:
return <b>Missing action/event equivalent</b>;
case WarningTypeEnums.LM:
return <b>Label language missing</b>;
case WarningTypeEnums.PSM:
return <b>Part of speech missing</b>;
default:
return <></>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,19 @@ export const EntityDetail: React.FC<EntityDetail> = ({ detailId }) => {

<StyledDetailWrapper>
{/* form section */}
<StyledDetailSection $firstSection>
<StyledDetailSectionContent $firstSection>
<StyledDetailSection firstSection>
<StyledDetailSectionContent firstSection>
<StyledDetailWarnings>
{entity.warnings &&
entity.warnings
.filter(
(w) =>
w.position?.section === IWarningPositionSection.Entity
)
.map((warning, key) => {
return <Message key={key} warning={warning} />;
})}
</StyledDetailWarnings>
<EntityDetailFormSection
entity={entity}
userCanEdit={userCanEdit}
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/models/entity/entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Db } from "@service/rethink";
import Entity from "./entity";
import Statement, {
StatementActant,
StatementAction,
StatementTerritory,
} from "@models/statement/statement";
import { clean } from "@modules/common.test";
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/models/entity/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
ModelNotValidError,
} from "@shared/types/errors";
import User from "@models/user/user";
import emitter from "@models/events/emitter";
import { EventTypes } from "@models/events/types";
import Prop from "@models/prop/prop";
import { findEntityById } from "@service/shorthands";
import { IRequest } from "../../custom_typings/request";
Expand Down
74 changes: 74 additions & 0 deletions packages/server/src/models/entity/warnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { clean } from "@modules/common.test";
import EntityWarnings from "./warnings";
import { prepareRelation } from "@models/relation/relation.test";
import Action from "@models/action/action";
import Concept from "@models/concept/concept";

describe("models/entity/warnings", function () {
describe("test hasSCLM", function () {
Expand Down Expand Up @@ -294,6 +295,64 @@ describe("models/entity/warnings", function () {
});
});

describe("test hasPSM", function () {
const db = new Db();
const conceptEntityWithEmptyPos = new Concept({
data: { pos: EntityEnums.ConceptPartOfSpeech.Empty },
});
const conceptEntityWithoutEmptyPos = new Concept({
data: { pos: EntityEnums.ConceptPartOfSpeech.Adj },
});
const [, actionInvalid] = prepareEntity(EntityEnums.Class.Action);

beforeAll(async () => {
await db.initDb();
await conceptEntityWithEmptyPos.save(db.connection);
await conceptEntityWithoutEmptyPos.save(db.connection);
await actionInvalid.save(db.connection);
});

afterAll(async () => {
await clean(db);
});

it("should ignore PSM for non-concept entity", async () => {
const psm = await new EntityWarnings(
actionInvalid.id,
actionInvalid.class
).hasPSM(db.connection);
expect(psm).toBeFalsy();
});

it("should have PSM for concept entity with empty pos", async () => {
const psm = await new EntityWarnings(
conceptEntityWithEmptyPos.id,
conceptEntityWithEmptyPos.class
).hasPSM(db.connection);
expect(psm).toBeTruthy();
});

it("should have not PSM for concept entity with filled pos", async () => {
const psm = await new EntityWarnings(
conceptEntityWithoutEmptyPos.id,
conceptEntityWithoutEmptyPos.class
).hasPSM(db.connection);
expect(psm).toBeFalsy();
});
});

describe("test hasLM", function () {
const db = new Db();
const [, actionWithEmptyLanguage] = prepareEntity(EntityEnums.Class.Action);
actionWithEmptyLanguage.language = EntityEnums.Language.Empty;
const [, conceptWithSetLanguage] = prepareEntity(EntityEnums.Class.Concept);
conceptWithSetLanguage.language = EntityEnums.Language.English;

beforeAll(async () => {
await db.initDb();
await actionWithEmptyLanguage.save(db.connection);
await conceptWithSetLanguage.save(db.connection);

describe("test VETV", function () {
const db = new Db();

Expand Down Expand Up @@ -339,6 +398,21 @@ describe("models/entity/warnings", function () {
await clean(db);
});

it("should have LM for entity without language", async () => {
const psm = await new EntityWarnings(
actionWithEmptyLanguage.id,
actionWithEmptyLanguage.class
).hasLM(db.connection);
expect(psm).toBeTruthy();
});

it("should have not LM for entity with language", async () => {
const psm = await new EntityWarnings(
conceptWithSetLanguage.id,
conceptWithSetLanguage.class
).hasLM(db.connection);
expect(psm).toBeFalsy();

it("should return 0 warnings", async () => {
const warnings = await new EntityWarnings(
actionEntity0.id,
Expand Down
64 changes: 60 additions & 4 deletions packages/server/src/models/entity/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Relation from "@models/relation/relation";
import Superclass from "@models/relation/superclass";
import { findEntityById } from "@service/shorthands";
import { EntityEnums, RelationEnums, WarningTypeEnums } from "@shared/enums";
import { IAction, IWarning } from "@shared/types";
import { IAction, IConcept, IWarning } from "@shared/types";
import { IActionValency } from "@shared/types/action";
import { InternalServerError } from "@shared/types/errors";
import { IWarningPositionSection } from "@shared/types/warning";
Expand Down Expand Up @@ -71,9 +71,19 @@ export default class EntityWarnings {
warnings.push(maeeWarning);
}

const psmWarning = await this.hasPSM(conn);
if (psmWarning) {
warnings.push(psmWarning);
}

const lmWarning = await this.hasLM(conn);
if (lmWarning) {
warnings.push(lmWarning);

const vetmWarnings = await this.hasVETM(conn);
if (vetmWarnings) {
vetmWarnings.forEach((w) => warnings.push(w));

}

return warnings;
Expand Down Expand Up @@ -101,9 +111,9 @@ export default class EntityWarnings {
return gotSCL
? null
: this.newWarning(
WarningTypeEnums.SCLM,
IWarningPositionSection.Relations
);
WarningTypeEnums.SCLM,
IWarningPositionSection.Relations
);
}

/**
Expand Down Expand Up @@ -306,6 +316,52 @@ export default class EntityWarnings {
return null;
}

/**
* Tests if there is PSM warning and returns it
* @param conn
* @returns
*/
async hasPSM(conn: Connection): Promise<IWarning | null> {
if (this.class !== EntityEnums.Class.Concept) {
return null;
}

const concept = await findEntityById<IConcept>(conn, this.entityId);

if (
!concept ||
concept.data.pos === EntityEnums.ConceptPartOfSpeech.Empty
) {
return this.newWarning(
WarningTypeEnums.PSM,
IWarningPositionSection.Entity
);
}

return null;
}

/**
* Tests if there is LM warning and returns it
* @param conn
* @returns
*/
async hasLM(conn: Connection): Promise<IWarning | null> {
const entity = await findEntityById(conn, this.entityId);

if (
!entity ||
entity.language === EntityEnums.Language.Empty
) {
return this.newWarning(
WarningTypeEnums.LM,
IWarningPositionSection.Entity
);
}

return null;
}

/**
* Tests if there is VETM warning and returns it
* @param conn
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/models/event/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Entity from "@models/entity/entity";
import { fillFlatObject, IModel, UnknownObject } from "@models/common";
import { fillFlatObject, IModel } from "@models/common";
import { EntityEnums } from "@shared/enums";
import { IEvent, IEventData } from "@shared/types";

Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/models/statement/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class MockResponse extends ResponseStatement {
this.entities[action.id] = action;
}

addActant(actant: IEntity, pos: EntityEnums.Position) {
addActant(actant: IEntity, position: EntityEnums.Position) {
this.data.actants.push(
new StatementActant({
entityId: actant.id,
position: pos,
position,
})
);
this.entities[actant.id] = actant;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/dictionaries/language.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EntityEnums } from "../enums";

export const languageDict = [
{ label: "-", value: EntityEnums.Language.Empty },
{ label: "empty", value: EntityEnums.Language.Empty },
{ label: "Latin", value: EntityEnums.Language.Latin },
{ label: "English", value: EntityEnums.Language.English },
{ label: "Middle English", value: EntityEnums.Language.MiddleEnglish },
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/enums/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ export enum WarningTypeEnums {
MVAL = "MVAL", // Missing at least one entity-type valency
AVAL = "AVAL", // Asymmetrical valency
MAEE = "MAEE", // Missing action/event equivalent
PSM = "PSM", // Part of speech is empty
LM = "LM", // Language is missing
VETM = "VETM", // Empty valency for Action
}
5 changes: 2 additions & 3 deletions packages/shared/types/warning.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { WarningTypeEnums } from "../enums";
import { IActionValency } from "./action";

export interface IWarning {
type: WarningTypeEnums;
position?: IWarningPosition
position?: IWarningPosition;
origin: string;
}

export interface IWarningPosition {

section?: IWarningPositionSection;
subSection?: string;
entityId?: string;
Expand All @@ -19,4 +17,5 @@ export enum IWarningPositionSection {
Relations = "Relations",
Valencies = "Valencies",
Statement = "Statement",
Entity = "Entity",
}

0 comments on commit 3041ea1

Please sign in to comment.