parse natural language

后端 未结 3 832
粉色の甜心
粉色の甜心 2021-02-06 17:17

To start: I know this system will have flaws!

NOTE: Im adding a few other languages because I don\'t find this problem specific to php

3条回答
  •  广开言路
    2021-02-06 17:55

    I have been working on parsing menus and recipes (not finished) and this is my approach:

    • find the sentences separators (I use AND as well as others)
    • parse each sentence to find the key words that you need (light/bulbs/etc.., on/off)
    • if you have a limited set of places (kitchen, bathroom, etc...)
      • search for those keywords, remove the others
      • ELSE
      • remove the extra words that some people might use (bright, colorful, etc...)
    • store it into an array, something that might look like this:
      • what
      • where
    • if you do not have one of the fields, leave it blank
    • for each result check what you have and if you have a blank field fill it up with the previous parsing

    I.E.: Turn the lights on in the bedroom and in the kitchen

    • 1:
      • turn the light on in the bedroom
      • what: lights on
      • where: bedroom
    • 2:
      • in the kitchen
      • what:
      • where: kitchen

    what_2 is empty, then what_2 is lights on

    keep in mind that sometime needs to fill up the array with the next results (depending on how the sentence is structured, but it is rare), I add a "+" or "-" to it so I know if I have to go forward or backwards to find the missing parts while parsing it

提交回复
热议问题