Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: >>>BLoCK PROLOG 1st QUERY<<<
Posted:
Feb 9, 2013 1:14 AM
|
|
On Feb 9, 1:18 pm, Graham Cooper <grahamcoop...@gmail.com> wrote: > QUERY: f [a [b d]] ? > > > > > TABLE QUERY > > ref term buds > > 1 f 0 > > 21 a 0 > > 221 b 0 <------- > > 222 d 0 <------- > > 1 * 0 > > 21 * 0 > > 2 * 2 > > 221 * 0 > > 22 * 1 <-------- > > 222 * 0 > > Simple explanation! > > If b and d don't get matched > you can still match Position 22 to a VAR instead > and subtract 1 from the expected matched terms! >
In this example:
f [ a [ b d ]] ? 4 TERM QUERY
| | |
f a D 2 TERM + 1 VAR = 3 MATCHING ROWS
so this SQL clause finds all Predicates with matching terms (all in the right position)
QUERY.ref=HEADS.ref AND QUERY.term=HEADS.term GROUP BY HID HAVING COUNT(HID)=$qc-SUM(QB)";
and COUNT(HEAD.ID) = 3 QC = Query Term Count = 4
SUM(BUDS) = 1
So 4-1 = 3 records found!
So it should return this Predicate in the Results.
QUERY: f [a [b d]] 4 - 1 bud RESULT: f a D 3
EASY!
All that's left is Variable Binding and Tail Recursion..
Herc -- www.BLoCKPROLOG.com
|
|
|
|