Skip to content

Commit

Permalink
Merge branch 'development' into 'main'
Browse files Browse the repository at this point in the history
Add ShExML execution capabilities to weaver (mostly bug fixing)

See merge request rml/proc/rmlweaver-js!1
  • Loading branch information
s-minoo committed Jun 14, 2024
2 parents 1a28029 + 6239559 commit 51d0b4e
Show file tree
Hide file tree
Showing 163 changed files with 1,340 additions and 958 deletions.
34 changes: 34 additions & 0 deletions .cmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The input parts
{
# Shows a list of options
"Type" = [
"feat",
"fix",
"docs",
"style",
"refactor",
"test",
"chore"
]
"Scope" = @ # Single line input
"Subject" = @
"Body" = !@ # Multi-line input
"Footer" = !@
}

# predefined messages
# this section is optional
{
vb = "chore: version bump"
readme = "docs: updated readme"
}

# The output format
# Takes the values provided from the input stage
# and interpolates them in
${Type} (${Scope}): ${Subject}

${Body}

${Footer}

5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
186 changes: 121 additions & 65 deletions src/operator/extendOperator.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,144 @@
import {Operator} from "./Operator.js";
import Handlebars from 'handlebars';
import {BlankNode, Iri, LanguageDataType, Literal} from "../types.js";
import { Operator } from './Operator.js'
import Handlebars from 'handlebars'
import { BlankNode, Iri, LanguageDataType, Literal } from '../types.js'
import { forEach } from 'most'

