.
This commit is contained in:
@@ -8,7 +8,6 @@ use oxigraph::model::{
|
||||
};
|
||||
use oxigraph::sparql::{QueryResults, SparqlEvaluator};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
|
||||
const PREFIXES: &[(&str, &str)] = &[
|
||||
("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
|
||||
@@ -170,14 +169,7 @@ SELECT DISTINCT ?class ?subject ?label ?comment ?read_only {
|
||||
query.on_queryable_dataset(dataset).execute().unwrap()
|
||||
{
|
||||
for solution in solutions.filter_map(Result::ok) {
|
||||
let resource_type = solution.get("class").and_then(term_to_named_node).and_then(
|
||||
|class| match class.as_ref() {
|
||||
rdf::PROPERTY => Some(ResourceType::Property),
|
||||
rdfs::CLASS => Some(ResourceType::Class),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
|
||||
let type_ = solution.get("class").and_then(term_to_named_node);
|
||||
let subject = solution.get("subject").and_then(term_to_named_node);
|
||||
let label = solution.get("label").and_then(term_to_string);
|
||||
let comment = solution.get("comment").and_then(term_to_string);
|
||||
@@ -186,11 +178,9 @@ SELECT DISTINCT ?class ?subject ?label ?comment ?read_only {
|
||||
.and_then(term_to_boolean)
|
||||
.unwrap_or(false);
|
||||
|
||||
if let Some(subject) = subject
|
||||
&& let Some(type_) = resource_type
|
||||
{
|
||||
if let Some(subject) = subject && let Some(type_) = type_ {
|
||||
let info = IriInformation {
|
||||
type_,
|
||||
type_: type_.clone(),
|
||||
label: label.map(String::from),
|
||||
comment: comment.map(String::from),
|
||||
read_only,
|
||||
@@ -253,25 +243,9 @@ SELECT DISTINCT ?class ?subject ?label ?comment ?read_only {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ResourceType {
|
||||
Property,
|
||||
Class,
|
||||
}
|
||||
|
||||
impl Display for ResourceType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = match self {
|
||||
ResourceType::Property => "Property".to_string(),
|
||||
ResourceType::Class => "Class".to_string(),
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IriInformation {
|
||||
pub type_: ResourceType,
|
||||
pub type_: NamedNode,
|
||||
pub label: Option<String>,
|
||||
pub comment: Option<String>,
|
||||
pub read_only: bool,
|
||||
@@ -358,38 +332,9 @@ impl Ontology {
|
||||
self.catalog_ids.get(class).copied()
|
||||
}
|
||||
|
||||
pub fn for_each_annotated_iri<F>(&self, f: F)
|
||||
where
|
||||
F: Fn(&str, Option<&str>, Option<&str>),
|
||||
pub fn iri_info(&self) -> &HashMap<NamedNode, IriInformation>
|
||||
{
|
||||
let query = SparqlEvaluator::new()
|
||||
.parse_query(
|
||||
r"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
|
||||
SELECT ?subject ?label ?comment WHERE {
|
||||
OPTIONAL {
|
||||
?subject rdfs:label ?label .
|
||||
FILTER (LANG(?label) = 'en' || LANG(?label) = '')
|
||||
}
|
||||
OPTIONAL {
|
||||
?subject rdfs:comment ?comment .
|
||||
FILTER (LANG(?comment) = 'en' || LANG(?comment) = '')
|
||||
}
|
||||
}",
|
||||
)
|
||||
.expect("Unable to parse annotation query");
|
||||
|
||||
if let QueryResults::Solutions(solutions) =
|
||||
query.on_queryable_dataset(&self.dataset).execute().unwrap()
|
||||
{
|
||||
for solution in solutions.filter_map(Result::ok) {
|
||||
let label = solution.get("label").and_then(term_to_string);
|
||||
let comment = solution.get("comment").and_then(term_to_string);
|
||||
if let Some(Term::NamedNode(subject)) = solution.get("subject") {
|
||||
f(subject.as_str(), label.as_deref(), comment.as_deref());
|
||||
}
|
||||
}
|
||||
}
|
||||
&self.iri_info
|
||||
}
|
||||
|
||||
pub fn datatypes(&self) -> impl Iterator<Item = NamedNodeRef<'_>> {
|
||||
|
||||
Reference in New Issue
Block a user