comunica / comunica-feature-reasoning

📬 Comunica packages for reasoning during query execution
MIT License
5 stars 5 forks source link

Get beforeActors working #57

Closed jeswr closed 2 years ago

jeswr commented 2 years ago

Issue type:


Description:

Namely for optimization rules

github-actions[bot] commented 2 years ago

Thanks for the suggestion!

jeswr commented 2 years ago

and re-introduce this generic

import type { IActorTest } from '@comunica/core';
import type { Rule } from '@comunica/reasoning-types';
import type { AsyncIterator } from 'asynciterator';
import type { IActionOptimizeRule, IActorOptimizeRuleArgs, IActorOptimizeRuleOutput } from './ActorOptimizeRule';
import { ActorOptimizeRule } from './ActorOptimizeRule';

export abstract class ActorOptimizeRuleTyped<R extends Rule = Rule> extends ActorOptimizeRule {
  public constructor(args: IActorOptimizeRuleArgs) {
    super(args);
  }

  // Abstract testRule(rules: AsyncIterator<Rule>): rules is AsyncIterator<Rule>;

  public abstract optimizeRule(rules: AsyncIterator<R>): AsyncIterator<R>;

  public async test(action: IActionOptimizeRule): Promise<IActorTest> {
    return true;
    // Return this.testRule(action.rules.clone());
  }

  public async run(action: IActionOptimizeRule): Promise<IActorOptimizeRuleOutput> {
    return { ...action, rules: this.optimizeRule(<AsyncIterator<R>> action.rules) };
  }
}