You are looking at historical revision 34622 of this page. It may differ significantly from its current revision.

Chicken bindings to the CMU link grammar parser.

Description

The link grammar parser is a syntactic parser of English, based on link grammar, an original theory of English syntax. Given a sentence, the system assigns to it a syntactic structure, which consists of a set of labeled links connecting pairs of words. The parser also produces a "constituent" representation of a sentence (showing noun phrases, verb phrases, etc.).

Author

David Ireland

Example

(require-extension link-grammar)

(define (display-linkage sentence opts index)
  (let* ([links-found (lg:linkages-found sentence)]
         [linkage (lg:create-linkage index sentence opts)])
    (when linkage
      (begin
        (let ([constituents (lg:get-constituents linkage lg:MAX-STYLES)]
              [diagram      (lg:get-diagram linkage #t 80)])
          (print "Constituents(" index ") -> " constituents)
          (print "Diagram(" index ") -> "  diagram)
          (lg:delete-linkage linkage))))
    (when (<= index links-found)
      (display-linkage sentence opts (+ index 1)))))
 
(define (parse text dictionary opts)
  (let* ([sentence     (lg:create-sentence text dictionary)]
         [num-linkages (lg:parse-sentence sentence opts)])
    (when (= num-linkages 0)
      (begin
       (lg:set-min-null-count! opts  1)
       (lg:set-max-null-count! opts (lg:sentence-length sentence))
       (set! num-linkages (lg:parse-sentence sentence opts))))
    (display-linkage sentence opts 0)
    (lg:delete-sentence sentence)))


; Main Entry
(define dictionary (lg:create-default-dictionary))
(define opts       (lg:init-opts))

(lg:set-linkage-limit!  opts 1000)
(lg:set-short-length!   opts 10)
(lg:set-verbosity!      opts 1) 
(lg:set-max-parse-time! opts 30)
(lg:set-linkage-limit!  opts 1000)
(lg:set-min-null-count! opts 0)
(lg:set-max-null-count! opts 0)
(lg:set-short-length!   opts 16)
(lg:set-islands-ok!     opts #f)

(parse "The black fox ran from the hunters" dictionary opts)

Produces the following output:

Constituents(0) -> (S (NP the black.a fox.n)
   (VP ran.v-d
       (PP from
           (NP the hunters.n))))
Diagram(0) -> 
   +------------------------Xp------------------------+       
   +----------->WV----------->+                       |       
   +---------Wd--------+      |                       |       
   |      +----Ds**x---+      |      +----Jp----+     |       
   |      |     +---A--+--Ss--+--MVp-+   +--Dmc-+     +--RW--+
   |      |     |      |      |      |   |      |     |      |
LEFT-WALL the black.a fox.n ran.v-d from the hunters.n . RIGHT-WALL 
Constituents(1) -> (S (NP the black.a fox.n)
   (VP ran.v-d
       (PP from
           (NP the hunters.n))))
Diagram(1) -> 
   +------------------------Xp------------------------+       
   +---------Wd--------+                              |       
   |      +----Ds**x---+             +----Jp----+     |       
   |      |     +---A--+--Ss--+--MVp-+   +--Dmc-+     +--RW--+
   |      |     |      |      |      |   |      |     |      |
LEFT-WALL the black.a fox.n ran.v-d from the hunters.n . RIGHT-WALL 

API

System Information

[procedure] (lg:get-version) -> string
[procedure] (lg:get-dictionary-version dictionary*) -> string
[procedure] (lg:get-dictionary-locale) dictionary*) -> string

Dictionary

[procedure] (lg:create-default-dictionary) -> dictionary*
[procedure] (lg:create-dictionary-from-utf8 string) -> dictionary*
[procedure] (lg:create-dictionary-with-language string) -> dictionary*
[procedure] (lg:get-dictionary-language dictionary*) -> string
[procedure] (lg:get-dictionary-data-dir dictionary*) -> string
[procedure] (lg:set-dictionary-data-dir! string)
[procedure] (lg:delete-dictionary! dictionary*)

Parse Options

[procedure] (lg:init-opts parse-options* int) -> parse-options*
[procedure] (lg:set-max-parse-time! parse-options* int)
[procedure] (lg:set-linkage-limit! parse-options* int)
[procedure] (lg:set-short-length! parse-options* int)
[procedure] (lg:set-disjunct-cost! parse-options* int)
[procedure] (lg:set-min-null-count! parse-options* int)
[procedure] (lg:set-max-null-count! parse-options* int)
[procedure] (lg:set-max-parse-time! parse-options* int)
[procedure] (lg:set-islands-ok! parse-options* bool)
[procedure] (lg:set-verbosity! parse-options* int)
[procedure] (lg:get-verbosity parse-options*) -> int
[procedure] (lg:resources-exhausted? parse-options*) -> bool
[procedure] (lg:memory-exhausted? parse-options*) -> bool
[procedure] (lg:timer-expired? parse-options*) -> bool
[procedure] (lg:reset-resources! parse-options*)
[procedure] (lg:delete-parse-options! parse-options*)

Sentences

[procedure] (lg:create-sentence string dictionary*) -> sentence*
[procedure] (lg:split-sentence sentence* parse-options*) -> int
[procedure] (lg:parse-sentence sentence* parse-options*) -> int
[procedure] (lg:sentence-length sentence*) -> int
[procedure] (lg:sentence-null-count sentence*) -> int
[procedure] (lg:sentence-disjunct-cost sentence* int) -> int
[procedure] (lg:sentence-link-cost sentence* int) -> int
[procedure] (lg:linkages-found sentence*) -> int
[procedure] (lg:linkages-post-processed sentence*) -> int
[procedure] (lg:linkages-violated sentence* int) -> int
[procedure] (lg:valid-linkages sentence*) -> int
[procedure] (lg:delete-sentence! sentence*)
                       

Linkages

[procedure] (lg:create-linkage int sentence* parse-options*) -> int
[procedure] (lg:corpus-cost linkage*) -> double
[procedure] (lg:get-lword linkage* int) -> int
[procedure] (lg:get-rword linkage* int) -> int
[procedure] (lg:get-words linkage*) -> list
[procedure] (lg:get-word linkage* int) -> string
[procedure] (lg:get-constituents linkage* int) -> string
[procedure] (lg:get-diagram linkage* bool int) -> string
[procedure] (lg:get-postscript inkage* bool bool) -> string
[procedure] (lg:get-disjuncts linkage*) -> string
[procedure] (lg:get-links-domains linkage*) -> string
[procedure] (lg:get-pp-msgs linkage*) -> string
[procedure] (lg:get-senses linkage*) -> string
[procedure] (lg:get-violation-name linkage*) -> string
[procedure] (lg:link-length linkage* int) -> int
[procedure] (lg:link-label linkage* int) -> int
[procedure] (lg:link-llabel linkage* int) -> int
[procedure] (lg:link-rlabel linkage* int) -> int
[procedure] (lg:link-cost linkage*) -> int
[procedure] (lg:link-domain-names linkage* int) -> list
[procedure] (lg:num-words linkage*) -> int
[procedure] (lg:num-links linkage*) -> int
[procedure] (lg:num-domains linkage* int) -> int
[procedure] (lg:unused-word-cost linkage*) -> int
[procedure] (lg:delete-linkage linkage*)

Changelog

License

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU  Lesser General Public License as 
published by the Free Software Foundation; either version 2 of 
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without  even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, 
write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA