-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_wordnet_test.ts
166 lines (156 loc) · 4.33 KB
/
parse_wordnet_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { assert } from "$std/assert/assert.ts";
import { parseLexicon, testFileParser } from "~/parse_wordnet.ts";
import {
Definition,
Example,
Form,
ILIDefinition,
Lemma,
LexicalEntry,
Pronunciation,
Sense,
SenseRelation,
Synset,
SynsetRelation,
} from "~/wordnet_types.ts";
type IdRegistry = Map<string, void>;
type RefRegistry = Map<string, void>;
type IdsPack = {
synsetIds: IdRegistry;
senseIds: IdRegistry;
lexicalEntryIds: IdRegistry;
syntacticBehaviorsIds: IdRegistry;
};
type RefsPack = {
senseSynsetRefs: RefRegistry;
senseSubCatRefs: RefRegistry;
senseRelationTargetRefs: RefRegistry;
synsetMembersRefs: RefRegistry;
synsetRelationTargetRefs: RefRegistry;
};
Deno.test("wordnet node relationships", async () => {
const parser = await testFileParser();
const lexicon = await parseLexicon(parser);
assert(lexicon != undefined);
const synsetIds: IdRegistry = new Map();
const senseIds: IdRegistry = new Map();
const lexicalEntryIds: IdRegistry = new Map();
const syntacticBehaviorsIds: IdRegistry = new Map();
const senseSynsetRefs: RefRegistry = new Map();
const senseSubCatRefs: RefRegistry = new Map();
const senseRelationTargetRefs: RefRegistry = new Map();
const synsetMembersRefs: RefRegistry = new Map();
const synsetRelationTargetRefs: RefRegistry = new Map();
lexicon.id;
lexicon.label;
lexicon.language;
lexicon.email;
lexicon.license;
lexicon.version;
lexicon.citation;
lexicon.url;
lexicon.lexicalEntries.forEach(
(le: LexicalEntry) => {
lexicalEntryIds.set(le.id);
le.lemmas.forEach((l: Lemma) => {
l.writtenForm; //
l.partOfSpeech; //
l.pronunciations.forEach((p: Pronunciation) => {
p.variety;
p.inner;
});
});
le.senses.forEach((s: Sense) => {
senseIds.set(s.id);
senseSynsetRefs.set(s.synset);
if (s.subCat) senseSubCatRefs.set(s.subCat);
s.adjPosition; //
s.senseRelations.forEach((sr: SenseRelation) => {
sr.relType;
sr.dcType;
senseRelationTargetRefs.set(sr.target);
});
});
le.forms.forEach((f: Form) => {
f.writtenForm;
});
},
);
lexicon.synsets.forEach((s: Synset) => {
synsetIds.set(s.id);
s.ili;
s.members.forEach((m) => {
synsetMembersRefs.set(m);
});
s.partOfSpeech;
s.lexfile;
s.dcSource;
s.definitions.forEach((d: Definition) => {
d.inner;
});
s.examples.forEach((e: Example) => {
e.inner;
e.dcSource;
});
s.iliDefinitions.forEach((i: ILIDefinition) => {
i.inner;
});
s.synsetRelations.forEach((s: SynsetRelation) => {
s.relType;
synsetRelationTargetRefs.set(s.target);
});
});
lexicon.syntacticBehaviors.forEach((s) => syntacticBehaviorsIds.set(s.id));
assertAllowedRelationships(
{
synsetIds,
senseIds,
lexicalEntryIds,
syntacticBehaviorsIds,
} satisfies IdsPack,
{
senseSynsetRefs,
senseSubCatRefs,
senseRelationTargetRefs,
synsetMembersRefs,
synsetRelationTargetRefs,
} satisfies RefsPack,
new Map([
["senseSubCatRefs > syntacticBehaviorsIds", undefined],
["senseRelationTargetRefs > senseIds", undefined],
["synsetMembersRefs > lexicalEntryIds", undefined],
["synsetRelationTargetRefs > synsetIds", undefined],
["senseSynsetRefs > synsetIds", undefined],
]),
);
});
const assertAllowedRelationships = (
idsPack: IdsPack,
refsPack: RefsPack,
allowed: Map<string, void>,
) => {
const found = collectRelationships(idsPack, refsPack);
found.forEach((_v, k) => {
assert(allowed.has(k), "Disallowed relation: " + k);
});
};
const collectRelationships = (idsPack: IdsPack, refsPack: RefsPack) => {
const result: Map<string, void> = new Map();
Object.entries(refsPack).forEach(([refPackKey, refPackRegistry]) => {
Object.entries(idsPack).forEach(([idPackKey, idPackRegistry]) => {
for (const ref of refPackRegistry.keys()) {
if (idPackRegistry.has(ref)) {
result.set(refPackKey + " > " + idPackKey);
}
}
});
});
return result;
/*
senseSynsetRefs > synsetIds
senseSubCatRefs > syntacticBehaviorsIds
senseRelationTargetRefs > senseIds
synsetMembersRefs > lexicalEntryIds
synsetRelationTargetRefs > synsetIds
*/
};