Re: [racket-users] Datalog questions

2015-09-17 Thread Eduardo Bellani

Hello Jay, thanks for your time.

I'll try the update asap. One question to anyone, what would the the
canonical way of fetching such an update in racket's package system?



Jay McCarthy writes:

> On Wed, Sep 16, 2015 at 2:50 PM, Eduardo Bellani <ebell...@gmail.com> wrote:
>> Hello list
>>
>> I'm trying to use racket's implementation of datalog as a query language
>> for a small database (5 gb). I'm running into some problems that I'd
>> appreciate your help with:
>>
>> * Is there support for negating a subgoal? E.g: [1]
>>
>>  Get the names of employees who do not work on any project.
>>  temp1(S) :- works_on(S,_,_).
>>  answer(F,M,L) :- employee(F,M,L,S,_,_,_,_,_,_), not temp1(S).
>
> No, but I have no objection to someone adding this. I believe it will
> require a different evaluation technique (bottom-up vs the present
> top-down) to run efficiently.
>
>> * Is there support for other comparison operators outside {=, !=}? E.g.
>>
>> (datalog *db*
>>  ;; shareholders
>>  (! (shareholder "Jorge"person))
>>  (! (shareholder "Bob"  person))
>>  (! (shareholder "Googly"   company))
>>  (! (shareholder "Megasoft" company))
>>  ;; ownership
>>  (! (owns-a-share "Jorge"  "Construction SA" 60.8))
>>  (! (owns-a-share "Bob""Construction SA" 39.2))
>>  (! (owns-a-share "Bob""WAKA SA" 100 ))
>>  (! (owns-a-share "Googly" "Toys SA" 100 )))
>>
>>
>> (let ((majority? (λ (percent)
>>(> percent 50
>>   (datalog *db*
>>(! (:- (major-stockholder COMPANY)
>>   (shareholder SHAREHOLDER person)
>>   (owns-a-share SHAREHOLDER COMPANY PERCENT)
>>   (majority? PERCENT :- TEMP)
>>   (= TEMP true)
>
> You could write (majority? PERCENT :- #t)
>
> Here's a tiny example
>
> #lang racket/base
> (require datalog)
>
> (datalog (make-theory)
>  (! (number 0))
>  (! (number 1))
>  (! (number 2))
>  (! (number 3))
>  (! (:- (awesome N)
> (number N)
> (even? N :- #t)))
>  (? (awesome N)))
>
>> * A syntax extension difficulty, not very much related to datalog per
>>   se. I have this syntax extension:
>>
>>
>> (define-syntax (->relations stx)
>>   ;; point here being getting true relations (sets) out of the results
>>   (syntax-case stx ()
>> [(_ rel-name rel-size)
>>  (with-syntax ([rel-vars (for/list ([x (in-range (syntax->datum 
>> #'rel-size))])
>>(gensym 'X))])
>>#`(map (λ (dic)
>> (list->set
>>  (map (λ (rel-var)
>> (hash-ref dic rel-var))
>>   #'rel-vars)))
>>   (datalog *db* (? (#,#'rel-name
>> #,@#'rel-vars)]))
>>
>> This is an case of an usage, in the context of the previous example:
>>
>> (->relations major-stockholder 1)
>>
>> I'm bumping in the following error:
>>
>> make-variable: contract violation
>>   expected: (or/c #f (list/c any/c (or/c exact-positive-integer? #f) (or/c 
>> exact-nonnegative-integer? #f) (or/c exact-nonnegative-integer? #f) (or/c 
>> exact-positive-integer? #f)))
>>   given: '(#f #f #f #f 0)
>>   in: the 1st argument of
>>   (->
>>(or/c
>> #f
>> (list/c
>>  any/c
>>  (or/c exact-positive-integer? #f)
>>  (or/c exact-nonnegative-integer? #f)
>>  (or/c exact-nonnegative-integer? #f)
>>  (or/c exact-positive-integer? #f)))
>>symbol?
>>variable?)
>>   contract from: /datalog/ast.rkt
>>
>> Which I interpreted as the LOC being lost in the syntax generator. I
>> haven't being able to resolve that yet. Any light on the subject?
>
> This is an error on my part. It should be POS NONNEG POS NONNEG but I
> wrote POS NONNEG NONNEG POS. I just did a push, let me know if that
> fixes it (or you could just change it on your own copy.)
>
> Jay
>
>> Thanks in advance for any pointers.
>>
>> [1] http://tinman.cs.gsu.edu/~raj/8710/f05/datalog.pdf
>>
>> --
>> Eduardo Bellani
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

--
Eduardo Bellani

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


Re: [racket-users] Datalog questions

2015-09-17 Thread Eduardo Bellani

Hello Jay,

Thanks, I've figured out the raco incantation beforehand. I should've
read more about the docs before asking.

One other question that slipped my mind before, about wildcards. Let's
take this example again:


 (define *db* (make-theory))

 (datalog *db*
  ;; shareholders
  (! (shareholder "Jorge"person))
  (! (shareholder "Bob"  person))
  (! (shareholder "Googly"   company))
  (! (shareholder "Megasoft" company))
  ;; ownership
  (! (owns-a-share "Jorge"  "Construction SA" 60.8))
  (! (owns-a-share "Bob""Construction SA" 39.2))
  (! (owns-a-share "Bob""WAKA SA" 100 ))
  (! (owns-a-share "Googly" "Toys SA" 100 )))


 (let ((majority? (λ (percent)
(> percent 50
   (datalog *db*
(! (:- (major-stockholder COMPANY)
   (shareholder SHAREHOLDER _) ;; <- I don't care about this 
attribute
   (owns-a-share SHAREHOLDER COMPANY PERCENT)
   (majority? PERCENT :- #t)

This is throwing this error:

 _: wildcard not allowed as an expression

Any idea of what I'm doing wrong?

Thanks again.

Jay McCarthy writes:

> I would do "raco pkg update --clone datalog" from "$PLTHOME/extra-pkgs"
>
> Jay
>
> On Thu, Sep 17, 2015 at 2:05 PM, Eduardo Bellani <ebell...@gmail.com> wrote:
>>
>> Hello Jay, thanks for your time.
>>
>> I'll try the update asap. One question to anyone, what would the the
>> canonical way of fetching such an update in racket's package system?
>>
>>
>>
>> Jay McCarthy writes:
>>
>>> On Wed, Sep 16, 2015 at 2:50 PM, Eduardo Bellani <ebell...@gmail.com> wrote:
>>>> Hello list
>>>>
>>>> I'm trying to use racket's implementation of datalog as a query language
>>>> for a small database (5 gb). I'm running into some problems that I'd
>>>> appreciate your help with:
>>>>
>>>> * Is there support for negating a subgoal? E.g: [1]
>>>>
>>>>  Get the names of employees who do not work on any project.
>>>>  temp1(S) :- works_on(S,_,_).
>>>>  answer(F,M,L) :- employee(F,M,L,S,_,_,_,_,_,_), not temp1(S).
>>>
>>> No, but I have no objection to someone adding this. I believe it will
>>> require a different evaluation technique (bottom-up vs the present
>>> top-down) to run efficiently.
>>>
>>>> * Is there support for other comparison operators outside {=, !=}? E.g.
>>>>
>>>> (datalog *db*
>>>>  ;; shareholders
>>>>  (! (shareholder "Jorge"person))
>>>>  (! (shareholder "Bob"  person))
>>>>  (! (shareholder "Googly"   company))
>>>>  (! (shareholder "Megasoft" company))
>>>>  ;; ownership
>>>>  (! (owns-a-share "Jorge"  "Construction SA" 60.8))
>>>>  (! (owns-a-share "Bob""Construction SA" 39.2))
>>>>  (! (owns-a-share "Bob""WAKA SA" 100 ))
>>>>  (! (owns-a-share "Googly" "Toys SA" 100 )))
>>>>
>>>>
>>>> (let ((majority? (λ (percent)
>>>>(> percent 50
>>>>   (datalog *db*
>>>>(! (:- (major-stockholder COMPANY)
>>>>   (shareholder SHAREHOLDER person)
>>>>   (owns-a-share SHAREHOLDER COMPANY PERCENT)
>>>>   (majority? PERCENT :- TEMP)
>>>>   (= TEMP true)
>>>
>>> You could write (majority? PERCENT :- #t)
>>>
>>> Here's a tiny example
>>>
>>> #lang racket/base
>>> (require datalog)
>>>
>>> (datalog (make-theory)
>>>  (! (number 0))
>>>  (! (number 1))
>>>  (! (number 2))
>>>  (! (number 3))
>>>  (! (:- (awesome N)
>>> (number N)
>>> (even? N :- #t)))
>>>  (? (awesome N)))
>>>
>>>> * A syntax extension difficulty, not very much related to datalog per
>>>>   se. I have this syntax extension:
>>>>
>>>>
>>>> (define-syntax (->relations stx)
>>>>   ;; point here being getting true relatio

[racket-users] Datalog questions

2015-09-16 Thread Eduardo Bellani
Hello list

I'm trying to use racket's implementation of datalog as a query language
for a small database (5 gb). I'm running into some problems that I'd
appreciate your help with:

* Is there support for negating a subgoal? E.g: [1]

 Get the names of employees who do not work on any project.
 temp1(S) :- works_on(S,_,_).
 answer(F,M,L) :- employee(F,M,L,S,_,_,_,_,_,_), not temp1(S).

* Is there support for other comparison operators outside {=, !=}? E.g.

(datalog *db*
 ;; shareholders
 (! (shareholder "Jorge"person))
 (! (shareholder "Bob"  person))
 (! (shareholder "Googly"   company))
 (! (shareholder "Megasoft" company))
 ;; ownership
 (! (owns-a-share "Jorge"  "Construction SA" 60.8))
 (! (owns-a-share "Bob""Construction SA" 39.2))
 (! (owns-a-share "Bob""WAKA SA" 100 ))
 (! (owns-a-share "Googly" "Toys SA" 100 )))


(let ((majority? (λ (percent)
   (> percent 50
  (datalog *db*
   (! (:- (major-stockholder COMPANY)
  (shareholder SHAREHOLDER person)
  (owns-a-share SHAREHOLDER COMPANY PERCENT)
  (majority? PERCENT :- TEMP)
  (= TEMP true)

* A syntax extension difficulty, not very much related to datalog per
  se. I have this syntax extension:


(define-syntax (->relations stx)
  ;; point here being getting true relations (sets) out of the results
  (syntax-case stx ()
[(_ rel-name rel-size)
 (with-syntax ([rel-vars (for/list ([x (in-range (syntax->datum 
#'rel-size))])
   (gensym 'X))])
   #`(map (λ (dic)
(list->set
 (map (λ (rel-var)
(hash-ref dic rel-var))
  #'rel-vars)))
  (datalog *db* (? (#,#'rel-name
#,@#'rel-vars)]))

This is an case of an usage, in the context of the previous example:

(->relations major-stockholder 1)

I'm bumping in the following error:

make-variable: contract violation
  expected: (or/c #f (list/c any/c (or/c exact-positive-integer? #f) (or/c 
exact-nonnegative-integer? #f) (or/c exact-nonnegative-integer? #f) (or/c 
exact-positive-integer? #f)))
  given: '(#f #f #f #f 0)
  in: the 1st argument of
  (->
   (or/c
#f
(list/c
 any/c
 (or/c exact-positive-integer? #f)
 (or/c exact-nonnegative-integer? #f)
 (or/c exact-nonnegative-integer? #f)
 (or/c exact-positive-integer? #f)))
   symbol?
   variable?)
  contract from: /datalog/ast.rkt

Which I interpreted as the LOC being lost in the syntax generator. I
haven't being able to resolve that yet. Any light on the subject?

Thanks in advance for any pointers.

[1] http://tinman.cs.gsu.edu/~raj/8710/f05/datalog.pdf

--
Eduardo Bellani

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature