.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.jisho Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 
 get_definitions (page)
 
 get_infobox (alt_forms, result_url, definitions)
 

Variables

dict about
 
list categories = ['dictionaries']
 
bool paging = False
 
str URL = 'https://jisho.org'
 
str BASE_URL = 'https://jisho.org/word/'
 
str SEARCH_URL = URL + '/api/v1/search/words?{query}'
 

Detailed Description

Jisho (the Japanese-English dictionary)

Function Documentation

◆ get_definitions()

searx.engines.jisho.get_definitions ( page)

Definition at line 75 of file jisho.py.

75def get_definitions(page):
76 # Process definitions
77 definitions = []
78 for defn_raw in page['senses']:
79 extra = []
80 # Extra data. Since they're not documented, this implementation is based solely by the author's assumptions.
81 if defn_raw.get('tags'):
82 if defn_raw.get('info'):
83 # "usually written as kana: <kana>"
84 extra.append(defn_raw['tags'][0] + ', ' + defn_raw['info'][0] + '. ')
85 else:
86 # abbreviation, archaism, etc.
87 extra.append(', '.join(defn_raw['tags']) + '. ')
88 elif defn_raw.get('info'):
89 # inconsistent
90 extra.append(', '.join(defn_raw['info']).capitalize() + '. ')
91 if defn_raw.get('restrictions'):
92 extra.append('Only applies to: ' + ', '.join(defn_raw['restrictions']) + '. ')
93 definitions.append(
94 (
95 ', '.join(defn_raw['parts_of_speech']),
96 '; '.join(defn_raw['english_definitions']),
97 ''.join(extra)[:-1],
98 )
99 )
100 return definitions
101
102

Referenced by searx.engines.jisho.response().

+ Here is the caller graph for this function:

◆ get_infobox()

searx.engines.jisho.get_infobox ( alt_forms,
result_url,
definitions )

Definition at line 103 of file jisho.py.

103def get_infobox(alt_forms, result_url, definitions):
104 infobox_content = []
105 # title & alt_forms
106 infobox_title = alt_forms[0]
107 if len(alt_forms) > 1:
108 infobox_content.append(f'<p><i>Other forms:</i> {", ".join(alt_forms[1:])}</p>')
109
110 # definitions
111 infobox_content.append(
112 '''
113 <small><a href="https://www.edrdg.org/wiki/index.php/JMdict-EDICT_Dictionary_Project">JMdict</a>
114 and <a href="https://www.edrdg.org/enamdict/enamdict_doc.html">JMnedict</a>
115 by <a href="https://www.edrdg.org/edrdg/licence.html">EDRDG</a>, CC BY-SA 3.0.</small>
116 <ul>
117 '''
118 )
119 for pos, engdef, extra in definitions:
120 if pos == 'Wikipedia definition':
121 infobox_content.append('</ul><small>Wikipedia, CC BY-SA 3.0.</small><ul>')
122 pos = f'<i>{pos}</i>: ' if pos else ''
123 extra = f' ({extra})' if extra else ''
124 infobox_content.append(f'<li>{pos}{engdef}{extra}</li>')
125 infobox_content.append('</ul>')
126
127 #
128 return {
129 'infobox': infobox_title,
130 'content': ''.join(infobox_content),
131 'urls': [
132 {
133 'title': 'Jisho.org',
134 'url': result_url,
135 }
136 ],
137 }

Referenced by searx.engines.jisho.response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.jisho.request ( query,
params )

Definition at line 27 of file jisho.py.

27def request(query, params):
28 query = urlencode({'keyword': query})
29 params['url'] = SEARCH_URL.format(query=query)
30 logger.debug(f"query_url --> {params['url']}")
31 return params
32
33

◆ response()

searx.engines.jisho.response ( resp)

Definition at line 34 of file jisho.py.

34def response(resp):
35 results = []
36 first_result = True
37
38 search_results = resp.json()
39
40 for page in search_results.get('data', []):
41 # Entries that are purely from Wikipedia are excluded.
42 parts_of_speech = page.get('senses') and page['senses'][0].get('parts_of_speech')
43 if parts_of_speech and parts_of_speech[0] == 'Wikipedia definition':
44 pass
45
46 # Process alternative forms
47 alt_forms = []
48 for title_raw in page['japanese']:
49 if 'word' not in title_raw:
50 alt_forms.append(title_raw['reading'])
51 else:
52 title = title_raw['word']
53 if 'reading' in title_raw:
54 title += ' (' + title_raw['reading'] + ')'
55 alt_forms.append(title)
56
57 result_url = urljoin(BASE_URL, page['slug'])
58 definitions = get_definitions(page)
59
60 # For results, we'll return the URL, all alternative forms (as title),
61 # and all definitions (as description) truncated to 300 characters.
62 content = " ".join(f"{engdef}." for _, engdef, _ in definitions)
63 results.append(
64 {'url': result_url, 'title': ", ".join(alt_forms), 'content': content[:300] + (content[300:] and '...')}
65 )
66
67 # Like Wordnik, we'll return the first result in an infobox too.
68 if first_result:
69 first_result = False
70 results.append(get_infobox(alt_forms, result_url, definitions))
71
72 return results
73
74

References searx.engines.jisho.get_definitions(), and searx.engines.jisho.get_infobox().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.jisho.about
Initial value:
1= {
2 "website": 'https://jisho.org',
3 "wikidata_id": 'Q24568389',
4 "official_api_documentation": "https://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api",
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8 "language": 'ja',
9}

Definition at line 9 of file jisho.py.

◆ BASE_URL

str searx.engines.jisho.BASE_URL = 'https://jisho.org/word/'

Definition at line 23 of file jisho.py.

◆ categories

list searx.engines.jisho.categories = ['dictionaries']

Definition at line 19 of file jisho.py.

◆ paging

bool searx.engines.jisho.paging = False

Definition at line 20 of file jisho.py.

◆ SEARCH_URL

str searx.engines.jisho.SEARCH_URL = URL + '/api/v1/search/words?{query}'

Definition at line 24 of file jisho.py.

◆ URL

str searx.engines.jisho.URL = 'https://jisho.org'

Definition at line 22 of file jisho.py.