Skip to content

Commit 97ae97b

Browse files
authored
Merge pull request #77 from CentreForDigitalHumanities/feature/parse-interface-ctd
Integration with parser backend
2 parents 6d03adb + 83513ab commit 97ae97b

28 files changed

Lines changed: 400 additions & 38 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ venv.bak/
3737
node_modules/
3838
frontend/src/environments/version.ts
3939
*~
40+
41+
# ProofBank datasets
42+
/backend/SICK.txt
43+
/backend/fracas.xml
44+
/backend/snli_1.0_dev.txt
45+
/backend/snli_1.0_test.txt

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "langpro-container"]
2+
path = langpro-container
3+
url = https://github.com/CentreForDigitalHumanities/langpro-container.git

CONTRIBUTING.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ This document contains basic documentation for developing LangPro Annotator.
44

55
## Before you start
66

7-
You need to install the following software, *unless* you will be using Docker:
7+
This repository has a submodule that requires [git-lfs][git-lfs]. It is recommended that you install git-lfs before cloning the repository to a local disk.
8+
9+
You also need to install the following software, *unless* you will be using Docker:
810

911
- PostgreSQL >= 10, client, server and C libraries
1012
- Python >= 3.8, <= 3.10
@@ -14,18 +16,33 @@ You need to install the following software, *unless* you will be using Docker:
1416
- Node.js >= 14.20.0
1517
- Yarn
1618

19+
After cloning the repository, run the following commands once in order to obtain a local copy of [langpro-container][container] and its recursive submodule [LangPro][langpro]:
20+
21+
``` sh
22+
git submodule init
23+
# customize clone URL in .git/config before proceeding (if needed)
24+
git submodule update --recursive
25+
```
26+
27+
If you don't need to customize clone URLs, you can also do both steps at once with `git submodule update --init --recursive`.
28+
1729
[1]: https://wiki.python.org/moin/WindowsCompilers
30+
[git-lfs]: https://git-lfs.com/
31+
[container]: https://github.com/CentreForDigitalHumanities/langpro-container
32+
[langpro]: https://github.com/kovvalsky/LangPro
1833

1934
## How it works
2035

21-
This project integrates three isolated subprojects, each inside its own subdirectory with its own code, package dependencies and tests:
36+
This project integrates four isolated subprojects, each inside its own subdirectory with its own code, package dependencies and tests:
2237

2338
- **backend**: the server side web application based on [Django][3] and [DRF][4]
2439

2540
- **frontend**: the client side web application based on [Angular](https://angular.io)
2641

2742
- **functional-tests**: the functional test suite based on [playwright][6] and [pytest][7]
2843

44+
- **langpro-container**: a git submodule that provides a backend for parsing and proving problems
45+
2946
[3]: https://www.djangoproject.com
3047
[4]: https://www.django-rest-framework.org
3148
[6]: https://playwright.dev/python/docs/library

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 = os.environ.get('LANGPRO_CONTAINER') or 'http://localhost:8080'

backend/problem/views/parse.py

Lines changed: 18 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
@@ -65,19 +67,21 @@ def post(self, request: Request) -> JsonResponse:
6567
def send_to_parser(self, data: ParserInput) -> dict | None:
6668
"""Send frontend data to downstream LangPro service."""
6769

68-
logger.info("Sending to LangPro service:", asdict(data))
70+
logger.info(f"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
72+
params = asdict(data)
73+
# ask LangPro container to return results in a format suitable for
74+
# this application
75+
params['format'] = 'annotator'
8176

82-
83-
return {"ok": "true"}
77+
try:
78+
response = requests.post(
79+
url=f"{settings.LANGPRO_URL}/api/prove/",
80+
json=params,
81+
headers={"Content-Type": "application/json"},
82+
)
83+
response.raise_for_status()
84+
return response.json()
85+
except requests.RequestException as e:
86+
logger.exception(f"Error sending request to LangPro: {e}")
87+
raise

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
include:
2+
- ./langpro-container/compose.yaml
3+
14
services:
25
postgres:
36
image: postgres:15
@@ -16,6 +19,7 @@ services:
1619
context: ./backend
1720
environment:
1821
PGHOST: postgres
22+
LANGPRO_CONTAINER: 'http://langpro:80'
1923
LANGPRO_FRONTEND: 'http://frontend:4200'
2024
depends_on:
2125
postgres:

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"colors": "^1.4.0",
3838
"express": "^4.18.2",
3939
"rxjs": "~7.8.0",
40+
"svg-pan-zoom": "bumbu/svg-pan-zoom",
4041
"tslib": "^2.3.0",
4142
"zone.js": "~0.15.1"
4243
},
@@ -57,4 +58,4 @@
5758
"ng-extract-i18n-merge": "^2.12.0",
5859
"typescript": "~5.8.3"
5960
}
60-
}
61+
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,6 @@ export class AnnotationInputComponent implements OnInit {
124124
});
125125
this.router.navigate(["/", "annotate", response.id]);
126126
});
127-
128-
// Subscription needed to ensure a request is actually made.
129-
// TODO: replace this with actual parse results.
130-
this.parseService.parse$
131-
.pipe(takeUntilDestroyed(this.destroyRef))
132-
.subscribe((response) => {
133-
console.log("Parse response:", response);
134-
});
135127
}
136128

137129
public startParse(): void {

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { Component } from "@angular/core";
1+
import { Component, DestroyRef, inject, OnInit } from "@angular/core";
2+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
23
import { mockResult } from "./mockParseResult";
4+
import { ParseService } from "@/services/parse.service";
35
import { ParseTreeTableComponent } from "./parse-tree-table/parse-tree-table.component";
46
import { NgbAccordionModule } from "@ng-bootstrap/ng-bootstrap";
57

@@ -11,6 +13,19 @@ import { NgbAccordionModule } from "@ng-bootstrap/ng-bootstrap";
1113
templateUrl: "./annotation-parse-results.component.html",
1214
styleUrl: "./annotation-parse-results.component.scss",
1315
})
14-
export class AnnotationParseResultsComponent {
15-
public readonly parseResults = mockResult;
16+
export class AnnotationParseResultsComponent implements OnInit {
17+
private destroyRef = inject(DestroyRef);
18+
private parseService = inject(ParseService);
19+
20+
public parseResults = mockResult;
21+
22+
ngOnInit(): void {
23+
// Subscription needed to ensure a request is actually made.
24+
this.parseService.parse$
25+
.pipe(takeUntilDestroyed(this.destroyRef))
26+
.subscribe((response) => {
27+
console.log("Parse response:", response);
28+
this.parseResults = response.data.ccg_trees;
29+
});
30+
}
1631
}
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)