{ "cells": [ { "cell_type": "markdown", "id": "66f72396-0cf1-41cf-a486-2930d2ad1652", "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": 5, "id": "444e0267-c783-4b5a-9546-ad007175b6ea", "metadata": {}, "outputs": [], "source": [ "from urllib.request import urlopen\n", "import json" ] }, { "cell_type": "code", "execution_count": 6, "id": "9bd8860a-9967-49d5-a74a-b5de669dfe6d", "metadata": {}, "outputs": [], "source": [ "def ghost_map(image: str, ghost_glyph: str ) -> str:\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.\"\"\" \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", " 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" ] }, { "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 the traces the annotations leave, ghost_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 a ghost-glyph that will replace all characters of the annotation-texts. The output is a string that includes all replaced annotation-texts plus html-tags that place them back into their original position.\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 replaces all characters of the annotation-texts with a ghost-glyph" ] }, { "cell_type": "code", "execution_count": 4, "id": "60d22cde-79da-4dbd-a8a7-7028f785ec93", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'

##### ####### ###### ## ######### #########

#### ## ## ## #### ## # ## ## # ##### ## #### ## #### ### ### #### ##\\n# ### ## ## ## ####### \\n##### #### ## ### ## ### \\n## ## ###### ######## #### ###

### ############ ## ######### ####### ########## ###### ####### ## ####### ## ####### ## ############ ####### ### ####### ## #### ####### #### ## ### ####### ## ### \\n#### #### #### ## # ##### ## ##### ########### #### ###### #### ## # #### # ### #### ## ### ################### #####

####### # #### ####### #### ## #### ####### ####### ## #### ### #### ### ##### ## ## ######### ####### ### ######## ###

##### ####### ## ####### #### #### ##### ## ### ####### ## ### # ##### #### ##### ####### ### ######## ##### ### #### ######## ###

# #### #### ## #### # ##### #### ### ## ###### #### ### ###### #####

##### ####### ######## ## ## ##### ####### #######

##### ####### ######### ########## #####\\n

# ##### ## ### ##### ###### ## ### ###### ###### ### ##### ### # ####### ## ######### ### # ###### ###### ########## ### ####### ##### ### ### #### ### #### #### ## ## ### ##### #####

## ##### # #### ### ###### ## ### #### ### ########## ##### ####### ## #### #####

##### ####### ######## ## ### ##### #### ## ##### ######### # ##### ### ##########

### #### ########## ##### ######## ## ####### ########## #### ### ######## ###### ### # ###### ### ### ###### ## ####### #### ### #### ###### ##### ### ##### #### #### #### ### # ## ### #### ######## ## ### ### #####

####### ### ## ### ##### ### ####### ### ####### ### ####### #### ### ### #### ### ### ## #### ##### ###### ### # ####### ## #### ## ######## ######## ## ############

##### ####### #### ## ## #### ####

# ### ### #### ####### ##### ####### ##### ### ###### ###### ###### ## ## ### ###### ### ## #### #### #### ###### #### ### ########## # ### ### ### ### #####

######## ## ### ######

## ##### ##### ######## # ### ###### ####### ##### #### #### ######### ####### # #### # ########## #### ### ##### # ###### # ##### ## ## ######## #### #### ####

##### ####### #### ## #### ####### ## ####

# ### ### #### ####### ##### ####### ##### ### ###### ###### ###### ## ## ### ###### ### ## #### #### #### ###### #### ### ### ############# # ### ### ### ### #####

### ## ###### ######### #### # ### ### ##### ## ### #### #### ## #### ## #### ## ##### ##### ##### ## ### #### ## ### ### ## #### ### ###### ### ### ## #### ## #####

# ######## ### ######## #### # #### ####### ## ### ####### #### ### ########### #########

# #### ######### ## ### ######### #### #### ### ####### ## ## ########### ############ #### ## ##### ## ############ ########## ##### ### # #### ##### ### ## ###### #######

##### ## #### ## #### ### ## ########### ## ######

## ### ###### ## #### #### # #### #### ## #### ####### #### ####### ## ##### # ####### ### ## ### ### ######### ## #### ### ##### ## ###### #### ###

######### ####### #### #### # #### ## ## ##### ### # ###### ##### ##### #### #### ##### ###### # ### ## ############ ## ### ############# #### ##### ######### ### ####### ### ### ## # #### # ### ########## ##### ###### ## ###### ######## ######### ### # ## ### ####### ###### ### # ## ##### ### ###########

##### #### ####### #### ## ######## ## # ##### #######

# ### ####### #### # #### ##### # ### #### ###### ## #### ####### ###### ### ##### ##### #### ##

## #### ### ###### #####

### ##### #### # ###### ######### ## ########## ##### # #### #### ## ### #### # ### ##### # ##### ## ######### ####### ### ######### ###### ##### ##### # #### ######## ## ###

# #### #### ######### ## ### ######### #### #### ####### # #### #### # ####### ####### ### ## ### ##### #### ##### ## ###### ######

######

###### # ### ## ######

# #### ######## #### #### ####### #### #### ## # #### ### #### ######## ## ## ######## ##### ## ########

## ##### ############## ##########

## #### ##### ## # ####### ##### #### ## ### ####### #### ### #### ####### ##### ############ ### # ### ### ## #### ### ## ### ##### ### ## ### ### ### ##### ### ##### ###### ### # #### ##### ### ### ### # #### ###### ## ### ## ###### ## # #####

## ###### ######### #### ########## ## # ##### #### #### ######## #### #### ## #### # #### ######## ##

###### ######## ######## ## ##### ###### #### ###### ## #### ###### ##############

# #### ######## #### #### ### ###### ######### ## ## ########## ## ## ####### #### ####### ## ########

# ### ######## #### # ########## ##### #### ###### ###### ####### #### ###### ###### ## ###### ### ### ### #### ## ######

#### ###### ## ### ##### ## ### ## #### ####### ###### #### ## ### ###### ### #### #### ### ####### ### ######## ########## ## #########

## ###### ######## ## ### ##### ## #### ###### ## #### #### ## ###### ## ###### ##### ### ## ######## ## ### ######## ####### ##### ## ### ########

##### #########\\n

##### ##### ## ######### # ### ## ##### ######### ### # #### ## #### ############## ### #### #### ### # ### ###### ## #### ### ### ## ### #### # ### ######### ### #### ### ##### ##### ##### ## #### # ###### #### ## #### #### # #### # ### ######## ##### #####

#### ## ### ############ ##### # ####### ######### ### ### ##### ##### # ### ####### #### ###### # ## ######## # ### ####### # ######## ## ##### ### ####### ## #### # ##### ##### ## #### ##### ## #### #### ####

# #### ##### #### ## #### #### ## ########## # ##### # ######## ## ### #### #######

# #### ####### # #### ### ## ### ###### ## ##

'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ghost_map('rejection_map.jpg', '#')" ] }, { "cell_type": "code", "execution_count": null, "id": "7a8c88f3-2f16-4dce-9e29-547648e251c2", "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 }