开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
3 Star 4 Fork 4

ToolGood/ToolGood.Algorithm

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (7)
标签 (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
master
分支 (7)
标签 (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (7)
标签 (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
ToolGood.Algorithm
/
JavaScript
/
src
/
AlgorithmEngineHelper.js
ToolGood.Algorithm
/
JavaScript
/
src
/
AlgorithmEngineHelper.js
AlgorithmEngineHelper.js 10.82 KB
一键复制 编辑 原始数据 按行查看 历史
sshuicn 提交于 2026年02月07日 13:43 +08:00 . fix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
import { CharUtil } from './Internals/Visitors/CharUtil.js';
import { AntlrCharStream } from './Internals/Visitors/AntlrCharStream.js';
import { AntlrErrorTextWriter } from './Internals/Visitors/AntlrErrorTextWriter.js';
import { DiyNameVisitor } from './Internals/Visitors/DiyNameVisitor.js';
import { MathFunctionVisitor } from './Internals/Visitors/MathFunctionVisitor.js';
import { MathSplitVisitor } from './Internals/Visitors/MathSplitVisitor.js';
import { MathSplitVisitor2 } from './Internals/Visitors/MathSplitVisitor2.js';
import { Function_AND } from './Internals/Functions/Operator/Function_AND.js';
import { Function_OR } from './Internals/Functions/Operator/Function_OR.js';
import { Function_Add } from './Internals/Functions/Operator/Function_Add.js';
import { Function_Sub } from './Internals/Functions/Operator/Function_Sub.js';
import { Function_Mul } from './Internals/Functions/Operator/Function_Mul.js';
import { Function_Div } from './Internals/Functions/Operator/Function_Div.js';
import { Function_Mod } from './Internals/Functions/Operator/Function_Mod.js';
import { Function_Connect } from './Internals/Functions/Operator/Function_Connect.js';
import { DistanceConverter } from './UnitConversion/DistanceConverter.js';
import { MassConverter } from './UnitConversion/MassConverter.js';
import { AreaConverter } from './UnitConversion/AreaConverter.js';
import { VolumeConverter } from './UnitConversion/VolumeConverter.js';
import { ConditionTreeType } from './Enums/ConditionTreeType.js';
import { CalculateTreeType } from './Enums/CalculateTreeType.js';
// 导入ANTLR生成的文件
import mathLexer from './math/mathLexer.js';
import CommonTokenStream from './antlr4/CommonTokenStream.js';
import mathParser from './math/mathParser.js';
/**
* 算法引擎助手
*/
export class AlgorithmEngineHelper {
static unitRegex = null;
/**
* 是不是参数
*/
static IsParameter(parameter) {
if (!parameter || parameter.trim() === '') { return false; }
try {
let diy = this.GetDiyNames(parameter);
if (diy.Functions && diy.Functions.length > 0) { return false; }
if (diy.Parameters && diy.Parameters.length === 1) {
let p = diy.Parameters[0];
return p.Name === parameter;
}
} catch (ex) { }
return false;
}
/**
* 获取 DIY 名称
*/
static GetDiyNames(exp) {
if (!exp || exp.trim() === '') {
throw new Error("Parameter exp invalid !");
}
let antlrErrorTextWriter = new AntlrErrorTextWriter();
let stream =new AntlrCharStream(exp);
let lexer = new mathLexer(stream, null, antlrErrorTextWriter);
lexer.removeErrorListeners();
lexer.addErrorListener(antlrErrorTextWriter);
let tokens = new CommonTokenStream(lexer);
let parser = new mathParser(tokens, null, antlrErrorTextWriter);
parser.removeErrorListeners();
parser.addErrorListener(antlrErrorTextWriter);
let context = parser.prog();
if (antlrErrorTextWriter.IsError) {
throw new Error(antlrErrorTextWriter.ErrorMsg);
}
let visitor = new DiyNameVisitor();
visitor.visit(context);
return visitor.diy;
}
/**
* 单位转换
*/
static UnitConversion(src, oldSrcUnit, oldTarUnit, name = null) {
if (!oldSrcUnit || !oldTarUnit) { return src; }
if (!this.unitRegex) {
this.unitRegex = /[\s\(\)()\[\]<>]/g;
}
oldSrcUnit = oldSrcUnit.replace(this.unitRegex, "");
if (oldSrcUnit === oldTarUnit) { return src; }
if (DistanceConverter.Exists(oldSrcUnit, oldTarUnit)) {
let c = new DistanceConverter(oldSrcUnit, oldTarUnit);
return c.LeftToRight(src);
}
if (MassConverter.Exists(oldSrcUnit, oldTarUnit)) {
let c = new MassConverter(oldSrcUnit, oldTarUnit);
return c.LeftToRight(src);
}
if (AreaConverter.Exists(oldSrcUnit, oldTarUnit)) {
let c = new AreaConverter(oldSrcUnit, oldTarUnit);
return c.LeftToRight(src);
}
if (VolumeConverter.Exists(oldSrcUnit, oldTarUnit)) {
let c = new VolumeConverter(oldSrcUnit, oldTarUnit);
return c.LeftToRight(src);
}
if (!name) {
throw new Error(`The input item has different units and cannot be converted from [${oldSrcUnit}] to [${oldTarUnit}]`);
}
throw new Error(`The input item [${name}] has different units and cannot be converted from [${oldSrcUnit}] to [${oldTarUnit}]`);
}
/**
* 编译公式
*/
static ParseFormula(exp,errorListener) {
if (!exp || exp.trim() === '') {
throw new Error("Parameter exp invalid !");
}
let antlrErrorTextWriter = new AntlrErrorTextWriter();
let stream =new AntlrCharStream(exp);
let lexer = new mathLexer(stream, null, antlrErrorTextWriter);
lexer.removeErrorListeners();
lexer.addErrorListener(antlrErrorTextWriter);
let tokens = new CommonTokenStream(lexer);
let parser = new mathParser(tokens, null, antlrErrorTextWriter);
parser.removeErrorListeners();
parser.addErrorListener(antlrErrorTextWriter);
if (errorListener) {
parser.addErrorListener(errorListener);
let context = parser.prog();
let visitor = new MathFunctionVisitor();
return visitor.visit(context);
}
let context = parser.prog();
if (antlrErrorTextWriter.IsError) {
throw new Error(antlrErrorTextWriter.ErrorMsg);
}
let visitor = new MathFunctionVisitor();
return visitor.visit(context);
}
/**
* 检查公式是否正确
*/
static CheckFormula(exp) {
if (!exp || exp.trim() === '') { return false; }
let antlrErrorTextWriter = new AntlrErrorTextWriter();
let stream =new AntlrCharStream(exp);
let lexer = new mathLexer(stream, null, antlrErrorTextWriter);
lexer.removeErrorListeners();
lexer.addErrorListener(antlrErrorTextWriter);
let tokens = new CommonTokenStream(lexer);
let parser = new mathParser(tokens, null, antlrErrorTextWriter);
parser.removeErrorListeners();
parser.addErrorListener(antlrErrorTextWriter);
let context = parser.prog();
if (antlrErrorTextWriter.IsError) {
return false;
}
return true;
}
/**
* 解析条件
*/
static ParseCondition(condition) {
let tree = {
Type: null,
ErrorMessage: null
};
if (!condition || condition.trim() === '') {
tree.Type = ConditionTreeType.Error;
tree.ErrorMessage = "condition is null";
return tree;
}
try {
let antlrErrorTextWriter = new AntlrErrorTextWriter();
let stream =new AntlrCharStream(condition);
let lexer = new mathLexer(stream, null, antlrErrorTextWriter);
lexer.removeErrorListeners();
lexer.addErrorListener(antlrErrorTextWriter);
let tokens = new CommonTokenStream(lexer);
let parser = new mathParser(tokens, null, antlrErrorTextWriter);
parser.removeErrorListeners();
parser.addErrorListener(antlrErrorTextWriter);
let context = parser.prog();
if (antlrErrorTextWriter.IsError) {
tree.Type = ConditionTreeType.Error;
tree.ErrorMessage = antlrErrorTextWriter.ErrorMsg;
return tree;
}
let visitor = new MathSplitVisitor();
return visitor.visit(context);
} catch (ex) {
tree.Type = ConditionTreeType.Error;
tree.ErrorMessage = ex.message;
}
return tree;
}
/**
* Creates a logical AND function that combines two specified functions.
*/
static Condition_And(left, right) {
return new Function_AND(left, right);
}
/**
* Creates a logical OR function that combines two specified functions.
*/
static Condition_Or(left, right) {
return new Function_OR(left, right);
}
/**
* 解析计算表达式
*/
static ParseCalculate(exp) {
let tree = {
Type: null,
ErrorMessage: null
};
if (!exp || exp.trim() === '') {
tree.Type = CalculateTreeType.Error;
tree.ErrorMessage = "exp is null";
return tree;
}
try {
let antlrErrorTextWriter = new AntlrErrorTextWriter();
let stream =new AntlrCharStream(exp);
let lexer = new mathLexer(stream, null, antlrErrorTextWriter);
lexer.removeErrorListeners();
lexer.addErrorListener(antlrErrorTextWriter);
let tokens = new CommonTokenStream(lexer);
let parser = new mathParser(tokens, null, antlrErrorTextWriter);
parser.removeErrorListeners();
parser.addErrorListener(antlrErrorTextWriter);
let context = parser.prog();
if (antlrErrorTextWriter.IsError) {
tree.Type = CalculateTreeType.Error;
tree.ErrorMessage = antlrErrorTextWriter.ErrorMsg;
return tree;
}
let visitor = new MathSplitVisitor2();
return visitor.visit(context);
} catch (ex) {
tree.Type = CalculateTreeType.Error;
tree.ErrorMessage = ex.message;
}
return tree;
}
/**
* Creates a function that represents the sum of two specified functions.
*/
static Calculate_Add(left, right) {
return new Function_Add(left, right);
}
/**
* Creates a function that represents the subtraction of two functions.
*/
static Calculate_Subtract(left, right) {
return new Function_Sub(left, right);
}
/**
* Creates a function that represents the multiplication of two functions.
*/
static Calculate_Multiply(left, right) {
return new Function_Mul(left, right);
}
/**
* Creates a function that represents the division of two functions.
*/
static Calculate_Divide(left, right) {
return new Function_Div(left, right);
}
/**
* Creates a function that computes the remainder after dividing the result of the left function by the result of the
* right function.
*/
static Calculate_Mod(left, right) {
return new Function_Mod(left, right);
}
/**
* Creates a new function that represents the connection of two functions.
*/
static Calculate_Connect(left, right) {
return new Function_Connect(left, right);
}
}
// 浏览器支持
if (typeof window !== 'undefined') {
window.AlgorithmEngineHelper = AlgorithmEngineHelper;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

ToolGood.Algorithm是一个功能强大、轻量级、兼容Excel公式的算法类库,旨在提高开发人员在不同业务场景中的生产力。
暂无标签
未知许可证
查看未知开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/toolgood/ToolGood.Algorithm.git
git@gitee.com:toolgood/ToolGood.Algorithm.git
toolgood
ToolGood.Algorithm
ToolGood.Algorithm
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /