/****************** dialog handler kb *********************/
user_selected(location, _Location) :-		/* user has given a location */
    u_post(location, _Location),		/* post in user conceptualization (user set) */
    ( /+lookup(position, _Location, _Latitude, _Longitude) -> /* do we know this position? */
	ask_user(latitide),			/* no, so ask user for lat/long (posts a */
	ask_user(longitude),			/* message to user dialog area on blackboard) */
	fail
    )
	check_location(_Location),		/* yes, so check location consistent with kb */
	k_post(latitude, _Latitude),		/* post in user conceptualization (user set) */
	k_post(longitude, _Longitude).

/*************** user conceptualization kb ******************/

infer_from(location, _Location) :-	/* what can we deduce from the user supplied location */
    lookup(site_type, _Location, _Site_type) ->	/* do we know this locations site_type */
	k_post(site_type, _Site_type),		/* yes, so set it (kb set) */
	suggest_user(site_type, _Site_type),	/* show default to user*/
	infer_from(site_type, _Site_type)	/* make further deductions */
    ; /* can we guess the buildings function (really speculative!) */
	( _Site_type = rural -> k_post(function, industrial)
	; _Site_type = urban -> k_post(function, residential)
	; _Site_type = city -> k_post(function, office)
	)
    ; /* infer_from predicates must not fail! */
	true
    ).
		
infer_from(position, _Latitude, _Longitude) :-	/* what can we deduce from this position */
    guess_climate_set(_Latitude, _Longitude, _Climate_set)
    k_post(climate, _Climate_file),		/* yes, so set it (kb set) */
    infer_from(climate, _Climate_file).		/* any further deductions? */

guess_climate_set(_Latitude, _Longitude, _Climate_set) :-
    ( known(analysis, _Analysis) ; true),		   /* get analysis type, if known */
    climate(_Clm_Lat, _Clm_Long, _Analysis, _Climate_set), /* get climate file near position */
    near(_Clm_Lat, _Clm_Long, _Latitude, _Longitude).      /*  suitable for this analysis */ 
