#ontology #owl #visitor #owl2

horned-visit

Visitor traits for horned-owl with overloadable implementations

1 unstable release

0.1.0 Feb 23, 2022

#824 in Science

21 downloads per month

MIT and LGPL-3.0

31KB
507 lines

horned-visit Star me

Visitor traits for horned-owl with overloadable implementations.

Actions Codecov License Source Crate Documentation Changelog GitHub issues

πŸ—ΊοΈ Overview

This library provides visitor traits for the horned-owl object model, which can be used to easily implement algorithms to query or edit an ontology.

πŸ”Œ Usage

Add the latest versions of horned-owl and horned-visit to the [dependencies] sections of your Cargo.toml manifest:

[dependencies]
horned-owl = "0.11.0"
horned-visit = "0.1.0"

Then use the horned_visit::Visit or horned_visit::VisitMut traits to implement an algorithm. The horned_visit::visit and horned_visit::visit_mut modules contain default methods implementations.

πŸ’‘ Example

OWL2 does not require all entities to be declared (see the specification), but it can be required by convention to help catching typos. Here is how an algorithm could be implemented with horned-visit that ensures that all the IRI referencing OWL2 classes are declared in an ontology document:

extern crate horned_owl;
extern crate horned_visit;

use std::collections::HashSet;
use std::fs::File;
use std::io::BufReader;

use horned_owl::model::*;
use horned_visit::Visit;

#[derive(Default, Debug)]
struct ClassDeclarationChecker<'ast> {
    declared: HashSet<&'ast IRI>,
    used: HashSet<&'ast IRI>
}

impl<'ast> Visit<'ast> for ClassDeclarationChecker<'ast> {
    fn visit_declare_class(&mut self, declare_class: &'ast DeclareClass) {
        self.declared.insert(&declare_class.0.0);
        horned_visit::visit::visit_declare_class(self, declare_class);
    }
    fn visit_class(&mut self, class: &'ast Class) {
        self.used.insert(&class.0);
    }
}

pub fn classes_well_declared(ontology: &horned_owl::ontology::set::SetOntology) -> bool {
    let mut checker = ClassDeclarationChecker::default();
    ontology.iter().for_each(|aa| checker.visit_annotated_axiom(aa));
    checker.used.is_subset(&checker.declared)
}

let mut f = File::open("tests/data/bfo.owl").map(BufReader::new).unwrap();
let ontology = horned_owl::io::rdf::reader::read(&mut f).unwrap().0.into();
assert!(classes_well_declared(&ontology));

πŸ’­ Feedback

⚠️ Issue Tracker

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker of the project if you need to report or ask something. If you are filling in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

πŸ“‹ Changelog

This project adheres to Semantic Versioning and provides a changelog in the Keep a Changelog format.

πŸ“œ License

This library is provided under the open-source MIT license.

This project was developed by Martin Larralde during his PhD project at the European Molecular Biology Laboratory in the Zeller team.

Dependencies

~4.5MB
~82K SLoC