Skip to content

Commit 9e7ecc4

Browse files
committed
preliminary working integration with parser backend
1 parent 039facf commit 9e7ecc4

22 files changed

Lines changed: 413 additions & 42 deletions

backend/langpro_annotator/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@
9191

9292
STATICFILES_DIRS = []
9393
PROXY_FRONTEND = None
94+
95+
LANGPRO_URL = 'http://localhost:8080'

backend/problem/views/parse.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import requests
2+
from django.conf import settings
13
from dataclasses import dataclass, field, asdict
24

35
from django.http import JsonResponse
@@ -67,17 +69,14 @@ def send_to_parser(self, data: ParserInput) -> dict | None:
6769

6870
logger.info("Sending to LangPro service:", asdict(data))
6971

70-
# try:
71-
# response = requests.post(
72-
# url=f"{LANGPRO_URL}/parse",
73-
# json=asdict(data),
74-
# headers={"Content-Type": "application/json"},
75-
# )
76-
# response.raise_for_status()
77-
# return response.json()
78-
# except requests.RequestException as e:
79-
# logger.exception(f"Error sending request to LangPro: {e}")
80-
# return None
81-
82-
83-
return {"ok": "true"}
72+
try:
73+
response = requests.post(
74+
url=f"{settings.LANGPRO_URL}/api/prove/",
75+
json=asdict(data),
76+
headers={"Content-Type": "application/json"},
77+
)
78+
response.raise_for_status()
79+
return response.json()
80+
except requests.RequestException as e:
81+
logger.exception(f"Error sending request to LangPro: {e}")
82+
raise

frontend/src/app/annotate/annotate.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<button
99
type="submit"
1010
class="btn btn-success btn-lg d-flex align-items-center"
11+
(click)="startParse()"
1112
>
1213
<fa-icon
1314
[icon]="faTree"
@@ -21,4 +22,4 @@
2122
</div>
2223
<la-annotation-input class="col-8" />
2324
</div>
24-
<la-annotation-menu />
25+
<la-annotation-menu [ccgTrees]="ccgTrees" />

frontend/src/app/annotate/annotate.component.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Component } from "@angular/core";
1+
import { Component, DestroyRef, inject, OnInit } from "@angular/core";
22
import { AnnotationMenuComponent } from "./annotation-menu/annotation-menu.component";
33
import { NavigatorComponent } from "./navigator/navigator.component";
4-
import { AnnotationInputComponent } from "./annotation-input/annotation-input.component";
4+
import { AnnotationInputComponent, ParseInput } from "./annotation-input/annotation-input.component";
55
import { SearchComponent } from "./search/search.component";
66
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
77
import { faTree } from "@fortawesome/free-solid-svg-icons";
8+
import { ParseResponse, ParseService } from "@/services/parse.service";
9+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
10+
import { ProblemResponse } from "@/types";
11+
import { ProblemService } from "@/services/problem.service";
812

913
@Component({
1014
selector: "la-annotate",
@@ -19,6 +23,39 @@ import { faTree } from "@fortawesome/free-solid-svg-icons";
1923
templateUrl: "./annotate.component.html",
2024
styleUrl: "./annotate.component.scss",
2125
})
22-
export class AnnotateComponent {
26+
export class AnnotateComponent implements OnInit {
2327
public faTree = faTree;
28+
private destroyRef = inject(DestroyRef);
29+
private parseService = inject(ParseService);
30+
private problemService = inject(ProblemService);
31+
32+
public ccgTrees: any[] = [];
33+
34+
private problem: ProblemResponse | null = null;
35+
36+
ngOnInit() {
37+
// TODO: This is wrong. It seems silly to keep a local copy of the problem,
38+
// and it's also not connected to the form, so any edits will not affect
39+
// the requests
40+
this.problemService.problem$
41+
.pipe(takeUntilDestroyed(this.destroyRef))
42+
.subscribe((problem) => {
43+
this.problem = problem;
44+
});
45+
}
46+
47+
onParse(response: ParseResponse) {
48+
console.log("Parse response:", response);
49+
this.ccgTrees = response!.data.ccg_trees;
50+
}
51+
52+
startParse() {
53+
// hardcoded data for now
54+
let input: ParseInput = {
55+
premises: this.problem?.problem?.premises!,
56+
hypothesis: this.problem?.problem?.hypothesis!,
57+
kbItems: []
58+
};
59+
this.parseService.startParse(input, (r) => this.onParse(r));
60+
}
2461
}

frontend/src/app/annotate/annotation-input/annotation-input.component.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { ProblemDetailsComponent } from "./problem-details/problem-details.compo
2020
import { combineLatest, Subject } from "rxjs";
2121
import { ActivatedRoute } from "@angular/router";
2222
import { ProblemService } from "@/services/problem.service";
23-
import { ParseService } from "@/services/parse.service";
2423

2524
export type ParseInputForm = FormGroup<{
2625
premises: FormArray<FormControl<string>>;
@@ -54,7 +53,6 @@ export class AnnotationInputComponent implements OnInit {
5453
private route = inject(ActivatedRoute);
5554
private destroyRef = inject(DestroyRef);
5655
private problemService = inject(ProblemService);
57-
private parseService = inject(ParseService);
5856

5957
public form: ParseInputForm | null = null;
6058
public problem: ProblemResponse | null = null;
@@ -75,14 +73,6 @@ export class AnnotationInputComponent implements OnInit {
7573
this.form = this.buildForm(problem);
7674
});
7775

78-
// Subscription needed to ensure a request is actually made.
79-
// TODO: replace this with actual parse results.
80-
this.parseService.parse$
81-
.pipe(takeUntilDestroyed(this.destroyRef))
82-
.subscribe((response) => {
83-
console.log("Parse response:", response);
84-
});
85-
8676
combineLatest([
8777
this.route.paramMap,
8878
this.route.queryParamMap])

frontend/src/app/annotate/annotation-menu/annotation-menu.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<span i18n>CCG / LLF</span>
1010
</button>
1111
<ng-template ngbNavContent>
12-
<la-annotation-parse-results />
12+
<!-- TODO: render multiple trees -->
13+
<la-parse-svg [tree]="ccgTrees[0]"></la-parse-svg>
1314
</ng-template>
1415
</li>
1516
<li [ngbNavItem]="2">

frontend/src/app/annotate/annotation-menu/annotation-menu.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from "@angular/core";
1+
import { Component, Input } from "@angular/core";
22
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
33
import { NgbNavModule } from "@ng-bootstrap/ng-bootstrap";
44
import {
@@ -9,6 +9,7 @@ import {
99
import { AnnotationParseResultsComponent } from "../annotation-parse-results/annotation-parse-results.component";
1010
import { AnnotationTableauComponent } from "../annotation-tableau/annotation-tableau.component";
1111
import { AnnotationCommentsComponent } from "../annotation-comments/annotation-comments.component";
12+
import { ParseSVG } from "../parse-tree/parse-svg.component";
1213

1314
@Component({
1415
selector: "la-annotation-menu",
@@ -19,6 +20,7 @@ import { AnnotationCommentsComponent } from "../annotation-comments/annotation-c
1920
AnnotationParseResultsComponent,
2021
AnnotationTableauComponent,
2122
AnnotationCommentsComponent,
23+
ParseSVG
2224
],
2325
templateUrl: "./annotation-menu.component.html",
2426
styleUrl: "./annotation-menu.component.scss",
@@ -29,4 +31,7 @@ export class AnnotationMenuComponent {
2931
public faSquarePollHorizontal = faSquarePollHorizontal;
3032
public faTree = faTree;
3133
public faPenNib = faPenNib;
34+
35+
@Input()
36+
public ccgTrees: any[] = [];
3237
}
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, ChangeDetectorRef, Input} from '@angular/core';
2+
import { CommonModule } from "@angular/common";
3+
import { Subject } from "rxjs";
4+
import { Dimensions } from '@/types';
5+
import { ParseTree } from './parse-tree.component';
6+
7+
@Component({
8+
selector: "la-parse-svg",
9+
standalone: true,
10+
imports: [CommonModule, ParseTree],
11+
templateUrl: "./parse-svg.component.svg",
12+
})
13+
export class ParseSVG {
14+
15+
treeDimensions$ = new Subject<Dimensions>();
16+
treeDimensions: Dimensions = {width:0, height: 0};
17+
18+
constructor(private cdref: ChangeDetectorRef) {}
19+
20+
onTreeSize(size: Dimensions) {
21+
this.treeDimensions = size;
22+
}
23+
24+
ngAfterViewChecked() {
25+
this.treeDimensions$.next(this.treeDimensions);
26+
this.cdref.detectChanges();
27+
}
28+
29+
@Input()
30+
tree: any = {};
31+
}
Lines changed: 26 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)