context-fabric 0.1.0__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.
- context_fabric-0.1.0/LICENSE +21 -0
- context_fabric-0.1.0/PKG-INFO +139 -0
- context_fabric-0.1.0/README.md +108 -0
- context_fabric-0.1.0/packages/cfabric/__init__.py +1 -0
- context_fabric-0.1.0/packages/cfabric/core/__init__.py +25 -0
- context_fabric-0.1.0/packages/cfabric/core/api.py +586 -0
- context_fabric-0.1.0/packages/cfabric/core/command.py +160 -0
- context_fabric-0.1.0/packages/cfabric/core/compile.py +798 -0
- context_fabric-0.1.0/packages/cfabric/core/computed.py +112 -0
- context_fabric-0.1.0/packages/cfabric/core/csr.py +152 -0
- context_fabric-0.1.0/packages/cfabric/core/data.py +626 -0
- context_fabric-0.1.0/packages/cfabric/core/edgefeature.py +480 -0
- context_fabric-0.1.0/packages/cfabric/core/fabric.py +1358 -0
- context_fabric-0.1.0/packages/cfabric/core/files.py +904 -0
- context_fabric-0.1.0/packages/cfabric/core/generic.py +148 -0
- context_fabric-0.1.0/packages/cfabric/core/helpers.py +717 -0
- context_fabric-0.1.0/packages/cfabric/core/locality.py +312 -0
- context_fabric-0.1.0/packages/cfabric/core/mmap.py +109 -0
- context_fabric-0.1.0/packages/cfabric/core/nodefeature.py +193 -0
- context_fabric-0.1.0/packages/cfabric/core/nodes.py +296 -0
- context_fabric-0.1.0/packages/cfabric/core/oslotsfeature.py +116 -0
- context_fabric-0.1.0/packages/cfabric/core/otypefeature.py +201 -0
- context_fabric-0.1.0/packages/cfabric/core/parameters.py +172 -0
- context_fabric-0.1.0/packages/cfabric/core/prepare.py +893 -0
- context_fabric-0.1.0/packages/cfabric/core/search/__init__.py +7 -0
- context_fabric-0.1.0/packages/cfabric/core/search/graph.py +245 -0
- context_fabric-0.1.0/packages/cfabric/core/search/relations.py +1813 -0
- context_fabric-0.1.0/packages/cfabric/core/search/search.py +542 -0
- context_fabric-0.1.0/packages/cfabric/core/search/searchexe.py +246 -0
- context_fabric-0.1.0/packages/cfabric/core/search/semantics.py +519 -0
- context_fabric-0.1.0/packages/cfabric/core/search/spin.py +433 -0
- context_fabric-0.1.0/packages/cfabric/core/search/stitch.py +882 -0
- context_fabric-0.1.0/packages/cfabric/core/search/syntax.py +678 -0
- context_fabric-0.1.0/packages/cfabric/core/strings.py +342 -0
- context_fabric-0.1.0/packages/cfabric/core/text.py +1291 -0
- context_fabric-0.1.0/packages/cfabric/core/timestamp.py +337 -0
- context_fabric-0.1.0/packages/context_fabric.egg-info/PKG-INFO +139 -0
- context_fabric-0.1.0/packages/context_fabric.egg-info/SOURCES.txt +41 -0
- context_fabric-0.1.0/packages/context_fabric.egg-info/dependency_links.txt +1 -0
- context_fabric-0.1.0/packages/context_fabric.egg-info/requires.txt +8 -0
- context_fabric-0.1.0/packages/context_fabric.egg-info/top_level.txt +1 -0
- context_fabric-0.1.0/pyproject.toml +70 -0
- context_fabric-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cody Kingham and Dirk Roorda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: context-fabric
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Graph-based corpus engine for annotated text with efficient traversal and search
|
|
5
|
+
Author: Cody Kingham, Dirk Roorda
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/codykingham/context-fabric
|
|
8
|
+
Project-URL: Repository, https://github.com/codykingham/context-fabric
|
|
9
|
+
Project-URL: Issues, https://github.com/codykingham/context-fabric/issues
|
|
10
|
+
Keywords: text,linguistics,annotation,corpus,graph
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.26
|
|
24
|
+
Requires-Dist: pyyaml>=5.3
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff; extra == "dev"
|
|
29
|
+
Requires-Dist: tox; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="assets/fabric_tan_mark_light.svg" alt="Context Fabric" width="120">
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<h1 align="center">Context-Fabric</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">A graph-based corpus engine for annotated text with efficient traversal and search.</p>
|
|
39
|
+
|
|
40
|
+
## Overview
|
|
41
|
+
|
|
42
|
+
Context-Fabric provides a powerful data model for working with annotated text corpora as graphs. It enables efficient navigation, feature lookup, and pattern-based search across large textual datasets.
|
|
43
|
+
|
|
44
|
+
Forked from Dirk Roorda's [Text-Fabric](https://github.com/annotation/text-fabric).
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install context-fabric
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from cfabric.core import Fabric
|
|
56
|
+
|
|
57
|
+
# Load a dataset
|
|
58
|
+
TF = Fabric(locations='path/to/data')
|
|
59
|
+
api = TF.load('feature1 feature2')
|
|
60
|
+
|
|
61
|
+
# Navigate nodes
|
|
62
|
+
for node in api.N():
|
|
63
|
+
print(api.F.feature1.v(node))
|
|
64
|
+
|
|
65
|
+
# Use locality
|
|
66
|
+
embedders = api.L.u(node)
|
|
67
|
+
embedded = api.L.d(node)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Core API
|
|
71
|
+
|
|
72
|
+
- **N** (Nodes) - Walk through nodes in canonical order
|
|
73
|
+
- **F** (Features) - Access node feature values
|
|
74
|
+
- **E** (Edges) - Access edge feature values
|
|
75
|
+
- **L** (Locality) - Navigate between related nodes
|
|
76
|
+
- **T** (Text) - Retrieve text representations
|
|
77
|
+
- **S** (Search) - Search using templates
|
|
78
|
+
|
|
79
|
+
## Performance
|
|
80
|
+
|
|
81
|
+
Context-Fabric uses memory-mapped numpy arrays for dramatically faster loading and reduced memory consumption compared to Text-Fabric's pickle-based caching.
|
|
82
|
+
|
|
83
|
+
### Benchmarks (BHSA Hebrew Bible corpus — 1.4M nodes, 109 features)
|
|
84
|
+
|
|
85
|
+
| Metric | Text-Fabric | Context-Fabric | Improvement |
|
|
86
|
+
|--------|-------------|----------------|-------------|
|
|
87
|
+
| **Load Time** | 7.0s | 2.4s | **2.9x faster** |
|
|
88
|
+
| **Memory Usage** | 6.1 GB | 1.6 GB | **74% reduction** |
|
|
89
|
+
| Compile Time | 7s | 91s | 13x slower |
|
|
90
|
+
| Cache Size | 138 MB | 859 MB | 6.2x larger |
|
|
91
|
+
|
|
92
|
+
<p align="center">
|
|
93
|
+
<img src="benchmarks/results/performance_comparison.png" alt="Performance Comparison" width="700">
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
The key insight: **compilation happens once, loading happens every session**. Context-Fabric optimizes for the common case with:
|
|
97
|
+
|
|
98
|
+
- **Memory-mapped arrays**: Data stays on disk, accessed on-demand
|
|
99
|
+
- **Efficient sparse iteration**: Uses numpy vectorized operations instead of Python loops
|
|
100
|
+
- **Cached materialization**: Dictionary views computed once per session
|
|
101
|
+
|
|
102
|
+
### Parallel Worker Scaling
|
|
103
|
+
|
|
104
|
+
Memory-mapped arrays enable efficient parallel processing. Multiple workers share the same mmap'd data instead of each loading a full copy into RAM.
|
|
105
|
+
|
|
106
|
+
**Spawn mode** (cold start — each worker loads independently):
|
|
107
|
+
|
|
108
|
+
| Metric | Text-Fabric | Context-Fabric | Savings |
|
|
109
|
+
|--------|-------------|----------------|---------|
|
|
110
|
+
| Total (4 workers) | 9.8 GB | 3.3 GB | **66% less** |
|
|
111
|
+
| Per worker | 2.5 GB | 821 MB | **3x less** |
|
|
112
|
+
|
|
113
|
+
**Fork mode** (API scenario — pre-load then fork workers):
|
|
114
|
+
|
|
115
|
+
| Metric | Text-Fabric | Context-Fabric | Savings |
|
|
116
|
+
|--------|-------------|----------------|---------|
|
|
117
|
+
| Total (4 workers) | 5.8 GB | 440 MB | **92% less** |
|
|
118
|
+
| Per worker | 1.5 GB | 110 MB | **13x less** |
|
|
119
|
+
|
|
120
|
+
*Measured with USS (Unique Set Size) which correctly excludes shared mmap pages.*
|
|
121
|
+
|
|
122
|
+
Run the benchmark yourself:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
python benchmarks/compare_performance.py --source path/to/tf/data --workers 4
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Testing
|
|
129
|
+
|
|
130
|
+
See [TESTING.md](TESTING.md) for how to run tests.
|
|
131
|
+
|
|
132
|
+
## Authors
|
|
133
|
+
|
|
134
|
+
- Cody Kingham
|
|
135
|
+
- Dirk Roorda
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/fabric_tan_mark_light.svg" alt="Context Fabric" width="120">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Context-Fabric</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">A graph-based corpus engine for annotated text with efficient traversal and search.</p>
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Context-Fabric provides a powerful data model for working with annotated text corpora as graphs. It enables efficient navigation, feature lookup, and pattern-based search across large textual datasets.
|
|
12
|
+
|
|
13
|
+
Forked from Dirk Roorda's [Text-Fabric](https://github.com/annotation/text-fabric).
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install context-fabric
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from cfabric.core import Fabric
|
|
25
|
+
|
|
26
|
+
# Load a dataset
|
|
27
|
+
TF = Fabric(locations='path/to/data')
|
|
28
|
+
api = TF.load('feature1 feature2')
|
|
29
|
+
|
|
30
|
+
# Navigate nodes
|
|
31
|
+
for node in api.N():
|
|
32
|
+
print(api.F.feature1.v(node))
|
|
33
|
+
|
|
34
|
+
# Use locality
|
|
35
|
+
embedders = api.L.u(node)
|
|
36
|
+
embedded = api.L.d(node)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Core API
|
|
40
|
+
|
|
41
|
+
- **N** (Nodes) - Walk through nodes in canonical order
|
|
42
|
+
- **F** (Features) - Access node feature values
|
|
43
|
+
- **E** (Edges) - Access edge feature values
|
|
44
|
+
- **L** (Locality) - Navigate between related nodes
|
|
45
|
+
- **T** (Text) - Retrieve text representations
|
|
46
|
+
- **S** (Search) - Search using templates
|
|
47
|
+
|
|
48
|
+
## Performance
|
|
49
|
+
|
|
50
|
+
Context-Fabric uses memory-mapped numpy arrays for dramatically faster loading and reduced memory consumption compared to Text-Fabric's pickle-based caching.
|
|
51
|
+
|
|
52
|
+
### Benchmarks (BHSA Hebrew Bible corpus — 1.4M nodes, 109 features)
|
|
53
|
+
|
|
54
|
+
| Metric | Text-Fabric | Context-Fabric | Improvement |
|
|
55
|
+
|--------|-------------|----------------|-------------|
|
|
56
|
+
| **Load Time** | 7.0s | 2.4s | **2.9x faster** |
|
|
57
|
+
| **Memory Usage** | 6.1 GB | 1.6 GB | **74% reduction** |
|
|
58
|
+
| Compile Time | 7s | 91s | 13x slower |
|
|
59
|
+
| Cache Size | 138 MB | 859 MB | 6.2x larger |
|
|
60
|
+
|
|
61
|
+
<p align="center">
|
|
62
|
+
<img src="benchmarks/results/performance_comparison.png" alt="Performance Comparison" width="700">
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
The key insight: **compilation happens once, loading happens every session**. Context-Fabric optimizes for the common case with:
|
|
66
|
+
|
|
67
|
+
- **Memory-mapped arrays**: Data stays on disk, accessed on-demand
|
|
68
|
+
- **Efficient sparse iteration**: Uses numpy vectorized operations instead of Python loops
|
|
69
|
+
- **Cached materialization**: Dictionary views computed once per session
|
|
70
|
+
|
|
71
|
+
### Parallel Worker Scaling
|
|
72
|
+
|
|
73
|
+
Memory-mapped arrays enable efficient parallel processing. Multiple workers share the same mmap'd data instead of each loading a full copy into RAM.
|
|
74
|
+
|
|
75
|
+
**Spawn mode** (cold start — each worker loads independently):
|
|
76
|
+
|
|
77
|
+
| Metric | Text-Fabric | Context-Fabric | Savings |
|
|
78
|
+
|--------|-------------|----------------|---------|
|
|
79
|
+
| Total (4 workers) | 9.8 GB | 3.3 GB | **66% less** |
|
|
80
|
+
| Per worker | 2.5 GB | 821 MB | **3x less** |
|
|
81
|
+
|
|
82
|
+
**Fork mode** (API scenario — pre-load then fork workers):
|
|
83
|
+
|
|
84
|
+
| Metric | Text-Fabric | Context-Fabric | Savings |
|
|
85
|
+
|--------|-------------|----------------|---------|
|
|
86
|
+
| Total (4 workers) | 5.8 GB | 440 MB | **92% less** |
|
|
87
|
+
| Per worker | 1.5 GB | 110 MB | **13x less** |
|
|
88
|
+
|
|
89
|
+
*Measured with USS (Unique Set Size) which correctly excludes shared mmap pages.*
|
|
90
|
+
|
|
91
|
+
Run the benchmark yourself:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
python benchmarks/compare_performance.py --source path/to/tf/data --workers 4
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Testing
|
|
98
|
+
|
|
99
|
+
See [TESTING.md](TESTING.md) for how to run tests.
|
|
100
|
+
|
|
101
|
+
## Authors
|
|
102
|
+
|
|
103
|
+
- Cody Kingham
|
|
104
|
+
- Dirk Roorda
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Context-Fabric package
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core API of Context-Fabric.
|
|
3
|
+
|
|
4
|
+
This API deals with the basic CF data model: a graph of nodes and edges,
|
|
5
|
+
annotated by features.
|
|
6
|
+
|
|
7
|
+
The core API consists of:
|
|
8
|
+
|
|
9
|
+
* `N`: see `nodes.Nodes` (walk through nodes)
|
|
10
|
+
* `F`: see `nodefeature.NodeFeature` (retrieve feature values for nodes)
|
|
11
|
+
* `E`: see `edgefeature.EdgeFeature` (retrieve feature values for edges)
|
|
12
|
+
* `L`: see `locality.Locality` (move between levels)
|
|
13
|
+
* `T`: see `text.Text` (get the text)
|
|
14
|
+
* `S`: see `search.search` (search by templates)
|
|
15
|
+
|
|
16
|
+
plus some additional methods.
|
|
17
|
+
|
|
18
|
+
Based on Text-Fabric by Dirk Roorda.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from cfabric.core.fabric import Fabric
|
|
22
|
+
from cfabric.core.parameters import VERSION, NAME, BANNER
|
|
23
|
+
|
|
24
|
+
__version__ = VERSION
|
|
25
|
+
__all__ = ["Fabric", "VERSION", "NAME", "BANNER"]
|