Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 7040561

Browse files
committed
predefined options working
1 parent 016b644 commit 7040561

File tree

14 files changed

+255
-80
lines changed

14 files changed

+255
-80
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ run: ## clean and make target, run target
44
runt: ## clean and make target, run target (text)
55
python3 -m nannotate text
66

7+
runt2: ## clean and make target, run target (text)
8+
python3 -m nannotate text nooptions
9+
710
runi: ## clean and make target, run target (inline)
811
python3 -m nannotate inline
912

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Automate ML dataset labelling
1313

1414

1515

16-
![](https://raw.githubusercontent.com/timkpaine/nannotate/master/docs/img/demo.gif)
16+
![](https://raw.githubusercontent.com/timkpaine/nannotate/master/docs/img/demo_full.gif)

docs/img/demo_full.gif

214 KB
Loading

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ An orchestration layer for plots and tables, dummy datasets, research, reports,
99

1010
|build-status| |issues| |waffle| |codecov| |bch| |pypil| |pypiv| |npm| |docs|
1111

12-
.. image:: ./img/demo.gif
12+
.. image:: ./img/demo_full.gif
1313
:scale: 100%
14-
:alt: demo.gif
14+
:alt: demo_full.gif
1515

1616

1717
.. toctree::

docs/quickstart.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ Notebook
1313
.. image:: ./img/demo_notebook.gif
1414
:scale: 100%
1515
:alt: demo_notebook.gif
16+
17+
Predefined Options
18+
===================
19+
.. image:: ./img/demo_full.gif
20+
:scale: 100%
21+
:alt: demo_full.gif

nannotate/__main__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import pandas as pd
44
from pprint import pprint
55
from .annotate import *
6+
from .utils import get_spacy_pos
67

78
f = faker.Faker()
89

910
if 'text' in sys.argv:
1011
print('annotating text')
11-
dat = pd.DataFrame([{'text': f.text()} for i in range(10)])
12+
spacy_options = get_spacy_pos()
13+
14+
if 'nooptions' in sys.argv:
15+
dat = pd.DataFrame([{'text': f.text()} for i in range(10)])
16+
else:
17+
dat = pd.DataFrame([{'text': f.text(), 'options': spacy_options if i % 2 == 0 else []} for i in range(10)])
1218
options = {'schema': 'text', 'port': 8080}
1319
standalone = True
1420
elif 'inline' in sys.argv:

nannotate/assets/bundle.js

Lines changed: 111 additions & 35 deletions
Large diffs are not rendered by default.

nannotate/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ def in_ipynb():
1212
return False
1313
return False
1414
return False
15+
16+
17+
def get_spacy_pos():
18+
import spacy
19+
ret = []
20+
for item in dir(spacy.parts_of_speech):
21+
if not item.startswith('__') and item != 'univ_pos_t':
22+
ret.append(item)
23+
return ret

packages/core/src/annotate.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,43 @@ class AnnotateWidget extends Widget {
2424
let controls = document.createElement('div');
2525
controls.classList.add('nano-controls');
2626

27+
let options = document.createElement('div');
28+
options.classList.add('nano-controls-options');
29+
2730
let input = document.createElement('textarea');
28-
input.classList.add('nano-io-controls-input');
31+
input.classList.add('nano-controls-input');
2932
controls.appendChild(input);
3033

31-
let io_controls = document.createElement('div');
32-
io_controls.classList.add('nano-io-controls');
34+
let controls_buttons = document.createElement('div');
35+
controls_buttons.classList.add('nano-controls-buttons');
3336

3437
let next = document.createElement('div');
38+
next.classList.add('next-button');
3539
next.textContent = 'Next';
3640
next.onclick = () => {
3741
this._manager._ws.send(JSON.stringify({'command': 'N'}));
3842
}
3943

4044
let previous = document.createElement('div');
4145
previous.textContent = 'Previous';
46+
previous.classList.add('prev-button');
4247
previous.onclick = () => {
4348
this._manager._ws.send(JSON.stringify({'command': 'P'}));
4449
}
4550

46-
let skip = document.createElement('div');
47-
skip.textContent = 'Skip';
48-
skip.onclick = () => {
49-
this._manager._ws.send(JSON.stringify({'command': 'N'}));
50-
}
51+
// let skip = document.createElement('div');
52+
// skip.textContent = 'Skip';
53+
// skip.onclick = () => {
54+
// this._manager._ws.send(JSON.stringify({'command': 'N'}));
55+
// }
5156

52-
io_controls.appendChild(next);
53-
io_controls.appendChild(previous);
54-
io_controls.appendChild(skip);
57+
controls_buttons.appendChild(next);
58+
controls_buttons.appendChild(previous);
59+
// controls_buttons.appendChild(skip);
5560

61+
io_holder.appendChild(options);
5662
io_holder.appendChild(controls);
57-
io_holder.appendChild(io_controls);
63+
io_holder.appendChild(controls_buttons);
5864

5965
div.appendChild(data_holder);
6066
div.appendChild(io_holder);
@@ -80,11 +86,24 @@ class AnnotateWidget extends Widget {
8086
}
8187

8288
get textAreaNode(): HTMLTextAreaElement {
83-
return this.node.getElementsByClassName('nano-io-controls-input')[0] as HTMLTextAreaElement;
89+
return this.node.getElementsByClassName('nano-controls-input')[0] as HTMLTextAreaElement;
90+
}
91+
92+
get nextButtonNode(): HTMLDivElement {
93+
return this.node.querySelector('div.next-button') as HTMLDivElement;
8494
}
8595

96+
get prevButtonNode(): HTMLDivElement {
97+
return this.node.querySelector('div.prev-button') as HTMLDivElement;
98+
}
99+
100+
get optionsNode(): HTMLDivElement {
101+
return this.node.querySelector('div.nano-controls-options') as HTMLDivElement;
102+
}
103+
104+
86105
onAfterAttach(msg: Message) : void {
87-
this._manager = new DataManager(this.dataNode, this._base, this._comm);
106+
this._manager = new DataManager(this, this._base, this._comm);
88107
let textarea = this.textAreaNode;
89108

90109
textarea.onkeyup = (event: KeyboardEvent) => {

packages/core/src/datagrid.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {DataModel} from '@phosphor/datagrid';
22
import {DataSource, DataJSON} from './datasource';
3+
import {AnnotateWidget} from './annotate';
34

45

56
export
67
class GridHelper extends DataModel implements DataSource {
7-
constructor(ws: WebSocket | any) {
8+
constructor(annotate: AnnotateWidget, ws: WebSocket | any) {
89
super();
910
this._ws = ws;
11+
this._annotate = annotate;
1012
}
1113

1214
rowCount(region: DataModel.RowRegion): number {
@@ -103,4 +105,5 @@ class GridHelper extends DataModel implements DataSource {
103105

104106
private _data: object[][] = [];
105107
public _ws: WebSocket | any;
108+
private _annotate: AnnotateWidget;
106109
}

0 commit comments

Comments
 (0)