Skip to content

Commit 51d0b4e

Browse files
committed
Merge branch 'development' into 'main'
Add ShExML execution capabilities to weaver (mostly bug fixing) See merge request rml/proc/rmlweaver-js!1
2 parents 1a28029 + 6239559 commit 51d0b4e

File tree

163 files changed

+1340
-958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+1340
-958
lines changed

.cmt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# The input parts
2+
{
3+
# Shows a list of options
4+
"Type" = [
5+
"feat",
6+
"fix",
7+
"docs",
8+
"style",
9+
"refactor",
10+
"test",
11+
"chore"
12+
]
13+
"Scope" = @ # Single line input
14+
"Subject" = @
15+
"Body" = !@ # Multi-line input
16+
"Footer" = !@
17+
}
18+
19+
# predefined messages
20+
# this section is optional
21+
{
22+
vb = "chore: version bump"
23+
readme = "docs: updated readme"
24+
}
25+
26+
# The output format
27+
# Takes the values provided from the input stage
28+
# and interpolates them in
29+
${Type} (${Scope}): ${Subject}
30+
31+
${Body}
32+
33+
${Footer}
34+

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 4,
3+
"semi": false,
4+
"singleQuote": true
5+
}

src/operator/extendOperator.js

Lines changed: 121 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,144 @@
1-
import {Operator} from "./Operator.js";
2-
import Handlebars from 'handlebars';
3-
import {BlankNode, Iri, LanguageDataType, Literal} from "../types.js";
1+
import { Operator } from './Operator.js'
2+
import Handlebars from 'handlebars'
3+
import { BlankNode, Iri, LanguageDataType, Literal } from '../types.js'
4+
import { forEach } from 'most'
45

56
export class ExtendOp extends Operator {
6-
generateMapping(key, mapping) { // In function so recursion is possible
7+
generateMapping(key, mapping) {
8+
// In function so recursion is possible
79

810
if (key.charAt(0) === '?') key = key.slice(1) // Remove ? When we have a *variable* attribute
9-
10-
const innerFunction = mapping.inner_function != null ? this.generateMapping(key, mapping.inner_function) : null;
11+
let regex = /\{([^}]+)}/g // Match text between curly brackets.
12+
const innerFunction =
13+
mapping.inner_function != null
14+
? this.generateMapping(key, mapping.inner_function)
15+
: null
1116

1217
switch (mapping.type) {
13-
14-
case('Iri'):
15-
return obj => {
16-
innerFunction(obj);
17-
obj[key] = new Iri(obj[key]);
18-
};
19-
20-
case('Literal'):
21-
const dtypeFunction = mapping.dtype_function != null ? this.generateMapping(key, mapping.inner_function) : null;
22-
const langtypeFunction = mapping.langtype_function != null ? this.generateMapping(key, mapping.inner_function) : null;
23-
24-
25-
return obj => {
26-
innerFunction(obj);
27-
if(dtypeFunction !== null){
18+
case 'Iri':
19+
return (obj) => {
20+
innerFunction(obj)
21+
obj[key] = new Iri(obj[key])
22+
}
23+
24+
case 'Literal':
25+
const dtypeFunction =
26+
mapping.dtype_function != null
27+
? this.generateMapping(key, mapping.inner_function)
28+
: null
29+
const langtypeFunction =
30+
mapping.langtype_function != null
31+
? this.generateMapping(key, mapping.inner_function)
32+
: null
33+
34+
return (obj) => {
35+
innerFunction(obj)
36+
if (dtypeFunction !== null) {
2837
dtypeFunction(obj)
2938
}
30-
if(langtypeFunction !== null){
39+
if (langtypeFunction !== null) {
3140
langtypeFunction(obj)
3241
}
33-
obj[key] = new Literal(obj[key]);
34-
};
35-
36-
case('BlankNode'):
37-
return obj => {
38-
innerFunction(obj);
39-
obj[key] = new BlankNode(obj[key]);
40-
};
41-
42-
case('UriEncode'):
43-
return obj => {
44-
innerFunction(obj);
45-
46-
obj[key] = encodeURI(obj[key]).replace(',', '%2C').replace('(', '%28').replace(')', '%29'); // Encode URI, Maybe manually in the future to match RML mapper.
47-
};
48-
49-
case('Reference'):
50-
return (obj => {
51-
obj[key] = obj[mapping.value];
52-
});
53-
54-
case('Constant'):
55-
return (obj => {
56-
obj[key] = mapping.value;
57-
});
58-
59-
case('TemplateString'):
60-
const regex = /\{([^}]+)}/g; // Match text between curly brackets.
61-
const template_string = mapping.value.replace(regex, (match, content) => `{{[${content}]}}`); // Double brackets for HandleBars.
62-
const template = Handlebars.compile(template_string);
63-
return (obj => {
64-
obj[key] = template(obj);
65-
});
42+
obj[key] = new Literal(obj[key])
43+
}
44+
45+
case 'BlankNode':
46+
return (obj) => {
47+
innerFunction(obj)
48+
obj[key] = new BlankNode(obj[key])
49+
}
50+
51+
case 'UriEncode':
52+
return (obj) => {
53+
innerFunction(obj)
54+
55+
obj[key] = encodeURI(obj[key])
56+
.replace(',', '%2C')
57+
.replace('(', '%28')
58+
.replace(')', '%29') // Encode URI, Maybe manually in the future to match RML mapper.
59+
}
60+
61+
case 'Reference':
62+
return (obj) => {
63+
obj[key] = obj[mapping.value]
64+
}
65+
66+
case 'Constant':
67+
return (obj) => {
68+
obj[key] = mapping.value
69+
}
70+
71+
case 'TemplateString':
72+
// Match text between curly brackets.
73+
let template_string = mapping.value.replace(
74+
regex,
75+
(match, content) => `{{[${content}]}}`,
76+
) // Double brackets for HandleBars.
77+
let template = Handlebars.compile(template_string)
78+
return (obj) => {
79+
obj[key] = template(obj)
80+
}
81+
82+
case 'TemplateFunctionValue':
83+
let template_string_2 = mapping.template.replace(
84+
regex,
85+
(match, content) => `{{[${content}]}}`,
86+
) // Double brackets for HandleBars.
87+
let template2 = Handlebars.compile(template_string_2)
88+
let var_function_pairs = {}
89+
for (let pair of mapping.variable_function_pairs) {
90+
let variable = pair[0]
91+
let ext_func = pair[1]
92+
ext_func = this.generateMapping(key, ext_func)
93+
var_function_pairs[variable] = ext_func
94+
}
95+
96+
return (obj) => {
97+
let temp_val = {};
98+
for (let variable in var_function_pairs) {
99+
let nest_func = var_function_pairs[variable]
100+
nest_func(obj)
101+
temp_val[variable] = obj[key]
102+
}
103+
obj[key] = template2(temp_val)
104+
}
105+
106+
case 'Concatenate':
107+
const left_function = this.generateMapping(
108+
key,
109+
mapping.left_value,
110+
)
111+
const right_function = this.generateMapping(
112+
key,
113+
mapping.right_value,
114+
)
115+
return (obj) => {
116+
left_function(obj)
117+
const left_value = obj[key]
118+
right_function(obj)
119+
const right_value = obj[key]
120+
obj[key] = left_value + mapping.separator + right_value
121+
}
66122

67123
default:
68-
throw Error(`Type (${mapping.type}) found in extend operator not supported!`);
124+
throw Error(
125+
`Type (${mapping.type}) found in extend operator not supported!`,
126+
)
69127
}
70128
}
71129

72-
73130
constructor(id, config) {
74-
super(id, config);
75-
this.extensions = [];
131+
super(id, config)
132+
this.extensions = []
76133
for (let key in config) {
77-
this.extensions.push(this.generateMapping(key, config[key]));
134+
this.extensions.push(this.generateMapping(key, config[key]))
78135
}
79136
}
80137

81138
next(v) {
82-
this.extensions.forEach(extend => {
83-
extend(v);
84-
});
85-
this.push(v);
139+
this.extensions.forEach((extend) => {
140+
extend(v)
141+
})
142+
this.push(v)
86143
}
87-
88144
}

src/operator/operatormanager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {SerializerOp} from "./serializerOperator.js";
55
import {TargetOp} from "./targetOperator.js";
66
import {FragmentOp} from "./fragmentOperator.js";
77
import {JoinOperator} from "./joinOperator.js";
8+
import { RenameOp } from "./renameOperator.js";
89

910

1011
export class OpManager {
@@ -49,8 +50,11 @@ export function parseOperator(id, type, config){
4950
case 'JoinOp':
5051
operator = new JoinOperator(id, config);
5152
break;
53+
case 'RenameOp':
54+
operator = new RenameOp(id, config);
55+
break;
5256
default:
5357
throw new Error(`Operator type ${type} is not supported`);
5458
}
5559
return operator
56-
}
60+
}

src/operator/renameOperator.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import {BlankNode, Iri, Literal} from "../types.js";
44
export class RenameOp extends Operator {
55
constructor(id, config) {
66
super(id, config);
7-
this.aliases = []
8-
for(let i =0; i < config.aliases; i++){
9-
const alias = config.aliases[i]
10-
if(alias[0] !== alias[1]){
11-
this.aliases.append(alias)
12-
}
7+
this.aliases = {}
8+
for (const from in config) {
9+
this.aliases[from] = config[from]
1310
}
1411
}
1512

1613
next(v) {
17-
for(let [_, alias] of this.aliases){
18-
v[alias[0]] = v[alias[1]]
19-
delete v[alias[1]]
14+
for(let from in this.aliases){
15+
let to = this.aliases[from]
16+
v[to] = v[from]
17+
delete v[from]
2018
}
2119
this.push(v);
2220
}

0 commit comments

Comments
 (0)