H
commited on
Commit
·
71d5f05
1
Parent(s):
4b9f80a
Set wikipedia lang (#1515)
Browse files### What problem does this PR solve?
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- graph/component/wikipedia.py +11 -2
graph/component/wikipedia.py
CHANGED
|
@@ -30,9 +30,16 @@ class WikipediaParam(ComponentParamBase):
|
|
| 30 |
def __init__(self):
|
| 31 |
super().__init__()
|
| 32 |
self.top_n = 10
|
|
|
|
| 33 |
|
| 34 |
def check(self):
|
| 35 |
self.check_positive_integer(self.top_n, "Top N")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
class Wikipedia(ComponentBase, ABC):
|
|
@@ -45,9 +52,11 @@ class Wikipedia(ComponentBase, ABC):
|
|
| 45 |
return Wikipedia.be_output(self._param.no)
|
| 46 |
|
| 47 |
wiki_res = []
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
try:
|
| 50 |
-
page =
|
| 51 |
wiki_res.append({"content": '<a href="' + page.url + '">' + page.title + '</a> ' + page.summary})
|
| 52 |
except Exception as e:
|
| 53 |
print(e)
|
|
|
|
| 30 |
def __init__(self):
|
| 31 |
super().__init__()
|
| 32 |
self.top_n = 10
|
| 33 |
+
self.lang = 'en'
|
| 34 |
|
| 35 |
def check(self):
|
| 36 |
self.check_positive_integer(self.top_n, "Top N")
|
| 37 |
+
self.check_valid_value(self.lang, "Wikipedia languages",
|
| 38 |
+
['af', 'pl', 'ar', 'ast', 'az', 'bg', 'nan', 'bn', 'be', 'ca', 'cs', 'cy', 'da', 'de',
|
| 39 |
+
'et', 'el', 'en', 'es', 'eo', 'eu', 'fa', 'fr', 'gl', 'ko', 'hy', 'hi', 'hr', 'id',
|
| 40 |
+
'it', 'he', 'ka', 'lld', 'la', 'lv', 'lt', 'hu', 'mk', 'arz', 'ms', 'min', 'my', 'nl',
|
| 41 |
+
'ja', 'nb', 'nn', 'ce', 'uz', 'pt', 'kk', 'ro', 'ru', 'ceb', 'sk', 'sl', 'sr', 'sh',
|
| 42 |
+
'fi', 'sv', 'ta', 'tt', 'th', 'tg', 'azb', 'tr', 'uk', 'ur', 'vi', 'war', 'zh', 'yue'])
|
| 43 |
|
| 44 |
|
| 45 |
class Wikipedia(ComponentBase, ABC):
|
|
|
|
| 52 |
return Wikipedia.be_output(self._param.no)
|
| 53 |
|
| 54 |
wiki_res = []
|
| 55 |
+
wikipedia.set_lang(self._param.lang)
|
| 56 |
+
wiki_engine = wikipedia
|
| 57 |
+
for wiki_key in wiki_engine.search(ans, results=self._param.top_n):
|
| 58 |
try:
|
| 59 |
+
page = wiki_engine.page(title=wiki_key, auto_suggest=False)
|
| 60 |
wiki_res.append({"content": '<a href="' + page.url + '">' + page.title + '</a> ' + page.summary})
|
| 61 |
except Exception as e:
|
| 62 |
print(e)
|