;;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10 -*- ;;;; --------------------------------------------------------------------------- ;;;; File name: ksl-to-cyc.lsp ;;;; System: Carve ;;;; Author: Praveen Paritosh ;;;; Created: January 26, 2004 15:45:00 ;;;; Purpose: To translate from Stanford CIA Factbook KB to Cyc ;;;; --------------------------------------------------------------------------- ;;;; Modified: Tuesday, February 3, 2004 at 16:59:35 by paritosh ;;;; --------------------------------------------------------------------------- (in-package :fire) ;; Goal : To Enrich and make uniform the country cases. ;; Extract facts from the Stanford WFB, rewrite in CycL and add to the KB ;; These facts will go in enriching the cases for experimenting with Carve (defun *wfb-filters* '(birth-rate-fact?)) ;; *** Stuff added monday 02/02/04 (defun gather-countries (&optional (facts data::*wfb-facts*)) (let (countries) (dolist (fact facts) (if (population-fact? fact) (push (second fact) countries))) (reverse countries))) ;; *** End of stuff added monday 02/02/04 (defun gather-facts (&optional (facts data::*wfb-facts*)) (let (gathered-facts) (dolist (fact facts) (cond ((birth-rate-fact? fact) (push (birth-rate-translate fact) gathered-facts)) ((death-rate-fact? fact) (push (death-rate-translate fact) gathered-facts)) ((exports-fact? fact) (push (exports-translate fact) gathered-facts)) ((imports-fact? fact) (push (imports-translate fact) gathered-facts)) ((population-fact? fact) (push (population-translate fact) gathered-facts)) ((area-fact? fact) (push (area-translate fact) gathered-facts)) (values gathered-facts))))) ;; First get the mapping between Cyc names of countries and WFB names of countries. ;; This function goes through the list of countries in WFB facts, and then sees if ;; by Cyclifying it, Cyc knows it. It compiles the list of those that Cyc doesnt ;; recognize so that we can better the cyclify-country-name to handle all of them. (defun isa-cyc-country? (country) (or (ask-it `(data::isa ,country data::Country)) (ask-it `(data::isa ,country data::GeographicalRegion)))) ;; (setq fire::*countries* (fire::gather-countries)) (defun unmapped-countries (&optional (wfb-facts data::*wfb-facts*)) (let ((countries *countries*) (unmapped-countries nil)) (dolist (country countries) (if (isa-cyc-country? (->data (cyclify-country-name country))) (format t "Cyclify works ~A ~A ~%" country (cyclify-country-name country)) (progn (format t "?? ~A ~A ~%" country (cyclify-country-name country)) (push country unmapped-countries)))) (reverse unmapped-countries))) (defun cyclify-country-name (country) (let ((capitalized-name (intern (remove #\_ (string-capitalize country)) :data))) (case capitalized-name (data::UnitedStates 'data::UnitedStatesOfAmerica) (data::BosniaAndHerzegovina 'data::Bosnia-Herzegovina) (data::Burkina 'data::BurkinaFaso) (data::China 'data::China-PeoplesRepublic) (data::Congo 'data::Congo-Brazzaville) (data::Comoros 'data::Comoros-TheNation) (data::Cyprus 'data::Cyprus-TheCountry) (data::TheGambia 'data::Gambia) (data::Georgia 'data::Georgia-TheNation) (data::Indonesia 'data::Indonesia-TheNation) (data::Ireland 'data::Ireland-TheNation) (data::Jordan 'data::Jordan-TheNation) (data::|Macedonia, The Former Yugoslav Republic Of| 'data::Macedonia) (data::Malta 'data::Malta-TheCountry) (data::|Micronesia, Federated States of| 'data::Micronesia-FederatedStatesOf) (data::SaintKittsAndNevis 'data::SaintKitts-Nevis) (data::SaintVincentAndTheGrenadines 'data::StVincentAndTheGrenadines) (data::SolomonIslands 'data::SolomonIslands-TheNation) (t capitalized-name)))) ;; *** Translation Code **** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; S: (wfb::birth_rate albania (* 21.7 |births/1,000 population|) );; line 1149 ;; C: (birthRate Azerbaijan 22.05) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun birth-rate-fact? (ksl-fact) (and (eql (length ksl-fact) 3) (eql (car ksl-fact) 'wfb::birth_rate) (numberp (strip-units (third ksl-fact))))) (defun birth-rate-translate (ksl-fact) `(data::birthRate ,(cyclify-country-name (second ksl-fact)) ,(strip-units (third ksl-fact)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Death Rate ;; C: (deathRate China-PeoplesRepublic 7.36) ;; S: (wfb::death_rate china (* 7.36 |deaths/1,000 population|) );; line 23431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun death-rate-fact? (ksl-fact) (and (eql (length ksl-fact) 3) (eql (car ksl-fact) 'wfb::death_rate) (numberp (strip-units (third ksl-fact))))) (defun birth-rate-translate (ksl-fact) `(data::deathRate ,(cyclify-country-name (second ksl-fact)) ,(strip-units (third ksl-fact)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; S: (wfb::exports albania (* 112e6 $) );; line 1395 ;; C: (exportValue Albania (cl-user::Dollar-UnitedStates 112000000)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun exports-fact? (fact) (and (eql (length fact) 3) (eql (car fact) 'wfb::exports) (numberp (strip-units (third fact))))) (defun exports-translate (fact) `(data::exportValue ,(cyclify-country-name (second fact)) (data::Dollar-UnitedStates ,(strip-units (third fact))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; S: (wfb::imports china (* 115.7e9 $) );; line 23717 ;; C: (importValue Bahrain (BillionDollars 3.5)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun imports-fact? (fact) (and (eql (length fact) 3) (eql (car fact) 'wfb::imports) (numberp (strip-units (third fact))))) (defun imports-translate (fact) `(data::importValue ,(cyclify-country-name (second fact)) (data::Dollar-UnitedStates ,(strip-units (third fact))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; C: (populationDuring UnitedStatesOfAmerica (YearFn 1997) 267954764) ;; S: (wfb::population united_states 263814032 );; line 117370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun population-fact? (fact) (and (eql (length fact) 3) (equal (car fact) 'wfb::population) (numberp (third fact)))) (defun population-translate (fact) `(data::populationDuring ,(cyclify-country-name (second fact)) (data::YearFn 1995) ,(third fact))) ;; C: (populationGrowthRate Afghanistan (Percent 14.47)) ;; Funny that year is dropped here? ;; S: (wfb::population_growth_rate united_states (* 1.02 %) );; line 117383 ;; Area ;; C: (areaOfRegion China-PeoplesRepublic (SquareKilometer 9596960)) ;; (landAreaOfRegion China-PeoplesRepublic (SquareKilometer 9326410)) ;; S: (wfb::area china total_area (* 9596960 sq_km) );; line 23314 ;; (wfb::area china land_area (* 9326410 sq_km) );; line 23316 ;; (wfb::land_use comoros arable_land (* 35 %) );; line 25469 (defun area-total-fact? (fact) (and (eql (length fact) 4) (eql (car fact) 'wfb::area) (eql (second fact) 'data::total_area) (numberp (strip-units (fourth fact))))) (defun area-total-translate (fact) `(data::areaOfRegion ,(cyclify-country-name (second fact)) (SquareKilometer ,(strip-units (fourth fact))))) ;;;(wfb::national_product_per_capita china (* 2500 $) );; line 23692 ;; Literacy ;; Cyc has two concepts literacyRate and literacyRateForGroupInRegion ;; (literacyRateForGroupInRegion Greece Person (Percent 95)) ;; (literacyRateForGroupInRegion Greece FemalePerson (Percent 93)) ;; (literacyRateForGroupInRegion Greece MalePerson (Percent 98)) ;; In Stanford ;; (wfb::literacy armenia total_population (* 99 %) );; line 5573 ;; (wfb::literacy armenia male (* 99 %) );; line 5575 ;; (wfb::literacy armenia female (* 98 %) );; line 5577 ;; also useful -- ;; (wfb::literacy-condition armenia "age 15 and over can read and write" );; line 5571 ;; Migration ;; S: (wfb::net_migration_rate china (* 0 |migrant(s)/1,000 population|) );; line 23435 ;;;(wfb::infant_mortality_rate china (* 52.1 |deaths/1,000 live births|) );; line 23439 ;;;(wfb::life_expectancy_at_birth china total_population (* 68.08 years) );; line 23444 ;;;(wfb::life_expectancy_at_birth china male (* 67.09 years) );; line 23446 ;;;(wfb::life_expectancy_at_birth china female (* 69.18 years) );; line 23448 ;;; ;;;(wfb::total_labor_force china 583.6e6 );; line 23491 ;; Economy ;;;(wfb::national_product_real_growth_rate china (* 11.8 %) );; line 23688 ;;;(wfb::|Inflation rate (consumer prices)| china "25.5% (December 1994 over December 1993)" );; line 23696 ;;; ;;; ;;;(wfb::external_debt china (* 100e9 $) );; line 23726 ;;;(wfb::unemployment_rate colombia (* 7.9 %) );; line 25223 ;;; ;;; ;;;(wfb::electricity china capacity (* 162000000 kw) );; line 23735 ;;;(wfb::electricity china production (* 746e9 kwh) );; line 23737 ;;;(wfb::electricity china consumption_per_capita (* 593 kwh) );; line 23739 ;;; ;;;(wfb::land_use comoros arable_land (* 35 %) );; line 25469 ;;; ;;;(wfb::railroads china total "65,780 km" );; line 23791 ;;; ;;;(wfb::highways china total (* 1.029e6 km) );; line 23802 ;;; ;;;(wfb::airports china total 204 );; line 23843 ;;; ;;;(wfb::radio china radios 215e6 );; line 23884 ;;; ;;;(wfb::television china televisions 75e6 );; line 23891 (defun strip-units (expr) ;; The usual form is (* val unit) (second expr)) ;; data (defparameter *countries* '(Afghanistan Albania Algeria AmericanSamoa Andorra Angola Anguilla AntiguaAndBarbuda Argentina Armenia Aruba Australia Austria Azerbaijan TheBahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia BosniaAndHerzegovina Botswana Brazil BritishVirginIslands Brunei Bulgaria Burkina Burma Burundi Cambodia Cameroon Canada CapeVerde CaymanIsland CentralAfricanRepublic Chad Chile China |Cocos (Keeling) Islands| Colombia Comoros Congo CookIslands CostaRica |Cote D'Ivoire| Croatia Cuba Cyprus CzechRepublic Denmark Djibouti Dominica DominicanRepublic Ecuador Egypt ElSalvador EquatorialGuinea Eritrea Estonia Ethiopia FaroeIslands Fiji Finland France FrenchGuiana FrenchPolynesia Gabon TheGambia GazaStrip Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guernsey Guinea Guinea-Bissau Guyana Haiti Honduras HongKong Hungary Iceland India Indonesia Iran Iraq Ireland Israel Italy Jamaica Japan Jersey Jordan Kazakhstan Kenya Kiribati |Korea, North| |Korea, South| Kuwait Kyrgyzstan Laos Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Macau |Macedonia, The Former Yugoslav Republic Of| Madagascar Malawi Malaysia Maldives Mali Malta |Man, Isle Of| MarshallIslands Martinique Mauritania Mauritius Mayotte Mexico |Micronesia, Federated States Of| Moldova Monaco Mongolia Montserrat Morocco Mozambique Namibia Nauru Nepal Netherlands NetherlandsAntilles NewCaledonia NewZealand Nicaragua Niger Nigeria NorthernMarianaIslands Norway Oman Pakistan Palau Panama PapuaNewGuinea Paraguay Peru Philippines PitcairnIslands Poland Portugal PuertoRico Qatar Reunion Romania Russia Rwanda SaintHelena SaintKittsAndNevis SaintLucia SaintPierreAndMiquelon SaintVincentAndTheGrenadines SanMarino SaoTomeAndPrincipe SaudiArabia Senegal SerbiaAndMontenegroMontenegro SerbiaAndMontenegroSerbia Seychelles SierraLeone Singapore Slovakia Slovenia SolomonIslands Somalia SouthAfrica Spain SriLanka Sudan Suriname Svalbard Swaziland Sweden Switzerland Syria Taiwan Tajikistan Tanzania Thailand Togo Tokelau Tonga TrinidadAndTobago Tunisia Turkey Turkmenistan TurksAndCaicosIslands Tuvalu Uganda Ukraine UnitedArabEmirates UnitedKingdom UnitedStates Uruguay Uzbekistan Vanuatu Venezuela Vietnam VirginIslands WakeIsland WallisAndFutuna WestBank WesternSahara WesternSamoa World Yemen Zaire Zambia Zimbabwe)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; End of Code