Controlled natural english PEG parser

  • 3 Replies
  • 278 Views
*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1017
  • Ready?
    • dissolvedgirl
Controlled natural english PEG parser
« on: March 08, 2020, 09:21:53 pm »
Hi,

I needed a parser for my project, so I did this one with PEGjs online.

Here is the code to paste in the "1" textarea:

PEGjs english.txt

And here is a testing text to paste in the "2" textarea:
Code
; test.
is there a man?
for every man is there a woman?
which man is there?
are there (a man and a woman)?
is it true that a man works on a problem?
does a man work on the problem?
does a man always work on a problem?
which man does work on this problem?
which problem does this man work on?
there is a man who works on this problem.
does the man find a solution to the problem?
for each of these problems there is a solution.
for some of them there are more than 1 solution.
if there is a problem then there is a solution.
if there is a man who works on a problem then there is a solution else there is no solution.
a young man does not have to find a solution.
a man gives a solution to another man.
there is a solution which is found by a man.
a man wants to find a solution to each of these problems.
a man finds nothing but solutions.
one always finds at least 1 solution to a problem.
you get the man's solution.
this solution looks good.
this solution looks better than mine.
you should not have to find a solution.
it is not provable that there is always a solution.
(the solution to a problem) is itself.
one can quickly find a solution to a problem.
a solution can always be found.
this one feels like the best solution.


Well, it's still a little rough, but it's short and fun. :)

Edit: added some details in the rendered JSON, and corrected a few bugs + link to Github.
The parser is 554Kb  :o
« Last Edit: March 09, 2020, 12:33:31 pm by Zero »

*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1017
  • Ready?
    • dissolvedgirl
Re: Controlled natural english PEG parser
« Reply #1 on: March 09, 2020, 12:28:57 pm »
Now let's make it work the other way around! I have the parse() part, I need the stringify() part...  :stirthepot:

*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1017
  • Ready?
    • dissolvedgirl
Re: Controlled natural english PEG parser
« Reply #2 on: March 11, 2020, 01:49:41 pm »
Done! DCE parser / stringifier.

As a test, the sentences below are parsed, the result is then stringified, then parsed again, then stringified again. And it's the same as the original. Needs more tests, but it feels like a success.

Next step: Ontology Engineering  :o

Quote
    is there a man;
    is there a woman;
    for every man is there a woman;
    is there a man who works?
    a man has to work.
    there are (a man and a woman) who have to work.
    for many problems there is at least a solution.
    there is a [woman]'s man.
    a solution is better than a problem.
    it is not impossible that a woman is more good than a man.
    is it provable that a man is more bad than a woman?
    this man is the smallest man.
    if there is a problem then there is a solution else there is no solution.
    does a man work on this problem?
    is there a man who works on this problem?
    is there a man?
    for every man is there a woman?
    which man is there?
    are there (a man and a woman)?
    is it true that a man works on a problem?
    does a man work on the problem?
    does a man always work on a problem?
    a man always works on a problem.
    which man does work on this problem?
    which problem does this man work on?
    there is a man who works on this problem.
    does the man find a solution to the problem?
    for each of these problems there is a solution.
    for some of them there are more than 1 solution.
    if there is a problem then there is a solution.
    if there is a man who works on a problem then there is a solution else there is no solution.
    a young man does not have to find a solution.
    a man gives a solution to another man.
    there is a solution which is found by a man.
    a man wants to find a solution to each of these problems.
    a man finds nothing but solutions.
    one always finds at least 1 solution to a problem.
    you get the [man]'s solution.
    this solution looks good.
    this solution looks better than mine.
    you should not have to find a solution.
    it is not provable that there is always a solution.
    (the solution to a problem) is itself.
    one can quickly find a solution to a problem.
    a solution can always be found.
    this one feels like the best solution.
    is there a [dog]?
    the [lion] is not always [hungry].
« Last Edit: March 12, 2020, 09:30:34 am by Zero »

*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1017
  • Ready?
    • dissolvedgirl
Re: Controlled natural english PEG parser
« Reply #3 on: March 12, 2020, 09:24:09 am »
So... in case somebody would want to try it, here is the procedure to set it up.

