Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fize Jacques
GMatch4py
Commits
6130f6cd
Commit
6130f6cd
authored
Jul 18, 2018
by
Fize Jacques
Browse files
ADD reader.pyx
-- add function to load graph in a elegant way \o/
parent
5282767f
Changes
3
Hide whitespace changes
Inline
Side-by-side
gmatch4py/helpers/__init__.py
0 → 100644
View file @
6130f6cd
# coding = utf-8
\ No newline at end of file
gmatch4py/helpers/reader.pyx
0 → 100644
View file @
6130f6cd
# coding = utf-8
import
sys
,
os
,
glob
,
json
,
re
import
networkx
as
nx
methods_read_graph
=
{
"gexf"
:
nx
.
read_gexf
,
"gml"
:
nx
.
read_gml
,
"graphml"
:
nx
.
read_graphml
}
def
extract_number
(
fn
):
try
:
return
int
(
re
.
findall
(
"\d+"
,
fn
)[
-
1
])
except
:
print
(
"No number found !"
)
return
0
def
import_dir
(
directory
,
format
=
"gexf"
,
numbered
=
True
):
if
not
os
.
path
.
exists
(
directory
):
raise
FileNotFoundError
if
not
format
in
methods_read_graph
:
raise
NotImplementedError
(
"{0} is not implemented !"
.
format
(
format
))
fns
=
glob
.
glob
(
os
.
path
.
join
(
directory
,
"*.{0}"
.
format
(
format
)))
graphs
=
[]
if
numbered
:
n
=
max
([
extract_number
(
fn
)
for
fn
in
fns
])
graphs
=
[
nx
.
Graph
()]
*
(
n
+
1
)
association_map
,
i
=
{},
0
for
fn
in
fns
:
if
not
numbered
:
graphs
.
append
(
methods_read_graph
[
format
](
fn
))
association_map
[
fn
]
=
i
i
+=
1
else
:
graphs
[
extract_number
(
fn
)]
=
methods_read_graph
[
format
](
fn
)
if
not
numbered
:
return
association_map
,
graphs
return
graphs
setup.py
View file @
6130f6cd
...
...
@@ -47,15 +47,15 @@ extensions = cythonize([makeExtension(name) for name in extNames])
setup
(
name
=
"GMatch4py"
,
description
=
"A module for graph matching"
,
packages
=
[
"gmatch4py"
],
packages
=
[
"gmatch4py"
,
"gmatch4py.helpers"
],
ext_modules
=
extensions
,
cmdclass
=
{
'build_ext'
:
build_ext
},
setup_requires
=
[
"numpy"
,
"networkx"
],
install_requires
=
[
"numpy"
,
"networkx"
],
setup_requires
=
[
"numpy"
,
"networkx"
,
"networkit"
],
install_requires
=
[
"numpy"
,
"networkx"
,
"networkit"
],
version
=
"0.1"
)
#Clean cpp and compiled file
f
=
Fals
e
f
=
Tru
e
if
f
:
if
os
.
path
.
exists
(
"build"
):
shutil
.
rmtree
(
"build"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment