ContentUnit.ts 829 B

123456789101112131415161718192021222324252627282930
  1. /// <reference path="ContentDifferential.ts" />
  2. class ContentUnit {
  3. public categories : Array<ContentDifferential> = [];
  4. public addCategory (...nouns : Array<Thing | typeof Thing | ContentDifferential>) {
  5. this.categories.push(new ContentDifferential(...nouns));
  6. return this;
  7. }
  8. public isMatch (cu : ContentUnit) {
  9. return ContentDifferential.isMatch(this.categories, cu.categories);
  10. }
  11. public getScore () {
  12. let score = 0;
  13. this.categories.forEach(diff => {
  14. score += diff.score;
  15. });
  16. return score / this.categories.length;
  17. }
  18. public matchAgainst (a : Array<ContentUnit>) : Array<number> {
  19. for (let i = 0; i < a.length; i++) {
  20. if (a[i].isMatch(this)) {
  21. return [i];
  22. }
  23. }
  24. }
  25. }