Skip to content

Commit

Permalink
1832 generalize sol superordinate location relation to soe superordin…
Browse files Browse the repository at this point in the history
…ate entity relation (#1837)

* rename sol to soe, add allowedEntities LOESBV

* update logic in backend for SOE relations

* Replace abbreviation in the data files

---------

Co-authored-by: Petr Hanak <[email protected]>
Co-authored-by: adammertel <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent 65aa50a commit d41c09c
Show file tree
Hide file tree
Showing 16 changed files with 71,382 additions and 73 deletions.
71,294 changes: 71,293 additions & 1 deletion packages/database/datasets/all-parsed/relations.json

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions packages/database/datasets/relationstest/relations.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,58 +272,58 @@
},

{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1", "l6"],
"order": 2
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1", "l10"],
"order": 3
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1", "l8"],
"order": 4
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l6", "l9"],
"order": 1
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l10", "l8"],
"order": 1
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l8", "l9"],
"order": 1
},

{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1200", "l1201"],
"order": 1
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1201", "l1202"],
"order": 1
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1201", "l1204"],
"order": 2
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1204", "l1"],
"order": 1
},
{
"type": "SOL",
"type": "SOE",
"entityIds": ["l1202", "l1203"],
"order": 1
},
Expand Down Expand Up @@ -608,7 +608,12 @@
},
{
"type": "SYN",
"entityIds": ["c-has-isync-1", "c-has-isync-2", "c-has-isync-3", "c-has-isync-4"],
"entityIds": [
"c-has-isync-1",
"c-has-isync-2",
"c-has-isync-3",
"c-has-isync-4"
],
"order": 1
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$ref": "#/definitions/Relation.ISuperordinateLocation",
"$ref": "#/definitions/Relation.ISuperordinateEntity",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Relation.ISuperordinateLocation": {
"Relation.ISuperordinateEntity": {
"additionalProperties": false,
"properties": {
"entityIds": {
Expand Down
4 changes: 2 additions & 2 deletions packages/database/scripts/generate-json-schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{'file': input_path + 'types/relation.ts', 'class': 'Relation.IRelated'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.IActionEventEquivalent'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.ISubjectActant1Reciprocal'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.ISuperordinateLocation'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.ISuperordinateEntity'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.IPropertyReciprocal'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.ISuperclass'},
{'file': input_path + 'types/relation.ts', 'class': 'Relation.IHolonym'},
Expand All @@ -52,7 +52,7 @@
# {'file': input_path + 'types/actant.ts', 'class': 'IActant'},
# {'file': input_path + 'types/relation.ts', 'class': 'Relation.IClassification'},
# {'file': input_path + 'types/relation.ts', 'class': 'Relation.ISubjectActant1Reciprocal'},
# {'file': input_path + 'types/relation.ts', 'class': 'Relation.ISuperordinateLocation'},
# {'file': input_path + 'types/relation.ts', 'class': 'Relation.ISuperordinateEntity'},
#]

for case in files_and_classes:
Expand Down
2 changes: 1 addition & 1 deletion packages/database/scripts/parse-development.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
" 'Relation.ISynonym':{\n",
" 'id':'', 'type':'SYN','entityIds': ['','']\n",
" },\n",
" 'Relation.ISuperordinateLocation':{\n",
" 'Relation.ISuperordinateEntity':{\n",
" 'id':'', 'type':'SOL','entityIds': ['',''], \"order\":1\n",
" },\n",
" 'Relation.ISuperclass':{\n",
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/models/entity/response-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ResponseTooltip

await this.relations.prepare(request, [
RelationEnums.Type.Superclass,
RelationEnums.Type.SuperordinateLocation,
RelationEnums.Type.SuperordinateEntity,
RelationEnums.Type.Synonym,
RelationEnums.Type.ActionEventEquivalent,
RelationEnums.Type.Classification,
Expand All @@ -43,7 +43,7 @@ export class ResponseTooltip
);
this.addLinkedEntities(
this.relations.getEntityIdsFromType(
RelationEnums.Type.SuperordinateLocation
RelationEnums.Type.SuperordinateEntity
)
);
this.addLinkedEntities(
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/models/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Holonym from "./relation/holonym";
import Implication from "./relation/implication";
import Related from "./relation/related";
import Superclass from "./relation/superclass";
import SuperordinateLocation from "./relation/superordinate-location";
import SuperordinateEntity from "./relation/superordinate-entity";
import PropertyReciprocal from "./relation/property-reciprocal";
import ActionEventEquivalent from "./relation/action-event-equivalent";
import SubjectActant1Reciprocal from "./relation/subject-actant1-reciprocal";
Expand Down Expand Up @@ -97,8 +97,8 @@ export function getRelationClass(data: UnknownObject): Relation {
return new Related(data);
case RelationEnums.Type.Superclass:
return new Superclass(data);
case RelationEnums.Type.SuperordinateLocation:
return new SuperordinateLocation(data);
case RelationEnums.Type.SuperordinateEntity:
return new SuperordinateEntity(data);
case RelationEnums.Type.Identification:
return new Identification(data);
case RelationEnums.Type.Synonym:
Expand Down
14 changes: 7 additions & 7 deletions packages/server/src/models/relation/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,22 @@ export const getIdentifications = async (
* recursively search for superordinate location relations
* @param conn
*/
export const getSuperordinateLocationTree = async (
export const getSuperordinateEntityTree = async (
conn: Connection,
asClass: EntityEnums.Class,
parentId: string
): Promise<EntityTooltip.ISuperordinateLocationTree> => {
const out: EntityTooltip.ISuperordinateLocationTree = {
): Promise<EntityTooltip.ISuperordinateEntityTree> => {
const out: EntityTooltip.ISuperordinateEntityTree = {
entityId: parentId,
subtrees: [],
};

if (asClass === EntityEnums.Class.Location) {
const locations: RelationTypes.ISuperordinateLocation[] =
const locations: RelationTypes.ISuperordinateEntity[] =
await Relation.findForEntity(
conn,
parentId,
RelationEnums.Type.SuperordinateLocation,
RelationEnums.Type.SuperordinateEntity,
0
);

Expand All @@ -200,7 +200,7 @@ export const getSuperordinateLocationTree = async (

for (const subparentId of subrootIds) {
out.subtrees.push(
await getSuperordinateLocationTree(conn, asClass, subparentId)
await getSuperordinateEntityTree(conn, asClass, subparentId)
);
}
}
Expand All @@ -209,7 +209,7 @@ export const getSuperordinateLocationTree = async (
};

export const getEntityIdsFromTree = (
tree: EntityTooltip.ISuperordinateLocationTree
tree: EntityTooltip.ISuperordinateEntityTree
): string[] => {
const out: string[] = [tree.entityId];

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/models/relation/identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Identification
return out;
}

let relations: RelationTypes.IIdentification[] =
const relations: RelationTypes.IIdentification[] =
await Relation.findForEntity(
conn,
entityId,
Expand Down
18 changes: 9 additions & 9 deletions packages/server/src/models/relation/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import Related from "./related";
import SubjectActant1Reciprocal from "./subject-actant1-reciprocal";
import SubjectSemantics from "./subject-semantics";
import Superclass from "./superclass";
import SuperordinateLocation from "./superordinate-location";
import SuperordinateEntity from "./superordinate-entity";
import Synonym from "./synonym";

type ISuperclass = RelationTypes.ISuperclass;
type ISuperordinateLocation = RelationTypes.ISuperordinateLocation;
type ISuperordinateEntity = RelationTypes.ISuperordinateEntity;
type ISynonym = RelationTypes.ISynonym;
type IAntonym = RelationTypes.IAntonym;
type IHolonym = RelationTypes.IHolonym;
Expand All @@ -47,7 +47,7 @@ export class UsedRelations implements RelationTypes.IUsedRelations {

[RelationEnums.Type.Superclass]?: RelationTypes.IDetailType<ISuperclass>;
[RelationEnums.Type
.SuperordinateLocation]?: RelationTypes.IDetailType<ISuperordinateLocation>;
.SuperordinateEntity]?: RelationTypes.IDetailType<ISuperordinateEntity>;
[RelationEnums.Type.Synonym]?: RelationTypes.IDetailType<ISynonym>;
[RelationEnums.Type.Antonym]?: RelationTypes.IDetailType<IAntonym>;
[RelationEnums.Type.Holonym]?: RelationTypes.IDetailType<IHolonym>;
Expand Down Expand Up @@ -98,18 +98,18 @@ export class UsedRelations implements RelationTypes.IUsedRelations {
};
}

async prepareSuperordinateLocations(dbConn: Connection): Promise<void> {
this[RelationEnums.Type.SuperordinateLocation] = {
async prepareSuperordinateEntitys(dbConn: Connection): Promise<void> {
this[RelationEnums.Type.SuperordinateEntity] = {
connections:
await SuperordinateLocation.getSuperordinateLocationForwardConnections(
await SuperordinateEntity.getSuperordinateEntityForwardConnections(
dbConn,
this.entityId,
this.entityClass,
this.maxNestLvl,
0
),
iConnections:
await SuperordinateLocation.getSuperordinateLocationInverseConnections(
await SuperordinateEntity.getSuperordinateEntityInverseConnections(
dbConn,
this.entityId,
this.entityClass
Expand Down Expand Up @@ -297,8 +297,8 @@ export class UsedRelations implements RelationTypes.IUsedRelations {
await this.prepareSuperclasses(req.db.connection);
}

if (types.indexOf(RelationEnums.Type.SuperordinateLocation) != -1) {
await this.prepareSuperordinateLocations(req.db.connection);
if (types.indexOf(RelationEnums.Type.SuperordinateEntity) != -1) {
await this.prepareSuperordinateEntitys(req.db.connection);
}

if (types.indexOf(RelationEnums.Type.Synonym) != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,41 @@ import Relation from "./relation";
import { Relation as RelationTypes } from "@shared/types";
import { Connection } from "rethinkdb-ts";

export default class SuperordinateLocation
export default class SuperordinateEntity
extends Relation
implements RelationTypes.ISuperordinateLocation
implements RelationTypes.ISuperordinateEntity
{
type: RelationEnums.Type.SuperordinateLocation;
type: RelationEnums.Type.SuperordinateEntity;
entityIds: [string, string];
order: number;

constructor(data: Partial<RelationTypes.ISuperordinateLocation>) {
constructor(data: Partial<RelationTypes.ISuperordinateEntity>) {
super(data);
this.entityIds = data.entityIds as [string, string];
this.type = RelationEnums.Type.SuperordinateLocation;
this.type = RelationEnums.Type.SuperordinateEntity;
this.order = data.order === undefined ? EntityEnums.Order.Last : data.order;
}

static async getSuperordinateLocationForwardConnections(
static async getSuperordinateEntityForwardConnections(
conn: Connection,
parentId: string,
asClass: EntityEnums.Class,
maxNestLvl: number,
nestLvl: number
): Promise<
RelationTypes.IConnection<RelationTypes.ISuperordinateLocation>[]
> {
const out: RelationTypes.IConnection<RelationTypes.ISuperordinateLocation>[] =
): Promise<RelationTypes.IConnection<RelationTypes.ISuperordinateEntity>[]> {
const out: RelationTypes.IConnection<RelationTypes.ISuperordinateEntity>[] =
[];

if (nestLvl > maxNestLvl) {
return out;
}

if (asClass === EntityEnums.Class.Location) {
const relations: RelationTypes.ISuperordinateLocation[] =
if (EntityEnums.LOESBV.indexOf(asClass) !== -1) {
const relations: RelationTypes.ISuperordinateEntity[] =
await Relation.findForEntity(
conn,
parentId,
RelationEnums.Type.SuperordinateLocation,
RelationEnums.Type.SuperordinateEntity,
0
);

Expand All @@ -52,14 +50,14 @@ export default class SuperordinateLocation

for (const relation of relations) {
const subparentId = relation.entityIds[1];
const connection: RelationTypes.IConnection<RelationTypes.ISuperordinateLocation> =
const connection: RelationTypes.IConnection<RelationTypes.ISuperordinateEntity> =
{
...relation,
subtrees: [],
};

connection.subtrees =
await SuperordinateLocation.getSuperordinateLocationForwardConnections(
await SuperordinateEntity.getSuperordinateEntityForwardConnections(
conn,
subparentId,
asClass,
Expand All @@ -74,18 +72,18 @@ export default class SuperordinateLocation
return out;
}

static async getSuperordinateLocationInverseConnections(
static async getSuperordinateEntityInverseConnections(
conn: Connection,
parentId: string,
asClass: EntityEnums.Class
): Promise<RelationTypes.ISuperordinateLocation[]> {
let out: RelationTypes.ISuperordinateLocation[] = [];
): Promise<RelationTypes.ISuperordinateEntity[]> {
let out: RelationTypes.ISuperordinateEntity[] = [];

if (asClass === EntityEnums.Class.Location) {
if (EntityEnums.LOESBV.indexOf(asClass) !== -1) {
out = await Relation.findForEntity(
conn,
parentId,
RelationEnums.Type.SuperordinateLocation,
RelationEnums.Type.SuperordinateEntity,
1
);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/shared/enums/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export namespace EntityEnums {
Class.Resource,
Class.Being,
];
export const LOESBV = [
Class.Location,
Class.Object,
Class.Event,
Class.Statement,
Class.Being,
Class.Value,
];

export enum Extension {
Any = "*",
Expand Down
Loading

0 comments on commit d41c09c

Please sign in to comment.