Skip to content

Commit 12d4199

Browse files
committed
Add examples and improve documentation in README.md
1 parent 14a8bb7 commit 12d4199

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ err-derive = "0.1.5"
3131

3232
[dev-dependencies]
3333
matches = "0.1.8"
34+
ureq = "0.11.0"
35+
36+
[features]
37+
_doc = []
38+
39+
[package.metadata.docs.rs]
40+
features = [ "_doc" ]

README.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `horned-functional` [![Star me](https://img.shields.io/github/stars/fastobo/horned-functional.svg?style=social&label=Star&maxAge=3600)](https://github.com/fastobo/horned-functional/stargazers)
22

3-
*An [OWL2 Functional-style Syntax](https://www.w3.org/TR/owl2-syntax/) parser for `horned-owl`*
3+
*An [OWL2 Functional-style Syntax](https://www.w3.org/TR/owl2-syntax/) parser for [`horned-owl`](https://github.com/phillord/horned-owl)*
44

55
[![TravisCI](https://img.shields.io/travis/fastobo/horned-functional/master.svg?maxAge=600&style=flat-square)](https://travis-ci.org/fastobo/horned-functional/branches)
66
[![Codecov](https://img.shields.io/codecov/c/gh/fastobo/horned-functional/master.svg?style=flat-square&maxAge=600)](https://codecov.io/gh/fastobo/horned-functional)
@@ -10,3 +10,63 @@
1010
[![Documentation](https://img.shields.io/badge/docs.rs-latest-4d76ae.svg?maxAge=2678400&style=flat-square)](https://docs.rs/horned-functional)
1111
[![Changelog](https://img.shields.io/badge/keep%20a-changelog-8A0707.svg?maxAge=2678400&style=flat-square)](https://github.com/fastobo/horned-functional/blob/master/CHANGELOG.md)
1212
[![GitHub issues](https://img.shields.io/github/issues/fastobo/horned-functional.svg?style=flat-square)](https://github.com/fastobo/horned-functional/issues)
13+
14+
## Overview
15+
16+
This library provides an OWL Functional-style parser implementation for the
17+
`horned-owl` library, which provides the complete OWL2 model as a Rust library.
18+
19+
The parser is implemented as a `pest` parser, using a translation of the BNF
20+
grammar. It provides spanned errors to easily identify the faulty parts of an
21+
invalid OWL2 document.
22+
23+
All OWL2 entities also receive an implementation of `FromFunctional`, which can
24+
be used to deserialize each entity independently from their functional syntax
25+
representation. Since the deserialization is context-dependent when not
26+
considering the entire document, it is possible to provide a custom prefix
27+
mapping to handle compact identifiers in situations where one is needed.
28+
29+
## Usage
30+
31+
Add `horned-owl` and `horned-functional` to the `[dependencies]` sections of
32+
your `Cargo.toml` manifest:
33+
```toml
34+
[dependencies]
35+
horned-functional = "0.1.0"
36+
```
37+
38+
The `from_reader` function is the easiest way to deserialize an OWL Functional
39+
document from a `Read` implementor:
40+
```rust,no_run
41+
extern crate ureq;
42+
extern crate horned_functional;
43+
44+
fn main() {
45+
let url = "https://raw.githubusercontent.com/ha-mo-we/Racer/master/examples/owl2/owl-primer-mod.ofn";
46+
47+
let response = ureq::get(url).call();
48+
let mut reader = response.into_reader();
49+
50+
match horned_functional::from_reader(reader) {
51+
Ok((ont, _)) => println!("Number of axioms: {}", ont.iter().count()),
52+
Err(e) => panic!("could not parse document: {}", e)
53+
};
54+
}
55+
```
56+
57+
58+
## Feedback
59+
60+
Found a bug ? Have an enhancement request ? Head over to the
61+
[GitHub issue tracker](https://github.com/fastobo/horned-functional/issues) of the project if
62+
you need to report or ask something. If you are filling in on a bug, please include as much
63+
information as you can about the issue, and try to recreate the same bug in a simple, easily
64+
reproducible situation.
65+
66+
67+
## About
68+
69+
This project was developed by [Martin Larralde](https://github.com/althonos)
70+
as part of a Master's Degree internship in the [BBOP team](http://berkeleybop.org/) of the
71+
[Lawrence Berkeley National Laboratory](https://www.lbl.gov/), under the supervision of
72+
[Chris Mungall](http://biosciences.lbl.gov/profiles/chris-mungall/).

src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![cfg_attr(feature = "_doc", feature(doc_cfg, external_doc))]
2+
#![cfg_attr(feature = "_doc", doc(include = "../README.md"))]
3+
14
#[macro_use]
25
extern crate err_derive;
36
#[macro_use]
@@ -31,7 +34,7 @@ pub fn from_str<S: AsRef<str>>(src: S) -> Result<(Ontology, PrefixMapping)> {
3134

3235
/// Parse an entire OWL document from a `Read` implementor.
3336
#[inline]
34-
pub fn from_reader<R: Read + 'static>(mut r: R) -> Result<(Ontology, PrefixMapping)> {
37+
pub fn from_reader<R: Read>(mut r: R) -> Result<(Ontology, PrefixMapping)> {
3538
let mut s = String::new();
3639
r.read_to_string(&mut s)?;
3740
from_str(s)
@@ -40,6 +43,5 @@ pub fn from_reader<R: Read + 'static>(mut r: R) -> Result<(Ontology, PrefixMappi
4043
/// Parse an entire OWL document from a file on the local filesystem..
4144
#[inline]
4245
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<(Ontology, PrefixMapping)> {
43-
//let f = File::open(path).map_err(Error::from)?;
44-
from_reader(File::open(path)?)
46+
File::open(path).map_err(Error::from).and_then(from_reader)
4547
}

0 commit comments

Comments
 (0)