Ossie

Overview

Apache Ossie (formerly OSI – Open Semantic Interchange) is a vendor-neutral specification for exchanging semantic models between data analytics, AI and BI tools. This generator targets the Ossie ontology specification, which is used for domain models: concepts and the relationships between them.

gen-ossie personinfo.yaml
linkml generate ossie --format json personinfo.yaml

Maintained in ohi LinkML

Important

The generator itself is not implemented in this repository. This is a wrapper around the Ossie generator in ohi LinkML.

Please report any bug reports or feature requests at https://github.com/NeverBlink-OSS/ohi/issues

You can also try the generator without installing anything in the in-browser playground.

When reporting bugs, please include the versions of both linkml and ohi LinkML. You can find them by running gen-ossie --version.

What gets generated

LinkML

Ossie

Class

EntityType concept

Enum

ValueType concept extending String, with its permissible values in requires

Type

ValueType concept extending the built-in value type for its base

Slot

Relationship of each class that uses it

is_a and mixins on a class

extends

identifier, key or unique_keys

identify_by

Required slot

requires

description

description

The full mapping is described in the ohi LinkML documentation.

Limitations

The schema has to be a path to a local file. ohi LinkML reads it and resolves its imports from disk itself, so a URL or an already-parsed SchemaDefinition is refused.

Docs

Command Line

gen-ossie

Generate an Apache Ossie ontology from a LinkML model.

Classes become EntityType concepts, enums and types become ValueType concepts, slots become relationships, and is_a and mixins become extends. Use –pruning-mode to leave out elements that are not reachable from the root schema or from the tree root class.

The generator is implemented in ohi LinkML, which is maintained separately. Please submit bug reports and feature requests to https://github.com/NeverBlink-OSS/ohi/issues

gen-ossie [OPTIONS] YAMLFILE

Options

-V, --version

Show the linkml and ohi LinkML versions and exit.

-o, --output <output>

Output file name. Writes to stdout if not given.

--tree-root <tree_root>

Tree root class name to use instead of the schema-defined tree_root.

--pruning-mode <pruning_mode>

Which unused elements (classes, types, enums) to remove. tree_root - remove all elements unreachable from the tree_root class. schema - remove all elements unreachable from any of the classes defined in the root schema. skip - do not remove unused elements.

Default:

'skip'

Options:

skip | schema | tree_root

-f, --format <format>

Output format

Default:

'yaml'

Options:

yaml | json

--metadata, --no-metadata

Include metadata in output

Default:

True

--generation-date, --no-generation-date

Stamp output with the generation_date timestamp. Off by default so output is reproducible across runs.

Default:

False

--useuris, --metauris

Use class and slot URIs over model uris

Default:

True

-im, --importmap <importmap>

Import mapping file

--log_level <log_level>

Logging level

Default:

'WARNING'

Options:

CRITICAL | ERROR | WARNING | INFO | DEBUG

-v, --verbose

Verbosity. Takes precedence over –log_level.

--mergeimports, --no-mergeimports

Merge imports into source file (default=mergeimports)

--stacktrace, --no-stacktrace

Print a stack trace when an error occurs

Default:

False

Arguments

YAMLFILE

Required argument

Code

class linkml.generators.ossiegen.OssieGenerator(schema: str | Path, format: str | None = None, metadata: bool = True, useuris: bool | None = None, include_generation_date: bool = False, log_level: int | None = 30, mergeimports: bool | None = True, source_file_date: str | None = None, source_file_size: int | None = None, logger: Logger | None = None, verbose: bool | None = None, output: str | None = None, directory_output: bool = False, base_dir: str | None = None, importmap: str | Mapping[str, str] | None = None, stacktrace: bool = False, include: str | Path | None = None, pruning_mode: str = 'skip', tree_root: str | None = None)[source]

Generates an Ossie ontology describing the schema’s classes, slots, enums and types.

>>> from linkml.generators.ossiegen import OssieGenerator
>>> schema = '''
... id: https://example.org/personinfo
... name: personinfo
... prefixes:
...   linkml: https://w3id.org/linkml/
...   personinfo: https://example.org/personinfo/
... default_prefix: personinfo
... default_range: string
... imports:
...   - linkml:types
... classes:
...   Person:
...     description: A human being
...     attributes:
...       age:
...         range: integer
... '''
>>> print(OssieGenerator(schema).serialize())
version: 0.2.0.dev0
name: personinfo
prefixes:
  personinfo: https://example.org/personinfo/
ontology:
  - concept: Person
    type: EntityType
    iri: personinfo:Person
    description: A human being
    relationships:
      - name: age
        iri: personinfo:age
        roles:
          - concept: Integer
        multiplicity: ManyToOne
        verbalizes:
          - "{Person} age {Integer}"
as_dict() → dict[str, Any][source]

Generate the Ossie ontology as a Python dictionary.

Parsed from the JSON.

Returns:

the parsed ontology.

as_json() → str[source]

Generate the Ossie ontology as JSON.

Returns:

the ontology in JSON.

as_yaml() → str[source]

Generate the Ossie ontology as YAML.

Returns:

the ontology in YAML.

serialize(**kwargs) → str[source]

Generate the Ossie ontology in format.

Parameters:

kwargs – ignored, so the shared CLI options can be passed straight through.

Returns:

the serialized ontology.

class linkml.generators.common.ohi.OhiBackedGenerator(schema: str | Path, format: str | None = None, metadata: bool = True, useuris: bool | None = None, include_generation_date: bool = False, log_level: int | None = 30, mergeimports: bool | None = True, source_file_date: str | None = None, source_file_size: int | None = None, logger: Logger | None = None, verbose: bool | None = None, output: str | None = None, directory_output: bool = False, base_dir: str | None = None, importmap: str | Mapping[str, str] | None = None, stacktrace: bool = False, include: str | Path | None = None)[source]

Base class for generators that use ohi LinkML.

Subclasses set valid_formats and implement serialize() by calling one method on ohi_schema.

Loading a schema is the expensive part and every generator call on a loaded schema is cheap, so ohi_schema is built on first use and then reused. Release it with close(), or use the generator as a context manager:

with SomeGenerator("schema.yaml") as generator:
    print(generator.serialize())

Dropping the last reference will release it too, but only when the garbage collector gets to it.

Unlike Generator this takes a path and nothing else, and nothing here parses the schema: ohi LinkML reads it, resolves its imports, and is the only thing that has an opinion about it. That is also why the options in UNSUPPORTED_OPTIONS are refused rather than emulated.

close() → None[source]

Release the loaded schema. Calling it more than once is fine.

property generatorversion: str

The ohi LinkML version doing the translation, read from the ABI.

property ohi_schema

The schema as ohi LinkML sees it, loaded on first use and then reused.

Returns:

a ohi_linkml.Schema, owned by this generator. Do not close it; call close() instead.

Raises:
  • ImportError – if the ohi LinkML bindings are not installed.

  • ohi_linkml.SchemaLoadError – if ohi LinkML cannot load the schema.