def test_assert_graph_equals_when_same(self):
     g1 = nx.DiGraph()
     g1.add_nodes_from([1, 2, 3])
     g1.add_edge(1, 2)
     g1.add_edge(2, 3)
     g2 = nx.DiGraph()
     g2.add_nodes_from([1, 2, 3])
     g2.add_edge(2, 3)
     g2.add_edge(1, 2)
     utils.assert_graph_equals(g1, g2, weight_column_name=None)
 def test_extract_network_from_broadcast_average_sentiment_weight(self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.SENTIMENT,
         aggregation_type=bne.AggregationType.AVERAGE)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([122, 123])
     expected_graph.add_edge(122, 123, weight=0.24695)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_count_weight(self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.NONE,
         aggregation_type=bne.AggregationType.SUM)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([122, 123])
     expected_graph.add_edge(122, 123, weight=2.0)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_returns_empty_graph_when_empty_df(
     self):
     empty_data = pd.DataFrame({
         'event_content': [],
         'timestamp': [],
         'sender_subject_id': []})
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=empty_data)
     expected_graph = nx.DiGraph()
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_assert_graph_equals_when_not_same_nodes(self):
     g1 = nx.DiGraph()
     g1.add_nodes_from([1, 2, 3, 4])
     g1.add_edge(1, 2)
     g1.add_edge(2, 3)
     g2 = nx.DiGraph()
     g2.add_nodes_from([1, 2, 3])
     g2.add_edge(1, 2)
     g2.add_edge(2, 3)
     with self.assertRaises(AssertionError):
         utils.assert_graph_equals(g1, g2, weight_column_name=None)
 def test_extract_network_from_broadcast_average_emotion_dominance_weight(
     self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.EMOTION_DOMINANCE,
         aggregation_type=bne.AggregationType.AVERAGE)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([122, 123])
     expected_graph.add_edge(122, 123, weight=0.37444444444444447)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_unweighted_real_log(self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.real_log_data,
         time_window=[2, 10],
         weight_type=bne.WeightType.NONE,
         aggregation_type=bne.AggregationType.BINARY)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([30, 29, 32, 31])
     expected_graph.add_edge(30, 29, weight=1) # 30 answers to person 29
     expected_graph.add_edge(32, 29, weight=1) # 32 answers to person 29
     expected_graph.add_edge(31, 29, weight=1) # 31 answers to person 29
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_average_reply_duration_weight(
     self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.REPLY_DURATION,
         aggregation_type=bne.AggregationType.AVERAGE,
         gamma=0.15)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([122, 123])
     expected_graph.add_edge(122, 123, weight=0.5130034323233221)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_assert_graph_equals_when_different_edge_weights(self):
     g1 = nx.DiGraph()
     g1.add_nodes_from([1, 2, 3])
     g1.add_edge(1, 2, weight='5')
     g1.add_edge(2, 3, weight='-1')
     g1.add_edge(1, 3, weight='1')
     g2 = nx.DiGraph()
     g2.add_nodes_from([1, 2, 3])
     g2.add_edge(1, 2, weight='5')
     g2.add_edge(2, 3, weight='9')
     g2.add_edge(1, 3, weight='1')
     with self.assertRaises(AssertionError):
         utils.assert_graph_equals(g1, g2, weight_column_name='weight')
 def test_apply_function_on_all_edges(self):
     dg = nx.DiGraph()
     dg.add_nodes_from([122, 123, 127])
     dg.add_edge(122, 123, weight=[6.3, 9.2, 2.5])
     dg.add_edge(123, 127, weight=[2.9])
     extractor = bne.NetworkExtraction()
     computed_graph = extractor._apply_function_on_all_edges(
         dgraph=dg, aggregation_type=bne.AggregationType.AVERAGE)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([122, 123, 127])
     expected_graph.add_edge(122, 123, weight=6.0)
     expected_graph.add_edge(123, 127, weight=2.9)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_average_sentiment_weight_real_log(
     self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.real_log_data,
         time_window=[2, 10],
         weight_type=bne.WeightType.SENTIMENT,
         aggregation_type=bne.AggregationType.AVERAGE)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([30, 29, 32, 31])
     expected_graph.add_edge(30, 29, weight=0.4019)   # Sentiment of yes.
     expected_graph.add_edge(
         32, 29, weight=0.0)  # If English is not fixed, sentiment is 0!
     expected_graph.add_edge(31, 29, weight=0.296)    # Sentiment of yeah.
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_count_weight_backandforth_log(self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.back_and_forth_data,
         time_window=[2, 10],
         weight_type=bne.WeightType.NONE,
         aggregation_type=bne.AggregationType.SUM)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([1, 2, 3])
     expected_graph.add_edge(2, 1, weight=1)
     expected_graph.add_edge(3, 1, weight=2)
     expected_graph.add_edge(3, 2, weight=1)
     expected_graph.add_edge(1, 2, weight=1)
     expected_graph.add_edge(1, 3, weight=2)
     expected_graph.add_edge(2, 3, weight=2)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_count_same_as_sum_reply_duration_weight(self):
     # It tests whether network with no weight and sum is same as with the
     #   one computed via exponential sum with gamma coefficient equals 0.
     computed_graph1 = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.REPLY_DURATION,
         aggregation_type=bne.AggregationType.SUM,
         gamma=0)
     computed_graph2 = self.extractor.extract_network_from_broadcast(
         communication_data=self.data,
         time_window=[1, 20],
         weight_type=bne.WeightType.NONE,
         aggregation_type=bne.AggregationType.SUM)
     utils.assert_graph_equals(computed_graph1, computed_graph2)
 def test_extract_network_from_broadcast_sentiment_weight_backandforth_log(
     self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.back_and_forth_data,
         time_window=[2, 10],
         weight_type=bne.WeightType.SENTIMENT,
         aggregation_type=bne.AggregationType.AVERAGE)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([1, 2, 3])
     expected_graph.add_edge(2, 1, weight=0.4019)
     expected_graph.add_edge(3, 1, weight=0)
     expected_graph.add_edge(3, 2, weight=0)
     expected_graph.add_edge(1, 2, weight=0.296)
     expected_graph.add_edge(1, 3, weight=0.592/2)
     expected_graph.add_edge(2, 3, weight=0.7224/2)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_reply_duration_weight_backandforth_log(self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.back_and_forth_data,
         time_window=[2, 10],
         weight_type=bne.WeightType.REPLY_DURATION,
         aggregation_type=bne.AggregationType.AVERAGE,
         gamma=0.1)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([1, 2, 3])
     expected_graph.add_edge(2, 1, weight=np.exp(-0.1*3))
     expected_graph.add_edge(
         3, 1, weight=(np.exp(-0.1*4) + np.exp(-0.1*7))/2)
     expected_graph.add_edge(3, 2, weight=np.exp(-0.1*4))
     expected_graph.add_edge(1, 2, weight=np.exp(-0.1*8))
     expected_graph.add_edge(
         1, 3, weight=(np.exp(-0.1*7) + np.exp(-0.1*4))/2)
     expected_graph.add_edge(
         2, 3, weight=(np.exp(-0.1*8) + np.exp(-0.1*5))/2)
     utils.assert_graph_equals(computed_graph, expected_graph)
 def test_extract_network_from_broadcast_average_reply_dur_weight_real_log(
     self):
     computed_graph = self.extractor.extract_network_from_broadcast(
         communication_data=self.real_log_data,
         time_window=[1, 10],
         weight_type=bne.WeightType.REPLY_DURATION,
         aggregation_type=bne.AggregationType.AVERAGE,
         gamma=0.15)
     expected_graph = nx.DiGraph()
     expected_graph.add_nodes_from([30, 29, 32, 31])
     expected_graph.add_edge(
         30, 29, weight=np.exp(-0.15*3))  # 30 answers to 29.
     expected_graph.add_edge(
         32, 29, weight=np.exp(-0.15*3))  # 32 answers to 29
     expected_graph.add_edge(
         31, 29, weight=np.exp(-0.15*4))  # 31 answers to 29
     expected_graph.add_edge(31, 30, weight=np.exp(-0.15*1))
     expected_graph.add_edge(31, 32, weight=np.exp(-0.15*1))
     utils.assert_graph_equals(computed_graph, expected_graph)