This commit is contained in:
baifuyu 2023-12-11 20:46:18 +08:00
parent 687906c0ae
commit f18648c86b
11 changed files with 50 additions and 20 deletions

View File

@ -30,7 +30,7 @@ public class PythonOperatorFactory implements OperatorFactory {
private static PythonInterpreter newPythonInterpreter(BuilderContext context) {
String pythonExec = context.getPythonExec();
String[] pythonPaths =
(context.getPythonPaths() != null ? context.getPythonPaths().split(",") : null);
(context.getPythonPaths() != null ? context.getPythonPaths().split(";") : null);
PythonInterpreterConfig.PythonInterpreterConfigBuilder builder =
PythonInterpreterConfig.newBuilder();

View File

@ -23,9 +23,9 @@ import lombok.Setter;
public class InvokeResult {
private String spgTypeName;
private Map<String, String> props;
private Map<String, String> properties;
public String getId() {
return props.get("id");
return properties.get("id");
}
}

View File

@ -55,7 +55,7 @@ public class UserDefinedExtractProcessor
for (InvokeResult data : invokeResultWrapper.getData()) {
results.add(
new BuilderRecord(
null, SPGTypeIdentifier.parse(data.getSpgTypeName()), data.getProps()));
null, SPGTypeIdentifier.parse(data.getSpgTypeName()), data.getProperties()));
}
}
return results;

View File

@ -35,7 +35,7 @@ public class BasicPropertyNormalizer implements PropertyNormalizer {
break;
}
} catch (NumberFormatException e) {
throw new PropertyNormalizeException(e, "");
throw new PropertyNormalizeException(e, "{} normalize error", rawValue);
}
record.getValue().setSingleStd(stdValue);
}

View File

@ -14,8 +14,10 @@ import com.antgroup.openspg.common.util.StringUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@Slf4j
@SuppressWarnings("unchecked")
public class PropertyOperatorNormalizer implements PropertyNormalizer {
@ -40,13 +42,18 @@ public class PropertyOperatorNormalizer implements PropertyNormalizer {
List<String> ids = new ArrayList<>(rawValues.size());
for (String rawValue : rawValues) {
Map<String, Object> result =
(Map<String, Object>)
operatorFactory.invoke(
normalizerConfig.getOperatorConfig(), rawValue, new HashMap<>(0));
InvokeResultWrapper<List<InvokeResult>> invokeResultWrapper =
mapper.convertValue(
result, new TypeReference<InvokeResultWrapper<List<InvokeResult>>>() {});
InvokeResultWrapper<List<InvokeResult>> invokeResultWrapper = null;
try {
Map<String, Object> result =
(Map<String, Object>)
operatorFactory.invoke(
normalizerConfig.getOperatorConfig(), rawValue, new HashMap<>(0));
invokeResultWrapper =
mapper.convertValue(
result, new TypeReference<InvokeResultWrapper<List<InvokeResult>>>() {});
} catch (Exception e) {
throw new PropertyNormalizeException(e, "{} normalize error", rawValue);
}
if (invokeResultWrapper == null || CollectionUtils.isEmpty(invokeResultWrapper.getData())) {
continue;

View File

@ -39,7 +39,13 @@ public class PropertySearchNormalizer implements PropertyNormalizer {
if (!objectTypeRef.isEntityType() && !objectTypeRef.isConceptType()) {
ids.add(rawValue);
} else {
ids.add(search(objectTypeRef, rawValue));
String searchResult = null;
try {
searchResult = search(objectTypeRef, rawValue);
} catch (Exception e) {
throw new PropertyNormalizeException(e, "{} normalize error", rawValue);
}
ids.add(searchResult);
}
}
record.getValue().setStds(Collections.singletonList(ids));

View File

@ -61,4 +61,9 @@ public class SPGSubPropertyRecord extends BasePropertyRecord implements WithSPGT
public SPGTypeEnum getSpgTypeEnum() {
return getSubProperty().getObjectTypeRef().getSpgTypeEnum();
}
@Override
public String toString() {
return subProperty.getName();
}
}

View File

@ -21,9 +21,11 @@ import com.antgroup.openspg.server.api.facade.dto.schema.request.ProjectSchemaRe
import com.antgroup.openspg.server.api.http.client.HttpSchemaFacade;
import com.antgroup.openspg.server.api.http.client.util.ConnectionInfo;
import com.antgroup.openspg.server.api.http.client.util.HttpClientBootstrap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.*;
import org.slf4j.LoggerFactory;
@Slf4j
public class LocalBuilderMain {
private static final String PROJECT_ID_OPTION = "projectId";
@ -36,9 +38,14 @@ public class LocalBuilderMain {
private static final String ALTER_OPERATION_OPTION = "alterOperation";
private static final String LOG_FILE_OPTION = "logFile";
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
CommandLine commandLine = parseArgs(args);
run(commandLine);
try {
run(commandLine);
} catch (Throwable e) {
log.error("unknown exception.", e);
System.exit(0);
}
}
public static CommandLine parseArgs(String[] args) {

View File

@ -14,7 +14,7 @@ from typing import List
from knext.operator.op import LinkOp
from knext.client.search import SearchClient
from operator.spg_record import SPGRecord
from knext.operator.spg_record import SPGRecord
class CertLinkerOperator(LinkOp):
@ -28,8 +28,8 @@ class CertLinkerOperator(LinkOp):
has_cert = property
query = {"match": {"certNum": has_cert}}
recall_certs = self.search_client.search(query, start=0, size=10)
if recall_certs is not None:
if recall_certs is not None and len(recall_certs) > 0:
return [
SPGRecord('RiskMining.Cert', {'id': recall_certs[0].doc_id})
]
return [SPGRecord('RiskMining.Cert', {})]
return [SPGRecord('RiskMining.Cert', {'id': property})]

View File

@ -122,14 +122,14 @@ class SPGRecord:
def to_dict(self):
"""Returns the model properties as a dict"""
return {
"SPGTypeName": self.spg_type_name,
"spgTypeName": self.spg_type_name,
"properties": self.properties,
}
@classmethod
def from_dict(cls, input: Dict[str, Any]):
"""Returns the model from a dict"""
return cls(input.get("SPGTypeName"), input.get("properties"))
return cls(input.get("spgTypeName"), input.get("properties"))
def __repr__(self):
"""For `print` and `pprint`"""

View File

@ -117,4 +117,9 @@ public class Property extends BaseSpoTriple
this.getProjectId(),
this.getOntologyId());
}
@Override
public String toString() {
return getName();
}
}