Hi,
From a node (oid) or a set of nodes (Objects) you can get the edges connected to them using "Explode".
For example, instead of directly getting the actors from the movies directed by Woody like this:
// Get the cast of the movies directed by Woody Allen
Objects *castDirectedByWoody = g->Neighbors(directedByWoody, castType, Any);
You can get the cast edges like this:
// Get the cast edges of the movies directed by Woody Allen
Objects *castEdgesDirectedByWoody = g->Explode(directedByWoody, castType, Any);
With an edge oid you can get the basic edge information (tail and head nodes) using "GetEdgeData" or it's attributes in the same way as the attributes of a node.
For example:
// Iterate the cast edges
ObjectsIterator *it = castEdgesDirectedByWoody->Iterator();
while (it->HasNext())
{
// Get the Character attribute from the edge
oid_t castEdgeOid = it->Next();
g->GetAttribute(castEdgeOid, castCharacterType, *value);
std::wcout << L"The character played is " << value->GetString() << std::endl;
// We can also get the movie and the actor nodes from the cast edge
EdgeData *edge = g->GetEdgeData(castEdgeOid);
oid_t movieOid = edge->GetTail();
oid_t actorOid;
// In this example, we know that the cast edges go from movie to people, but
// it's not a restricted edge, so we should check the node type to see if the
// movie is the head or the tail of the edge.
if ( g->GetObjectType(movieOid) == movieType )
{
// the movie is in the tail and the people in the head of the edge
actorOid = edge->GetHead();
}
else
{
// the movie is in the head and the people in the tail of the edge
// This will never happen in this example because the movies are
// always in the "tail" side of all our CAST edges.
actorOid = edge->GetTail();
movieOid = edge->GetHead();
}
// We can get attributes from the nodes
g->GetAttribute(movieOid, movieTitleType, *value);
std::wcout << L"The movie is " << value->GetString() << std::endl;
g->GetAttribute(actorOid, peopleNameType, *value);
std::wcout << L"The actor is " << value->GetString() << std::endl;
delete edge;
}
delete it;
delete castEdgesDirectedByWoody;
Best regards.
El dijous, 27 agost de 2015 20:08:30 UTC+2, Robert Pappenhagen va escriure: