本文整理汇总了Java中org.neo4j.graphdb.Relationship.getEndNode方法的典型用法代码示例。如果您正苦于以下问题:Java Relationship.getEndNode方法的具体用法?Java Relationship.getEndNode怎么用?Java Relationship.getEndNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.graphdb.Relationship
的用法示例。
在下文中一共展示了Relationship.getEndNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildrenConnectedBy
import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static List<Node> getChildrenConnectedBy(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 childNode = rel.getEndNode();
if (childNode.getId() == nodeId)
continue;
retval.add(childNode);
}
return retval;
}
示例2: alternatingOrder
import org.neo4j.graphdb.Relationship; //导入方法依赖的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;
}
示例3: rankDest
import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
/**
* Rank the destination nodes of the outgoing edges of the given node.
* @param n the source node of the destination nodes to be ranked.
*/
private void rankDest(Node n) {
int baseSource = (int) n.getProperty(BASE_DIST.name())
+ (int) n.getProperty(Scores.SEQ_LENGTH.name());
int rankSource = (int) n.getProperty(RANK.name()) + 1;
for (Relationship r : n.getRelationships(RelTypes.NEXT, Direction.OUTGOING)) {
Node dest = r.getEndNode();
if ((int) dest.getProperty(BASE_DIST.name()) < baseSource) {
dest.setProperty(BASE_DIST.name(), baseSource);
}
if ((int) dest.getProperty(RANK.name()) < rankSource) {
dest.setProperty(RANK.name(), rankSource);
}
}
}
示例4: evaluate
import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public Collection<Neo4jSemaphoreNeighborInjectMatch> evaluate() {
final Collection<Neo4jSemaphoreNeighborInjectMatch> matches = new ArrayList<>();
final GraphDatabaseService graphDb = driver.getGraphDb();
try (Transaction tx = graphDb.beginTx()) {
// (route:Route)
final Iterable<Node> routes = () -> graphDb.findNodes(Neo4jConstants.labelRoute);
for (final Node route : routes) {
Iterable<Relationship> entries = route.getRelationships(Direction.OUTGOING, Neo4jConstants.relationshipTypeEntry);
for (Relationship entry : entries) {
final Node semaphore = entry.getEndNode();
final Map<String, Object> match = new HashMap<>();
match.put(QueryConstants.VAR_ROUTE, route);
match.put(QueryConstants.VAR_SEMAPHORE, semaphore);
matches.add(new Neo4jSemaphoreNeighborInjectMatch(match));
}
}
}
return matches;
}
示例5: 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;
}
示例6: getCalleeFromCall
import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
public static String getCalleeFromCall(Long nodeId)
{
Node node = Neo4JDBInterface.getNodeById(nodeId);
Iterable<Relationship> rels = node.getRelationships();
for (Relationship rel : rels)
{
if (!rel.getType().name().equals(EdgeTypes.IS_AST_PARENT))
continue;
Node endNode = rel.getEndNode();
if (endNode.getId() == node.getId())
continue;
try
{
String childNumStr = (String) endNode
.getProperty(NodeKeys.CHILD_NUMBER);
if (childNumStr.equals("0"))
return endNode.getProperty(NodeKeys.CODE).toString();
}
catch (RuntimeException ex)
{
return endNode.getProperty(NodeKeys.CODE).toString();
}
}
return "";
}
示例7: repeatLastOrder
import org.neo4j.graphdb.Relationship; //导入方法依赖的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;
}
示例8: 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;
}
示例9: 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);
}
示例10: 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();
}
示例11: 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 );
}
示例12: 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;
}
}
示例13: 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();
}
示例14: evaluate
import org.neo4j.graphdb.Relationship; //导入方法依赖的package包/类
@Override
public Collection<Neo4jSwitchMonitoredMatch> evaluate() {
final Collection<Neo4jSwitchMonitoredMatch> matches = new ArrayList<>();
final GraphDatabaseService graphDb = driver.getGraphDb();
try (Transaction tx = graphDb.beginTx()) {
final Iterable<Node> sws = () -> graphDb.findNodes(Neo4jConstants.labelSwitch);
// (sw:Switch)
for (final Node sw : sws) {
// (sw)-[:sensor]->(Sensor) NAC
final Iterable<Relationship> relationshipSensors = sw.getRelationships(Direction.OUTGOING, Neo4jConstants.relationshipTypeMonitoredBy);
boolean hasSensor = false;
for (final Relationship relationshipSensor : relationshipSensors) {
final Node sensor = relationshipSensor.getEndNode();
if (sensor.hasLabel(Neo4jConstants.labelSensor)) {
hasSensor = true;
break;
}
}
if (!hasSensor) {
final Map<String, Object> match = new HashMap<>();
match.put(VAR_SW, sw);
matches.add(new Neo4jSwitchMonitoredMatch(match));
}
}
}
return matches;
}
示例15: 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();
}