当前位置: 首页>>代码示例>>Java>>正文


Java Node.getSingleRelationship方法代码示例

本文整理汇总了Java中org.neo4j.graphdb.Node.getSingleRelationship方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getSingleRelationship方法的具体用法?Java Node.getSingleRelationship怎么用?Java Node.getSingleRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.neo4j.graphdb.Node的用法示例。


在下文中一共展示了Node.getSingleRelationship方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: alternatingOrder

import org.neo4j.graphdb.Node; //导入方法依赖的package包/类
static ArrayList<Node> alternatingOrder (Node order) {
    ArrayList<Node> products = new ArrayList<>();
    Relationship prevRel = order.getSingleRelationship(RelationshipTypes.PREV, Direction.OUTGOING);
    if (prevRel != null) {
        Node prevOrder = prevRel.getEndNode();
        prevRel = prevOrder.getSingleRelationship(RelationshipTypes.PREV, Direction.OUTGOING);
        if (prevRel != null) {
            prevOrder = prevRel.getEndNode();
            for (Relationship r1 : prevOrder.getRelationships(Direction.OUTGOING, RelationshipTypes.HAS)) {
                Node product = r1.getEndNode();
                products.add(product);
            }
        }
    }
    return products;
}
 
开发者ID:maxdemarzi,项目名称:instacart,代码行数:17,代码来源:Predictions.java

示例2: repeatLastOrder

import org.neo4j.graphdb.Node; //导入方法依赖的package包/类
static ArrayList<Node> repeatLastOrder (Node order) {
    ArrayList<Node> products = new ArrayList<>();
    Relationship prevRel = order.getSingleRelationship(RelationshipTypes.PREV, Direction.OUTGOING);
    if (prevRel != null) {
        Node prevOrder = prevRel.getEndNode();
        for (Relationship r1 : prevOrder.getRelationships(Direction.OUTGOING, RelationshipTypes.HAS)) {
            Node product = r1.getEndNode();
            products.add(product);
        }
    }
    return products;
}
 
开发者ID:maxdemarzi,项目名称:instacart,代码行数:13,代码来源:Predictions.java

示例3: topReorderedBoostedByCartOrder

import org.neo4j.graphdb.Node; //导入方法依赖的package包/类
static ArrayList<Node> topReorderedBoostedByCartOrder(Node order) {
    ArrayList<Integer> sizes = new ArrayList<>();
    HashMap<Node, Double> products = new HashMap<>();
    Relationship ordered = order.getSingleRelationship(RelationshipTypes.ORDERED_BY, Direction.OUTGOING);
    Node user = ordered.getEndNode();
    for (Relationship r1 : user.getRelationships(Direction.INCOMING, RelationshipTypes.ORDERED_BY)) {
        Node prevOrder = r1.getStartNode();
        sizes.add(prevOrder.getDegree(RelationshipTypes.HAS, Direction.OUTGOING));
        for (Relationship r2 : prevOrder.getRelationships(Direction.OUTGOING, RelationshipTypes.HAS)) {
            Node product = r2.getEndNode();
            Double count = 1.0;
            Double boost = 0.0;
            // Products added to the cart earlier are more likely to be re-ordered, give them a boost
            switch (String.valueOf(r2.getProperty("order",99))){
                case "1" : boost = 0.3; break;
                case "2" : boost = 0.2; break;
                case "3" : boost = 0.1; break;
            }
            if (products.containsKey(product)) {
                count = 1.0 + products.get(product);
            }
            products.put(product, count + boost);
        }
    }
    Long average = Math.round(sizes.stream().mapToInt(i -> i).average().orElse(0));
    List<Node> topProducts = products.entrySet().stream()
            .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
            .limit(average)
            .map(Map.Entry::getKey)
            .collect(Collectors.toList());
    return (ArrayList<Node>) topProducts;
}
 
开发者ID:maxdemarzi,项目名称:instacart,代码行数:33,代码来源:Predictions.java


注:本文中的org.neo4j.graphdb.Node.getSingleRelationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。