use crate::memory::identity::{
ALIASES_FIELD, ALIAS_KEYS_FIELD, SAME_AS_EDGE, SAME_AS_FLOOR, SAME_AS_WEIGHT,
};
use crate::schema::Schema;
use core_rules::{Predicate, RuleDef};
pub const MEMORY_ENTITY_LABELS: &[&str] = &["Person", "Org", "Project", "Concept", "Event"];
pub const PROVISIONAL_LABEL: &str = "Entity";
pub const PROVISIONAL_PROP: &str = "provisional";
pub const NAME_FIELD: &str = "name";
pub fn memory_defaults() -> Schema {
let mut fulltext: Vec<(String, String)> = MEMORY_ENTITY_LABELS
.iter()
.map(|l| ((*l).to_string(), NAME_FIELD.to_string()))
.collect();
fulltext.push(("Note".to_string(), "text".to_string()));
fulltext.push(("Concept".to_string(), "summary".to_string()));
fulltext.push((PROVISIONAL_LABEL.to_string(), NAME_FIELD.to_string()));
let indexes: Vec<(String, String)> = MEMORY_ENTITY_LABELS
.iter()
.map(|l| ((*l).to_string(), NAME_FIELD.to_string()))
.collect();
Schema {
fulltext,
indexes,
rules: Vec::new(),
views: Vec::new(),
roles: Vec::new(),
}
}
pub fn memory_identity() -> Schema {
let overlap = Predicate::Overlap {
field: ALIASES_FIELD.to_string(),
min: SAME_AS_FLOOR,
};
let claim = Predicate::KeyMatch {
field: ALIAS_KEYS_FIELD.to_string(),
};
let rule = |name: String, src: &str, dst: &str, predicate: &Predicate| RuleDef {
name,
src_label: src.to_string(),
dst_label: dst.to_string(),
predicate: predicate.clone(),
edge_type: SAME_AS_EDGE.to_string(),
weight_prop: Some(SAME_AS_WEIGHT.to_string()),
max_edges: Some(core_rules::default_max_edges(predicate)),
approximate: false,
via_label: None,
via_edge: None,
via_dir: None,
namespace: None,
};
let mut rules: Vec<RuleDef> = MEMORY_ENTITY_LABELS
.iter()
.chain(std::iter::once(&PROVISIONAL_LABEL))
.map(|l| rule(format!("same_as_{}", l.to_lowercase()), l, l, &overlap))
.collect();
rules.extend(MEMORY_ENTITY_LABELS.iter().map(|l| {
rule(
format!("same_as_entity_{}", l.to_lowercase()),
PROVISIONAL_LABEL,
l,
&overlap,
)
}));
rules.extend(MEMORY_ENTITY_LABELS.iter().map(|l| {
rule(
format!("same_as_claim_{}", l.to_lowercase()),
l,
PROVISIONAL_LABEL,
&claim,
)
}));
Schema {
fulltext: Vec::new(),
indexes: Vec::new(),
rules,
views: Vec::new(),
roles: Vec::new(),
}
}