
------------------------------------------------------------------------------------------------

def sss_similarity(s1, s2, threshold=0.50, type='relation', corpus='webbase'):
    sss_url = "http://swoogle.umbc.edu/SimService/GetSimilarity"
    try:
        response = get(sss_url,
                       params={'operation': 'api', 'phrase1': s1, 'phrase2': s2, 'type': type, 'corpus': corpus})
        similarity = float(response.text.strip())
        return similarity
    except Exception as ex:
        print ex.msg
        return 0

s1 = u'When I try to build the index for the applications, the KHelpCenter would hang, now it just crashes.'
s2 = u'As I said, I can install fonts - so I know the basic system works.'
print sss_similarity(s1, s2)
s2 = u'If it does, then the font installed has an issue, if not then it is an system problem.'
print sss_similarity(s1, s2)
s2 = u'Installing (and removing) system fonts is now working for me in KDE 4.14.9, except that I always get prompted for root authentication twice.'
print sss_similarity(s1, s2)

s1 = u"I\\'m a newbie to KDE, and it would be very helpful to have an index to the application documents/handbooks."
s2 = u'So, this does sound like a system issue.'
print sss_similarity(s1, s2)

------------------------------------------------------------------------------------------------

# [sb['id'] for sb in recommended_similar_bugs]
bug_ids = [351900, 347673, 351405, 340147, 347145, 348378, 343961]

sentences = []
for idx, id in enumerate(ids):
   if id in bug_ids:
     sentences.append(aux_sentences[idx])

for s1 in original:
   for s2 in sentences:
     similarity = sss(s1, s2)
     print similarity
     if similarity >= 0.25:
       print s1
       print
       print s2



sample_ok = [
    351724, 
    350707, 
    277464, 
    351405,  
    269619, 
    300577, 
    351869, 
    351900, 
    343772,
    335678,
    300951,
    343961,
    351559,
    343982,
    341951,
    344114 
]

def chunks(l, n):
    for i in range(0, len(l), n):
        yield l[i:i + n]


batch = chunks(aux, bugs_per_chunk)
for i, current_batch in enumerate(batch):
    analysis_similarity_file = 'analysis_similarity_file_{}.json'.format(str(i))
    print analysis_similarity_file
    with open(analysis_similarity_file, 'wb+') as outfile:
        json.dump(current_batch, outfile, indent=4, sort_keys=True)

def count_similar(data, t):
    count = 0
    for a in data:
        if a['value']['similarity'] >= t:
            count += 1
    return count


with open('analysis_similarity_file.json', 'rb') as data:
    aux = json.load(data)

def pairs_in_range(data, lower_bound, upper_bound):
    return [r['key'] for r in data if lower_bound <= r['value']['similarity'] < upper_bound]

def percentage_in_range(tuples_in_range, data):
    return len(tuples_in_range) / len(data)

semantic_020_025 = pairs_in_range(analyses, 0.20, 0.25)
semantic_025_030 = pairs_in_range(analyses, 0.25, 0.30)
semantic_030_035 = pairs_in_range(analyses, 0.30, 0.35)
semantic_035_040 = pairs_in_range(analyses, 0.35, 0.40)
semantic_040_045 = pairs_in_range(analyses, 0.40, 0.45)
semantic_045_050 = pairs_in_range(analyses, 0.45, 0.50)
semantic_050_055 = pairs_in_range(analyses, 0.50, 0.55)   
semantic_065_070 = pairs_in_range(analyses, 0.65, 0.70) 
semantic_070_075 = pairs_in_range(analyses, 0.70, 0.75) 


percentage_in_range(semantic_020_025, analyses)
percentage_in_range(semantic_030_035, analyses)
percentage_in_range(semantic_035_040, analyses)
percentage_in_range(semantic_040_045, analyses)
percentage_in_range(semantic_045_050, analyses)
percentage_in_range(semantic_050_055, analyses)

percentage_in_range(semantic_065_070, analyses)
percentage_in_range(semantic_070_075, analyses)

list(filter(lambda a: a['key'] == random.choice(semantic_020_025), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_025_030), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_030_035), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_035_040), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_040_045), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_045_050), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_050_055), analyses))
list(filter(lambda a: a['key'] == random.choice(semantic_065_070), analyses))

list(filter(lambda a: a['key'] == random.choice(semantic_070_075), analyses))



random.choice(semantic_045_050)
random.choice(semantic_045_050)

random.choice(semantic_050_055)
random.choice(semantic_050_055)


with open('problem_vector_similarity_map.json', 'rb') as data:
    aux = json.load(data)
    vector_similarity_map = {}
    for r in aux:
        key = (r['key'][0], r['key'][1])
        value = r['value']
        vector_similarity_map[key] = value


[  266290, -- search
 122437, 
           [164308, 
           , 
           
           
            311799, 
           101876]



351869, 351627 <- wrong summary

def is_in(key):
    return len(list(filter(lambda a: key in a['key'], analyses))) > 0

def threshold_of(a, b):
    return list(filter(lambda x: x['key'] == [a, b], analyses))

------------------------------------------------------------------------------------------------


Teaching assistantship is a job, and for scheduling purposes TA duties take precedence over all other UBC-related duties, except for regularly scheduled activities (lectures, labs, etc.) for the courses that the TA is taking for credit.

import os, sys
from PIL import Image
from resizeimage import resizeimage


from os import listdir
from os.path import isfile, join

cwd = os.getcwd()
onlyfiles = [f for f in listdir(cwd) if isfile(join(cwd, f))]

for i, f in enumerate(onlyfiles):
    try:
        with open(f, 'r+b') as f:
            with Image.open(f) as image:
                cover = resizeimage.resize_cover(image, [210, 330])
                outfile = 'large/portrait_{}_lg.jpeg'.format(str(i))
                cover.save(outfile, image.format)
    except Exception as ex:
        print ex
        continue