Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Graham Cooper

Posts: 4,333
Registered: 5/20/10
Re: >>>BLoCK PROLOG 1st QUERY<<<
Posted: Feb 9, 2013 1:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.