-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semantic filtering client-side evaluation #109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As all of this (and the server changes) are very generic and do not do anything currently, some documentation how to use this, some tests, or simple examples should be added to show what this does.
export class SemanticFilterTag implements SemanticFilterRule { | ||
ruleName?: string | ||
tag: string | ||
/** Not defining num defaults it to 0. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When creating such an element here would default to it being undefined
and not 0
. I guess here you refer to tags from the server will default to 0
? Then I would remove the ?
here as a value is guaranteed.
//// Numeric Connectives //// | ||
|
||
/** | ||
* A LessThan Connective takes one rule R and evaluates to true | ||
* iff | ||
* R.num < correspondingTag.num. | ||
* @example R.num < correspondingTag.num | ||
*/ | ||
export class LessThanConnective implements UnaryConnective { | ||
static NAME = "LESSTHAN" | ||
name = LessThanConnective.NAME | ||
operand: SemanticFilterTag | ||
ruleName?: string | ||
} | ||
|
||
/** | ||
* A GreaterThan Connective takes one rule R and evaluates to true | ||
* iff | ||
* R.num > correspondingTag.num. | ||
* @example R.num > correspondingTag.num | ||
*/ | ||
export class GreaterThanConnective implements UnaryConnective { | ||
static NAME = "GREATERTHAN" | ||
name = GreaterThanConnective.NAME | ||
operand: SemanticFilterTag | ||
ruleName?: string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default relation definitions usually is using <=
, >=
and =
resp. !=
instead of <
and >
case NegationConnective.NAME: | ||
return !(evaluateRule(unary.operand, tags)); | ||
case AndConnective.NAME: | ||
return evaluateRule(binary.leftOperand, tags) | ||
&& evaluateRule(binary.rightOperand, tags); | ||
case OrConnective.NAME: | ||
return evaluateRule(binary.leftOperand, tags) | ||
|| evaluateRule(binary.rightOperand, tags); | ||
case IfThenConnective.NAME: | ||
return !evaluateRule(binary.leftOperand, tags) | ||
|| evaluateRule(binary.rightOperand, tags); | ||
case LogicEqualConnective.NAME: | ||
return evaluateRule(binary.leftOperand, tags) | ||
=== evaluateRule(binary.rightOperand, tags); | ||
case IfThenElseConnective.NAME: | ||
return evaluateRule(ternary.firstOperand, tags) | ||
? evaluateRule(ternary.secondOperand, tags) | ||
: evaluateRule(ternary.thirdOperand, tags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the evaluation of the directives would be better placed in the namespace of the directive classes in some evaluate
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could that not cause problems with the deserialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialization only uses fields and no methods of classes, I am not quite sure about the other way around. But Actions circumvent this by putting the function into the namespace, not into some class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, I can do it that way
export class NumericPlusConnective implements BinaryConnective { | ||
static NAME = "NUMERICPLUS" | ||
name = NumericPlusConnective.NAME | ||
leftOperand: SemanticFilterRule | ||
rightOperand: SemanticFilterRule | ||
} | ||
|
||
export namespace NumericPlusConnective { | ||
export function evaluate(conn: NumericPlusConnective): number { | ||
return evaluateNumeric(conn.leftOperand) + evaluateNumeric(conn.rightOperand); | ||
} | ||
} | ||
|
||
/** | ||
* A Numeric Minus Connective takes two numeric operands and evaluates | ||
* to their difference. | ||
*/ | ||
export class NumericMinusConnective implements BinaryConnective { | ||
static NAME = "NUMERICMINUS" | ||
name = NumericMinusConnective.NAME | ||
leftOperand: SemanticFilterRule | ||
rightOperand: SemanticFilterRule | ||
} | ||
|
||
export namespace NumericMinusConnective { | ||
export function evaluate(conn: NumericMinusConnective): number { | ||
return evaluateNumeric(conn.leftOperand) - evaluateNumeric(conn.rightOperand); | ||
} | ||
} | ||
|
||
/** | ||
* A Numeric Times Connective takes two numeric operands and evaluates | ||
* to their product. | ||
*/ | ||
export class NumericTimesConnective implements BinaryConnective { | ||
static NAME = "NUMERICTIMES" | ||
name = NumericTimesConnective.NAME | ||
leftOperand: SemanticFilterRule | ||
rightOperand: SemanticFilterRule | ||
} | ||
|
||
export namespace NumericTimesConnective { | ||
export function evaluate(conn: NumericTimesConnective): number { | ||
return evaluateNumeric(conn.leftOperand) * evaluateNumeric(conn.rightOperand); | ||
} | ||
} | ||
|
||
/** | ||
* A Numeric Divides Connective takes two numeric operands and evaluates | ||
* to their product. | ||
*/ | ||
export class NumericDividesConnective implements BinaryConnective { | ||
static NAME = "NUMERICDIVIDES" | ||
name = NumericDividesConnective.NAME | ||
leftOperand: SemanticFilterRule | ||
rightOperand: SemanticFilterRule | ||
} | ||
|
||
export namespace NumericDividesConnective { | ||
export function evaluate(conn: NumericDividesConnective): number { | ||
return evaluateNumeric(conn.leftOperand) / evaluateNumeric(conn.rightOperand); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename these to …Addition…, …Subtraction…, …Multiplication…, and …Division…
function evaluateNumeric(rule: SemanticFilterRule, tags: Array<SemanticFilterTag>): number { | ||
// Rule is a Tag | ||
if ((rule as SemanticFilterTag).tag !== undefined) { | ||
let nodeTag = tags.find((tag: SemanticFilterTag) => tag.tag === (rule as SemanticFilterTag).tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be const to pass checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
superseded by #86 |
kieler/KLighD#137