简体   繁体   English

自然语言处理数据库查询

[英]Natural Language Processing Database Querying

I need to develop natural language querying tool for a structured database.我需要为结构化数据库开发自然语言查询工具。 I tried two approaches.我尝试了两种方法。

  • using Python nltk (Natural Language Toolkit for python) using使用 Python nltk(Python 的自然语言工具包)使用
  • Javascript and JSON (for data source) Javascript 和 JSON(用于数据源)

In the first case I did some NLP steps to format the natural query by doing removing stop words, stemming, finally mapping keywords using featured grammar mapping.在第一种情况下,我做了一些 NLP 步骤来格式化自然查询,方法是去除停用词、词干提取,最后使用特征语法映射来映射关键字。 This methodology works for simple scenarios.这种方法适用于简单的场景。

Then I moved to second approach.然后我转向第二种方法。 Finding the data in JSON and getting corresponding column name and table name , then building a sql query.在JSON中查找数据并获取对应的列名和表名,然后构建sql查询。 For this one, I also implemented removing stop words, stemming using javascript.对于这个,我还实现了删除停用词,使用 javascript 进行词干化。

Both of these techniques have limitations.I want to implement semantic search approach.这两种技术都有局限性。我想实现语义搜索方法。

Please can anyone suggest me better approach to do this..请任何人都可以建议我更好的方法来做到这一点..

Semantic parsing for NLIDB (natural language interface to data bases) is a very evolved domain with many techniques: rule based methods (involving grammars) or machine learning techniques. NLIDB(数据库的自然语言接口)的语义解析是一个非常进化的领域,有许多技术:基于规则的方法(涉及语法)或机器学习技术。 They cover a large range of query inputs, and offer much more results than pure NL processing or regex methods.它们涵盖了大范围的查询输入,并提供比纯 NL 处理或正则表达式方法更多的结果。

The technique I favor is based on Feature based context-free grammars FCFG .我喜欢的技术基于基于特征的上下文无关文法FCFG For starters, in the NTLK book available online , look for the string "sql0.fcfg".首先,在在线提供的 NTLK 书籍中,查找字符串“sql0.fcfg”。 The code example shows how to map the NL phrase structure query "What cities are located in China" into an SQL query "SELECT City FROM city_table WHERE Country="china" via the feature "SEM" or semantics of the FCFG.该代码示例展示了如何通过功能“SEM”或 FCFG 的语义将 NL 短语结构查询“中国位于哪些城市”映射到 SQL 查询“SELECT City FROM city_table WHERE Country="china”。

I recommend Covington's books我推荐卡温顿的书

  • NLP for Prloog Programmers (1994)面向 Prloog 程序员的 NLP (1994)
  • Prolog Programming in Depth (1997) Prolog 深度编程 (1997)

They will help You go a long way.他们会帮助你走很长的路。 These PDF's are downloadable from his site .这些 PDF 可从他的网站下载。

As I commented, I think you should add some code, since not everyone has read the book.正如我所评论的,我认为您应该添加一些代码,因为不是每个人都读过这本书。

Anyway my conclusion is that yes, as you said it has a lot of limitations and the only way to achieve more complex queries is to write very extensive and complete grammar productions, a pretty hard work.无论如何,我的结论是,是的,正如您所说,它有很多限制,实现更复杂查询的唯一方法是编写非常广泛和完整的语法产品,这是一项非常艰巨的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM