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
Hide 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
import
json
nodeIds
=
[]
destIds
=
[]
def
do
():
clusterlabels
=
[]
destclusterlabel
=
[]
cluster
=
[]
labalvlues
=
[]
def
classify
():
df_nodes
=
load_values
()
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'
])):
for
j
in
range
(
len
(
row
[
'TransactionFrom'
])):
print
(
" Input Ids: "
,
row
[
'TransactionFrom'
][
j
])
print
(
" Input Ids: "
,
row
[
'TransactionFrom'
][
j
])
nodeIds
.
append
(
row
[
'TransactionFrom'
])
nodeIds
.
append
(
row
[
'TransactionFrom'
])
print
(
"This is nodes: "
,
nodeIds
)
print
(
"This is nodes: "
,
nodeIds
)
for
row
in
df_nodes
:
for
row
in
df_nodes
:
destIds
.
append
(
row
[
'TransactionTo'
])
destIds
.
append
(
row
[
'TransactionTo'
])
for
row
in
range
(
len
(
nodeIds
)):
for
row
in
range
(
len
(
nodeIds
)):
print
(
nodeIds
[
row
])
print
(
nodeIds
[
row
])
print
(
"Finish InputIDs"
)
print
(
"Finish InputIDs"
)
i
=
0
i
=
0
for
row
in
range
(
len
(
nodeIds
)):
for
row
in
range
(
len
(
nodeIds
)):
clusterlabels
.
append
(
row
)
clusterlabels
.
append
(
row
)
i
+=
1
i
+=
1
print
(
i
)
print
(
i
)
return
{
'nodeIds'
:
nodeIds
,
'clusterlabels'
:
clusterlabels
,
'destIds'
:
destIds
}
def
classify_input
(
nodeIds
,
clusterlabels
):
"""" classifying Inputs"""
"""" classifying Inputs"""
"""" Labaling inputs"""
"""" Labaling inputs"""
for
row
in
range
(
len
(
nodeIds
)):
for
row
in
range
(
len
(
nodeIds
)):
...
@@ -55,42 +76,43 @@ def classify():
...
@@ -55,42 +76,43 @@ def classify():
clusterlabels
[
row2
]
=
clusterlabels
[
row1
]
clusterlabels
[
row2
]
=
clusterlabels
[
row1
]
clusterlabels
[
row
]
=
clusterlabels
[
row1
]
clusterlabels
[
row
]
=
clusterlabels
[
row1
]
print
(
clusterlabels
)
print
(
clusterlabels
)
print
(
"cluster labels:"
,
len
(
clusterlabels
))
print
(
"cluster labels:"
,
len
(
clusterlabels
))
print
(
"NodeIDs: "
,
len
(
nodeIds
))
print
(
"NodeIDs: "
,
len
(
nodeIds
))
return
clusterlabels
def
calc_cluster_num
(
clusterlabels
):
"""" Calculating the number of clusters"""
"""" Calculating the number of clusters"""
clusternum
=
1
labelvals
=
[]
labalvlues
.
append
(
clusterlabels
[
0
])
labelvals
.
append
(
clusterlabels
[
0
])
for
row
in
range
(
len
(
clusterlabels
)):
for
row
in
range
(
len
(
clusterlabels
)):
flag
=
True
flag
=
True
for
row1
in
range
(
len
(
lab
alvlue
s
)):
for
row1
in
range
(
len
(
lab
elval
s
)):
if
(
clusterlabels
[
row
]
==
lab
alvlue
s
[
row1
]):
if
(
clusterlabels
[
row
]
==
lab
elval
s
[
row1
]):
flag
=
False
flag
=
False
if
(
flag
):
if
(
flag
):
clusternum
=
+
1
labelvals
.
append
(
clusterlabels
[
row
])
labalvlues
.
append
(
clusterlabels
[
row
])
print
(
"label values (source Ids in the network): "
,
labalvlues
,
" and the number of clusters is: "
,
len
(
labalvlues
))
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"""
"""" 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
([])
cluster
.
append
([])
for
row3
in
range
(
len
(
nodeIds
)):
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
])
cluster
[
row
]
.
extend
(
nodeIds
[
row3
])
print
(
"clusters: "
,
cluster
)
print
(
"clusters: "
,
cluster
)
return
cluster
def
remove_duplicates
(
cluster
):
""" Removing duplicating items in cluster"""
""" Removing duplicating items in cluster"""
flag
=
True
flag
=
True
...
@@ -112,28 +134,26 @@ def classify():
...
@@ -112,28 +134,26 @@ def classify():
break
break
print
(
"cluster:"
,
cluster
)
print
(
"cluster:"
,
cluster
)
return
cluster
def
cluster_dest_ids
(
labelvals
,
cluster
,
destIds
):
"""" Clustering Destination Ids """
"""" Clustering Destination Ids """
destclusterlabel
=
[]
for
row
in
range
(
len
(
destIds
)):
for
row
in
range
(
len
(
destIds
)):
destclusterlabel
.
append
([])
destclusterlabel
.
append
([])
for
row2
in
range
(
len
(
destIds
[
row
])):
for
row2
in
range
(
len
(
destIds
[
row
])):
flag
=
True
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
])):
for
row1
in
range
(
len
(
cluster
[
rownum
])):
if
(
destIds
[
row
][
row2
]
==
cluster
[
rownum
][
row1
]):
if
(
destIds
[
row
][
row2
]
==
cluster
[
rownum
][
row1
]):
destclusterlabel
[
row
]
.
append
(
lab
alvlue
s
[
rownum
])
destclusterlabel
[
row
]
.
append
(
lab
elval
s
[
rownum
])
flag
=
False
flag
=
False
if
(
flag
):
if
(
flag
):
destclusterlabel
.
append
(
destIds
[
row
][
row2
])
destclusterlabel
.
append
(
destIds
[
row
][
row2
])
print
(
"destination labels (destination Ids): "
,
destclusterlabel
)
print
(
"destination labels (destination Ids): "
,
destclusterlabel
)
def
load_values
():
return
destclusterlabel
with
open
(
"mult_in_out_large.json"
,
"r"
)
as
json_file
:
\ No newline at end of file
df_nodes
=
json
.
load
(
json_file
)
return
df_nodes
\ 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