An open API service indexing awesome lists of open source software.

https://github.com/alejandro945/cyk-algorithm-server

In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is a parsing algorithm for context-free grammars published by Itiroo Sakai in 1961.
https://github.com/alejandro945/cyk-algorithm-server

cyk-algorithm rails-api ruby

Last synced: 3 months ago
JSON representation

In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is a parsing algorithm for context-free grammars published by Itiroo Sakai in 1961.

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)

# Rails CYK Rest API 🧶

## Project Setup

**Install all gems**:

```console
$ bundle install
```

**Update the database with new data model**:

```console
$ rails db:migrate
```

**Feed the database with default seeds**:

```console
$ rails db:seed
```

**Start the web server on `http://localhost:3000` by default**:

```console
$ rails server
```

**Run all RSpec tests and Rubocop**:

```console
$ rails test
```

## Usage

| HTTP verbs | Paths | Used for |
| ---------- | ------ | --------:|
| POST | api/v1/responses | Determintes if w is generated by G|
| GET | api/v1/responses | List all responses - **DEPRECATED**|

## Use Case Examples

### CYK Algorithm

**Boolean Output: w ∈ L(G) only if S ∈ X1n.**:

```console
$ curl -X POST -H 'Content-type: application/json' -d '{}' localhost:3000/api/v1/responses
```
#### Json Input
```json
{
"grammar": [
{
"producer": "S",
"products": ["BA", "A"]
},
{
"producer": "A",
"products": ["CA","a"]
},
{
"producer": "B",
"products": ["BB","b"]
},
{
"producer": "C",
"products": ["BA", "c"]
}
],
"word": "bca"
}
```
#### Json Output
```json
{
"id": 12,
"word": "bca",
"isAdmitted": true,
"created_at": "2022-10-18T02:14:45.389Z",
"updated_at": "2022-10-18T02:14:45.389Z"
}
```
#### New Response From Slides Example
```json
{
"response": true,
"matrix": [
[
[
"A"
],
[
[
"A"
]
],
[
[],
[
"S"
]
]
],
[
[
"A"
],
[
[
"S"
]
],
null
],
[
[
"B"
],
null,
null
]
]
}
```

**Get responses in postgress database**:

```console
$ curl localhost:3000/api/v1/responses
```
#### Json Output
```json
[
{
"id": 8,
"word": "bbab",
"isAdmitted": true,
"created_at": "2022-10-18T01:50:28.200Z",
"updated_at": "2022-10-18T01:50:28.200Z"
},
{
"id": 9,
"word": "bbab",
"isAdmitted": true,
"created_at": "2022-10-18T01:53:37.901Z",
"updated_at": "2022-10-18T01:53:37.901Z"
},
{
"id": 10,
"word": "aab",
"isAdmitted": true,
"created_at": "2022-10-18T01:54:40.336Z",
"updated_at": "2022-10-18T01:54:40.336Z"
},
{
"id": 11,
"word": "aab",
"isAdmitted": true,
"created_at": "2022-10-18T01:55:11.980Z",
"updated_at": "2022-10-18T01:55:11.980Z"
},
{
"id": 12,
"word": "bca",
"isAdmitted": true,
"created_at": "2022-10-18T02:14:45.389Z",
"updated_at": "2022-10-18T02:14:45.389Z"
}
]
```