Controlled natural english PEG parser

  • 3 Replies
  • 1244 Views
*

Zero

  • Eve
  • ***********
  • 1287
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

  • Eve
  • ***********
  • 1287
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

  • Eve
  • ***********
  • 1287
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

  • Eve
  • ***********
  • 1287
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


 


Requirements for functional equivalence to conscious processing?
by DaltonG (General AI Discussion)
November 19, 2024, 11:56:05 am
Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am

Users Online

345 Guests, 0 Users

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

Articles