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


Java Uniqueness类代码示例

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


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

示例1: call

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
@Override
public Map<String, Set<Long>> call() throws Exception {
  logger.info("Processsing " + category);
  Map<String, Set<Long>> map = new HashMap<String, Set<Long>>();
  Set<Long> nodeSet = new HashSet<Long>();
  Transaction tx = graphDb.beginTx();
  try {
    for (Path position : graphDb.traversalDescription().uniqueness(Uniqueness.NODE_GLOBAL).depthFirst()
        .relationships(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING).relationships(OwlRelationships.RDF_TYPE, Direction.INCOMING)
        .relationships(OwlRelationships.OWL_EQUIVALENT_CLASS, Direction.BOTH).relationships(OwlRelationships.OWL_SAME_AS, Direction.BOTH)
        .traverse(root)) {
      Node end = position.endNode();
      nodeSet.add(end.getId());
    }
    logger.info("Discovered " + nodeSet.size() + " nodes for " + category);
    map.put(category, nodeSet);
  } catch (Exception e) {
    logger.warning("IRI not found for category: " + category);
  } finally {
    tx.success();
    tx.close();
  }
  return map;
}
 
开发者ID:SciGraph,项目名称:SciGraph,代码行数:25,代码来源:CategoryProcessor.java

示例2: getResourcePaths

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
/**
 * note: should be run in transaction scope
 *
 * @param graphDB
 * @param prefixedResourceURI
 * @return
 */
public static Iterable<Path> getResourcePaths(final GraphDatabaseService graphDB, final String prefixedResourceURI) {

	final Node resourceNode = getResourceNode(graphDB, prefixedResourceURI);

	// TODO: maybe replace with gethEntityPaths(GraphdataBaseService, Node)
	final Iterable<Path> paths = graphDB.traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL)
			.order(BranchOrderingPolicies.POSTORDER_BREADTH_FIRST).expand(PathExpanderBuilder.allTypes(Direction.OUTGOING).build())
			.evaluator(path -> {

				final boolean hasLeafLabel = path.endNode() != null &&
						path.endNode().hasLabel(org.dswarm.graph.GraphProcessingStatics.LEAF_LABEL);

				if (hasLeafLabel) {

					return org.neo4j.graphdb.traversal.Evaluation.INCLUDE_AND_CONTINUE;
				}
				return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_CONTINUE;
			}).traverse(resourceNode);

	return paths;
}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:29,代码来源:GraphDBUtil.java

