概述

编辑器的算法管理器对象AlgorithmsManager,定义在ThinkEditor.Defined.js文件中。
AlgorithmsManager应当跨文档管理共享知识库算法数据,编辑器默认初始化了一个全局算法管理器对象algorithmsManager实例来管理选项。

import { algorithmsManager } from '@/components/editor/ThinkEditor.Defined';

算法数据的产生

算法数据由如下几种方式产生

  • 方式一:解析文档时如文档有使用算法数据,将产生setAlgorithms.event事件
  • 方式二:利用UI-知识库管理 编辑、新增algorithmsManager对象中的算法数据
  • 方式三:通过调用接口添加算法使用

注意:

  • 算法数据并不是直接加载到文档或编辑器中的,而是跨文档加载到新增到algorithmsManager对象的算法数据中。

方式一:解析文档时setAlgorithms.event事件

算法数据会按需保存到xml中,解析一个文档结束后将产生setAlgorithms.event事件,应用监听编辑器的setAlgorithms.event事件获取算法数据。

示例代码:

添加监听setAlgorithms.event事件
 addEditorEventListener(thinkEditor) {
 ...
  thinkEditor.removeEventListener(E_EVENT_KEY.setAlgorithms, this.OnSetAlgorithms);
 ... 
  }
关闭编辑器时应当移除监听setAlgorithms.event事件 
removeEditorEventListener(thinkEditor) {
 ...
  thinkEditor.removeEventListener(E_EVENT_KEY.setAlgorithms, this.OnSetAlgorithms);
 ... 
  }

方式二:利用UI-知识库管理 编辑、新增

  • 详见Demo algorithmSet.vue algorithmsManager.AddAlgorithm处理
    鼠标右键菜单-知识库

方式三:应用通过接口添加

第三方应用可按如下规则组织算法参数。

  • 详见Demo async PreLoadUserDefinedAlgorithms()处理
  • 用户应当结合自己系统完善PreLoadUserDefinedAlgorithms方法实现

算法参数结构如下
algorithms

[
    {
        "algoGroup": "评分加法",
        "algoMode": 1,
        "algoScope": 1,

    }
]

调用接口

algorithmsManager.AddAlgorithms(algorithms)

算法数据的消费

注意:

  • algorithmsManager中的算法数据有如下的消费场景
    a、提供给UI(算法Comb)
    b、文档按需加载选项数据

a、提供给UI(算法Comb)

运算集

algorithmsManager.algorithms数组中的algoGroup为当前系统支持的选项类

示例使用代码
<el-option v-for="item in algorithmsManager.algorithms" :key="item.algoGroup" :label="item.algoGroup" :value="item.algoGroup"></el-option>

算法和范围

var currentAlgorithmObj = optionsManager.algorithms[i]

  • 选定了一个运算集,则算法和范围就确定了。可在 知识库-算法中修改

currentAlgorithmObj中的algoMode、algoScope分别为算法和范围

角色

角色的可选项固定为 “输入”、“输出”。同一运算集,不同元素(对象)可以按需配置角色。

示例:通过UI给元素配置算法

文档更新时间: 2024-11-20 21:55   作者:admin