/** * 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 = []; private type = ContentNounType.MANDATORY; public constructor (...nouns : Array) { this.addNoun(...nouns); } public addNoun (...nouns : Array) { 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; } } }