Skip to content

Commit

Permalink
making API for javascripty
Browse files Browse the repository at this point in the history
  • Loading branch information
chanind committed Jan 1, 2024
1 parent 846f2fa commit 03214d2
Show file tree
Hide file tree
Showing 41 changed files with 794 additions and 592 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"functional/immutable-data": "off",
"functional/prefer-immutable-types": "off",
"functional/no-throw-statements": "off",
"functional/no-mixed-types": "off",
"functional/functional-parameters": "off",
"functional/prefer-type-literal": "off",
"no-constant-condition": "off",
Expand Down
39 changes: 12 additions & 27 deletions docs/docs/api.constant.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import FLOAT, {toc as FloatToc} from '../generated/variables/lib_constant.FLOAT.mdx'
import INTEGER, {toc as IntegerToc} from '../generated/variables/lib_constant.INTEGER.mdx'
import NULL, {toc as NullToc} from '../generated/variables/lib_constant.NULL.mdx'
import STRING, {toc as StringToc} from '../generated/variables/lib_constant.STRING.mdx'
import SYMBOL, {toc as SymbolToc} from '../generated/variables/lib_constant.SYMBOL.mdx'
import Quote, {toc as QuoteToc} from '../generated/functions/lib_constant.quote.mdx'
import Evaluate, {toc as EvaluateToc} from '../generated/functions/lib_constant.evaluate.mdx'
import Type, {toc as TypeToc} from '../generated/functions/lib_constant.type-1.mdx'
import ConstantTypeEnum, {toc as ConstantTypeEnumToc} from '../generated/enums/lib_constant.ConstantType.mdx'
import QuoteConstant, {toc as QuoteConstantToc} from '../generated/functions/lib_constant.quoteConstant.mdx'
import EvaluateConstant, {toc as EvaluateConstantToc} from '../generated/functions/lib_constant.evaluateConstant.mdx'
import ConstantType, {toc as ConstantTypeToc} from '../generated/functions/lib_constant.constantType-1.mdx'

# constant

Expand All @@ -19,28 +15,17 @@ value, is used when an attribute is missing its target, but aside from
robustness measures it is not a supported datatype.




<Quote />
<QuoteConstant />
___
<Evaluate />
<EvaluateConstant />
___
<Type />
<ConstantType />
___

<FLOAT />
<INTEGER />
<NULL />
<STRING />
<SYMBOL />
<ConstantTypeEnum />

export const toc = [
...QuoteToc,
...EvaluateToc,
...TypeToc,
...FloatToc,
...IntegerToc,
...NullToc,
...StringToc,
...SymbolToc,
...QuoteConstantToc,
...EvaluateConstantToc,
...ConstantTypeToc,
...ConstantTypeEnumToc,
]
8 changes: 4 additions & 4 deletions docs/docs/api.graph.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Graph, { toc as GraphToc } from '../generated/classes/lib_graph.Graph.mdx';
import Triple, { toc as TripleToc } from '../generated/types/lib_graph.Triple.mdx';
import Instance, { toc as InstanceToc } from '../generated/types/lib_graph.Instance.mdx';
import Edge, { toc as EdgeToc } from '../generated/types/lib_graph.Edge.mdx';
import Attribute, { toc as AttributeToc } from '../generated/types/lib_graph.Attribute.mdx';
import Triple, { toc as TripleToc } from '../generated/types/lib_types.Triple.mdx';
import Instance, { toc as InstanceToc } from '../generated/types/lib_types.Instance.mdx';
import Edge, { toc as EdgeToc } from '../generated/types/lib_types.Edge.mdx';
import Attribute, { toc as AttributeToc } from '../generated/types/lib_types.Attribute.mdx';


# graph
Expand Down
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
".": {
"import": "./build/module/index.js",
"require": "./build/main/index.js"
},
"./*": {
"import": "./build/module/*.js",
"require": "./build/main/*.js"
},
"./models/*": {
"import": "./build/module/lib/models/*.js",
"require": "./build/main/lib/models/*.js"
}
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/codec.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/constant.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/epigraph.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/exceptions.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/graph.ts

This file was deleted.

