Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • frank/wakefield-movie-recommender
1 result
Show changes
Commits on Source (5)
/config.local
/tmp
/cache
# Add patterns of files dvc should ignore, which could improve
# the performance. Learn more at
# https://dvc.org/doc/user-guide/dvcignore
__pycache__/
.ipynb_checkpoints/
*.ipynb
/examples
# Copyright 2022, Frank Sauerburger
"""Movie title suggestion api"""
import json
from flask import Flask, request
import qgram
app = Flask(__name__)
with open("examples/titles.json") as fileobj:
titles = json.load(fileobj)
index = qgram.QGramIndex()
for title, _ in titles.values():
index.add_term(title)
@app.route("/")
def suggest():
query = request.args.get("q")
if not query:
return {}
results = index.search(query)
return {
"suggestions": results[:100]
}
outs:
- md5: 89bb55be2fbe9a824be916d12042252b.dir
size: 394035
nfiles: 2
path: examples
......@@ -40,7 +40,7 @@ class QGramIndex:
jaccard = count / (n_term + n_query - count)
result.append((jaccard, term))
result.sort(key=lambda x: x[0])
result.sort(key=lambda x: -x[0])
return result
......@@ -55,7 +55,7 @@ class QGramIndex:
The beginning and end of the string is denoted by a dollar sign ($).
If the term is too short, the qgrams might be shorter than q.
"""
term = f"${term}$"
term = f"${term}$".lower()
qgrams = []
if len(term) < self.q_param:
......
flask~=2.1.2
......@@ -9,6 +9,12 @@ from qgram import QGramIndex
class QGramChunkTest(unittest.TestCase):
"""Test the implementation"""
def test_case(self):
"""Test the chunk converts to lower case"""
index = QGramIndex()
qgrams = index._chunk("WeaTHer")
self.assertEqual(qgrams, ["$we", "wea", "eat", "ath", "the", "her", "er$"])
def test_long(self):
"""Test the chunk method with a long string"""
index = QGramIndex()
......