Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename REST "analyze" method to "suggest" #272

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions annif/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def show_project(project_id):
return project.dump()


def analyze(project_id, text, limit, threshold):
"""analyze text and return a dict with results formatted according to
Swagger spec"""
def suggest(project_id, text, limit, threshold):
"""suggest subjects for the given text and return a dict with results
formatted according to Swagger spec"""

try:
project = annif.project.get_project(
Expand Down
6 changes: 3 additions & 3 deletions annif/swagger/annif.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ paths:
$ref: '#/definitions/Problem'
tags:
- Project administration
'/projects/{project_id}/analyze':
'/projects/{project_id}/suggest':
post:
summary: suggest subjects for a given text
operationId: annif.rest.analyze
operationId: annif.rest.suggest
consumes:
- application/x-www-form-urlencoded
produces:
Expand All @@ -60,7 +60,7 @@ paths:
- $ref: '#/parameters/project_id'
- name: text
in: formData
description: text to analyze
description: input text
required: true
type: string
- name: limit
Expand Down
6 changes: 3 additions & 3 deletions annif/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h2 v-if="problem.hasTitle()"><% problem.title %></h2>
</div>
<div class="col-md-4">
<annif-projects :projects="projects" @project-selected="onProjectSelected"></annif-projects>
<button type="button" class="btn btn-primary" @click="analyze" :disabled="loading">
<button type="button" class="btn btn-primary" @click="suggest" :disabled="loading">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" v-if="loading"></span>
<span v-if="!loading">Analyze</span>
<span v-else>Loading...</span>
Expand Down Expand Up @@ -183,7 +183,7 @@ <h2 class="mt-4">Results</h2>\
}
});
},
analyze: function(event) {
suggest: function(event) {
this.problems = [];
if (this.text.trim() === "") {
this.problems.push(new Problem('', 'You need to enter the text to analyze', false));
Expand All @@ -198,7 +198,7 @@ <h2 class="mt-4">Results</h2>\
}
var this_ = this;
$.ajax({
url: "/v1/projects/" + this_.project + "/analyze",
url: "/v1/projects/" + this_.project + "/suggest",
method: 'POST',
data: {
text: this_.text,
Expand Down
22 changes: 11 additions & 11 deletions tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,52 @@ def test_rest_show_project_nonexistent(app):
assert result.status_code == 404


def test_rest_analyze_public(app):
def test_rest_suggest_public(app):
# public projects should be accessible via REST
with app.app_context():
result = annif.rest.analyze(
result = annif.rest.suggest(
'dummy-fi',
text='example text',
limit=10,
threshold=0.0)
assert 'results' in result


def test_rest_analyze_hidden(app):
def test_rest_suggest_hidden(app):
# hidden projects should be accessible if you know the project id
with app.app_context():
result = annif.rest.analyze(
result = annif.rest.suggest(
'dummy-en',
text='example text',
limit=10,
threshold=0.0)
assert 'results' in result


def test_rest_analyze_private(app):
def test_rest_suggest_private(app):
# private projects should not be accessible via REST
with app.app_context():
result = annif.rest.analyze(
result = annif.rest.suggest(
'dummydummy',
text='example text',
limit=10,
threshold=0.0)
assert result.status_code == 404


def test_rest_analyze_nonexistent(app):
def test_rest_suggest_nonexistent(app):
with app.app_context():
result = annif.rest.analyze(
result = annif.rest.suggest(
'nonexistent',
text='example text',
limit=10,
threshold=0.0)
assert result.status_code == 404


def test_rest_analyze_novocab(app):
def test_rest_suggest_novocab(app):
with app.app_context():
result = annif.rest.analyze(
result = annif.rest.suggest(
'novocab',
text='example text',
limit=10,
Expand All @@ -111,7 +111,7 @@ def test_rest_learn(app):
response = annif.rest.learn('dummy-en', documents)
assert response == (None, 204) # success, no output

result = annif.rest.analyze(
result = annif.rest.suggest(
'dummy-en',
text='example text',
limit=10,
Expand Down