Skip to content

cknoll/yamlpyowl

Repository files navigation

Build Status Code style: black

General Information

This tool (yamlpyowl) aims to read an ontology (including individuals and SWRL rules) specified via the simple and widespread data-serialization language YAML and represent it as collection of python-objects via the package owlready2. From there, a reasoner can be used or the ontology can be exported to standard-owl format rdfxml.

Motivation

Almost all existing OWL2-syntax-dialects (RDF-XML, Turtle, Manchester) seem more or less unpractical for manual authoring. On the other hand, to encourage contributions, e.g. from students, the requirement to learn a sophisticated tool like Protégé or at least some exotic syntax like Manchester seems to be a significant hurdle. See also this blog post from knowledge engineering expert Maria Keet, and especially requirement HU-3: "Have at least one compact, human-readable syntax defined so that it can be easily typed up in emails." The tool yamlpyowl aims to explore in that direction. It relies on the widespread human-readable data-serialization language YAML.

The project is part of the authors endeavour to simplify the understanding and the usage of semantic technologies for humans without much experience in this field, e.g. from engineering.

Examples

Overview

More examples can be found in the directory.

Pizza Ontology Preview

The following example is a strongly simplified fragment of the "Pizza-Ontology" which is often used as introduction, e.g. in Protégé tutorials.

# shortcut to define multiple classes
- multiple_owl_classes:
      - Food:
          SubClassOf: "owl:Thing"
      - PizzaBase:
          SubClassOf: Food
      # ---
      - ThinAndCrispyBase:
          SubClassOf: PizzaBase
      # ---
      - PizzaTopping:
          SubClassOf: Food
      - CheezeTopping:
          SubClassOf: PizzaTopping
      - MozzarellaTopping:
          SubClassOf: CheezeTopping

      # ...

- owl_object_property:
    hasSpiciness:
        Domain:
          - "owl:Thing"
        Range:
          - Spiciness
        Characteristics:
            - Functional

- owl_object_property:
    hasIngredient:
        # shortcut: use plain string instead of len1-list
        Domain: Food
        Range: Food
        Characteristics:
            - Transitive
# ...


# create an individual 
- owl_individual:
    mypizza1:
      types:
        - Pizza

# assert some facts 
- property_facts:
    hasTopping:
        Facts:
            - mypizza1:
                - iTomatoTopping
                - iMozzarellaTopping
    hasBase:
        Facts:
            - mypizza1: iThinAndCrispyBase 

Features

yamlpyowl implements some "magic" convenience features, i.e. extensions to OWL2. To be easily recognizable the corresponding keywords all start with X_.

RelationConcepts to Simplify n-ary Relations

The concept name X_RelationConcept has a special meaning. It is used to simplify the creation of n-ary relations. In OWL it is typically required to create a own concept for such relations and an instance (individual) for each concrete relation, see this W3C Working Group Note.

The parser of yamlpyowl simplifies this: For every subclass of X_RelationConcept (which must start with X_and by convention should end with _RC, e.g. X_DocumentReference_RC)) the parser automatically creates a role X_hasDocumentReference_RC. Its domain can be specified with the attribute X_associatedWithClasses. The roles which can be applied to this concept are defined as usual. The application to individuals is done by relation_concept_facts.

Short Example:

- multiple_owl_classes:

      # ...

      - X_RelationConcept:
          # base class
          SubClassOf: "owl:Thing"

      - X_CombinedTasteValue_RC:
          SubClassOf: X_RelationConcept
          X_associatedWithClasses:
            - PizzaTopping


- owl_object_property:
    hasCombinationPartner:
        Domain: X_CombinedTasteValue_RC
        Range: Food

- owl_data_property:
    hasFunctionValue:
        Domain: "owl:Thing"
        Range:
            - float
        Characteristics:
            - Functional

# model two ternary relations: Mozzarella tastes 95%-good in
# combination with tomatos but only 50%-good in combination with meat.
- relation_concept_facts:
    iMozzarellaTopping:
        X_hasCombinedTasteValue_RC:
            - hasCombinationPartner: iTomatoTopping
              hasFunctionValue: 0.95
            - hasCombinationPartner: iMeatTopping
              hasFunctionValue: 0.5

Further example: see regional-rules.owl.yml

SWRL Rules

Semantic Web Rule Language (SWRL) rules can be defined with the keyword swrl_rule. See regional-rules.owl.yml for example usages.

Proxy Individuals

The python package owlready2 and most owl reasoners do not support meta classes (also called "punning"). However, sometimes it is necessary to express knowledge which refers to a class and not primarily to its instances. This can be modeled with "proxy individuals". yamlpyowl has the following optional keyword for this: __create_proxy_individual. Allowed values are True, recursive, and False (default). The respective individuals have the name i<ClassName>.

Command Line Interface

yamlpyowl comes with a command line interface which is automatically installed via pip. Main purpose: simple conversion from yaml to rdfxml format. See yamlpyowl --help for more information.

Documentation

Ordinary documentation does not yet exist. However, the following might be at least somewhat useful:

Requirements

  • python >= 3.8
  • java
  • <requirements.txt> (installed automatically via pip)

The docker container which provides the runtime environment for unittests is available here: carvk/java_python.

Installation

Install for Normal Usage

  • Run pip install yamlpyowl to install the latest officially released version

Install Directly from Source Repo

  • Clone the repo
  • Run pip install -e . from the project root
    • This installs in "editable mode" best suited for experimenting and hacking.

Development Status

Yamlpyowl is currently an early prototype and will likely be expanded (and changed) in the future. If you are interested in using this package in your project as a dependency or in contributing to Yamlpyowl please open an issue or contact the author. The same holds for feature requests and bug reports.

Contribution

Contributions in form of issues or pull requests are highly welcome. If you submit code please ensure that this project uses automatic code formatting with the tool black, more precisely: black -l 120 src.

Misc remarks

  • There exists at least one earlier similar tool: yaml2owl, written in haskel.