diff --git a/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingHelper.java b/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingHelper.java index bf7695d0..74c7eecb 100644 --- a/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingHelper.java +++ b/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingHelper.java @@ -23,15 +23,13 @@ import com.antgroup.openspg.builder.core.strategy.predicting.RecordPredicting; import com.antgroup.openspg.builder.core.strategy.predicting.RecordPredictingImpl; import com.antgroup.openspg.builder.model.exception.BuilderRecordException; import com.antgroup.openspg.builder.model.pipeline.config.SPGTypeMappingNodeConfig; -import com.antgroup.openspg.builder.model.record.BaseAdvancedRecord; -import com.antgroup.openspg.builder.model.record.BaseSPGRecord; -import com.antgroup.openspg.builder.model.record.BuilderRecord; -import com.antgroup.openspg.builder.model.record.RelationRecord; +import com.antgroup.openspg.builder.model.record.*; import com.antgroup.openspg.cloudext.interfaces.graphstore.adapter.util.EdgeRecordConvertor; import com.antgroup.openspg.cloudext.interfaces.graphstore.adapter.util.VertexRecordConvertor; import com.antgroup.openspg.common.util.StringUtils; import com.antgroup.openspg.core.schema.model.BaseOntology; import com.antgroup.openspg.core.schema.model.identifier.BaseSPGIdentifier; +import com.antgroup.openspg.core.schema.model.identifier.ConceptIdentifier; import com.antgroup.openspg.core.schema.model.identifier.SPGIdentifierTypeEnum; import com.antgroup.openspg.core.schema.model.identifier.SPGTypeIdentifier; import com.antgroup.openspg.core.schema.model.type.BaseSPGType; @@ -113,11 +111,19 @@ public class SPGTypeMappingHelper { return true; } - public List toSPGRecords(BuilderRecord record) { + public List toSPGRecords(BuilderRecord record, boolean first) { Map propertyValues = propertyMapping(record); - Map relationValues = relationMapping(record); List results = new ArrayList<>(); + if (first && spgType.isConceptType()) { + List fatherConcepts = hypernymPredicate(record, propertyValues); + for (BuilderRecord fatherConcept : fatherConcepts) { + results.addAll(toSPGRecords(fatherConcept, false)); + } + } + + Map relationValues = relationMapping(record); + List advancedRecords = toAdvancedRecord(propertyValues, relationValues); for (BaseAdvancedRecord advancedRecord : advancedRecords) { if (CollectionUtils.isNotEmpty(advancedRecord.getRelationRecords())) { @@ -155,6 +161,25 @@ public class SPGTypeMappingHelper { return propertyValues; } + private List hypernymPredicate( + BuilderRecord record, Map propertyValues) { + String bizId = propertyValues.get("id"); + if (StringUtils.isBlank(bizId)) { + throw new BuilderRecordException("id is not in propertyValues"); + } + + List fatherBuilderRecord = new ArrayList<>(); + String fatherId = new ConceptIdentifier(bizId).getFatherId(); + while (StringUtils.isNotBlank(fatherId)) { + Map fatherProps = new HashMap<>(1); + fatherProps.put(config.getSourceFromTarget("id"), fatherId); + fatherBuilderRecord.add(record.withNewProps(fatherProps)); + + fatherId = new ConceptIdentifier(fatherId).getFatherId(); + } + return fatherBuilderRecord; + } + public Map relationMapping(BuilderRecord record) { List relationMappingConfigs = config.getRelationLinkingConfigs(); @@ -194,7 +219,7 @@ public class SPGTypeMappingHelper { Map propertyValues, Map relationValues) { String bizId = propertyValues.get("id"); if (StringUtils.isBlank(bizId)) { - throw new BuilderRecordException(""); + throw new BuilderRecordException("id is not in propertyValues"); } BaseAdvancedRecord advancedRecord = diff --git a/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingProcessor.java b/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingProcessor.java index d5c3ec2d..7d37a6d0 100644 --- a/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingProcessor.java +++ b/builder/core/src/main/java/com/antgroup/openspg/builder/core/physical/process/SPGTypeMappingProcessor.java @@ -89,6 +89,6 @@ public class SPGTypeMappingProcessor extends BaseProcessor - 4.0.0 diff --git a/server/core/schema/model/src/main/java/com/antgroup/openspg/core/schema/model/identifier/ConceptIdentifier.java b/server/core/schema/model/src/main/java/com/antgroup/openspg/core/schema/model/identifier/ConceptIdentifier.java index 579f6c7c..ceb6ba2d 100644 --- a/server/core/schema/model/src/main/java/com/antgroup/openspg/core/schema/model/identifier/ConceptIdentifier.java +++ b/server/core/schema/model/src/main/java/com/antgroup/openspg/core/schema/model/identifier/ConceptIdentifier.java @@ -24,6 +24,8 @@ public class ConceptIdentifier extends BaseSPGIdentifier { /** The seperator symbol between parent and child concept names. */ public static final String SEPARATOR = "-"; + private static final String ROOT = "__ROOT__"; + /** Unique id of concept node. */ private final String id; @@ -51,8 +53,11 @@ public class ConceptIdentifier extends BaseSPGIdentifier { public String getFatherId() { String[] splits = id.split(SEPARATOR); - if (splits.length <= 1) { + if (ROOT.equals(id)) { return StringUtils.EMPTY; + } + if (splits.length <= 1) { + return ROOT; } else { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < splits.length - 2; i++) { @@ -63,6 +68,10 @@ public class ConceptIdentifier extends BaseSPGIdentifier { } } + public boolean isRootConcept() { + return ROOT.equals(id); + } + @Override public String toString() { return id;