Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
b19dc287
Commit
b19dc287
authored
Sep 23, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call hypergraph impl
parent
f18e7ea3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
20 deletions
+17
-20
SemanticLinking.py
...c-linking-microservice/app/initialdemo/SemanticLinking.py
+17
-20
No files found.
data-hub/semantic-linking-microservice/app/initialdemo/SemanticLinking.py
View file @
b19dc287
import
networkx
as
nx
import
matplotlib.pyplot
as
plt
from
collections
import
Counter
import
HyperGraph
as
hg
from
HyperGraph
import
HyperGraph
import
warnings
# pip install networkx
...
...
@@ -13,9 +13,18 @@ import warnings
class
SemanticLinking
:
def
__init__
(
self
):
hg
.
classify
()
hg
:
HyperGraph
=
None
df_nodes
=
[]
destf_nodes
=
[]
def
__init__
(
self
):
warnings
.
filterwarnings
(
'ignore'
)
self
.
hg
=
HyperGraph
()
self
.
hg
.
classify
()
self
.
df_nodes
=
self
.
hg
.
cluster_labels
self
.
destf_nodes
=
self
.
hg
.
dest_cluster_labels
def
_color_network
(
self
,
G
):
"""Colors the network so that neighboring nodes all have distinct colors.
...
...
@@ -30,7 +39,6 @@ class SemanticLinking:
coloring
[
color
]
=
set
([
node
])
return
coloring
def
_labeling_complete
(
self
,
labeling
,
G
):
"""Determines whether or not LPA is done.
...
...
@@ -42,7 +50,6 @@ class SemanticLinking:
return
all
(
labeling
[
v
]
in
self
.
_most_frequent_labels
(
v
,
labeling
,
G
)
for
v
in
G
if
len
(
G
[
v
])
>
0
)
def
_most_frequent_labels
(
self
,
node
,
labeling
,
G
):
"""Returns a set of all labels with maximum frequency in `labeling`.
...
...
@@ -58,7 +65,6 @@ class SemanticLinking:
max_freq
=
max
(
freqs
.
values
())
return
{
label
for
label
,
freq
in
freqs
.
items
()
if
freq
==
max_freq
}
def
_update_label
(
self
,
node
,
labeling
,
G
):
"""Updates the label of a node using the Prec-Max tie breaking algorithm
...
...
@@ -75,16 +81,8 @@ class SemanticLinking:
labeling
[
node
]
=
max
(
high_labels
)
warnings
.
filterwarnings
(
'ignore'
)
#G = nx.DiGraph(directed=True)
G
=
nx
.
MultiDiGraph
(
day
=
"Stackoverflow"
)
df_nodes
=
hg
.
clusterlabels
destf_nodes
=
hg
.
destclusterlabel
color_map
=
{
1
:
'#f09494'
,
2
:
'#eebcbc'
,
3
:
'#72bbd0'
,
4
:
'#91f0a1'
,
5
:
'#629fff'
,
6
:
'#bcc2f2'
,
7
:
'#eebcbc'
,
8
:
'#f1f0c0'
,
9
:
'#d2ffe7'
,
10
:
'#caf3a6'
,
11
:
'#ffdf55'
,
12
:
'#ef77aa'
,
13
:
'#d6dcff'
,
14
:
'#d2f5f0'
}
...
...
@@ -102,24 +100,23 @@ class SemanticLinking:
labeling
=
{}
def
drawedges
(
self
):
"""drawing edges in graph"""
labelvalues
=
self
.
hg
.
label_values
for
drow
in
range
(
len
(
self
.
df_nodes
)):
for
row
in
range
(
len
(
self
.
destf_nodes
[
drow
])):
self
.
G
.
add_edge
(
self
.
df_nodes
[
drow
],
self
.
destf_nodes
[
drow
][
row
])
for
row
in
range
(
len
(
hg
.
labalv
lues
)):
for
row1
in
range
(
len
(
hg
.
labalv
lues
)):
self
.
weight1
.
append
(
self
.
G
.
number_of_edges
(
hg
.
labalvlues
[
row
],
hg
.
labalv
lues
[
row1
]))
print
(
"The number of coccurance from node "
,
hg
.
labalvlues
[
row
],
"to node "
,
hg
.
labalv
lues
[
row1
],
": "
,
self
.
weight1
[
row1
])
for
row
in
range
(
len
(
labelva
lues
)):
for
row1
in
range
(
len
(
labelva
lues
)):
self
.
weight1
.
append
(
self
.
G
.
number_of_edges
(
labelvalues
[
row
],
labelva
lues
[
row1
]))
print
(
"The number of coccurance from node "
,
labelvalues
[
row
],
"to node "
,
labelva
lues
[
row1
],
": "
,
self
.
weight1
[
row1
])
self
.
G
.
__setattr__
(
'weight'
,
self
.
weight1
)
def
dolabeling
(
self
):
"""label_propagation_communities(G) """
coloring
=
self
.
_color_network
(
self
.
G
)
# Create a unique label for each node in the graph
labeling
=
{
v
:
k
for
k
,
v
in
enumerate
(
self
.
G
)}
...
...
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