@@ -4,23 +4,23 @@ import { Reasoner } from "../reasoner/Reasoner";
4
4
import { EyeJsReasoner } from "../reasoner/EyeJsReasoner" ;
5
5
import * as path from "path"
6
6
import * as fs from "fs"
7
- import { combineNotation3 , combineNotation3Files } from '../util/Notation3Util' ;
7
+ import { RULES } from '../rules/Rules'
8
8
9
9
export interface Engine {
10
10
evaluate ( input : Quad [ ] ) : Promise < Quad [ ] > ;
11
11
}
12
12
13
13
export class ODRLN3Engine implements Engine {
14
14
protected readonly reasoner : Reasoner ;
15
- protected readonly rules : string ;
15
+ protected readonly rules : string [ ] ;
16
16
17
- constructor ( reasoner : Reasoner , rules : string ) {
17
+ constructor ( reasoner : Reasoner , rules : string [ ] ) {
18
18
this . reasoner = reasoner ;
19
19
this . rules = rules ;
20
20
}
21
21
22
22
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 ) ;
24
24
return evaluation . getQuads ( null , null , null , null ) ;
25
25
}
26
26
}
@@ -30,48 +30,27 @@ export class ODRLEngine extends ODRLN3Engine {
30
30
const ruleDir = path . join ( path . dirname ( __filename ) , ".." , "rules" ) ;
31
31
const rulePath = path . join ( ruleDir , "simpleRules.n3" ) ;
32
32
const rules = fs . readFileSync ( rulePath , "utf-8" ) ;
33
- super ( reasoner , rules ) ;
33
+ super ( reasoner , [ rules ] ) ;
34
34
}
35
35
}
36
36
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" ) ;
44
37
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 ) ;
59
43
}
60
44
61
45
public async evaluate ( input : Quad [ ] ) : Promise < Quad [ ] > {
62
46
const complianceReportQuads : Quad [ ] = [ ] ;
63
47
const store = new Store ( input ) ;
64
48
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
+ }
75
54
return complianceReportQuads ;
76
55
}
77
56
}
0 commit comments