.
This commit is contained in:
+23
-39
@@ -149,34 +149,10 @@ SELECT DISTINCT ?subject ?label ?comment ?read_only {{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn memoize(ontology: &mut Ontology) {
|
fn memoize(ontology: &mut Ontology) {
|
||||||
/*// Read-only properties
|
|
||||||
for quad in ontology.dataset.quads_for_pattern(
|
|
||||||
None,
|
|
||||||
Some(rdf::TYPE),
|
|
||||||
Some(TermRef::NamedNode(GL_READ_ONLY)),
|
|
||||||
None,
|
|
||||||
) {
|
|
||||||
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject {
|
|
||||||
ontology.read_only_properties.insert(subject.into_owned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read-only classes
|
|
||||||
for quad in ontology.dataset.quads_for_pattern(
|
|
||||||
None,
|
|
||||||
Some(rdfs::SUB_CLASS_OF),
|
|
||||||
Some(TermRef::NamedNode(GL_READ_ONLY)),
|
|
||||||
None,
|
|
||||||
) {
|
|
||||||
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject {
|
|
||||||
ontology.read_only_classes.insert(subject.into_owned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Full-text search index field names
|
// Full-text search index field names
|
||||||
for quad in ontology
|
for quad in ontology
|
||||||
.dataset
|
.dataset
|
||||||
.quads_for_pattern(None, Some(GL_INDEXED_BY_FIELD), None, None)
|
.quads_for_pattern(None, Some(gl::INDEXED_BY_FIELD), None, None)
|
||||||
{
|
{
|
||||||
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject
|
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject
|
||||||
&& let TermRef::Literal(literal) = quad.object
|
&& let TermRef::Literal(literal) = quad.object
|
||||||
@@ -190,7 +166,7 @@ SELECT DISTINCT ?subject ?label ?comment ?read_only {{
|
|||||||
// Catalog IDs (used to quickly filter full-text search results)
|
// Catalog IDs (used to quickly filter full-text search results)
|
||||||
for quad in ontology
|
for quad in ontology
|
||||||
.dataset
|
.dataset
|
||||||
.quads_for_pattern(None, Some(GL_CATALOG_ID), None, None)
|
.quads_for_pattern(None, Some(gl::CATALOG_ID), None, None)
|
||||||
{
|
{
|
||||||
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject
|
if let NamedOrBlankNodeRef::NamedNode(subject) = quad.subject
|
||||||
&& let TermRef::Literal(literal) = quad.object
|
&& let TermRef::Literal(literal) = quad.object
|
||||||
@@ -200,7 +176,7 @@ SELECT DISTINCT ?subject ?label ?comment ?read_only {{
|
|||||||
ontology.catalog_ids.insert(subject.into_owned(), value);
|
ontology.catalog_ids.insert(subject.into_owned(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(&mut self) -> error::Result<Ontology> {
|
pub fn build(&mut self) -> error::Result<Ontology> {
|
||||||
@@ -237,8 +213,6 @@ SELECT DISTINCT ?subject ?label ?comment ?read_only {{
|
|||||||
prefixes,
|
prefixes,
|
||||||
properties,
|
properties,
|
||||||
classes,
|
classes,
|
||||||
read_only_properties: HashSet::new(),
|
|
||||||
read_only_classes: HashSet::new(),
|
|
||||||
field_map: HashMap::new(),
|
field_map: HashMap::new(),
|
||||||
catalog_ids: HashMap::new(),
|
catalog_ids: HashMap::new(),
|
||||||
};
|
};
|
||||||
@@ -248,7 +222,7 @@ SELECT DISTINCT ?subject ?label ?comment ?read_only {{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct IriInformation {
|
struct IriInformation {
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
comment: Option<String>,
|
comment: Option<String>,
|
||||||
@@ -260,8 +234,6 @@ pub struct Ontology {
|
|||||||
prefixes: HashMap<String, String>,
|
prefixes: HashMap<String, String>,
|
||||||
properties: HashMap<NamedNode, IriInformation>,
|
properties: HashMap<NamedNode, IriInformation>,
|
||||||
classes: HashMap<NamedNode, IriInformation>,
|
classes: HashMap<NamedNode, IriInformation>,
|
||||||
read_only_properties: HashSet<NamedNode>,
|
|
||||||
read_only_classes: HashSet<NamedNode>,
|
|
||||||
field_map: HashMap<NamedNode, String>,
|
field_map: HashMap<NamedNode, String>,
|
||||||
catalog_ids: HashMap<NamedNode, u64>,
|
catalog_ids: HashMap<NamedNode, u64>,
|
||||||
}
|
}
|
||||||
@@ -394,24 +366,36 @@ SELECT ?subject ?label ?comment WHERE {
|
|||||||
pub fn is_read_only<'a>(&self, triple: impl Into<TripleRef<'a>>) -> bool {
|
pub fn is_read_only<'a>(&self, triple: impl Into<TripleRef<'a>>) -> bool {
|
||||||
let triple = triple.into();
|
let triple = triple.into();
|
||||||
let read_only_property = self
|
let read_only_property = self
|
||||||
.read_only_properties
|
.properties
|
||||||
.contains(&triple.predicate.into_owned());
|
.get(&triple.predicate.into_owned())
|
||||||
|
.map(|info| info.read_only)
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
let read_only_class = match (triple.predicate, triple.object) {
|
let read_only_class = match (triple.predicate, triple.object) {
|
||||||
(rdf::TYPE, TermRef::NamedNode(node)) => {
|
(rdf::TYPE, TermRef::NamedNode(node)) => {
|
||||||
self.read_only_classes.contains(&node.into_owned())
|
self.classes
|
||||||
|
.get(&node.into_owned())
|
||||||
|
.map(|info| info.read_only)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
read_only_property || read_only_class
|
read_only_property || read_only_class
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exclude_read_only_predicate(&self) -> impl Fn(TripleRef<'_>) -> bool + 'static {
|
pub fn exclude_read_only_predicate(&self) -> impl Fn(TripleRef<'_>) -> bool + 'static {
|
||||||
let classes = self.read_only_classes.clone();
|
let classes = self.classes.clone();
|
||||||
let properties = self.read_only_properties.clone();
|
let properties = self.properties.clone();
|
||||||
move |triple| {
|
move |triple| {
|
||||||
let read_only_property = properties.contains(&triple.predicate.into_owned());
|
let read_only_property = properties.get(&triple.predicate.into_owned())
|
||||||
|
.map(|info| info.read_only)
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
let read_only_class = match (triple.predicate, triple.object) {
|
let read_only_class = match (triple.predicate, triple.object) {
|
||||||
(rdf::TYPE, TermRef::NamedNode(node)) => classes.contains(&node.into_owned()),
|
(rdf::TYPE, TermRef::NamedNode(node)) => classes.get(&node.into_owned())
|
||||||
|
.map(|info| info.read_only)
|
||||||
|
.unwrap_or(false),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
!(read_only_property || read_only_class)
|
!(read_only_property || read_only_class)
|
||||||
|
|||||||
Reference in New Issue
Block a user