You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-tos/pynxtools/ontology-service.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,31 @@
1
-
# Using ontology service in pynxtools
1
+
# Using the ontology service in pynxtools
2
2
3
-
!!! info "This is a how-to guide for using the ontology service. If you want to learn more about how `ontology service` works in `pynxtools`, please visit the [explanation](../../learn/pynxtools/ontology-service.md)"
3
+
!!! info "This is a how-to guide for using the ontology service. If you want to learn more about how `ontology service` works in `pynxtools`, please visit the [explanation](../../learn/pynxtools/ontology-service.md)."
4
4
5
5
## Prerequisites
6
6
7
7
- Python 3.10+
8
-
- Install required packages:
9
-
-`pynxtools` and its dependencies (see [`pyproject.toml`](https://github.com/FAIRmat-NFDI/pynxtools/blob/master/pyproject.toml))
10
-
-`owlready2`, `pygit2`, `fastapi`, `uvicorn`
11
-
- Ensure the NeXusOntology and definitions submodules are initialized (see [Development guide](../../tutorial/contributing.md#development-installation)).
8
+
- You will first need to install pynxtools and its dependencies (see [pyproject.toml](https://github.com/FAIRmat-NFDI/pynxtools/blob/master/pyproject.toml)), including owlready2, pygit2, fastapi, uvicorn. For more information about the installation, see [installation guide](../../tutorial/installation.md)
9
+
- If you plan to work on `pynxtools` and the ontology service locally, follow the [development guide](../../tutorial/contributing.md). Ensure the NeXusOntology and definitions submodules [are initialized](../../tutorial/contributing.md#development-installation).
12
10
13
-
## Getting Started
11
+
!!! note "NeXusOntology and definitions submodules"
12
+
=== "Using pynxtools (standard installation)"
13
+
If you are simply using `pynxtools` as a package, the NeXusOntology and definitions submodules are included automatically during installation. Follow the [installation guide](../../tutorial/installation.md) to get started.
14
14
15
-
### Importing and Using the Service
15
+
=== "Developing the ontology service"
16
+
If you are contributing to or developing the ontology service, you need to manually initialize the submodules. See the [development guide](../../tutorial/contributing.md#development-installation) for instructions on setting up the development environment.
17
+
18
+
## Getting started
19
+
20
+
### Importing and using the service
16
21
17
22
The main entry point is the FastAPI app defined in [`pynxtools.nomad.apis.ontology_service`](https://github.com/FAIRmat-NFDI/pynxtools/blob/ontology-service/src/pynxtools/nomad/apis/ontology_service.py). You can import and use the service as follows:
18
23
19
24
```python
20
25
from pynxtools.nomad.apis.ontology_service import app, load_ontology, fetch_superclasses
21
26
```
22
27
23
-
### Minimal Working Example
28
+
### Minimal working example
24
29
25
30
You can extract superclasses for a NeXus class using the ontology service's HTTP API endpoint. Here's an example using Python's `requests` library:
26
31
@@ -46,14 +51,11 @@ When you upload a NeXus file to NOMAD, the ontology service is automatically tri
46
51
47
52
1.**Triggering**: During normalization, NOMAD reads the `definition__field` from NeXus entry (e.g., `NXmpes_arpes`).
48
53
49
-
{ width="800" }
2.**Querying**: The service loads the ontology (or generates it if not already present) and retrieves all superclasses for that application definition.
53
58
54
59
3.**Storing results**: The retrieved superclasses are stored in `results.eln.methods` in the NOMAD archive.
55
60
56
-
{ width="800" }
57
-
58
-
!!! info "Further Reading"
59
-
- [Learn: Understanding the ontology service in pynxtools](../../learn/pynxtools/ontology-service.md)
61
+
{ width="800" }
Copy file name to clipboardExpand all lines: docs/learn/pynxtools/ontology-service.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Understanding the ontology service in pynxtools
2
2
3
-
!!! info "This is a learn guide for using the ontology service. If you want to learn more about how to use `ontology service` in `pynxtools`, please visit the [explanation](../../how-tos/pynxtools/ontology-service.md)"
3
+
!!! info "This is a learn guide for using the ontology service. If you want to learn more about how to use `ontology service` in `pynxtools`, please visit the [explanation](../../how-tos/pynxtools/ontology-service.md)."
4
4
5
5
## Introduction
6
6
@@ -16,9 +16,9 @@ By using these ontologies, the service maps NeXus application definitions to sta
16
16
17
17
## How it fits in pynxtools
18
18
19
-
This service only operates when `pynxtools` is run within `NOMAD`, exposing ontological data for NeXus Application definitions through a FastAPI interface. It uses NOMAD's configuration to set up the API base path and plugin entry points, then processes NeXus definitions to provide semantic data to users and connected systems.
19
+
The `ontology service` only operates when `pynxtools` is run within `NOMAD`. It is registered as an [`ApiEntryPoint`](https://nomad-lab.eu/prod/v1/docs/reference/config.html#apientrypoint), which allows NOMADto automatically discover and mount the FastAPI routes at startup. The service exposes [NeXus ontology](https://github.com/nexusformat/NeXusOntology) to users and connected systems.
20
20
21
-
## Core Concepts
21
+
## Core concepts
22
22
23
23
-**Ontology**: A formal representation of concepts (classes), relationships, and properties, typically serialized as [OWL](https://www.w3.org/OWL/) files.
24
24
-**Application definition**: A class or term describing an experimental technique in the NeXus (e.g., `NXmpes_arpes`).
@@ -27,24 +27,24 @@ This service only operates when `pynxtools` is run within `NOMAD`, exposing onto
27
27
28
28
Ontologies are represented as OWL files (e.g., `NeXusOntology_full_<commit>_inferred.owl`) and loaded using `owlready2`.
29
29
30
-
## Architecture & Design
30
+
## Architecture & design
31
31
32
-
-**Main Modules**:
33
-
-`pynxtools.nomad.apis.ontology_service`: FastAPI app, core logic for loading and querying ontologies.
34
-
-`pynxtools.NeXusOntology.script.generate_ontology`: Generates ontology files from NeXus definitions.
35
-
-`pynxtools.nomad.schema`: Initializes metainfo and schema integration.
36
-
-**Key Classes/Functions**:
37
-
-`load_ontology()`: Loads the inferred ontology file.
38
-
-`fetch_superclasses(ontology, class_name)`: Retrieves superclasses for a given NeXus class.
39
-
-`ensure_ontology_file()`: Ensures ontology file is present and up-to-date.
40
-
-**Data Flow**:
41
-
1. On startup, the service verifies whether the inferred ontology file exists; if absent, it runs the reasoner and generates the inferred ontology file.
42
-
2. Inferred ontology is loaded via `owlready2`.
43
-
3. API endpoints query this inferred ontology for relationships and metadata.
32
+
-**Main modules**:
33
+
-`pynxtools.nomad.apis.ontology_service`: FastAPI app, core logic for loading and querying ontologies.
34
+
-`pynxtools.NeXusOntology.script.generate_ontology`: Generates ontology files from NeXus definitions.
35
+
-`pynxtools.nomad.schema`: Initializes metainfo and schema integration.
36
+
-**Key classes/functions**:
37
+
-`load_ontology()`: Loads the inferred ontology file.
38
+
-`fetch_superclasses(ontology, class_name)`: Retrieves superclasses for a given NeXus class.
39
+
-`ensure_ontology_file()`: Ensures ontology file is present and up-to-date.
40
+
-**Data flow**:
41
+
- On startup, the service verifies whether the inferred ontology file exists; if absent, it runs the reasoner and generates the inferred ontology file.
42
+
- Inferred ontology is loaded via `owlready2`.
43
+
- API endpoints query this inferred ontology for relationships and metadata.
44
44
45
-
## Extensibility Points
45
+
## Extensibility points
46
46
47
-
- Extend FastAPI routes in `ontology_service.py` for new queries.
47
+
- Extend FastAPI routes in [`ontology_service.py`](https://github.com/FAIRmat-NFDI/pynxtools/blob/ontology-service/src/pynxtools/nomad/apis/ontology_service.py) for new queries.
0 commit comments