comp-think / 2021-2022

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2021/2022).
18 stars 9 forks source link

Lecture "Organising information: graphs", exercise 2 #38

Open essepuntato opened 2 years ago

essepuntato commented 2 years ago

Create a directed graph that relates the actors Brad Pitt, Eva Green, George Clooney, Catherine Zeta-Jones, Johnny Depp, and Helena Bonham Carter to the following movies: Ocean's Twelve, Fight Club, Dark Shadows.

MaddaGh commented 2 years ago
from networkx import MultiDiGraph

actor_film=MultiDiGraph()

actor_film.add_node("Brad Pitt")
actor_film.add_node("Catherine Zeta-Jones")
actor_film.add_node("Eva Green")
actor_film.add_node("George Clooney")
actor_film.add_node("Helena Bonham-Carter")
actor_film.add_node("Johnny Depp")
actor_film.add_node("Dark Shadows")
actor_film.add_node("Fight Club")
actor_film.add_node("Ocean's Twelve")

actor_film.add_edge("Ocean's Twelve", "Brad Pitt")
actor_film.add_edge("Ocean's Twelve", "Catherine Zeta-Jones")
actor_film.add_edge("Ocean's Twelve", "George Clooney")
actor_film.add_edge("Fight Club", "Brad Pitt")
actor_film.add_edge("Fight Club", "Helena Bonham-Carter")
actor_film.add_edge("Dark Shadows", "Eva Green")
actor_film.add_edge("Dark Shadows", "Jhonny Depp")
actor_film.add_edge("Dark Shadows", "Helena Bonham-Carter")

print(actor_film.nodes())
print(actor_film.edges())
11051620 commented 2 years ago

Screenshot 2021-12-15 at 16 25 23

OrsolaMBorrini commented 2 years ago
from networkx import MultiDiGraph

movies_graph = MultiDiGraph()

movies_graph.add_node("Brad Pitt")
movies_graph.add_node("Eva Green")
movies_graph.add_node("George Clooney")
movies_graph.add_node("Catherine Zeta-Jones")
movies_graph.add_node("Johnny Depp")
movies_graph.add_node("Helena Bonham Carter")

movies_graph.add_edge("Brad Pitt","Fight Club")
movies_graph.add_edge("Brad Pitt","Ocean's Twelve")
movies_graph.add_edge("Eva Green","Dark Shadows")
movies_graph.add_edge("George Clooney","Ocean's Twelve")
movies_graph.add_edge("Catherine Zeta-Jones","Ocean's Twelve")
movies_graph.add_edge("Johnny Depp","Dark Shadows")
movies_graph.add_edge("Helena Bonham Carter","Fight Club")
movies_graph.add_edge("Helena Bonham Carter","Dark Shadows")
Postitisnt commented 2 years ago
from networkx import MultiDiGraph

MoviesCast_DirGraph = MultiDiGraph()

MoviesCast_DirGraph.add_edge("Brad Pitt", "Ocean's Twelve")
MoviesCast_DirGraph.add_edge("Brad Pitt", "Fight Club")
MoviesCast_DirGraph.add_edge("George Clooney", "Ocean's Twelve")
MoviesCast_DirGraph.add_edge("Eva Green", "Dark Shadows")
MoviesCast_DirGraph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")
MoviesCast_DirGraph.add_edge("Helena Bonham Carter", "Fight Club")
MoviesCast_DirGraph.add_edge("Helena Bonham Carter", "Dark Shadows")
MoviesCast_DirGraph.add_edge("Johnny Depp", "Dark Shadows")

print(MoviesCast_DirGraph.nodes())
print(MoviesCast_DirGraph.edges())
AnastasiyaSopyryaeva commented 2 years ago
from networkx import DiGraph

movies = DiGraph()

movies.add_edge("Ocean's Twelve", "Brad Pitt")
movies.add_edge("Ocean's Twelve", "George Clooney")
movies.add_edge("Ocean's Twelve", "Catherine Zeta-Jones")

movies.add_edge("Fight Club", "Brad Pitt")
movies.add_edge("Fight Club", "Helena Bonham Carter")

movies.add_edge("Dark Shadows", "Johnny Depp")
movies.add_edge("Dark Shadows", "Eva Green")
movies.add_edge("Dark Shadows", "Helena Bonham Carter")

print(movies.nodes())
print(movies.edges())
ManueleVeggi commented 2 years ago

If I checked correctly, the graph should contain the following information

Actor Starring in
Bread Pitt Ocean's Twelve, Fight Club
Eva Green Dark Shadows
George Clooney Ocean's Twelve
Catherine Zeta-Jones Ocean's Twelve
Johnny Depp Dark Shadows
Helena Bonham Carter Fight Club, Dark Shadows

The graph translating this schema is:

from networkx import DiGraph

movieGraph = DiGraph()

#Actors
movieGraph.add_node("Bread Pitt")
movieGraph.add_node("Eva Green")
movieGraph.add_node("George Clooney")
movieGraph.add_node("Catherine Zeta-Jones")
movieGraph.add_node("Johnny Depp")
movieGraph.add_node("Helena Bonham Carter")

#Movies
movieGraph.add_node("Ocean's Twelve")
movieGraph.add_node("Fight Club")
movieGraph.add_node("Dark Shadows")

#Edges
movieGraph.add_edge("Bread Pitt", "Ocean's Twelve")
movieGraph.add_edge("Bread Pitt", "Fight Club")
movieGraph.add_edge("Eva Green", "Dark Shadows")
movieGraph.add_edge("George Clooney", "Ocean's Twelve")
movieGraph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")
movieGraph.add_edge("Johnny Depp", "Dark Shadows")
movieGraph.add_edge("Helena Bonham Carter", "Fight Club")
movieGraph.add_edge("Helena Bonham Carter", "Dark Shadows")
angstigone commented 2 years ago
Schermata 2021-12-19 alle 19 44 23
katya-avem commented 2 years ago

image

AmeliaLamargese commented 2 years ago
from networkx import Graph

my_graph = DiGraph()

my_graph.add_node(1, name = "Brad Pitt")
my_graph.add_node(2, name = "Eva Green")
my_graph.add_node(3, name = "George Clooney")
my_graph.add_node(4, name = "Catherine Zeta-Jones")
my_graph.add_node(5, name = "Johnny Depp")
my_graph.add_node(6, name = "Helena Bonham Carter")
my_graph.add_node(7, name = "Ocean's Twelve")
my_graph.add_node(8, name = "Fight Club")
my_graph.add_node(9, name = "Dark Shadows")

my_graph.add_edge(1, 7)
my_graph.add_edge(3, 7)
my_graph.add_edge(4, 7)
my_graph.add_edge(1, 8)
my_graph.add_edge(6, 8)
my_graph.add_edge(5, 9)
my_graph.add_edge(6, 9)
my_graph.add_edge(2, 9)
NoraPs commented 2 years ago

Cattura