Skip to content

Commit

Permalink
Fix #1 handle property id in the web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fnielsen committed Nov 5, 2024
1 parent b424743 commit 2ac1049
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wembedder/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from functools import wraps

import re

from flask import (
Blueprint, current_app, jsonify, render_template, request)
from werkzeug.routing import BaseConverter
Expand Down Expand Up @@ -70,9 +68,9 @@ def decorated_function(*args, **kwargs):

# Wikidata item identifier matcher
q_pattern = r'<regex("Q[1-9]\d*"):q>'
p_pattern = r'<regex("P[1-9]\d*"):q>' # Note variable is 'q'
q1_pattern = r'<regex("Q[1-9]\d*"):q1>'
q2_pattern = r'<regex("Q[1-9]\d*"):q2>'
Q_PATTERN = re.compile(r'Q[1-9]\d*')


def sanitize_language(language):
Expand Down Expand Up @@ -108,13 +106,15 @@ def about():
return render_template('about.html')


@main.route('/most-similar/' + p_pattern)
@main.route('/most-similar/' + q_pattern)
@main.route('/most-similar/')
def show_most_similiar(q=None):
language = sanitize_language(request.args.get('language'))
return render_template('most-similar.html', q=q, language=language)


@main.route('/api/most-similar/' + p_pattern)
@main.route('/api/most-similar/' + q_pattern)
@jsonp
def api_most_similar(q):
Expand Down Expand Up @@ -194,7 +194,7 @@ def api_similarity(q1, q2):
"""
try:
# float is due to "TypeError: Object of type float32 is not JSON
# serializable"
# serializable"
similarity = float(current_app.model.similarity(q1, q2))
except KeyError:
message = {
Expand Down Expand Up @@ -222,6 +222,7 @@ def api_similarity(q1, q2):
return response


@main.route('/api/vector/' + p_pattern)
@main.route('/api/vector/' + q_pattern)
def api_vector(q):
"""Return JSON for raw vector.
Expand Down

0 comments on commit 2ac1049

Please sign in to comment.