Changeset 35279 in project


Ignore:
Timestamp:
03/12/18 05:40:54 (5 months ago)
Author:
djireland
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/semantics

    r35278 r35279  
    1 === Test
     1== semantics
     2
     3Semantics using Link-Grammar Library
     4[[toc:]]
     5=== Heading Here
     6Text goes here
     7
     8
     9==== {{semantics}}
     10'''[module]''' {{semantics}}
     11
     12Semantics Module
     13* [[#remove-tags]]
     14* [[#remove-square-brackets]]
     15* [[#split-word-tags]]
     16* [[#test]]
     17* [[#utterance->links]]
     18* [[#utterance->logic]]
     19* [[#links->words]]
     20* [[#is-utterance-interrogative?]]
     21* [[#has-link?]]
     22* [[#has-word?]]
     23* [[#join-links]]
     24* [[#link-has-arg?]]
     25* [[#extract-word]]
     26* [[#extract-links]]
     27* [[#extract-using-types]]
     28* [[#process-main-verb]]
     29* [[#find-main-verb]]
     30* [[#find-object]]
     31* [[#find-subject]]
     32* [[#find-link-with-types]]
     33* [[#query/2]]
     34* [[#query/1]]
     35* [[#rule/2]]
     36* [[#fact]]
     37==== {{remove-square-brackets}}
     38<procedure>(remove-square-brackets in) → string</procedure>
     39Removes any characters between and including the square brackets [..].
     40
     41First occurance only
     42; {{in}} : Input string
     43<enscript highlight="scheme">(define (remove-square-brackets in) (string-substitute "\\[.*\\]" "" in))
     44</enscript>
     45===== Examples
     46Example 1.
     47 (remove-square-brackets "Thee[?].a")
     48  => "Thee.a"
     49 
     50Example 2.
     51 (remove-square-brackets "firetruck[!].n")
     52  => "firetruck.n"
     53 
     54Example 2.
     55 (remove-square-brackets "red.a")
     56  => "red.a"
     57 
     58==== {{split-word-tags}}
     59<procedure>(split-word-tags in) → string</procedure>
     60Handles words and their tags e.g. 'cat.n' and returns a pair.
     61
     62If no tag is present
     63
     64 is set as the second of the pair.
     65; {{in}} : The string to be split
     66<enscript highlight="scheme">(define (split-word-tags in)
     67  (let* ((val (s-split "." in)) (len (length val)))
     68    (if (> len 1) (cons (car val) (cadr val)) (cons (car val) "-"))))
     69</enscript>
     70===== Examples
     71Example 1.
     72 (split-word-tags "cat.n")
     73  => ("cat" . "n")
     74 
     75Example 2.
     76 (split-word-tags "the")
     77  => ("the" . "-")
     78 
     79==== {{remove-tags}}
     80<procedure>(remove-tags words) → list</procedure>
     81Removes words that have been tagged.
     82; {{words}} : The list of words with tags
     83<enscript highlight="scheme">(define (remove-tags words) (map (lambda (x) (car (s-split "." x))) words))
     84</enscript>
     85===== Examples
     86Example:
     87 (remove-tags
     88  '("LEFT-WALL" "all.a" "humans.n" "are.v" "mortal.a" "RIGHT-WALL"))
     89  => ("LEFT-WALL" "all" "humans" "are" "mortal" "RIGHT-WALL")
     90 
     91==== {{has-word?}}
     92<procedure>(has-word? words word) → boolean</procedure>
     93Checks if word exists in word list.
     94; {{words}} : The list of words with tags
     95; {{word}} : The word to match (string)
     96<enscript highlight="scheme">(define (has-word? words word)
     97  (not (null? (filter (lambda (x) (string=? x word)) (remove-tags words)))))
     98</enscript>
     99===== Examples
     100Example:
     101 (has-word? '("LEFT-WALL" "all.a" "humans.n" "are.v" "mortal.a" "RIGHT-WALL")
     102            "are")
     103  => #t
     104 
     105==== {{extract-links}}
     106<procedure>(extract-links links link) → list</procedure>
     107Extracts a specific link from a list of links
     108; {{links}} : List of links
     109; {{link}} : Link name to extract (string)
     110<enscript highlight="scheme">(define (extract-links links link)
     111  (filter (lambda (y) (equal? link (caar y))) links))
     112</enscript>
     113===== Examples
     114Example using 'All humans are mortal'
     115 (extract-links
     116  '((("RW" . "") (0 . "-") (5 . "-"))  (("WV" . "") (0 . "-") (3 . "v"))
     117     (("W" . "d") (0 . "-") (2 . "n"))  (("S" . "px") (2 . "n") (3 . "v"))
     118     (("D" . "mc") (1 . "a") (2 . "n")) (("P" . "a") (3 . "v") (4 . "a")))
     119  "RW")
     120  => ((("RW" . "") (0 . "-") (5 . "-")))
     121 
     122==== {{extract-using-types}}
     123<procedure>(extract-using-types links types) → list</procedure>
     124Extracts a specific link based on word types
     125; {{links}} : List of links
     126; {{link}} : List of word types to extract
     127<enscript highlight="scheme">(define (extract-using-types links types)
     128  (filter
     129    (lambda (x) (member (cdr x) types))
     130    (cdr-or (list) (delete-duplicates links equal?))))
     131</enscript>
     132===== Examples
     133Example using 'All humans are mortal'
     134 (extract-using-types '((0 . "-") (1 . "v") (2 . "a") (5 . "-")) '("-" "a"))
     135  => ((2 . "a") (5 . "-"))
     136 
     137=== About this egg
     138
     139==== Author
     140
     141[[/users/(anonymous)|David Ireland]]
     142
     143==== License
     144BSD
     145
     146
     147==== Colophon
     148
     149Documented by [[/egg/hahn|hahn]].
Note: See TracChangeset for help on using the changeset viewer.