mirror of
https://github.com/OpenSPG/openspg.git
synced 2025-06-27 03:20:10 +00:00
fix(reasoner): support add facts in thinker. (#396)
Co-authored-by: matthewhyx <matthew.hyx@antgroup.com>
This commit is contained in:
parent
84b9209ed9
commit
23cd365ff9
@ -191,12 +191,18 @@ class SPGConceptRuleMarkLang:
|
||||
if self.is_reasoning:
|
||||
predicate_name = self.predicate
|
||||
subject_type = (
|
||||
self.src_concept[0] if len(self.src_concept) > 0 else None
|
||||
f"{self.namespace}.{self.src_concept[0]}"
|
||||
if len(self.src_concept) > 0
|
||||
else None
|
||||
)
|
||||
subject_name = (
|
||||
self.src_concept[1] if len(self.src_concept) > 0 else None
|
||||
)
|
||||
object_type = self.dst_concept[0] if len(self.dst_concept) > 0 else None
|
||||
object_type = (
|
||||
f"{self.namespace}.{self.dst_concept[0]}"
|
||||
if len(self.dst_concept) > 0
|
||||
else None
|
||||
)
|
||||
object_name = self.dst_concept[1] if len(self.dst_concept) > 0 else None
|
||||
elif self.dst_concept[0] is not None:
|
||||
predicate_name = "leadTo"
|
||||
|
@ -13,15 +13,20 @@
|
||||
|
||||
package com.antgroup.openspg.server.core.reasoner.service.runner;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.antgroup.kg.reasoner.thinker.Thinker;
|
||||
import com.antgroup.kg.reasoner.thinker.catalog.LogicCatalog;
|
||||
import com.antgroup.kg.reasoner.thinker.engine.DefaultThinker;
|
||||
import com.antgroup.kg.reasoner.thinker.logic.Result;
|
||||
import com.antgroup.kg.reasoner.thinker.logic.graph.Entity;
|
||||
import com.antgroup.kg.reasoner.thinker.logic.graph.Node;
|
||||
import com.antgroup.openspg.reasoner.runner.local.thinker.LocalThinkerMain;
|
||||
import com.antgroup.openspg.reasoner.runner.local.thinker.OpenSPGLogicCatalog;
|
||||
import com.antgroup.openspg.reasoner.runner.local.thinker.ThinkerParams;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ -42,15 +47,30 @@ public class ThinkerRunner {
|
||||
LocalThinkerMain.loadGraph(graphStateClass, task.getGraphStateInitString()),
|
||||
logicCatalog);
|
||||
List<Result> result;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : task.getParams().entrySet()) {
|
||||
if (entry.getKey().equals("entities")) {
|
||||
List<Map<String, String>> entities =
|
||||
JSON.parseObject(
|
||||
String.valueOf(entry.getValue()),
|
||||
new TypeReference<List<Map<String, String>>>() {});
|
||||
for (Map<String, String> map : entities) {
|
||||
Entity entity = new Entity(map.get("id"), map.get("type"));
|
||||
params.put(entity.toString(), entity);
|
||||
}
|
||||
} else {
|
||||
params.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if (task.getMode().toLowerCase().equals("spo")) {
|
||||
result =
|
||||
thinker.find(
|
||||
task.getTriple().getSubject(),
|
||||
task.getTriple().getPredicate(),
|
||||
task.getTriple().getObject(),
|
||||
task.getParams());
|
||||
params);
|
||||
} else {
|
||||
result = thinker.find((Node) task.getTriple().getObject(), task.getParams());
|
||||
result = thinker.find((Node) task.getTriple().getObject(), params);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user