@@ -4,23 +4,23 @@ import { Reasoner } from "../reasoner/Reasoner";
44import { EyeJsReasoner } from "../reasoner/EyeJsReasoner" ;
55import * as path from "path"
66import * as fs from "fs"
7- import { combineNotation3 , combineNotation3Files } from '../util/Notation3Util' ;
7+ import { RULES } from '../rules/Rules'
88
99export interface Engine {
1010 evaluate ( input : Quad [ ] ) : Promise < Quad [ ] > ;
1111}
1212
1313export class ODRLN3Engine implements Engine {
1414 protected readonly reasoner : Reasoner ;
15- protected readonly rules : string ;
15+ protected readonly rules : string [ ] ;
1616
17- constructor ( reasoner : Reasoner , rules : string ) {
17+ constructor ( reasoner : Reasoner , rules : string [ ] ) {
1818 this . reasoner = reasoner ;
1919 this . rules = rules ;
2020 }
2121
2222 public async evaluate ( input : Quad [ ] ) : Promise < Quad [ ] > {
23- const evaluation = await this . reasoner . reason ( new Store ( input ) , [ this . rules ] ) ;
23+ const evaluation = await this . reasoner . reason ( new Store ( input ) , this . rules ) ;
2424 return evaluation . getQuads ( null , null , null , null ) ;
2525 }
2626}
@@ -30,48 +30,27 @@ export class ODRLEngine extends ODRLN3Engine {
3030 const ruleDir = path . join ( path . dirname ( __filename ) , ".." , "rules" ) ;
3131 const rulePath = path . join ( ruleDir , "simpleRules.n3" ) ;
3232 const rules = fs . readFileSync ( rulePath , "utf-8" ) ;
33- super ( reasoner , rules ) ;
33+ super ( reasoner , [ rules ] ) ;
3434 }
3535}
3636
37- export class ODRLEngineMultipleSteps extends ODRLN3Engine {
38- private readonly firstStepRules : string ;
39- private readonly secondStepRules : string ;
40-
41- constructor ( reasoner ?: Reasoner ) {
42- reasoner = reasoner ?? new EyeJsReasoner ( ) ;
43- const ruleDir = path . join ( path . dirname ( __filename ) , ".." , "rules" ) ;
4437
45- // note: if there are more steps than two, this MUST be made into a function.
46- // This also applies to the class variables and evaluate function.
47- const fileNamesRulesFirst = [ "built-ins.n3" , "constraints.n3" , "report.n3" , "odrl-voc.ttl" , "odrl-voc-inferences.ttl" ] ;
48- const fileNamesRulesSecond = [ "activation-state.n3" ] ;
49-
50- const firstStepRulePaths = fileNamesRulesFirst . map ( fileName => path . join ( ruleDir , fileName ) ) ;
51- const secondStepRulePaths = fileNamesRulesSecond . map ( fileName => path . join ( ruleDir , fileName ) ) ;
52-
53- const firstStepRules = combineNotation3Files ( firstStepRulePaths ) ;
54- const secondStepRules = combineNotation3Files ( secondStepRulePaths ) ;
55-
56- super ( reasoner , combineNotation3 ( [ firstStepRules , secondStepRules ] ) ) ;
57- this . firstStepRules = firstStepRules ;
58- this . secondStepRules = secondStepRules ;
38+ export class ODRLEngineMultipleSteps extends ODRLN3Engine {
39+ constructor ( config ?: { reasoner ?: Reasoner , rules ?: string [ ] } ) {
40+ const reasoner = config ?. reasoner ?? new EyeJsReasoner ( ) ;
41+ const rules = config ?. rules ?? RULES ;
42+ super ( reasoner , rules ) ;
5943 }
6044
6145 public async evaluate ( input : Quad [ ] ) : Promise < Quad [ ] > {
6246 const complianceReportQuads : Quad [ ] = [ ] ;
6347 const store = new Store ( input ) ;
6448
65- const firstEvaluation = await this . reasoner . reason ( store , [ this . firstStepRules ] ) ;
66-
67- // The first evaluation creates a partial report. Now reason again over the same input + partial evaluation report
68- complianceReportQuads . push ( ...firstEvaluation . getQuads ( null , null , null , null ) ) ;
69- store . addQuads ( complianceReportQuads )
70-
71- // might be a problem that store is re-used?
72- const secondEvaluation = await this . reasoner . reason ( store , [ this . secondStepRules ] ) ;
73-
74- complianceReportQuads . push ( ...secondEvaluation . getQuads ( null , null , null , null ) ) ;
49+ for ( const rule of this . rules ) {
50+ const evaluation = await this . reasoner . reason ( store , [ rule ] ) ;
51+ complianceReportQuads . push ( ...evaluation . getQuads ( null , null , null , null ) ) ;
52+ store . addQuads ( complianceReportQuads )
53+ }
7554 return complianceReportQuads ;
7655 }
7756}
0 commit comments