|
1 | | -# How to use the ontology service in pynxtools |
| 1 | +# Using ontology service in pynxtools |
2 | 2 |
|
3 | | -## Overview |
4 | | - |
5 | | -The ontology service in `pynxtools` provides a FastAPI-based app for querying NeXus ontology integrated with ESRFET and PaNET. It enables users to retrieve ontological information, such as superclasses for NeXus Application definitions and makes datasets of different experimental techniques based on PaNET ontology findable in NOMAD. |
| 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) " |
6 | 4 |
|
7 | 5 | ## Prerequisites |
8 | 6 |
|
9 | | -- Python 3.8+ |
| 7 | +- Python 3.10+ |
10 | 8 | - Install required packages: |
11 | | - - `pynxtools` and its dependencies (see [`pyproject.toml`](../../../pyproject.toml)) |
| 9 | + - `pynxtools` and its dependencies (see [`pyproject.toml`](https://github.com/FAIRmat-NFDI/pynxtools/blob/master/pyproject.toml)) |
12 | 10 | - `owlready2`, `pygit2`, `fastapi`, `uvicorn` |
13 | | -- Ensure the NeXusOntology and definitions submodule are present in the repository, typically at [`src/pynxtools/NeXusOntology`](../../../src/pynxtools/NeXusOntology/) and [`src/pynxtools/definitions`](../../../src/pynxtools/definitions/) respectively. |
| 11 | +- Ensure the NeXusOntology and definitions submodules are initialized (see [Development guide](../../tutorial/contributing.md#development-installation)). |
14 | 12 |
|
15 | 13 | ## Getting Started |
16 | 14 |
|
17 | 15 | ### Importing and Using the Service |
18 | 16 |
|
19 | | -The main entry point is the FastAPI app defined in [`pynxtools.nomad.apis.ontology_service`](../../../src/pynxtools//nomad/apis/ontology_service.py). You can import and use the service as follows: |
| 17 | +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: |
20 | 18 |
|
21 | 19 | ```python |
22 | 20 | from pynxtools.nomad.apis.ontology_service import app, load_ontology, fetch_superclasses |
23 | 21 | ``` |
24 | 22 |
|
25 | 23 | ### Minimal Working Example |
26 | 24 |
|
27 | | -You can extract superclasses for a NeXus class using the ontology service's HTTP API endpoint. For example, using Python's `requests` library: |
| 25 | +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: |
28 | 26 |
|
29 | 27 | ```python |
30 | 28 | import requests |
31 | 29 |
|
32 | 30 | # Replace with the actual running service URL |
33 | 31 | base_url = "http://localhost:8000/nomad-oasis/" |
34 | | -class_name = "NXiv_temp" |
| 32 | +class_name = "NXmpes_arpes" |
35 | 33 | response = requests.get(f"{base_url}/superclasses/{class_name}") |
36 | 34 | if response.status_code == 200: |
37 | 35 | superclasses = response.json().get("superclasses", []) |
|
40 | 38 | print(f"Error: {response.status_code} - {response.text}") |
41 | 39 | ``` |
42 | 40 |
|
43 | | -This endpoint returns a JSON object with the list of superclasses for the given NeXus class name, as used internally in [pynxtools](../../../src/pynxtools/nomad/schema.py) |
| 41 | +This endpoint returns a JSON object with the list of superclasses for the given NeXus class name, as used internally in [pynxtools](https://github.com/FAIRmat-NFDI/pynxtools/blob/ontology-service/src/pynxtools/nomad/schema.py) |
| 42 | + |
| 43 | +## How it works in NOMAD |
| 44 | + |
| 45 | +When you upload a NeXus file to NOMAD, the ontology service is automatically triggered during data processing. Here's what happens: |
| 46 | + |
| 47 | +1. **Triggering**: During normalization, NOMAD reads the `definition__field` from NeXus entry (e.g., `NXmpes_arpes`). |
| 48 | + |
| 49 | +{ width="800" } |
| 50 | +{ width="800" } |
| 51 | + |
| 52 | +2. **Querying**: The service loads the ontology (or generates it if not already present) and retrieves all superclasses for that application definition. |
| 53 | + |
| 54 | +3. **Storing results**: The retrieved superclasses are stored in `results.eln.methods` in the NOMAD archive. |
44 | 55 |
|
45 | | -### Further Reading |
| 56 | +{ width="800" } |
46 | 57 |
|
47 | | -- [Learn: Understanding the ontology service in pynxtools](../../learn/pynxtools/ontology-service.md) |
| 58 | +!!! info "Further Reading" |
| 59 | + - [Learn: Understanding the ontology service in pynxtools](../../learn/pynxtools/ontology-service.md) |
0 commit comments