@@ -16,7 +16,8 @@ describe('@hydrofoil/sparql-processor', function () {
16
16
const name = path . basename ( file )
17
17
18
18
it ( `does not modify the query (${ name } )` , function ( ) {
19
- const processor = new ( class extends QueryProcessor { } ) ( rdf )
19
+ const processor = new ( class extends QueryProcessor {
20
+ } ) ( rdf )
20
21
21
22
const processed = processor . process ( loadQuery ( name ) )
22
23
@@ -27,33 +28,60 @@ describe('@hydrofoil/sparql-processor', function () {
27
28
} )
28
29
29
30
context ( 'replacing triples with other patterns' , function ( ) {
30
- class FullTextSearchProcessor extends QueryProcessor {
31
- override processTriple ( triple : Triple ) {
32
- if ( 'termType' in triple . predicate && triple . predicate . value === 'http://example.org/fullTextSearch' ) {
33
- return < FilterPattern > {
34
- type : 'filter' ,
35
- expression : {
36
- type : 'operation' ,
37
- operator : 'regex' ,
38
- args : [
39
- triple . subject ,
40
- triple . object ,
41
- ] ,
42
- } ,
31
+ context ( 'magic property' , function ( ) {
32
+ class FullTextSearchProcessor extends QueryProcessor {
33
+ override processTriple ( triple : Triple ) {
34
+ if ( 'termType' in triple . predicate && triple . predicate . value === 'http://example.org/fullTextSearch' ) {
35
+ return < FilterPattern > {
36
+ type : 'filter' ,
37
+ expression : {
38
+ type : 'operation' ,
39
+ operator : 'regex' ,
40
+ args : [
41
+ triple . subject ,
42
+ triple . object ,
43
+ ] ,
44
+ } ,
45
+ }
43
46
}
47
+ return super . processTriple ( triple )
44
48
}
45
- return super . processTriple ( triple )
46
49
}
47
- }
48
50
49
- it ( 'replaces triples with fullTextSearch predicate' , function ( ) {
50
- const processor = new FullTextSearchProcessor ( rdf )
51
+ it ( 'replaces triples with fullTextSearch predicate' , function ( ) {
52
+ const processor = new FullTextSearchProcessor ( rdf )
51
53
52
- const query = loadQuery ( 'triple-patterns/magic-property.rq' )
53
- const processed = processor . process ( query )
54
+ const query = loadQuery ( 'triple-patterns/magic-property.rq' )
55
+ const processed = processor . process ( query )
54
56
55
- expect ( stringifyQuery ( processed ) )
56
- . to . deep . equal ( stringifyQuery ( loadQuery ( 'triple-patterns/magic-property.expected.rq' ) ) )
57
+ expect ( stringifyQuery ( processed ) )
58
+ . to . deep . equal ( stringifyQuery ( loadQuery ( 'triple-patterns/magic-property.expected.rq' ) ) )
59
+ } )
60
+ } )
61
+
62
+ context ( 'multiple resulting patterns' , function ( ) {
63
+ class FullTextSearchProcessor extends QueryProcessor {
64
+ override processTriple ( triple : Triple ) {
65
+ if ( 'type' in triple . predicate && triple . predicate . pathType === '/' ) {
66
+ return triple . predicate . items . map ( ( predicate , index , array ) : Triple => {
67
+ const subject = index === 0 ? triple . subject : this . factory . variable ( `v${ index - 1 } ` )
68
+ const object = index === array . length - 1 ? triple . object : this . factory . variable ( `v${ index } ` )
69
+ return { subject, predicate, object }
70
+ } )
71
+ }
72
+ return super . processTriple ( triple )
73
+ }
74
+ }
75
+
76
+ it ( 'replaces one triples with multiple' , function ( ) {
77
+ const processor = new FullTextSearchProcessor ( rdf )
78
+
79
+ const query = loadQuery ( 'triple-patterns/sequence.rq' )
80
+ const processed = processor . process ( query )
81
+
82
+ expect ( stringifyQuery ( processed ) )
83
+ . to . deep . equal ( stringifyQuery ( loadQuery ( 'triple-patterns/sequence.expected.rq' ) ) )
84
+ } )
57
85
} )
58
86
} )
59
87
} )
0 commit comments