【发布时间】:2016-12-25 00:31:03
【问题描述】:
我正在尝试从使用 Boost Graph 库的 yEd 创建的 .graphml 文件中读取与图形相关的(自定义)属性。读取顶点和边 (dynamic_) 属性有效,但我的 图形属性始终为空。我也遇到过how to read graph-domain attributes with boost::read_graphml?,但该解决方案只会产生空字符串(它在下面的代码中)。除此之外,我无法找到有关该问题的太多信息。
这是缩短的代码 (complete working example test.cpp here):
struct VertexProperties { string url, description; };
struct EdgeProperties { string url, description; };
struct GraphProperties { string title; };
// ...
typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperties, GraphProperties> DirectedGraph;
typedef dynamic_properties Properties;
DirectedGraph graph(0);
Properties props(ignore_other_properties);
props.property("url", get(&VertexProperties::url, graph));
props.property("description", get(&VertexProperties::description, graph));
props.property("url", get(&EdgeProperties::url, graph));
props.property("description", get(&EdgeProperties::description, graph));
map<string, string> attribute_name2name;
associative_property_map<map<string, string>> graphname_map(attribute_name2name);
props.property("title", graphname_map);
// ...
read_graphml(validated, graph, props);
graph[graph_bundle].title = get(graphname_map, "title");
cout << "\"" << graph[graph_bundle].title << "\"" << endl;
您可以使用g++ test.cpp --std=c++11 -o test -lboost_graph编译完整代码。使用./test simple_graph.graphml 运行它只会产生“”而不是“foobar”,这是预期的输出,因为图表有
<data key="d1"><![CDATA[foobar]]></data>
标签定义为
<key attr.name="title" attr.type="string" for="graph" id="d1">
<default/>
</key>
我上传了simple_graph.graphml example file(没有足够的代表来发布 img/更多详细信息)。
后续小问题:是否可以在不“修复” yEd 导出文件的情况下加载图表(参见代码)?解析器总是抱怨这样的行(不确定是否在 GraphML 标准中允许在标准中允许:“该组由两个 可选 属性 - attr. name(给出数据函数的名称)- attr.type((声明数据函数的值范围)。”):
<key for="port" id="d2" yfiles.type="portgraphics"/>
出现此错误:
解析错误:键的类型“”无法识别
非常感谢任何帮助/想法。非常感谢!
【问题讨论】:
-
this issue 可能相关,因为这两个错误都处理空 CDATA 解析结果。标记中的 CDATA 部分是否有解决方法?
-
感谢您的回复!好点(我的代码中没有解决方法),但我认为它不相关,因为顶点和边属性被正确解析并且它们也在使用 CDATA,例如,(对于顶点)
<data key="d6"><![CDATA[just a test]]></data>。为了测试,我还删除了图形属性 (-><data key="d1">foobar</data>) 中的 CDATA,但我仍然有空的图形属性。更多想法?
标签: c++ boost graph graphml dynamic-properties