# ai-matcher

> Microservice that matches query strings to a large database of questions/answers, with context

Latest version **0.0.1** (published 2016-03-29) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install ai-matcher
pnpm add ai-matcher
yarn add ai-matcher
bun add ai-matcher
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-03-29 |
| First published | 2016-03-29 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| Author | @brandonhorst |
| Maintainers | brandonhorst |

## Links

- npm: https://www.npmjs.com/package/ai-matcher
- Repository: https://github.com/AdmitHub/ai-matcher
- Homepage: https://github.com/AdmitHub/ai-matcher#readme
- Issues: https://github.com/AdmitHub/ai-matcher/issues
- npm.io page: https://npm.io/package/ai-matcher

## Dependencies (11)

- [lodash](https://npm.io/package/lodash.md) ^4.6.1
- [express](https://npm.io/package/express.md) ^4.13.4
- [winston](https://npm.io/package/winston.md) ^2.2.0
- [mongoose](https://npm.io/package/mongoose.md) ^4.4.9
- [body-parser](https://npm.io/package/body-parser.md) ^1.15.0
- [escape-regexp](https://npm.io/package/escape-regexp.md) 0.0.1
- [babel-register](https://npm.io/package/babel-register.md) ^6.7.2
- [fast-levenshtein](https://npm.io/package/fast-levenshtein.md) ^1.1.3
- [normalize-english](https://npm.io/package/normalize-english.md) ^1.0.0
- [winston-papertrail](https://npm.io/package/winston-papertrail.md) ~1.0.2
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.6.0

## Recent versions

- 0.0.1 (latest) — 2016-03-29

## README

# ai-matcher
Microservice that matches query strings to a large database
of questions/answers, with context

## Setup

Clone the repo. `npm install`. Copy `conf.json.example` to `conf.json`.
Run `mongod` locally in another process.

`npm test` to run test suite. `npm test -- -w` to watch for file updates.
`npm test -- test/route-query.js` to run tests on a particular file.

`npm start` to spin up the server, then call make requests with

```sh
curl 'localhost:3002/api/query?question=how+are+you' -H 'Authorization: Bearer test'
```

## Design

### Endpoints

All inputs and outputs are JSON. Query parameters should be sent like so:

- Dates in Query Strings should be in ISO_8601 format
- Arrays in Query Strings should be any format understood by `qs`
  (`a[]=b&a[]=c` works fine)
- Bools in Query Strings should be `0` or `1`
- `PUT` methods merged onto the existing objects using `_.assign`
- `created` and `updated` are set automatically and cannot be modified

---

- `GET /query` - Run a question through the system. Creates a `Log` entry.
  - Query Parameters
    * `question : String` - User's question
    * `messagingService : String` - filters the Understandings based upon the
      college we are concerned about
    * `contexts : [String]` - allows access to Understandings that have
      `inputContexts` specified
    * `userId : String` - For logging purposes
  - Returns
    * `success : Boolean`
    * `topic : String` - `topic` for the matched `Understanding`
    * `answer : String` - answer to send the user
    * `outputContexts : [String]` - contexts that should be sent with the next
      request
    * `logId : String` - `id` of the generated `Log` entry.

- `GET /logs` - Return a list of all logs, optionally filtered. Please
  filter, or there will be too many results
  - Query Parameters
    * `createdBefore, createdAfter, updatedBefore, updatedAfter : Date`
    * `needsReview, handled : Boolean`
    * `messagingService : String`
- `PUT /logs/:id` - Update a log. Sets `handledDate` and `reviewedDate`
  automatically

- `GET /understandings` - Get a list of all understandings, optionally filtered
  - Query Parameters
    * `createdBefore, createdAfter, updatedBefore, updatedAfter : Date`
- `PUT /understandings/:id` - Update an understanding
- `POST /understandings/` - Create a new understanding

- `GET /entities` - Get a list of all entities, optionally filtered
  - Query Parameters
    * `createdBefore, createdAfter, updatedBefore, updatedAfter : Date`
- `PUT /entities/:id` - Update an entity
- `POST /entities` - Create a new entity

### Collections

- `Understandings`
  - `created : Date`
  - `updated : Date`
  - `topic : String`
  - `keywords : [String]`
  - `outputContexts : [String]`
  - `questionGroups : [Object]`
    - `inputContexts : [String]`
    - `fuzzyQuestions [String]`
    - `exactQuestions [String]`
  - `answerGroups : [Object]`
    - `messagingService : String`
    - `answers : [String]`
    - `media : [String]`
- `Entities`
  - `created : Date`
  - `updated : Date`
  - `name : String`
  - `synonymGroups : [Object]`
    - `messagingService : String`
    - `synonyms : [String]`
- `Logs`
  - `created : Date`
  - `updated : Date`
  - `userId : String` - Oli User ID
  - `question : String`
  - `inputContexts : [String]`
  - `outputContexts : [String]`
  - `topic : String`
  - `messagingService : String`
  - `answer : String`
  - `sentToHuman : String`
  - `handled : Boolean`
  - `handledBy : String` - Oli User ID
  - `handledDate : Date` - Set automatically with
    `PUT /logs` if `{handled : true}`
  - `handledAction : [String]`
  - `humanResponse : String`
  - `reviewed : Boolean`
  - `reviewedBy : String` - Oli User ID
  - `reviewedDate : Date` - Set automatically with
    `PUT /logs` if `{needsReview : true -> false}`
  - `reviewedAction : String`
  - `error : String`

---
_Source: https://npm.io/package/ai-matcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
