From 59c8dffb0160d265d166d85faae33836b191f4e4ca2cafbfbe84b3ac38674c10 Mon Sep 17 00:00:00 2001 From: Alex Wied <543423+centromere@users.noreply.github.com> Date: Mon, 29 Jun 2026 15:20:02 -0400 Subject: [PATCH] . --- Cargo.lock | 40 ++++----- publish/src/app.rs | 49 +++++------ publish/src/error.rs | 3 + publish/src/main.rs | 4 +- publish/src/rdf/conversion.rs | 13 +-- publish/src/rdf/materialize.rs | 18 +++-- publish/src/rdf/ontologies/ontology.ttl | 4 + publish/src/rdf/ontology.rs | 103 ++++++++++++------------ search/src/error.rs | 3 - search/src/index.rs | 53 ++++++------ 10 files changed, 149 insertions(+), 141 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cad638c..074cc62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,9 +106,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" [[package]] name = "arboard" @@ -130,9 +130,9 @@ dependencies = [ [[package]] name = "arc-swap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a3a1fd6f75306b68087b831f025c712524bcb19aad54e557b1129cfa0a2b207" +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" dependencies = [ "rustversion", ] @@ -1399,9 +1399,9 @@ dependencies = [ [[package]] name = "glam" -version = "0.33.1" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "898f5a568a84989b6c0f8caa50a93074b97dbdc58fc6d9543157bb4562758933" +checksum = "7f22fb22f065b308be0d8724e3706c7fa3fc2a6c7d6899df4cad7860e7a75436" [[package]] name = "glob" @@ -1630,7 +1630,7 @@ dependencies = [ [[package]] name = "iced" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "iced_core", "iced_debug", @@ -1645,7 +1645,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "bitflags 2.13.0", "bytes", @@ -1663,7 +1663,7 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "iced_core", "iced_futures", @@ -1673,7 +1673,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "futures", "iced_core", @@ -1687,7 +1687,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "bitflags 2.13.0", "bytemuck", @@ -1705,7 +1705,7 @@ dependencies = [ [[package]] name = "iced_program" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "iced_graphics", "iced_runtime", @@ -1714,7 +1714,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1726,7 +1726,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "bytes", "iced_core", @@ -1737,7 +1737,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "bytemuck", "cosmic-text", @@ -1753,7 +1753,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "bitflags 2.13.0", "bytemuck", @@ -1770,7 +1770,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "iced_renderer", "iced_runtime", @@ -1784,7 +1784,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.15.0-dev" -source = "git+https://github.com/iced-rs/iced.git?branch=master#e46f9c9e69a8d787823c4a64fdcc49c23f303065" +source = "git+https://github.com/iced-rs/iced.git?branch=master#36b6ed0aec85fb01afbb63b4f48afa7763487967" dependencies = [ "arboard", "iced_debug", @@ -4727,9 +4727,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.23.3" +version = "1.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "144d6b123cef80b301b8f72a9e2ca4370ddec21950d0a103dd22c437006d2db7" +checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53" dependencies = [ "getrandom 0.4.3", "js-sys", diff --git a/publish/src/app.rs b/publish/src/app.rs index 5ec76b3..5dd9a3c 100644 --- a/publish/src/app.rs +++ b/publish/src/app.rs @@ -1,7 +1,7 @@ use crate::rdf::ontology::{LabeledIri, Ontology}; use crate::rdf::term_helper::{TermHelper, TermHelperMut}; use crate::rdf::vocab::{gl, rda}; -use gl_search::{Schema, SearchDocument, SearchIndex, doc, NamedFieldDocument, OwnedValue}; +use gl_search::{Schema, SearchDocument, SearchIndex, NamedFieldDocument, OwnedValue, doc}; use http::StatusCode; use iced::alignment::Horizontal; use iced::widget::button::Style; @@ -18,8 +18,8 @@ use ldp::traverse::Traverse; use ldp::{RdfSource, RdfSourceUpdateResponse, ResourceRequestBuilder, SerializationOptions}; use oxigraph::io::RdfFormat; use oxigraph::model::vocab::{rdf, rdfs}; -use oxigraph::model::{BaseDirection, Dataset, NamedNode, NamedNodeRef, Quad, Term, TermRef}; -use tracing::{debug, error, info}; +use oxigraph::model::{BaseDirection, Dataset, NamedNode, Quad, Term, TermRef}; +use tracing::{debug, error, info, info_span, span, Level}; use crate::widget::iri_input::iri_input; #[derive(Debug, Clone)] @@ -95,40 +95,41 @@ pub(crate) struct Publisher { impl Publisher { pub(crate) fn new() -> (Self, Task) { - let ontology = Ontology::builder() - .with_path("/home/alex/.local/share/org.graphofliberty.desktop/ontology") - .build() - .expect("Failed to build ontology"); + let ontology = info_span!("Ontology Creation").in_scope(|| { + Ontology::builder() + .with_path("/home/alex/.local/share/org.graphofliberty.desktop/ontology") + .build() + .expect("Failed to build ontology") + }); - let mut index = SearchIndex::builder() - .with_path("/home/alex/Documents/Index") - .build() - .expect("Failed to build search index"); + let index = info_span!("Ontology Indexing").in_scope(|| { + let mut index = SearchIndex::builder() + //.with_path("/home/alex/.local/share/org.graphofliberty.desktop/index") + .build() + .expect("Failed to build search index"); - if let Some(id) = ontology.catalog_id(&rdf::PROPERTY.into_owned()) { index.remove_all_of_type(id); } - if let Some(id) = ontology.catalog_id(&rdfs::CLASS.into_owned()) { index.remove_all_of_type(id); } + if let Some(id) = ontology.catalog_id(&rdf::PROPERTY.into_owned()) { index.remove_all_of_type(id); } + if let Some(id) = ontology.catalog_id(&rdfs::CLASS.into_owned()) { index.remove_all_of_type(id); } - /*for (iri, info) in ontology.iri_info() { - if let Some(type_) = ontology.catalog_id(&info.type_) { + for (iri, entity) in ontology.entities() { let mut document = doc!( - Schema::type_field() => type_, + Schema::type_field() => entity.catalog_id, Schema::iri_field() => iri.as_str(), ); - if let Some(label) = &info.label && - let Some(field) = ontology.field_for_property(&rdfs::LABEL.into_owned()) { - document.add_text(Schema::field(&field.name), label); + if let Some(field) = ontology.field_for_property(&rdfs::LABEL.into_owned()) { + document.add_text(Schema::field(&field.name), &entity.label); } - if let Some(comment) = &info.comment && - let Some(field) = ontology.field_for_property(&rdfs::COMMENT.into_owned()) { - document.add_text(Schema::field(&field.name), comment); + if let Some(field) = ontology.field_for_property(&rdfs::COMMENT.into_owned()) { + document.add_text(Schema::field(&field.name), entity.comment.clone().unwrap_or(String::from(""))); } index.add(document).expect("Unable to add annotated IRI to search index"); } - } - index.commit().expect("Unable to commit ontology to index");*/ + index.commit().expect("Unable to commit ontology to index"); + index + }); let mut abbreviated_datatypes = ontology .datatypes() diff --git a/publish/src/error.rs b/publish/src/error.rs index 467be57..025aee7 100644 --- a/publish/src/error.rs +++ b/publish/src/error.rs @@ -21,4 +21,7 @@ pub(crate) enum Error { #[error(transparent)] Search(#[from] gl_search::SearchError), + + #[error(transparent)] + QueryEvaluation(#[from] oxigraph::sparql::QueryEvaluationError), } diff --git a/publish/src/main.rs b/publish/src/main.rs index 3aebe53..8c125d0 100644 --- a/publish/src/main.rs +++ b/publish/src/main.rs @@ -4,16 +4,16 @@ mod rdf; mod windows; mod widget; -use iced::Program; use crate::app::Publisher; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{EnvFilter, fmt}; +use tracing_subscriber::fmt::format::FmtSpan; fn main() -> color_eyre::Result<()> { let appender = tracing_appender::rolling::never("/tmp", "publisher-log"); tracing_subscriber::registry() - .with(fmt::layer().with_writer(appender)) + .with(fmt::layer().with_span_events(FmtSpan::CLOSE).with_writer(appender)) .with(EnvFilter::from_default_env()) .init(); color_eyre::install()?; diff --git a/publish/src/rdf/conversion.rs b/publish/src/rdf/conversion.rs index 5852d76..1949cb6 100644 --- a/publish/src/rdf/conversion.rs +++ b/publish/src/rdf/conversion.rs @@ -1,11 +1,12 @@ use oxigraph::model::{NamedNode, Quad, Term}; use oxigraph::model::vocab::{rdf, xsd}; +use tracing::info; -fn quad_to_term(quad: &Quad) -> &Term { +pub fn quad_to_term(quad: &Quad) -> &Term { &quad.object } -fn term_to_named_node(term: &Term) -> Option<&NamedNode> { +pub fn term_to_named_node(term: &Term) -> Option<&NamedNode> { if let Term::NamedNode(node) = term { Some(node) } else { @@ -13,7 +14,7 @@ fn term_to_named_node(term: &Term) -> Option<&NamedNode> { } } -fn term_to_string(term: &Term) -> Option<&str> { +pub fn term_to_string(term: &Term) -> Option<&str> { if let Term::Literal(literal) = term { match literal.datatype() { xsd::STRING | xsd::NORMALIZED_STRING | rdf::LANG_STRING | rdf::DIR_LANG_STRING => { @@ -26,7 +27,7 @@ fn term_to_string(term: &Term) -> Option<&str> { } } -fn term_to_boolean(term: &Term) -> Option { +pub fn term_to_boolean(term: &Term) -> Option { if let Term::Literal(literal) = term { if literal.datatype() == xsd::BOOLEAN { literal.value().parse().ok() @@ -38,9 +39,9 @@ fn term_to_boolean(term: &Term) -> Option { } } -fn term_to_u64(term: &Term) -> Option { +pub fn term_to_u64(term: &Term) -> Option { if let Term::Literal(literal) = term && - literal.datatype() == xsd::NON_NEGATIVE_INTEGER { + (literal.datatype() == xsd::NON_NEGATIVE_INTEGER || literal.datatype() == xsd::INTEGER) { let value: u64 = literal.value().parse().expect("Failed to parse u64 from ontology. It ought to be a non-negative integer."); Some(value) } else { None } diff --git a/publish/src/rdf/materialize.rs b/publish/src/rdf/materialize.rs index b755912..556b5a8 100644 --- a/publish/src/rdf/materialize.rs +++ b/publish/src/rdf/materialize.rs @@ -4,7 +4,7 @@ use oxigraph::store::Store; use crate::error; use crate::rdf::vocab::owl; -pub fn same_as(store: Store) -> error::Result { +pub fn same_as(store: &mut Store) -> error::Result<()> { let additional_quads = store .quads_for_pattern(None, Some(owl::SAME_AS), None, None) .filter_map(Result::ok) @@ -42,11 +42,11 @@ pub fn same_as(store: Store) -> error::Result { if new_size > old_size { same_as(store) } else { - Ok(store) + Ok(()) } } -pub fn super_classes(dataset: &mut Dataset) { +pub fn super_classes(store: &mut Store) -> error::Result<()> { let query = SparqlEvaluator::new() .parse_query( r#"PREFIX rdfs: @@ -61,7 +61,7 @@ CONSTRUCT { .expect("Unable to parse superclass query"); let mut additional_quads = Dataset::new(); - if let QueryResults::Graph(graph) = query.on_queryable_dataset(&*dataset).execute().unwrap() + if let QueryResults::Graph(graph) = query.on_store(&store).execute().unwrap() { additional_quads.extend(graph.filter_map(Result::ok).map(|triple| { Quad::new( @@ -73,12 +73,14 @@ CONSTRUCT { })); } - let old_size = dataset.len(); - dataset.extend(&additional_quads); - let new_size = dataset.len(); + let old_size = store.len()?; + store.extend(&additional_quads)?; + let new_size = store.len()?; if new_size > old_size { - super_classes(dataset) + super_classes(store) + } else { + Ok(()) } } diff --git a/publish/src/rdf/ontologies/ontology.ttl b/publish/src/rdf/ontologies/ontology.ttl index 08eedfc..faf93da 100644 --- a/publish/src/rdf/ontologies/ontology.ttl +++ b/publish/src/rdf/ontologies/ontology.ttl @@ -214,11 +214,15 @@ fedora:lastModifiedBy rdf:type owl:NamedIndividual ; ### http://www.w3.org/1999/02/22-rdf-syntax-ns#Property rdf:Property rdf:type owl:NamedIndividual ; + :associatedProperty :comment , + :label ; :catalogId "0"^^xsd:nonNegativeInteger . ### http://www.w3.org/2000/01/rdf-schema#Class rdfs:Class rdf:type owl:NamedIndividual ; + :associatedProperty :comment , + :label ; :catalogId "1"^^xsd:nonNegativeInteger . diff --git a/publish/src/rdf/ontology.rs b/publish/src/rdf/ontology.rs index c3b0bee..c1aeaa6 100644 --- a/publish/src/rdf/ontology.rs +++ b/publish/src/rdf/ontology.rs @@ -9,7 +9,8 @@ use std::fmt::Display; use std::path::{Path, PathBuf}; use std::sync::LazyLock; use oxigraph::store::Store; -use crate::rdf::materialize; +use tracing::{info, instrument}; +use crate::rdf::{conversion, materialize}; static PREFIXES: LazyLock> = LazyLock::new(|| { BTreeMap::from_iter([ @@ -57,7 +58,7 @@ impl OntologyBuilder { } pub fn build(self) -> error::Result { - let store = if let Some(path) = self.path { + let mut store = if let Some(path) = self.path { Store::open(path) } else { Store::new() @@ -68,41 +69,40 @@ impl OntologyBuilder { .map(|(k, v)| (k.to_string(), v.to_string())) .collect::>(); - let store = materialize::same_as(store)?; - //materialize::super_classes(&mut dataset); + materialize::same_as(&mut store)?; + materialize::super_classes(&mut store)?; + store.optimize()?; // Full-text search index field names - //let fields = Self::fields(&dataset); + let fields = Self::fields(&store)?; - /*let mut entities: HashMap = HashMap::new(); - let entity_iris = Self::subclass_of(&dataset, gl::ENTITY) - .chain(Self::subclass_of(&dataset, rda::ENTITY)) - .chain([ - rdf::PROPERTY.into_owned(), - rdfs::CLASS.into_owned(), - ]); - - for iri in entity_iris { - let subject = iri.as_ref().into(); - - let label = dataset.quads_for_pattern(Some(subject), Some(rdfs::LABEL), None, None) - .filter_map(|quad| term_to_string(&quad.object.into_owned()).map(String::from)) + let mut entities: HashMap = HashMap::new(); + // All Entities have exactly one catalog ID. + for quad in store.quads_for_pattern(None, Some(gl::CATALOG_ID), None, None) + .filter_map(Result::ok) { + let label = store.quads_for_pattern(Some(quad.subject.as_ref().into()), Some(rdfs::LABEL), None, None) + .filter_map(Result::ok) + .filter_map(|quad| conversion::term_to_string(&quad.object).map(String::from)) .next(); - let catalog_id = dataset.quads_for_pattern(Some(subject), Some(gl::CATALOG_ID), None, None) - .filter_map(|quad| term_to_u64(&quad.object.into_owned())) + let comment = store.quads_for_pattern(Some(quad.subject.as_ref().into()), Some(rdfs::COMMENT), None, None) + .filter_map(Result::ok) + .filter_map(|quad| conversion::term_to_string(&quad.object).map(String::from)) .next(); - if let Some(catalog_id) = catalog_id { + if let Some(catalog_id) = conversion::term_to_u64(&quad.object) && + let NamedOrBlankNode::NamedNode(subject) = quad.subject && + let Some(label) = label { let mut properties = HashSet::new(); - for quad in dataset.quads_for_pattern(Some(subject), Some(gl::ASSOCIATED_PROPERTY), None, None) { - if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject - && let TermRef::NamedNode(property) = quad.object { - properties.insert(property.into_owned()); + for quad in store.quads_for_pattern(Some(subject.as_ref().into()), Some(gl::ASSOCIATED_PROPERTY), None, None) + .filter_map(Result::ok) { + if let Term::NamedNode(property) = quad.object { + properties.insert(property); } } - entities.insert(iri, Entity { - label: label.unwrap_or(catalog_id.to_string()), + entities.insert(subject, Entity { + label, + comment, catalog_id, properties, }); @@ -110,28 +110,25 @@ impl OntologyBuilder { } let mut indexed_by = HashMap::new(); - for quad in dataset.quads_for_pattern(None, Some(gl::INDEXED_BY_FIELD), None, None) { - if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject - && let TermRef::NamedNode(field) = quad.object + for quad in store.quads_for_pattern(None, Some(gl::INDEXED_BY_FIELD), None, None) + .filter_map(Result::ok) { + if let NamedOrBlankNode::NamedNode(subject) = quad.subject + && let Term::NamedNode(field) = quad.object { - indexed_by.insert(subject.into_owned(), field.into_owned()); + indexed_by.insert(subject, field); } - }*/ + } Ok(Ontology { store, prefixes, - fields: HashMap::new(), - entities: HashMap::from_iter([(rdf::PROPERTY.into_owned(), Entity { - label: "property".to_string(), - catalog_id: 0, - properties: HashSet::new(), - })]), - indexed_by: HashMap::new(), + fields, + entities, + indexed_by, }) } - /*fn fields(dataset: &Dataset) -> HashMap { + fn fields(store: &Store) -> error::Result> { let query = SparqlEvaluator::new() .parse_query( r#"PREFIX rdfs: @@ -147,13 +144,12 @@ SELECT DISTINCT ?subject ?name ?label { .expect("Unable to parse field query"); let mut results = HashMap::new(); - if let QueryResults::Solutions(solutions) = - query.on_queryable_dataset(dataset).execute().unwrap() + if let QueryResults::Solutions(solutions) = query.on_store(store).execute()? { for solution in solutions.filter_map(Result::ok) { - let subject = solution.get("subject").and_then(term_to_named_node); - let name = solution.get("name").and_then(term_to_string); - let label = solution.get("label").and_then(term_to_string); + let subject = solution.get("subject").and_then(conversion::term_to_named_node); + let name = solution.get("name").and_then(conversion::term_to_string); + let label = solution.get("label").and_then(conversion::term_to_string); if let Some(subject) = subject && let Some(name) = name { let field = IndexField { @@ -164,10 +160,10 @@ SELECT DISTINCT ?subject ?name ?label { } } } - results + Ok(results) } - fn subclass_of(dataset: &Dataset, class: NamedNodeRef<'_>) -> impl Iterator { + /*fn subclass_of(dataset: &Dataset, class: NamedNodeRef<'_>) -> impl Iterator { let query = SparqlEvaluator::new() .parse_query( format!( @@ -200,6 +196,7 @@ SELECT ?class {{ pub struct LabeledIri { pub iri: NamedNode, pub label: String, + pub comment: Option, } impl PartialEq for LabeledIri { @@ -225,6 +222,7 @@ pub struct IriInformation { #[derive(Clone, Debug)] pub struct Entity { pub label: String, + pub comment: Option, pub catalog_id: u64, pub properties: HashSet, } @@ -263,11 +261,6 @@ impl Ontology { &*PREFIXES } - /*pub fn info(&self, node: NamedNodeRef<'_>) -> Option<&IriInformation> { - let node = node.into_owned(); - self.iri_info.get(&node) - }*/ - pub fn abbreviate(&self, node: NamedNodeRef<'_>) -> String { for (prefix_name, prefix_iri) in &self.prefixes { if let Some(local_name) = node.as_str().strip_prefix(prefix_iri) { @@ -314,6 +307,7 @@ impl Ontology { .map(|entity| LabeledIri { iri: class.to_owned(), label: entity.label.to_owned(), + comment: entity.comment.to_owned(), }) } @@ -322,9 +316,14 @@ impl Ontology { .map(|(iri, entity)| LabeledIri { iri: iri.to_owned(), label: entity.label.to_owned(), + comment: entity.comment.to_owned(), }) } + pub fn entities(&self) -> impl Iterator { + self.entities.iter() + } + pub fn datatypes(&self) -> impl Iterator { self.store .quads_for_pattern( diff --git a/search/src/error.rs b/search/src/error.rs index 3ee6735..a1713c9 100644 --- a/search/src/error.rs +++ b/search/src/error.rs @@ -11,7 +11,4 @@ pub enum SearchError { #[error(transparent)] OpenDirectoryError(#[from] tantivy::directory::error::OpenDirectoryError), - - #[error("Path to index not specified")] - IndexPathNotSpecified, } diff --git a/search/src/index.rs b/search/src/index.rs index 2e9f2ec..17f8d31 100644 --- a/search/src/index.rs +++ b/search/src/index.rs @@ -21,37 +21,38 @@ impl SearchIndexBuilder { } pub fn build(self) -> error::Result { - if let Some(path) = self.path { - let ngram_32 = NgramTokenizer::new(1, 32, false)?; - let ngram_32_lowercase = TextAnalyzer::builder(ngram_32) - .filter(LowerCaser) - .build(); + let ngram_32 = NgramTokenizer::new(1, 32, false)?; + let ngram_32_lowercase = TextAnalyzer::builder(ngram_32) + .filter(LowerCaser) + .build(); - let tokenizer_manager = TokenizerManager::default(); - tokenizer_manager.register("ngram_32", ngram_32_lowercase); + let tokenizer_manager = TokenizerManager::default(); + tokenizer_manager.register("ngram_32", ngram_32_lowercase); + let builder = Index::builder() + .schema(Schema::schema().clone()) + .tokenizers(tokenizer_manager); + + let index = if let Some(path) = self.path { let mmap_directory = MmapDirectory::open(path)?; let managed_directory = ManagedDirectory::wrap(Box::new(mmap_directory))?; - let index = Index::builder() - .schema(Schema::schema().clone()) - .tokenizers(tokenizer_manager) - .open_or_create(managed_directory)?; - - let reader = index - .reader_builder() - .reload_policy(ReloadPolicy::OnCommitWithDelay) - .try_into()?; - - let writer = index.writer(50_000_000)?; - - Ok(SearchIndex { - index, - reader, - writer, - }) + builder.open_or_create(managed_directory)? } else { - Err(SearchError::IndexPathNotSpecified) - } + builder.create_in_ram()? + }; + + let reader = index + .reader_builder() + .reload_policy(ReloadPolicy::OnCommitWithDelay) + .try_into()?; + + let writer = index.writer(50_000_000)?; + + Ok(SearchIndex { + index, + reader, + writer, + }) } }