mirror of
https://github.com/OpenSPG/openspg.git
synced 2025-06-27 03:20:10 +00:00
fix(reasoner): fix repeat match error (#500)
This commit is contained in:
parent
5a7495856e
commit
3eb3d6fa4a
@ -136,6 +136,85 @@ public class TransitiveOptionalTest {
|
|||||||
Assert.assertEquals(1, rst.getRows().size());
|
Assert.assertEquals(1, rst.getRows().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOptionalLoop() {
|
||||||
|
String dsl =
|
||||||
|
"\n"
|
||||||
|
+ "GraphStructure {\n"
|
||||||
|
+ " API [RAC.ServiceApi, __start__='true']\n"
|
||||||
|
+ " DbTable [RAC.DbTable]\n"
|
||||||
|
+ " //F_IdParam [RAC.Feature]\n"
|
||||||
|
+ " //F_SensResp [RAC.Feature]\n"
|
||||||
|
+ "\n"
|
||||||
|
+ " // 正向链路\n"
|
||||||
|
+ " A [RAC.Param]\n"
|
||||||
|
+ " B [RAC.Param]\n"
|
||||||
|
+ " API->A [api2param] as api2param\n"
|
||||||
|
+ " A->B [virtualDataFlowEdge] repeat(0,3) as e\n"
|
||||||
|
+ " B->DbTable [param2table]\n"
|
||||||
|
+ " // // 特征\n"
|
||||||
|
+ " //A->F_IdParam[param2feature, __optional__='true'] as paramId\n"
|
||||||
|
+ " //API->F_SensResp[api2feature, __optional__='true'] as apiSensResp\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "\n"
|
||||||
|
+ " // 反向链路\n"
|
||||||
|
+ " C [RAC.Param]\n"
|
||||||
|
+ " D [RAC.Param]\n"
|
||||||
|
+ " API->D [api2param] as api2param_r\n"
|
||||||
|
+ " C->D [virtualDataFlowEdge] repeat(0,3) as e_r\n"
|
||||||
|
+ " C->DbTable [param2table]\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "}\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "Rule {\n"
|
||||||
|
+ " time = to_timestamp(now() * 1000)\n"
|
||||||
|
+ " //L_permissionCheck1 = e.edges().reduce((res, ele) => concat(res, ele.L_permissionCheck), '') \n"
|
||||||
|
+ " //L_permissionCheck2 = e_r.edges().reduce((res, ele) => concat(res, ele.L_permissionCheck), '')\n"
|
||||||
|
+ " \n"
|
||||||
|
+ " // check L_permissionCheck\n"
|
||||||
|
+ " // R1: e.edges().constraint((pre, cur) => (cur.L_permissionCheck != \"true\"))\n"
|
||||||
|
+ " // R2: e_r.edges().constraint((pre, cur) => (cur.L_permissionCheck != \"true\"))\n"
|
||||||
|
+ "}\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "Action {\n"
|
||||||
|
+ " get(API.id,__path__)\n"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
String dataGraphStr =
|
||||||
|
"Graph {\n"
|
||||||
|
+ " API_1 [RAC.ServiceApi]\n"
|
||||||
|
+ " DbTable_1 [RAC.DbTable]\n"
|
||||||
|
+ " P_A1 [RAC.Param]\n"
|
||||||
|
+ " P_B2 [RAC.Param]\n"
|
||||||
|
+ " P_C3 [RAC.Param]\n"
|
||||||
|
+ " P_D4 [RAC.Param]\n"
|
||||||
|
+ "\n"
|
||||||
|
+ " API_1 -> P_A1 [api2param]\n"
|
||||||
|
+ " API_1 -> P_D4 [api2param]\n"
|
||||||
|
+ " P_B2 -> DbTable_1 [param2table]\n"
|
||||||
|
+ " P_C3 -> DbTable_1 [param2table]\n"
|
||||||
|
+ " P_C3 -> P_D4 [virtualDataFlowEdge]\n"
|
||||||
|
+ " P_A1 -> P_B2 [virtualDataFlowEdge]\n"
|
||||||
|
+ "}";
|
||||||
|
Map<String, Set<String>> schema = new HashMap<>();
|
||||||
|
schema.put("RAC.ServiceApi", Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
schema.put("RAC.DbTable", Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
schema.put("RAC.Param", Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
schema.put(
|
||||||
|
"RAC.ServiceApi_api2param_RAC.Param",
|
||||||
|
Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
schema.put(
|
||||||
|
"RAC.Param_virtualDataFlowEdge_RAC.Param",
|
||||||
|
Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
schema.put(
|
||||||
|
"RAC.Param_param2table_RAC.DbTable",
|
||||||
|
Convert2ScalaUtil.toScalaImmutableSet(Sets.newHashSet()));
|
||||||
|
|
||||||
|
LocalReasonerResult rst = runTest(schema, dsl, dataGraphStr);
|
||||||
|
|
||||||
|
Assert.assertEquals(1, rst.getRows().size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptional1() {
|
public void testOptional1() {
|
||||||
String dsl =
|
String dsl =
|
||||||
|
@ -152,6 +152,16 @@ public class FoldEdgeImpl implements Serializable {
|
|||||||
// 开始构造新的PathEdge
|
// 开始构造新的PathEdge
|
||||||
Set<IEdge<IVertexId, IProperty>> newPathEdgeSet = new HashSet<>();
|
Set<IEdge<IVertexId, IProperty>> newPathEdgeSet = new HashSet<>();
|
||||||
for (IEdge<IVertexId, IProperty> edge : pathEdgeSet) {
|
for (IEdge<IVertexId, IProperty> edge : pathEdgeSet) {
|
||||||
|
if (edge instanceof OptionalEdge) {
|
||||||
|
// 构造只有一条边的PathEdge
|
||||||
|
List<IEdge<IVertexId, IProperty>> nextEdgeList = fromEdgeMap.get(edge.getTargetId());
|
||||||
|
for (IEdge<IVertexId, IProperty> nextIEdge : nextEdgeList) {
|
||||||
|
PathEdge<IVertexId, IProperty, IProperty> pathEdge =
|
||||||
|
new PathEdge<>((Edge<IVertexId, IProperty>) nextIEdge);
|
||||||
|
newPathEdgeSet.add(pathEdge);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
PathEdge<IVertexId, IProperty, IProperty> pathEdge =
|
PathEdge<IVertexId, IProperty, IProperty> pathEdge =
|
||||||
(PathEdge<IVertexId, IProperty, IProperty>) edge;
|
(PathEdge<IVertexId, IProperty, IProperty>) edge;
|
||||||
IVertexId pathEdgeSearchId = pathEdge.getTargetId();
|
IVertexId pathEdgeSearchId = pathEdge.getTargetId();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user