对于使用弹簧数据neo4j的图形,我有以下定义。
更新关系时,更改将传播到关系的节点(@StartNode和@EndNode)。我如何避免这种行为?
我只想更新@RelationshipEntity,而不要更新关系的节点。
谢谢
@Data
public class Graph {
@Id
@GeneratedValue
private Long id;
private String name;
@Relationship(type = "MADE_OF")
private List<Relationship> relationships = new ArrayList<>();
}
@Data
@RelationshipEntity(type = "MADE_OF")
public final class Relationship {
@Id
@GeneratedValue
private Long id;
@StartNode
private Node source;
@EndNode
private Node target;
}
@Data
public class Node {
@Id
@GeneratedValue
private Long id;
private String name;
private String description;
}
答案 0 :(得分:0)
如果使用[batch_size, height, num_channels, width]
,则不能不更新关系的开始和结束节点而更新关系。即使您指定了input_data = tf.Variable(tf.random_normal([2,16,16,200], mean=10, stddev=10))
# compute mean over channels dimension using tf.reduce_mean
mean = tf.reduce_mean(input_data, reduction_indices=[3], keep_dims=True)
# transpose to [batch_size, height, num_channels, width]
input_t = tf.transpose(input_data, [0,1,3,2])
# get the value of num_channels
num_channels = input_t.get_shape().as_list()[2]
# compute mean using tf.nn.avg_pool
avg = tf.nn.avg_pool(value=input_t,
ksize=[1, 1, num_channels, 1],
strides=[1, 1, num_channels, 1],
padding="SAME")
# transpose back to original form
input_tt = tf.transpose(avg, [0,1,3,2])
sess = tf. InteractiveSession()
sess.run(tf.initialize_all_variables())
avg_value = input_tt.eval()
print("Shape after avg_pool method: %s" % str(avg_value.shape))
# >>> (2, 16, 16, 1)
mean_value = mean.eval()
print("Shape after reduce_mean method: %s" % str(mean_value.shape))
# >>> (2, 16, 16, 1)
之类的session.save(entity)
。
如果您要持久保存的对象是deph
,则持久保存意味着开始节点和结束节点也将持久保存。它来自session.save(entity, depth)
lib中的RelationshipEntity
请考虑直接使用org.neo4j.ogm.context.EntityGraphMapper.map(Object, int)
来更新您的关系属性。
neo4j-ogm-core