Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SemiSupervisedEmbeddingFramework
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamida Seba
SemiSupervisedEmbeddingFramework
Commits
3d178d4c
Commit
3d178d4c
authored
2 years ago
by
Ikenna Oluigbo
Browse files
Options
Downloads
Patches
Plain Diff
Reconstruct Graph from Input data
parent
a5666150
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
builder.py
+45
-0
45 additions, 0 deletions
builder.py
with
45 additions
and
0 deletions
builder.py
0 → 100644
+
45
−
0
View file @
3d178d4c
'''
Reads the graph and node contexts
'''
import
networkx
as
nx
def
build_graph
():
'''
Read input network
'''
G
=
nx
.
read_edgelist
(
'
input/cora.edgelist
'
,
nodetype
=
int
,
create_using
=
nx
.
Graph
())
for
e
in
G
.
edges
:
G
.
edges
[
e
][
'
weight
'
]
=
1
return
G
def
node_labels
():
'''
Read node classes
'''
G
=
build_graph
()
d
=
{}
with
open
(
'
input/coralabels.edgelist
'
,
'
r
'
)
as
lab
:
l
=
lab
.
readlines
()
if
len
(
l
[
0
].
split
(
'
'
))
==
2
:
x
=
[
int
(
w
.
split
(
'
'
)[
0
])
for
w
in
l
]
y
=
[
int
(
w
.
split
(
'
'
)[
-
1
].
rstrip
(
'
\n
'
))
for
w
in
l
]
for
j
in
range
(
len
(
x
)):
d
[
x
[
j
]]
=
y
[
j
]
#For label data with node
elif
len
(
l
[
0
].
split
(
'
'
))
==
1
:
for
i
,
k
in
enumerate
(
l
,
1
):
#start counting from 1
d
[
i
]
=
int
(
k
.
rstrip
(
'
\n
'
))
#For label data without node
else
:
print
(
'
Edges more than 2 nodes
'
)
labels_dict
=
{}
for
node
in
G
.
nodes
:
labels_dict
[
node
]
=
d
[
node
]
return
labels_dict
def
node_neighbor_labels
():
G
=
build_graph
()
labels_dict
=
node_labels
()
neighbor_labels
=
{}
for
node
in
G
.
nodes
:
nn
=
list
(
G
.
neighbors
(
node
))
nnlabel
=
[
labels_dict
[
n
]
for
n
in
nn
]
#Superimpose labels on node id
neighbor_labels
[
node
]
=
nnlabel
return
neighbor_labels
,
labels_dict
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment