<commit_before># HTTP API for [UnnaturalCode][]

# Install

    pip install -r requirements.txt
    pip install -e <fully-qualified-path-to-unnaturalcode>

Though you'll probably want to create a `virtualenv` before this.

# Run

    python server.py

# All rooted on resource `/{corpus}`

 * Currently, only the `py` corpus is supported. Obviously, `py` is the
   occam-π corpus.


# `GET /{corpus}/`—Corpus info

Returns metadata for the given corpus. Metadata includes:

 * `fullname`
 * `last_updated`
 * `description`
 * `language`—programming or otherwise
 * `order`
 * `smoothing`—Probably always `ModKN`
 * `vocabulary`
   * `size`
   * `categories`—lists syntactic categories


# `GET /{corpus}/predict/{context*}`—Predict

     GET /py/predict/<unk>/for/i/in HTTP/1.1

     {"suggestions": [3.45, ["range", "(", "5", ")", ":"]]}

## Mandatory arguments

Must give context as a context path.

### `{context*}`

Preceding token context. The more tokens provided, the better. See
[Context format](#context-format).



# `POST /{corpus}/xentropy`—calculate cross entropy
<commit_msg>Made README more accurate for info path.<commit_after># HTTP API for [UnnaturalCode][]

# Install

    pip install -r requirements.txt
    pip install -e <fully-qualified-path-to-unnaturalcode>

You'll (most likely) want to create a [virtualenv][] before this.

[virtualenv]: http://virtualenv.readthedocs.org/en/latest/

# Run

    python server.py

# Test

    python test_server.py

# All rooted on resource `/{corpus}`

 * Currently, only the `py` corpus is supported. Obviously, `py` is the
   occam-π corpus.


# `GET /{corpus}/`—Corpus info

Returns metadata for the given corpus. Metadata includes:

 * `name`
 * `description`
 * `language`—programming or otherwise
 * `order`— order of the *n*-gram
 * `smoothing`—Probably always `ModKN` ([Modified Kneser-Ney][ModKN])
 
[ModKN]: https://kheafield.com/professional/edinburgh/estimate_paper.pdf.


# `GET /{corpus}/predict/{context*}`—Predict

     GET /py/predict/<unk>/for/i/in HTTP/1.1

     {"suggestions": [3.45, ["range", "(", "5", ")", ":"]]}

## Mandatory arguments

Must give context as a context path.

### `{context*}`

Preceding token context. The more tokens provided, the better. See
[Context format](#context-format).



# `POST /{corpus}/xentropy`—calculate cross entropy

{'fraction_non_alphanumeric': 0.14989293361884368, 'fraction_numerical': 0.005139186295503212, 'mean_word_length': 3.89727463312369, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7070394', 'n_tokens_mistral': 810, 'n_tokens_neox': 757, 'n_words': 225}