Skip to content

Commit

Permalink
upd to 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed May 14, 2021
1 parent 95c9cb3 commit f5799f6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 80 deletions.
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"js-yaml": "^3.14.0",
"lodash": "^4.17.21",
"markdown": "^0.5.0",
"mathjs": "^5.10.3",
"mathjs-mathml": "^0.2.4",
"mathjs-translate": "^0.2.0",
"mathjs": "^6.6.5",
"mathjs-mathml": "^0.2.6",
"mathjs-translate": "^0.2.2",
"npm": "^6.14.12",
"nunjucks": "^3.2.3",
"random-id": "^1.0.4",
Expand Down
43 changes: 2 additions & 41 deletions src/core/expression.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
const math = require('mathjs');
const mathjsTranslate = require('mathjs-translate');
math.import(mathjsTranslate);
const mathCalcUnits = require('./math-calc-unit');
math.import(mathCalcUnits);
const { math } = require('./utilities');

let { OperatorNode, SymbolNode } = math.expression.node;
const _ = require('lodash');

/* remove parenthesis from top */
function _removeParenthesis(node) {
if (node.type === 'ParenthesisNode') {
return _removeParenthesis(node.content);
} else {
return node;
}
}

/*
To check if mathjs.Node instance has boolean or numeric result
*/
math.import({
name: 'hasBooleanResult',
path: 'expression.node.Node.prototype',
factory: function(){
let operators = [
'smaller', 'smallerEq',
'larger', 'largerEq',
'equal', 'unequal',
'and', 'or', 'xor', 'not'
];

return function(){
let expr = _removeParenthesis(this);

let isBooleanOperator = expr.type === 'OperatorNode'
&& operators.indexOf(expr.fn) !== -1;
let isBooleanValue = expr.type === 'ConstantNode'
&& [true, false].indexOf(expr.value) !== -1;

return isBooleanOperator || isBooleanValue;
};
}
});

/*
To store mathematical expressions with additional methods
*/
Expand Down
45 changes: 44 additions & 1 deletion src/core/utilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// TODO: replace nesessary content to /src/utils.js

const { create, all } = require('mathjs');
const math = create(all);
math.import(require('mathjs-translate'));
math.import(require('./math-calc-unit'));
math.import(require('mathjs-mathml'));

/*
To check if mathjs.Node instance has boolean or numeric result
*/
math.import({
name: 'hasBooleanResult',
path: 'expression.node.Node.prototype',
factory: function(){
let operators = [
'smaller', 'smallerEq',
'larger', 'largerEq',
'equal', 'unequal',
'and', 'or', 'xor', 'not'
];

return function(){
let expr = _removeParenthesis(this);

let isBooleanOperator = expr.type === 'OperatorNode'
&& operators.indexOf(expr.fn) !== -1;
let isBooleanValue = expr.type === 'ConstantNode'
&& [true, false].indexOf(expr.value) !== -1;

return isBooleanOperator || isBooleanValue;
};
}
});

/* remove parenthesis from top */
function _removeParenthesis(node) {
if (node.type === 'ParenthesisNode') {
return _removeParenthesis(node.content);
} else {
return node;
}
}

const schema = require('../heta.json-schema');
const Ajv = require('ajv');
const _ = require('lodash');
Expand Down Expand Up @@ -37,5 +79,6 @@ function flatten(o){

module.exports = {
validator,
flatten
flatten,
math
};
4 changes: 0 additions & 4 deletions src/sbml-export/expression.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { Expression } = require('../core/expression');

const math = require('mathjs');
const mathjsMathML = require('mathjs-mathml');
math.import(mathjsMathML);

const csymbols = {
t: 'http://www.sbml.org/sbml/symbols/time'
};
Expand Down

0 comments on commit f5799f6

Please sign in to comment.