@Override public Traverser.Admin<E> next() { final Traverser.Admin<E> traverser = super.next(); if (traverser.get() instanceof Attachable && !(traverser.get() instanceof Property)) traverser.set( (E) ((Attachable<Element>) traverser.get()).attach(Attachable.Method.get(graph))); return traverser; }
@Test public void testComputerAwareCountMatchAlgorithm() { // MAKE SURE OLAP JOBS ARE BIASED TOWARDS STAR GRAPH DATA final Consumer doNothing = s -> {}; Traversal.Admin<?, ?> traversal = __.match( as("a").sideEffect(doNothing).as("b"), // 1 as("b").sideEffect(doNothing).as("c"), // 2 as("a").sideEffect(doNothing).as("d"), // 5 as("c").sideEffect(doNothing).as("e"), // 4 as("c").sideEffect(doNothing).as("f")) // 3 .asAdmin(); traversal.applyStrategies(); // necessary to enure step ids are unique MatchStep.CountMatchAlgorithm countMatchAlgorithm = new MatchStep.CountMatchAlgorithm(); countMatchAlgorithm.initialize( TraversalEngine.Type.COMPUTER, ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren()); Traversal.Admin<Object, Object> firstPattern = ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren().get(0); Traversal.Admin<Object, Object> secondPattern = ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren().get(1); Traversal.Admin<Object, Object> thirdPattern = ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren().get(2); Traversal.Admin<Object, Object> forthPattern = ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren().get(3); Traversal.Admin<Object, Object> fifthPattern = ((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren().get(4); countMatchAlgorithm .bundles .stream() .forEach(bundle -> assertEquals(0.0d, bundle.multiplicity, 0.0d)); assertEquals( MatchStep.TraversalType.MATCH_TRAVERSAL, countMatchAlgorithm.getBundle(firstPattern).traversalType); assertEquals( MatchStep.TraversalType.MATCH_TRAVERSAL, countMatchAlgorithm.getBundle(secondPattern).traversalType); assertEquals( MatchStep.TraversalType.MATCH_TRAVERSAL, countMatchAlgorithm.getBundle(thirdPattern).traversalType); assertEquals( MatchStep.TraversalType.MATCH_TRAVERSAL, countMatchAlgorithm.getBundle(forthPattern).traversalType); assertEquals( MatchStep.TraversalType.MATCH_TRAVERSAL, countMatchAlgorithm.getBundle(fifthPattern).traversalType); assertEquals(firstPattern, countMatchAlgorithm.bundles.get(0).traversal); assertEquals(secondPattern, countMatchAlgorithm.bundles.get(1).traversal); assertEquals(thirdPattern, countMatchAlgorithm.bundles.get(2).traversal); assertEquals(forthPattern, countMatchAlgorithm.bundles.get(3).traversal); assertEquals(fifthPattern, countMatchAlgorithm.bundles.get(4).traversal); // MAKE THE SECOND PATTERN EXPENSIVE countMatchAlgorithm.recordStart(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), secondPattern); // MAKE THE THIRD PATTERN MORE EXPENSIVE THAN FORTH countMatchAlgorithm.recordStart(EmptyTraverser.instance(), thirdPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), thirdPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), thirdPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), thirdPattern); // MAKE THE FORTH PATTERN EXPENSIVE countMatchAlgorithm.recordStart(EmptyTraverser.instance(), forthPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), forthPattern); countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), forthPattern); // Traverser.Admin traverser = B_LP_O_P_S_SE_SL_TraverserGenerator.instance().generate(1, EmptyStep.instance(), 1l); traverser.addLabels(Collections.singleton("a")); assertEquals(firstPattern, countMatchAlgorithm.apply(traverser)); traverser = traverser.split(1, EmptyStep.instance()); traverser.getTags().add(firstPattern.getStartStep().getId()); traverser.addLabels(Collections.singleton("b")); // assertEquals(secondPattern, countMatchAlgorithm.apply(traverser)); traverser = traverser.split(1, EmptyStep.instance()); traverser.getTags().add(secondPattern.getStartStep().getId()); traverser.addLabels(Collections.singleton("c")); // assertEquals(fifthPattern, countMatchAlgorithm.apply(traverser)); traverser = traverser.split(1, EmptyStep.instance()); traverser.getTags().add(fifthPattern.getStartStep().getId()); traverser.addLabels(Collections.singleton("f")); // assertEquals(forthPattern, countMatchAlgorithm.apply(traverser)); traverser = traverser.split(1, EmptyStep.instance()); traverser.getTags().add(forthPattern.getStartStep().getId()); traverser.addLabels(Collections.singleton("e")); // assertEquals(thirdPattern, countMatchAlgorithm.apply(traverser)); traverser = traverser.split(1, EmptyStep.instance()); traverser.getTags().add(thirdPattern.getStartStep().getId()); traverser.addLabels(Collections.singleton("d")); }