File tree Expand file tree Collapse file tree 2 files changed +27
-25
lines changed
Expand file tree Collapse file tree 2 files changed +27
-25
lines changed Original file line number Diff line number Diff line change 3737 1 DOLLAR
3838 1 SMALL
3939 >>> index = UnicodeNameIndex()
40- >>> index.word_report(7)
40+ >>> index.word_report(10)
41+ 75821 CJK
42+ 75761 IDEOGRAPH
43+ 74656 UNIFIED
4144 13196 SYLLABLE
4245 11735 HANGUL
4346 7616 LETTER
4649 2122 SMALL
4750 1709 CAPITAL
4851
49- Note: character names starting with the string `` 'CJK UNIFIED IDEOGRAPH'``
50- are not indexed. Those names are not useful for searching, since the only
51- unique part of the name is the codepoint in hexadecimal .
52+ Note: characters with names starting with 'CJK UNIFIED IDEOGRAPH'
53+ are indexed with those three words only, excluding the hexadecimal
54+ codepoint at the end of the name .
5255
5356"""
5457
@@ -134,19 +137,6 @@ def word_rank(self, top=None):
134137 return res
135138
136139 def word_report (self , top = None ):
137- """
138- Generate report with most frequent words
139-
140- >>> index = UnicodeNameIndex()
141- >>> index.word_report(7)
142- 13196 SYLLABLE
143- 11735 HANGUL
144- 7616 LETTER
145- 2232 WITH
146- 2180 SIGN
147- 2122 SMALL
148- 1709 CAPITAL
149- """
150140 for postings , key in self .word_rank (top ):
151141 print ('{:5} {}' .format (postings , key ))
152142
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
13import asyncio
24from aiohttp import web
35
46from charfinder import UnicodeNameIndex
57
6- TEMPLATE = '''
8+ PAGE_TPL = '''
79<!DOCTYPE html>
810<html lang="en">
911 <head>
1012 <meta charset="utf-8">
11- <title>title </title>
13+ <title>Charserver </title>
1214 </head>
1315 <body>
14- <form action="/">
15- <input type="search" name="query" value="{query}">
16- <input type="submit" value="find">
17- </form>
16+ <p>
17+ <form action="/">
18+ <input type="search" name="query" value="{query}">
19+ <input type="submit" value="find">
20+ Examples: {links}
21+ </form>
22+ </p>
1823 <p>{message}</p>
1924 <hr>
2025 <pre>
2631
2732CONTENT_TYPE = 'text/html; charset=UTF-8'
2833
34+ EXAMPLE_WORDS = ('chess cat circled Malayalam digit Roman face Ethiopic'
35+ ' black mark symbol dot operator Braille hexagram' ).split ()
36+ LINK_TPL = '<a href="/?query={0}" title="find "{0}"">{0}</a>'
37+
2938index = None # a UnicodeNameIndex instance
3039
3140
@@ -41,9 +50,12 @@ def handle(request):
4150 else :
4251 lines = []
4352 res = ''
44- msg = 'Type words describing characters, e.g. chess .'
53+ msg = 'Type words describing characters.'
4554
46- text = TEMPLATE .format (query = query , result = res , message = msg )
55+ links = ', ' .join (LINK_TPL .format (word )
56+ for word in sorted (EXAMPLE_WORDS , key = str .upper ))
57+ text = PAGE_TPL .format (query = query , result = res ,
58+ message = msg , links = links )
4759 return web .Response (content_type = CONTENT_TYPE , text = text )
4860
4961
You can’t perform that action at this time.
0 commit comments