8.0 KiB
target_map¶
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
from urllib.request import urlopen import json
def target_map(image: str, targets: list ) -> list: """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.""" url = f"https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image={image}" response = urlopen(url) data_json = json.loads(response.read()) filter_map = [] for label in data_json['labels']: for target in targets: if target in label['text']: filter_map.append(label) return filter_map
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.
Example for a label:
{'image': 'map.jpg',
'position': {'x': 12, 'y': 97},
'size': {'width': 43, 'height': 18},
'text': 'This is a text! Is this a text?',
'timestamp': 'Wed, 01 Dec 2021 14:04:00 GMT',
'userID': 5766039063}
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.
How to get a json-file with annotation-labels?
https://hub.xpub.nl/soupboat/generic-labels/
The Annotation Compass allows people to uplaod an image and ask others to annotate it. A json-file of the annotations is provided.
Examples¶
In this example, the function returns all annotation-labels that include two specific targets.
target_map('rejection_map.jpg', ['house', 'sad'])
[{'image': 'rejection_map.jpg', 'position': {'x': 48.135, 'y': 20.4458}, 'size': {'height': 4.62487, 'width': 2.94785}, '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.', 'timestamp': 'Wed, 15 Dec 2021 11:36:48 GMT', 'userID': '1933684842'}, {'image': 'rejection_map.jpg', 'position': {'x': 76.25, 'y': 69.5246}, 'size': {'height': 12.3939, 'width': 15.625}, 'text': "I once went to view a house here but it didn't have the floor. crap.", 'timestamp': 'Wed, 15 Dec 2021 11:36:51 GMT', 'userID': '6286616941'}, {'image': 'rejection_map.jpg', 'position': {'x': 55.0889, 'y': 15.6154}, 'size': {'height': 4.21377, 'width': 3.55253}, '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?", 'timestamp': 'Wed, 15 Dec 2021 11:37:46 GMT', 'userID': '1933684842'}, {'image': 'rejection_map.jpg', 'position': {'x': 45.2507, 'y': 29.3907}, 'size': {'height': 6.09319, 'width': 6.59631}, '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.", 'timestamp': 'Wed, 15 Dec 2021 11:38:09 GMT', 'userID': '4287159985'}, {'image': 'rejection_map.jpg', 'position': {'x': 42.0882, 'y': 18.8014}, 'size': {'height': 3.08325, 'width': 1.66289}, '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.', 'timestamp': 'Wed, 15 Dec 2021 11:38:41 GMT', 'userID': '1933684842'}, {'image': 'rejection_map.jpg', 'position': {'x': 43.7995, 'y': 27.0609}, 'size': {'height': 9.319, 'width': 8.04749}, '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.", 'timestamp': 'Wed, 15 Dec 2021 11:39:12 GMT', 'userID': '1165348288'}, {'image': 'rejection_map.jpg', 'position': {'x': 55.621, 'y': 33.6313}, 'size': {'height': 15.6597, 'width': 7.43427}, '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', 'timestamp': 'Wed, 15 Dec 2021 11:43:45 GMT', 'userID': '4164927552'}, {'image': 'rejection_map.jpg', 'position': {'x': 55.621, 'y': 33.6313}, 'size': {'height': 15.6597, 'width': 7.43427}, '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', 'timestamp': 'Wed, 15 Dec 2021 11:43:45 GMT', 'userID': '4164927552'}, {'image': 'rejection_map.jpg', 'position': {'x': 33.8622, 'y': 34.9877}, 'size': {'height': 12.8237, 'width': 13.7806}, 'text': 'house rejection\n', 'timestamp': 'Wed, 15 Dec 2021 11:49:37 GMT', 'userID': '4164927552'}]