You'd go to the github repo, and download the zip. In the folder where you extract it, you would launch a "npm install", to install dependencies. Then "npm start" would start the command-line interface. To enter the natural language REPL, type the command "dce". From there, the REPL will show a JSON representation of the sentences you type.

It works only for simple present (no past, no future). The vocabulary is very limited, and it is hard-coded. You can still introduce unknown words between square brackets, like this:
Quote
a [lion] is not always [hungry]

You can put fragments of sentences between parentheses to explicitly indicate the structure. Also, you need parentheses for: and, or, whose, of, to.

This is intended to be an interface to something that has functionalities similar to Description Logic, so don't expect it to parse Baudelaire :)  on the other hand, if you consider it's not parsing correctly something it should, please let me know so I can enhance it.

Here is the built-in vocabulary.

Quote
times time persons person years year ways way days day things thing women woman men man worlds world lives life hands hand parts part children child eyes eye places place works work weeks week cases case points point truths truth teams team numbers number groups group problems problem solutions solution facts fact tests test beliefs belief there here now jade time-thing time-things mind-thing mind-things world-thing world-things period periods change changes event events action actions concept concepts instance instances collection collections relation relations area areas object objects agent agents message messages meaning meanings inflected-form inflected-forms definition definitions context contexts synonym synonyms antonym antonyms derivative derivatives special-case special-cases abstraction abstractions member members part parts substance substances aspect aspects symbol symbols location locations neighbor neighbors cause causes posterior-event posterior-events next-event next-events overlapping-event overlapping-events sub-event sub-events first-sub-event first-sub-events last-sub-event last-sub-events prerequisite prerequisites obstacle obstacles desire desires intention intentions creation creations motivation motivations interface interfaces way-to-do ways-to-do purpose purposes capacity capacities saying says say said getting gets get gotten got making makes make made going goes gone go knowing knows known know takes taking taken take sees seeing seen see comes come coming thinks thinking think thought looks looking looked look wants wanting wanted want gives giving given give uses using used use finds finding found find tells telling told tell asks asking asked ask works working worked work seems seeming seemed seem feels feeling felt feel tries trying tried try leaves leave leaving left calls calling called call believes believing believed believe is are am being been accidentally actually always awkwardly beautifully briefly carefully certainly easily especially exactly frequently generally greatly happily helpfully honestly immediately lively mysteriously naturally often politely quickly randomly rapidly regularly seldom slowly suddenly thankfully unexpectedly unfortunately usefully voluntarily wrongly yesterday good new first last long great little own other old right big high low different small large next early young important few public bad same able true false


 


Arecibo radio telescope
by infurl (General Chat)
Today at 12:09:00 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
December 01, 2020, 10:59:22 pm
New Server
by LOCKSUIT (Announcements)
November 30, 2020, 06:38:12 am
Releasing full AGI/evolution research
by LOCKSUIT (General Project Discussion)
November 28, 2020, 06:58:33 pm
alert manager class for waifubots
by yotamarker (General AI Discussion)
November 27, 2020, 04:12:22 pm
Giving AI rights
by frankinstien (General Project Discussion)
November 26, 2020, 04:26:07 pm
We are computational machines after all!
by MikeB (General Project Discussion)
November 26, 2020, 08:37:45 am
Pattern based NLP
by MikeB (General Project Discussion)
November 26, 2020, 08:28:32 am
AI leads a revolution in biology.
by infurl (AI News )
November 30, 2020, 09:56:38 pm
Syntherapy AI psychotherapist game.
by 8pla.net (AI News )
November 30, 2020, 04:58:36 am
Senate Approves Deepfake bill
by LOCKSUIT (AI News )
November 25, 2020, 02:01:18 am
Sony Patent Suggests PS5 Will Have a Chatbot Feature
by frankinstien (AI News )
November 18, 2020, 05:47:45 pm
Potentially life-saving robot scares bears.
by infurl (Robotics News)
November 12, 2020, 12:41:40 am
good news everyone
by HS (AI News )
November 07, 2020, 10:03:04 pm
Meet Kuki
by 8pla.net (AI News )
November 05, 2020, 04:18:34 am
Realistic and Interactive Robot Gaze by Disney Research
by infurl (AI News )
November 03, 2020, 06:33:15 am

Users Online

133 Guests, 1 User
Users active in past 15 minutes:
Data
[Trusty Member]

Most Online Today: 143. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles