Skip to content

Commit 4fc05b1

Browse files
committed
Output spans to Python without color, update Examples
1 parent 8638f5f commit 4fc05b1

File tree

6 files changed

+172
-239
lines changed

6 files changed

+172
-239
lines changed

examples/Example.ipynb

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "ef30f8e3-f583-4b8f-beda-27c5c0797f78",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import jupyterannotate"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "36d45960-3b14-4a33-a7ab-06d506812b9e",
16+
"metadata": {},
17+
"source": [
18+
"# Basic Usage"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"id": "06362c99-b674-4a4a-bfd5-159ba7c3d9fa",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"LABELS = [\"Organization\", \"Product\", \"Person\", \"Country\", \"Date\", \"Quantity\"]\n",
29+
"\n",
30+
"NEWS_HEADLINES = [\n",
31+
" \"Oracle introduced a new BI platform yesterday, Business Intelligence 10g that rolls up into one solution all of their BI tools. However, more interesting than the nitty-gritty details of what is included is the back story taking place at the same time.\",\n",
32+
" \"Microsoft will delay the release of its SP2 update for another week to fix software glitches. But not everyone is quite so eager to install the SP2 update for Windows XP. In fact, many companies have demanded the ability to prevent their ...\",\n",
33+
" \"SAN JOSE, Calif. - In a sign that Google Inc.'s initial public offering isn't as popular as expected, the company lowered its estimated price range to between \\$85 and \\$95 per share, down from the earlier prediction of \\$108 and \\$135 per share...\",\n",
34+
"]"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 3,
40+
"id": "b0af5576-99f6-4c81-8411-37a44df69fc3",
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"data": {
45+
"application/vnd.jupyter.widget-view+json": {
46+
"model_id": "2efc9029e27c4548ab03763df8ab9217",
47+
"version_major": 2,
48+
"version_minor": 0
49+
},
50+
"text/plain": [
51+
"AnnotateWidget(value=None, docs=['Oracle introduced a new BI platform yesterday, Business Intelligence 10g tha…"
52+
]
53+
},
54+
"metadata": {},
55+
"output_type": "display_data"
56+
}
57+
],
58+
"source": [
59+
"annotation_widget = jupyterannotate.AnnotateWidget(\n",
60+
" docs=NEWS_HEADLINES,\n",
61+
" labels=LABELS\n",
62+
")\n",
63+
"annotation_widget"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": 5,
69+
"id": "926883f8-328f-4c2f-b7e7-99999c9cc6b1",
70+
"metadata": {},
71+
"outputs": [
72+
{
73+
"data": {
74+
"text/plain": [
75+
"[[{'start': 0, 'end': 6, 'text': 'Oracle', 'label': 'Organization'},\n",
76+
" {'start': 69, 'end': 72, 'text': '10g', 'label': 'Quantity'}],\n",
77+
" [{'start': 0, 'end': 9, 'text': 'Microsoft', 'label': 'Organization'},\n",
78+
" {'start': 159, 'end': 169, 'text': 'Windows XP', 'label': 'Product'}],\n",
79+
" [{'start': 34, 'end': 40, 'text': 'Google', 'label': 'Organization'}]]"
80+
]
81+
},
82+
"execution_count": 5,
83+
"metadata": {},
84+
"output_type": "execute_result"
85+
}
86+
],
87+
"source": [
88+
"annotation_widget.spans"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"id": "b89e2cc0-9ce5-43ff-a4f6-e1908a9e181f",
95+
"metadata": {},
96+
"outputs": [],
97+
"source": []
98+
}
99+
],
100+
"metadata": {
101+
"kernelspec": {
102+
"display_name": "Python 3 (ipykernel)",
103+
"language": "python",
104+
"name": "python3"
105+
},
106+
"language_info": {
107+
"codemirror_mode": {
108+
"name": "ipython",
109+
"version": 3
110+
},
111+
"file_extension": ".py",
112+
"mimetype": "text/x-python",
113+
"name": "python",
114+
"nbconvert_exporter": "python",
115+
"pygments_lexer": "ipython3",
116+
"version": "3.9.13"
117+
}
118+
},
119+
"nbformat": 4,
120+
"nbformat_minor": 5
121+
}

examples/introduction.ipynb

-213
This file was deleted.

src/__tests__/Annotate.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Annotate from "../components/Annotate";
66
import { Span } from "../annotate";
77

88
const RANGE = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
9-
const LABELS = RANGE.map(() => faker.random.word());
9+
const LABELS = RANGE.map(() => ({ text: faker.random.word(), color: "red" }));
1010
const DOCUMENTS = RANGE.map(() => faker.hacker.phrase());
1111

1212
describe("Annotate", () => {
@@ -65,13 +65,13 @@ describe("Annotate", () => {
6565
start: 8,
6666
end: 12,
6767
text: targetText,
68-
label: { color: "red", text: LABELS[0] },
68+
label: LABELS[0],
6969
},
7070
],
7171
])
7272
);
7373

74-
const span = await findByTitle(LABELS[0]);
74+
const span = await findByTitle(LABELS[0].text);
7575
expect(span.textContent).toEqual(targetText);
7676
});
7777

@@ -103,12 +103,12 @@ describe("Annotate", () => {
103103
start: 8,
104104
end: 12,
105105
text: targetText,
106-
label: { color: "red", text: LABELS[0] },
106+
label: LABELS[0],
107107
},
108108
],
109109
]);
110110

111-
const span = await findByTitle(LABELS[0]);
111+
const span = await findByTitle(LABELS[0].text);
112112
expect(span.textContent).toEqual(targetText);
113113
});
114114
});

0 commit comments

Comments
 (0)