{ "cells": [ { "cell_type": "markdown", "id": "66f72396-0cf1-41cf-a486-2930d2ad1652", "metadata": {}, "source": [ "# individual_map\n", "give a string with the name of the image-file that was annotated with the Annotation Compass; Select one or more specific targets and return a list of all labels that include these targetsselect one or more specific users and return a list of all labels from these users." ] }, { "cell_type": "code", "execution_count": 6, "id": "de97fe2f-daae-4293-a0b3-ea42c759535a", "metadata": {}, "outputs": [], "source": [ "from urllib.request import urlopen\n", "import json" ] }, { "cell_type": "code", "execution_count": 7, "id": "9bd8860a-9967-49d5-a74a-b5de669dfe6d", "metadata": {}, "outputs": [], "source": [ "def individual_map(image: str, users: list ) -> list:\n", " \n", " \"\"\"give a string with the name of the image-file that was annotated with the Annotation Compass; Select one or more specific targets and return a list of all labels that include these targetsselect one or more specific users and return a list of all labels from these users.\"\"\" \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 = []\n", " for label in data_json['labels']:\n", " for user in users:\n", " if label['userID'] == user:\n", " filtered_map.append(label)\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 of one or more specific users, individual_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 as well as one or more specific userIDs to target. The output is a list of all labels from the users of interest.\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 returns all annotation-labels of two specific users." ] }, { "cell_type": "code", "execution_count": 5, "id": "e3d7e97b-0089-4c29-a2c1-9ef823ff2e37", "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[{'image': 'rejection_map.jpg',\n", " 'position': {'x': 63.9896, 'y': 34.2958},\n", " 'size': {'height': 3.23944, 'width': 2.90155},\n", " 'text': 'here, someone called my behaviour \"strange\"',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:36:04 GMT',\n", " 'userID': '8112114057'},\n", " {'image': 'rejection_map.jpg',\n", " 'position': {'x': 39.3264, 'y': 46.831},\n", " 'size': {'height': 6.19718, 'width': 9.2228},\n", " 'text': 'here, someone screamed at me \"move fucking chinee\"',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:36:55 GMT',\n", " 'userID': '8112114057'},\n", " {'image': 'rejection_map.jpg',\n", " 'position': {'x': 36.5285, 'y': 54.2958},\n", " 'size': {'height': 1.69014, 'width': 3.31606},\n", " 'text': 'here, someone screamed at me, right into my face, something I could not understand',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:37:37 GMT',\n", " 'userID': '8112114057'},\n", " {'image': 'rejection_map.jpg',\n", " 'position': {'x': 42.5389, 'y': 45.7042},\n", " 'size': {'height': 13.662, 'width': 23.9378},\n", " 'text': 'here, someone told me to move away',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:38:04 GMT',\n", " 'userID': '8112114057'},\n", " {'image': 'rejection_map.jpg',\n", " 'position': {'x': 39.1192, 'y': 36.2676},\n", " 'size': {'height': 11.6901, 'width': 20.4145},\n", " 'text': 'here, someone told to stop looking at them',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:38:45 GMT',\n", " 'userID': '8112114057'},\n", " {'image': 'rejection_map.jpg',\n", " 'position': {'x': 46.3713, 'y': 58.4289},\n", " 'size': {'height': 6.99541, 'width': 15.1055},\n", " 'text': '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.',\n", " 'timestamp': 'Wed, 15 Dec 2021 11:40:54 GMT',\n", " 'userID': '6004575665'}]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "individual_map('rejection_map.jpg', ['8112114057', '6004575665'])" ] }, { "cell_type": "code", "execution_count": null, "id": "fcbbb728-217d-47a3-b672-d03d120fa408", "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 }