问题描述
你好,
我需要一些关于我梦想的网络应用程序的想法
并且在python中流口水。我希望搜索页面看起来完全像
Google。但是当我按下搜索按钮时,它应该在像Oracle这样的rdbms中搜索数据库
并提供结果。
例如,如果我的关键字是所有客户姓名
以''上帝''开头它应该以某种方式搜索表CUSTOMER,跟随查询后显示
:
来自CUSTOMER的SELECT CUSTNAME CUSTNAME喜欢''上帝%''
所以我们基本上需要一个好的python解析器模块,它将
关键字解析为sql或sqls并列出结果。我可以在
关键字中查找表和列的同义词并将其映射到
表和列名并创建sql,但这不是一个万无一失的想法,因为
我们都知道英语是一种非常含糊的语言。上面的想法将会失败,如果我无法识别表格,列名称
,运算符和逻辑顺序中的值,以便创建一个
语法正确的sql。如果涉及更多的表,我应该
也想到加入表(内部,外部,equi连接)。
我想要的只是来自蟒蛇黑客的一些启发性想法(我的意思是
程序员)那里.Plz抛光你的灰色细胞让我知道你的b
想法。
#this是我的基本和愚蠢的关键词解析器
#对象db提供表格和列名
#因为你可以看到它可能会也可能不会对单个表有效
class KeyWordParser(object):
def __init __(self,keywords,db):
self.keywords = keywords.upper()。 split()
self.db = db
self.tables = []
self.columns = []
def parse2sql(self):
for self.keywords中的单词:
如果self.db.tables()中的单词:
self.tables.append(word)
for self.keywords中的单词:
表格中的表格:
self.db.columns(表)中的列
:
if column == word:
self.columns.append(column)
sql =''SELECT%s FROM%s' '%('',''。join(self.columns)或
''*'','',''。join(self.tables))
返回sql
Hello there,
I need some thoughts about a web application that i am dreaming
and drooling about in python. I want a search page to look exactly like
Google. But when i press the search button, it should search a database
in an rdbms like Oracle and provide results.
For example, if my keywords are "all customers with names
starting with ''God''" it should somehow search table CUSTOMER , with
following query :
SELECT CUSTNAME FROM CUSTOMER WHERE CUSTNAME LIKE ''God%''
So we basically need is a good python parser module which parses the
keywords into an sql or sqls and list the results. I can look in the
keywords for table and column synonyms and map it into
table and column names and create sql but it''s not a foolproof idea as
we all know that english is a very vague language. The above idea wil
fail , if i can''t identify table,column names
,operators and values in their logical orders so as to create a
syntactically correct sql. If there are more tables involved, i should
also think of joining tables (inner,outer,equi joins).
All I want is some enlightening thoughts from the python hackers(i mean
programmers) out there.Plz polish your grey cells and let me know your
thoughts.
# this is my basic and foolish keywordparser
# the object db provides the table as well as column names
# as u can see it may or may not work even for a single table
class KeyWordParser(object):
def __init__(self,keywords,db):
self.keywords = keywords.upper().split()
self.db = db
self.tables = []
self.columns = []
def parse2sql(self):
for word in self.keywords:
if word in self.db.tables():
self.tables.append(word)
for word in self.keywords:
for table in self.tables:
for column in self.db.columns(table):
if column == word:
self.columns.append(column)
sql = ''SELECT %s FROM %s'' % ('',''.join(self.columns) or
''*'','',''.join(self.tables))
return sql
推荐答案
这是自然语言处理(NLP)任务。一般情况下,它很难b / b
。对于Python,有自然语言工具包(NLTK):
但是,通过接受一个特定的子集,
所谓的你可以走得很远受控自然语言做法。例如:
-
Robert Kern
"在草地长得高的地狱里
梦想的坟墓是否已经死亡。
- Richard Harter
This is a Natural Language Processing (NLP) task. In general, it''s
pretty hard. For Python, there is the Natural Language Toolkit (NLTK):
http://nltk.sourceforge.net/
You could get pretty far, though, by accepting a specific subset, the
so-called "controlled natural language" approach. For example:
http://www.jfsowa.com/clce/specs.htm
http://www.ics.mq.edu.au/~rolfs/cont...ral-languages/
http://www.ifi.unizh.ch/attempto/
--
Robert Kern
rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
这篇关于Web应用程序,如谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!