Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. % Assess whether the user is of low income.
  2. low_income(X) :- X =< 20000.
  3. % Are they old enough to remember Margaret Thatcher? Assuming the user
  4. % had to be at least 5 years old in 1990 - ie the year of their birth
  5. % was 1985 or earlier.
  6. remembersThatcher(X) :- X =< 1985.
  7. % Count the number of hits in a list.
  8. %
  9. hits([], SearchList, 0). % If there are no search terms there can be no hits.
  10. hits([Head|Tail], SearchList, Sum) :-
  11. member(Head, SearchList),
  12. hits(Tail, SearchList, Temp),
  13. Sum is Temp + 1.
  14. hits([Head|Tail], SearchList, Sum) :-
  15. \+ member(Head, SearchList),
  16. hits(Tail, SearchList, Sum).
  17.  
  18. education(graduate).
  19. education(none).
  20.  
  21. gender(male). gender(m). gender(female). gender(f).
  22.  
  23. toryLike(['nimbyIssues']).
  24. toryHate(['europe']).
  25.  
  26. % Special Case, poor people who remember Margaret Thatcher will never vote Tory.
  27. neverVotesTory(AnualIncome, YearOfBirth) :-
  28. low_income(AnualIncome), remembersThatcher(YearOfBirth).
  29. % Establish a 'base level' based on socio-economic background.
  30. tory(_,_,_,_,_,_,0).
  31. tory(YearOfBirth, AnualIncome, MyEducation, graduate, Gender, [], [], Confidence) :-
  32. education(MyEducation),
  33. gender(Gender),
  34. \+ neverVotesTory(AnualIncome, YearOfBirth),
  35. Confidence is 1.
  36. tory(YearOfBirth, AnualIncome, MyEducation, FathersEducation, male, [], [], Confidence) :-
  37. education(MyEducation), education(FathersEducation),
  38. \+ neverVotesTory(AnualIncome, YearOfBirth),
  39. Confidence is 1 rdiv 2.
  40.  
  41. % Multiply the Confidence value by 1 / the number of hated likes and
  42. % liked hates.
  43. tory(YearOfBirth, AnualIncome, MyEducation, FathersEducation, Gender, Likes, Dislikes, Confidence) :-
  44. education(MyEducation), education(FathersEducation),
  45. toryLike(ToryLike), toryHate(ToryHate),
  46. hits(ToryLike, Dislikes, Temp1), hits(ToryHate, Likes, Temp2),
  47. Temp3 is Temp2 + Temp1 + 1,!,
  48. tory(YearOfBirth, AnualIncome, MyEducation, FathersEducation, Gender, [], [], Temp),
  49. Confidence is Temp rdiv Temp3,
  50. writeln(MyEducation).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement