HelloSparksee sample - how to get the roles played by actors?

14 views
Skip to first unread message

Robert Pappenhagen

unread,
Aug 27, 2015, 2:08:30 PM8/27/15
to Sparksee
Part of the "joy" of a sample project is being able to actually see it work. Running it in release mode is not very helpful. So now that I've figured out VS char_t issues
I'm moving on to print out the various query results to gett a better feel of what I'd need to do in a real environment.

So I'd like to print out the roles played by the actors in movies directed by woody allen...

We have from prior queries the movies, and the actors in those movies (both sets are nodes)
How do I get from a node the edge called Cast and from there back to the attribute for the role played

C++
Visual Studio 12


c3po.ac

unread,
Aug 28, 2015, 5:03:00 AM8/28/15
to Sparksee

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:
Reply all
Reply to author
Forward
0 new messages