This commit is contained in:
Alex Wied
2026-06-30 19:25:15 -04:00
parent 5cea8e8307
commit 2a6e9432d9
21 changed files with 1039 additions and 235 deletions
+26 -20
View File
@@ -1,16 +1,16 @@
use crate::error;
use crate::rdf::vocab::{gl, owl, rda};
use oxigraph::io::{RdfFormat, RdfParser};
use crate::rdf::vocab::gl;
use oxigraph::model::vocab::{rdf, rdfs, xsd};
use oxigraph::model::{Dataset, GraphName, LiteralRef, NamedNode, NamedNodeRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, Term, TermRef, Triple, TripleRef};
use oxigraph::model::{LiteralRef, NamedNode, NamedNodeRef, NamedOrBlankNode, NamedOrBlankNodeRef, Term, TermRef, Triple, TripleRef};
use oxigraph::sparql::{QueryResults, SparqlEvaluator};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use oxigraph::store::Store;
use tracing::{info, instrument};
use tracing::debug_span;
use crate::rdf::{conversion, materialize};
use crate::rdf::conversion::LanguageCondition;
static PREFIXES: LazyLock<BTreeMap<String, String>> = LazyLock::new(|| {
BTreeMap::from_iter([
@@ -70,8 +70,9 @@ impl OntologyBuilder {
.collect::<HashMap<String, String>>();
materialize::same_as(&mut store)?;
materialize::super_properties(&mut store)?;
materialize::super_classes(&mut store)?;
store.optimize()?;
debug_span!("Optimize Ontology").in_scope(|| store.optimize())?;
// Full-text search index field names
let fields = Self::fields(&store)?;
@@ -82,12 +83,16 @@ impl OntologyBuilder {
.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))
.map(conversion::quad_into_term)
.filter(|term| conversion::language_matches(term, &conversion::english()))
.filter_map(conversion::term_into_string)
.next();
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))
.map(conversion::quad_into_term)
.filter(|term| conversion::language_matches(term, &conversion::english()))
.filter_map(conversion::term_into_string)
.next();
if let Some(catalog_id) = conversion::term_to_u64(&quad.object) &&
@@ -130,28 +135,25 @@ impl OntologyBuilder {
fn fields(store: &Store) -> error::Result<HashMap<NamedNode, IndexField>> {
let query = SparqlEvaluator::new()
.with_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#")?
.with_prefix("gl", "https://graphofliberty.org/2026/04/ont/")?
.parse_query(
r#"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX gl: <https://graphofliberty.org/2026/04/ont/>
SELECT DISTINCT ?subject ?name ?label {
r#"SELECT DISTINCT ?subject ?name ?label {
GRAPH ?graph {
?subject a gl:IndexDocumentField ;
gl:fieldName ?name ;
gl:fieldLabel ?label .
FILTER (langMATCHES(LANG(?label), "en") || !hasLANG(?label))
}
}"#,
)
.expect("Unable to parse field query");
}"#)?;
let mut results = HashMap::new();
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(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);
let name = solution.get("name").and_then(conversion::term_as_str);
let label = solution.get("label").and_then(conversion::term_as_str);
if let Some(subject) = subject && let Some(name) = name {
let field = IndexField {
@@ -306,15 +308,19 @@ impl Ontology {
} else { None })
}
pub fn info(&self, iri: &NamedNode) -> LabeledIri {
pub fn info(&self, iri: &NamedNode, language: &LanguageCondition) -> LabeledIri {
let label = self.store.quads_for_pattern(Some(iri.as_ref().into()), Some(rdfs::LABEL), None, None)
.filter_map(Result::ok)
.filter_map(|quad| conversion::term_to_string(&quad.object).map(String::from))
.map(conversion::quad_into_term)
.filter(|term| conversion::language_matches(term, language))
.filter_map(conversion::term_into_string)
.next();
let comment = self.store.quads_for_pattern(Some(iri.as_ref().into()), Some(rdfs::COMMENT), None, None)
.filter_map(Result::ok)
.filter_map(|quad| conversion::term_to_string(&quad.object).map(String::from))
.map(conversion::quad_into_term)
.filter(|term| conversion::language_matches(term, language))
.filter_map(conversion::term_into_string)
.next();
LabeledIri {