ContentUnit.ts 808 B

1234567891011121314151617181920212223242526272829
  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. }
  7. public isMatch (cu : ContentUnit) {
  8. return ContentDifferential.isMatch(this.categories, cu.categories);
  9. }
  10. public getScore () {
  11. let score = 0;
  12. this.categories.forEach(diff => {
  13. score += diff.score;
  14. });
  15. return score / this.categories.length;
  16. }
  17. public matchAgainst (a : Array<ContentUnit>) : Array<number> {
  18. for (let i = 0; i < a.length; i++) {
  19. if (a[i].isMatch(this)) {
  20. return [i];
  21. }
  22. }
  23. }
  24. }