Installing ontologies (pico)
Contents
Installing ontologies (pico)#
SimPhoNy works with data that is based on ontologies. In particular, all
information is represented in terms of ontology individuals that belong to
specific ontology classes, have specific attributes and can be connected to
other individuals through relationships. Classes, attributes and relationships
are defined in the ontologies. Therefore, in order for SimPhoNy to be able to
properly interpret the data, such ontologies need to be made available to it.
For that purpose, SimPhoNy includes an ontology management tool called pico
.
Ontologies can be added to SimPhoNy by installing ontology packages, which are YAML configuration files that, in addition to pointing to the actual ontology files, also define extra metadata. A list of supported ontology languages is available here.
We bundle a few of these files with SimPhoNy to enable rapid installation of common, well-known ontologies. If the ontology you wish to install is not among these, and the ontology author does not provide such a file, then you may just simply create one yourself.
There are three main operations that can be done with pico:
pico
can be used both from the command-line
and
as a Python module within the Python shell.
Using pico from the command line#
There are different possible logging levels available, and they can be set via
--log-level <ERROR|WARNING|INFO|DEBUG>
. The default value is INFO
.
pico install#
Usage:
pico install <path/to/ontology_package.yml>
pico install <path/to/ontology_package1.yml> <path/to/ontology_package2.yml> ...
pico install city foaf emmo dcat
(ontology packages that are bundled with SimPhoNy can be installed using this shortcut)
Behaviour:
The ontology file is parsed, and the entities mapped to Python objects.
The Python objects can be imported via their namespace
from osp.core.namespaces import namespace
.
Example:
(venv) user@PC:~$ pico install city
INFO [simphony_osp.utils.pico]: Will install the following packages: city.
INFO [simphony_osp.utils.pico]: Will install the following namespaces: city.
INFO [simphony_osp.utils.pico]: Installation successful
pico list#
Usage: pico list
Behaviour:
The installed namespaces and packages are printed out. A package can be uninstalled and can contain many namespaces. A namespace can be imported within the Python shell.
Example:
Packages:
- qe
- city
Namespaces:
- xml
- rdf
- rdfs
- xsd
- cuba
- owl
- qe
- city
pico uninstall#
Usage:
pico uninstall <package>
pico uninstall all
Behaviour:
The specified packages are uninstalled.
All packages except the uninstalled ones are re-installed.
Example:
(venv) user@PC:~$ pico uninstall city
INFO [osp.core.ontology.installation]: Will install the following namespaces: ['qe']
INFO [osp.core.ontology.yml.yml_parser]: Parsing YAML ontology file /home/<username>/.osp_ontologies/qe.yml
INFO [osp.core.ontology.yml.yml_parser]: You can now use `from osp.core.namespaces import qe`.
INFO [osp.core.ontology.parser]: Loaded 205 ontology triples in total
INFO [osp.core.ontology.installation]: Uninstallation successful
Conflicts with other “pico” installations#
Some operating systems might have a pre-existing tool called pico. In most cases, the previous commands should work, but if any problem arises, you can use the following alternative:
python -m simphony_osp.tools.pico <command>
For example:
python -m simphony_osp.tools.pico install city
Using pico as a Python module#
pico
can also be used within the Python shell. In particular, four
functions are available to be imported from the simphony_osp.tools.pico
module,
from simphony_osp.tools.pico import install, namespaces, packages, uninstall
that cover the three main operations that pico is meant to perform: installing
ontologies (install
), uninstalling ontologies (uninstall
), and listing the
installed ontologies (packages
, namespaces
).
Each function is used in a similar way to its command-line counterpart.
install
: accepts one or more positional arguments of string type, which can be either paths toyml
ontology installation files or names of ontologies that can be installed via this shortcut. It is meant to clone the behavior of its command-line counterpart.uninstall
: accepts one or more positional arguments of string type, which must be names of already installed ontology packages. It also clones the behavior of its command-line counterpart.packages
: accepts no arguments and returns an iterator over the names of the installed packages.namespaces
: accepts no arguments and returns an iterator yielding oneOntologyNamespace
object for each installed namespace.
Usage examples:
install('city', 'path/to/ontology_package.yml')
,install('foaf', 'dcat2')
uninstall('city', 'foaf')
print(list(packages()))
print(list(namespaces()))
Ontology installation folder#
The installed ontologies are stored in the directory
~/.simphony-osp/ontologies
by default. On Windows, ~
usually refers to the
path C:\Users\<my username>
.
The installation directory can be changed by setting the
environment variable SIMPHONY_ONTOLOGIES_DIR
.