-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutilities.py
36 lines (33 loc) · 1.09 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from furl import furl
import numpy as np
# utility function to strip URLs of the schema, parameters, and www
def strip_url(url):
url = furl(url).remove(args=True, fragment=True).url
if "://www." in url:
url = url.split("://www.",1)[1]
elif "://" in url:
url = url.split("://",1)[1]
return url
# network conversion functions
def elements2cy(elements):
cy = []
for element in elements:
if "labels" in element:
element["label"] = element.pop("labels")[0]
if "id" in element:
element["id"] = str(element["id"])
if "source" in element:
element["source"] = str(element["source"])
if "target" in element:
element["target"] = str(element["target"])
if "properties" in element:
if "sub_id" in element["properties"]:
element["properties"]["sub_id"] = int(element["properties"]["sub_id"])
cy.append({
"data": element
})
return cy
# convert numpy types to python
def convert(o):
if isinstance(o, np.int64):
return int(o)