Skip to content

Commit

Permalink
Print most frequent words first
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Jun 8, 2018
1 parent 7a55e7e commit 68d1671
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions opencog/nlp/learn/learn-lang-diary/word-classes/word-classes.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
(cog-get-atoms 'WordClassNode)))

; Print the members of one class.
; Print most frequent words first.
(define (prt-members-of-class CLS)
(define membs (cog-incoming-by-type CLS 'MemberLink))
(define words (map gar membs))
(define words-by-freq
(sort! words
(lambda (WRD-A WRD-B) (> (get-count WRD-A) (get-count WRD-B)))))
(format #t "Class <~A> has ~A members:\n "
(cog-name CLS) (length membs))
(cog-name CLS) (length words-by-freq))
(for-each
(lambda (memb)
(format #t "~A " (cog-name (gar memb))))
membs)
(lambda (wrd)
(format #t "~A " (cog-name wrd)))
words-by-freq)
(newline))

; Print all classes and members
Expand All @@ -42,6 +47,8 @@
(define by-size
(sort! all-classes
(lambda (CLS-A CLS-B) (> (nmemb CLS-A) (nmemb CLS-B)))))
(format #t "There are ~A words placed into ~A classes\n"
(num-classified-words) (cog-count-atoms 'WordClassNode))
(for-each prt-members-of-class by-size))

; Print distribution, viz, Some statistic, vs. the class.
Expand Down

0 comments on commit 68d1671

Please sign in to comment.