Changeset 34614 in project


Ignore:
Timestamp:
09/20/17 07:30:27 (4 weeks ago)
Author:
djireland
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/link-grammar

    r34613 r34614  
    1919
    2020<enscript highlight="scheme">
    21 (import link-grammar)
     21(require-extension link-grammar)
    2222
    23 (define (process-linkage sentence opts)
     23(define (display-linkage sentence opts index)
     24  (let* ([links-found (lg:linkages-found sentence)]
     25         [linkage (lg:create-linkage index sentence opts)])
     26    (when linkage
     27      (begin
     28        (let ([constituents (lg:get-constituents linkage lg:MAX-STYLES)]
     29              [diagram      (lg:get-diagram linkage #t 80)])
     30          (print "Constituents(" index ") -> " constituents)
     31          (print "Diagram(" index ") -> "  diagram)
     32          (lg:delete-linkage linkage))))
     33    (when (<= index links-found)
     34      (display-linkage sentence opts (+ index 1)))))
     35 
     36(define (process-links sentence opts)
    2437  (let* ([verbosity   (lg:get-verbosity opts)]
    2538         [links-found (lg:linkages-found sentence)]
    2639         [max-links   1024]
    2740         [index       0])
    28     (print "Verbosity: " verbosity)
    29     (print "Links found: " links-found)
    30 
    31     (define (display-linkage sentence opts index)
    32       (let* ([linkage     (lg:create-linkage index sentence opts)])
    33              (when linkage
    34                (begin
    35                  (let ([constituents (lg:get-constituents linkage lg:MAX-STYLES)]
    36                        [diagram      (lg:get-diagram linkage #t 80)])
    37                  (print "Constituents(" index ") -> " constituents)
    38                  (print "Diagram(" index ") -> "  diagram)
    39                  (lg:delete-linkage linkage))))
    40              (when (<= index links-found)
    41                (display-linkage sentence opts (+ index 1)))))
    4241    (display-linkage sentence opts 0)))
    43 
     42 
    4443(define (parse text dictionary opts)
    4544  (let* ([sentence     (lg:create-sentence text dictionary)]
     
    5049       (lg:set-max-null-count! opts (lg:sentence-length sentence))
    5150       (set! num-linkages (lg:parse-sentence sentence opts))))
    52     (process-linkage sentence opts)))
     51    (process-links sentence opts)))
    5352
     53; Main Entry
    5454(define dictionary (lg:create-default-dictionary))
    5555(define opts       (lg:init-opts))
    5656(lg:set-linkage-limit!  opts 1000)
    5757(lg:set-short-length!   opts 10)
    58 (lg:set-verbosity!      opts 1)
     58(lg:set-verbosity!      opts 1) 
    5959(lg:set-max-parse-time! opts 30)
    6060(lg:set-linkage-limit!  opts 1000)
     
    6464(lg:set-islands-ok!     opts #f)
    6565
    66 (parse "The black fox ran from the hunters." opts)
     66(parse "The black fox ran from the hunters." dictionary opts)
    6767</enscript>
    6868
    69 <text>
     69
    7070Produces the following output:
    7171
     
    9292LEFT-WALL the black.a fox.n ran.v-d from the hunters.n . RIGHT-WALL
    9393
    94 </text>
    9594
    9695== API
Note: See TracChangeset for help on using the changeset viewer.