;;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10 -*- ;;;; --------------------------------------------------------------------------- ;;;; File name: wfb-africa-extractor.lsp ;;;; System: ;;;; Author: Praveen Paritosh ;;;; Created: February 8, 2004 16:19:20 ;;;; Purpose: ;;;; --------------------------------------------------------------------------- ;;;; Modified: Sunday, February 8, 2004 at 20:20:01 by paritosh ;;;; --------------------------------------------------------------------------- (in-package :common-lisp-user) ;; WFB Africa Extraction (defparameter *wfb-cyc-name-mappings* ;; This was partly done by hand. '((algeria . Algeria) (angola . Angola) (benin . Benin) (botswana . Botswana) (burkina . BurkinaFaso) (burundi . Burundi) (cameroon . Cameroon) (cape_verde . CapeVerde) (central_african_republic . CentralAfricanRepublic) (chad . Chad) (comoros . Comoros-TheNation) (congo . Congo-Brazzaville) (|Cote d'Ivoire| . IvoryCoast) (djibouti . Djibouti) (egypt . Egypt) (equatorial_guinea . EquatorialGuinea) (eritrea . Eritrea) (ethiopia . Ethiopia) (gabon . Gabon) (the_gambia . Gambia) (ghana . Ghana) (guinea . Guinea) (guinea-bissau . Guinea-Bissau) (kenya . Kenya) (lesotho . Lesotho) (liberia . Liberia) (libya . Libya) (madagascar . Madagascar) (malawi . Malawi) (mali . Mali) (mauritania . Mauritania) (mauritius . Mauritius) (morocco . Morocco) (mozambique . Mozambique) (namibia . Namibia) (niger . Niger) (nigeria . Nigeria) (rwanda . Rwanda) (sao_tome_and_principe . SaoTome-Island) (senegal . Senegal) (seychelles . Seychelles) (sierra_leone . SierraLeone) (somalia . Somalia) (south_africa . SouthAfrica) (sudan . Sudan) (swaziland . Swaziland) (tanzania . Tanzania) (togo . Togo) (tunisia . Tunisia) (uganda . Uganda) (western_sahara . WesternSahara) (zaire . Congo-Kinshasa) (zambia . Zambia) (zimbabwe . Zimbabwe))) ;; Lets go get facts from both sources WFB and Cyc on all of these countries and cache them (defun gather-wfb-facts-for-country (country &optional (wfb-facts *wfb-facts*)) ;; In a WFB-Fact, for each fact, the country that it refers to is in the second position (let (country-facts) (dolist (fact wfb-facts) (if (eql (second fact) country) (push fact country-facts))) (values (nreverse country-facts)))) ;; Extract facts from KB for country (defun gather-cyc-facts-for-country (country &optional (kb fire::*kb*)) ;; The simplest: retrieve-references (fire::retrieve-references country)) ;; Cache these extracted facts. These are stored in a very simple ;; format. ( ) and the country name ;; depends upon the source from where the knowledge came. (defparameter *cyc-africa-cache* "D:\\qrg\\fire\\v1\\carve\\data\\countrydata\\africa_cyc.lsp") (defparameter *wfb-africa-cache* "D:\\qrg\\fire\\v1\\carve\\data\\countrydata\\africa_wfb.lsp") (defun gather-and-cache-africa-from-cyc (&optional (wfb-cyc-mappings *wfb-cyc-name-mappings*) (kb fire::*kb*)) (dolist (country-pair wfb-cyc-mappings) (let ((facts (gather-cyc-facts-for-country (cdr country-pair) kb))) (format t "Extracted facts for ~A. ~A facts" (cdr country-pair) (length facts)) (save-facts (cdr country-pair) facts *cyc-africa-cache*)))) (defun gather-and-cache-africa-from-wfb (&optional (wfb-cyc-mappings *wfb-cyc-name-mappings*) (wfb-facts *wfb-facts*)) (dolist (country-pair wfb-cyc-mappings) (let ((facts (gather-wfb-facts-for-country (car country-pair) wfb-facts))) (format t "Extracted facts for ~A. ~A facts~%" (car country-pair) (length facts)) (save-facts (car country-pair) facts *wfb-africa-cache*)))) (defun save-facts (country facts file-name &key (if-exists :append) (kb fire::*kb*)) "Dump case to a flat file to in a format amenable to re-loading" (with-open-file (fout file-name :direction :output :if-exists if-exists :if-does-not-exist :create) (format fout "(~A ~%" country) (pprint facts fout) (format fout ")~%") (terpri fout) (finish-output fout))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; End of Code