@bradtech/ontologies 1.1.0
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.
- package/LICENSE +620 -0
- package/README.md +66 -0
- package/data/crop-covers/bare-soil.md +23 -0
- package/data/crop-covers/index.md +21 -0
- package/data/crop-covers/permanent-sod.md +23 -0
- package/data/crop-covers/sown-legume.md +23 -0
- package/data/crop-covers/spontaneous-grass.md +23 -0
- package/data/crops/index.md +23 -0
- package/data/crops/lavandula-angustifolia.md +30 -0
- package/data/crops/malus-domestica.md +30 -0
- package/data/crops/prunus-persica.md +30 -0
- package/data/crops/triticum-aestivum.md +30 -0
- package/data/crops/vitis-vinifera.md +30 -0
- package/data/crops/zea-mays.md +30 -0
- package/data/index.md +22 -0
- package/data/irrigations/drip.md +24 -0
- package/data/irrigations/gravity.md +24 -0
- package/data/irrigations/index.md +21 -0
- package/data/irrigations/none.md +24 -0
- package/data/irrigations/sprinkler.md +24 -0
- package/data/soils/clay-loam.md +29 -0
- package/data/soils/clay.md +29 -0
- package/data/soils/index.md +26 -0
- package/data/soils/loam.md +29 -0
- package/data/soils/sand.md +29 -0
- package/data/soils/sandy-clay-loam.md +29 -0
- package/data/soils/sandy-clay.md +29 -0
- package/data/soils/sandy-loam.md +29 -0
- package/data/soils/silt-loam.md +29 -0
- package/data/soils/silt.md +29 -0
- package/data/soils/silty-clay-loam.md +29 -0
- package/dist/build.d.ts +5 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +61 -0
- package/dist/build.js.map +1 -0
- package/dist/catalog.json +1623 -0
- package/dist/embeddedData.d.ts +6 -0
- package/dist/embeddedData.d.ts.map +1 -0
- package/dist/embeddedData.js +906 -0
- package/dist/embeddedData.js.map +1 -0
- package/dist/extractor.d.ts +31 -0
- package/dist/extractor.d.ts.map +1 -0
- package/dist/extractor.js +161 -0
- package/dist/extractor.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +25 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +104 -0
- package/dist/loader.js.map +1 -0
- package/dist/opendata.jsonld +268 -0
- package/dist/parser.d.ts +14 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +124 -0
- package/dist/parser.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
- package/src/build.ts +71 -0
- package/src/embeddedData.ts +910 -0
- package/src/extractor.ts +207 -0
- package/src/index.ts +98 -0
- package/src/loader.ts +126 -0
- package/src/parser.ts +137 -0
- package/src/types.ts +110 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": {
|
|
3
|
+
"@vocab": "https://schema.org/",
|
|
4
|
+
"okf": "https://openknowledgeformat.org/ns/",
|
|
5
|
+
"eppo": "https://gd.eppo.int/taxon/",
|
|
6
|
+
"agrovoc": "http://aims.fao.org/aos/agrovoc/",
|
|
7
|
+
"wrb": "https://www.isric.org/explore/wrb/"
|
|
8
|
+
},
|
|
9
|
+
"@type": "DataCatalog",
|
|
10
|
+
"name": "OSFARM & Brad Agricultural Taxonomies",
|
|
11
|
+
"url": "https://lexicon.osfarm.org",
|
|
12
|
+
"publisher": {
|
|
13
|
+
"@type": "Organization",
|
|
14
|
+
"name": "Brad Technology SAS & OSFARM Collective"
|
|
15
|
+
},
|
|
16
|
+
"itemListElement": [
|
|
17
|
+
{
|
|
18
|
+
"@type": "Plant",
|
|
19
|
+
"@id": "okf:crop/triticum-aestivum",
|
|
20
|
+
"identifier": "triticum-aestivum",
|
|
21
|
+
"name": "Blé tendre (Triticum aestivum)",
|
|
22
|
+
"description": "Céréale à paille annuelle de la famille des Poacées, base de la meunerie et de la panification.",
|
|
23
|
+
"keywords": "crop, cereals, annual, field-crop",
|
|
24
|
+
"sameAs": [
|
|
25
|
+
"https://gd.eppo.int/taxon/TRZAX",
|
|
26
|
+
"http://aims.fao.org/aos/agrovoc/c_7951"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"@type": "Plant",
|
|
31
|
+
"@id": "okf:crop/zea-mays",
|
|
32
|
+
"identifier": "zea-mays",
|
|
33
|
+
"name": "Maïs grain et fourrage (Zea mays)",
|
|
34
|
+
"description": "Plante herbacée annuelle en C4 de la famille des Poacées, à forte productivité de biomasse et forts besoins hydriques estivaux.",
|
|
35
|
+
"keywords": "crop, cereals, annual, c4, summer-crop",
|
|
36
|
+
"sameAs": [
|
|
37
|
+
"https://gd.eppo.int/taxon/ZEAMX",
|
|
38
|
+
"http://aims.fao.org/aos/agrovoc/c_8504"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"@type": "Plant",
|
|
43
|
+
"@id": "okf:crop/malus-domestica",
|
|
44
|
+
"identifier": "malus-domestica",
|
|
45
|
+
"name": "Pommier cultivé (Malus domestica)",
|
|
46
|
+
"description": "Arbre fruitier de la famille des Rosacées cultivé pour la production de pommes de table et de transformation.",
|
|
47
|
+
"keywords": "crop, arboriculture, fruit, orchard, deciduous",
|
|
48
|
+
"sameAs": [
|
|
49
|
+
"https://gd.eppo.int/taxon/MABDO",
|
|
50
|
+
"http://aims.fao.org/aos/agrovoc/c_594"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"@type": "Plant",
|
|
55
|
+
"@id": "okf:crop/prunus-persica",
|
|
56
|
+
"identifier": "prunus-persica",
|
|
57
|
+
"name": "Pêcher / Nectarinier (Prunus persica)",
|
|
58
|
+
"description": "Arbre fruitier cultivé pour ses pêches, nectarines et brugnons, sensible aux gelées printanières précoces.",
|
|
59
|
+
"keywords": "crop, arboriculture, fruit, orchard, frost-sensitive",
|
|
60
|
+
"sameAs": [
|
|
61
|
+
"https://gd.eppo.int/taxon/PRNPS",
|
|
62
|
+
"http://aims.fao.org/aos/agrovoc/c_6267"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"@type": "Plant",
|
|
67
|
+
"@id": "okf:crop/vitis-vinifera",
|
|
68
|
+
"identifier": "vitis-vinifera",
|
|
69
|
+
"name": "Vigne cultivée (Vitis vinifera)",
|
|
70
|
+
"description": "Liane ligneuse pérenne cultivée pour le raisin de cuve et le raisin de table.",
|
|
71
|
+
"keywords": "crop, viticulture, perennial, fruit, wine",
|
|
72
|
+
"sameAs": [
|
|
73
|
+
"https://gd.eppo.int/taxon/VITVI",
|
|
74
|
+
"http://aims.fao.org/aos/agrovoc/c_8340"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"@type": "Plant",
|
|
79
|
+
"@id": "okf:crop/lavandula-angustifolia",
|
|
80
|
+
"identifier": "lavandula-angustifolia",
|
|
81
|
+
"name": "Lavande vraie / Lavandin (Lavandula)",
|
|
82
|
+
"description": "Arbrisseau dicotylédone pérenne de la famille des Lamiacées cultivé pour son huile essentielle et ses fleurs.",
|
|
83
|
+
"keywords": "crop, aromatics, medicinal, perennial, drought-resistant",
|
|
84
|
+
"sameAs": [
|
|
85
|
+
"https://gd.eppo.int/taxon/LAVAN",
|
|
86
|
+
"http://aims.fao.org/aos/agrovoc/c_4219"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"@type": "DefinedTerm",
|
|
91
|
+
"@id": "okf:irrigation/gravity",
|
|
92
|
+
"identifier": "gravity",
|
|
93
|
+
"name": "Gravitaire (Submersion / Planches / Raies)",
|
|
94
|
+
"description": "Irrigation par écoulement de surface guidé par la gravité le long de calants, planches ou sillons.",
|
|
95
|
+
"keywords": "irrigation, surface, gravity, traditional",
|
|
96
|
+
"sameAs": [
|
|
97
|
+
"http://aims.fao.org/aos/agrovoc/c_7531"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"@type": "DefinedTerm",
|
|
102
|
+
"@id": "okf:irrigation/drip",
|
|
103
|
+
"identifier": "drip",
|
|
104
|
+
"name": "Goutte à goutte (Micro-irrigation)",
|
|
105
|
+
"description": "Système de micro-irrigation localisé en surface ou enterré délivrant l'eau directement au pied des cultures avec une haute efficience.",
|
|
106
|
+
"keywords": "irrigation, microirrigation, drip, precision",
|
|
107
|
+
"sameAs": [
|
|
108
|
+
"http://aims.fao.org/aos/agrovoc/c_2374"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"@type": "DefinedTerm",
|
|
113
|
+
"@id": "okf:irrigation/sprinkler",
|
|
114
|
+
"identifier": "sprinkler",
|
|
115
|
+
"name": "Aspersion (Pivots / Enrouleurs / Couverture)",
|
|
116
|
+
"description": "Distribution de l'eau sous forme de pluie artificielle sous pression par asperseurs, canons ou rampes mobiles.",
|
|
117
|
+
"keywords": "irrigation, sprinkler, overhead",
|
|
118
|
+
"sameAs": [
|
|
119
|
+
"http://aims.fao.org/aos/agrovoc/c_7342"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"@type": "DefinedTerm",
|
|
124
|
+
"@id": "okf:irrigation/none",
|
|
125
|
+
"identifier": "none",
|
|
126
|
+
"name": "Sans irrigation (Non irrigué / Pluvial)",
|
|
127
|
+
"description": "Parcelle conduite en sec, sans équipement d'apport artificiel d'eau. Les augmentations d'humidité du sol correspondent exclusivement à des pluies ou condensations naturelles.",
|
|
128
|
+
"keywords": "irrigation, rainfed, dryland",
|
|
129
|
+
"sameAs": [
|
|
130
|
+
"http://aims.fao.org/aos/agrovoc/c_2393"
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"@type": "DefinedTerm",
|
|
135
|
+
"@id": "okf:soil/silty-clay-loam",
|
|
136
|
+
"identifier": "silty-clay-loam",
|
|
137
|
+
"name": "Sol Limono-Argileux",
|
|
138
|
+
"description": "Sol composé de 27-40% d'argile et > 40% de limons, très riche chimiquement, sensible à la battance.",
|
|
139
|
+
"keywords": "soil, texture, inrae, usda",
|
|
140
|
+
"sameAs": []
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"@type": "DefinedTerm",
|
|
144
|
+
"@id": "okf:soil/clay",
|
|
145
|
+
"identifier": "clay",
|
|
146
|
+
"name": "Sol Argileux",
|
|
147
|
+
"description": "Sol à forte teneur en argile (> 40%), forte capacité de rétention en eau et plasticité élevée.",
|
|
148
|
+
"keywords": "soil, texture, inrae, usda, heavy",
|
|
149
|
+
"sameAs": []
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"@type": "DefinedTerm",
|
|
153
|
+
"@id": "okf:soil/clay-loam",
|
|
154
|
+
"identifier": "clay-loam",
|
|
155
|
+
"name": "Sol Argilo-Limoneux",
|
|
156
|
+
"description": "Sol équilibré à dominante argileuse et limoneuse (27-40% argile, 20-45% sable), excellente rétention en eau.",
|
|
157
|
+
"keywords": "soil, texture, inrae, usda, balanced",
|
|
158
|
+
"sameAs": []
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"@type": "DefinedTerm",
|
|
162
|
+
"@id": "okf:soil/sandy-clay",
|
|
163
|
+
"identifier": "sandy-clay",
|
|
164
|
+
"name": "Sol Sablo-Argileux",
|
|
165
|
+
"description": "Sol contenant 35-55% d'argile et 45-65% de sable, combinant plasticité et drainage granulaire.",
|
|
166
|
+
"keywords": "soil, texture, inrae, usda",
|
|
167
|
+
"sameAs": []
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"@type": "DefinedTerm",
|
|
171
|
+
"@id": "okf:soil/silt",
|
|
172
|
+
"identifier": "silt",
|
|
173
|
+
"name": "Sol Limoneux Pur",
|
|
174
|
+
"description": "Sol composé de plus de 80% de limon et moins de 12% d'argile, très soyeux, très sensible à la battance et au compactage superficiel.",
|
|
175
|
+
"keywords": "soil, texture, inrae, usda",
|
|
176
|
+
"sameAs": []
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"@type": "DefinedTerm",
|
|
180
|
+
"@id": "okf:soil/sand",
|
|
181
|
+
"identifier": "sand",
|
|
182
|
+
"name": "Sol Sableux",
|
|
183
|
+
"description": "Sol très filtrant composé de plus de 85% de particules de sable, très faible réserve utile, réchauffement quasi immédiat.",
|
|
184
|
+
"keywords": "soil, texture, inrae, usda, draining",
|
|
185
|
+
"sameAs": []
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"@type": "DefinedTerm",
|
|
189
|
+
"@id": "okf:soil/silt-loam",
|
|
190
|
+
"identifier": "silt-loam",
|
|
191
|
+
"name": "Sol Limono-Sableux / Limon Fin",
|
|
192
|
+
"description": "Sol composé de plus de 50% de limons, doux au toucher, très filtrant et sensible à l'érosion éolienne et hydrique.",
|
|
193
|
+
"keywords": "soil, texture, inrae, usda, light",
|
|
194
|
+
"sameAs": []
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"@type": "DefinedTerm",
|
|
198
|
+
"@id": "okf:soil/sandy-clay-loam",
|
|
199
|
+
"identifier": "sandy-clay-loam",
|
|
200
|
+
"name": "Sol Sablo-Argilo-Limoneux",
|
|
201
|
+
"description": "Sol contenant 20-35% d'argile, 45-80% de sable et moins de 28% de limon, sol d'arboriculture et de vigne très répandu.",
|
|
202
|
+
"keywords": "soil, texture, inrae, usda",
|
|
203
|
+
"sameAs": []
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"@type": "DefinedTerm",
|
|
207
|
+
"@id": "okf:soil/loam",
|
|
208
|
+
"identifier": "loam",
|
|
209
|
+
"name": "Sol Limoneux / Franc",
|
|
210
|
+
"description": "Sol franc idéal réunissant sable (40%), limon (40%) et argile (20%), aéré, drainant et retenant l'eau.",
|
|
211
|
+
"keywords": "soil, texture, inrae, usda, fertile",
|
|
212
|
+
"sameAs": []
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"@type": "DefinedTerm",
|
|
216
|
+
"@id": "okf:soil/sandy-loam",
|
|
217
|
+
"identifier": "sandy-loam",
|
|
218
|
+
"name": "Sol Sablo-Limoneux",
|
|
219
|
+
"description": "Sol contenant plus de 50% de sable et moins de 20% d'argile, réchauffement très rapide, réserve utile modérée.",
|
|
220
|
+
"keywords": "soil, texture, inrae, usda, warm",
|
|
221
|
+
"sameAs": []
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"@type": "DefinedTerm",
|
|
225
|
+
"@id": "okf:crop-cover/bare-soil",
|
|
226
|
+
"identifier": "bare-soil",
|
|
227
|
+
"name": "Sol Nu / Désherbage Mécanique",
|
|
228
|
+
"description": "Sol maintenu sans végétation adventice par travail superficiel ou binage. Zéro compétition hydrique, mais forte exposition à l'érosion et au ruissellement.",
|
|
229
|
+
"keywords": "crop-cover, tilled, bare-soil",
|
|
230
|
+
"sameAs": [
|
|
231
|
+
"http://aims.fao.org/aos/agrovoc/c_34125"
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"@type": "DefinedTerm",
|
|
236
|
+
"@id": "okf:crop-cover/permanent-sod",
|
|
237
|
+
"identifier": "permanent-sod",
|
|
238
|
+
"name": "Enherbement Permanent Maîtrisé",
|
|
239
|
+
"description": "Gazon ou graminées pérennes installées durablement sur l'inter-rang, tondues régulièrement pour limiter la concurrence hydrique.",
|
|
240
|
+
"keywords": "crop-cover, permanent, sod, grass",
|
|
241
|
+
"sameAs": [
|
|
242
|
+
"http://aims.fao.org/aos/agrovoc/c_3313"
|
|
243
|
+
]
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"@type": "DefinedTerm",
|
|
247
|
+
"@id": "okf:crop-cover/sown-legume",
|
|
248
|
+
"identifier": "sown-legume",
|
|
249
|
+
"name": "Couvert Semé de Légumineuses / Engrais Verts",
|
|
250
|
+
"description": "Mélange semé (trèfle, féverole, vesce) apportant un enrichissement en azote symbiotique et une structuration profonde du sol.",
|
|
251
|
+
"keywords": "crop-cover, legume, green-manure, nitrogen-fixation",
|
|
252
|
+
"sameAs": [
|
|
253
|
+
"http://aims.fao.org/aos/agrovoc/c_3364"
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"@type": "DefinedTerm",
|
|
258
|
+
"@id": "okf:crop-cover/spontaneous-grass",
|
|
259
|
+
"identifier": "spontaneous-grass",
|
|
260
|
+
"name": "Enherbement Spontané Temporaire",
|
|
261
|
+
"description": "Développement de la flore naturelle locale maîtrisé par fauche ou broyage périodique.",
|
|
262
|
+
"keywords": "crop-cover, spontaneous, grass, eco",
|
|
263
|
+
"sameAs": [
|
|
264
|
+
"http://aims.fao.org/aos/agrovoc/c_3313"
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight, zero-dependency OKF (Open Knowledge Format v0.1) Markdown & YAML parser.
|
|
3
|
+
*/
|
|
4
|
+
import type { AnyOntologyItem } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Parses simple YAML frontmatter strings into a JavaScript object.
|
|
7
|
+
* Supports strings, numbers, booleans, flat arrays `[a, b]`, and 1-level nested maps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseYamlFrontmatter(yamlContent: string): Record<string, any>;
|
|
10
|
+
/**
|
|
11
|
+
* Parses an entire OKF Markdown file into an OntologyItem.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseOkfDocument(content: string): AnyOntologyItem;
|
|
14
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAA;AAEhE;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAuD7E;AAmCD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAiCjE"}
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight, zero-dependency OKF (Open Knowledge Format v0.1) Markdown & YAML parser.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses simple YAML frontmatter strings into a JavaScript object.
|
|
6
|
+
* Supports strings, numbers, booleans, flat arrays `[a, b]`, and 1-level nested maps.
|
|
7
|
+
*/
|
|
8
|
+
export function parseYamlFrontmatter(yamlContent) {
|
|
9
|
+
const result = {};
|
|
10
|
+
const lines = yamlContent.split(/\r?\n/);
|
|
11
|
+
let currentParentKey = null;
|
|
12
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13
|
+
const rawLine = lines[i];
|
|
14
|
+
const trimmed = rawLine.trim();
|
|
15
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
// Check indentation to determine if child of current parent
|
|
19
|
+
const isIndented = /^\s{2,}/.test(rawLine);
|
|
20
|
+
if (isIndented && currentParentKey) {
|
|
21
|
+
const colonIndex = trimmed.indexOf(':');
|
|
22
|
+
if (colonIndex !== -1) {
|
|
23
|
+
const subKey = trimmed.slice(0, colonIndex).trim();
|
|
24
|
+
const rawVal = trimmed.slice(colonIndex + 1).trim();
|
|
25
|
+
if (!result[currentParentKey] || typeof result[currentParentKey] !== 'object') {
|
|
26
|
+
result[currentParentKey] = {};
|
|
27
|
+
}
|
|
28
|
+
result[currentParentKey][subKey] = parseYamlValue(rawVal);
|
|
29
|
+
}
|
|
30
|
+
else if (trimmed.startsWith('- ')) {
|
|
31
|
+
// Array element under parent
|
|
32
|
+
if (!Array.isArray(result[currentParentKey])) {
|
|
33
|
+
result[currentParentKey] = [];
|
|
34
|
+
}
|
|
35
|
+
result[currentParentKey].push(parseYamlValue(trimmed.slice(2).trim()));
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// Top-level key
|
|
40
|
+
const colonIndex = trimmed.indexOf(':');
|
|
41
|
+
if (colonIndex === -1) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const key = trimmed.slice(0, colonIndex).trim();
|
|
45
|
+
const rawValue = trimmed.slice(colonIndex + 1).trim();
|
|
46
|
+
if (rawValue === '') {
|
|
47
|
+
// Parent block starting
|
|
48
|
+
currentParentKey = key;
|
|
49
|
+
result[key] = {};
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
currentParentKey = null;
|
|
53
|
+
result[key] = parseYamlValue(rawValue);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function parseYamlValue(val) {
|
|
59
|
+
if (val === '')
|
|
60
|
+
return null;
|
|
61
|
+
if (val === 'true' || val === 'yes')
|
|
62
|
+
return true;
|
|
63
|
+
if (val === 'false' || val === 'no')
|
|
64
|
+
return false;
|
|
65
|
+
if (val === 'null' || val === '~')
|
|
66
|
+
return null;
|
|
67
|
+
// Numbers
|
|
68
|
+
if (!isNaN(Number(val)) && !val.includes(' ') && val !== '') {
|
|
69
|
+
return Number(val);
|
|
70
|
+
}
|
|
71
|
+
// Arrays format: [a, b, c]
|
|
72
|
+
if (val.startsWith('[') && val.endsWith(']')) {
|
|
73
|
+
const inner = val.slice(1, -1).trim();
|
|
74
|
+
if (!inner)
|
|
75
|
+
return [];
|
|
76
|
+
return inner
|
|
77
|
+
.split(',')
|
|
78
|
+
.map((item) => item.trim())
|
|
79
|
+
.map((item) => {
|
|
80
|
+
if (item.startsWith('"') && item.endsWith('"'))
|
|
81
|
+
return item.slice(1, -1);
|
|
82
|
+
if (item.startsWith("'") && item.endsWith("'"))
|
|
83
|
+
return item.slice(1, -1);
|
|
84
|
+
return parseYamlValue(item);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// Strip surrounding quotes
|
|
88
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
89
|
+
return val.slice(1, -1);
|
|
90
|
+
}
|
|
91
|
+
return val;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parses an entire OKF Markdown file into an OntologyItem.
|
|
95
|
+
*/
|
|
96
|
+
export function parseOkfDocument(content) {
|
|
97
|
+
const trimmed = content.trim();
|
|
98
|
+
if (!trimmed.startsWith('---')) {
|
|
99
|
+
throw new Error('Invalid OKF document: Missing leading YAML frontmatter delimiter (---)');
|
|
100
|
+
}
|
|
101
|
+
const secondDelimiterIndex = trimmed.indexOf('\n---', 3);
|
|
102
|
+
if (secondDelimiterIndex === -1) {
|
|
103
|
+
throw new Error('Invalid OKF document: Missing closing YAML frontmatter delimiter (---)');
|
|
104
|
+
}
|
|
105
|
+
const frontmatterRaw = trimmed.slice(3, secondDelimiterIndex).trim();
|
|
106
|
+
const bodyMarkdown = trimmed.slice(secondDelimiterIndex + 4).trim();
|
|
107
|
+
const frontmatter = parseYamlFrontmatter(frontmatterRaw);
|
|
108
|
+
if (!frontmatter.id || !frontmatter.title) {
|
|
109
|
+
throw new Error(`Invalid OKF document: Mandatory "id" or "title" missing in frontmatter`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
type: frontmatter.type || 'concept',
|
|
113
|
+
id: String(frontmatter.id),
|
|
114
|
+
title: String(frontmatter.title),
|
|
115
|
+
description: String(frontmatter.description || ''),
|
|
116
|
+
tags: Array.isArray(frontmatter.tags) ? frontmatter.tags : [],
|
|
117
|
+
translations: frontmatter.translations || {},
|
|
118
|
+
standards: frontmatter.standards || {},
|
|
119
|
+
bodyMarkdown,
|
|
120
|
+
timestamp: frontmatter.timestamp,
|
|
121
|
+
...frontmatter,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
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AAK,CAAC,wEAAwE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO;QACJ,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,SAAS;QACnC,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC;QAChC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC;QAClD,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QAC7D,YAAY,EAAE,WAAW,CAAC,YAAY,IAAI,EAAE;QAC5C,SAAS,EAAE,WAAW,CAAC,SAAS,IAAI,EAAE;QACtC,YAAY;QACZ,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,GAAG,WAAW;KACG,CAAA;AACvB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for @bradtech/ontologies (OKF v0.1 Agricultural Lexicon)
|
|
3
|
+
*/
|
|
4
|
+
export type SupportedLanguage = 'fr' | 'en' | 'es' | 'it' | 'de';
|
|
5
|
+
export type LanguageMap = Partial<Record<SupportedLanguage, string>>;
|
|
6
|
+
export type OntologyDomain = 'soils' | 'irrigations' | 'crops' | 'crop-covers';
|
|
7
|
+
export interface OntologyStandards {
|
|
8
|
+
eppo?: string;
|
|
9
|
+
agrovoc?: string;
|
|
10
|
+
inrae?: string;
|
|
11
|
+
usda?: string;
|
|
12
|
+
wrb?: string;
|
|
13
|
+
icid?: string;
|
|
14
|
+
telepac_rpg?: string[];
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface BaseOntologyItem {
|
|
18
|
+
type: string;
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
tags: string[];
|
|
23
|
+
translations: LanguageMap;
|
|
24
|
+
standards?: OntologyStandards;
|
|
25
|
+
bodyMarkdown?: string;
|
|
26
|
+
timestamp?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SoilPhysics {
|
|
29
|
+
fieldCapacityPoint: number;
|
|
30
|
+
temporaryWiltingPoint: number;
|
|
31
|
+
permanentWiltingPoint: number;
|
|
32
|
+
bulkDensityKgM3: number;
|
|
33
|
+
clayPercentageApprox?: number;
|
|
34
|
+
sandPercentageApprox?: number;
|
|
35
|
+
siltPercentageApprox?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface SoilOntologyItem extends BaseOntologyItem {
|
|
38
|
+
type: 'soil';
|
|
39
|
+
physics: SoilPhysics;
|
|
40
|
+
}
|
|
41
|
+
export interface IrrigationEngineering {
|
|
42
|
+
method: string;
|
|
43
|
+
applicationEfficiency: number;
|
|
44
|
+
wettingPatternFraction: number;
|
|
45
|
+
}
|
|
46
|
+
export interface IrrigationOntologyItem extends BaseOntologyItem {
|
|
47
|
+
type: 'irrigation';
|
|
48
|
+
engineering: IrrigationEngineering;
|
|
49
|
+
}
|
|
50
|
+
export interface CropAgronomy {
|
|
51
|
+
rootDepthMaxCm: number;
|
|
52
|
+
kcInitial: number;
|
|
53
|
+
kcMid: number;
|
|
54
|
+
kcEnd: number;
|
|
55
|
+
baseTemperatureGdd: number;
|
|
56
|
+
waterRequirementMmAnnual?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface CropOntologyItem extends BaseOntologyItem {
|
|
59
|
+
type: 'crop';
|
|
60
|
+
category: string;
|
|
61
|
+
scientificName?: string;
|
|
62
|
+
agronomy: CropAgronomy;
|
|
63
|
+
}
|
|
64
|
+
export interface CropCoverEffects {
|
|
65
|
+
soilProtectionFactor: number;
|
|
66
|
+
waterCompetitionIndex: number;
|
|
67
|
+
nitrogenFixation: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface CropCoverOntologyItem extends BaseOntologyItem {
|
|
70
|
+
type: 'crop-cover';
|
|
71
|
+
effects: CropCoverEffects;
|
|
72
|
+
}
|
|
73
|
+
export type AnyOntologyItem = SoilOntologyItem | IrrigationOntologyItem | CropOntologyItem | CropCoverOntologyItem | BaseOntologyItem;
|
|
74
|
+
export interface FlatSelectOption {
|
|
75
|
+
id: string;
|
|
76
|
+
label: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
standards?: OntologyStandards;
|
|
79
|
+
}
|
|
80
|
+
export interface HierarchyNode<T = AnyOntologyItem> {
|
|
81
|
+
item: T;
|
|
82
|
+
children: HierarchyNode<T>[];
|
|
83
|
+
}
|
|
84
|
+
export interface OntologyLookupResult {
|
|
85
|
+
item: AnyOntologyItem;
|
|
86
|
+
domain: OntologyDomain;
|
|
87
|
+
matchedBy: 'id' | 'eppo' | 'agrovoc' | 'telepac' | 'alias';
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAEhE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAA;AAEpE,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,CAAA;AAE9E,MAAM,WAAW,iBAAiB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;I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M,WAAW,gBAAiB,SAAQ,gBAAgB;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,YAAY,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC9B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,gBAAgB,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC5D,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,gBAAgB,CAAA;CAC3B;AAED,MAAM,MAAM,eAAe,GACtB,gBAAgB,GAChB,sBAAsB,GACtB,gBAAgB,GAChB,qBAAqB,GACrB,gBAAgB,CAAA;AAErB,MAAM,WAAW,gBAAgB;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,iBAAiB,CAAA;CAC/B;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,eAAe;IAC/C,IAAI,EAAE,CAAC,CAAA;IACP,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAA;CAC9B;AAED,MAAM,WAAW,oBAAoB;IAClC,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,cAAc,CAAA;IACtB,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;CAC5D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bradtech/ontologies",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Open Knowledge Format (OKF v0.1) agricultural taxonomies, multilingual selectors, and open data cross-referencing engine",
|
|
5
|
+
"author": "Olivier Lépine <olivier@lepine.fr>",
|
|
6
|
+
"license": "AGPL-3.0-or-later",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./src/index.ts"
|
|
15
|
+
},
|
|
16
|
+
"./data": "./data/index.md"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"data",
|
|
25
|
+
"src",
|
|
26
|
+
"!**/*.test.ts",
|
|
27
|
+
"!**/__tests__"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "bun run src/build.ts && tsc -p tsconfig.build.json",
|
|
31
|
+
"test": "bun test"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.4.5"
|
|
35
|
+
},
|
|
36
|
+
"copyright": "Copyright (C) 2026 Olivier Lépine",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/bradtech-oss/stack.git",
|
|
40
|
+
"directory": "packages/ontologies"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static JSON Catalog & Embedded TypeScript Data Compiler for @bradtech/ontologies.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { resolve } from 'node:path'
|
|
7
|
+
import { loadOntologyCatalog, scanMarkdownFiles } from './loader'
|
|
8
|
+
import { parseOkfDocument } from './parser'
|
|
9
|
+
import { readFileSync } from 'node:fs'
|
|
10
|
+
import { toOpenDataJsonLd } from './extractor'
|
|
11
|
+
|
|
12
|
+
function build() {
|
|
13
|
+
const dataDir = resolve(__dirname, '../data')
|
|
14
|
+
const distDir = resolve(__dirname, '../dist')
|
|
15
|
+
const srcDir = resolve(__dirname, '../src')
|
|
16
|
+
|
|
17
|
+
console.log('Compiling OKF Agricultural Ontologies...')
|
|
18
|
+
|
|
19
|
+
const files = scanMarkdownFiles(dataDir)
|
|
20
|
+
const allItems = []
|
|
21
|
+
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
const content = readFileSync(file, 'utf-8')
|
|
24
|
+
try {
|
|
25
|
+
const doc = parseOkfDocument(content)
|
|
26
|
+
allItems.push(doc)
|
|
27
|
+
} catch (err) {
|
|
28
|
+
// Skip non-concept files
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const catalog = loadOntologyCatalog(dataDir)
|
|
33
|
+
|
|
34
|
+
mkdirSync(distDir, { recursive: true })
|
|
35
|
+
|
|
36
|
+
// 1. Write src/embeddedData.ts
|
|
37
|
+
const embeddedTsContent = `/**
|
|
38
|
+
* Auto-generated by build.ts. Do not edit manually.
|
|
39
|
+
*/
|
|
40
|
+
import type { AnyOntologyItem } from './types'
|
|
41
|
+
|
|
42
|
+
export const EMBEDDED_ONTOLOGY_ITEMS: AnyOntologyItem[] = ${JSON.stringify(allItems, null, 2)}
|
|
43
|
+
`
|
|
44
|
+
const embeddedPath = resolve(srcDir, 'embeddedData.ts')
|
|
45
|
+
writeFileSync(embeddedPath, embeddedTsContent, 'utf-8')
|
|
46
|
+
console.log(` -> Generated static embedded data at ${embeddedPath}`)
|
|
47
|
+
|
|
48
|
+
// 2. Write dist/catalog.json
|
|
49
|
+
const compiledCatalog = {
|
|
50
|
+
version: '0.1.0',
|
|
51
|
+
timestamp: new Date().toISOString(),
|
|
52
|
+
itemCount: catalog.items.length,
|
|
53
|
+
items: catalog.items,
|
|
54
|
+
soils: catalog.byDomain.get('soils') || [],
|
|
55
|
+
irrigations: catalog.byDomain.get('irrigations') || [],
|
|
56
|
+
crops: catalog.byDomain.get('crops') || [],
|
|
57
|
+
cropCovers: catalog.byDomain.get('crop-covers') || [],
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const catalogJsonPath = resolve(distDir, 'catalog.json')
|
|
61
|
+
writeFileSync(catalogJsonPath, JSON.stringify(compiledCatalog, null, 2), 'utf-8')
|
|
62
|
+
console.log(` -> Written compiled catalog (${catalog.items.length} concepts) to ${catalogJsonPath}`)
|
|
63
|
+
|
|
64
|
+
// 3. Write dist/opendata.jsonld
|
|
65
|
+
const openDataPath = resolve(distDir, 'opendata.jsonld')
|
|
66
|
+
const openData = toOpenDataJsonLd(catalog)
|
|
67
|
+
writeFileSync(openDataPath, JSON.stringify(openData, null, 2), 'utf-8')
|
|
68
|
+
console.log(` -> Written Open Data JSON-LD to ${openDataPath}`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
build()
|