mirror of
https://github.com/OpenSPG/openspg.git
synced 2025-12-17 10:15:04 +00:00
feat(reasoner): add config in UdfMng (#391)
Co-authored-by: FishJoy <chengqiang.cq@antgroup.com>
This commit is contained in:
parent
37514d94f5
commit
84b9209ed9
@ -85,4 +85,7 @@ public class Constants {
|
|||||||
Sets.newHashSet("isA", "locateAt");
|
Sets.newHashSet("isA", "locateAt");
|
||||||
|
|
||||||
public static final String CONCEPT_EDGE_EXPAND_FUNC_NAME = "concept_edge_expand";
|
public static final String CONCEPT_EDGE_EXPAND_FUNC_NAME = "concept_edge_expand";
|
||||||
|
|
||||||
|
/** allow throw exception in udf */
|
||||||
|
public static final String ALLOW_UDF_EXCEPTION = "allowUDFThrowException";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,11 +13,16 @@
|
|||||||
|
|
||||||
package com.antgroup.openspg.reasoner.udf.builtin.udf;
|
package com.antgroup.openspg.reasoner.udf.builtin.udf;
|
||||||
|
|
||||||
|
import com.antgroup.openspg.reasoner.common.constants.Constants;
|
||||||
|
import com.antgroup.openspg.reasoner.udf.impl.UdfMngImpl;
|
||||||
import com.antgroup.openspg.reasoner.udf.model.UdfDefine;
|
import com.antgroup.openspg.reasoner.udf.model.UdfDefine;
|
||||||
|
import java.util.Map;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class ContainsAny {
|
public class ContainsAny {
|
||||||
|
|
||||||
|
public ContainsAny() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains any function. Return true if the first element of the input array (a string) contains
|
* Contains any function. Return true if the first element of the input array (a string) contains
|
||||||
* one or more of the remaining elements, otherwise return false. Such as: 1."adfvg", ["as, "gv"]
|
* one or more of the remaining elements, otherwise return false. Such as: 1."adfvg", ["as, "gv"]
|
||||||
@ -53,6 +58,12 @@ public class ContainsAny {
|
|||||||
*/
|
*/
|
||||||
@UdfDefine(name = "contains_any", compatibleName = "contains")
|
@UdfDefine(name = "contains_any", compatibleName = "contains")
|
||||||
public boolean contains(String toCheckedStr, String keyword) {
|
public boolean contains(String toCheckedStr, String keyword) {
|
||||||
|
Map<String, Object> configMap = UdfMngImpl.sceneConfigMap.get();
|
||||||
|
Boolean allowUDFThrowException =
|
||||||
|
(Boolean) configMap.getOrDefault(Constants.ALLOW_UDF_EXCEPTION, false);
|
||||||
|
if ((toCheckedStr == null || keyword == null) && allowUDFThrowException) {
|
||||||
|
throw new RuntimeException("contains_any arguments is null");
|
||||||
|
}
|
||||||
if (StringUtils.isEmpty(toCheckedStr) || null == keyword) {
|
if (StringUtils.isEmpty(toCheckedStr) || null == keyword) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,9 @@ public class UdfMngImpl implements UdfMng {
|
|||||||
|
|
||||||
private static volatile UdfMngImpl instance = null;
|
private static volatile UdfMngImpl instance = null;
|
||||||
|
|
||||||
|
public static ThreadLocal<Map<String, Object>> sceneConfigMap =
|
||||||
|
ThreadLocal.withInitial(HashMap::new);
|
||||||
|
|
||||||
/** 单例 */
|
/** 单例 */
|
||||||
public static UdfMngImpl getInstance() {
|
public static UdfMngImpl getInstance() {
|
||||||
if (null == instance) {
|
if (null == instance) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user