You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
14 KiB
Plaintext
142 lines
14 KiB
Plaintext
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "66f72396-0cf1-41cf-a486-2930d2ad1652",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# highlight_map\n",
|
||
|
"Give a string with the name of the image-file that was annotated with the Annotation Compass; Give a target-word; Return a string that includes all annotation-texts plus html-tags that place them back into their original position while highlighting the annotation-texts that include the target."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"id": "2d179f96-2f4c-419f-97d9-9ea833bfc4b3",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from urllib.request import urlopen\n",
|
||
|
"import json"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"id": "9bd8860a-9967-49d5-a74a-b5de669dfe6d",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def highlight_map(image: str, target: str ) -> str:\n",
|
||
|
" \n",
|
||
|
" \"\"\"Give a string with the name of the image-file that was annotated with the Annotation Compass; Give a target-word; Return a string that includes all annotation-texts plus html-tags that place them back into their original position while highlighting the annotation-texts that include the target.\"\"\" \n",
|
||
|
"\n",
|
||
|
" url = f\"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image={image}\"\n",
|
||
|
" response = urlopen(url)\n",
|
||
|
" data_json = json.loads(response.read()) \n",
|
||
|
" \n",
|
||
|
" filtered_map = '<link rel=\"stylesheet\" href=\"/soupboat/si16-app/static/css/jian.css\">'\n",
|
||
|
" for label in data_json['labels']:\n",
|
||
|
" if target in label['text']:\n",
|
||
|
" highlight_tag = f'<p class=\"highlight\" style=\"left: {label[\"position\"][\"x\"]}%; top: {label[\"position\"][\"y\"]}%; position: absolute;\">{ label[\"text\"] }</p>'\n",
|
||
|
" filtered_map = filtered_map + highlight_tag\n",
|
||
|
" else:\n",
|
||
|
" html_tag = f'<p class=\"lowlight\" style=\"left: {label[\"position\"][\"x\"]}%; top: {label[\"position\"][\"y\"]}%; position: absolute;\">{ label[\"text\"] }</p>'\n",
|
||
|
" filtered_map = filtered_map + html_tag\n",
|
||
|
" \n",
|
||
|
" return filtered_map"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "1094ed8e-1387-481e-b612-9a8cc81d5c18",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"This function was built for a project where individuals are invited to add their annotations on a map using the Annotation Compass. Each annotation-label is stored in a json-file and includes the annotation-text itself, but also the name of the image-file as well as the position, size, index, timestamp and userID of the annotation.\n",
|
||
|
"\n",
|
||
|
" Example for a label:\n",
|
||
|
"\n",
|
||
|
" {'image': 'map.jpg',\n",
|
||
|
" 'position': {'x': 12, 'y': 97},\n",
|
||
|
" 'size': {'width': 43, 'height': 18},\n",
|
||
|
" 'text': 'This is a text! Is this a text?',\n",
|
||
|
" 'timestamp': 'Wed, 01 Dec 2021 14:04:00 GMT',\n",
|
||
|
" 'userID': 5766039063}\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"If interested in all annotations that include a specific target, highlight_map() can help. The function needs a string with the name of the of the image-file that was annotated with the annotation compass tool and a target-word. The output is a string that includes all annotation-texts plus html-tags that place them back into their original position while highlighting the annotation-texts that include the target.\n",
|
||
|
"\n",
|
||
|
"How to get a json-file with annotation-labels?\n",
|
||
|
"\n",
|
||
|
" https://hub.xpub.nl/soupboat/generic-labels/\n",
|
||
|
"The Annotation Compass allows people to uplaod an image and ask others to annotate it. A json-file of the annotations is provided."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "2c3e992a-317b-4433-8c3b-9efcedea575d",
|
||
|
"metadata": {
|
||
|
"tags": []
|
||
|
},
|
||
|
"source": [
|
||
|
"## Examples\n",
|
||
|
"\n",
|
||
|
"In this example, the function highlights all annotation-texts that include a specific target."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"id": "e3d7e97b-0089-4c29-a2c1-9ef823ff2e37",
|
||
|
"metadata": {
|
||
|
"scrolled": true,
|
||
|
"tags": []
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"'<link rel=\"stylesheet\" href=\"/soupboat/si16-app/static/css/jian.css\"><p class=\"lowlight\" style=\"left: 63.9896%; top: 34.2958%; position: absolute;\">here, someone called my behaviour \"strange\"</p><p class=\"lowlight\" style=\"left: 33.6269%; top: 65.1408%; position: absolute;\">윰보에서 장을 보고 집에 돌아오는 길. 두 명의 남자 가 다가왔어. 나는 낑낑대며 나의 일주일간 식량을 옮기고 있었지. 쾅!\\n큰 소리가 났고 나는 순간 움츠러들었어. \\n건너편에서 다가오던 남자 두명이 크게 웃더니 \\n나를 보며 Chino! Chino!라고 외쳤어. 시발.</p><p class=\"lowlight\" style=\"left: 92.3483%; top: -0.179426%; position: absolute;\">the municipality of rotterdam (prince alexander) almost refused to approve my request of registration because the italian id card doesn\\'t have my sex written on it. \\nthey said that if i bring my birth certificate that states that im a male i can have my bsn otherwise.......... nope.</p><p class=\"lowlight\" style=\"left: 65.3034%; top: 35.4839%; position: absolute;\">getting a text message from my good friend, telling me that she will not visit me in Rotterdam despite she promised me.</p><p class=\"highlight\" style=\"left: 48.135%; top: 20.4458%; position: absolute;\">house viewing 2: meeting with some girls in the evening to see a room; felt super exposed and awkward. Later on, they rejected me.</p><p class=\"highlight\" style=\"left: 76.25%; top: 69.5246%; position: absolute;\">I once went to view a house here but it didn\\'t have the floor. crap.</p><p class=\"lowlight\" style=\"left: 39.3264%; top: 46.831%; position: absolute;\">here, someone screamed at me \"move fucking chinee\"</p><p class=\"lowlight\" style=\"left: 77.0%; top: 63.7521%; position: absolute;\">other housing rejection situations here.\\n</p><p class=\"lowlight\" style=\"left: 63.7806%; top: 41.0296%; position: absolute;\">a woman on the train showed me the middle finger the first day i arrived to rotterdam and i didn\\'t really understand why because she\\'s the one that was mean with me in the first place</p><p class=\"lowlight\" style=\"left: 48.9886%; top: 51.256%; position: absolute;\">at 22:01 a bald man kicked us out from the basketball court because we were noisy</p><p class=\"lowlight\" style=\"left: 36.5285%; top: 54.2958%; position: absolute;\">here, someone screamed at me, right into my face, something I could not understand</p><p class=\"highlight\" style=\"left: 55.0889%; top: 15.6154%; position: absolute;\">the most unpleasant house viewing: my viewing overlapped with the previous person and I didn\\'t got the chance to connect with the ones living them. How could then they know who I am and even consider me for the room?</p><p class=\"lowlight\" style=\"left: 47.2668%; top: 70.1459%; position: absolute;\">Stepped out at the wrong bus station and because the waiting time for the next bus was (a bit) long, Carmen and I decided to walk to Varia... Rejected by punctuality.</p><p class=\"lowlight\" style=\"left: 42.5389%; top: 45.7042%; position: absolute;\">here, someone told me to move away</p><p class=\"highlight\" style=\"left: 45.2507%; top: 29.3907%; position: absolute;\">I had the most awkward house viewing here. The people barely talked to me and really let me know that they didn\\'t like me. Obviously, I did not get the room.</p><p class=\"lowlight\" style=\"left: 60.774%; top: 59.7488%; position: absolute;\">rejected by the police</p><p class=\"highlight\" style=\"left: 42.0882%; top: 18.8014%; position: absolute;\">my first house viewing: I was really hopeful about this one, actually, because I felt a connection with the girl. I waited 2 weeks to be rejected from this one.</p><p class=\"lowlight\" style=\"left: 39.1192%; top: 36.2676%; position: absolute;\">here, someone told to stop looking at them</p><p class=\"highlight\" style=\"left: 43.7995%; top: 27.0609%; position: absolute;\">I had the most awkward house viewing here. The people barely talked to me and really let me know that they didn\\'t like me. N
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"highlight_map('rejection_map.jpg', 'house')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "ed9f5de3-451d-4dc5-8e9f-97228df73e11",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.7.3"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|