A package to view and write ontologies directly from draw.io diagram files.
Project description
CEMENTO
CEMENTO is a component python package of the larger SDLE FAIR application suite of tools for creating scientific ontologies more efficiently. This package provides functional interfaces for converting draw.io diagrams of ontologies into RDF triple file formats and vice versa. This package is able to provide term matching between reference ontology files and terms used in draw.io diagrams allowing for faster ontology deployment while maintaining robust cross-references.
CEMENTO stands for the Centralized Entity Mapping & Extraction Nexus for Triples and Ontologies – a mouthful for an acronym, but an important metaphor for the package building the road to ontologies for materials data.
Documentation Page
This README.md is supplemented by a more comprehensive documentation page. It can be found in our homepage.
Check out MDS-Onto, the modular ontology for materials data, and other FAIR-related projects through this link.
Features
To summarize, the package offers the following features:
- Converting RDF triples into draw.io diagrams of the ontology terms and relationships and vice versa
- Substituting and matching terms based on ontologies that YOU provide
- Support for nested collections, axioms and restrictions for directly inputting your rulesets into the diagrams!
- Creating coherent tree-based layouts for terms for visualizing ontology class and instance relationships
- Tree-splitting diagram layouts to support multiple inheritance between classes (though multiple inheritance is not recommended by BFO)
- Support for URI prefixes (via binding) and literal annotations (language annotations like
@enand datatype annotations like^^xsd:string) - Providing a log for substitutions made and suppressing substitutions by adding a key (*).
- Support for Property definitions. Properties that do not have definitions will default as an Object Property type.
- Support for multiple pages in a draw.io file, for when you want to organize terms your way.
Installation
To install this particular package, use pip to install the latest version of the package:
# use a python environment
python -m venv .cemento
source .cemento/bin/activate
# install the actual package
pip install cemento
Usage
To convert from turtle to drawio and vice versa:
# converting from .ttl to drawio
$ cemento ttl_drawio your_triples.ttl your_output_diagram.drawio
# converting from .drawio to .ttl
$ cemento drawio_ttl your_output_diagram.drawio your_triples.ttl
To convert in another RDF file format, do:
converting from .xml to drawio
$ cemento rdf_drawio your_triples.xml your_output_diagram.drawio
alternatively, specify the format
$ cemento rdf_drawio -f xml your_triples.xml your_output_diagram.drawio
You can also use the inverse:
# converting from .drawio to .ttl
$ cemento drawio_ttl your_output_diagram.drawio your_triples.ttl
# converting from .drawio to .xml
$ cemento drawio_rdf your_output_diagram.drawio your_triples.xml
# alternatively, specify the format
$ cemento drawio_rdf -f xml your_output_diagram.drawio your_triples.xml
Adding Reference Ontologies
When using cemento ttl_drawio and cemento rdf_drawio, point the --onto-ref-folder-path argument with the folder containing the files you want to reference. The package comes pre-bundled with the Common Core Ontology (CCO). CCO will be used by default if the reference folder is not specified.
CAUTION: Repeated references are overwritten in the order the files are read by python (usually alphabetical order). If your reference files conflict with one another, please be advised and resolve those conflicts first by deleting the terms or modifying them.
Adding Custom Prefixes
Add your custom prefixes and namespaces to a prefixes.json file. An example can be found in examples/prefixes.json. Add your prefix-namespace pair at the bottom. To use your new prefixes.json file, use --prefix-file-path when calling cemento drawio_ttl or cemento drawio_rdf.
Scripting
To convert from draw.io diagram into an RDF file:
from cemento.rdf.drawio_to_rdf import convert_drawio_to_rdf
INPUT_PATH = "happy-example.drawio"
OUTPUT_PATH = "sample.ttl"
LOG_PATH = "substitution-log.csv"
if __name__ == "__main__":
convert_drawio_to_rdf(
INPUT_PATH,
OUTPUT_PATH,
file_format="turtle", # set the desired format for the rdf file output. The format is inferred if this is set to None
check_errors=True, # set whether to check for diagram errors prior to processing
log_substitution_path=LOG_PATH, # set where to save the substitution log for term fuzzy search
)
To do the opposite:
from cemento.rdf.rdf_to_drawio import convert_rdf_to_drawio
INPUT_PATH = "your_onto.ttl"
OUTPUT_PATH = "your_diagram.drawio"
if __name__ == "__main__":
convert_ttl_to_drawio(
INPUT_PATH,
OUTPUT_PATH,
file_format="turtle", # set the desired format for the rdf input. The format is inferred if this is set to None
horizontal_tree=False, #sets whether to display tree horizontally or vertically
set_unique_literals=False, # sets whether to make literals with the same content, language and type unique
classes_only=False, # sets whether to display classes only, useful for large turtles like CCO
demarcate_boxes=True, # sets whether to move all instances to A-box and classes to T-box
)
Drawing Basics
The following diagram goes through an example supplied with the repository called happy-example.drawio with its corresponding .ttl file called happy-example.ttl. We used CCO terms to model the ontology.
NOTE: Click on the figure and click the Raw button on the subsequent page to enlarge. If you prefer, your can also refer to the do-not-input-this-happy-example-explainer.drawio file found in the figures folder.
Future Features
This package was designed with end-to-end conversion in mind. The package is still in active development, and future features may include, but are not limited to the following:
- Visualizing Axioms and Restrictions. Users will be able to visualize the axioms and restrictions already in the input RDF file.
- An interactive mode. Users will be able to visualize syntax errors, improper term connections (leveraging domains and ranges), and substitutions and make edits in iterations before finalizing a draw.io or
.ttloutput. - Integrated reasoner. Packages like
owlready2have reasoners likeHermiTandPelletthat will be integrated to diagram-to-triple conversion. This is for when some implicit connections that you would want to make are a little bit tedious to draw but are equally as important.
License
This project was released under the BSD-3-Clause License. For more information about the license, please check the attached LICENSE.md file.
Third-party Licenses
For information about third-party licenses for packages used in this project, please refer to the THIRD_PARTY_LICENSES.txt file or the Licenses Page on the documentation.
Contact Information
If you have any questions or need further assistance, please open a GitHub issue and we can assist you there.
Project details
Release history Release notifications | RSS feed
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 cemento-0.14.1.tar.gz.
File metadata
- Download URL: cemento-0.14.1.tar.gz
- Upload date:
- Size: 10.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f491c44c868d3786f893634a75cdf04cfe5c79077df74905189e675556e976c7
|
|
| MD5 |
2e3a737ddbd354285fd4545679d40fe7
|
|
| BLAKE2b-256 |
be17fefb8767bb55b7c2fe29444411adaefbfdf31557d3aaea319b14f9252987
|
File details
Details for the file cemento-0.14.1-py3-none-any.whl.
File metadata
- Download URL: cemento-0.14.1-py3-none-any.whl
- Upload date:
- Size: 352.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10a682931d2fe00b7b0cdccd627148b2862636d7090c0e4a61a9acbbc20eb9e7
|
|
| MD5 |
bf4b746382ed8edd71edf13fcbb6b82e
|
|
| BLAKE2b-256 |
8e3fbe6368de2feb0bf9dc7327170b5f1a2351e4fb5b2824c40d6722057d0e07
|