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

Set limit on list results #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ kalliope install --git-url https://github.com/kalliope-project/kalliope_neuron_w
## Options

| parameter | required | default | choices | comment |
|-----------|----------|---------|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| language | yes | | E.g: "fr", "en", "it", "es" | See the list of available language in the "Note" section |
| query | yes | | | The wikipedia page you are looking for. This parameter can be passed as an argument in the neuron from the order with {{ query}} |
|-----------|----------|---------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| language | yes | | E.g: "fr", "en", "it", "es" | See the list of available language in the "Note" section |
| query | yes | | | The wikipedia page you are looking for. This parameter can be passed as an argument in the neuron from the order with {{ query}} |
| sentences | no | 10 | Integer in range 1-10 | if set, return the first number of sentences(can be no greater than 10) specified in this parameter. |
| titles | no | ~ | Integer | With this parameter you can limit the number of search result in case there are more then one |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe titles is not the right name for this parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to wikipedia.summary those are auto_suggest.
So, what about auto_suggest or auto_suggest_limit ?



## Return Values
Expand Down Expand Up @@ -48,14 +49,14 @@ This synapse will look for the {{ query }} spelt by the user on Wikipedia

```

## Templates example
## Templates example

This template will simply make Kalliope speak out loud the summary section of the Wikipédia page of the query.
If the query match more than one page, Kaliope will give the user all matched pages.
If the query doesn't match any page on Wikipedia, kalliope will notify the user.
```
{% if returncode == "DisambiguationError" %}
The query match following pages
The query match following pages {% if titles %}limited to {{ titles }} results{% endif %}
{% if may_refer is not none %}
{% for page in may_refer %}
{{ page }}
Expand All @@ -76,5 +77,5 @@ Available languages in [the detailed list of the offical Wikipedia page](https:/

Copyright (c) 2016. All rights reserved.

Kalliope is covered by the MIT license, a permissive free software license that lets you do anything you want with the source code,
Kalliope is covered by the MIT license, a permissive free software license that lets you do anything you want with the source code,
as long as you provide back attribution and ["don't hold you liable"](http://choosealicense.com/). For the full license text see the [LICENSE.md](LICENSE.md) file.
4 changes: 3 additions & 1 deletion wikipedia_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, **kwargs):
self.query = kwargs.get('query', None)
self.language = kwargs.get('language', None)
self.sentences = kwargs.get('sentences', None)
self.titles = kwargs.get('titles', None)

self.may_refer = None
self.returncode = None
Expand All @@ -39,7 +40,7 @@ def __init__(self, **kwargs):
# The options property contains a list of titles of Wikipedia pages that the query may refer to.
self.may_refer = e.options
# Removing duplicates in lists.
self.may_refer = list(set(self.may_refer))
self.may_refer = list(set(self.may_refer))[:self.titles]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the behavior if not set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it defaults to None thanks to line 23 self.titles = kwargs.get('titles', None) and serves back all the results

self.returncode = "DisambiguationError"
summary = ""
except wikipedia.exceptions.PageError:
Expand All @@ -50,6 +51,7 @@ def __init__(self, **kwargs):
self.message = {
"summary": summary,
"may_refer": self.may_refer,
"titles": self.titles,
"returncode": self.returncode
}
logger.debug("Wikipedia returned message: %s" % str(self.message))
Expand Down