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


Java Relationship.getStartNode方法代码示例

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


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

示例1: getParentsConnectedBy

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static List<Node> getParentsConnectedBy(Node node, String edgeType)
{
	List<Node> retval = new LinkedList<Node>();

	long nodeId = node.getId();

	Iterable<Relationship> rels = node.getRelationships();
	for (Relationship rel : rels)
	{
		if (!rel.getType().name().equals(edgeType))
			continue;
		Node parentNode = rel.getStartNode();
		if (parentNode.getId() == nodeId)
			continue;

		retval.add(parentNode);
	}
	return retval;
}
 
开发者ID:RUB-SysSec,项目名称:EvilCoder,代码行数:20,代码来源:Traversals.java

示例2: getAdjacentNodes

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static Iterable<Node> getAdjacentNodes(final Node sourceNode, final RelationshipType relationshipType, final Direction direction, final Label targetNodeLabel) {
	final Collection<Node> nodes = new ArrayList<>();
	
	final Iterable<Relationship> relationships = sourceNode.getRelationships(relationshipType, direction);
	for (final Relationship relationship : relationships) {
		final Node candidate;
		switch (direction) {
		case INCOMING:
			candidate = relationship.getStartNode();
			break;
		case OUTGOING:
			candidate = relationship.getEndNode();			
			break;
		default:
			throw new UnsupportedOperationException("Direction: " + direction + " not supported.");
		}
		if (!candidate.hasLabel(targetNodeLabel)) {
			continue;
		}
		nodes.add(candidate);
	}
	return nodes;
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:24,代码来源:Neo4jUtil.java

示例3: getStatementForASTNode

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static Node getStatementForASTNode(Node node)
{
	Node n = node;
	Node parent = node;

	while (true)
	{

		try
		{
			Object property = n.getProperty(NodeKeys.IS_CFG_NODE);
			return n;
		}
		catch (NotFoundException ex)
		{

		}

		Iterable<Relationship> rels = n
				.getRelationships(Direction.INCOMING);
		for (Relationship rel : rels)
		{
			parent = rel.getStartNode();
			break;
		}

		if (n == parent)
			return null;
		n = parent;
	}
}
 
开发者ID:RUB-SysSec,项目名称:EvilCoder,代码行数:32,代码来源:Traversals.java

示例4: topReorderedBoostedByCartOrder

import org.neo4j.graphdb.Relationship; //导入方法依赖的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

示例5: prepare

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
private void prepare() {
    List<String> entities = new ArrayList<>();
    List<String> relations = new ArrayList<>();
    List<Triple<String, String, String>> triples = new ArrayList<>();
    try (Transaction tx = db.beginTx()) {
        for (Node node : db.getAllNodes()) {
            if (!node.hasLabel(Label.label(JavaCodeExtractor.CLASS)) &&
                    !node.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)) &&
                    !node.hasLabel(Label.label(JavaCodeExtractor.METHOD)) &&
                    !node.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
                continue;
            entities.add("" + node.getId());
        }

        for (Relationship rel : db.getAllRelationships()) {
            Node node1 = rel.getStartNode();
            if (!node1.hasLabel(Label.label(JavaCodeExtractor.CLASS)) &&
                    !node1.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)) &&
                    !node1.hasLabel(Label.label(JavaCodeExtractor.METHOD)) &&
                    !node1.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
                continue;
            Node node2 = rel.getEndNode();
            if (!node2.hasLabel(Label.label(JavaCodeExtractor.CLASS)) &&
                    !node2.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)) &&
                    !node2.hasLabel(Label.label(JavaCodeExtractor.METHOD)) &&
                    !node2.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
                continue;
            triples.add(new ImmutableTriple<>("" + node1.getId(), "" + node2.getId(), rel.getType().name()));
            if (!relations.contains(rel.getType().name()))
                relations.add(rel.getType().name());
        }
        tx.success();
    }
    transE.prepare(entities, relations, triples);
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:36,代码来源:TransExtractor.java

