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

{
"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. Not surprisingly, I did not get the room.</p><p class=\"lowlight\" style=\"left: 75.285%; top: 29.2254%; position: absolute;\">어딘지 잘은 모르겠지만, Kralingen 쪽이었던 것 같아. bsn 거주등록을 위해 학교에 갔는데, 시청에서 나온 사람들이 나의 룸메이트 ID card가 필요하다며 거절했지. 나의 아침을 날렸어. 나의 룸메가 나에게 ID card 사진을 보내줬지만, 그들은 서명이 같지 않다면서 다시 거절했지. </p><p class=\"lowlight\" style=\"left: 52.0%; top: 48.1324%; position: absolute;\">i couldn\\'t eat anything from a spar because it was selling only non gluten-free products. </p><p class=\"lowlight\" style=\"left: 16.5775%; top: 28.7791%; position: absolute;\">I felt rejection in Art Rotterdam 2019 when the parents of my boyfriend\\'s exgirlfriend came to visit my exboyfriends exhibition there and I felt kinda OUT OF PLACE? heheheh </p><p class=\"lowlight\" style=\"left: 60.1554%; top: 63.3099%; position: absolute;\">Emma와 함께 프린트를 하러 갔는데, 그곳에 있는 instructor가 매우 불친절했어. </p><p class=\"lowlight\" style=\"left: 65.0396%; top: 45.3405%; position: absolute;\">An old friend of mine that I know from my home country also studies at WDKA. I reached out to him and suggested to hang out soon. He didn\\'t want to.</p><p class=\"lowlight\" style=\"left: 46.3713%; top: 58.4289%; position: absolute;\">somewhere between this line i lost my ID card. and I really wasnt aware that this could linger a lot my registration to the municipality. This kinda triggered but feeling for me, as I felt a lot disorented here, having no formal document verifying who I am and feeling guilty tat I am still not registered.</p><p class=\"lowlight\" style=\"left: 30.75%; top: 43.0391%; position: absolute;\">super nice sublet. I\\'ll be rejected in a month though.</p><p class=\"lowlight\" style=\"left: 60.3757%; top: 46.2333%; position: absolute;\">i got ejected from a bike here. i was just trying to move through space, but bikes don\\'t like me</p><p class=\"lowlight\" style=\"left: 49.2084%; top: 34.0502%; position: absolute;\">My bike got stolen here.</p><p class=\"lowlight\" style=\"left: 38.4744%; top: 58.0105%; position: absolute;\">The first time I stayed overnight in Rotterdam, after a nice walk in the sun, I got stuck 2 hours at Centraal, because the Intercity direct broke down. I felt rejected by NS.</p><p class=\"lowlight\" style=\"left: 23.9572%; top: 33.8663%; position: absolute;\">I also felt rejection in Art Rotterdam 2020 when someone I knew from a gallery decided not to say hello back after me saying HELLO.</p><p class=\"lowlight\" style=\"left: 57.625%; top: 34.3803%; position: absolute;\">💫💔💥🥐🍟🍕</p><p class=\"lowlight\" style=\"left: 40.125%; top: 29.966%; position: absolute;\">missed a lot of trains</p><p class=\"lowlight\" style=\"left: 51.123%; top: 18.1686%; position: absolute;\">I felt rejected from some friends that made me a book but stop replying to my messages after my breakup.</p><p class=\"lowlight\" style=\"left: 44.3557%; top: 20.4458%; position: absolute;\">my first no-credit-card experience</p><p class=\"highlight\" style=\"left: 55.621%; top: 33.6313%; position: absolute;\">we were going to a friends house when we got trapped into the riot against covid restrictions and a car got on fire and it was super bad to see all the anger all these people had i felt small and sad and i just wanted to run as faster as i could</p><p class=\"lowlight\" style=\"left: 39.745%; top: 19.3153%; position: absolute;\">my second no-credit card experience in a super nice bar; however, they were ok with a bank transfer :D </p><p class=\"lowlight\" style=\"left: 57.9156%; top: 37.276%; position: absolute;\">People throwing firework at other people here during an anti corona demonstration. </p><p class=\"lowlight\" style=\"left: 50.3743%; top: 52.0349%; position: absolute;\">I felt rejected here when the friend mentioned in n3 introduced me to someone else calling me \"Raquel\"</p><p class=\"lowlight\" style=\"left: 73.703%; top: 49.514%; position: absolute;\">i got rejected from a skateboard here. it\\'s normal though because it\\'s always trying to reject you and you love it anyway</p><p class=\"lowlight\" style=\"left: 58.7942%; top: 43.0025%; position: absolute;\">they called me and tried to get my bank details saying that my bsn number has been used for illigal and criminal activities in amsterdam</p><p class=\"lowlight\" style=\"left: 64.4007%; top: 39.7934%; position: absolute;\">my wallet rejected me for about 10 mins heree. it fell from my pocket at albert heijn but we reunited at the customer service desk. it was intense.</p><p class=\"highlight\" style=\"left: 33.8622%; top: 34.9877%; position: absolute;\">house rejection\\n</p>'"
]
},
"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
}