Compare commits
No commits in common. "main" and "gh-pages" have entirely different histories.
14 changed files with 69746 additions and 1722 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
/ana
|
||||
/ana.data
|
||||
/ana.js*
|
||||
/ana.so
|
||||
/ana.wasm*
|
||||
/dict.bin
|
||||
/run.o
|
||||
/words
|
||||
339
LICENSE
339
LICENSE
|
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
62
Makefile
62
Makefile
|
|
@ -1,62 +0,0 @@
|
|||
# Copyright © 2013 Jeff Epler <jepler@unpythonic.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
pyconfig = $(shell python3 -c \
|
||||
'from distutils import sysconfig; print(sysconfig.$(1))')
|
||||
|
||||
CXXFLAGS_PYTHON := -DANA_AS_PYMODULE \
|
||||
-I $(call pyconfig, get_python_inc(False)) \
|
||||
-I $(call pyconfig, get_python_inc(True)) \
|
||||
-fPIC
|
||||
|
||||
LFLAGS_PYTHON := \
|
||||
-shared \
|
||||
$(call pyconfig, get_config_var("LIBS"))
|
||||
|
||||
CXX := g++
|
||||
CXXFLAGS := -g -std=c++2b -Wall
|
||||
EXTRAFLAGS ?=
|
||||
|
||||
.PHONY: all
|
||||
all: ana python dict.bin
|
||||
|
||||
.PHONY: web
|
||||
web: ana.js
|
||||
|
||||
.PHONY: python
|
||||
python: ana.so
|
||||
|
||||
ana.js: $(wildcard *.cc) $(wildcard *.h) Makefile words
|
||||
em++ -flto -O3 -g --bind -std=c++2b -s TOTAL_MEMORY=33554432 --preload-file words -DANA_AS_JS run.cc -o ana.js
|
||||
|
||||
words:
|
||||
LANG=C.UTF-8 grep '^[a-z]*$$' /usr/share/dict/words > $@
|
||||
|
||||
dict.bin: words ana
|
||||
./ana -D $@ -d $<
|
||||
|
||||
ana: $(wildcard *.cc) | $(wildcard *.h) Makefile
|
||||
$(CXX) $(CXXFLAGS) $(EXTRAFLAGS) -flto -o $@ $^
|
||||
ana.so: $(wildcard *.cc) | $(wildcard *.h) Makefile
|
||||
$(CXX) $(CXXFLAGS) $(CXXFLAGS_PYTHON) -o $@ $^ $(LFLAGS_PYTHON)
|
||||
|
||||
publish: ana.js ana.html ana.wasm ana.data ana.wasm
|
||||
git branch -D gh-pages || true
|
||||
./import $(filter-out ana.html,$^) index.html=ana.html | git fast-import --date-format=now
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f ana ana.so dict.bin words ana.js ana.wasm
|
||||
49
README.md
49
README.md
|
|
@ -1,49 +0,0 @@
|
|||
# Build instructions:
|
||||
|
||||
make
|
||||
|
||||
# Use instructions:
|
||||
|
||||
./ana terms...
|
||||
man ./ana.1 ;# for help
|
||||
|
||||
# Binary dictionaries
|
||||
These start a bit faster than reading the system dictionary.
|
||||
|
||||
Build one with
|
||||
|
||||
./ana -D dict.bin -d /usr/share/dict/words
|
||||
|
||||
then use it with
|
||||
|
||||
./ana -D dict.bin terms...
|
||||
|
||||
# Python use
|
||||
```
|
||||
$ python3
|
||||
>>> import ana
|
||||
>>> d = ana.from_binary("dict.bin")
|
||||
>>> for row in d.run("hello world"):
|
||||
... print(row)
|
||||
```
|
||||
|
||||
# Web Browser Version (WASM/js)
|
||||
|
||||
1. Compile with emscripten (tested with the version in debian bookworm):
|
||||
|
||||
make ana.js
|
||||
|
||||
1. Test it to your satisfaction using a local html server:
|
||||
|
||||
python3 http.server &
|
||||
|
||||
1. Commit it:
|
||||
|
||||
make publish
|
||||
|
||||
1. Push it to github:
|
||||
|
||||
git push origin gh-pages
|
||||
|
||||
# Live web version
|
||||
https://www.unpythonic.net/anagram/
|
||||
127
ana.1
127
ana.1
|
|
@ -1,127 +0,0 @@
|
|||
.TH ANA "1" "2013-02-23" "" ""
|
||||
.SH NAME
|
||||
ana \- generate anagrams
|
||||
.SH DESCRIPTION
|
||||
.B ana
|
||||
is a program for generating anagrams of input words. It has several advanced
|
||||
features such as length constraints on each word of the generated output,
|
||||
a binary dictionary format for reduced startup time, and a server mode which
|
||||
makes it useful to invoke from long-lived programs.
|
||||
.SH INVOCATION
|
||||
.SS Anagramming
|
||||
.HP
|
||||
.B ana \fR[\fB-d \fItext-dictionary\fR|\fB-D \fIbinary-dictionary\fR]
|
||||
[\fB-l \fIlen1,...\fR] [\fB-m \fIminlen\fR]
|
||||
[\fB-M \fImaxlen\fR] [\fB-a\fR] [\fB-c\fR]
|
||||
[\fB-L \fImatchlimit\fR]
|
||||
\fIterms...\fR \fR[-- \fIrequired-terms...\fR]
|
||||
.SS Make a binary dictionary from a text dictionary
|
||||
.HP
|
||||
.B ana -d\fItext-dictionary\fB -D\fIbinary-dictionary
|
||||
.SS Anagram server
|
||||
.HP
|
||||
.B ana -s \fI[\fB-d\fItext-dictionary\fI|\fB-D\fIbinary-dictionary\fI]
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
-d \fItext-dictionary
|
||||
.TQ
|
||||
-D \fIbinary-dictionary
|
||||
Specify the dictionary to be used. If no dictionary is specified,
|
||||
/usr/share/dict/words is used. If both a text dictionary and a binary
|
||||
dictionary are specified, the binary dictionary is written from the text
|
||||
dictionary (dictionary generation mode)
|
||||
.TP
|
||||
-l \fIlen1,...
|
||||
Specify one or more length words that are required to appear in the output
|
||||
.TP
|
||||
-m \fIminlen
|
||||
.TQ
|
||||
-M \fImaxlen
|
||||
Specify the minimum and maximum length of words. If any \fB-l\fR specification
|
||||
exceeds these values, they will be reduced or increased accordingly. (this relation between -m/-M and -l may change in a future version)
|
||||
.TP
|
||||
-a
|
||||
Toggle "accept apostrophes" mode (default: off). If this mode is off, words
|
||||
from the dictionary with apostrophes will never be chosen. Otherwise, they
|
||||
may be chosen.
|
||||
.TP
|
||||
-c
|
||||
Toggle "just candidates" mode (default: off). If this mode is off, whole
|
||||
phrases are printed. If this mode is on, all words that can be spelled from
|
||||
the input terms minus the required terms (and which match the first length
|
||||
restriction, if specified) are printed.
|
||||
.TP
|
||||
-L \fImatchlimit
|
||||
Limit number of anagrams or candidates printed to \fBmatchlimit\fR.
|
||||
.TP
|
||||
terms...
|
||||
Alphabetic characters from these terms are added to the pool of letters to be
|
||||
anagrammed.
|
||||
.TP
|
||||
-- required-terms...
|
||||
Each word from required-terms is included in every result. Words in this list
|
||||
need not be in the dictionary.
|
||||
|
||||
.SH SERVER MODE
|
||||
In server mode, \fBana\fR produces and consumes line-oriented data.
|
||||
The input consists of a search specification and the output consists of
|
||||
zero or more non-blank lines, which are either anagram results or
|
||||
commentary prefixed with "#", followed by a single blank line. In a search
|
||||
specification, words are interpreted as follows:
|
||||
.TP
|
||||
<\fInumber\fR
|
||||
The maximum word length is set to \fInumber\fR
|
||||
.TP
|
||||
>\fInumber\fR
|
||||
The minimum word length is set to \fInumber\fR
|
||||
.TP
|
||||
\fInumber\fR
|
||||
A word of exactly \fInumber\fR letters must be chosen
|
||||
.TP
|
||||
\(aq
|
||||
Toggle the flag for acceptance of words with apostrophes (default: not accepted)
|
||||
.TP
|
||||
-\fInumber\fR
|
||||
Stop producing results after \fInumber\fR
|
||||
.TP
|
||||
=\fIword\fR
|
||||
The exact word \fIword\fR must be chosen (this works for words not in the
|
||||
dictionary)
|
||||
.TP
|
||||
\fIword\fR
|
||||
The letters of \fIword\fR are added to the letters available to anagram
|
||||
|
||||
.SH How required lengths and required terms interact
|
||||
First, each required term is pulled out of the available letters. Then for
|
||||
each required length, a word of exactly that length is sought. After the
|
||||
list of required lengths is exhausted, words of any length are sought.
|
||||
|
||||
Example: Given the term \fIsatisfiable\fR and no further constraints, \fIsafest
|
||||
alibi\fR is one of the results produced. It would also be produced if the
|
||||
length constraint \fI6\fR or \fI6,5\fR are specified, or if the required term
|
||||
\fIsafest\fR is specified. If the required term \fIsafest\fR is specified,
|
||||
then the length specification \fI5\fR will produce \fIsafest alibi\fR, because
|
||||
after the word \fIsafest\fR is produced, the next word uses the first specified
|
||||
length.
|
||||
|
||||
.SH BUGS
|
||||
.SS Non-ASCII environments not supported
|
||||
In dictionaries, words with non-ASCII characters are ignored. Characters
|
||||
which are not isalpha() in the "C" locale are ignored for purposes of
|
||||
anagramming, and they are always downcased according to tolower() in the "C"
|
||||
locale. The design of the code is such that these limitations are not easily
|
||||
lifted.
|
||||
|
||||
.SH AUTHOR
|
||||
.MT jepler@unpythonic.net
|
||||
Jeff Epler
|
||||
.ME
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright \[co] 2013
|
||||
.MT jepler@unpythonic.net
|
||||
Jeff Epler
|
||||
.ME
|
||||
and licensed under the terms of the GNU General Public License, version 2
|
||||
or later.
|
||||
BIN
ana.wasm
Normal file
BIN
ana.wasm
Normal file
Binary file not shown.
98
anagram.js
98
anagram.js
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2013 Jeff Epler <jepler@unpythonic.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
var request = null, lastquery = '';
|
||||
|
||||
function updatejax() {
|
||||
if(!request) return;
|
||||
if(request.readyState > 1) {
|
||||
var response = '';
|
||||
try {
|
||||
if(request.response)
|
||||
response = request.response;
|
||||
else if(request.responseText)
|
||||
response = request.responseText;
|
||||
} catch(unused) {}
|
||||
if(response != '') {
|
||||
response = response.replace(/&/g, "&");
|
||||
response = response.replace(/</g, "<");
|
||||
response = response.replace(/>/g, ">");
|
||||
var el = document.getElementById('results');
|
||||
if(el.outerHTML) {
|
||||
el.outerHTML = '<pre id="results">' + response + '</pre>';
|
||||
} else {
|
||||
el.innerHTML = response;
|
||||
}
|
||||
}
|
||||
if(request.readyState == 4) {
|
||||
clearjax();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearjax() {
|
||||
request = null;
|
||||
mayjax();
|
||||
}
|
||||
|
||||
function makejax() {
|
||||
try { return new XMLHttpRequest(); } catch(e) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
function queuejax (suffix) {
|
||||
var query = $('#query').val();
|
||||
lastquery = query;
|
||||
query = query.replace(/[=<>-]\s*$/, '')
|
||||
var loc = (
|
||||
document.location.toString().replace(/[?#].*$/, "")
|
||||
+ '?' + $.param({'p': 1, 'q': query + suffix}));
|
||||
request = makejax();
|
||||
request.open("GET", loc, true);
|
||||
try {
|
||||
request.overrideMimeType('text/plain')
|
||||
} catch (unused) {}
|
||||
request.onreadystatechange = updatejax;
|
||||
request.onprogress = updatejax;
|
||||
request.onloadend = updatejax;
|
||||
request.onload = updatejax;
|
||||
request.onerror = updatejax;
|
||||
request.send(null);
|
||||
if(window && window.history && window.history.replaceState)
|
||||
window.history.replaceState({}, '',
|
||||
document.location.toString().replace(/[?#].*$/, "")
|
||||
+ '?' + $.param({'q': query}));
|
||||
}
|
||||
|
||||
function fulljax (e) {
|
||||
if(request) request.abort();
|
||||
queuejax('');
|
||||
if(e) e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
function mayjax() {
|
||||
if(request) return;
|
||||
var query = $('#query').val();
|
||||
if(query == '' || query == lastquery) return;
|
||||
queuejax(' -50');
|
||||
}
|
||||
|
||||
lastquery = $('#query').val();
|
||||
$('#query').keyup(mayjax).change(mayjax);
|
||||
$('#f').submit(fulljax);
|
||||
25
dictfilt.py
25
dictfilt.py
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Remove uppercase words from dictionary when a lowercase form is
|
||||
# present
|
||||
#
|
||||
# Copyright © 2013 Jeff Epler <jepler@unpythonic.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
import sys
|
||||
s = set(line.strip() for line in sys.stdin)
|
||||
s = set(i for i in s if i == i.lower() or i.lower() not in s)
|
||||
for i in sorted(s):
|
||||
print i
|
||||
37
import
37
import
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--branch", metavar='branch', default="gh-pages",
|
||||
help="branch to use (any old contents are destroyed)")
|
||||
parser.add_argument('files', metavar='files', nargs='+',
|
||||
help='files to be committed')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
version = subprocess.getoutput("git describe --always --dirty")
|
||||
|
||||
fd = os.fdopen(sys.stdout.fileno(), 'wb')
|
||||
|
||||
fd.write(b"commit refs/heads/" + args.branch.encode('utf-8') + b"\n")
|
||||
fd.write(b"committer Doc Man <noreply@example.com> now" + b"\n")
|
||||
fd.write(b"data <<EOF" + b"\n")
|
||||
fd.write(b"Docs built at " + version.encode('utf-8') + b"\n")
|
||||
fd.write(b"EOF" + b"\n")
|
||||
|
||||
for fn in args.files:
|
||||
if '=' in fn:
|
||||
dest, src = fn.split('=', 1)
|
||||
else:
|
||||
dest = src = fn
|
||||
with open(src, 'rb') as f: contents = f.read()
|
||||
fd.write(b"M 644 inline " + os.path.basename(dest).encode('utf-8') + b"\n")
|
||||
fd.write(b"data " + str(len(contents)).encode("utf-8") + b"\n")
|
||||
fd.write(contents)
|
||||
fd.write(b"done\n")
|
||||
|
||||
856
run.cc
856
run.cc
|
|
@ -1,856 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2013 Jeff Epler <jepler@unpythonic.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef ANA_AS_PYMODULE
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <endian.h>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <inttypes.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct worddata
|
||||
{
|
||||
worddata()
|
||||
{
|
||||
m = 0;
|
||||
l = 0;
|
||||
memset(&c, 0, sizeof(c));
|
||||
w[0] = 0;
|
||||
}
|
||||
|
||||
operator bool() const { return m; }
|
||||
|
||||
uint32_t m;
|
||||
unsigned char c[26];
|
||||
uint16_t l;
|
||||
char w[1]; // note: not declared as flexible member for Reasons
|
||||
|
||||
private:
|
||||
/* Note: Constructor assumes that storage for word has been
|
||||
allocated! Doesn't work with stacked or regular new'd storage.
|
||||
*/
|
||||
worddata(const char *word)
|
||||
{
|
||||
m = 0;
|
||||
l = 0;
|
||||
strcpy(w, word);
|
||||
memset(&c, 0, sizeof(c));
|
||||
|
||||
const char *s = word;
|
||||
for(;*s;s++) {
|
||||
if(!isalpha(*s)) continue;
|
||||
int o = tolower(*s)-'a';
|
||||
l++;
|
||||
c[o]++;
|
||||
m |= (1<<o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static worddata *make_word(const char *word) {
|
||||
size_t sz = sizeof(worddata) + strlen(word);
|
||||
char *storage = new char[sz];
|
||||
worddata *r = reinterpret_cast<worddata *>(storage);
|
||||
new(r) worddata(word);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void delete_word(worddata *word) {
|
||||
delete[] reinterpret_cast<char*>(word);
|
||||
}
|
||||
|
||||
friend struct wordholder;
|
||||
friend struct dict;
|
||||
};
|
||||
|
||||
struct wordholder
|
||||
{
|
||||
wordholder() : w(worddata::make_word("")) {}
|
||||
wordholder(const wordholder &h) : w(worddata::make_word(h.w->w)) {}
|
||||
wordholder(const char *s) : w(worddata::make_word(s)) {}
|
||||
wordholder(const string &s)
|
||||
: w(worddata::make_word(s.c_str())) {}
|
||||
|
||||
~wordholder() {
|
||||
worddata::delete_word(w);
|
||||
}
|
||||
const worddata &value() const { return *w; }
|
||||
worddata &value() { return *w; }
|
||||
private:
|
||||
worddata *w;
|
||||
wordholder &operator=(const wordholder &o) = delete;
|
||||
};
|
||||
|
||||
inline size_t lcnt(const struct worddata &w)
|
||||
{
|
||||
return w.l;
|
||||
}
|
||||
|
||||
inline bool candidate(const worddata &a, const worddata &b)
|
||||
{
|
||||
if((a.m & b.m) != b.m) return false;
|
||||
for(int i=0; i<26; i++)
|
||||
if(a.c[i] < b.c[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline worddata operator-(const worddata &a, const worddata &b)
|
||||
{
|
||||
worddata r;
|
||||
|
||||
for(int i=0; i<26; i++)
|
||||
{
|
||||
unsigned char tmp;
|
||||
r.c[i] = tmp = a.c[i] - b.c[i];
|
||||
if(tmp) {
|
||||
r.m |= (1<<i);
|
||||
}
|
||||
}
|
||||
r.l = a.l - b.l;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#if !ANA_JS
|
||||
template<class T>
|
||||
void bwrite(ostream &o, const T &t) {
|
||||
o.write(reinterpret_cast<const char *>(&t), sizeof(t));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void bwrite(ostream &o, const T *t, size_t n) {
|
||||
o.write(reinterpret_cast<const char *>(t), sizeof(T)*n);
|
||||
}
|
||||
|
||||
void bwrite_be32(ostream &o, const uint32_t t) {
|
||||
uint32_t t_be32 = htobe32(t);
|
||||
bwrite(o, t_be32);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void bread(istream &o, T &t) {
|
||||
o.read(reinterpret_cast<char *>(&t), sizeof(t));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void bread(istream &o, T *t, size_t n) {
|
||||
o.read(reinterpret_cast<char *>(t), sizeof(T)*n);
|
||||
}
|
||||
|
||||
void bread_be32(istream &o, uint32_t &t) {
|
||||
uint32_t t_be32;
|
||||
bread(o, t_be32);
|
||||
t = htobe32(t_be32);
|
||||
}
|
||||
|
||||
inline bool ascii(const string &s)
|
||||
{
|
||||
for(string::size_type i=0; i != s.size(); i++)
|
||||
if(!isascii(s[i])) return false;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct dict {
|
||||
struct byinvwordlen {
|
||||
byinvwordlen(const dict &d) : d(d) {}
|
||||
bool operator()(size_t a, size_t b) const {
|
||||
return lcnt(*reinterpret_cast<const worddata*>(&d.wdata[a]))
|
||||
> lcnt(*reinterpret_cast<const worddata*>(&d.wdata[b]));
|
||||
}
|
||||
const dict &d;
|
||||
};
|
||||
|
||||
vector<uint32_t> woff;
|
||||
vector<char> wdata;
|
||||
|
||||
const worddata *getword(size_t i) const {
|
||||
return reinterpret_cast<const worddata*>(&wdata[woff.at(i)]);
|
||||
}
|
||||
|
||||
worddata *getword(size_t i) {
|
||||
return reinterpret_cast<worddata*>(&wdata[woff.at(i)]);
|
||||
}
|
||||
|
||||
// 16-align words
|
||||
static size_t pad(size_t t) { return (t + 15) & ~size_t(15); }
|
||||
|
||||
size_t nwords() const { return woff.size(); }
|
||||
|
||||
void addword(const char *word) {
|
||||
size_t i = woff.size();
|
||||
size_t sz = pad(sizeof(worddata) + strlen(word));
|
||||
size_t off = wdata.size();
|
||||
wdata.resize(off+sz);
|
||||
woff.push_back(off);
|
||||
new(getword(i)) worddata(word);
|
||||
}
|
||||
|
||||
void readdict(const char *dictpath) {
|
||||
ifstream i(dictpath);
|
||||
string w;
|
||||
while((i >> w))
|
||||
{
|
||||
if(!ascii(w)) continue;
|
||||
addword(w.c_str());
|
||||
}
|
||||
sort_me();
|
||||
}
|
||||
|
||||
void sort_me() {
|
||||
stable_sort(woff.begin(), woff.end(), byinvwordlen(*this));
|
||||
}
|
||||
|
||||
#if !ANA_JS
|
||||
static const uint32_t signature = 0x414e4144;
|
||||
static const uint32_t signature2 = sizeof(uint64_t);
|
||||
static const uint32_t signature_rev = 0x44414e41;
|
||||
void serialize(const char *ofn) const {
|
||||
ofstream o(ofn, ios::binary);
|
||||
uint32_t s = signature;
|
||||
bwrite_be32(o, s);
|
||||
s = signature2;
|
||||
bwrite_be32(o, s);
|
||||
|
||||
if(woff.size() > INT32_MAX) {
|
||||
throw runtime_error("dictionary too big (woff)");
|
||||
}
|
||||
bwrite_be32(o, woff.size());
|
||||
bwrite(o, &woff[0], woff.size());
|
||||
if(woff.size() > INT32_MAX) {
|
||||
throw runtime_error("dictionary too big (wdata)");
|
||||
}
|
||||
bwrite_be32(o, wdata.size());
|
||||
bwrite(o, &wdata[0], wdata.size());
|
||||
}
|
||||
|
||||
void deserialize(const char *ifn) {
|
||||
ifstream i(ifn, ios::binary);
|
||||
uint32_t sig;
|
||||
bread_be32(i, sig);
|
||||
if(sig == signature_rev)
|
||||
throw runtime_error("endianness error");
|
||||
else if(sig != signature)
|
||||
throw runtime_error("not an anagram dictionary archive");
|
||||
|
||||
bread_be32(i, sig);
|
||||
if(sig != signature2)
|
||||
throw runtime_error("count-size error");
|
||||
|
||||
uint32_t sz;
|
||||
bread_be32(i, sz);
|
||||
woff.resize(sz);
|
||||
bread(i, &*(woff.begin()), sz);
|
||||
|
||||
bread_be32(i, sz);
|
||||
wdata.resize(sz);
|
||||
bread(i, &*(wdata.begin()), sz);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
void usage(const char *progname)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-d text-dictionary|-D bin-dictionary]\n\t"
|
||||
"[-l len1,...] [-m minlen] [-M maxlen]\n\t"
|
||||
"[-a] [-c] [-s] terms... -- required...\n",
|
||||
progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void print_stack(ostream &o, vector<worddata *> &s)
|
||||
{
|
||||
for(vector<worddata *>::const_iterator it = s.begin(); it != s.end(); it++)
|
||||
{
|
||||
o << (*it)->w;
|
||||
if(it + 1 == s.end()) o << "\n";
|
||||
else o << " ";
|
||||
}
|
||||
}
|
||||
|
||||
struct filterer
|
||||
{
|
||||
filterer(const worddata &a) : a(a) { }
|
||||
bool operator()(const worddata *b) const { return candidate(a, *b); }
|
||||
const worddata &a;
|
||||
};
|
||||
|
||||
vector<size_t> parse_lengths(const char *l)
|
||||
{
|
||||
istringstream s(l);
|
||||
vector<size_t> r;
|
||||
size_t i;
|
||||
while((s >> i)) {
|
||||
r.push_back(i);
|
||||
if(s.peek() == ',') s.get();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
double cputime()
|
||||
{
|
||||
#if defined(ANA_AS_JS)
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec + tv.tv_usec * 1e-6;
|
||||
#else
|
||||
struct rusage u;
|
||||
getrusage(RUSAGE_SELF, &u);
|
||||
return (u.ru_utime.tv_sec + u.ru_utime.tv_usec * 1e-6)
|
||||
+ (u.ru_stime.tv_sec + u.ru_stime.tv_usec * 1e-6);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
struct ana_cfg {
|
||||
ana_cfg()
|
||||
: apos(0), just_candidates(0), minlen(3), maxlen(10),
|
||||
total_matches(0), max_matches(1000), total_searches(0),
|
||||
max_searches(1000000) {}
|
||||
|
||||
ana_cfg(bool apos, bool just_candidates, size_t minlen, size_t maxlen,
|
||||
size_t max_matches,
|
||||
size_t max_searches, const vector<size_t>& lengths,
|
||||
const string &ws, const string &rs)
|
||||
: apos(apos), just_candidates(just_candidates), minlen(minlen),
|
||||
maxlen(maxlen),
|
||||
total_matches(0), max_matches(max_matches), total_searches(0),
|
||||
max_searches(max_searches), lengths(lengths), rs(rs), ww() {
|
||||
auto wsv = wordholder(ws).value();
|
||||
auto rsv = wordholder(rs).value();
|
||||
if (candidate(wsv, rsv)) {
|
||||
ww = wsv - rsv;
|
||||
} else {
|
||||
this->max_searches = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool apos, just_candidates;
|
||||
size_t minlen, maxlen;
|
||||
size_t total_matches, max_matches, total_searches, max_searches;
|
||||
vector<size_t> lengths;
|
||||
std::string rs;
|
||||
worddata ww;
|
||||
};
|
||||
|
||||
struct ana_frame {
|
||||
worddata l;
|
||||
vector<const worddata*> c;
|
||||
vector<const worddata*>::iterator st, en;
|
||||
vector<size_t>::iterator lst, len;
|
||||
};
|
||||
|
||||
struct ana_st {
|
||||
ana_cfg cfg;
|
||||
double t0;
|
||||
vector<ana_frame> fr;
|
||||
vector<const char *> words;
|
||||
};
|
||||
|
||||
void setup(ana_st &st, const ana_cfg &cfg, const dict &d)
|
||||
{
|
||||
st.cfg = cfg;
|
||||
st.t0 = cputime();
|
||||
st.fr.clear();
|
||||
st.fr.reserve(lcnt(cfg.ww));
|
||||
st.fr.push_back(ana_frame());
|
||||
ana_frame &f = st.fr.back();
|
||||
f.l = st.cfg.ww;
|
||||
f.lst = st.cfg.lengths.begin();
|
||||
f.len = st.cfg.lengths.end();
|
||||
filterer fi(f.l);
|
||||
for(size_t i=0; i != d.nwords(); i++)
|
||||
{
|
||||
const worddata *it = d.getword(i);
|
||||
if(lcnt(*it) < cfg.minlen || lcnt(*it) > cfg.maxlen) continue;
|
||||
if(!cfg.apos && strchr(it->w, '\'')) continue;
|
||||
if(!fi(it)) continue;
|
||||
f.c.push_back(it);
|
||||
}
|
||||
f.st = f.c.begin();
|
||||
f.en = f.c.end();
|
||||
st.words.clear();
|
||||
if(!st.cfg.rs.empty()) st.words.push_back(st.cfg.rs.c_str());
|
||||
}
|
||||
|
||||
bool words_to_string(const vector<const char*> words, std::string &resultline) {
|
||||
resultline.clear();
|
||||
|
||||
for(vector<const char *>::const_iterator it = words.begin(); it != words.end(); it++)
|
||||
{
|
||||
if(!resultline.empty()) resultline += ' ';
|
||||
resultline += *it;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool step(ana_st &st, string &resultline) {
|
||||
resultline = string();
|
||||
|
||||
if(st.cfg.total_matches == st.cfg.max_matches) {
|
||||
ostringstream o;
|
||||
o << "# Reached maximum of " << st.cfg.total_matches << " matches in " << setprecision(2) << (cputime() - st.t0) << "s";
|
||||
resultline = o.str();
|
||||
return false;
|
||||
}
|
||||
|
||||
while(!st.fr.empty()) {
|
||||
if(st.cfg.total_searches == st.cfg.max_searches) {
|
||||
ostringstream o;
|
||||
o << "# Reached maximum of " << st.cfg.total_searches << " searches in " << setprecision(2) << (cputime() - st.t0) << "s";
|
||||
resultline = o.str();
|
||||
return false;
|
||||
}
|
||||
|
||||
st.cfg.total_searches ++;
|
||||
|
||||
ana_frame &f = st.fr.back();
|
||||
|
||||
if(!f.l) {
|
||||
st.cfg.total_matches ++;
|
||||
words_to_string(st.words, resultline);
|
||||
st.words.pop_back();
|
||||
st.fr.pop_back();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(f.lst != f.len) {
|
||||
size_t reqlen = *f.lst;
|
||||
while(f.st != f.en && lcnt(**f.st) != reqlen) f.st ++;
|
||||
}
|
||||
|
||||
if(f.st == f.en)
|
||||
{
|
||||
st.fr.pop_back();
|
||||
st.words.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(st.cfg.just_candidates) {
|
||||
st.cfg.total_matches ++;
|
||||
resultline = std::string((*f.st)->w);
|
||||
f.st++;
|
||||
return true;
|
||||
}
|
||||
|
||||
// guaranteed not to move, because of earlier reserve()!
|
||||
assert(st.fr.size() + 1 < st.fr.capacity());
|
||||
st.fr.push_back(ana_frame());
|
||||
|
||||
st.words.push_back((*f.st)->w);
|
||||
|
||||
ana_frame &nf = st.fr.back();
|
||||
nf.l = f.l - **f.st;
|
||||
nf.c.clear();
|
||||
if(f.lst != f.len) {
|
||||
copy_if(f.c.begin(), f.en, back_inserter(nf.c), filterer(nf.l));
|
||||
nf.lst = f.lst + 1;
|
||||
nf.len = f.len;
|
||||
} else {
|
||||
copy_if(f.st, f.en, back_inserter(nf.c), filterer(nf.l));
|
||||
nf.lst = nf.len = f.len;
|
||||
}
|
||||
nf.st = nf.c.begin();
|
||||
nf.en = nf.c.end();
|
||||
|
||||
f.st++;
|
||||
}
|
||||
|
||||
ostringstream o;
|
||||
o << "# " << st.cfg.total_matches << " matches ("
|
||||
<< st.cfg.total_searches << " searches) in "
|
||||
<< setprecision(2) << (cputime() - st.t0) << "s";
|
||||
resultline = o.str();
|
||||
return false;
|
||||
}
|
||||
|
||||
int run(dict &d, ostream &o, ana_cfg &cfg) {
|
||||
ana_st st;
|
||||
setup(st, cfg, d);
|
||||
while(1) {
|
||||
std::string line;
|
||||
bool res = step(st, line);
|
||||
o << line << endl;
|
||||
if(!res) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t maxsearch = 10000000;
|
||||
int run(dict &d, ostream &o, bool apos, bool just_candidates, size_t minlen, size_t maxlen, size_t maxcount, vector<size_t> &lengths, string &aw, string &rw) {
|
||||
ana_cfg cfg(apos, just_candidates, minlen, maxlen, maxcount, maxsearch,
|
||||
lengths, aw, rw);
|
||||
return run(d, o, cfg);
|
||||
}
|
||||
|
||||
void parse(const std::string &s, ana_cfg &st, bool def_apos, bool def_just_candidates, size_t def_minlen, size_t def_maxlen, size_t def_maxcount) {
|
||||
string an;
|
||||
string reqd;
|
||||
|
||||
bool apos = def_apos;
|
||||
bool just_candidates = def_just_candidates;
|
||||
size_t minlen = def_minlen;
|
||||
size_t maxlen = def_maxlen;
|
||||
size_t maxcount = def_maxcount;
|
||||
vector<size_t> lengths;
|
||||
string aw, rw;
|
||||
|
||||
int c;
|
||||
|
||||
istringstream i(s);
|
||||
|
||||
while((c = i.peek()) != EOF)
|
||||
{
|
||||
switch(c) {
|
||||
case '<':
|
||||
(void) i.get();
|
||||
i >> maxlen; break;
|
||||
case '>':
|
||||
(void) i.get();
|
||||
i >> minlen; break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
size_t len;
|
||||
i >> len;
|
||||
lengths.push_back(len);
|
||||
minlen = std::min(minlen, len);
|
||||
maxlen = std::max(maxlen, len);
|
||||
break;
|
||||
}
|
||||
case '+': case '=':
|
||||
{
|
||||
string s;
|
||||
(void) i.get();
|
||||
i >> s;
|
||||
if(!rw.empty()) rw = rw + " " + s;
|
||||
else rw = s;
|
||||
break;
|
||||
}
|
||||
case '-':
|
||||
{
|
||||
(void) i.get();
|
||||
i >> maxcount;
|
||||
maxcount = min(def_maxcount, maxcount);
|
||||
break;
|
||||
}
|
||||
case '\'':
|
||||
(void) i.get();
|
||||
apos = !apos;
|
||||
break;
|
||||
case '?':
|
||||
(void) i.get();
|
||||
just_candidates = !just_candidates;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if(isspace(c)) {
|
||||
(void) i.get();
|
||||
break;
|
||||
}
|
||||
string s;
|
||||
i >> s;
|
||||
if(!aw.empty()) aw = aw + " " + s;
|
||||
else aw = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
st.~ana_cfg();
|
||||
new(&st) ana_cfg(apos, just_candidates, minlen, maxlen, maxcount, maxsearch,
|
||||
lengths, aw, rw);
|
||||
}
|
||||
|
||||
void serve(istream &i, ostream &o, dict &d, bool def_apos, bool def_just_candidates, size_t def_minlen, size_t def_maxlen, size_t def_maxcount) {
|
||||
string s;
|
||||
while((getline(i, s))) {
|
||||
ana_cfg cfg;
|
||||
parse(s, cfg, def_apos, def_just_candidates, def_minlen, def_maxlen, def_maxcount);
|
||||
run(d, o, cfg);
|
||||
o.put('\n'); o.flush();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ANA_AS_PYMODULE)
|
||||
struct dict_object {
|
||||
PyObject_HEAD
|
||||
dict d;
|
||||
};
|
||||
|
||||
static PyTypeObject dict_type = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "ana.anadict",
|
||||
.tp_basicsize = sizeof(dict_object),
|
||||
};
|
||||
|
||||
struct search_object {
|
||||
PyObject_HEAD;
|
||||
dict_object *d;
|
||||
ana_st *st;
|
||||
};
|
||||
|
||||
static PyTypeObject search_type = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "ana.results",
|
||||
.tp_basicsize = sizeof(search_object),
|
||||
};
|
||||
|
||||
search_object *search_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||
{
|
||||
return reinterpret_cast<search_object*>(type->tp_alloc(type, 0));
|
||||
}
|
||||
|
||||
PyObject *py_run(PyObject *self, PyObject *args, PyObject *keywds) {
|
||||
dict_object *d = (dict_object*)self;
|
||||
int apos = false, just_candidates = false;
|
||||
Py_ssize_t minlen = 3;
|
||||
Py_ssize_t maxlen = 11;
|
||||
Py_ssize_t maxcount = 1000;
|
||||
|
||||
char *terms;
|
||||
Py_ssize_t terms_sz;
|
||||
static const char * kwlist[] = {
|
||||
"terms", "apos", "just_candidates", "minlen", "maxlen", "maxcount",
|
||||
NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "s#|iinnn:ana.dict.run",
|
||||
const_cast<char**>(kwlist),
|
||||
&terms, &terms_sz, &apos, &just_candidates,
|
||||
&minlen, &maxlen, &maxcount))
|
||||
return NULL;
|
||||
|
||||
string query(terms, terms+terms_sz);
|
||||
|
||||
search_object *o = search_new(&search_type, 0, 0);
|
||||
o->d = d;
|
||||
Py_INCREF(d);
|
||||
|
||||
ana_cfg cfg;
|
||||
o->st = new ana_st;
|
||||
parse(query, cfg, apos, just_candidates, minlen, maxlen, maxcount);
|
||||
setup(*o->st, cfg, d->d);
|
||||
|
||||
return reinterpret_cast<PyObject*>(o);
|
||||
}
|
||||
|
||||
static PyMethodDef dict_methods[] = {
|
||||
{"run", reinterpret_cast<PyCFunction>(py_run), METH_VARARGS|METH_KEYWORDS,
|
||||
"Run one anagram"},
|
||||
{},
|
||||
};
|
||||
static PyObject *
|
||||
dict_new(PyTypeObject *type, PyObject *args, PyObject *kw) {
|
||||
dict_object *self = reinterpret_cast<dict_object*>(type->tp_alloc(type, 0));
|
||||
new(&self->d) dict();
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static void
|
||||
dict_dealloc(dict_object *self) {
|
||||
self->d.~dict();
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
py_fromascii(PyObject *self, PyObject *args) {
|
||||
PyObject *d = dict_new(&dict_type, NULL, NULL);
|
||||
dict_object *r = reinterpret_cast<dict_object*>(d);
|
||||
char *path;
|
||||
if(!PyArg_ParseTuple(args, "s", &path)) return NULL;
|
||||
r->d.readdict(path);
|
||||
return d;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
py_frombin(PyObject *self, PyObject *args) {
|
||||
PyObject *d = dict_new(&dict_type, NULL, NULL);
|
||||
dict_object *r = reinterpret_cast<dict_object*>(d);
|
||||
char *path;
|
||||
if(!PyArg_ParseTuple(args, "s", &path)) return NULL;
|
||||
r->d.deserialize(path);
|
||||
return d;
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
{"from_ascii", py_fromascii, METH_VARARGS, "Parse ASCII dictionary"},
|
||||
{"from_binary", py_frombin, METH_VARARGS, "Parse binary dictionary"},
|
||||
{},
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
search_iter(PyObject *self) {
|
||||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
// Note: it's up to the user to ensure no more than one thread is calling
|
||||
// .next() on a specific search_object at the same time
|
||||
static PyObject *
|
||||
search_iternext(search_object *self) {
|
||||
std::string result;
|
||||
if(!self->st) return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
bool res = step(*self->st, result);
|
||||
if(!res) { delete self->st; self->st = NULL; }
|
||||
Py_END_ALLOW_THREADS
|
||||
return PyUnicode_FromStringAndSize(result.data(), result.size());
|
||||
}
|
||||
|
||||
static void
|
||||
search_dealloc(search_object *self) {
|
||||
Py_XDECREF(self->d);
|
||||
delete self->st;
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static struct PyModuleDef moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"ana",
|
||||
"Quickly compute anagrams of strings",
|
||||
-1,
|
||||
methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit_ana(void) {
|
||||
PyObject *m;
|
||||
m = PyModule_Create(&moduledef);
|
||||
|
||||
dict_type.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||
dict_type.tp_new = dict_new;
|
||||
dict_type.tp_dealloc = reinterpret_cast<destructor>(dict_dealloc);
|
||||
dict_type.tp_methods = dict_methods;
|
||||
if(PyType_Ready(&dict_type) < 0) return NULL;
|
||||
|
||||
search_type.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||
search_type.tp_new = reinterpret_cast<newfunc>(search_new);
|
||||
search_type.tp_dealloc = reinterpret_cast<destructor>(search_dealloc);
|
||||
search_type.tp_iter = reinterpret_cast<getiterfunc>(search_iter);
|
||||
search_type.tp_iternext =
|
||||
reinterpret_cast<iternextfunc>(search_iternext);
|
||||
if(PyType_Ready(&search_type) < 0) return NULL;
|
||||
|
||||
PyModule_AddObject(m, "anadict", (PyObject *)&dict_type);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
#elif defined(ANA_AS_JS)
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
dict d;
|
||||
|
||||
std::string js_run(std::string s) {
|
||||
std::string result;
|
||||
ana_cfg cfg;
|
||||
ana_st st;
|
||||
parse(s, cfg, false, false, 3, 11, 10000);
|
||||
if (!d.nwords()) {
|
||||
std::cerr << "# reading words\n";
|
||||
d.readdict("words");
|
||||
}
|
||||
setup(st, cfg, d);
|
||||
while(1) {
|
||||
std::string line;
|
||||
bool res = step(st, line);
|
||||
result += line; result += "\n";
|
||||
if(!res) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(ana) {
|
||||
emscripten::function("ana", &js_run);
|
||||
}
|
||||
|
||||
#else
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *dictpath=0, *defdict="/usr/share/dict/words", *bindict=0;
|
||||
int opt;
|
||||
size_t minlen=3, maxlen=11, maxcount=1000;
|
||||
bool apos=false, just_candidates=false, server=false;
|
||||
vector<size_t> lengths;
|
||||
string aw;
|
||||
|
||||
while((opt = getopt(argc, argv, "-acD:d:M:m:l:s")) != -1)
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
case 'a': apos = !apos; break;
|
||||
case 'c': just_candidates = !just_candidates; break;
|
||||
case 'L': maxcount = atoi(optarg); break;
|
||||
case 'D': bindict = optarg; break;
|
||||
case 'd': dictpath = optarg; break;
|
||||
case 'M': maxlen = atoi(optarg); break;
|
||||
case 'm': minlen = atoi(optarg); break;
|
||||
case 'l': lengths = parse_lengths(optarg); break;
|
||||
case 's': server = !server; break;
|
||||
case 1: aw += optarg; break;
|
||||
default: usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
dict d;
|
||||
if(bindict && dictpath) {
|
||||
d.readdict(dictpath);
|
||||
d.serialize(bindict);
|
||||
cout << "# Read and serialized " << d.nwords() << " candidate words in " << setprecision(2) << cputime() << "s\n";
|
||||
return 0;
|
||||
} else if(bindict) {
|
||||
d.deserialize(bindict);
|
||||
cout << "# Deserialized " << d.nwords() << " candidate words in " << setprecision(2) << cputime() << "s\n";
|
||||
} else {
|
||||
d.readdict(dictpath ? dictpath : defdict);
|
||||
cout << "# Read " << d.nwords() << " candidate words in " << setprecision(2) << cputime() << "s\n";
|
||||
}
|
||||
|
||||
if(server) {
|
||||
serve(cin, cout, d, apos, just_candidates, minlen, maxlen, maxcount);
|
||||
return 0;
|
||||
} else {
|
||||
string rw;
|
||||
for(int i=optind; i<argc; i++)
|
||||
{
|
||||
if(rw.empty()) rw = argv[i];
|
||||
else rw = rw + " " + argv[i];
|
||||
}
|
||||
return run(d, cout, apos, just_candidates, minlen, maxlen, maxcount, lengths, aw, rw);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
121
webapp.py
121
webapp.py
|
|
@ -1,121 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2013 Jeff Epler <jepler@unpythonic.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
import subprocess
|
||||
import threading
|
||||
import sys
|
||||
import os
|
||||
import cgi
|
||||
import traceback
|
||||
import errno
|
||||
import ana
|
||||
|
||||
d = ana.from_binary('dict.bin')
|
||||
|
||||
def query(pi):
|
||||
return d.run(pi)
|
||||
|
||||
|
||||
# Every WSGI application must have an application object - a callable
|
||||
# object that accepts two arguments. For that purpose, we're going to
|
||||
# use a function (note that you're not limited to a function, you can
|
||||
# use a class for example). The first argument passed to the function
|
||||
# is a dictionary containing CGI-style envrironment variables and the
|
||||
# second variable is the callable object (see PEP 333).
|
||||
def anagram_app(environ, start_response):
|
||||
status = '200 OK' # HTTP Status
|
||||
|
||||
pi = environ['QUERY_STRING']
|
||||
pi = cgi.parse_qs(pi)
|
||||
plain = pi.get('p', False)
|
||||
if pi:
|
||||
pi = pi.get('q', [''])[-1]
|
||||
else:
|
||||
pi = ''
|
||||
|
||||
if plain:
|
||||
headers = [('Content-type', 'application/octet-stream')] # HTTP Headers
|
||||
else:
|
||||
headers = [('Content-type', 'text/html')] # HTTP Headers
|
||||
start_response(status, headers)
|
||||
|
||||
if not plain:
|
||||
yield '''<!DOCTYPE html>
|
||||
<html>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<head>
|
||||
<title>Surly Anagram Server</title>
|
||||
<style>
|
||||
@media screen and (min-width: 680px) { #cheatsheet { float: right; } }
|
||||
#cheatsheet { font-size: 71%%; cursor: pointer; }
|
||||
#cheatsheet table, #cheatsheet caption { background: #d9d9d9; color: #000; }
|
||||
#cheatsheet.hidden { cursor: zoom-in; }
|
||||
#cheatsheet caption:after { content: "\\a0«" }
|
||||
#cheatsheet.hidden caption:after { content: "\\a0»" }
|
||||
#cheatsheet.hidden tbody { display: none; }
|
||||
//#cheatsheet { float: right; }
|
||||
#cheatsheet th { text-align: left }
|
||||
#cheatsheet caption { font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="cheatsheet">
|
||||
<table>
|
||||
<caption>Cheatsheet</caption>
|
||||
<tr><th>letters... <td> Letters available to anagram
|
||||
<tr><th>=word <td> word must be in result
|
||||
<tr><th>>n <td> words must contain at least n letters
|
||||
<tr><th><n <td> words must contain at most n letters
|
||||
<tr><th>' <td> words with apostrophes are considered
|
||||
<tr><th>n <td> choose a word with exactly n letters
|
||||
<tr><th>-n <td> display at most n results (limit 1000)
|
||||
<tr><th>? <td> display candidate words, not whole phrases
|
||||
<tr><td colspan=2>In ajax mode, hit enter or click "anagram" to do get full results
|
||||
<tr><td colspan=2>Source (web app and unix commandline program) on
|
||||
<a href="https://github.com/jepler/anagram">github</a>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form id="f"><input type="text" id="query" name="q" value="%s">
|
||||
<input type="submit" value="anagram">
|
||||
<script>document.getElementById("query").focus()</script>
|
||||
</form>
|
||||
<pre id="results">''' % cgi.escape(pi, True)
|
||||
|
||||
if pi:
|
||||
if plain: e = lambda x: x
|
||||
else: e = cgi.escape
|
||||
yield '# Query: ' + e(repr(pi)) + '\n'
|
||||
|
||||
for row in query(pi):
|
||||
yield e(row) + '\n'
|
||||
|
||||
if not plain:
|
||||
yield '''
|
||||
</pre>
|
||||
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||
<script src="anagram.js"></script>
|
||||
<script>
|
||||
$("#cheatsheet").click(function() { $(this).toggleClass("hidden"); })
|
||||
</script>
|
||||
</body></html>'''
|
||||
|
||||
from flup.server.fcgi import WSGIServer
|
||||
WSGIServer(anagram_app).run()
|
||||
Loading…
Reference in a new issue