Skip to content
Snippets Groups Projects
Commit 89c62155 authored by Yassin's avatar Yassin
Browse files

Refactorings Code and Adding Node Filter

parent f16596a5
No related branches found
No related tags found
1 merge request!1Adding new methods and the consensual backbone
......@@ -12,7 +12,7 @@ def boolean_filter(backbone, narrate=True, value=[]):
data = nx.to_pandas_edgelist(data)
if narrate:
backbone.narrate()
return nx.from_pandas_edgelist(data[data[column] == True], edge_attr=edge_properties(data))
return nx.from_pandas_edgelist(data[data[column]], edge_attr=edge_properties(data))
print("The accepted filters for " + backbone.method_name + " are: " + ', '.join(
[fun.__name__ for fun in backbone.compatible_filters()]))
......@@ -21,19 +21,30 @@ def threshold_filter(backbone, value, narrate=True, secondary_property='weight',
**kwargs):
data = backbone.to_dataframe()
property_name = backbone.property_name
ascending = backbone.ascending
filter_by = [property_name]
ascending = [backbone.ascending]
if backbone.filter_on == 'Edges':
filter_by.append(secondary_property)
ascending.append(secondary_property_ascending)
if threshold_filter in backbone.compatible_filters():
data = data.sort_values(by=[property_name, secondary_property],
ascending=[ascending, secondary_property_ascending])
data = data.sort_values(by=filter_by,
ascending=ascending)
if narrate:
backbone.narrate()
if ascending:
return nx.from_pandas_edgelist(data[data[property_name] < value], edge_attr=edge_properties(data))
if backbone.ascending:
data = data[data[property_name] < value]
if backbone.filter_on == 'Edges':
return nx.from_pandas_edgelist(data, edge_attr=edge_properties(data))
return backbone.graph.subgraph(list(data.index)).copy()
else:
return nx.from_pandas_edgelist(data[data[property_name] > value], edge_attr=edge_properties(data))
data = data[data[property_name] > value]
if backbone.filter_on == 'Edges':
return nx.from_pandas_edgelist(data, edge_attr=edge_properties(data))
return backbone.graph.subgraph(list(data.index)).copy()
print("The accepted filters for " + backbone.method_name + " are: " + ', '.join(
[fun.__name__ for fun in backbone.compatible_filters()]))
......@@ -45,7 +56,6 @@ def fraction_filter(backbone, value, narrate=True, secondary_property='weight',
filter_by = [backbone.property_name]
ascending = [backbone.ascending]
if backbone.filter_on == 'Edges':
filter_by.append(secondary_property)
ascending.append(secondary_property_ascending)
......@@ -60,9 +70,8 @@ def fraction_filter(backbone, value, narrate=True, secondary_property='weight',
value = math.ceil(value * len(data))
return nx.from_pandas_edgelist(data[:value], edge_attr=edge_properties(data))
else:
b = backbone.graph.copy()
value = math.ceil(value * len(backbone.graph))
return b.subgraph(list(data[:value].index))
return backbone.graph.subgraph(list(data[:value].index)).copy()
print("The accepted filters for " + backbone.method_name + " are: " + ', '.join(
[fun.__name__ for fun in backbone.compatible_filters()]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment