Understanding search queries, semantics, and "Meaning" ...aren't we all looking for meaning?
5lvqbwl02 at sneakemail.com
5lvqbwl02 at sneakemail.com
Wed Dec 31 00:25:27 CET 2008
> > library, as I'm looking to learn to fish, so to speak, and to learn a
> > bit about the biology of fish.
> I'm going to break rule #1 of your requirements but in an unexpected
> way. Rather than studying PostgreSQL, MySQL, or Oracle, why don't you
> crack open the topic of relational database theory and relational
> algebra? That should help with the "big thinking" bit in the same way
> understanding 1+1 helps you understand how to add any two numbers
Ah, exactly, thanks for understanding my original post :) I guess
'relational database theory' is what I should start looking around
for... otherwise googling on sql, queries, etc., just returns how to
execute a query, but says nothing about how a fish works.
> In a typical SQL database, when you type in "SELECT foo FROM bar WHERE
> baz='bo'", you are not writing a program, at least not in the sense of
> Python or C or Java or Perl where you give instructions on HOW to run
> the program. You are writing a program in the sense of Lisp or Scheme
> or Haskell in that you are giving instructions on WHAT the program is.
I've gotten a strong inkling that parsing a query yields new code,
(lambdas) that are created on the fly to do the search.
> table and then start going through the process of elimination removing
> rows it doesn't want to think about. That's highly inefficient, of
Exactly what I'm trying to avoid.
> course. Instead, it transforms the query (the WHAT) into a set of
> procedures that describe HOW to get the result.
For now I'm not parsing actual text queries... my real "search query"
is coded directly in python like this:
p1 = lambda: db.search_leaf('x location', 'lte', 5)
p2 = lambda: db.search_leaf('footprint', 'eq', '0603')
p3 = lambda: db.search(db.AND, p1, p2)
p4 = lambda: db.search_leaf('x location', 'gte', 19)
p5 = lambda: db.search_leaf('footprint', 'eq', '0402')
p6 = lambda: db.search(db.AND, p1, p2)
fc = db.search(db.OR, p3, p4)
this particular example doesn't necessarily make any sense, but in
effect I'm trying to string together lambda functions which are
created explicitly for the individual query, then strung together with
> Oh, by the way, this step is nondeterministic. Why? Well, no one can
> really say what the BEST way to run any sufficiently complicated
> program is. We can point out good ways and bad ways, but not the best
> way. It's like the travelling salesman problem in a way.
The nondeterministic stuff... wow, I've come across (call/cc...),
(require...), and different variants of this, both in sicp, teach
yourself scheme, the plt docs, other places, etc., but it still eludes
me. I'm afraid that unless I understand it, I'll wind up creating
some type of cargo-cult mimcry of a database without doing it right
> programmer, will be infinitely better for it. When you understand it,
> you will really unlock the full potential of Python and Scheme and
> whatever other language is out there because you will see how to go
> from HOW languages to WHAT languages.
I'm under the impression python doesn't have the internal guts for
nondeterministic programming, specifcially that its lambdas are
limited to single-line expressions, but I may be wrong here.
Still, at the begining of the nondeterministic section of SICP
(section 4.3), it says "nondeterministic computing... is useful for
'generate and test' applications", which almost categorically sounds
like an element-by-element search for what you're looking for. This
was my initial intention behind (prematurely?) optimizing the database
by using parameter keys instead of something like [x for x in stuff if
pred(x, val)] filtering.
> Programmers who can write compilers are GOOD programmers. Programmers
> who can understand someone else's compilers are even better.
Does incorporating a search capability in an application necessarily
mean I'm writing a search compiler? That seems overkill for the
specific case, but may be true generally. For instance, if a word
processing app allows you to search for characters with a certain
font, is that incorporating a search compiler and query language? Or
is it just brute-force filtering?
> That's my semi-guru advice.
More information about the Python-list