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


Java Relationship.getOtherNode方法代码示例

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


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

示例1: getMostFrequentLabel

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
protected long getMostFrequentLabel(Node node) {
	Long2LongMap commMap = new Long2LongOpenHashMap();
       Iterable<Relationship> relationships = relType == null ? node.getRelationships() : node.getRelationships(relType);

       for (Relationship r : relationships) {
           Node other = r.getOtherNode(node);
		long otherCommunity = (long) other.getProperty(attName);
		// commMap.put(other.getId(), otherCommunity);	WRONG
		long count = commMap.getOrDefault(otherCommunity, 0L);
		commMap.put(otherCommunity, count+1);
	}

	long mostFrequentLabel = -1;
	long mostFrequentLabelCount = -1;
	for( Entry<Long, Long> e : commMap.entrySet() ) {
		if( e.getValue() > mostFrequentLabelCount ) {
			mostFrequentLabelCount = e.getValue();
			mostFrequentLabel = e.getKey();
		}
	}
	return mostFrequentLabel;
}
 
开发者ID:besil,项目名称:Neo4jSNA,代码行数:23,代码来源:LabelPropagation.java

示例2: run

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
	public void run() {
		try (Transaction tx = database.beginTx())
        {
			writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up "+nodeLabel.toString()+" index...\n");
			writer.flush();
			int d = 0;
			
			ResourceIterator<Node> it = database.findNodes(nodeLabel);
			
            while (it.hasNext()) {
            	Node node = it.next();
//            	Boolean has_token_count = false;
            	for (String prop : node.getPropertyKeys()) {
            		node.getProperty(prop);
            	}
            	
            	for (Relationship in : node.getRelationships(Direction.INCOMING)) {
            		@SuppressWarnings("unused")
					Node other = in.getOtherNode(node);
//                	for (String prop : other.getPropertyKeys()) {
//                		other.getProperty(prop);
//                	}
            	}
            	d++;
            	if (d % 50000 == 0) {
            		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - "+nodeLabel.toString()+": read "+String.valueOf(d)+" nodes so far...\n");
    				writer.flush();
            	}
            }
			
			writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Finished warming up "+nodeLabel.toString()+" index.\n");
			writer.flush();
			
            tx.success();
        } catch (IOException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:40,代码来源:IndexWarmUp.java

示例3: run

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public void run() {
	try (Transaction tx = database.beginTx())
       {
		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Counting pos in collection "+startNode.getProperty("title")+"...\n");
		writer.flush();
		int d = 0;
		Node corpus = startNode.getRelationships(LinkLabel.HAS_COLLECTION, Direction.INCOMING).iterator().next().getOtherNode(startNode);
		String corpusTitle = (String) corpus.getProperty("title");
		corpusTitle = corpusTitle.replaceAll("-", "_");
		
		for (Relationship hasDocument : startNode.getRelationships(LinkLabel.HAS_DOCUMENT, Direction.OUTGOING)) {
			Node document = hasDocument.getOtherNode(startNode);
           	
           	for (Relationship hasToken : document.getRelationships(LinkLabel.HAS_TOKEN, Direction.OUTGOING)) {
           		Node token = hasToken.getOtherNode(document);
           		
           		for (Relationship hasPosTag : token.getRelationships(LinkLabel.HAS_POS_TAG, Direction.OUTGOING)) {
           			Node posTag = hasPosTag.getOtherNode(token);
           			if (posTag.hasProperty("token_count_"+corpusTitle))
           				posTag.setProperty("token_count_"+corpusTitle, (long) posTag.getProperty("token_count_"+corpusTitle) + 1);
           			else
           				posTag.setProperty("token_count_"+corpusTitle, (long) 1);
           		}
           	}
           	d++;
           	if (d % 50000 == 0) {
           		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - "+startNode.getProperty("title")+": read "+String.valueOf(d)+" documents so far...\n");
   				writer.flush();
           	}
		}
		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Finished counting pos in collection "+startNode.getProperty("title")+".\n");
		writer.flush();
		
           tx.success();
       } catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:40,代码来源:PosCounter.java

示例4: apply

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public void apply(Node node) {
	double secondMember = 0.0;
	for( Relationship rin : node.getRelationships() ) {
		Node neigh = rin.getOtherNode(node);
		
		double neighRank = (double) neigh.getProperty(attName);
		secondMember += neighRank / neigh.getDegree();
	}
	
	secondMember *= this.dampingFactor;
	node.setProperty(attName, firstMember + secondMember);
}
 
开发者ID:besil,项目名称:Neo4jSNA,代码行数:14,代码来源:PageRank.java

示例5: isConnected

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static boolean isConnected(final Node source, final Node target, final RelationshipType relationshipType) {
	final int sourceDegree = source.getDegree(relationshipType, Direction.OUTGOING);
	final int targetDegree = target.getDegree(relationshipType, Direction.INCOMING);
	
	final Direction searchDirection;
	final Node searchSource;
	final Node searchTarget;
	if (sourceDegree <= targetDegree) {
		searchDirection = Direction.OUTGOING;
		searchSource = source;
		searchTarget = target;
	} else {
		searchDirection = Direction.INCOMING;
		searchSource = target;
		searchTarget = source;
	}
	
	final Iterator<Relationship> edges = searchSource.getRelationships(searchDirection, relationshipType).iterator();
	while (edges.hasNext()) {
		final Relationship edge = edges.next();
		final Node otherNode = edge.getOtherNode(searchSource);
		if (searchTarget.equals(otherNode)) {
			return true;
		}
	}

	return false;
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:29,代码来源:Neo4jUtil.java

示例6: warmup

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@POST
@Path( "/warmup" )
public Response warmup() {
	final long start = System.currentTimeMillis();

	StreamingOutput stream = new StreamingOutput() {
		@Override
		public void write(OutputStream os) throws IOException, WebApplicationException {
			final Writer writer = new BufferedWriter(new OutputStreamWriter(os));
			System.out.println(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up database...");
			writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up database...\n");
			writer.flush();
			
			try (Transaction tx = database.beginTx()) {
				ResourceIterator<Node> corpIt = database.findNodes(NodeLabel.Corpus);
				
	            while (corpIt.hasNext()) {
	            	Node corpus = corpIt.next();
					List<Thread> threads = new ArrayList<Thread>();
	            	
	            	for (Relationship hasCollection : corpus.getRelationships(LinkLabel.HAS_COLLECTION, Direction.OUTGOING)) {
	            		Node collection = hasCollection.getOtherNode(corpus);
	            		Thread colWarmupThread = new Thread(new NodeWarmUp(database, writer, collection, start));
	            		colWarmupThread.start();
	            		threads.add(colWarmupThread);
	            		if (threads.size() == 16)
	            			threads = finishThreads(threads);
	            	}
	            	
	            	finishThreads(threads);
	            }
				
	            tx.success();
	        }

			System.out.println(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Completed database warmup.");
			writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Completed database warmup.\n");
			writer.flush();
		}
	};
	return Response.ok().entity( stream ).type( MediaType.TEXT_PLAIN ).build();
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:43,代码来源:DatabaseAdministration.java

示例7: run

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public void run() {
	try (Transaction tx = database.beginTx())
       {
		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up collection "+startNode.getProperty("title")+"...\n");
		writer.flush();
		int d = 0;
		for (Relationship hasDocument : startNode.getRelationships(LinkLabel.HAS_DOCUMENT, Direction.OUTGOING)) {
			Node document = hasDocument.getOtherNode(startNode);
			
			for (String key : document.getPropertyKeys()) {
           		document.getProperty(key);
           	}
           	
           	for (Relationship hasMetadatum : document.getRelationships(LinkLabel.HAS_METADATUM, Direction.OUTGOING)) {
           		Node metadatum = hasMetadatum.getOtherNode(document);
           		metadatum.getProperty("group");
           		metadatum.getProperty("key");
           		hasMetadatum.getProperty("value");
       		}
           	
           	for (Relationship hasToken : document.getRelationships(LinkLabel.HAS_TOKEN, Direction.OUTGOING)) {
           		Node token = hasToken.getOtherNode(document);
           		
           		for (Relationship hasAnnotation : token.getRelationships(Direction.OUTGOING)) {
           			Node annotation = hasAnnotation.getOtherNode(token);
           			if (annotation.hasProperty("label"))
           				annotation.getProperty("label");
           		}
           	}
           	d++;
           	if (d % 50000 == 0) {
           		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - "+startNode.getProperty("title")+": read "+String.valueOf(d)+" documents so far...\n");
   				writer.flush();
           	}
		}
		writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Finished warming up collection "+startNode.getProperty("title")+".\n");
		writer.flush();
		
           tx.success();
       } catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:45,代码来源:NodeWarmUp.java


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