示例3: energization

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
@POST
public Response energization(String body, @Context GraphDatabaseService db) throws IOException {
    HashMap input = Validators.getValidEquipmentIds(body);

    Set<Node> startingEquipment = new HashSet<>();
    Set results = new HashSet<>();
    ArrayList<Long> skip = new ArrayList<>();

    try (Transaction tx = db.beginTx()) {
        ((Collection) input.get("ids")).forEach((id) -> startingEquipment.add(db.findNode(Labels.Equipment, "equipment_id", id)));

        if (startingEquipment.isEmpty()) {
            throw Exceptions.equipmentNotFound;
        }

        startingEquipment.forEach(bus -> {
            InitialBranchState.State<Double> ibs;
            ibs = new InitialBranchState.State<>((Double) bus.getProperty("voltage", 999.0), 0.0);
            TraversalDescription td = db.traversalDescription()
                    .depthFirst()
                    .expand(expander, ibs)
                    .uniqueness(Uniqueness.NODE_GLOBAL)
                    .evaluator(evaluator);

            for (org.neo4j.graphdb.Path position : td.traverse(bus)) {
                Node endNode = position.endNode();
                if (!skip.contains(endNode.getId())) {
                    results.add(position.endNode().getProperty("equipment_id"));
                    skip.add(endNode.getId());
                }

                endNode.setProperty("Energized", true);
            }
        });
        tx.success();
    }
    return  Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:power_grid,代码行数:39,代码来源:Energization.java

示例4: topologicalOrder

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
private Iterable<Node> topologicalOrder(GraphDatabaseService service,
					PrimitiveLongSet processed) {
	return service.traversalDescription()
			.depthFirst()
			.expand(new TopologicalPathExpander()
			, new State<>(processed, null))
			// We manage uniqueness for ourselves.
			.uniqueness(Uniqueness.NONE)
			.traverse(loop(roots))
			.nodes();
}
 
开发者ID:ProgrammingLife2015,项目名称:dnainator,代码行数:12,代码来源:AnalyzeCommand.java

示例5: findConnectedNodesUsingTraversalAPI

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
/**
     * demo usage of traversal API, see http://docs.neo4j.org/chunked/stable/tutorial-traversal.html
     */
    @GET
    @Produces("application/json")
    @Path("/traversalapi/{label}/{key}/{value}/{relType}/{depth}")
    public People findConnectedNodesUsingTraversalAPI(
            @PathParam("label") String label,
            @PathParam("key") String key,
            @PathParam("value") String value,
            @PathParam("relType") String relType,
            @PathParam("depth") int depth) {

        try (Transaction tx = graphDatabaseService.beginTx()) {
            Node startNode = IteratorUtil.single(graphDatabaseService.findNodesByLabelAndProperty(
                    DynamicLabel.label(label), key, value
            ));

            Iterable<org.neo4j.graphdb.Path> traverserResult =
                    graphDatabaseService
                            .traversalDescription()
                            .relationships(DynamicRelationshipType.withName(relType), Direction.OUTGOING)
                            .uniqueness(Uniqueness.NODE_LEVEL)
                            .evaluator(Evaluators.atDepth(depth))
//                            .evaluator(new TraversalPrinter(Evaluators.atDepth(depth)))
                            .traverse(startNode);
            return new People(new LastNodePropertyIterator(traverserResult, key));
        }
    }
 
开发者ID:sarmbruster,项目名称:unmanaged-extension,代码行数:30,代码来源:UnmanagedExtension.java

示例6: DbManager

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
public DbManager( GraphDatabaseService db )
{
    this.db = db;
    // START SNIPPET: basetraverser
    friendsTraversal = db.traversalDescription()
            .depthFirst()
            .relationships( Rels.KNOWS )
            .uniqueness( Uniqueness.RELATIONSHIP_GLOBAL );
    // END SNIPPET: basetraverser
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:11,代码来源:DbManager.java

示例7: getRelationships

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
public final List<UserItemRelationship> getRelationships(final String userID,
                                                         final String depth,
                                                         final String sinceTimestamp,
                                                         final String untilTimestamp,
                                                         final boolean removeDuplicates)

        throws ObelixNodeNotFoundException {
    try (Transaction tx = neoDb.beginTx()) {
        List<UserItemRelationship> userItemRelationships = new LinkedList<>();
        Node user = getUserNode(neoDb, userID);

        for (Path path : neoDb.traversalDescription()
                .breadthFirst()
                .expand(new TimeStampExpander(sinceTimestamp, untilTimestamp, depth))
                .evaluator(Evaluators.toDepth(Integer.parseInt(depth)))
                .uniqueness(Uniqueness.RELATIONSHIP_GLOBAL)
                .traverse(user)) {

            if (path.lastRelationship() != null) {

                String itemid = path.lastRelationship()
                        .getEndNode().getProperty("node_id").toString();

                userItemRelationships.add(new UserItemRelationship(itemid, path.length()));
            }
        }
        tx.success();
        return userItemRelationships;
    }
}
 
开发者ID:inveniosoftware-contrib,项目名称:obelix,代码行数:31,代码来源:NeoGraphDatabase.java

示例8: openDb

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
@Before
public void openDb() throws IOException {
    String tempDir = temporaryFolder.newFolder().getAbsolutePath();
    db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(tempDir).newGraphDatabase();
    stepsBuilder = new StepsBuilder();
    baseTraversalDescription = db.traversalDescription().uniqueness(Uniqueness.NONE).breadthFirst();
}
 
开发者ID:alexaverbuch,项目名称:steps,代码行数:8,代码来源:StepsBuilderTest.java

示例9: openDb

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
@Before
public void openDb() throws IOException {
    String tempDir = temporaryFolder.newFolder().getAbsolutePath();
    db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(tempDir).newGraphDatabase();
    engine = new ExecutionEngine(db);
    stepsBuilder = new StepsBuilder();
    baseTraversalDescription = db.traversalDescription().uniqueness(Uniqueness.NONE).breadthFirst();
}
 
开发者ID:alexaverbuch,项目名称:steps,代码行数:9,代码来源:StepTraversalTest.java

示例10: run

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
@Override
public void run() {
  logger.info("Starting clique merge");

  Transaction tx = graphDb.beginTx();
  ResourceIterable<Node> allNodes = graphDb.getAllNodes();
  int size = Iterators.size(allNodes.iterator());
  tx.success();
  tx.close();

  logger.info(size + " nodes left to process");

  tx = graphDb.beginTx();
  TraversalDescription traversalDescription =
      graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL);
  for (RelationshipType rel : relationships) {
    traversalDescription = traversalDescription.relationships(rel, Direction.BOTH);
  }

  Set<Long> processedNodes = new HashSet<Long>();

  for (Node baseNode : allNodes) {

    size -= 1;

    if (size % 100000 == 0) {
      logger.info(size + " nodes left to process");
    }

    if (size % batchCommitSize == 0) {
      logger.fine("Node batch commit");
      tx.success();
      tx.close();
      tx = graphDb.beginTx();
    }

    logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI));

    if (!processedNodes.contains(baseNode.getId())) {
      // Keep a list of equivalentNodes
      List<Node> clique = new ArrayList<Node>();
      for (Node node : traversalDescription.traverse(baseNode).nodes()) {
        logger.fine("-- " + node.getProperty(NodeProperties.IRI));
        clique.add(node);
        processedNodes.add(node.getId());
      }

      logger.fine("clique size: " + clique.size());
      if (clique.size() == 1) {
        Node defactoLeader = clique.get(0);
        markAsCliqueLeader(defactoLeader);
      } else {
        Node leader = electCliqueLeader(clique, prefixLeaderPriority);
        markAsCliqueLeader(leader);
        clique.remove(leader); // keep only the peasants
        moveEdgesToLeader(leader, clique, tx);
        ensureLabel(leader, clique);
      }

    }

  }

  tx.success();
  tx.close();
}
 
开发者ID:SciGraph,项目名称:SciGraph,代码行数:67,代码来源:Clique.java

示例11: createIndex

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
/**
 * Create a reachability index on a graph.
 * 
 * @throws InterruptedException
 */
public void createIndex(Predicate<Node> nodePredicate) throws InterruptedException {
  if (indexExists()) {
    throw new IllegalStateException(
        "Reachability index already exists. Drop it first and then recreate it.");
  }

  long startTime = System.currentTimeMillis();
  Set<Entry<Long, Integer>> hopCoverages = getHopCoverages(nodePredicate);
  logger.info(format("Calculated hop coverage in %d second(s)",
      TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)));

  InMemoryReachabilityIndex inMemoryIndex = new InMemoryReachabilityIndex();

  TraversalDescription incomingTraversal = graphDb.traversalDescription().breadthFirst()
      .uniqueness(Uniqueness.NODE_GLOBAL).expand(new DirectionalPathExpander(Direction.INCOMING))
      .evaluator(new ReachabilityEvaluator(inMemoryIndex, Direction.INCOMING, nodePredicate));

  TraversalDescription outgoingTraversal = graphDb.traversalDescription().breadthFirst()
      .uniqueness(Uniqueness.NODE_GLOBAL).expand(new DirectionalPathExpander(Direction.OUTGOING))
      .evaluator(new ReachabilityEvaluator(inMemoryIndex, Direction.OUTGOING, nodePredicate));

  startTime = System.currentTimeMillis();

  try (Transaction tx = graphDb.beginTx()) {
    for (Entry<Long, Integer> coverage : hopCoverages) {

      Node workingNode = graphDb.getNodeById(coverage.getKey());

      if (coverage.getValue() < 0) {
        inMemoryIndex.put(coverage.getKey(), new InOutList());
      } else {
        InOutListTraverser incomingListTaverser = new InOutListTraverser(incomingTraversal,
            workingNode);
        incomingListTaverser.start();

        InOutListTraverser outgoingListTaverser = new InOutListTraverser(outgoingTraversal,
            workingNode);
        outgoingListTaverser.start();

        incomingListTaverser.join();
        outgoingListTaverser.join();
      }

    }
    tx.success();
  }

  logger.info("Built an InMemoryReachability index in " + ((System.currentTimeMillis() - startTime) / 1000)
      + " sec(s).");
  commitIndexToGraph(inMemoryIndex);
  logger.info("Reachability index created.");
}
 
开发者ID:SciGraph,项目名称:SciGraph,代码行数:58,代码来源:ReachabilityIndex.java

示例12: getEntityPaths

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
/**
 * note: should be run in transaction scope
 *
 * @param graphDB
 * @param entityNode
 * @return
 */
private static Iterable<Path> getEntityPaths(final GraphDatabaseService graphDB, final Node entityNode) {

	return graphDB.traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL).order(BranchOrderingPolicies.POSTORDER_BREADTH_FIRST)
			.expand(PathExpanderBuilder.allTypes(Direction.OUTGOING).build()).evaluator(path -> {

				final boolean hasLeafLabel = path.endNode().hasLabel(org.dswarm.graph.GraphProcessingStatics.LEAF_LABEL);

				if (hasLeafLabel) {

					return org.neo4j.graphdb.traversal.Evaluation.INCLUDE_AND_PRUNE;
				}

				return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_CONTINUE;
			}).traverse(entityNode);
}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:23,代码来源:GraphDBUtil.java

示例13: getNonMatchedSubGraphPaths

import org.neo4j.graphdb.traversal.Uniqueness; //导入依赖的package包/类
/**
 * note: should be executed in transaction scope
 *
 * @param nodeId
 * @param graphDB
 * @return
 */
public static Iterable<Path> getNonMatchedSubGraphPaths(final long nodeId, final GraphDatabaseService graphDB) {

	final Node entityNode = graphDB.getNodeById(nodeId);

	// final int entityNodeHierarchyLevel = (int) entityNode.getProperty("__HIERARCHY_LEVEL__");

	final Iterable<Path> paths = graphDB.traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL)
			.order(BranchOrderingPolicies.POSTORDER_BREADTH_FIRST).expand(PathExpanderBuilder.allTypes(Direction.OUTGOING).build())
			.evaluator(path -> {

				// if (entityNodeHierarchyLevel > (int) path.endNode().getProperty("__HIERARCHY_LEVEL__")) {
				//
				// return Evaluation.EXCLUDE_AND_PRUNE;
				// }

				if (path.lastRelationship() == null && path.endNode().hasLabel(org.dswarm.graph.GraphProcessingStatics.LEAF_LABEL)) {

					return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_PRUNE;
				}

				if (path.lastRelationship() == null) {

					return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_CONTINUE;
				}

				if (path.lastRelationship().hasProperty(org.dswarm.graph.delta.DeltaStatics.MATCHED_PROPERTY)) {

					// include only non-matched relationships (paths)
					return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_PRUNE;
				}

				final boolean hasLeafLabel = path.endNode().hasLabel(org.dswarm.graph.GraphProcessingStatics.LEAF_LABEL);

				if (hasLeafLabel) {

					return org.neo4j.graphdb.traversal.Evaluation.INCLUDE_AND_PRUNE;
				}

				return org.neo4j.graphdb.traversal.Evaluation.EXCLUDE_AND_CONTINUE;
			}).traverse(entityNode);

	return paths;
}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:51,代码来源:GraphDBUtil.java


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