在查找路径时,在py2neo中获取节点的字母数字引用

时间:2018-04-09 16:20:22

标签: neo4j py2neo

我有一个由DATASET和GRAPH节点组成的图表。有以下关系:

Hyperparameter Tuning Trial #4 Failed before any other successful trials were completed. The failed trial had parameters: optimizer=SGD, batch_size=128, learning_rate=0.00075073617775056709, . The trial's ror message was: The replica worker 1 exited with a non-zero status of 1. Termination reason: Error. Traceback (most recent call last): [...] File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 421, in train_and_evaluate executor.run() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 522, in run getattr(self, task_to_run)() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 532, in run_worker return self._start_distributed_training() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 715, in _start_distributed_training saving_listeners=saving_listeners) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/estimator.py", line 352, in train loss = self._train_model(input_fn, hooks, saving_listeners) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/estimator.py", line 891, in _train_model _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss]) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 546, in run run_metadata=run_metadata) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1022, in run run_metadata=run_metadata) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1113, in run raise six.reraise(*original_exc_info) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1098, in run return self._sess.run(*args, **kwargs) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1178, in run run_metadata=run_metadata)) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/basic_session_run_hooks.py", line 617, in after_run raise NanLossDuringTrainingError NanLossDuringTrainingError: NaN loss during training. The replica worker 3 exited with a non-zero status of 1. Termination reason: Error. Traceback (most recent call last): [...] File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 421, in train_and_evaluate executor.run() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 522, in run getattr(self, task_to_run)() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 532, in run_worker return self._start_distributed_training() File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/training.py", line 715, in _start_distributed_training saving_listeners=saving_listeners) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/estimator.py", line 352, in train loss = self._train_model(input_fn, hooks, saving_listeners) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/estimator/estimator.py", line 891, in _train_model _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss]) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 546, in run run_metadata=run_metadata) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1022, in run run_metadata=run_metadata) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1113, in run raise six.reraise(*original_exc_info) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1098, in run return self._sess.run(*args, **kwargs) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/monitored_session.py", line 1178, in run run_metadata=run_metadata)) File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/training/basic_session_run_hooks.py", line 617, in after_run raise NanLossDuringTrainingError NanLossDuringTrainingError: NaN loss during training.

DATASET->READS->GRAPH

当我运行以下内容时:GRAPH->WRITES->DATASET

在Neo4J桌面中,我得到的结果是正确的,其中存在节点名称。但是当我在py2neo中运行它时:

MATCH (p1:DATASET_NAME { name:'test1.dat' }),(p3:DATASET_NAME { name:'test32.txt' }), p = ((p1)-[:READS|:WRITES*1..8]->(p3))
RETURN p

我得到以下格式的结果:

graph.run("MATCH (p1:DATASET_NAME { name:'test1.dat' }),(p3:DATASET_NAME { name:'test32.txt' }), p = ((p1)-[:READS|:WRITES*1..8]->(p3)) RETURN p").dump()

我假设这些是某种参考。有没有办法从这些引用中获取(f3ff862)-[:READS]->(c539bdc)-[:WRITES]->(b217f5a)-[:READS]->(ebf9c4f)-[:WRITES]->(f9ddd22)-[:READS]->(fcca016)-[:WRITES]->(a9c241a)
(f3ff862)-[:READS]->(c539bdc)-[:WRITES]->(b217f5a)-[:READS]->(ebf9c4f)-[:WRITES]->(f9ddd22)-[:READS]->(fcca016)-[:WRITES]->(e152f69)-[:READS]->(fcca016)-[:WRITES]->(a9c241a) (f3ff862)-[:READS]->(c539bdc)-[:WRITES]->(b217f5a)-[:READS]->(ebf9c4f)-[:WRITES]->(cbc5d42)-[:READS]->(fcca016)-[:WRITES]->(a9c241a)
的字符串值?

1 个答案:

答案 0 :(得分:0)

您正在返回匹配的路径,因此您在py2neo中看到的是路径对象的表示。在neo4j控制台中,它会为您提供一些额外的查找,并将路径显示为一组节点和关系,并根据您在控制台中配置的内容对其进行标记。

如果要查看py2neo输出中的名称,可以使用返回路径reduce上的p函数生成包含节点名称和关系类型的字符串。这样的事情应该让你开始。

MATCH (p1:DATASET_NAME { name:'test1.dat' }),(p3:DATASET_NAME { name:'test32.txt' }), p = ((p1)-[:READS|:WRITES*1..8]->(p3))
RETURN head(nodes(p)).name + ' - ' + reduce(path_str = "", r in relationships(p) | path_str + type(r) + ' - ' + endnode(r).name)

在py2neo中[注意添加转义字符以避免密码错误。 @ ...reduce(path_str = \"\"...]:

graph.run("MATCH (p1:DATASET_NAME { name:'/projects/bkrpty_vfcn/bkrpty_vfcn_vendr/data/serial/temp/yyyymmdd_yyyymmddhhmiss_bk_mrk_stat_init.dat' }),(p3:DATASET_NAME { name:'/projects/bkrpty_vfcn/bkrpty_vfcn_vendr/tables/onevgb1/ai_bkrpty_case' }), p = ((p1)-[:READS|:WRITES*1..8]->(p3)) RETURN head(nodes(p)).name + ' - ' + reduce(path_str = \"\", r in relationships(p) | path_str + type(r) + ' - ' + endnode(r).name)").dump()