Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

Eddykasp
Copy link
Contributor

@Eddykasp Eddykasp commented Jul 25, 2022

@Eddykasp Eddykasp added enhancement New feature or request klighd-core requires server change This change is linked to some change on the server side implementation in KLighD labels Jul 25, 2022
Copy link
Member

@NiklasRentzCAU NiklasRentzCAU left a 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. */
Copy link
Member

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.

Comment on lines 166 to 192
//// 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
}
Copy link
Member

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 >

Comment on lines 261 to 278
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);
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Comment on lines 380 to 442
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);
}
}
Copy link
Member

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)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Eddykasp
Copy link
Contributor Author

Eddykasp commented Sep 8, 2023

superseded by #86

@Eddykasp Eddykasp closed this Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request klighd-core requires server change This change is linked to some change on the server side implementation in KLighD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants