Skip to content

Commit 7337796

Browse files
Add scaffolding for future parses
1 parent 3775368 commit 7337796

6 files changed

Lines changed: 58 additions & 18 deletions

File tree

frontend/src/app/annotate/annotation-parse-results/annotation-parse-results.component.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
@let ccgTrees = (parseResults$ | async)?.ccg_trees;
1+
@let ccgParses = (parseResults$ | async);
22
<div>
33
<div ngbAccordion>
4-
@for (tree of ccgTrees; track $index) {
4+
@for (parse of ccgParses; track $index) {
55
<div ngbAccordionItem>
66
<h2 ngbAccordionHeader>
77
<button ngbAccordionButton>
8-
--sentence-text--
8+
{{ parse.sentence }}
99
</button>
1010
</h2>
1111
<div ngbAccordionCollapse>
1212
<div ngbAccordionBody>
1313
<ng-template>
14-
<la-parse-tree-table [tree]="tree" />
14+
<div class="d-flex flex-column gap-3 overflow-x-scroll">
15+
@for (tree of parse.ccgTrees; track $index) {
16+
<la-parse-tree-table [tree]="tree" />
17+
}
18+
</div>
1519
</ng-template>
1620
</div>
1721
</div>

frontend/src/app/annotate/annotation-parse-results/annotation-parse-results.component.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ import { ParseTreeTableComponent } from "./parse-tree-table/parse-tree-table.com
55
import { NgbAccordionModule } from "@ng-bootstrap/ng-bootstrap";
66
import { map } from "rxjs";
77
import { CommonModule } from "@angular/common";
8+
import { CCGNode, CCGParse } from "./types";
9+
10+
export interface TreeWithType {
11+
type: string;
12+
tree: CCGNode;
13+
}
14+
15+
interface FlattenedParseResult {
16+
sentence: string;
17+
ccgTrees: TreeWithType[];
18+
}
19+
20+
function flattenResult(parse: CCGParse): FlattenedParseResult {
21+
const { ccg_tree, ccg_term, corr_term, llf } = parse.ccg_trees;
22+
// TODO: Reintroduce the other trees once they are serialized properly.
23+
return {
24+
...parse,
25+
ccgTrees: [
26+
{ type: "CCG Tree", tree: ccg_tree },
27+
// { type: "CCG Term", tree: ccg_term },
28+
// { type: "Corrected CCG Term", tree: corr_term },
29+
// { type: "Lambda Logical Form", tree: llf }
30+
]
31+
};
32+
}
833

934

1035
@Component({
@@ -20,7 +45,7 @@ export class AnnotationParseResultsComponent {
2045

2146
public parseResults$ = this.parseService.parse$
2247
.pipe(
23-
map(response => response?.data || null),
48+
map(response => response?.data?.ccg_parses.map(parse => flattenResult(parse)) ?? null),
2449
takeUntilDestroyed(this.destroyRef)
2550
);
2651
}

frontend/src/app/annotate/annotation-parse-results/parse-tree-table/parse-tree-table.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<div class="border border-secondary rounded overflow-hidden">
1+
<div class="border border-secondary rounded">
22
<div class="card-header text-bg-secondary p-3">
3-
<h3 class="h5 fw-bold">--tree type--</h3>
3+
<h3 class="h5 fw-bold">{{ treeType() }}</h3>
44
</div>
55
<div class="p-4">
66
<div class="d-flex border border-secondary">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
width: fit-content;
3+
}

frontend/src/app/annotate/annotation-parse-results/parse-tree-table/parse-tree-table.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, computed, input } from '@angular/core';
22
import { TreeNodeComponent } from './tree-node.component';
33
import { CCGNode, LeafNode, BinaryNode, UnaryNode } from "../types";
44
import { TreeNodeDisplay } from "./tree-node.component";
5+
import { TreeWithType } from '../annotation-parse-results.component';
56

67
export function buildDisplayTree(node: CCGNode): TreeNodeDisplay {
78
if (nodeIsLeaf(node)) {
@@ -20,7 +21,7 @@ export function buildDisplayTree(node: CCGNode): TreeNodeDisplay {
2021
}
2122

2223
function nodeIsLeaf(node: CCGNode): node is LeafNode {
23-
return Array.isArray(node.node);
24+
return !('children' in node);
2425
}
2526

2627
function nodeIsBinary(node: CCGNode): node is BinaryNode {
@@ -70,16 +71,16 @@ function buildUnaryNode(node: UnaryNode): TreeNodeDisplay {
7071

7172
/**
7273
* Parses a node string to extract the rule and the content.
73-
*
74-
* A node string is usually of the form "A(B)", where a is the rule applied
74+
*
75+
* A node string is usually of the form "A(B)", where a is the rule applied
7576
* and B is the resulting category. The rule is anything everything before
76-
* the first parenthesis. Everything within it is the content. For example,
77+
* the first parenthesis. Everything within it is the content. For example,
7778
* in "fa(s:ng-np)", "fa" is the rule and "s:ng-np" is the content.
78-
*
79-
* Due to a bug in the CCG parser, sometimes the node string can have
80-
* multiple layers of parentheses, e.g. fa(((s:ng-np)-(s:ng-np))).
79+
*
80+
* Due to a bug in the CCG parser, sometimes the node string can have
81+
* multiple layers of parentheses, e.g. fa(((s:ng-np)-(s:ng-np))).
8182
* function only strips off the first.
82-
*
83+
*
8384
*/
8485
function extractRule(nodeString: string): { rule: string, content: string; } {
8586
const firstParen = nodeString.indexOf('(');
@@ -107,7 +108,8 @@ function extractRule(nodeString: string): { rule: string, content: string; } {
107108
styleUrl: './parse-tree-table.component.scss'
108109
})
109110
export class ParseTreeTableComponent {
110-
public readonly tree = input.required<CCGNode>();
111+
public readonly tree = input.required<TreeWithType>();
111112

112-
public displayTree = computed(() => buildDisplayTree(this.tree()));
113+
public displayTree = computed(() => buildDisplayTree(this.tree().tree));
114+
public treeType = computed(() => this.tree().type);
113115
}

frontend/src/app/annotate/annotation-parse-results/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ export type BinaryNode = {
1515

1616
export type CCGNode = LeafNode | UnaryNode | BinaryNode;
1717

18+
export type ParseTreeType = 'ccg_tree' | 'ccg_term' | 'corr_term' | 'llf';
19+
20+
export interface CCGParse {
21+
sentence: string;
22+
ccg_trees: Record<ParseTreeType, CCGNode>;
23+
};
1824

1925
export type ParseResponseData = {
20-
ccg_trees: CCGNode[];
26+
ccg_parses: CCGParse[];
2127
proofs: unknown[];
2228
};

0 commit comments

Comments
 (0)