1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * Mandatory = One of the nouns MUST be present.
- * Optional = If on specific side, can be ignored. Behaves as mandatory on Vague side.
- * Fully_Adaptive = Behaves as optional on either side.
- */
- enum ContentNounType {MANDATORY, OPTIONAL, FULLY_ADAPTIVE};
- /**
- * Holds an array of valid nouns. This is meant to allow smarter responses that work off multiple Nouns without requiring too much code.
- * NOTE: This means only ONE of the nouns needs to fit!
- */
- class ContentNoun {
- private nouns : Array<any> = [];
- private type = ContentNounType.MANDATORY;
- public constructor (...nouns : Array<any>) {
- this.addNoun(...nouns);
- }
- public addNoun (...nouns : Array<any>) {
- this.nouns.push(...nouns);
- return this;
- }
- public getNouns () {
- return [...this.nouns];
- }
- public setType (type : ContentNounType) {
- this.type = type;
- return this;
- }
- public getType () {
- return this.type;
- }
- public compareAgainst (anything : any) {
- if (anything instanceof ContentNoun) {
- // test each of my nouns against each of other nouns
- for (let i = 0; i < this.nouns.length; i++) {
- let specificNoun = this.nouns[i];
- for (let k = 0; k < anything.nouns.length; k++) {
- let vagueNoun = anything.nouns[k];
- if (ContentAtom.compareNoun(specificNoun, vagueNoun)) {
- return true;
- }
- }
- return false;
- }
- } else {
- // test each noun against anything
- for (let i = 0; i < this.nouns.length; i++) {
- if (ContentAtom.compareNoun(this.nouns[i], anything)) {
- // A match was found.
- return true;
- }
- }
- return false;
- }
- }
- }
|