infer_from(user_name, _Name) :-
	( um_known(user_type, _User_type) ->
		kset(user_type, _User_type),
		to_bb(user_dialog, tell_user, user_type, _User_type)
	; true
	),
	( um_known(user_level, _User_level) ->
		kset(user_level, _User_level),
		( _User_level == expert ->		/* heavily used */
			assert(user_level(expert))
		;
			assert(user_level(novice))
		),
		to_bb(user_dialog, tell_user, user_level, _User_level)
	; true
	).


infer_from(location, _Location) :-
	( \+uc_known(latitude, _), \+uc_known(longitude, _),
	  position(_Location, _Latitude, _Longitude) ->
	  	kset(latitude, _Latitude),
	 	kset(longitude, _Longitude),
	  	infer_from(position, _Latitude, _Longitude)
	; true		/* must not fail */
	),
	( \+uc_known(environment, _),
	  environment(_Location, _Environment),
	 	kset(environment, _Environment),
	 	infer_from(environment, _Environment)
	; true		/* must not fail */
	).

retract_infer(location) :-
	retract(u_cpt, latitude), retract_infer(latitude),
	retract(u_cpt, longitude), retract_infer(longitude),
	retract(u_cpt, environment), retract_infer(environment).


infer_from(position, _Latitude, _Longitude) :-
	( \+uc_known(location, _),
	  position(_Location, _Lat, _Long),
	  near(_Latitude, _Longitude, _Lat, _Long, 0.5) ->  /* 30 miles */
	  	kset(location, _Location),
	  	infer_from(location, _Location)
	; true
	),
	( \+uc_known(climate_set, _),
	  ( uc_known(analysis_climate_requirment, _Climate_type), /* suits analysis requirements */
	    climate_type(_Climate_set, _Climate_type, _, _)
	  ; true		/* no particular requirements (yet) */
	  ),
	  climate_set(_Climate_set, _Lat, _Long),
	  near(_Latitude, _Longitude, _Lat, _Long, 1.5) ->  /* 100 miles */
		  kset(climate_set, _Climate_set),
		  infer_from(climate_set, _Climate_set)
	; true
	).

retract_infer(position) :-
	retract(u_cpt, location), retract_infer(location),
	retract(u_cpt, climate_set), retract_infer(climate_set).


infer_from(environment, _Environment) :-
	( \+uc_known(exposure, _),
	  exposure(_Environment, _Exposure) ->
	  	kset(exposure, _Exposure),
		infer_from(exposure, _Exposure)
	; true
	),
	( \+uc_known(grnd_rflct, _Grnd_rflct),
	  grnd_rflct(_Environment, _Grnd_rflct) ->
	  	kset(grnd_rflct, _Grnd_rflct),
		infer_from(grnd_rflct, _Grnd_rflct)
	; true
	).

retract_infer(environment) :-
	retract(u_cpt, exposure), retract_infer(exposure),
	retract(u_cpt, grnd_rflct), retract_infer(grnd_rflct).


infer_from(climate_set, _).
retract_infer(climate_set).
infer_from(exposure, _).
retract_infer(exposure).
infer_from(grnd_rflct, _).
retract_infer(grnd_rflct).
