Skip to content

Commit

Permalink
Merge branch 'devel' into fix/clean-test-files
Browse files Browse the repository at this point in the history
  • Loading branch information
phillord authored Mar 11, 2024
2 parents 2a408c0 + 6222654 commit 6f24b1c
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 75 deletions.
2 changes: 1 addition & 1 deletion horned-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub mod naming {
ReflexiveObjectProperty => "Reflexive Object Property",
IrreflexiveObjectProperty => "Irreflexive Object Property",
SymmetricObjectProperty => "Symmetric Object Property",
AsymmetricObjectProperty => "Assymmetric Object Property",
AsymmetricObjectProperty => "Asymmetric Object Property",
TransitiveObjectProperty => "Transitive Object Property",
SubDataPropertyOf => "Sub Data Property Of",
EquivalentDataProperties => "Equivalent Data Properties",
Expand Down
3 changes: 2 additions & 1 deletion src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Parsers and Renders for OWL Ontologies
//! Parsers and renderers for several of the ontology formats listed in the
//! [W3C recommendation](https://www.w3.org/TR/owl2-overview/#Syntaxes).
pub mod owx;
pub mod rdf;
Expand Down
2 changes: 2 additions & 0 deletions src/io/owx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
//! [OWL/XML](https://www.w3.org/TR/2012/REC-owl2-xml-serialization-20121211/)
//! syntax for OWL.
pub mod reader;
pub mod writer;
4 changes: 4 additions & 0 deletions src/io/owx/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ from_start! {
IRI::from_xml(r, e.local_name().as_ref())?
.into()
}
b"AnonymousIndividual" => {
AnonymousIndividual::from_start(r, e)?
.into()
}
_ => {
return Err
(error_unexpected_tag(e.local_name().as_ref(), r));
Expand Down
10 changes: 10 additions & 0 deletions src/io/owx/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ render! {
AnnotationValue::Literal(l) => {
l.render(w, m)?;
}
AnnotationValue::AnonymousIndividual(a) => {
a.render(w, m)?;
}
}

Ok(())
Expand Down Expand Up @@ -1471,6 +1474,13 @@ mod test {
));
}

#[test]
fn anonymous_annotation_value() {
assert_round(include_str!(
"../../ont/owl-xml/anonymous-annotation-value.owx"
));
}

#[test]
fn family() {
assert_round(include_str!("../../ont/owl-xml/manual/family.owx"));
Expand Down
1 change: 1 addition & 0 deletions src/io/rdf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/) syntax for OWL.
pub mod closure_reader;
pub mod reader;
pub mod writer;
32 changes: 25 additions & 7 deletions src/io/rdf/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
av: ob.clone().into(),
}
}
[s, Iri(p), Term::BNode(bnodeid)] => {
Annotation {
ap: AnnotationProperty(p.clone()),
av: AnonymousIndividual(bnodeid.0.clone()).into(),
}
}
_ => {
dbg!(t);
todo!()
Expand Down Expand Up @@ -1794,10 +1800,10 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
self.headers();

// Can we pull out annotations at this point and handle them
// as we do in reader2? Tranform them into a triple which we
// as we do in reader2? Transform them into a triple which we
// handle normally, then bung the annotation on later?

// Table 5: Backward compability -- skip this for now (maybe
// Table 5: Backward compatibility -- skip this for now (maybe
// for ever)

// Table 6: Don't understand this
Expand Down Expand Up @@ -2332,11 +2338,6 @@ mod test {
assert_eq!(amont.i().declare_class().count(), 1);
}

#[test]
fn datatype() {
compare("datatype");
}

#[test]
fn object_has_value() {
compare("object-has-value");
Expand Down Expand Up @@ -2372,6 +2373,11 @@ mod test {
compare("object-exact-cardinality");
}

#[test]
fn datatype() {
compare("datatype");
}

#[test]
fn datatype_alias() {
compare("datatype-alias");
Expand Down Expand Up @@ -2628,6 +2634,18 @@ mod test {
let _aa = ont.i().annotation_assertion().next();
}

#[test]
fn anonymous_annotation_value() {
let s = slurp_rdfont("anonymous-annotation-value");
let ont: ComponentMappedOntology<_, _> = read_ok(&mut s.as_bytes()).into();

// We cannot do the usual "compare" because the anonymous
// individuals break a direct comparision
assert_eq!(ont.i().annotation_assertion().count(), 1);

let _aa = ont.i().annotation_assertion().next();
}

// #[test]
// fn import_property() {
// compare("import-property")
Expand Down
3 changes: 3 additions & 0 deletions src/io/rdf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ render! {
f, bn, &self.ap.0, iri
)
}
AnnotationValue::AnonymousIndividual(an) => {
triple!(f, bn, &self.ap.0, an)
}
}
)
}
Expand Down
19 changes: 6 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
//! # Horned-OWL
//!
//! Horned-OWL is a library for the reading, manipulation and blah
//! generation of
//! [OWL](https://www.w3.org/TR/2012/REC-owl2-primer-20121211/)
//! ontologies.
//! Horned-OWL provides an interface to parse, generate and handle ontologies
//! written using the [Web Ontology Language (OWL)](https://www.w3.org/TR/2012/REC-owl2-primer-20121211/).
//!
//! The W3C Ontology Web Language (OWL) is a mechanism for
//! representing complex knowledge in the form an Ontology; describing
//! entities and the relationship between. Unlike a simple
//! classification taxonomy, OWL is highly expressive and maps to a
//! formal semantics which makes the ontology open to computational
//! Unlike a simple classification taxonomy, OWL is highly expressive and maps
//! to a formal semantics which makes the ontology open to computational
//! reasoning.
//!
//! The aim of the library is to provide a representation of OWL that
//! can be used to mainpulate OWL ontologies. As well as a library,
//! it offers a number of command-line tools for performing the same.
//! can be used to manipulate OWL ontologies.
//!
//! The focus of this library is on performance, compared to the [OWL
//! API](https://github.com/owlcs/owlapi), thereby allowing large
//! scale, bulk manipulation of ontologies that currently requires
//! specialized machinary.
//! specialized machinery.
//!
//! # Author
//!
Expand Down
20 changes: 13 additions & 7 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ components! {
sub: ClassExpression<A>
},

/// An equivalance relationship between two `ClassExpression`.
/// An equivalence relationship between two `ClassExpression`.
///
/// All instances of `ClassExpression` are also instances
/// of other other.
Expand All @@ -1068,7 +1068,7 @@ components! {

/// A sub property relationship between two object properties.
///
/// The existance of the sub property relationship between two
/// The existence of the sub property relationship between two
/// individuals also implies the super property relationship
/// also. The super property can also be a property chain.
/// So, if `s` is a super property of `r` then `a r b` implies `a
Expand Down Expand Up @@ -1226,7 +1226,7 @@ components! {
/// See also: [Functional Data Property]:(https://www.w3.org/TR/owl2-syntax/#Functional_Data_Properties)
Axiom FunctionalDataProperty(DataProperty<A>),

/// Defintion of a datatype.
/// Definition of a datatype.
///
/// See also: [Datatype Definitions](https://www.w3.org/TR/owl2-syntax/#Datatype_Definitions)
Axiom DatatypeDefinition {
Expand Down Expand Up @@ -1410,6 +1410,7 @@ pub struct Annotation<A> {
pub enum AnnotationValue<A> {
Literal(Literal<A>),
IRI(IRI<A>),
AnonymousIndividual(AnonymousIndividual<A>),
}

impl<A: ForIRI> From<Literal<A>> for AnnotationValue<A> {
Expand All @@ -1424,6 +1425,12 @@ impl<A: ForIRI> From<IRI<A>> for AnnotationValue<A> {
}
}

impl<A: ForIRI> From<AnonymousIndividual<A>> for AnnotationValue<A> {
fn from(ai: AnonymousIndividual<A>) -> Self {
AnnotationValue::AnonymousIndividual(ai)
}
}

/// A object property expression
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum ObjectPropertyExpression<A> {
Expand Down Expand Up @@ -1634,11 +1641,11 @@ pub enum ClassExpression<A> {
bce: Box<ClassExpression<A>>,
},

/// An exististential relationship.
/// An existential relationship.
///
/// This is the anonymous class of individuals `i` which have the
/// relationship `dp` to the data range, `dr`. Every individual
/// `i` must have this relationship to data constrainted by `dr`.
/// `i` must have this relationship to data constrained by `dr`.
///
/// See also: [Existential Quantification](https://www.w3.org/TR/owl2-syntax/#Existential_Quantification_2)
DataSomeValuesFrom {
Expand Down Expand Up @@ -1774,9 +1781,8 @@ pub trait MutableOntology<A> {

#[cfg(test)]
mod test {
use crate::ontology::component_mapped::ComponentMappedOntology;

use super::*;
use crate::ontology::component_mapped::ComponentMappedOntology;

#[test]
fn test_iri_from_string() {
Expand Down
20 changes: 20 additions & 0 deletions src/ont/owl-rdf/anonymous-annotation-value.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.example.com/iri#"
xml:base="http://www.example.com/iri"
xmlns:o="http://www.example.com/iri#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.example.com/iri">
<owl:versionIRI rdf:resource="http://www.example.com/viri"/>
</owl:Ontology>
<owl:AnnotationProperty rdf:about="http://www.example.com/iri#annotation"/>
<rdf:Description rdf:about="http://www.example.com/iri#class">
<annotation>
<rdf:Description/>
</annotation>
</rdf:Description>
</rdf:RDF>

21 changes: 21 additions & 0 deletions src/ont/owl-xml/anonymous-annotation-value.owx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.example.com/iri"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://www.example.com/iri"
versionIRI="http://www.example.com/viri">
<Prefix name="o" IRI="http://www.example.com/iri#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="o:annotation"/>
<AbbreviatedIRI>o:class</AbbreviatedIRI>
<AnonymousIndividual nodeID="_:genid2147483648"/>
</AnnotationAssertion>
</Ontology>
13 changes: 11 additions & 2 deletions src/ontology/component_mapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! onimpl {
};
}

#[derive(Debug, Default, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub struct ComponentMappedIndex<A, AA> {
component: RefCell<BTreeMap<ComponentKind, BTreeSet<AA>>>,
pd: PhantomData<A>,
Expand Down Expand Up @@ -189,7 +189,7 @@ onimpl! {InverseFunctionalObjectProperty, inverse_functional_object_property}
onimpl! {ReflexiveObjectProperty, reflexive_object_property}
onimpl! {IrreflexiveObjectProperty, irreflexive_object_property}
onimpl! {SymmetricObjectProperty, symmetric_object_property}
onimpl! {AsymmetricObjectProperty, assymmetric_object_property}
onimpl! {AsymmetricObjectProperty, asymmetric_object_property}
onimpl! {TransitiveObjectProperty, transitive_object_property}
onimpl! {SubDataPropertyOf, sub_data_property_of}
onimpl! {EquivalentDataProperties, equivalent_data_properties}
Expand All @@ -211,6 +211,15 @@ onimpl! {SubAnnotationPropertyOf, sub_annotation_property_of}
onimpl! {AnnotationPropertyDomain, annotation_property_domain}
onimpl! {AnnotationPropertyRange, annotation_property_range}

impl<A, AA> Default for ComponentMappedIndex<A, AA> {
fn default() -> Self {
Self {
component: Default::default(),
pd: Default::default(),
}
}
}

/// An owning iterator over the annotated components of an `Ontology`.
impl<A: ForIRI, AA: ForIndex<A>> IntoIterator for ComponentMappedIndex<A, AA> {
type Item = AnnotatedComponent<A>;
Expand Down
10 changes: 8 additions & 2 deletions src/ontology/declaration_mapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::collections::HashSet;
use std::marker::PhantomData;
use std::collections::HashMap;

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct DeclarationMappedIndex<A, AA>(HashMap<IRI<A>, NamedEntityKind>,
HashSet<IRI<A>>,
PhantomData<AA>);
Expand Down Expand Up @@ -84,9 +84,15 @@ macro_rules! some {
};
}

impl<A, AA> Default for DeclarationMappedIndex<A, AA> {
fn default() -> Self {
DeclarationMappedIndex(Default::default(), Default::default(), Default::default())
}
}

impl<A: ForIRI, AA: ForIndex<A>> OntologyIndex<A, AA> for DeclarationMappedIndex<A, AA> {
fn index_insert(&mut self, ax: AA) -> bool {
some! {
some!{
{
let ne = self.aa_to_ne(ax.borrow())?;
let iri = self.aa_to_iri(ax.borrow())?;
Expand Down
Loading

0 comments on commit 6f24b1c

Please sign in to comment.