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.

191 lines
8.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "66f72396-0cf1-41cf-a486-2930d2ad1652",
"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": 5,
"id": "dc7040fd-ec5d-49e6-98e5-1feae91fc74b",
"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 target_map(image: str, targets: 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 targets.\"\"\" \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",
" filter_map = []\n",
" for label in data_json['labels']:\n",
" for target in targets:\n",
" if target in label['text']:\n",
" filter_map.append(label)\n",
" return filter_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 one or more specific targets, target_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 targets. The output is a list of all labels that include these targets.\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 that include two specific targets."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e3d7e97b-0089-4c29-a2c1-9ef823ff2e37",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[{'image': 'rejection_map.jpg',\n",
" 'position': {'x': 48.135, 'y': 20.4458},\n",
" 'size': {'height': 4.62487, 'width': 2.94785},\n",
" 'text': 'house viewing 2: meeting with some girls in the evening to see a room; felt super exposed and awkward. Later on, they rejected me.',\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:36:48 GMT',\n",
" 'userID': '1933684842'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 76.25, 'y': 69.5246},\n",
" 'size': {'height': 12.3939, 'width': 15.625},\n",
" 'text': \"I once went to view a house here but it didn't have the floor. crap.\",\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:36:51 GMT',\n",
" 'userID': '6286616941'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 55.0889, 'y': 15.6154},\n",
" 'size': {'height': 4.21377, 'width': 3.55253},\n",
" 'text': \"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?\",\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:37:46 GMT',\n",
" 'userID': '1933684842'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 45.2507, 'y': 29.3907},\n",
" 'size': {'height': 6.09319, 'width': 6.59631},\n",
" 'text': \"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.\",\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:38:09 GMT',\n",
" 'userID': '4287159985'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 42.0882, 'y': 18.8014},\n",
" 'size': {'height': 3.08325, 'width': 1.66289},\n",
" 'text': '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.',\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:38:41 GMT',\n",
" 'userID': '1933684842'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 43.7995, 'y': 27.0609},\n",
" 'size': {'height': 9.319, 'width': 8.04749},\n",
" 'text': \"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.\",\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:39:12 GMT',\n",
" 'userID': '1165348288'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 55.621, 'y': 33.6313},\n",
" 'size': {'height': 15.6597, 'width': 7.43427},\n",
" 'text': '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',\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:43:45 GMT',\n",
" 'userID': '4164927552'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 55.621, 'y': 33.6313},\n",
" 'size': {'height': 15.6597, 'width': 7.43427},\n",
" 'text': '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',\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:43:45 GMT',\n",
" 'userID': '4164927552'},\n",
" {'image': 'rejection_map.jpg',\n",
" 'position': {'x': 33.8622, 'y': 34.9877},\n",
" 'size': {'height': 12.8237, 'width': 13.7806},\n",
" 'text': 'house rejection\\n',\n",
" 'timestamp': 'Wed, 15 Dec 2021 11:49:37 GMT',\n",
" 'userID': '4164927552'}]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"target_map('rejection_map.jpg', ['house', 'sad'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c91b182-7541-4a79-a0f2-b2e688dd4371",
"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
}