Skip to content

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.

Notifications You must be signed in to change notification settings

alejandro945/cyk-algorithm-server

Repository files navigation

Build Status

Rails CYK Rest API 🧶

Project Setup

Install all gems:

$ bundle install

Update the database with new data model:

$ rails db:migrate

Feed the database with default seeds:

$ rails db:seed

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

$ rails server

Run all RSpec tests and Rubocop:

$ 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.:

$ curl -X POST -H 'Content-type: application/json' -d '{}' localhost:3000/api/v1/responses

Json Input

{
    "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

{
    "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

{
    "response": true,
    "matrix": [
        [
            [
                "A"
            ],
            [
                [
                    "A"
                ]
            ],
            [
                [],
                [
                    "S"
                ]
            ]
        ],
        [
            [
                "A"
            ],
            [
                [
                    "S"
                ]
            ],
            null
        ],
        [
            [
                "B"
            ],
            null,
            null
        ]
    ]
}

Get responses in postgress database:

$ curl localhost:3000/api/v1/responses

Json Output

[
    {
        "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"
    }
]

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published