Skip to content

Commit 8f13ae0

Browse files
committed
add ontology for TIS
1 parent 117d56d commit 8f13ae0

59 files changed

Lines changed: 3386 additions & 623 deletions

File tree

Some content is hidden

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

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/BasicOntologyPropertyTypeRef.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.qlangtech.tis.plugin.ontology;import com.qlangtech.tis.extension.Describable;import com.qlangtech.tis.extension.Descriptor;import com.qlangtech.tis.manage.common.Option;import com.qlangtech.tis.plugin.annotation.FormField;import com.qlangtech.tis.plugin.annotation.FormFieldType;import com.qlangtech.tis.plugin.ontology.impl.OntologyPluginMeta;import com.qlangtech.tis.plugin.ontology.impl.typeref.DefaultPropertyTypeRef;import com.qlangtech.tis.plugin.ontology.impl.typeref.SharedPropertyTypeRef;import com.qlangtech.tis.runtime.module.action.IParamGetter;import com.qlangtech.tis.util.UploadPluginMeta;import org.apache.commons.lang3.StringUtils;import java.util.List;import java.util.Optional;import java.util.function.BiFunction;import static com.qlangtech.tis.plugin.ontology.OntologyValueType.getMatchedValTypeOptions;/** * * @author 百岁 (baisui@qlangtech.com) * @date 2026/4/24 * @see SharedPropertyTypeRef * @see DefaultPropertyTypeRef */public abstract class BasicOntologyPropertyTypeRef implements Describable<BasicOntologyPropertyTypeRef>, OntologyPropertyTypeRef { public static final String FIELD_VALUE_TYPE = "valueType"; /** * 使用值类型 */ @FormField(ordinal = 2, type = FormFieldType.ENUM, validate = {}) public String valueType; @Override public Optional<String> getValueTypeRef() { return Optional.ofNullable(valueType); }// public abstract Optional<OntologySharedProperty> getSharedPropertyRef();// public abstract OntologyType getOntologyType(); protected static abstract class BasicDesc extends Descriptor<BasicOntologyPropertyTypeRef> { /** * 取得change 事件源头字段名称 * * @return */ protected abstract String getTypeFieldName(); public BasicDesc() { super(); // 定义前端field属性值变化同步管道 this.valueChangePipe(getTypeFieldName(), FIELD_VALUE_TYPE) .render(new BiFunction<UploadPluginMeta, IParamGetter, List<? extends Option>>() { @Override public List<? extends Option> apply(UploadPluginMeta pluginMeta, IParamGetter param) { //JSONObject result = new JSONObject(); Integer ontologyType = Integer.parseInt(getOntologyType(param)); OntologyPluginMeta meta = OntologyPluginMeta.createPluginMeta(pluginMeta); // result.put(FIELD_VALUE_TYPE // // , Option.toJson(getMatchedValTypeOptions(meta, // OntologyType.parse(ontologyType)))); // return result; return getMatchedValTypeOptions(meta, OntologyType.parse(ontologyType)); } }); } protected String getOntologyType(IParamGetter param) { String typeStr = param.getString(getTypeFieldName()); if (StringUtils.isEmpty(typeStr)) { throw new IllegalArgumentException("param '" + getTypeFieldName() + "' can not be empty"); } return (typeStr); } }}

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/ExportToOntologyInDataSource.java

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/InferOntologyFromLLMHost.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.qlangtech.tis.plugin.ontology;
22

3+
import com.alibaba.citrus.turbine.Context;
34
import com.alibaba.fastjson.JSONObject;
4-
import com.qlangtech.tis.extension.Descriptor;
55
import com.qlangtech.tis.extension.DescriptorUseableShortComment;
66
import com.qlangtech.tis.extension.MultiStepsSupportHost;
77
import com.qlangtech.tis.extension.MultiStepsSupportHostDescriptor;
@@ -10,14 +10,19 @@
1010
import com.qlangtech.tis.plugin.IEndTypeGetter;
1111
import com.qlangtech.tis.plugin.IPluginStore;
1212
import com.qlangtech.tis.plugin.IdentityName;
13+
import com.qlangtech.tis.plugin.ds.manipulate.ManipulateItemsProcessor;
14+
import com.qlangtech.tis.plugin.ontology.impl.OntologyPluginMeta;
15+
import com.qlangtech.tis.plugin.ontology.impl.infer.DeserializeOntologyRes;
1316
import com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1;
1417
import com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep2Execute;
1518
import com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep2Prompt;
1619
import com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep3Execute;
1720
import com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep3Prompt;
21+
import com.qlangtech.tis.util.IPluginContext;
1822

1923
import java.util.List;
2024
import java.util.Objects;
25+
import java.util.Optional;
2126

2227
/**
2328
*
@@ -33,6 +38,20 @@ public void setSteps(OneStepOfMultiSteps[] stepsPlugin) {
3338
this._stepsPlugin = Objects.requireNonNull(stepsPlugin, "stepsPlugin can not be null");
3439
}
3540

41+
@Override
42+
protected void afterManipuldateProcess(IPluginContext pluginContext
43+
, Optional<Context> context, ManipulateItemsProcessor itemsProcessor) {
44+
// super.afterManipuldateProcess(pluginContext, context, itemsProcessor);
45+
OntologyPluginMeta meta = OntologyPluginMeta.createPluginMeta(itemsProcessor.getPluginMeta());
46+
DeserializeOntologyRes ontologyRes
47+
= DeserializeOntologyRes.getDomainInferResult(meta.getDomain());
48+
// 创建实例,并且在注册器中注销
49+
int createResCount = ontologyRes.create(pluginContext);
50+
if (createResCount > 0) {
51+
pluginContext.addActionMessage(context.orElseThrow(), "已经成功创建" + createResCount + "条Ontology(本体)资源");
52+
}
53+
}
54+
3655
@Override
3756
public OneStepOfMultiSteps[] getMultiStepsSavedItems() {
3857
return this._stepsPlugin;
@@ -41,11 +60,11 @@ public OneStepOfMultiSteps[] getMultiStepsSavedItems() {
4160

4261
@Override
4362
public String identityValue() {
44-
return "";
63+
return "infer_ontology_from_llm";
4564
}
4665

4766
@TISExtension
48-
public static class DftDesc extends Descriptor<InferOntologyFromLLMHost> implements MultiStepsSupportHostDescriptor<InferOntologyFromLLMHost>, IEndTypeGetter, DescriptorUseableShortComment {
67+
public static class DftDesc extends BasicDesc implements MultiStepsSupportHostDescriptor<InferOntologyFromLLMHost>, IEndTypeGetter, DescriptorUseableShortComment {
4968

5069
@Override
5170
public Class<InferOntologyFromLLMHost> getHostClass() {

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/OntologyPropertyTypeRef.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/StreamingJsonOntologyParser.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import java.io.PrintStream;
2828
import java.util.Objects;
2929

30-
import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_GLOSSARIES;
31-
import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_LINK_TYPES;
32-
import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_SHARED_PROPERTIES;
33-
import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_VALUE_TYPES;
30+
//import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_GLOSSARIES;
31+
//import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_LINK_TYPES;
32+
//import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_SHARED_PROPERTIES;
33+
//import static com.qlangtech.tis.plugin.ontology.impl.infer.InferOntologyFromLLMStep1.KEY_VALUE_TYPES;
3434

3535
/**
3636
* 流式 JSON 解析器,用于增量反序列化 LLM 返回的本体推断结果
@@ -58,6 +58,10 @@ public class StreamingJsonOntologyParser {
5858
private boolean escapeNext = false;
5959
private int processedUpTo = 0; // Track how much of the buffer we've processed
6060

61+
62+
public StreamingJsonOntologyParser() {
63+
}
64+
6165
public interface Callbacks {
6266
void onLinkType(JSONObject element);
6367

@@ -173,13 +177,14 @@ public void parse() throws IOException {
173177
}
174178

175179
String fieldName = json.substring(i + 1, closingQuote);
176-
if (KEY_LINK_TYPES.equals(fieldName)) {
180+
181+
if (Ontology.OntologyEnum.Linker.typeIdentity.equals(fieldName)) {
177182
currentArray = CurrentArray.LINK_TYPES;
178-
} else if (KEY_SHARED_PROPERTIES.equals(fieldName)) {
183+
} else if (Ontology.OntologyEnum.SharedProperty.typeIdentity.equals(fieldName)) {
179184
currentArray = CurrentArray.SHARED_PROPERTIES;
180-
} else if (KEY_VALUE_TYPES.equals(fieldName)) {
185+
} else if (Ontology.OntologyEnum.ValueType.typeIdentity.equals(fieldName)) {
181186
currentArray = CurrentArray.VALUE_TYPES;
182-
} else if (KEY_GLOSSARIES.equals(fieldName)) {
187+
} else if (Ontology.OntologyEnum.Glossary.typeIdentity.equals(fieldName)) {
183188
currentArray = CurrentArray.GLOSSARIES;
184189
}
185190
// unknown field: just skip past the closing quote and keep currentArray as-is

tis-ontology-plugin/src/main/java/com/qlangtech/tis/plugin/ontology/impl/glossary/DefaultOntologyGlossary.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
import com.alibaba.citrus.turbine.Context;
2121
import com.qlangtech.tis.extension.TISExtension;
2222
import com.qlangtech.tis.plugin.IPluginStore;
23+
import com.qlangtech.tis.plugin.datax.transformer.UDFDesc;
24+
import com.qlangtech.tis.plugin.ds.BasicMultiSelectSingleValElementCreatorFactory;
2325
import com.qlangtech.tis.plugin.ontology.Ontology;
2426
import com.qlangtech.tis.plugin.ontology.OntologyGlossary;
2527
import com.qlangtech.tis.plugin.ontology.impl.OntologyPluginMeta;
2628
import com.qlangtech.tis.plugin.ontology.sync.OntologyNeo4jSyncService;
2729
import com.qlangtech.tis.plugin.ontology.sync.OntologySyncQueue;
2830
import com.qlangtech.tis.util.IPluginContext;
2931

32+
import com.google.common.collect.Lists;
33+
34+
import java.util.List;
3035
import java.util.Optional;
3136

3237
/**
@@ -48,6 +53,21 @@ protected void sync() {
4853
});
4954
}
5055

56+
@Override
57+
public List<UDFDesc> getLiteria() {
58+
List<UDFDesc> literia = Lists.newArrayList();
59+
literia.add(new UDFDesc("Term", this.term));
60+
literia.add(new UDFDesc("Description", this.description));
61+
// Synonyms: join all synonym values as a comma-separated string
62+
List<String> synonymVals = this.getSynonyms().stream()
63+
.map(BasicMultiSelectSingleValElementCreatorFactory.OneOfMultiElement::getEnumVal)
64+
.collect(java.util.stream.Collectors.toList());
65+
literia.add(new UDFDesc("Synonyms", String.join(", ", synonymVals)));
66+
// Target: use getTargetLiteral() which provides a meaningful description of the target
67+
literia.add(new UDFDesc("Target", this.target.getTargetLiteral()));
68+
return literia;
69+
}
70+
5171
@TISExtension
5272
public static class DefaultDesc extends Ontology.BasicDesc {
5373
public DefaultDesc() {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.qlangtech.tis.plugin.ontology.impl.infer;
2+
3+
import com.alibaba.citrus.turbine.Context;
4+
import com.alibaba.fastjson.JSONArray;
5+
import com.alibaba.fastjson.JSONObject;
6+
import com.google.common.collect.Lists;
7+
import com.qlangtech.tis.extension.IPropertyType;
8+
import com.qlangtech.tis.extension.OneStepOfMultiSteps;
9+
import com.qlangtech.tis.plugin.ds.CMeta;
10+
import com.qlangtech.tis.plugin.ds.ElementCreatorFactory;
11+
import com.qlangtech.tis.plugin.ds.ViewContent;
12+
import com.qlangtech.tis.plugin.ontology.Ontology;
13+
import com.qlangtech.tis.plugin.ontology.impl.OntologyPluginMeta;
14+
import com.qlangtech.tis.plugin.ontology.impl.glossary.DefaultOntologyGlossary;
15+
import com.qlangtech.tis.runtime.module.misc.IControlMsgHandler;
16+
import com.qlangtech.tis.util.DescriptorsJSON;
17+
import org.apache.commons.lang3.StringUtils;
18+
19+
import javax.ws.rs.NotSupportedException;
20+
import java.util.List;
21+
import java.util.Set;
22+
import java.util.function.BiConsumer;
23+
24+
import static com.qlangtech.tis.plugin.ontology.OntologyDomain.NAME_ONTOLOGY_DOMAIN;
25+
26+
/**
27+
*
28+
* @author 百岁 (baisui@qlangtech.com)
29+
* @date 2026/6/8
30+
*/
31+
public abstract class BaseInferenceParseCreatorFactory implements ElementCreatorFactory<InferenceParse<?>> {
32+
@Override
33+
public final CMeta.ParsePostMCols<InferenceParse<?>> parsePostMCols(IPropertyType propertyType
34+
, IControlMsgHandler msgHandler, Context context, String keyColsMeta, JSONArray targetCols) {
35+
CMeta.ParsePostMCols<InferenceParse<?>> mCols = new CMeta.ParsePostMCols<>();
36+
for (Object c : targetCols) {
37+
if (c instanceof JSONObject col) {
38+
Integer id = col.getInteger("id");
39+
Boolean selected = col.getBoolean("selected");
40+
InferenceParse<DefaultOntologyGlossary> defaultInterence = createDefaultInterence(id);
41+
// JSON 中没有该字段,视为"默认选中",返回 true
42+
defaultInterence.setSelected(selected == null || selected);
43+
mCols.writerCols.add(defaultInterence);
44+
} else {
45+
throw new IllegalStateException("type of c:" + c.getClass().getName() + " must be " + JSONObject.class.getName());
46+
}
47+
}
48+
return mCols;
49+
}
50+
51+
@Override
52+
public final String getTuplesKey() {
53+
return "_inferResults";
54+
}
55+
56+
@Override
57+
public final void appendExternalJsonProp(IPropertyType propertyType, JSONObject biz) {
58+
//ElementCreatorFactory.super.appendExternalJsonProp(propertyType, biz);
59+
OntologyPluginMeta pluginMeta = OntologyPluginMeta.createPluginMeta();
60+
DeserializeOntologyRes inferOntologyRes = DeserializeOntologyRes.getDomainInferResult(pluginMeta.getDomain());
61+
List<InferenceParse> inferenceResult = inferOntologyRes.getTargetInferenceParseResult( //
62+
getSupportOntologyEnum());
63+
64+
biz.put("inferenceResult", Lists.reverse(inferenceResult));
65+
biz.put(DescriptorsJSON.KEY_IMPL, getInferOntologyFromLLMExecuteClass().getName());
66+
biz.put(NAME_ONTOLOGY_DOMAIN, pluginMeta.getDomain());
67+
}
68+
69+
protected abstract Set<Ontology.OntologyEnum> getSupportOntologyEnum();
70+
71+
protected abstract Class<? extends OneStepOfMultiSteps> getInferOntologyFromLLMExecuteClass();
72+
73+
@Override
74+
public final ViewContent getViewContentType() {
75+
return ViewContent.OntologyResInference;
76+
}
77+
78+
@Override
79+
public InferenceParse<?> createDefault(JSONObject targetCol) {
80+
return createDefaultInterence(0);
81+
}
82+
83+
private static InferenceParse<DefaultOntologyGlossary> createDefaultInterence(Integer id) {
84+
return new InferenceParse<>(id, DeserializeOntologyRes.InferBatch.LinkTypeBatch
85+
, StringUtils.EMPTY, InferenceParse.InferenceConfidence.Low, new DefaultOntologyGlossary());
86+
}
87+
88+
@Override
89+
public InferenceParse<?> create(JSONObject targetCol, BiConsumer<String, String> errorProcess) {
90+
throw new NotSupportedException();
91+
}
92+
}

0 commit comments

Comments
 (0)