AdaptiveDifferential.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///<reference path="ContentDifferential.ts"/>
  2. class AdaptiveDifferential {
  3. public compareFunction : (noun : any) => boolean = () => false;
  4. public countsAs = 0;
  5. public score = 0;
  6. public getScore () {
  7. return this.score;
  8. }
  9. constructor (replacer : (noun : any) => boolean, score : number) {
  10. this.compareFunction = replacer;
  11. }
  12. public isMatch (noun : any) {
  13. return this.compareFunction(noun);
  14. }
  15. public static ANYOF (...acceptableValues) {
  16. return new AdaptiveDifferential((noun : any) => {
  17. //console.log(acceptableValues, noun);
  18. for (let i = 0; i < acceptableValues.length; i++) {
  19. if (ContentDifferential.compareNouns(acceptableValues[i], noun)) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }, (new ContentDifferential(...acceptableValues).getScore()));
  25. }
  26. public static FULLYADAPTIVE (...acceptableValues) {
  27. let ad = AdaptiveDifferential.ANYOF(...acceptableValues);
  28. ad.countsAs = -1;
  29. return ad;
  30. }
  31. public static MALE = new AdaptiveDifferential((noun : any) => {
  32. if (noun instanceof Humanoid) {
  33. return noun.isMale();
  34. }
  35. return false;
  36. }, new ContentDifferential(Humanoid).getScore());
  37. public static FEMALE = new AdaptiveDifferential((noun : any) => {
  38. if (noun instanceof Humanoid) {
  39. return noun.isMale();
  40. }
  41. return false;
  42. }, new ContentDifferential(Humanoid).getScore());
  43. public static MASCULINE = new AdaptiveDifferential((noun : any) => {
  44. if (noun instanceof Humanoid) {
  45. return noun.getGenderValue().genderValueCorrected <= 50;
  46. }
  47. return false;
  48. }, new ContentDifferential(Humanoid).getScore());
  49. public static FEMININE = new AdaptiveDifferential((noun : any) => {
  50. if (noun instanceof Humanoid) {
  51. return noun.getGenderValue().genderValueCorrected >= 50;
  52. }
  53. return false;
  54. }, new ContentDifferential(Humanoid).getScore());
  55. }