export class ExtendOp extends Operator {
generateMapping(key, mapping) { // In function so recursion is possible
generateMapping(key, mapping) {
// In function so recursion is possible

if (key.charAt(0) === '?') key = key.slice(1) // Remove ? When we have a *variable* attribute

const innerFunction = mapping.inner_function != null ? this.generateMapping(key, mapping.inner_function) : null;
let regex = /\{([^}]+)}/g // Match text between curly brackets.
const innerFunction =
mapping.inner_function != null
? this.generateMapping(key, mapping.inner_function)
: null

switch (mapping.type) {

case('Iri'):
return obj => {
innerFunction(obj);
obj[key] = new Iri(obj[key]);
};

case('Literal'):
const dtypeFunction = mapping.dtype_function != null ? this.generateMapping(key, mapping.inner_function) : null;
const langtypeFunction = mapping.langtype_function != null ? this.generateMapping(key, mapping.inner_function) : null;


return obj => {
innerFunction(obj);
if(dtypeFunction !== null){
case 'Iri':
return (obj) => {
innerFunction(obj)
obj[key] = new Iri(obj[key])
}

case 'Literal':
const dtypeFunction =
mapping.dtype_function != null
? this.generateMapping(key, mapping.inner_function)
: null
const langtypeFunction =
mapping.langtype_function != null
? this.generateMapping(key, mapping.inner_function)
: null

return (obj) => {
innerFunction(obj)
if (dtypeFunction !== null) {
dtypeFunction(obj)
}
if(langtypeFunction !== null){
if (langtypeFunction !== null) {
langtypeFunction(obj)
}
obj[key] = new Literal(obj[key]);
};

case('BlankNode'):
return obj => {
innerFunction(obj);
obj[key] = new BlankNode(obj[key]);
};

case('UriEncode'):
return obj => {
innerFunction(obj);

obj[key] = encodeURI(obj[key]).replace(',', '%2C').replace('(', '%28').replace(')', '%29'); // Encode URI, Maybe manually in the future to match RML mapper.
};

case('Reference'):
return (obj => {
obj[key] = obj[mapping.value];
});

case('Constant'):
return (obj => {
obj[key] = mapping.value;
});

case('TemplateString'):
const regex = /\{([^}]+)}/g; // Match text between curly brackets.
const template_string = mapping.value.replace(regex, (match, content) => `{{[${content}]}}`); // Double brackets for HandleBars.
const template = Handlebars.compile(template_string);
return (obj => {
obj[key] = template(obj);
});
obj[key] = new Literal(obj[key])
}

case 'BlankNode':
return (obj) => {
innerFunction(obj)
obj[key] = new BlankNode(obj[key])
}

case 'UriEncode':
return (obj) => {
innerFunction(obj)

obj[key] = encodeURI(obj[key])
.replace(',', '%2C')
.replace('(', '%28')
.replace(')', '%29') // Encode URI, Maybe manually in the future to match RML mapper.
}

case 'Reference':
return (obj) => {
obj[key] = obj[mapping.value]
}

case 'Constant':
return (obj) => {
obj[key] = mapping.value
}

case 'TemplateString':
// Match text between curly brackets.
let template_string = mapping.value.replace(
regex,
(match, content) => `{{[${content}]}}`,
) // Double brackets for HandleBars.
let template = Handlebars.compile(template_string)
return (obj) => {
obj[key] = template(obj)
}

case 'TemplateFunctionValue':
let template_string_2 = mapping.template.replace(
regex,
(match, content) => `{{[${content}]}}`,
) // Double brackets for HandleBars.
let template2 = Handlebars.compile(template_string_2)
let var_function_pairs = {}
for (let pair of mapping.variable_function_pairs) {
let variable = pair[0]
let ext_func = pair[1]
ext_func = this.generateMapping(key, ext_func)
var_function_pairs[variable] = ext_func
}

return (obj) => {
let temp_val = {};
for (let variable in var_function_pairs) {
let nest_func = var_function_pairs[variable]
nest_func(obj)
temp_val[variable] = obj[key]
}
obj[key] = template2(temp_val)
}

case 'Concatenate':
const left_function = this.generateMapping(
key,
mapping.left_value,
)
const right_function = this.generateMapping(
key,
mapping.right_value,
)
return (obj) => {
left_function(obj)
const left_value = obj[key]
right_function(obj)
const right_value = obj[key]
obj[key] = left_value + mapping.separator + right_value
}

default:
throw Error(`Type (${mapping.type}) found in extend operator not supported!`);
throw Error(
`Type (${mapping.type}) found in extend operator not supported!`,
)
}
}


constructor(id, config) {
super(id, config);
this.extensions = [];
super(id, config)
this.extensions = []
for (let key in config) {
this.extensions.push(this.generateMapping(key, config[key]));
this.extensions.push(this.generateMapping(key, config[key]))
}
}

next(v) {
this.extensions.forEach(extend => {
extend(v);
});
this.push(v);
this.extensions.forEach((extend) => {
extend(v)
})
this.push(v)
}

}
6 changes: 5 additions & 1 deletion src/operator/operatormanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {SerializerOp} from "./serializerOperator.js";
import {TargetOp} from "./targetOperator.js";
import {FragmentOp} from "./fragmentOperator.js";
import {JoinOperator} from "./joinOperator.js";
import { RenameOp } from "./renameOperator.js";


export class OpManager {
Expand Down Expand Up @@ -49,8 +50,11 @@ export function parseOperator(id, type, config){
case 'JoinOp':
operator = new JoinOperator(id, config);
break;
case 'RenameOp':
operator = new RenameOp(id, config);
break;
default:
throw new Error(`Operator type ${type} is not supported`);
}
return operator
}
}
16 changes: 7 additions & 9 deletions src/operator/renameOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import {BlankNode, Iri, Literal} from "../types.js";
export class RenameOp extends Operator {
constructor(id, config) {
super(id, config);
this.aliases = []
for(let i =0; i < config.aliases; i++){
const alias = config.aliases[i]
if(alias[0] !== alias[1]){
this.aliases.append(alias)
}
this.aliases = {}
for (const from in config) {
this.aliases[from] = config[from]
}
}

next(v) {
for(let [_, alias] of this.aliases){
v[alias[0]] = v[alias[1]]
delete v[alias[1]]
for(let from in this.aliases){
let to = this.aliases[from]
v[to] = v[from]
delete v[from]
}
this.push(v);
}
Expand Down
Loading

0 comments on commit 51d0b4e

Please sign in to comment.