Onya 0.1.1__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.
onya-0.1.1/.gitignore ADDED
@@ -0,0 +1,44 @@
1
+ scratch
2
+ #PyCharm
3
+ .idea
4
+ .vscode
5
+ MANIFEST
6
+
7
+ #----
8
+
9
+ *.py[cod]
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Packages
15
+ *.egg
16
+ *.egg-info
17
+ dist
18
+ build
19
+ eggs
20
+ parts
21
+ bin
22
+ var
23
+ sdist
24
+ develop-eggs
25
+ .installed.cfg
26
+ lib
27
+ lib64
28
+ __pycache__
29
+
30
+ # Installer logs
31
+ pip-log.txt
32
+
33
+ # Unit test / coverage reports
34
+ .coverage
35
+ .tox
36
+ nosetests.xml
37
+
38
+ # Translations
39
+ *.mo
40
+
41
+ # Mr Developer
42
+ .mr.developer.cfg
43
+ .project
44
+ .pydevproject
@@ -0,0 +1,47 @@
1
+ Word Loom Specification License
2
+
3
+ The Word Loom specification document (wordloom_spec.md) is licensed under the
4
+ Creative Commons Attribution 4.0 International License (CC BY 4.0).
5
+
6
+ To view a copy of this license, visit:
7
+ https://creativecommons.org/licenses/by/4.0/
8
+
9
+ or send a letter to:
10
+ Creative Commons
11
+ PO Box 1866
12
+ Mountain View, CA 94042
13
+ USA
14
+
15
+ ---
16
+
17
+ You are free to:
18
+
19
+ * Share — copy and redistribute the specification in any medium or format
20
+ * Adapt — remix, transform, and build upon the specification for any purpose,
21
+ even commercially
22
+
23
+ Under the following terms:
24
+
25
+ * Attribution — You must give appropriate credit, provide a link to the
26
+ license, and indicate if changes were made. You may do so in any reasonable
27
+ manner, but not in any way that suggests the licensor endorses you or your
28
+ use.
29
+
30
+ * No additional restrictions — You may not apply legal terms or technological
31
+ measures that legally restrict others from doing anything the license
32
+ permits.
33
+
34
+ ---
35
+
36
+ This is a human-readable summary of (and not a substitute for) the full license.
37
+
38
+ The full legal text of the Creative Commons Attribution 4.0 International
39
+ License is available at:
40
+ https://creativecommons.org/licenses/by/4.0/legalcode
41
+
42
+ ---
43
+
44
+ Copyright (c) 2023-2025 Oori Data
45
+
46
+ Attribution example:
47
+ "Based on the Word Loom specification by Oori Data (https://github.com/OoriData/WordLoom)"
onya-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: Onya
3
+ Version: 0.1.1
4
+ Summary: Knowledge graph (property graph-style) model and serialization for web resources
5
+ Project-URL: Homepage, https://github.com/OoriData/Onya
6
+ Project-URL: Repository, https://github.com/OoriData/Onya
7
+ Project-URL: Issues, https://github.com/OoriData/Onya/issues
8
+ Author-email: Uche Ogbuji <uche@ogbuji.net>
9
+ License: Apache-2.0
10
+ License-File: LICENSE-spec
11
+ Keywords: data,graph,linked-data,rdf,web
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: amara>=4.0.1
24
+ Requires-Dist: markdown
25
+ Requires-Dist: pyparsing
26
+ Provides-Extra: demo
27
+ Requires-Dist: fire; extra == 'demo'
28
+ Provides-Extra: dev
29
+ Requires-Dist: build; extra == 'dev'
30
+ Requires-Dist: hatch; extra == 'dev'
31
+ Requires-Dist: pipdeptree; extra == 'dev'
32
+ Requires-Dist: pytest; extra == 'dev'
33
+ Requires-Dist: pytest-asyncio; extra == 'dev'
34
+ Requires-Dist: pytest-mock; extra == 'dev'
35
+ Requires-Dist: ruff; extra == 'dev'
36
+ Requires-Dist: twine; extra == 'dev'
37
+ Description-Content-Type: text/markdown
38
+
39
+ **Onya** is a knowledge graph expression and implementation. This repository combines a [data model and format spec](SPEC.md) with a Python parser and API implementation.
40
+
41
+ # Python quick start
42
+
43
+ ## Installation
44
+
45
+ <!--
46
+ ```bash
47
+ pip install amara
48
+ ```
49
+
50
+ Or with uv (recommended):
51
+
52
+ ```bash
53
+ uv pip install amara
54
+ ```
55
+ -->
56
+
57
+ Requires Python 3.12 or later. The package is still in early development, so install directly from source:
58
+
59
+ ```bash
60
+ git clone https://github.com/OoriData/Onya.git
61
+ cd Onya
62
+ pip install -U .
63
+ ```
64
+
65
+ <!--
66
+ pip install git+https://github.com/OoriData/Onya.git
67
+ -->
68
+
69
+ ## Basic Usage
70
+
71
+ Here's a simple example demonstrating the core Onya API. First, let's define a small friendship graph in Onya Literate format:
72
+
73
+ ```
74
+ # @docheader
75
+
76
+ * @document: http://example.org/friendship-graph
77
+ * @base: http://example.org/people/
78
+ * @schema: https://schema.org/
79
+ * @type-base: https://schema.org/
80
+
81
+ # Chuks [Person]
82
+
83
+ * name: Chukwuemeka Okafor
84
+ * nickname: Chuks
85
+ * age: 28
86
+
87
+ # Ify [Person]
88
+
89
+ * name: Ifeoma Adebayo
90
+ * nickname: Ify
91
+ * age: 27
92
+ ```
93
+
94
+ Now let's parse this graph and interact with it using the Python API:
95
+
96
+ ```python
97
+ from onya.graph import graph
98
+ from onya.serial import literate_lex
99
+
100
+ # Parse the Onya Literate text into a graph
101
+ onya_text = '''
102
+ # @docheader
103
+
104
+ * @document: http://example.org/friendship-graph
105
+ * @base: http://example.org/people/
106
+ * @schema: https://schema.org/
107
+ * @type-base: https://schema.org/
108
+
109
+ # Chuks [Person]
110
+
111
+ * name: Chukwuemeka Okafor
112
+ * nickname: Chuks
113
+ * age: 28
114
+
115
+ # Ify [Person]
116
+
117
+ * name: Ifeoma Adebayo
118
+ * nickname: Ify
119
+ * age: 27
120
+ '''
121
+
122
+ g = graph()
123
+ doc_iri = literate_lex.parse(onya_text, g)
124
+ print(f"Parsed document: {doc_iri}")
125
+ print(f"Graph has {len(g)} nodes")
126
+
127
+ # Access nodes and their properties
128
+ chuks = g['http://example.org/people/Chuks']
129
+ ify = g['http://example.org/people/Ify']
130
+
131
+ # Get a specific property value
132
+ for prop in chuks.getprop('https://schema.org/name'):
133
+ print(f"Name: {prop.value}")
134
+
135
+ # Add a friendship edge between Chuks and Ify
136
+ friendship = chuks.add_edge('https://schema.org/knows', ify)
137
+ print(f"Added edge: {friendship}")
138
+
139
+ # Add nested properties to the friendship (metadata about the relationship)
140
+ friendship.add_property('https://schema.org/startDate', '2018-03-15')
141
+ friendship.add_property('https://schema.org/description', 'Met at university')
142
+
143
+ # Add a new property to Ify
144
+ ify.add_property('https://schema.org/jobTitle', 'Software Engineer')
145
+
146
+ # Modify a property by removing the old one and adding a new one
147
+ age_props = list(chuks.getprop('https://schema.org/age'))
148
+ for prop in age_props:
149
+ chuks.remove_property(prop)
150
+ chuks.add_property('https://schema.org/age', '29')
151
+
152
+ # Traverse edges
153
+ for edge in chuks.traverse('https://schema.org/knows'):
154
+ friend = edge.target
155
+ for name_prop in friend.getprop('https://schema.org/name'):
156
+ print(f"Chuks knows: {name_prop.value}")
157
+ # Access nested properties on the edge
158
+ for date_prop in edge.getprop('https://schema.org/startDate'):
159
+ print(f" Friends since: {date_prop.value}")
160
+
161
+ # Find all nodes of a certain type
162
+ for person in g.typematch('https://schema.org/Person'):
163
+ for name_prop in person.getprop('https://schema.org/name'):
164
+ print(f"Person in graph: {name_prop.value}")
165
+ ```
166
+
167
+ This example demonstrates:
168
+ - Parsing Onya Literate format
169
+ - Accessing nodes and properties
170
+ - Adding edges with nested properties (reified relationships)
171
+ - Modifying properties
172
+ - Traversing the graph
173
+ - Querying by type
174
+
175
+ # Background
176
+
177
+ Onya is based on experience from developing [Versa](https://github.com/uogbuji/versa) and also working on [the MicroXML spec](https://dvcs.w3.org/hg/microxml/raw-file/tip/spec/microxml.html) and implementations thereof.
178
+
179
+ The URL used for metavocabulary is [managed via purl.org](https://purl.archive.org/purl/onya/vocab).
180
+
181
+ The name is from Igbo "ọ́nyà", web, snare, trap, and by extension, network. The expanded sense is ọ́nyà úchè, web of knowledge.
182
+
183
+ # Contributing
184
+
185
+ Contributions welcome! We're interested in feedback from the community about what works and what doesn't in real-world usage. To get help with the code implementation, read [CONTRIBUTING.md](CONTRIBUTING.md).
186
+
187
+ # License
188
+
189
+ - **Code** (Python library): Apache 2.0 - See [LICENSE](LICENSE)
190
+ - **Specification** (wordloom_spec.md): [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/) - See [LICENSE-spec](LICENSE-spec)
191
+
192
+ The specification is under CC BY 4.0 to encourage broad adoption and derivative work while ensuring attribution. We want the format itself to be as open and reusable as possible, allowing anyone to create implementations in any language or adapt the format for their specific needs.
193
+
194
+ # Acknowledgments
195
+
196
+ Created by [Oori Data](https://oori.dev). Word Loom emerged from our work building multilingual LLM applications and finding gaps in existing prompt management approaches.
197
+
198
+ # Related Work
199
+
200
+ - [networkx](https://github.com/networkx/networkx): Network Analysis in Python
201
+ - [Apache AGE](https://github.com/apache/incubator-age): PostgreSQL Extension that for graphs. ANSI SQL & openCypher over the same DB.
onya-0.1.1/README.md ADDED
@@ -0,0 +1,163 @@
1
+ **Onya** is a knowledge graph expression and implementation. This repository combines a [data model and format spec](SPEC.md) with a Python parser and API implementation.
2
+
3
+ # Python quick start
4
+
5
+ ## Installation
6
+
7
+ <!--
8
+ ```bash
9
+ pip install amara
10
+ ```
11
+
12
+ Or with uv (recommended):
13
+
14
+ ```bash
15
+ uv pip install amara
16
+ ```
17
+ -->
18
+
19
+ Requires Python 3.12 or later. The package is still in early development, so install directly from source:
20
+
21
+ ```bash
22
+ git clone https://github.com/OoriData/Onya.git
23
+ cd Onya
24
+ pip install -U .
25
+ ```
26
+
27
+ <!--
28
+ pip install git+https://github.com/OoriData/Onya.git
29
+ -->
30
+
31
+ ## Basic Usage
32
+
33
+ Here's a simple example demonstrating the core Onya API. First, let's define a small friendship graph in Onya Literate format:
34
+
35
+ ```
36
+ # @docheader
37
+
38
+ * @document: http://example.org/friendship-graph
39
+ * @base: http://example.org/people/
40
+ * @schema: https://schema.org/
41
+ * @type-base: https://schema.org/
42
+
43
+ # Chuks [Person]
44
+
45
+ * name: Chukwuemeka Okafor
46
+ * nickname: Chuks
47
+ * age: 28
48
+
49
+ # Ify [Person]
50
+
51
+ * name: Ifeoma Adebayo
52
+ * nickname: Ify
53
+ * age: 27
54
+ ```
55
+
56
+ Now let's parse this graph and interact with it using the Python API:
57
+
58
+ ```python
59
+ from onya.graph import graph
60
+ from onya.serial import literate_lex
61
+
62
+ # Parse the Onya Literate text into a graph
63
+ onya_text = '''
64
+ # @docheader
65
+
66
+ * @document: http://example.org/friendship-graph
67
+ * @base: http://example.org/people/
68
+ * @schema: https://schema.org/
69
+ * @type-base: https://schema.org/
70
+
71
+ # Chuks [Person]
72
+
73
+ * name: Chukwuemeka Okafor
74
+ * nickname: Chuks
75
+ * age: 28
76
+
77
+ # Ify [Person]
78
+
79
+ * name: Ifeoma Adebayo
80
+ * nickname: Ify
81
+ * age: 27
82
+ '''
83
+
84
+ g = graph()
85
+ doc_iri = literate_lex.parse(onya_text, g)
86
+ print(f"Parsed document: {doc_iri}")
87
+ print(f"Graph has {len(g)} nodes")
88
+
89
+ # Access nodes and their properties
90
+ chuks = g['http://example.org/people/Chuks']
91
+ ify = g['http://example.org/people/Ify']
92
+
93
+ # Get a specific property value
94
+ for prop in chuks.getprop('https://schema.org/name'):
95
+ print(f"Name: {prop.value}")
96
+
97
+ # Add a friendship edge between Chuks and Ify
98
+ friendship = chuks.add_edge('https://schema.org/knows', ify)
99
+ print(f"Added edge: {friendship}")
100
+
101
+ # Add nested properties to the friendship (metadata about the relationship)
102
+ friendship.add_property('https://schema.org/startDate', '2018-03-15')
103
+ friendship.add_property('https://schema.org/description', 'Met at university')
104
+
105
+ # Add a new property to Ify
106
+ ify.add_property('https://schema.org/jobTitle', 'Software Engineer')
107
+
108
+ # Modify a property by removing the old one and adding a new one
109
+ age_props = list(chuks.getprop('https://schema.org/age'))
110
+ for prop in age_props:
111
+ chuks.remove_property(prop)
112
+ chuks.add_property('https://schema.org/age', '29')
113
+
114
+ # Traverse edges
115
+ for edge in chuks.traverse('https://schema.org/knows'):
116
+ friend = edge.target
117
+ for name_prop in friend.getprop('https://schema.org/name'):
118
+ print(f"Chuks knows: {name_prop.value}")
119
+ # Access nested properties on the edge
120
+ for date_prop in edge.getprop('https://schema.org/startDate'):
121
+ print(f" Friends since: {date_prop.value}")
122
+
123
+ # Find all nodes of a certain type
124
+ for person in g.typematch('https://schema.org/Person'):
125
+ for name_prop in person.getprop('https://schema.org/name'):
126
+ print(f"Person in graph: {name_prop.value}")
127
+ ```
128
+
129
+ This example demonstrates:
130
+ - Parsing Onya Literate format
131
+ - Accessing nodes and properties
132
+ - Adding edges with nested properties (reified relationships)
133
+ - Modifying properties
134
+ - Traversing the graph
135
+ - Querying by type
136
+
137
+ # Background
138
+
139
+ Onya is based on experience from developing [Versa](https://github.com/uogbuji/versa) and also working on [the MicroXML spec](https://dvcs.w3.org/hg/microxml/raw-file/tip/spec/microxml.html) and implementations thereof.
140
+
141
+ The URL used for metavocabulary is [managed via purl.org](https://purl.archive.org/purl/onya/vocab).
142
+
143
+ The name is from Igbo "ọ́nyà", web, snare, trap, and by extension, network. The expanded sense is ọ́nyà úchè, web of knowledge.
144
+
145
+ # Contributing
146
+
147
+ Contributions welcome! We're interested in feedback from the community about what works and what doesn't in real-world usage. To get help with the code implementation, read [CONTRIBUTING.md](CONTRIBUTING.md).
148
+
149
+ # License
150
+
151
+ - **Code** (Python library): Apache 2.0 - See [LICENSE](LICENSE)
152
+ - **Specification** (wordloom_spec.md): [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/) - See [LICENSE-spec](LICENSE-spec)
153
+
154
+ The specification is under CC BY 4.0 to encourage broad adoption and derivative work while ensuring attribution. We want the format itself to be as open and reusable as possible, allowing anyone to create implementations in any language or adapt the format for their specific needs.
155
+
156
+ # Acknowledgments
157
+
158
+ Created by [Oori Data](https://oori.dev). Word Loom emerged from our work building multilingual LLM applications and finding gaps in existing prompt management approaches.
159
+
160
+ # Related Work
161
+
162
+ - [networkx](https://github.com/networkx/networkx): Network Analysis in Python
163
+ - [Apache AGE](https://github.com/apache/incubator-age): PostgreSQL Extension that for graphs. ANSI SQL & openCypher over the same DB.