在 igraph 和 NetworkX 中读取缺少数据的 GML 文件时出错

问题描述

我有一组网络,其中包含一些缺失的节点属性数据。我需要能够在 igraph、NetworkX 和 Gephi 中访问这些网络。我知道我可以在 GML 中将缺失值记录为 NAN,igraph 会理解它,但 NetworkX 不会(出现此错误消息:networkx.exception.NetworkXError: expected an int,float,string or '[',found 'NAN' at (16,9))。

GML 文件看起来像这样(称为“export.gml”):

graph [
  directed 1
  node [
    id 0
    label "1"
    age 1
  ]
  node [
    id 1
    label "2"
    age 2
  ]
  node [
    id 2
    label "3"
    age "NA"
  ]
  edge [
    source 0
    target 1
  ]
  edge [
    source 1
    target 2
  ]
  edge [
    source 2
    target 0
  ]
]

我可以在 Python 中的 igraph 中打开这个文件,直到最近我还可以在 R 中打开类似的文件。截至今天,这是我得到的,首先是在 Python 中:

>>> import igraph
>>> g = igraph.read("export.gml")
>>> g.vs["age"]
['1','2','NA']

然后在 R 中:

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos,'help()' for on-line help,or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(igraph)

Attaching package: ‘igraph’

The following objects are masked from ‘package:stats’:

    decompose,spectrum

The following object is masked from ‘package:base’:

    union

> igraph_version()
[1] "1.2.6"
> g <- read_graph("export.gml",format = "gml")

 *** caught segfault ***
address (nil),cause 'memory not mapped'

Traceback:
 1: read.graph.gml(file,...)
 2: read_graph("export.gml",format = "gml")

Possible actions:
1: abort (with core dump,if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

有没有办法在 R igraph 中打开这个文件?或者,有没有办法让 NetworkX 正确解释 GML 文件中的 NAN

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)