{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "aecab081-a69a-4e38-9a30-cfc95661e56b", "metadata": {}, "outputs": [], "source": [ "from urllib.request import urlopen\n", "import json" ] }, { "cell_type": "markdown", "id": "9538705e-e51e-49da-b4fe-e6c4c6f6c435", "metadata": {}, "source": [ "Area Map:\n", "Give a string with the name of the image-file that was annotated with the Annotation Compass; Select a specific area of the image, return a list of all labels in that specific area." ] }, { "cell_type": "code", "execution_count": 2, "id": "13246f4a-81ac-4b68-b974-ae04064d10cc", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# (combined with html_tag_list)\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def area_map_list(labels: list, left: int, right: int, top: int, bottom: int ) -> list: \n", " \n", " filtered_map = []\n", " for label in labels:\n", " if left <= (label['position']['x']) <= right and top <= (label['position']['y']) <= bottom:\n", " filtered_map.append(label)\n", " \n", " return filtered_map\n", "\n", "#area_map_list(data_json['labels'], 0, 10, 30, 70)" ] }, { "cell_type": "markdown", "id": "34b43aae-0830-47ca-86c9-5827bfa44cef", "metadata": {}, "source": [ "Ghost Map:\n", "Give a string with the name of the image-file that was annotated with the Annotation Compass; Replace all characters of all annotation-texts with a ghost-glyph and return a string that includes all replaced annotation-texts plus html-tags that place them back into their original position." ] }, { "cell_type": "code", "execution_count": 4, "id": "dcbe893c-d00a-4933-9a18-8216a5f7459a", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# this function links to jian.css\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def ghost_map_list(labels: list, ghost_glyph: str ) -> str:\n", " \n", " filtered_map = ''\n", " for label in labels:\n", " replaced_text = ''\n", " for char in label['text']:\n", " replaced_char = char\n", " if not char.isspace():\n", " replaced_char = ghost_glyph\n", " replaced_text = replaced_text + replaced_char\n", " html_tag = f'

{ replaced_text }

'\n", " filtered_map = filtered_map + html_tag\n", " return filtered_map\n", "\n", "#ghost_map_list(data_json['labels'], '.')" ] }, { "cell_type": "markdown", "id": "863a6716-d9e4-413f-a597-a16cc0f04d6d", "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": 5, "id": "18cfc4fa-4039-49fe-8b29-5bbec0e89b6f", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# this function links to jian.css\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def highlight_map_list(labels: list, target: str ) -> str:\n", "\n", " filtered_map = ''\n", " for label in labels:\n", " if target in label['text']:\n", " highlight_tag = f'

{ label[\"text\"] }

'\n", " filtered_map = filtered_map + highlight_tag\n", " else:\n", " html_tag = f'

{ label[\"text\"] }

'\n", " filtered_map = filtered_map + html_tag\n", " \n", " return filtered_map\n", "\n", "#highlight_map_list(data_json['labels'], 'tunnel')" ] }, { "cell_type": "markdown", "id": "9c41f5fd-1071-43b3-88bc-41a8e5907fdb", "metadata": {}, "source": [ "html-tag:\n", "Give a string with the name of the image-file that was annotated with the Annotation Compass; Return a string that can include the position, text, timestamp and/or userID of all labels plus html-tags that place them back into their original position." ] }, { "cell_type": "code", "execution_count": 6, "id": "a7ee1bdf-a356-4a66-aa01-ef1dad8738ca", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# this function links to jian.css\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def html_tag_list(labels: list, position: bool, text: bool, timestamp: bool, userID: bool ) -> str: \n", " \n", " html_tags = ''\n", " for label in labels:\n", " html_tags = html_tags + f'

'\n", " if position == True:\n", " html_position = f'{ label[\"position\"] } '\n", " html_tags = html_tags + html_position\n", " if text == True:\n", " html_text = f'{ label[\"text\"] } '\n", " html_tags = html_tags + html_text\n", " if timestamp == True:\n", " html_timestamp = f'{ label[\"timestamp\"] } '\n", " html_tags = html_tags + html_timestamp\n", " if userID == True:\n", " html_userID = f'{ label[\"userID\"] } '\n", " html_tags = html_tags + html_userID\n", " html_tags = html_tags + '

'\n", " \n", " return html_tags\n", "\n", "#html_tag_list(data_json['labels'], True, False, False, False)" ] }, { "cell_type": "markdown", "id": "d05dd98e-0cdb-4a50-839a-7a67cdc22010", "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": 9, "id": "e8d7824d-4523-46f7-b89f-0e8f2d98e564", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# hei kamo! is it already in the flask? should be?\n", "# (combined with html_tag_list)\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def individual_map_list(labels: list, users: list ) -> list: \n", " \n", " filtered_map = []\n", " for label in labels:\n", " for user in users:\n", " if label['userID'] == user:\n", " filtered_map.append(label)\n", " return filtered_map\n", "\n", "#individual_map_list(data_json['labels'], ['5058763759', '5941298752'])" ] }, { "cell_type": "markdown", "id": "0f3febed-e702-4585-a7a1-e62d1a16d1c0", "metadata": {}, "source": [ "Target 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 targets" ] }, { "cell_type": "code", "execution_count": 7, "id": "9d263750-bab0-4989-9074-a58eba21b2c5", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# (combined with html_tag_list)\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def target_map_list(labels: list, targets: list ) -> list: \n", " \n", " filter_map = []\n", " for label in labels:\n", " for target in targets:\n", " if target in label['text']:\n", " filter_map.append(label)\n", " return filter_map\n", "\n", "#target_map_list(data_json['labels'], ['tunnel', 'happy'])" ] }, { "cell_type": "markdown", "id": "a8e5a256-b9e6-4f0f-b395-690c36d88a7e", "metadata": {}, "source": [ "Vernacular Map:\n", "Give a string with the name of the image-file that was annotated with the Annotation Compass; Return a string that includes all annotation-texts plus html-tags that place them back into their original position." ] }, { "cell_type": "code", "execution_count": 8, "id": "d78dca69-5f1e-408d-85b5-6cc594f2f875", "metadata": {}, "outputs": [], "source": [ "# function for the project!\n", "# please, kamo, put it in the flask app! thxxxx\n", "# this function links to jian.css\n", "\n", "url = \"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/\"\n", "response = urlopen(url)\n", "data_json = json.loads(response.read()) \n", "\n", "def vernacular_map_list(labels: list) -> str: \n", "\n", " filtered_map = ''\n", " for label in labels:\n", " html_tag = f'

{ label[\"text\"] }

'\n", " filtered_map = filtered_map + html_tag\n", " \n", " return filtered_map\n", "\n", "#vernacular_map_list(data_json['labels'])" ] }, { "cell_type": "code", "execution_count": null, "id": "6a207852-701e-48ef-8469-96c245aea6a4", "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 }