A Python binding for the Semantic Analyser service maintained by BODC
Project description
semanticanalyser-py
A lightweight Python client for the BODC Semantic Analyser API. It helps you discover controlled vocabularies, explore categories, match types and properties, and run term analysis to resolve terms to canonical concepts (with codes and URIs) across marine community vocabularies, including BODC NVS.
The project is authored by Ahmad Mahmoud during his internship at CNR-IIA.
Key features
- Retrieve semantic categories
- List supported vocabularies
- Discover supported match types and match properties
- Analyse free-text terms and obtain matched concepts, codes, and vocabularies
- Simple, Pythonic API with minimal dependencies
Installation
pip install semanticanalyser-py
Quick start
# Basic usage example
from analyser import SemanticAnalyzer, Matchtype, MatchProperty
analyser = SemanticAnalyzer() # uses the public BODC endpoint by default
# Explore categories
categories = analyser.get_categories()
print("Categories:", categories)
# Choose a category (e.g., first one) and list vocabularies
if categories:
cat_code = categories[0]["termCode"]
vocabs = analyser.get_vocabularies(cat_code)
for v in vocabs:
print(v)
# Discover matching options
match_types = analyser.getMatchTypes() # e.g., ["exact", "broad", ...]
match_props = analyser.getMatchProperties() # e.g., ["prefLabel", "altLabel", ...]
# Prepare the query
terms = ["dissolved oxygen", "chlorophyll a"]
# Optionally filter or construct match types/properties
# (example below demonstrates using them as returned)
analysis = analyser.analyzeTerms(
terms=terms,
matchTypes=match_types,
matchProperties=match_props
)
if analysis:
for m in analysis.get_matches():
print(
m.getMatchingTerm(),
m.getMatchProperty(),
m.getMatchType(),
m.getTermCode(),
m.getVocabulary(),
m.getConceptURI(),
)
When to use this library
- You need to map free-text terms to standardised concepts and codes
- You’re enriching marine dataset descriptions with semantic metadata (URIs, codes, vocabularies)
Configuration
- Endpoint: By default, the client targets the public BODC Semantic Analyser API. You can override the endpoint:
from analyser import SemanticAnalyzer
analyser = SemanticAnalyzer(endpoint="https://semantics.bodc.ac.uk/api")
Requirements
- Python: 3.8 or newer
- Dependencies: requests
Roadmap ideas
- Robust pagination and retry logic
- Additional helpers for filtering results
- CLI utilities
Contributing
Issues and pull requests are welcome.
License
GNU GPL-3.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semanticanalyser_py-0.1.1.tar.gz.
File metadata
- Download URL: semanticanalyser_py-0.1.1.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
728976094acf8265c2f1432816477bc3e9bb2492f5e8aefa1e5f5c8e3d132e61
|
|
| MD5 |
aced646c2265b75ba0a227e6f2b4bb36
|
|
| BLAKE2b-256 |
17c971b73bf79fe0e5c912f8e5c32509b45c8552546574affec2c78356068c48
|
File details
Details for the file semanticanalyser_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: semanticanalyser_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78d7e893ddc3abd9aeefc3c2222c2647f54e60aa3445fad1e01c59bbce365514
|
|
| MD5 |
976feee420d3df5c819dc86237417121
|
|
| BLAKE2b-256 |
a563fc269f5fd1c054aeee0a50284c08c3da75c3b68142ae00e7d22a9efbef15
|