-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparse-disjuncts.scm
51 lines (46 loc) · 1.92 KB
/
parse-disjuncts.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;
; parse-disjuncts.scm -- Demo of getting the disjuncts used in a parse.
;
; The Link Grammar parser will parse natural language sentences,
; returning a dependency graph of how the words are connected.
; The Atomese API for the LG parser converts that graph into
; Atomese format. This format is quite verbose, and some applications
; do not need the full parse information. This demo illustrates how
; to get the disjuncts, only, without the rest of the parse info.
; -----------------------------------------------------------------
; Load the guile modules
(use-modules (opencog) (opencog exec))
(use-modules (opencog nlp) (opencog nlp lg-parse))
; Parse an example sentence
(cog-execute!
(LgParseDisjuncts ; There is also a "full" parse, demoed elsewhere.
(PhraseNode "this is a test.") ; The example sentence
(LgDictNode "en") ; The dictionary to use - English in this case.
(NumberNode 1))) ; The number of parses to perform.
; To see the parse in it's full glory, it's easiest to just print
; the entire contents of the AtomSpace.
(cog-prt-atomspace)
; One of the disjuncts will look like this:
;
; (LgDisjunct (ctv 1 0 1)
; (WordNode "this")
; (LgAnd
; (LgConnector
; (LgConnNode "Wd")
; (LgConnDirNode "-"))
; (LgConnector
; (LgConnNode "Ss*b")
; (LgConnDirNode "+"))))
;
; which says that the word `this` had the disjunct `Wd- & Ss*b+` on it.
; Note that the CountTruthValue on `LgDisjunct` has been set to 1.0.
; If the parse is re-run, the count will increment by one. If more
; than one parse is requested, then the counts will reflect the number
; of times a given disjunct was used in all of the parses.
;
; Note that this format does NOT include any info about which
; word-instance this was in the sentence, nor which words the
; connectors connected to. That info is available by using the
; `LgParseLink` parser.
; ---------------------
; That's all, folks!