Skip to main content

swls_core/systems/lov/
setup.rs

1use std::{borrow::Cow, collections::HashSet};
2
3use bevy_ecs::prelude::*;
4
5use crate::{prelude::*, systems::prefix::PREFIX_CC};
6
7#[derive(Component, Debug)]
8pub struct PrefixEntry {
9    pub namespace: Cow<'static, str>,
10    pub name: Cow<'static, str>,
11    pub rank: usize,
12}
13
14pub fn populate_known_ontologies(mut commands: Commands) {
15    let mut actual_local = HashSet::new();
16    for lov in swls_lov::LOCAL_PREFIXES.iter() {
17        actual_local.insert(lov.name.clone());
18        // TODO:  I actually want to spawn the ontology fully
19        commands.spawn(lov.clone());
20    }
21
22    for (i, (name, url)) in PREFIX_CC
23        .split('\n')
24        .flat_map(|x| {
25            let mut s = x.split(' ');
26            let first = s.next()?;
27            let second = s.next()?;
28            Some((first.to_string(), second.to_string()))
29        })
30        .enumerate()
31    {
32        let name: Cow<'static, str> = name.into();
33        if actual_local.contains(&name) {
34            continue;
35        }
36        let namespace: Cow<'static, str> = url.into();
37        let lov = PrefixEntry {
38            namespace,
39            name: name.clone(),
40            rank: i,
41        };
42
43        commands.spawn(lov);
44    }
45}
46
47#[derive(Debug, Clone, Component)]
48pub struct FromPrefix(pub Prefix);