Boost Graph ライブラリを使用して、yEd で作成された .graphml ファイルからグラフ関連の (カスタム) プロパティを読み取ろうとしています。頂点とエッジ (dynamic_) プロパティの読み取りは機能しますが、グラフのプロパティは常に空です。また、boost::read_graphml でグラフ ドメイン属性を読み取る方法にも遭遇しました。しかし、そのソリューションは空の文字列を生成するだけです (以下のコードにあります)。それとは別に、問題に関する多くの情報を見つけることができませんでした。
短縮されたコードは次のとおりです(完全な動作例test.cpp
はこちら):
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
、グラフには
<data key="d1"><![CDATA[foobar]]></data>
として定義されているタグ
<key attr.name="title" attr.type="string" for="graph" id="d1">
<default/>
</key>
simple_graph.graphml サンプル ファイルをアップロードしました(画像や詳細を投稿するには十分な担当者がいません)。
マイナーなフォローアップの質問: yEd でエクスポートされたファイル (コードを参照) を「修正」せずにグラフをロードすることは可能ですか? パーサーは常に次のような行について不平を言います (標準で許可されている GraphML 標準で許可されているかどうかは不明です:「このグループは、2 つのオプションの属性で構成されています - attr.name (データ関数の名前を指定します) - attr.type ((データ関数の値の範囲を宣言します)):
<key for="port" id="d2" yfiles.type="portgraphics"/>
このエラーで:
解析エラー: キーのタイプ "" を認識できません
ヘルプ/アイデアは大歓迎です。どうもありがとうございました!