67 changes: 61 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
export { parse, iterparse, parseTriples } from './lib/_parse';
export { format, formatTriples } from './lib/_format';
export { interpret, configure } from './lib/layout';
export { Tree } from './lib/tree';
export { Graph, Triple } from './lib/graph';
export { parse, iterparse, parseTriples } from './lib/parse';
export { format, formatTriples } from './lib/format';
export {
LayoutMarker,
Push,
Pop,
POP,
interpret,
rearrange,
configure,
reconfigure,
getPushedVariable,
appearsInverted,
nodeContexts,
} from './lib/layout';
export { Tree, isAtomic } from './lib/tree';
export { Graph } from './lib/graph';
export {
Triple,
Instance,
Edge,
Attribute,
Branch,
Node,
Constant,
Variable,
Role,
} from './lib/types';
export {
PENMANCodec,
decode,
Expand All @@ -13,4 +36,36 @@ export {
load,
loads,
} from './lib/codec';
export { DecodeError, PenmanError } from './lib/exceptions';
export {
canonicalizeRoles,
reifyEdges,
dereifyEdges,
reifyAttributes,
indicateBranches,
} from './lib/transform';
export {
AlignmentMarker,
Alignment,
RoleAlignment,
alignments,
roleAlignments,
} from './lib/surface';
export { Model } from './lib/model';
export { amrModel } from './lib/models/amr';
export { noopModel } from './lib/models/noop';
export {
PenmanError,
ConstantError,
GraphError,
LayoutError,
DecodeError,
SurfaceError,
ModelError,
} from './lib/exceptions';
export { Epidatum } from './lib/epigraph';
export {
ConstantType,
constantType,
evaluateConstant,
quoteConstant,
} from './lib/constant';
13 changes: 0 additions & 13 deletions src/layout.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/lib/_lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class TokenIterator {
this._next = null;
}
this._last = current;
if (current == null) {
throw new Error('Unexpected end of input');
}
return current;
}

Expand Down Expand Up @@ -155,7 +158,7 @@ export class TokenIterator {
}

error(message: string, token?: Token): DecodeError {
let line: string | null = null;
let line: string | undefined;
let lineno: number;
let offset: number;
if (token == null) {
Expand Down Expand Up @@ -226,7 +229,7 @@ const _lex = function* (
`capturing group:\n${regex.source}`,
);
}
const token: Token = [typ, val, i, m.index, line];
const token: Token = [typ, val, i, m.index ?? 0, line];
debug(`${token}`);
yield token;
}
Expand Down
18 changes: 9 additions & 9 deletions src/lib/codec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test('decode_alignments', (t) => {
const expectedRoleAlignments = new ArrayKeysMap();
expectedRoleAlignments.set(
['a', ':ARG', 'b'],
new surface.RoleAlignment([1, 2], 'e.'),
new surface.RoleAlignment([1, 2], { prefix: 'e.' }),
);
t.deepEqual(surface.roleAlignments(g2), expectedRoleAlignments);

Expand Down Expand Up @@ -239,7 +239,7 @@ test('encode', (t) => {
t.is(codec.encode(g), '()');

// unlabeled single node
g = new Graph([], 'a');
g = new Graph([], { top: 'a' });
t.is(codec.encode(g), '(a)');

// labeled node
Expand All @@ -255,19 +255,19 @@ test('encode', (t) => {
t.is(codec.encode(g), '(a : b)');
const epidata = new EpidataMap();
epidata.set(['a', ':', 'b'], [new layout.Push('b')]);
g = new Graph([['a', ':', 'b']], undefined, epidata);
g = new Graph([['a', ':', 'b']], { epidata });
t.is(codec.encode(g), '(a : (b))');

// inverted unlabeled edge
g = new Graph([['a', '', 'b']], 'b');
g = new Graph([['a', '', 'b']], { top: 'b' });
t.is(codec.encode(g), '(b :-of a)');

// labeled edge to unlabeled node
g = new Graph([['a', 'ARG', 'b']]);
t.is(codec.encode(g), '(a :ARG b)');

// inverted edge
g = new Graph([['a', 'ARG', 'b']], 'b');
g = new Graph([['a', 'ARG', 'b']], { top: 'b' });
t.is(codec.encode(g), '(b :ARG-of a)');
});

Expand Down Expand Up @@ -304,9 +304,9 @@ test('encode issue 61', (t) => {
['i', ':instance', 'i'],
['i2', ':ARG0', 'i'],
],
'i2',
{ top: 'i2' },
);
t.is(codec.encode(g, undefined, null), '(i2 / i :ARG0 (i / i))');
t.is(codec.encode(g, { indent: null }), '(i2 / i :ARG0 (i / i))');
});

test('encode issue 67', (t) => {
Expand All @@ -318,13 +318,13 @@ test('encode issue 67', (t) => {
['h', ':ARG2', 'a'],
];
t.is(
codec.encode(new Graph(triples, 'a')),
codec.encode(new Graph(triples, { top: 'a' })),
`(a / activist
:ARG0-of (h / have-org-role-91)
:ARG2-of h)`,
);
t.is(
codec.encode(new Graph(triples, 'h')),
codec.encode(new Graph(triples, { top: 'h' })),
`(h / have-org-role-91
:ARG0 (a / activist)
:ARG2 a)`,
Expand Down
Loading

0 comments on commit 03214d2

Please sign in to comment.