Changeset 34593 in project


Ignore:
Timestamp:
09/20/17 04:50:11 (4 weeks ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [140.253.78.168]:

File:
1 edited

Legend:

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

    r34592 r34593  
    1414
    1515David Ireland
     16
     17== Example
     18
     19(import link-grammar)
     20
     21<enscript highlight="scheme">
     22(define (process-linkage sentence opts)
     23  (let* ([verbosity   (lg:get-verbosity opts)]
     24         [links-found (lg:linkages-found sentence)]
     25         [max-links   1024]
     26         [index       0])
     27    (print "Verbosity: " verbosity)
     28    (print "Links found: " links-found)
     29
     30    (define (display-linkage sentence opts index)
     31      (let* ([linkage     (lg:create-linkage index sentence opts)])
     32             (when linkage
     33               (begin
     34                 (let ([constituents (lg:get-constituents linkage lg:MAX-STYLES)]
     35                       [diagram      (lg:get-diagram linkage #t 80)])
     36                 (print "Constituents(" index ") -> " constituents)
     37                 (print "Diagram(" index ") -> "  diagram)
     38                 (lg:delete-linkage linkage))))
     39             (when (<= index links-found)
     40               (display-linkage sentence opts (+ index 1)))))
     41    (display-linkage sentence opts 0)))
     42
     43(define (parse text dictionary opts)
     44  (let* ([sentence     (lg:create-sentence text dictionary)]
     45         [num-linkages (lg:parse-sentence sentence opts)])
     46    (when (= num-linkages 0)
     47      (begin
     48       (lg:set-min-null-count! opts  1)
     49       (lg:set-max-null-count! opts (lg:sentence-length sentence))
     50       (set! num-linkages (lg:parse-sentence sentence opts))))
     51    (process-linkage sentence opts)))
     52
     53(define dictionary (lg:create-default-dictionary))
     54(define opts       (lg:init-opts))
     55(lg:set-linkage-limit!  opts 1000)
     56(lg:set-short-length!   opts 10)
     57(lg:set-verbosity!      opts 1)
     58(lg:set-max-parse-time! opts 30)
     59(lg:set-linkage-limit!  opts 1000)
     60(lg:set-min-null-count! opts 0)
     61(lg:set-max-null-count! opts 0)
     62(lg:set-short-length!   opts 16)
     63(lg:set-islands-ok!     opts #f)
     64
     65(parse "Terry wrote Principia" dictionary opts)
     66</enscript>
     67
    1668
    1769== API
Note: See TracChangeset for help on using the changeset viewer.