def raw_finder(lang, model, userquery): g.lang = lang g.strings = language_dicts[lang] model = model.strip() if not model.strip() in our_models: return render_template('home.html') if userquery.strip().replace('_', '').replace('-', '').isalnum(): query = process_query(userquery.strip()) if tags: if len(query.split('_')) < 2: return render_template('wordpage.html', error=query) pos_tag = query.split('_')[-1] else: pos_tag = 'ALL' message = "1;" + query + ";" + pos_tag + ";" + model result = serverquery(message) associates_list = [] if "unknown to the" in result or "No results" in result: return render_template('wordpage.html', error=result.decode('utf-8')) else: output = result.split('&') associates = output[0] if len(associates) > 1: vector = ','.join(output[1:]) for word in associates.split(): w = word.split("#") associates_list.append((w[0].decode('utf-8'), float(w[1]))) m = hashlib.md5() name = query.encode('ascii', 'backslashreplace') m.update(name) fname = m.hexdigest() plotfile = root + 'static/singleplots/' + model + '_' + fname + '.png' if os.access(plotfile, os.F_OK) == False: vector2 = output[1].split(',') vector2 = [float(a) for a in vector2] singularplot(query, model, vector2) if dbpedia: if tags: image = getdbpediaimage(query.split('_')[0].encode('utf-8')) else: image = getdbpediaimage(query.encode('utf-8')) else: image = None return render_template('wordpage.html', list_value=associates_list, word=query, model=model, pos=pos_tag, vector=vector, image=image, vectorvis=fname, tags=tags) else: error_value = u'Incorrect query: %s' % userquery return render_template("wordpage.html", error=error_value, tags=tags) return render_template("wordpage.html", tags=tags)
def get_images(images): imagecache = {} imagedata = codecs.open(root + cachefile, 'r', 'utf-8') for LINE in imagedata: result = LINE.strip().split('\t') if len(result) == 2: (word, image) = result image = image.strip() if image == 'None': image = None imagecache[word.strip()] = image else: continue imagedata.close() for w in images: image = getdbpediaimage(w.encode('utf-8'), imagecache) if image: images[w] = image return images
def raw_finder(lang, model, userquery): g.lang = lang s = set() s.add(lang) other_lang = list(set(language_dicts.keys()) - s)[0] # works only for two languages g.strings = language_dicts[lang] model = model.strip() if not model.strip() in our_models: return render_template('home.html', other_lang=other_lang, languages=languages, url=url) if userquery.strip().replace('_', '').replace('-', '').replace('::', '').isalnum(): query = process_query(userquery.strip()) if tags: if len(query.split('_')) < 2: return render_template('wordpage.html', error=query, other_lang=other_lang, languages=languages, url=url) pos_tag = query.split('_')[-1] else: pos_tag = 'ALL' message = "1;" + query + ";" + pos_tag + ";" + model result = serverquery(message) associates_list = [] if "unknown to the" in result or "No results" in result: return render_template('wordpage.html', error=result.decode('utf-8'), other_lang=other_lang, languages=languages, url=url) else: output = result.split('&&&') associates = output[0] if len(associates) > 1: vector = ','.join(output[1:]) else: vector = '' for word in associates.split(): w = word.split("#") associates_list.append((w[0].decode('utf-8'), float(w[1]))) m = hashlib.md5() name = query.encode('ascii', 'backslashreplace') m.update(name) fname = m.hexdigest() plotfile = root + 'data/images/singleplots/' + model + '_' + fname + '.png' if not os.access(plotfile, os.F_OK): vector2 = output[1].split(',') vector2 = [float(a) for a in vector2] singularplot(query, model, vector2) if dbpedia: imagecache = {} imagedata = codecs.open(root + cachefile, 'r', 'utf-8') for line in imagedata: res = line.strip().split('\t') if len(res) == 2: (word, image) = res image = image.strip() if image == 'None': image = None imagecache[word.strip()] = image else: continue imagedata.close() image = getdbpediaimage( query.split('_')[0].encode('utf-8'), imagecache) else: image = None return render_template('wordpage.html', list_value=associates_list, word=query, model=model, pos=pos_tag, vector=vector, image=image, vectorvis=fname, tags=tags, other_lang=other_lang, languages=languages, url=url) else: error_value = u'Incorrect query: %s' % userquery return render_template("wordpage.html", error=error_value, tags=tags, other_lang=other_lang, languages=languages, url=url)