Improve NetworkX module import (#21)
* Improve NetworkX module import * Add Networkx dependencies to Dockerfiles
This commit is contained in:
parent
157590a294
commit
48587d6d5e
@ -1,11 +1,21 @@
|
|||||||
|
import sys
|
||||||
import mgp
|
import mgp
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from itertools import chain, repeat
|
from itertools import chain, repeat
|
||||||
from inspect import cleandoc
|
from inspect import cleandoc
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple
|
||||||
from mgp_networkx import MemgraphMultiDiGraph
|
try:
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
|
except ImportError as import_error:
|
||||||
|
sys.stderr.write((
|
||||||
|
'\n'
|
||||||
|
'NOTE: Please install networkx to be able to use graph_analyzer '
|
||||||
|
'module. Using Python:\n'
|
||||||
|
+ sys.version +
|
||||||
|
'\n'))
|
||||||
|
raise import_error
|
||||||
|
# Imported last because it also depends on networkx.
|
||||||
|
from mgp_networkx import MemgraphMultiDiGraph # noqa E402
|
||||||
|
|
||||||
|
|
||||||
_MAX_LIST_SIZE = 10
|
_MAX_LIST_SIZE = 10
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
import sys
|
||||||
import mgp
|
import mgp
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import networkx as nx
|
try:
|
||||||
|
import networkx as nx
|
||||||
|
except ImportError as import_error:
|
||||||
|
sys.stderr.write((
|
||||||
|
'\n'
|
||||||
|
'NOTE: Please install networkx to be able to use Memgraph NetworkX '
|
||||||
|
'wrappers. Using Python:\n'
|
||||||
|
+ sys.version +
|
||||||
|
'\n'))
|
||||||
|
raise import_error
|
||||||
|
|
||||||
|
|
||||||
class MemgraphAdjlistOuterDict(collections.abc.Mapping):
|
class MemgraphAdjlistOuterDict(collections.abc.Mapping):
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
|
import sys
|
||||||
import mgp
|
import mgp
|
||||||
from mgp_networkx import (MemgraphMultiDiGraph, MemgraphDiGraph,
|
try:
|
||||||
|
import networkx as nx
|
||||||
|
import numpy # noqa E401
|
||||||
|
import scipy # noqa E401
|
||||||
|
except ImportError as import_error:
|
||||||
|
sys.stderr.write((
|
||||||
|
'\n'
|
||||||
|
'NOTE: Please install networkx, numpy, scipy to be able to '
|
||||||
|
'use proxied NetworkX algorithms. E.g., CALL nxalg.pagerank(...).\n'
|
||||||
|
'Using Python:\n'
|
||||||
|
+ sys.version +
|
||||||
|
'\n'))
|
||||||
|
raise import_error
|
||||||
|
# Imported last because it also depends on networkx.
|
||||||
|
from mgp_networkx import (MemgraphMultiDiGraph, MemgraphDiGraph, # noqa: E402
|
||||||
MemgraphMultiGraph, MemgraphGraph,
|
MemgraphMultiGraph, MemgraphGraph,
|
||||||
PropertiesDictionary)
|
PropertiesDictionary)
|
||||||
import networkx as nx
|
|
||||||
|
|
||||||
|
|
||||||
# networkx.algorithms.approximation.connectivity.node_connectivity
|
# networkx.algorithms.approximation.connectivity.node_connectivity
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
|
import sys
|
||||||
import mgp
|
import mgp
|
||||||
|
try:
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
|
except ImportError as import_error:
|
||||||
|
sys.stderr.write(
|
||||||
|
'\n'
|
||||||
|
'NOTE: Please install networkx to be able to use wcc module.\n'
|
||||||
|
'Using Python:\n'
|
||||||
|
+ sys.version +
|
||||||
|
'\n')
|
||||||
|
raise import_error
|
||||||
|
|
||||||
|
|
||||||
@mgp.read_proc
|
@mgp.read_proc
|
||||||
@ -28,8 +37,10 @@ def get_components(vertices: mgp.List[mgp.Vertex],
|
|||||||
vertices labeled `Person` and edges between such vertices can be obtained
|
vertices labeled `Person` and edges between such vertices can be obtained
|
||||||
using the following openCypher query:
|
using the following openCypher query:
|
||||||
|
|
||||||
MATCH (n:Person)-[e]->(m:Person) WITH collect(n) AS nodes, collect(e) AS edges
|
MATCH (n:Person)-[e]->(m:Person)
|
||||||
CALL wcc.get_components(nodes, edges) YIELD * RETURN n_components, components;
|
WITH collect(n) AS nodes, collect(e) AS edges
|
||||||
|
CALL wcc.get_components(nodes, edges) YIELD *
|
||||||
|
RETURN n_components, components;
|
||||||
'''
|
'''
|
||||||
g = nx.DiGraph()
|
g = nx.DiGraph()
|
||||||
g.add_nodes_from(vertices)
|
g.add_nodes_from(vertices)
|
||||||
|
@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
--no-install-recommends \
|
--no-install-recommends \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
RUN pip3 install networkx
|
RUN pip3 install networkx==2.4 numpy==1.19.2 scipy==1.5.2
|
||||||
|
|
||||||
COPY ${deb_release} /
|
COPY ${deb_release} /
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
--no-install-recommends \
|
--no-install-recommends \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
RUN pip3 install networkx
|
RUN pip3 install networkx==2.4 numpy==1.19.2 scipy==1.5.2
|
||||||
|
|
||||||
COPY ${deb_release} /
|
COPY ${deb_release} /
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user