linked 0.0.2__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- linked-0.0.4/PKG-INFO +40 -0
- linked-0.0.4/README.md +30 -0
- linked-0.0.4/linked/__init__.py +27 -0
- {linked-0.0.2 → linked-0.0.4}/linked/datasrc/__init__.py +2 -1
- linked-0.0.4/linked/datasrc/minidot.py +94 -0
- linked-0.0.4/linked/util.py +16 -0
- linked-0.0.4/linked.egg-info/PKG-INFO +40 -0
- {linked-0.0.2 → linked-0.0.4}/linked.egg-info/SOURCES.txt +1 -0
- {linked-0.0.2 → linked-0.0.4}/setup.cfg +1 -2
- linked-0.0.2/PKG-INFO +0 -17
- linked-0.0.2/README.md +0 -6
- linked-0.0.2/linked/__init__.py +0 -0
- linked-0.0.2/linked/datasrc/minidot.py +0 -65
- linked-0.0.2/linked.egg-info/PKG-INFO +0 -17
- {linked-0.0.2 → linked-0.0.4}/LICENSE +0 -0
- {linked-0.0.2 → linked-0.0.4}/linked.egg-info/dependency_links.txt +0 -0
- {linked-0.0.2 → linked-0.0.4}/linked.egg-info/not-zip-safe +0 -0
- {linked-0.0.2 → linked-0.0.4}/linked.egg-info/top_level.txt +0 -0
- {linked-0.0.2 → linked-0.0.4}/setup.py +0 -0
linked-0.0.4/PKG-INFO
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: linked
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Create and transform graphs
|
|
5
|
+
Home-page: https://github.com/i2mint/linked
|
|
6
|
+
License: apache-2.0
|
|
7
|
+
Platform: any
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
|
|
11
|
+
# linked
|
|
12
|
+
|
|
13
|
+
Create and transform graphs
|
|
14
|
+
|
|
15
|
+
To install: ```pip install linked```
|
|
16
|
+
|
|
17
|
+
# Examples
|
|
18
|
+
|
|
19
|
+
## mini_dot_to_graph_jdict
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
>>> from linked import mini_dot_to_graph_jdict
|
|
23
|
+
>>> mini_dot_to_graph_jdict('''
|
|
24
|
+
... 1 -> 2
|
|
25
|
+
... 2, 3 -> 5, 6, 7
|
|
26
|
+
... ''')
|
|
27
|
+
{'nodes': [{'id': '1'},
|
|
28
|
+
{'id': '2'},
|
|
29
|
+
{'id': '5'},
|
|
30
|
+
{'id': '6'},
|
|
31
|
+
{'id': '7'},
|
|
32
|
+
{'id': '3'}],
|
|
33
|
+
'links': [{'source': '1', 'target': '2'},
|
|
34
|
+
{'source': '2', 'target': '5'},
|
|
35
|
+
{'source': '2', 'target': '6'},
|
|
36
|
+
{'source': '2', 'target': '7'},
|
|
37
|
+
{'source': '3', 'target': '5'},
|
|
38
|
+
{'source': '3', 'target': '6'},
|
|
39
|
+
{'source': '3', 'target': '7'}]}
|
|
40
|
+
```
|
linked-0.0.4/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# linked
|
|
2
|
+
|
|
3
|
+
Create and transform graphs
|
|
4
|
+
|
|
5
|
+
To install: ```pip install linked```
|
|
6
|
+
|
|
7
|
+
# Examples
|
|
8
|
+
|
|
9
|
+
## mini_dot_to_graph_jdict
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from linked import mini_dot_to_graph_jdict
|
|
13
|
+
>>> mini_dot_to_graph_jdict('''
|
|
14
|
+
... 1 -> 2
|
|
15
|
+
... 2, 3 -> 5, 6, 7
|
|
16
|
+
... ''')
|
|
17
|
+
{'nodes': [{'id': '1'},
|
|
18
|
+
{'id': '2'},
|
|
19
|
+
{'id': '5'},
|
|
20
|
+
{'id': '6'},
|
|
21
|
+
{'id': '7'},
|
|
22
|
+
{'id': '3'}],
|
|
23
|
+
'links': [{'source': '1', 'target': '2'},
|
|
24
|
+
{'source': '2', 'target': '5'},
|
|
25
|
+
{'source': '2', 'target': '6'},
|
|
26
|
+
{'source': '2', 'target': '7'},
|
|
27
|
+
{'source': '3', 'target': '5'},
|
|
28
|
+
{'source': '3', 'target': '6'},
|
|
29
|
+
{'source': '3', 'target': '7'}]}
|
|
30
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Create and transform graph data.
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
|
|
6
|
+
>>> from linked import mini_dot_to_graph_jdict
|
|
7
|
+
>>> mini_dot_to_graph_jdict('''
|
|
8
|
+
... 1 -> 2
|
|
9
|
+
... 2, 3 -> 5, 6, 7
|
|
10
|
+
... ''') # doctest: +NORMALIZE_WHITESPACE
|
|
11
|
+
{'nodes': [{'id': '1'},
|
|
12
|
+
{'id': '2'},
|
|
13
|
+
{'id': '5'},
|
|
14
|
+
{'id': '6'},
|
|
15
|
+
{'id': '7'},
|
|
16
|
+
{'id': '3'}],
|
|
17
|
+
'links': [{'source': '1', 'target': '2'},
|
|
18
|
+
{'source': '2', 'target': '5'},
|
|
19
|
+
{'source': '2', 'target': '6'},
|
|
20
|
+
{'source': '2', 'target': '7'},
|
|
21
|
+
{'source': '3', 'target': '5'},
|
|
22
|
+
{'source': '3', 'target': '6'},
|
|
23
|
+
{'source': '3', 'target': '7'}]}
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from linked.datasrc import mini_dot_to_graph_jdict
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mini-dot: A very simple mini-language resembling graphviz dot
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from operator import methodcaller
|
|
6
|
+
from functools import partial
|
|
7
|
+
from itertools import product, chain
|
|
8
|
+
from typing import Iterable
|
|
9
|
+
import re
|
|
10
|
+
from types import SimpleNamespace
|
|
11
|
+
|
|
12
|
+
from dol import Pipe
|
|
13
|
+
|
|
14
|
+
DFLT_FIELD_NAMES = {
|
|
15
|
+
"id": "id",
|
|
16
|
+
"nodes": "nodes",
|
|
17
|
+
"links": "links",
|
|
18
|
+
"source": "source",
|
|
19
|
+
"target": "target",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
comment_marker = r"#"
|
|
23
|
+
to_and_from_nodes_sep = "->"
|
|
24
|
+
node_regular_expression = r"\w+"
|
|
25
|
+
|
|
26
|
+
iterize = lambda func: partial(map, func)
|
|
27
|
+
|
|
28
|
+
remove_comments = Pipe(
|
|
29
|
+
re.compile(f"[^{comment_marker}]*").match, methodcaller("group", 0)
|
|
30
|
+
)
|
|
31
|
+
split_to_and_from_nodes = methodcaller("split", to_and_from_nodes_sep)
|
|
32
|
+
extract_nodes = re.compile(node_regular_expression).findall
|
|
33
|
+
|
|
34
|
+
process_one_line = Pipe(
|
|
35
|
+
source_and_target_lists_str=split_to_and_from_nodes,
|
|
36
|
+
source_and_target_lists=Pipe(iterize(extract_nodes), list),
|
|
37
|
+
generate_all_combinations=lambda x: product(*x),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
get_source_target_pairs = Pipe(
|
|
41
|
+
lines=lambda x: str.splitlines(x),
|
|
42
|
+
remove_comments=iterize(remove_comments),
|
|
43
|
+
filter_out_empty_lines=partial(filter, None),
|
|
44
|
+
process_lines=iterize(process_one_line),
|
|
45
|
+
chain=chain.from_iterable,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def source_target_pairs_to_graph_jdict(
|
|
50
|
+
source_target_pairs: Iterable, *, field_names=DFLT_FIELD_NAMES
|
|
51
|
+
):
|
|
52
|
+
nodes = []
|
|
53
|
+
links = []
|
|
54
|
+
_nodes = set(nodes)
|
|
55
|
+
|
|
56
|
+
def add_node_if_not_already_there(node):
|
|
57
|
+
if node not in _nodes:
|
|
58
|
+
nodes.append(node)
|
|
59
|
+
_nodes.add(node)
|
|
60
|
+
|
|
61
|
+
field = SimpleNamespace(**dict(DFLT_FIELD_NAMES, **field_names))
|
|
62
|
+
|
|
63
|
+
for source, target in source_target_pairs:
|
|
64
|
+
add_node_if_not_already_there(source)
|
|
65
|
+
add_node_if_not_already_there(target)
|
|
66
|
+
links.append({field.source: source, field.target: target})
|
|
67
|
+
|
|
68
|
+
return {field.nodes: [{field.id: node} for node in nodes], field.links: links}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def mini_dot_to_graph_jdict(mini_dot: str, *, field_names=DFLT_FIELD_NAMES):
|
|
72
|
+
"""
|
|
73
|
+
Make a graph json dict from a mini-dot string.
|
|
74
|
+
|
|
75
|
+
>>> mini_dot_to_graph_jdict('''
|
|
76
|
+
... 1 -> 2
|
|
77
|
+
... 2, 3 -> 5, 6, 7
|
|
78
|
+
... ''') # doctest: +NORMALIZE_WHITESPACE
|
|
79
|
+
{'nodes': [{'id': '1'},
|
|
80
|
+
{'id': '2'},
|
|
81
|
+
{'id': '5'},
|
|
82
|
+
{'id': '6'},
|
|
83
|
+
{'id': '7'},
|
|
84
|
+
{'id': '3'}],
|
|
85
|
+
'links': [{'source': '1', 'target': '2'},
|
|
86
|
+
{'source': '2', 'target': '5'},
|
|
87
|
+
{'source': '2', 'target': '6'},
|
|
88
|
+
{'source': '2', 'target': '7'},
|
|
89
|
+
{'source': '3', 'target': '5'},
|
|
90
|
+
{'source': '3', 'target': '6'},
|
|
91
|
+
{'source': '3', 'target': '7'}]}
|
|
92
|
+
"""
|
|
93
|
+
pairs = get_source_target_pairs(mini_dot)
|
|
94
|
+
return source_target_pairs_to_graph_jdict(pairs, field_names=field_names)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Utils"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def ordered_unique(iterable):
|
|
5
|
+
seen = set()
|
|
6
|
+
seen_add = seen.add
|
|
7
|
+
return (x for x in iterable if not (x in seen or seen_add(x)))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _nodes_from_links(links):
|
|
11
|
+
def _yield_nodes_from_links():
|
|
12
|
+
for link in links:
|
|
13
|
+
yield link["source"]
|
|
14
|
+
yield link["target"]
|
|
15
|
+
|
|
16
|
+
return [{"id": x} for x in ordered_unique(_yield_nodes_from_links(links))]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: linked
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Create and transform graphs
|
|
5
|
+
Home-page: https://github.com/i2mint/linked
|
|
6
|
+
License: apache-2.0
|
|
7
|
+
Platform: any
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
|
|
11
|
+
# linked
|
|
12
|
+
|
|
13
|
+
Create and transform graphs
|
|
14
|
+
|
|
15
|
+
To install: ```pip install linked```
|
|
16
|
+
|
|
17
|
+
# Examples
|
|
18
|
+
|
|
19
|
+
## mini_dot_to_graph_jdict
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
>>> from linked import mini_dot_to_graph_jdict
|
|
23
|
+
>>> mini_dot_to_graph_jdict('''
|
|
24
|
+
... 1 -> 2
|
|
25
|
+
... 2, 3 -> 5, 6, 7
|
|
26
|
+
... ''')
|
|
27
|
+
{'nodes': [{'id': '1'},
|
|
28
|
+
{'id': '2'},
|
|
29
|
+
{'id': '5'},
|
|
30
|
+
{'id': '6'},
|
|
31
|
+
{'id': '7'},
|
|
32
|
+
{'id': '3'}],
|
|
33
|
+
'links': [{'source': '1', 'target': '2'},
|
|
34
|
+
{'source': '2', 'target': '5'},
|
|
35
|
+
{'source': '2', 'target': '6'},
|
|
36
|
+
{'source': '2', 'target': '7'},
|
|
37
|
+
{'source': '3', 'target': '5'},
|
|
38
|
+
{'source': '3', 'target': '6'},
|
|
39
|
+
{'source': '3', 'target': '7'}]}
|
|
40
|
+
```
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = linked
|
|
3
|
-
version = 0.0.
|
|
3
|
+
version = 0.0.4
|
|
4
4
|
url = https://github.com/i2mint/linked
|
|
5
5
|
platforms = any
|
|
6
6
|
description_file = README.md
|
|
7
7
|
root_url = https://github.com/i2mint/
|
|
8
8
|
license = apache-2.0
|
|
9
|
-
author = OtoSense
|
|
10
9
|
description = Create and transform graphs
|
|
11
10
|
long_description = file:README.md
|
|
12
11
|
long_description_content_type = text/markdown
|
linked-0.0.2/PKG-INFO
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: linked
|
|
3
|
-
Version: 0.0.2
|
|
4
|
-
Summary: Create and transform graphs
|
|
5
|
-
Home-page: https://github.com/i2mint/linked
|
|
6
|
-
Author: OtoSense
|
|
7
|
-
License: apache-2.0
|
|
8
|
-
Platform: any
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# linked
|
|
14
|
-
Create and transform graphs
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
To install: ```pip install linked```
|
linked-0.0.2/README.md
DELETED
linked-0.0.2/linked/__init__.py
DELETED
|
File without changes
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
mini-dot: A very simple mini-language resembling graphviz dot
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from operator import methodcaller
|
|
6
|
-
from functools import partial
|
|
7
|
-
from itertools import product, chain
|
|
8
|
-
from typing import Iterable
|
|
9
|
-
import re
|
|
10
|
-
|
|
11
|
-
from dol import Pipe
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
comment_marker = r'#'
|
|
15
|
-
to_and_from_nodes_sep = '->'
|
|
16
|
-
node_regular_expression = r'\w+'
|
|
17
|
-
|
|
18
|
-
iterize = lambda func: partial(map, func)
|
|
19
|
-
|
|
20
|
-
remove_comments = Pipe(
|
|
21
|
-
re.compile(f'[^{comment_marker}]*').match,
|
|
22
|
-
methodcaller('group', 0)
|
|
23
|
-
)
|
|
24
|
-
split_to_and_from_nodes = methodcaller('split', to_and_from_nodes_sep)
|
|
25
|
-
extract_nodes = re.compile(node_regular_expression).findall
|
|
26
|
-
|
|
27
|
-
process_one_line = Pipe(
|
|
28
|
-
source_and_target_lists_str=split_to_and_from_nodes,
|
|
29
|
-
source_and_target_lists=Pipe(iterize(extract_nodes), list),
|
|
30
|
-
generate_all_combinations=lambda x: product(*x),
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
get_source_target_pairs = Pipe(
|
|
34
|
-
lines=lambda x: str.splitlines(x),
|
|
35
|
-
remove_comments=iterize(remove_comments),
|
|
36
|
-
filter_out_empty_lines=partial(filter, None),
|
|
37
|
-
process_lines=iterize(process_one_line),
|
|
38
|
-
chain=chain.from_iterable
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def source_target_pairs_to_graph_jdict(source_target_pairs: Iterable):
|
|
43
|
-
nodes = []
|
|
44
|
-
links = []
|
|
45
|
-
_nodes = set(nodes)
|
|
46
|
-
|
|
47
|
-
def add_node_if_not_already_there(node):
|
|
48
|
-
if node not in _nodes:
|
|
49
|
-
nodes.append(node)
|
|
50
|
-
_nodes.add(node)
|
|
51
|
-
|
|
52
|
-
for source, target in source_target_pairs:
|
|
53
|
-
add_node_if_not_already_there(source)
|
|
54
|
-
add_node_if_not_already_there(target)
|
|
55
|
-
links.append({"source": source, "target": target})
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
"nodes": [{"id": node} for node in nodes],
|
|
59
|
-
"links": links
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def mini_dot_to_graph_jdict(mini_dot: str):
|
|
64
|
-
pairs = get_source_target_pairs(mini_dot)
|
|
65
|
-
return source_target_pairs_to_graph_jdict(pairs)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: linked
|
|
3
|
-
Version: 0.0.2
|
|
4
|
-
Summary: Create and transform graphs
|
|
5
|
-
Home-page: https://github.com/i2mint/linked
|
|
6
|
-
Author: OtoSense
|
|
7
|
-
License: apache-2.0
|
|
8
|
-
Platform: any
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# linked
|
|
14
|
-
Create and transform graphs
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
To install: ```pip install linked```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|