示例6: getMetadataGroupKeyValueDocuments

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
protected Response getMetadataGroupKeyValueDocuments(final String group, final String key, final String value) {
	StreamingOutput stream = new StreamingOutput()
	{
		@Override
		public void write( OutputStream os ) throws IOException, WebApplicationException
		{
			try ( Transaction tx = database.beginTx() ) {
				JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
				IndexManager index = database.index();
				Index<Relationship> metadataValues = index.forRelationships("HAS_METADATUM");
				List<String> documentsSeen = new ArrayList<String>();
				jg.writeStartArray();
				
				System.out.println("VALUE: "+value);
				for (Relationship hasMetadatum : metadataValues.get("value", value)) {
					Node metadatum = hasMetadatum.getEndNode();
					String mGroup = (String) metadatum.getProperty("group");
					String mKey = (String) metadatum.getProperty("key");
					if (mGroup.equals(group) && mKey.equals(key)) {
						Node document = hasMetadatum.getStartNode();
						String xmlid = (String) document.getProperty("xmlid");
						if (!documentsSeen.contains(xmlid)) {
							jg.writeString(xmlid);
							documentsSeen.add(xmlid);
						}
					}
				}
				
				jg.writeEndArray();
				jg.flush();
				tx.success();
			}
		}
	};

	return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:38,代码来源:MetadatumSearcher.java

示例7: doGetForRelationships

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Test
public void doGetForRelationships()
{
    RelationshipIndex roles = graphDb.index().forRelationships( "roles" );

    // START SNIPPET: getSingleRelationship
    Relationship persephone = roles.get( "name", "Persephone" ).getSingle();
    Node actor = persephone.getStartNode();
    Node movie = persephone.getEndNode();
    // END SNIPPET: getSingleRelationship

    assertEquals( "Monica Bellucci", actor.getProperty( "name" ) );
    assertEquals( "The Matrix Reloaded", movie.getProperty( "title" ) );

    @SuppressWarnings("serial") List<String> expectedActors = new ArrayList<String>()
    {
        {
            add( "Keanu Reeves" );
            add( "Keanu Reeves" );
        }
    };
    List<String> foundActors = new ArrayList<>();

    // START SNIPPET: getRelationships
    for ( Relationship role : roles.get( "name", "Neo" ) )
    {
        // this will give us Reeves twice
        Node reeves = role.getStartNode();
        // END SNIPPET: getRelationships
        foundActors.add( (String) reeves.getProperty( "name" ) );
        // START SNIPPET: getRelationships
    }
    // END SNIPPET: getRelationships

    assertEquals( expectedActors, foundActors );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:37,代码来源:ImdbDocTest.java

示例8: compute

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public void compute(Relationship r) {
	Node n1 = r.getStartNode();
	Node n2 = r.getEndNode();
	
	if( n1.getProperty(attName) == n2.getProperty(attName) ) {
		double weight = r.hasProperty("weight") ? (double) r.getProperty("weight") : 1.0;
		eii += weight;
	}
}
 
开发者ID:besil,项目名称:Neo4jSNA,代码行数:11,代码来源:DirectedModularity.java

示例9: singleNeighborhood

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static Node singleNeighborhood(Node node, RelationshipTypes rel, Direction direction, boolean startNode) {
    Iterator<Relationship> it = node.getRelationships(rel, direction).iterator();
    if ( !it.hasNext() ){
        return null;
    }

    Relationship r = it.next();
    if (startNode)
        return r.getStartNode();
    return r.getEndNode();
}
 
开发者ID:vahidooo,项目名称:quranic-graph,代码行数:12,代码来源:NodeUtils.java

示例10: getMetadataGroupKeyValueDocumentsWithCounts

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
protected Response getMetadataGroupKeyValueDocumentsWithCounts(final String group, final String key, final String value) {
	StreamingOutput stream = new StreamingOutput()
	{
		@Override
		public void write( OutputStream os ) throws IOException, WebApplicationException
		{
			try ( Transaction tx = database.beginTx() ) {
				JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
				IndexManager index = database.index();
				Index<Relationship> metadataValues = index.forRelationships("HAS_METADATUM");
				List<String> documentsSeen = new ArrayList<String>();
				jg.writeStartArray();
				
				System.out.println("VALUE: "+value);
				for (Relationship hasMetadatum : metadataValues.get("value", value)) {
					Node metadatum = hasMetadatum.getEndNode();
					String mGroup = (String) metadatum.getProperty("group");
					String mKey = (String) metadatum.getProperty("key");
					if (mGroup.equals(group) && mKey.equals(key)) {
						Node document = hasMetadatum.getStartNode();
						String xmlid = (String) document.getProperty("xmlid");
						if (!documentsSeen.contains(xmlid)) {
							jg.writeStartObject();
							jg.writeStringField("xmlid", xmlid);
							Object tokenCount = document.getProperty("token_count");
							if (tokenCount instanceof Long)
								jg.writeNumberField("token_count", (Long) tokenCount);
							else if (tokenCount instanceof Integer)
								jg.writeNumberField("token_count", (Integer) tokenCount);
							jg.writeEndObject();
							documentsSeen.add(xmlid);
						}
					}
				}
				
				jg.writeEndArray();
				jg.flush();
				tx.success();
			}
		}
	};

	return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:45,代码来源:MetadatumSearcher.java

示例11: doQueriesForRelationships

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Test
public void doQueriesForRelationships()
{
    IndexManager index = graphDb.index();
    RelationshipIndex roles = index.forRelationships( "roles" );
    Index<Node> actors = graphDb.index().forNodes( "actors" );
    Index<Node> movies = index.forNodes( "movies" );

    Node reeves = actors.get( "name", "Keanu Reeves" ).getSingle();
    Node theMatrix = movies.get( "title", "The Matrix" ).getSingle();

    // START SNIPPET: queryForRelationships
    // find relationships filtering on start node
    // using exact matches
    IndexHits<Relationship> reevesAsNeoHits;
    reevesAsNeoHits = roles.get( "name", "Neo", reeves, null );
    Relationship reevesAsNeo = reevesAsNeoHits.iterator().next();
    reevesAsNeoHits.close();
    // END SNIPPET: queryForRelationships
    assertEquals( "Neo", reevesAsNeo.getProperty( "name" ) );
    Node actor = reevesAsNeo.getStartNode();
    assertEquals( reeves, actor );

    // START SNIPPET: queryForRelationships
    // find relationships filtering on end node
    // using a query
    IndexHits<Relationship> matrixNeoHits;
    matrixNeoHits = roles.query( "name", "*eo", null, theMatrix );
    Relationship matrixNeo = matrixNeoHits.iterator().next();
    matrixNeoHits.close();
    // END SNIPPET: queryForRelationships
    assertEquals( "Neo", matrixNeo.getProperty( "name" ) );
    actor = matrixNeo.getStartNode();
    assertEquals( reeves, actor );

    // START SNIPPET: queryForRelationshipType
    // find relationships filtering on end node
    // using a relationship type.
    // this is how to add it to the index:
    roles.add( reevesAsNeo, "type", reevesAsNeo.getType().name() );
    // Note that to use a compound query, we can't combine committed
    // and uncommitted index entries, so we'll commit before querying:
    tx.success();
    tx.close();

    // and now we can search for it:
    try ( Transaction tx = graphDb.beginTx() )
    {
        IndexHits<Relationship> typeHits = roles.query( "type:ACTS_IN AND name:Neo", null, theMatrix );
        Relationship typeNeo = typeHits.iterator().next();
        typeHits.close();
        // END SNIPPET: queryForRelationshipType
        assertThat(typeNeo, inTx( graphDb, hasProperty( "name" ).withValue( "Neo" ) ));
        actor = matrixNeo.getStartNode();
        assertEquals( reeves, actor );
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:58,代码来源:ImdbDocTest.java

示例12: populateGraph

import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
static void populateGraph(GraphDatabaseService graphDb) {
  try (Transaction tx = graphDb.beginTx()) {
    Relationship r1 = addRelationship("http://x.org/a_a", "http://x.org/a_b", OwlRelationships.RDFS_SUBCLASS_OF);
    Relationship r2 = addRelationship("http://x.org/a_b", "http://x.org/a_c", OwlRelationships.RDFS_SUBCLASS_OF);
    Relationship r3 = addRelationship("http://x.org/a_c", "http://x.org/a_d", OwlRelationships.RDF_TYPE);
    Relationship r4 = addRelationship("http://x.org/a_e", "http://x.org/a_d", RelationshipType.withName("CAUSES"));
    Relationship r5 = addRelationship("http://x.org/a_f", "http://x.org/a_e", RelationshipType.withName("partOf"));
    graph.setRelationshipProperty(r4.getId(), CommonProperties.IRI, "http://x.org/a_causes");
    addRelationship("http://x.org/a_causes_parent", "http://x.org/a_causes", OwlRelationships.RDFS_SUB_PROPERTY_OF);
    addRelationship("_:anon", "http://x.org/a_b", OwlRelationships.RDFS_SUBCLASS_OF);
    r1.getEndNode().setProperty(NodeProperties.LABEL, "A");
    r2.getStartNode().setProperty(NodeProperties.LABEL, "C");
    a = r1.getEndNode();
    b = r2.getEndNode();
    c = r2.getStartNode();
    d = r3.getStartNode();
    e = r4.getEndNode();
    f = r5.getEndNode();
    Node assn = createNode("http://x.org/a_assn");
    Node assnParent = createNode("http://x.org/a_assn_parent");
    assn.createRelationshipTo(assnParent, OwlRelationships.RDFS_SUBCLASS_OF);
    Node evidence = createNode("http://x.org/a_evidence");
    assn.createRelationshipTo(evidence, RelationshipType.withName("http://purl.obolibrary.org/obo/RO_0002558"));
    assn.createRelationshipTo(d, RelationshipType.withName("http://purl.org/oban/association_has_subject"));
    assn.createRelationshipTo(e, RelationshipType.withName("http://purl.org/oban/association_has_object"));
    
    Node gene = createNode("http://x.org/gene");
    gene.addLabel(Label.label("gene"));
    Node ortholog = createNode("http://x.org/gene_ortholog");
    ortholog.addLabel(Label.label("gene"));
    gene.createRelationshipTo(ortholog, RelationshipType.withName("http://purl.obolibrary.org/obo/RO_HOM0000017"));

    Node foo = createNode("http://x.org/gene");
    foo.addLabel(Label.label("gene"));

    Node forebrain = createNode("http://purl.obolibrary.org/obo/UBERON_0001890");
    forebrain.addLabel(Label.label("forebrain"));
    forebrain.addLabel(Label.label("anatomical entity"));
    Relationship foo2forebrain = foo.createRelationshipTo(forebrain, RelationshipType.withName("http://purl.obolibrary.org/obo/RO_0002206"));
    foo2forebrain.setProperty(CommonProperties.IRI, "http://purl.obolibrary.org/obo/RO_0002206");

    Node brain = createNode("http://purl.obolibrary.org/obo/UBERON_0000955");
    brain.addLabel(Label.label("brain"));
    brain.addLabel(Label.label("anatomical entity"));
    Relationship forebrain2brain = forebrain.createRelationshipTo(brain, RelationshipType.withName("http://purl.obolibrary.org/obo/BFO_0000050"));
    forebrain2brain.setProperty(CommonProperties.IRI, "http://purl.obolibrary.org/obo/BFO_0000050");

    Node neuralTube = createNode("http://purl.obolibrary.org/obo/UBERON_0001049");
    neuralTube.addLabel(Label.label("neural tube"));
    neuralTube.addLabel(Label.label("anatomical entity"));
    Relationship brain2neuralTube = brain.createRelationshipTo(neuralTube, RelationshipType.withName("http://purl.obolibrary.org/obo/RO_0002202"));
    brain2neuralTube.setProperty(CommonProperties.IRI, "http://purl.obolibrary.org/obo/RO_0002202");

    Node head = createNode("http://purl.obolibrary.org/obo/UBERON_0000033");
    head.addLabel(Label.label("head"));
    head.addLabel(Label.label("anatomical entity"));
    Relationship brain2head = brain.createRelationshipTo(head, RelationshipType.withName("http://purl.obolibrary.org/obo/BFO_0000050"));
    brain2head.setProperty(CommonProperties.IRI, "http://purl.obolibrary.org/obo/BFO_0000050");

    Node bodyPart = createNode("http://x.org/body_part");
    bodyPart.addLabel(Label.label("body part"));
    bodyPart.addLabel(Label.label("anatomical entity"));
    Relationship head2bodyPart = head.createRelationshipTo(bodyPart, OwlRelationships.RDFS_SUBCLASS_OF);
    head2bodyPart.setProperty(CommonProperties.IRI, OwlRelationships.RDFS_SUBCLASS_OF.name());

    Node anatomicalEntity = createNode("http://purl.obolibrary.org/obo/UBERON_0001062");
    anatomicalEntity.addLabel(Label.label("anatomical entity"));
    Relationship bodyPart2anatomicalEntity = bodyPart.createRelationshipTo(anatomicalEntity, OwlRelationships.RDFS_SUBCLASS_OF);
    bodyPart2anatomicalEntity.setProperty(CommonProperties.IRI, OwlRelationships.RDFS_SUBCLASS_OF.name());

    tx.success();
  }
}
 
开发者ID:SciGraph,项目名称:golr-loader,代码行数:74,代码来源:GolrLoadSetup.java


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