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.
si16-cat-walking/_wip/jian_project_functions.ipynb

12 KiB

In [1]:
from urllib.request import urlopen
import json

Area Map: 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.

In [2]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# (combined with html_tag_list)

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read()) 

def area_map_list(labels: list, left: int, right: int, top: int, bottom: int ) -> list:   
    
    filtered_map = []
    for label in labels:
        if left <= (label['position']['x']) <= right and top <= (label['position']['y']) <= bottom:
            filtered_map.append(label)
        
    return filtered_map

#area_map_list(data_json['labels'], 0, 10, 30, 70)

Ghost Map: 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.

In [4]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# this function links to jian.css

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read()) 

def ghost_map_list(labels: list, ghost_glyph: str ) -> str:
    
    filtered_map = '<link rel="stylesheet" href="/soupboat/si16-app/static/css/jian.css">'
    for label in labels:
        replaced_text = ''
        for char in label['text']:
            replaced_char = char
            if not char.isspace():
                replaced_char = ghost_glyph
            replaced_text = replaced_text + replaced_char
        html_tag = f'<p class="ghost" style="left: {label["position"]["x"]}%; top: {label["position"]["y"]}%; position: absolute;">{ replaced_text }</p>'
        filtered_map = filtered_map + html_tag
    return filtered_map

#ghost_map_list(data_json['labels'], '.')

Highlight Map: 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.

In [5]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# this function links to jian.css

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read())  

def highlight_map_list(labels: list, target: str ) -> str:

    filtered_map = '<link rel="stylesheet" href="/soupboat/si16-app/static/css/jian.css">'
    for label in labels:
        if target in label['text']:
            highlight_tag = f'<p class="highlight" style="left: {label["position"]["x"]}%; top: {label["position"]["y"]}%; position: absolute;">{ label["text"] }</p>'
            filtered_map = filtered_map + highlight_tag
        else:
            html_tag = f'<p class="lowlight" style="left: {label["position"]["x"]}%; top: {label["position"]["y"]}%; position: absolute;">{ label["text"] }</p>'
            filtered_map = filtered_map + html_tag
        
    return filtered_map

#highlight_map_list(data_json['labels'], 'tunnel')

html-tag: 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.

In [6]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# this function links to jian.css

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read())  

def html_tag_list(labels: list, position: bool, text: bool, timestamp: bool, userID: bool ) -> str: 
    
    html_tags = '<link rel="stylesheet" href="/soupboat/si16-app/static/css/jian.css">'
    for label in labels:
        html_tags = html_tags + f'<p style="left: {label["position"]["x"]}%; top: {label["position"]["y"]}%; position: absolute;">'
        if position == True:
            html_position = f'{ label["position"] } '
            html_tags = html_tags + html_position
        if text == True:
            html_text = f'{ label["text"] } '
            html_tags = html_tags + html_text
        if timestamp == True:
            html_timestamp = f'{ label["timestamp"] } '
            html_tags = html_tags + html_timestamp
        if userID == True:
            html_userID = f'{ label["userID"] } '
            html_tags = html_tags + html_userID
        html_tags = html_tags + '</p>'
    
    return html_tags

#html_tag_list(data_json['labels'], True, False, False, False)

Individual 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 targetsselect one or more specific users and return a list of all labels from these users.

In [9]:
# function for the project!
# hei kamo! is it already in the flask? should be?
# (combined with html_tag_list)

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read()) 

def individual_map_list(labels: list, users: list ) -> list:  
    
    filtered_map = []
    for label in labels:
        for user in users:
            if label['userID'] == user:
                filtered_map.append(label)
    return filtered_map

#individual_map_list(data_json['labels'], ['5058763759', '5941298752'])

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

In [7]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# (combined with html_tag_list)

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read()) 

def target_map_list(labels: list, targets: list ) -> list:       
    
    filter_map = []
    for label in labels:
        for target in targets:
            if target in label['text']:
                filter_map.append(label)
    return filter_map

#target_map_list(data_json['labels'], ['tunnel', 'happy'])

Vernacular Map: 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.

In [8]:
# function for the project!
# please, kamo, put it in the flask app! thxxxx
# this function links to jian.css

url = "https://hub.xpub.nl/soupboat/generic-labels/get-labels/?image=rejection_map.jpg/"
response = urlopen(url)
data_json = json.loads(response.read())  

def vernacular_map_list(labels: list) -> str:   

    filtered_map = '<link rel="stylesheet" href="/soupboat/si16-app/static/css/jian.css">'
    for label in labels:
        html_tag = f'<p style="left: {label["position"]["x"]}%; top: {label["position"]["y"]}%; position: absolute;">{ label["text"] }</p>'
        filtered_map = filtered_map + html_tag
        
    return filtered_map

#vernacular_map_list(data_json['labels'])
In [ ]: