1. link grammar
    1. Description
    2. Project / Source Code Repository
    3. Maintainer
  2. Example
  3. API
    1. System Information
    2. Constants
      1. Displaying Constituents
      2. Error Handling
    3. Dictionary
    4. Parse Options
    5. Sentences
    6. Linkages
  4. Changelog
  5. License

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.).

Project / Source Code Repository

https://gitlab.com/maxwell79/chicken-link-grammar

Maintainer

David Ireland (djireland79 at gmail dot com)

Example

(use (prefix link-grammar :lg))

(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)
          (print 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)
(lg:delete-parse-options! opts)
(lg:delete-dictionary! dictionary)

Produces the following output:

(S (NP the black.a fox.n)
   (VP ran.v-d
       (PP from
           (NP the hunters.n))))
   +------------------------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 
(S (NP the black.a fox.n)
   (VP ran.v-d
       (PP from
           (NP the hunters.n))))

   +------------------------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] (get-version) -> string
[procedure] (get-dictionary-version dictionary*) -> string
[procedure] (get-dictionary-locale) dictionary*) -> string

Constants

Displaying Constituents

[constant] NO-DISPLAY
[constant] NO-MULTI-LINE
[constant] NO-BRACKET-TREE
[constant] NO-SINGLE-LINE
[constant] NO-MAX-STYLES

Error Handling

[constant] FATAL
[constant] ERROR
[constant] WARN
[constant] INFO
[constant] DEBUG
[constant] TRACE
[constant] NONE

Dictionary

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

Parse Options

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

Sentences

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

Linkages

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