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        commands.spawn(lov.clone());
19    }
20
21    for (i, (name, url)) in PREFIX_CC
22        .split('\n')
23        .flat_map(|x| {
24            let mut s = x.split(' ');
25            let first = s.next()?;
26            let second = s.next()?;
27            Some((first.to_string(), second.to_string()))
28        })
29        .enumerate()
30    {
31        let name: Cow<'static, str> = name.into();
32        if actual_local.contains(&name) {
33            continue;
34        }
35        let namespace: Cow<'static, str> = url.into();
36        let lov = PrefixEntry {
37            namespace,
38            name: name.clone(),
39            rank: i,
40        };
41
42        commands.spawn(lov);
43    }
44}
45
46#[derive(Debug, Clone, Component)]
47pub struct FromPrefix(pub Prefix);