Book in question
Prolog and Natural-Language Analysis by Fernando C. N. Pereira and Stuart M. Shieber (PDF)
Notes on Semantic Nets and Frames
http://www.eecs.qmul.ac.uk/~mmh/AINotes/AINotes4.pdf

Review

This book has been interesting so far.

On reading the 1st chapter, I discovered how to build Semantic Networks in prolog.

On reading the 2nd chapter I realised I would like to make a NL parser in prolog. It would a fast way to explore building my own programmatic (as opposed to transformer-based) NL parser.

writing this blog article

Extend emacs to do write prolog more easily

  • Automate the writing of:
    • axioms
    • facts
  • Fuzzy search to build new rules
    • Construct the database

Build a prolog database system in emacs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
professor(terry).
professor(roger).
professor(bertrand).
professor(gottlob).

concerns(shrdlu, blocks).
concerns(lunar, rocks).
concerns(sam, stories).

concerns(principia, logic).
concerns(principia, mathematics).
concerns(begriffsschrift, logic).

Learn the built in functions first

remember

kb f
M-e prolog-end-of-clause nil
M-a prolog-beginning-of-clause nil

Rebind these

  • prolog-consult-region
  • prolog-consult-file
  • prolog-consult-file
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
C-c C-z         run-prolog
C-c C-d         prolog-debug-on
C-c C-n         prolog-insert-predicate-template
C-c C-p         prolog-consult-predicate
C-c C-r         prolog-consult-region
C-c C-s         prolog-insert-predspec
C-c C-t         prolog-trace-on
C-c C-c b       prolog-compile-buffer
C-c C-c f       prolog-compile-file
C-c C-c p       prolog-compile-predicate
C-c C-c r       prolog-compile-region
C-c C-v C-s     prolog-view-predspec
C-c C-v a       prolog-variables-to-anonymous
kb f
C-c C-b prolog-consult-buffer nil

new unit clauses

new relation/clause (wrote)

1
wrote(roger, sam).

new facts

1
program(lunar).

Create rules

1
author(Person) :- book(Book), wrote(Person, Book).

query

yes/no (provable) queries

1
:- wrote(terry, shrdlu).
1
:- program(principia).

Search queries (variable/wildcard)

:- wrote(Who,shrdlu).

Make some upgrades to my Prolog environment

 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
(require 'ob-prolog)

;; Also see my-perl.el

;; TODO Start by making functions for constructing prolog databases

;; =atomic formula= wrote(X,Y)
;; wrote(roger, sam). -> wrote
(defun pro-get-relation-names ()
  (snc "sed -n 's/\\b\\([a-z]\\+\\)([a-z]\\+, \\?[a-z]\\+).*/\\1/p'" (buffer-string)))

;; Permute the atomic formulae with wildcards for querying


;; =base clause=, which represents a simple fact
(defun pro-get-base-clause-names ()
  (snc "sed -n 's/\\b\\([a-z]\\+\\)([a-z]\\+).*/\\1/p'" (buffer-string)))

(define-key prolog-mode-map (kbd "M-o b") 'prolog-consult-buffer)
(define-key prolog-mode-map (kbd "M-o f") 'prolog-consult-file)
(define-key prolog-mode-map (kbd "M-o r") 'prolog-consult-region)
(define-key prolog-mode-map (kbd "M-o M-d") 'prolog-debug-on)
(define-key prolog-mode-map (kbd "M-o M-n") 'prolog-insert-predicate-template)

(provide 'my-prolog)