Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: >>>BLoCK PROLOG 1st QUERY<<<
Replies: 2   Last Post: Feb 9, 2013 1:14 AM

 Messages: [ Previous | Next ]
 Graham Cooper Posts: 4,421 Registered: 5/20/10
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)

GROUP BY HID HAVING COUNT(HID)=\$qc-SUM(QB)";

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

Date Subject Author
2/8/13 Graham Cooper
2/8/13 Graham Cooper
2/9/13 Graham Cooper