diff --git a/README.md b/README.md index b163a98..354c56a 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,56 @@ co.py.cat ========= -An implementation of [Douglas Hofstadter](http://prelectur.stanford.edu/lecturers/hofstadter/)'s copycat algorithm. The copycat algorithm is explained [on Wikipedia](https://en.wikipedia.org/wiki/Copycat_%28software%29), and that page has many links for deeper reading. +An implementation of [Douglas Hofstadter](http://prelectur.stanford.edu/lecturers/hofstadter/)'s Copycat algorithm. +The Copycat algorithm is explained [on Wikipedia](https://en.wikipedia.org/wiki/Copycat_%28software%29), and that page has many links for deeper reading. -This implementation is a copycat of Scott Boland's [Java implementation](http://itee.uq.edu.au/~scottb/_Copycat/), but re-written into Python. It's not a direct translation - but based on his code. I did not carry over the GUI, as this version can more usefully be run from command line, or imported for use by other Python scripts. +This implementation is a copycat of Scott Boland's [Java implementation](https://archive.org/details/JavaCopycat). +The original Java-to-Python translation work was done by J Alan Brogan (@jalanb on GitHub). +The Java version has a GUI similar to the original Lisp; this Python version has no GUI code built in but can be incorporated into a larger GUI program. -In cases where I could not grok the Java implementation easily I took ideas from the [LISP implementation](http://web.cecs.pdx.edu/~mm/how-to-get-copycat.html), or directly from [Melanie Mitchell](https://en.wikipedia.org/wiki/Melanie_Mitchell)'s "[Analogy-Making as Perception](http://www.amazon.com/Analogy-Making-Perception-Computer-Melanie-Mitchell/dp/0262132893/ref=tmm_hrd_title_0?ie=UTF8&qid=1351269085&sr=1-3)" +J Alan Brogan writes: +> In cases where I could not grok the Java implementation easily, I took ideas from the +> [LISP implementation](http://web.cecs.pdx.edu/~mm/how-to-get-copycat.html), or directly +> from [Melanie Mitchell](https://en.wikipedia.org/wiki/Melanie_Mitchell)'s book +> "[Analogy-Making as Perception](http://www.amazon.com/Analogy-Making-Perception-Computer-Melanie-Mitchell/dp/0262132893/ref=tmm_hrd_title_0?ie=UTF8&qid=1351269085&sr=1-3)". -I also tried to make the code more pythonic. +Cloning the repo +---------------- -Installation ------------- +To clone the repo locally, run these commands: -There are no particular installation instructions, just clone and run, e.g. - -```sh -$ git clone https://github.com/jalanb/co.py.cat.git +``` +$ git clone https://github.com/Quuxplusone/co.py.cat.git $ cd co.py.cat/copycat -$ python main.py abc abd ijk +$ python main.py abc abd ppqqrr 10 ``` -Running -------- +The script takes three or four arguments. +The first two are a pair of strings with some change, for example "abc" and "abd". +The third is a string which the script should try to change analogously. +The fourth (which defaults to "1") is a number of iterations. -The script takes three arguments. - The first two are a pair of triplets with some change, for example "abc" and "abd". - The third is a triplet which the script should try to change analogously +This might produce output such as -For example the following invocation will probably display "ijl" - -```sh -$ python main.py abc abd ijk ``` +ppqqss: 6 (avg time 869.0, avg temp 23.4) +ppqqrs: 4 (avg time 439.0, avg temp 37.3) +``` + +The first number indicates how many times Copycat chose that string as its answer; higher means "more obvious". +The last number indicates the average final temperature of the workspace; lower means "more elegant". + +Installing the module +--------------------- + +To install the Python module and get started with it, run these commands: + +``` +$ pip install -e git+git://github.com/Quuxplusone/co.py.cat.git#egg=copycat +$ python +>>> from copycat import Copycat +>>> Copycat().run('abc', 'abd', 'ppqqrr', 10) +{'ppqqrs': {'count': 4, 'avgtime': 439, 'avgtemp': 37.3}, 'ppqqss': {'count': 6, 'avgtime': 869, 'avgtemp': 23.4}} +``` + +The result of `run` is a dict containing the same information as was printed by `main.py` above. diff --git a/copycat/__init__.py b/copycat/__init__.py index e69de29..ae36718 100644 --- a/copycat/__init__.py +++ b/copycat/__init__.py @@ -0,0 +1 @@ +from copycat import Copycat diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5cffd86 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +from setuptools import setup + +readme = open('README.md').read() +requirements = [l.strip() for l in open('requirements.txt').readlines()] + +setup( + name='copycat', + version='0.0.1', + packages=['copycat'], + install_requires=[l.strip() for l in open('requirements.txt').readlines()], + package_data={'': ['LICENSE']}, + + # metadata for upload to PyPI + author="The Fluid Analogies Research Group, J Alan Brogan, and Arthur O'Dwyer", + author_email='arthur.j.odwyer@gmail.com', + description="Python implementation of Douglas Hofstadter's Copycat.", + license='MIT license', + long_description=open('README.md').read(), + keywords='ai analogy copycat farg fargitecture hofstadter slipnet', + url='https://github.com/Quuxplusone/co.py.cat', +)