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
ef2f767f
Commit
ef2f767f
authored
Sep 23, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracted methods
parent
1efb006e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
37 deletions
+57
-37
HyperGraph.py
...mantic-linking-microservice/app/initialdemo/HyperGraph.py
+57
-37
No files found.
data-hub/semantic-linking-microservice/app/initialdemo/HyperGraph.py
View file @
ef2f767f
import
json
nodeIds
=
[]
destIds
=
[]
clusterlabels
=
[]
destclusterlabel
=
[]
cluster
=
[]
labalvlues
=
[]
def
classify
():
def
do
():
df_nodes
=
load_values
()
for
row
in
df_nodes
:
ret_val
=
init
(
df_nodes
)
nodeIds
=
ret_val
[
'nodeIds'
]
clusterlabels
=
ret_val
[
'clusterlabels'
]
destIds
=
ret_val
[
'destIds'
]
clusterlabels
=
classify_input
(
nodeIds
,
clusterlabels
)
labelvals
=
calc_cluster_num
(
clusterlabels
)
cluster
=
cluster_with_labels
(
nodeIds
,
clusterlabels
,
labelvals
)
cluster
=
remove_duplicates
(
cluster
)
destclusterlabel
=
cluster_dest_ids
(
labelvals
,
cluster
,
destIds
)
def
load_values
():
with
open
(
"mult_in_out_large.json"
,
"r"
)
as
json_file
:
df_nodes
=
json
.
load
(
json_file
)
return
df_nodes
def
init
(
df_nodes
):
nodeIds
=
[]
clusterlabels
=
[]
destIds
=
[]
for
row
in
df_nodes
:
for
j
in
range
(
len
(
row
[
'TransactionFrom'
])):
print
(
" Input Ids: "
,
row
[
'TransactionFrom'
][
j
])
nodeIds
.
append
(
row
[
'TransactionFrom'
])
print
(
"This is nodes: "
,
nodeIds
)
for
row
in
df_nodes
:
destIds
.
append
(
row
[
'TransactionTo'
])
for
row
in
range
(
len
(
nodeIds
)):
print
(
nodeIds
[
row
])
print
(
"Finish InputIDs"
)
i
=
0
for
row
in
range
(
len
(
nodeIds
)):
clusterlabels
.
append
(
row
)
i
+=
1
print
(
i
)
return
{
'nodeIds'
:
nodeIds
,
'clusterlabels'
:
clusterlabels
,
'destIds'
:
destIds
}
def
classify_input
(
nodeIds
,
clusterlabels
):
"""" classifying Inputs"""
"""" Labaling inputs"""
for
row
in
range
(
len
(
nodeIds
)):
...
...
@@ -55,42 +76,43 @@ def classify():
clusterlabels
[
row2
]
=
clusterlabels
[
row1
]
clusterlabels
[
row
]
=
clusterlabels
[
row1
]
print
(
clusterlabels
)
print
(
"cluster labels:"
,
len
(
clusterlabels
))
print
(
"NodeIDs: "
,
len
(
nodeIds
))
return
clusterlabels
def
calc_cluster_num
(
clusterlabels
):
"""" Calculating the number of clusters"""
clusternum
=
1
labalvlues
.
append
(
clusterlabels
[
0
])
labelvals
=
[]
labelvals
.
append
(
clusterlabels
[
0
])
for
row
in
range
(
len
(
clusterlabels
)):
flag
=
True
for
row1
in
range
(
len
(
lab
alvlue
s
)):
if
(
clusterlabels
[
row
]
==
lab
alvlue
s
[
row1
]):
for
row1
in
range
(
len
(
lab
elval
s
)):
if
(
clusterlabels
[
row
]
==
lab
elval
s
[
row1
]):
flag
=
False
if
(
flag
):
clusternum
=
+
1
labalvlues
.
append
(
clusterlabels
[
row
])
print
(
"label values (source Ids in the network): "
,
labalvlues
,
" and the number of clusters is: "
,
len
(
labalvlues
))
labelvals
.
append
(
clusterlabels
[
row
])
print
(
"label values (source Ids in the network): "
,
labelvals
,
" and the number of clusters is: "
,
len
(
labelvals
))
return
labelvals
def
cluster_with_labels
(
nodeIds
,
clusterlabels
,
labelvals
):
"""" clustering Ids according to their labels"""
cluster
=
[]
for
row
in
range
(
len
(
lab
alvlue
s
)):
for
row
in
range
(
len
(
lab
elval
s
)):
cluster
.
append
([])
for
row3
in
range
(
len
(
nodeIds
)):
if
(
lab
alvlue
s
[
row
]
==
clusterlabels
[
row3
]):
if
(
lab
elval
s
[
row
]
==
clusterlabels
[
row3
]):
cluster
[
row
]
.
extend
(
nodeIds
[
row3
])
print
(
"clusters: "
,
cluster
)
return
cluster
def
remove_duplicates
(
cluster
):
""" Removing duplicating items in cluster"""
flag
=
True
...
...
@@ -113,27 +135,25 @@ def classify():
print
(
"cluster:"
,
cluster
)
return
cluster
def
cluster_dest_ids
(
labelvals
,
cluster
,
destIds
):
"""" Clustering Destination Ids """
destclusterlabel
=
[]
for
row
in
range
(
len
(
destIds
)):
destclusterlabel
.
append
([])
for
row2
in
range
(
len
(
destIds
[
row
])):
flag
=
True
for
rownum
in
range
(
len
(
lab
alvlue
s
)):
for
rownum
in
range
(
len
(
lab
elval
s
)):
for
row1
in
range
(
len
(
cluster
[
rownum
])):
if
(
destIds
[
row
][
row2
]
==
cluster
[
rownum
][
row1
]):
destclusterlabel
[
row
]
.
append
(
lab
alvlue
s
[
rownum
])
destclusterlabel
[
row
]
.
append
(
lab
elval
s
[
rownum
])
flag
=
False
if
(
flag
):
destclusterlabel
.
append
(
destIds
[
row
][
row2
])
print
(
"destination labels (destination Ids): "
,
destclusterlabel
)
def
load_values
():
with
open
(
"mult_in_out_large.json"
,
"r"
)
as
json_file
:
df_nodes
=
json
.
load
(
json_file
)
return
df_nodes
\ No newline at end of file
return
destclusterlabel
\ No newline at end of file
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