List of usage examples for org.apache.commons.lang3.tuple Triple getRight
public abstract R getRight();
Gets the right element from this triple.
From source file:org.dllearner.algorithms.qtl.operations.lgg.AbstractLGGGenerator.java
protected RDFResourceTree processClassNodes(RDFResourceTree tree1, RDFResourceTree tree2) { RDFResourceTree lgg = new RDFResourceTree(); Set<Triple<Node, Node, Node>> relatedEdges = getRelatedEdges(tree1, tree2); for (Triple<Node, Node, Node> entry : relatedEdges) { if (stop || isTimeout()) { complete = false;/*from w w w .j a v a2s . c o m*/ break; } Node edge1 = entry.getLeft(); Node edge2 = entry.getMiddle(); Node lcs = entry.getRight(); Set<RDFResourceTree> addedChildren = new HashSet<>(); // loop over children of first tree for (RDFResourceTree child1 : tree1.getChildren(edge1)) {//System.out.println("c1:" + child1); if (stop || isTimeout()) { complete = false; break; } // loop over children of second tree for (RDFResourceTree child2 : tree2.getChildren(edge2)) {//System.out.println("c2:" + child2); if (stop || isTimeout()) { complete = false; break; } RDFResourceTree lggChild = computeLGG(child1, child2, false); // check if there was already a more specific child computed before // and if so don't add the current one boolean add = true; for (Iterator<RDFResourceTree> it = addedChildren.iterator(); it.hasNext();) { RDFResourceTree addedChild = it.next(); if (isSubTreeOf(addedChild, lggChild)) { // logger.trace("Skipped adding: Previously added child {} is subsumed by {}.", // addedChild.getStringRepresentation(), // lggChild.getStringRepresentation()); add = false; break; } else if (isSubTreeOf(lggChild, addedChild)) { // logger.trace("Removing child node: {} is subsumed by previously added child {}.", // lggChild.getStringRepresentation(), // addedChild.getStringRepresentation()); lgg.removeChild(addedChild, lgg.getEdgeToChild(addedChild)); it.remove(); } } if (add) { lgg.addChild(lggChild, lcs); addedChildren.add(lggChild); // logger.trace("Adding child {}", lggChild.getStringRepresentation()); } } } } return lgg; }
From source file:org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorRDFS.java
@Override protected RDFResourceTree processClassNodes(RDFResourceTree tree1, RDFResourceTree tree2) { if (tree1.isResourceNode() && tree2.isResourceNode()) { System.out.print("LCS(" + tree1 + ", " + tree2 + ")"); Node lcs = NonStandardReasoningServices.getLeastCommonSubsumer(reasoner, tree1.getData(), tree2.getData(), EntityType.CLASS); System.out.println(" = " + lcs); if (lcs != null) { return new RDFResourceTree(lcs); }//from w w w .ja v a2 s.c om } RDFResourceTree lgg = new RDFResourceTree(); Set<Triple<Node, Node, Node>> relatedEdges = getRelatedEdges(tree1, tree2); for (Triple<Node, Node, Node> entry : relatedEdges) { Node edge1 = entry.getLeft(); Node edge2 = entry.getMiddle(); Node lcs = entry.getRight(); Set<RDFResourceTree> addedChildren = new HashSet<>(); // loop over children of first tree for (RDFResourceTree child1 : tree1.getChildren(edge1)) {//System.out.println("c1:" + child1); // loop over children of second tree for (RDFResourceTree child2 : tree2.getChildren(edge2)) {//System.out.println("c2:" + child2); RDFResourceTree lggChild = computeLGG(child1, child2, false); // check if there was already a more specific child computed before // and if so don't add the current one boolean add = true; for (Iterator<RDFResourceTree> it = addedChildren.iterator(); it.hasNext();) { RDFResourceTree addedChild = it.next(); if (isSubTreeOf(addedChild, lggChild)) { // logger.trace("Skipped adding: Previously added child {} is subsumed by {}.", // addedChild.getStringRepresentation(), // lggChild.getStringRepresentation()); add = false; break; } else if (isSubTreeOf(lggChild, addedChild)) { // logger.trace("Removing child node: {} is subsumed by previously added child {}.", // lggChild.getStringRepresentation(), // addedChild.getStringRepresentation()); lgg.removeChild(addedChild, lgg.getEdgeToChild(addedChild)); it.remove(); } } if (add) { lgg.addChild(lggChild, lcs); addedChildren.add(lggChild); // logger.trace("Adding child {}", lggChild.getStringRepresentation()); } } } } return lgg; }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionBool.java
/** * generic test-case/*w w w .j ava2s .c o m*/ * * @param p_input test-case data * @throws IllegalAccessException is thrwon on instantiation error * @throws InstantiationException is thrwon on instantiation error */ @Test @UseDataProvider("generate") public final void execute(final Triple<List<ITerm>, Class<? extends IAction>, Stream<Object>> p_input) throws IllegalAccessException, InstantiationException { final List<ITerm> l_return = new ArrayList<>(); p_input.getMiddle().newInstance().execute(false, null, p_input.getLeft(), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::raw).toArray(), p_input.getRight().toArray()); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionCrypto.java
/** * test encrypting & decrypting//from www . ja v a 2 s .co m */ @Test @UseDataProvider("generatecrypt") public final void encryptdecreypt(final Triple<String, Integer, Integer> p_crypt) { final List<ITerm> l_returnkey = new ArrayList<>(); new CCreateKey().execute(false, IContext.EMPTYPLAN, Stream.of(CRawTerm.from(p_crypt.getLeft())).collect(Collectors.toList()), l_returnkey); Assert.assertEquals(l_returnkey.size(), p_crypt.getMiddle().intValue()); final List<ITerm> l_returnencrypt = new ArrayList<>(); new CEncrypt().execute(false, IContext.EMPTYPLAN, Stream.of(l_returnkey.get(0), CRawTerm.from("test string"), CRawTerm.from(12345)) .collect(Collectors.toList()), l_returnencrypt); final List<ITerm> l_return = new ArrayList<>(); new CDecrypt().execute(false, IContext.EMPTYPLAN, Stream.concat(Stream.of(l_returnkey.get(p_crypt.getRight())), l_returnencrypt.stream()) .collect(Collectors.toList()), l_return); Assert.assertEquals(l_return.size(), 2); Assert.assertEquals(l_return.get(0).raw(), "test string"); Assert.assertEquals(l_return.get(1).<Number>raw(), 12345); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java
/** * test apply-days minus//w w w .j av a2 s .c o m */ @Test @UseDataProvider("generateapplyminus") public final void applysminus(final Triple<IAction, Pair<ZonedDateTime, Integer>, String> p_value) { final List<ITerm> l_return = new ArrayList<>(); p_value.getLeft().execute(false, IContext.EMPTYPLAN, Stream.of("minus", p_value.getMiddle().getRight(), p_value.getMiddle().getLeft()) .map(CRawTerm::from).collect(Collectors.toList()), l_return); Assert.assertEquals(l_return.size(), 1); Assert.assertEquals(l_return.get(0).raw(), ZonedDateTime.parse(p_value.getRight())); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java
/** * test apply-days plus//from ww w . jav a2 s. com */ @Test @UseDataProvider("generateapplyplus") public final void applyplus(final Triple<IAction, Pair<ZonedDateTime, Integer>, String> p_value) { final List<ITerm> l_return = new ArrayList<>(); p_value.getLeft().execute(false, IContext.EMPTYPLAN, Stream.of("plus", p_value.getMiddle().getRight(), p_value.getMiddle().getLeft()).map(CRawTerm::from) .collect(Collectors.toList()), l_return); Assert.assertEquals(l_return.size(), 1); Assert.assertEquals(l_return.get(0).raw(), ZonedDateTime.parse(p_value.getRight())); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java
/** * test between//from w w w . j ava 2 s.c om */ @Test @UseDataProvider("generatebetween") public final void between(final Triple<IAction, Stream<ITerm>, Stream<Number>> p_value) { final List<ITerm> l_return = new ArrayList<>(); p_value.getLeft().execute(false, IContext.EMPTYPLAN, p_value.getMiddle().collect(Collectors.toList()), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::<Number>raw).mapToLong(Number::longValue).toArray(), p_value.getRight().mapToLong(Number::longValue).toArray()); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java
/** * test all aggregation-value actions/*from w w w . j a va2s . co m*/ * * @param p_input test data * * @throws IllegalAccessException is thrown on instantiation error * @throws InstantiationException is thrown on instantiation error */ @Test @UseDataProvider("aggregationvaluegenerate") public final void aggregationvalueaction( final Triple<List<ITerm>, Class<? extends IAction>, Function<Stream<Number>, ?>> p_input) throws IllegalAccessException, InstantiationException { final List<ITerm> l_return = new ArrayList<>(); p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return); Assert.assertEquals(l_return.size(), 1); Assert.assertEquals(l_return.get(0).raw(), p_input.getRight().apply(p_input.getLeft().stream().map(ITerm::<Number>raw))); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java
/** * test all single-value actions// ww w . j a v a 2 s .c o m * * @param p_input test data * * @throws IllegalAccessException is thrown on instantiation error * @throws InstantiationException is thrown on instantiation error */ @Test @UseDataProvider("singlevaluegenerate") public final void singlevalueaction( final Triple<List<ITerm>, Class<? extends IAction>, Function<Number, ?>> p_input) throws IllegalAccessException, InstantiationException { final List<ITerm> l_return = new ArrayList<>(); p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return); Assert.assertArrayEquals(p_input.getMiddle().toGenericString(), l_return.stream().map(ITerm::raw).toArray(), p_input.getLeft().stream().map(ITerm::<Number>raw).map(p_input.getRight()).toArray()); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathBitMatrix.java
/** * test all input actions// ww w . java2 s.c o m * * @throws IllegalAccessException is thrown on instantiation error * @throws InstantiationException is thrown on instantiation error */ @Test @UseDataProvider("generator") public final void action(final Triple<List<ITerm>, Class<? extends IAction>, Stream<Object>> p_input) throws IllegalAccessException, InstantiationException { final List<ITerm> l_return = new ArrayList<>(); p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return); Assert.assertArrayEquals(p_input.getMiddle().toGenericString(), l_return.stream().map(ITerm::raw).toArray(), p_input.getRight().toArray()); }