Function bodies 69 total
new function · rust · L30-L39 (10 LOC)src/edge.rs
pub fn new(source: Uuid, target: Uuid, kind: EdgeKind, reason: String) -> Self {
Self {
id: Uuid::new_v4(),
source,
target,
kind,
reason,
created_at: Utc::now(),
}
}test_edge_creation function · rust · L47-L55 (9 LOC)src/edge.rs
fn test_edge_creation() {
let a = Uuid::new_v4();
let b = Uuid::new_v4();
let edge = Edge::new(a, b, EdgeKind::Reference, "공통 시그널 사용".into());
assert_eq!(edge.source, a);
assert_eq!(edge.target, b);
assert_eq!(edge.kind, EdgeKind::Reference);
assert_eq!(edge.reason, "공통 시그널 사용");
}test_edge_kinds function · rust · L58-L64 (7 LOC)src/edge.rs
fn test_edge_kinds() {
let a = Uuid::new_v4();
let b = Uuid::new_v4();
assert_eq!(Edge::new(a, b, EdgeKind::Superset, "r".into()).kind, EdgeKind::Superset);
assert_eq!(Edge::new(a, b, EdgeKind::Subset, "r".into()).kind, EdgeKind::Subset);
assert_eq!(Edge::new(a, b, EdgeKind::Orthogonal, "r".into()).kind, EdgeKind::Orthogonal);
}get_embedding function · rust · L7-L91 (85 LOC)src/embedding.rs
pub async fn get_embedding(text: &str) -> Result<Vec<f32>, Box<dyn std::error::Error + Send + Sync>> {
let api_key = std::env::var("OPENAI_API_KEY")
.map_err(|_| "OPENAI_API_KEY not set")?;
let client = reqwest::Client::new();
#[derive(Serialize)]
struct Req<'a> {
model: &'a str,
input: &'a str,
}
let resp = client
.post("https://api.openai.com/v1/embeddings")
.bearer_auth(&api_key)
.json(&Req { model: "text-embedding-3-small", input: text })
.send()
.await?;
if !resp.status().is_success() {
let status = resp.status();
let body = resp.text().await.unwrap_or_default();
return Err(format!("OpenAI API error {}: {}", status, body).into());
}
#[derive(Deserialize)]
struct EmbeddingData {
embedding: Vec<f32>,
}
#[derive(Deserialize)]
struct EmbeddingResp {
data: Vec<EmbeddingData>,
}
let parsed: EmbeddingResp = resp.json().acosine_similarity function · rust · L94-L110 (17 LOC)src/embedding.rs
pub fn cosine_similarity(a: &[f32], b: &[f32]) -> f64 {
if a.len() != b.len() || a.is_empty() {
return 0.0;
}
let mut dot = 0.0f64;
let mut mag_a = 0.0f64;
let mut mag_b = 0.0f64;
for i in 0..a.len() {
let ai = a[i] as f64;
let bi = b[i] as f64;
dot += ai * bi;
mag_a += ai * ai;
mag_b += bi * bi;
}
let denom = mag_a.sqrt() * mag_b.sqrt();
if denom == 0.0 { 0.0 } else { dot / denom }
}test_cosine_identical function · rust · L117-L121 (5 LOC)src/embedding.rs
fn test_cosine_identical() {
let v = vec![1.0, 0.0, 0.0];
let sim = cosine_similarity(&v, &v);
assert!((sim - 1.0).abs() < 1e-6);
}test_cosine_orthogonal function · rust · L124-L129 (6 LOC)src/embedding.rs
fn test_cosine_orthogonal() {
let a = vec![1.0, 0.0, 0.0];
let b = vec![0.0, 1.0, 0.0];
let sim = cosine_similarity(&a, &b);
assert!(sim.abs() < 1e-6);
}Powered by Repobility — scan your code at https://repobility.com
test_cosine_opposite function · rust · L132-L137 (6 LOC)src/embedding.rs
fn test_cosine_opposite() {
let a = vec![1.0, 0.0];
let b = vec![-1.0, 0.0];
let sim = cosine_similarity(&a, &b);
assert!((sim - (-1.0)).abs() < 1e-6);
}test_cosine_empty function · rust · L140-L143 (4 LOC)src/embedding.rs
fn test_cosine_empty() {
let sim = cosine_similarity(&[], &[]);
assert_eq!(sim, 0.0);
}test_cosine_different_lengths function · rust · L146-L151 (6 LOC)src/embedding.rs
fn test_cosine_different_lengths() {
let a = vec![1.0, 2.0];
let b = vec![1.0, 2.0, 3.0];
let sim = cosine_similarity(&a, &b);
assert_eq!(sim, 0.0);
}new function · rust · L25-L32 (8 LOC)src/graph.rs
pub fn new() -> Self {
Self {
nodes: HashMap::new(),
edges: HashMap::new(),
adjacency: HashMap::new(),
reverse_adj: HashMap::new(),
}
}add_node function · rust · L35-L42 (8 LOC)src/graph.rs
pub fn add_node(&mut self, node: Node) -> Uuid {
let id = node.id;
self.nodes.insert(id, node);
self.adjacency.entry(id).or_default();
self.reverse_adj.entry(id).or_default();
id
}get_node function · rust · L43-L46 (4 LOC)src/graph.rs
pub fn get_node(&self, id: &Uuid) -> Option<&Node> {
self.nodes.get(id)
}get_node_mut function · rust · L47-L50 (4 LOC)src/graph.rs
pub fn get_node_mut(&mut self, id: &Uuid) -> Option<&mut Node> {
self.nodes.get_mut(id)
}remove_node function · rust · L51-L71 (21 LOC)src/graph.rs
pub fn remove_node(&mut self, id: &Uuid) -> Option<Node> {
// Collect edge IDs to remove
let mut edge_ids = Vec::new();
if let Some(out_edges) = self.adjacency.get(id) {
edge_ids.extend(out_edges.iter());
}
if let Some(in_edges) = self.reverse_adj.get(id) {
edge_ids.extend(in_edges.iter());
}
let edge_ids: Vec<Uuid> = edge_ids.into_iter().copied().collect();
// Remove edges
for eid in edge_ids {
self.remove_edge(&eid);
}
self.adjacency.remove(id);
self.reverse_adj.remove(id);
self.nodes.remove(id)
}Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
nodes_by_status function · rust · L72-L75 (4 LOC)src/graph.rs
pub fn nodes_by_status(&self, status: NodeStatus) -> Vec<&Node> {
self.nodes.values().filter(|n| n.status == status).collect()
}node_count function · rust · L76-L79 (4 LOC)src/graph.rs
pub fn node_count(&self) -> usize {
self.nodes.len()
}add_edge function · rust · L82-L89 (8 LOC)src/graph.rs
pub fn add_edge(&mut self, edge: Edge) -> Uuid {
let id = edge.id;
self.adjacency.entry(edge.source).or_default().push(id);
self.reverse_adj.entry(edge.target).or_default().push(id);
self.edges.insert(id, edge);
id
}get_edge function · rust · L90-L93 (4 LOC)src/graph.rs
pub fn get_edge(&self, id: &Uuid) -> Option<&Edge> {
self.edges.get(id)
}remove_edge function · rust · L94-L107 (14 LOC)src/graph.rs
pub fn remove_edge(&mut self, id: &Uuid) -> Option<Edge> {
if let Some(edge) = self.edges.remove(id) {
if let Some(adj) = self.adjacency.get_mut(&edge.source) {
adj.retain(|eid| eid != id);
}
if let Some(radj) = self.reverse_adj.get_mut(&edge.target) {
radj.retain(|eid| eid != id);
}
Some(edge)
} else {
None
}
}edge_count function · rust · L108-L111 (4 LOC)src/graph.rs
pub fn edge_count(&self) -> usize {
self.edges.len()
}neighbors function · rust · L116-L155 (40 LOC)src/graph.rs
pub fn neighbors(
&self,
node_id: &Uuid,
direction: Direction,
edge_filter: Option<&[EdgeKind]>,
) -> Vec<(Uuid, &Edge)> {
let mut result = Vec::new();
let check_filter = |edge: &Edge| -> bool {
edge_filter.map_or(true, |kinds| kinds.contains(&edge.kind))
};
// Outgoing
if matches!(direction, Direction::Out | Direction::Both) {
if let Some(edge_ids) = self.adjacency.get(node_id) {
for eid in edge_ids {
if let Some(edge) = self.edges.get(eid) {
if check_filter(edge) {
result.push((edge.target, edge));
}
}
}
}
}
// Incoming
if matches!(direction, Direction::In | Direction::Both) {
if let Some(edge_ids) = self.reverse_adj.get(node_id) {
for eid in edge_ids {
walk function · rust · L159-L187 (29 LOC)src/graph.rs
pub fn walk(
&self,
start: &Uuid,
max_hops: usize,
edge_filter: Option<&[EdgeKind]>,
) -> Vec<(Uuid, usize)> {
let mut visited = HashSet::new();
let mut queue = VecDeque::new();
let mut result = Vec::new();
visited.insert(*start);
queue.push_back((*start, 0usize));
while let Some((node_id, depth)) = queue.pop_front() {
result.push((node_id, depth));
if depth >= max_hops {
continue;
}
for (neighbor_id, _edge) in self.neighbors(&node_id, Direction::Both, edge_filter) {
if visited.insert(neighbor_id) {
queue.push_back((neighbor_id, depth + 1));
}
}
}
result
}Repobility · code-quality intelligence · https://repobility.com
walk_exclude_orthogonal function · rust · L190-L196 (7 LOC)src/graph.rs
pub fn walk_exclude_orthogonal(
&self,
start: &Uuid,
max_hops: usize,
) -> Vec<(Uuid, usize)> {
self.walk(start, max_hops, Some(&[EdgeKind::Reference, EdgeKind::Superset, EdgeKind::Subset]))
}subgraph function · rust · L199-L206 (8 LOC)src/graph.rs
pub fn subgraph(&self, node_ids: &[Uuid]) -> (Vec<&Node>, Vec<&Edge>) {
let id_set: HashSet<&Uuid> = node_ids.iter().collect();
let nodes: Vec<&Node> = node_ids.iter().filter_map(|id| self.nodes.get(id)).collect();
let edges: Vec<&Edge> = self.edges.values()
.filter(|e| id_set.contains(&e.source) && id_set.contains(&e.target))
.collect();
(nodes, edges)
}summary function · rust · L209-L228 (20 LOC)src/graph.rs
pub fn summary(&self) -> GraphSummary {
let mut status_counts = HashMap::new();
let mut total_experiments = 0usize;
for node in self.nodes.values() {
*status_counts.entry(format!("{:?}", node.status)).or_insert(0usize) += 1;
total_experiments += node.experiments.len();
}
let mut edge_counts = HashMap::new();
for edge in self.edges.values() {
*edge_counts.entry(format!("{:?}", edge.kind)).or_insert(0usize) += 1;
}
GraphSummary {
n_nodes: self.nodes.len(),
n_edges: self.edges.len(),
n_experiments: total_experiments,
status_counts,
edge_kinds: edge_counts,
}
}default function · rust · L232-L234 (3 LOC)src/graph.rs
fn default() -> Self {
Self::new()
}make_hypothesis function · rust · L250-L253 (4 LOC)src/graph.rs
fn make_hypothesis(statement: &str) -> Node {
Node::new(statement.into())
}test_add_and_get function · rust · L256-L262 (7 LOC)src/graph.rs
fn test_add_and_get() {
let mut g = AmureGraph::new();
let node = make_hypothesis("OI는 momentum 선행지표");
let id = g.add_node(node);
assert!(g.get_node(&id).is_some());
assert_eq!(g.node_count(), 1);
}test_remove_node_cascades_edges function · rust · L265-L275 (11 LOC)src/graph.rs
fn test_remove_node_cascades_edges() {
let mut g = AmureGraph::new();
let c = g.add_node(make_hypothesis("hypothesis 1"));
let r = g.add_node(make_hypothesis("hypothesis 2"));
g.add_edge(Edge::new(r, c, EdgeKind::Reference, "관련".into()));
assert_eq!(g.edge_count(), 1);
g.remove_node(&c);
assert_eq!(g.node_count(), 1);
assert_eq!(g.edge_count(), 0);
}test_neighbors function · rust · L278-L293 (16 LOC)src/graph.rs
fn test_neighbors() {
let mut g = AmureGraph::new();
let c = g.add_node(make_hypothesis("hypothesis 1"));
let r1 = g.add_node(make_hypothesis("hypothesis 2"));
let r2 = g.add_node(make_hypothesis("hypothesis 3"));
g.add_edge(Edge::new(r1, c, EdgeKind::Reference, "ref".into()));
g.add_edge(Edge::new(r2, c, EdgeKind::Superset, "sup".into()));
// Incoming to c
let neighbors = g.neighbors(&c, Direction::In, None);
assert_eq!(neighbors.len(), 2);
// Filter Reference only
let ref_only = g.neighbors(&c, Direction::In, Some(&[EdgeKind::Reference]));
assert_eq!(ref_only.len(), 1);
}Repobility's GitHub App fixes findings like these · https://github.com/apps/repobility-bot
test_walk_bfs function · rust · L296-L311 (16 LOC)src/graph.rs
fn test_walk_bfs() {
let mut g = AmureGraph::new();
let a = g.add_node(make_hypothesis("h1"));
let b = g.add_node(make_hypothesis("h2"));
let c = g.add_node(make_hypothesis("h3"));
g.add_edge(Edge::new(b, a, EdgeKind::Reference, "r".into()));
g.add_edge(Edge::new(c, b, EdgeKind::Subset, "s".into()));
// Walk from a, 2 hops
let walked = g.walk(&a, 2, None);
assert_eq!(walked.len(), 3);
// Walk from a, 1 hop
let walked_1 = g.walk(&a, 1, None);
assert_eq!(walked_1.len(), 2);
}test_walk_exclude_orthogonal function · rust · L314-L329 (16 LOC)src/graph.rs
fn test_walk_exclude_orthogonal() {
let mut g = AmureGraph::new();
let a = g.add_node(make_hypothesis("h1"));
let b = g.add_node(make_hypothesis("h2"));
let c = g.add_node(make_hypothesis("h3"));
g.add_edge(Edge::new(b, a, EdgeKind::Reference, "r".into()));
g.add_edge(Edge::new(c, a, EdgeKind::Orthogonal, "o".into()));
// Walk excluding orthogonal — should NOT reach c
let walked = g.walk_exclude_orthogonal(&a, 2);
assert_eq!(walked.len(), 2); // a + b only
// Walk including all — should reach c
let walked_all = g.walk(&a, 2, None);
assert_eq!(walked_all.len(), 3); // a + b + c
}test_subgraph function · rust · L332-L346 (15 LOC)src/graph.rs
fn test_subgraph() {
let mut g = AmureGraph::new();
let a = g.add_node(make_hypothesis("h1"));
let b = g.add_node(make_hypothesis("h2"));
let c = g.add_node(make_hypothesis("h3"));
g.add_edge(Edge::new(b, a, EdgeKind::Reference, "r".into()));
let (nodes, edges) = g.subgraph(&[a, b]);
assert_eq!(nodes.len(), 2);
assert_eq!(edges.len(), 1);
// c is not in subgraph
let (nodes2, _) = g.subgraph(&[a, c]);
assert_eq!(nodes2.len(), 2);
}test_summary function · rust · L349-L358 (10 LOC)src/graph.rs
fn test_summary() {
let mut g = AmureGraph::new();
g.add_node(make_hypothesis("h1"));
let mut h2 = make_hypothesis("h2");
h2.status = NodeStatus::Decline;
g.add_node(h2);
let s = g.summary();
assert_eq!(s.n_nodes, 2);
assert_eq!(s.n_experiments, 0);
}test_summary_counts_experiments function · rust · L361-L375 (15 LOC)src/graph.rs
fn test_summary_counts_experiments() {
let mut g = AmureGraph::new();
let mut h = make_hypothesis("h1");
h.experiments.push(crate::node::Experiment {
id: uuid::Uuid::new_v4(),
kind: crate::node::ExperimentKind::Universe,
target: "BTC".into(),
result: serde_json::json!({}),
verdict: crate::node::Verdict::Support,
note: None,
});
g.add_node(h);
let s = g.summary();
assert_eq!(s.n_experiments, 1);
}new function · rust · L62-L76 (15 LOC)src/node.rs
pub fn new(statement: String) -> Self {
let now = Utc::now();
Self {
id: Uuid::new_v4(),
kind: NodeKind::Hypothesis,
statement,
abstract_: String::new(),
discussion: String::new(),
status: NodeStatus::Draft,
experiments: Vec::new(),
embedding: None,
created_at: now,
updated_at: now,
}
}embed_text function · rust · L79-L85 (7 LOC)src/node.rs
pub fn embed_text(&self) -> String {
if self.abstract_.is_empty() {
self.statement.clone()
} else {
format!("{} {}", self.statement, self.abstract_)
}
}tokens function · rust · L88-L91 (4 LOC)src/node.rs
pub fn tokens(&self) -> Vec<String> {
let text = format!("{} {} {}", self.statement, self.abstract_, self.discussion);
tokenize(&text)
}Powered by Repobility — scan your code at https://repobility.com
tokenize function · rust · L95-L126 (32 LOC)src/node.rs
pub fn tokenize(text: &str) -> Vec<String> {
let lower = text.to_lowercase();
let mut tokens = Vec::new();
let mut current = String::new();
let is_korean = |c: char| ('\u{AC00}'..='\u{D7A3}').contains(&c);
let is_word = |c: char| c.is_ascii_alphanumeric() || c == '_' || c == '-';
for ch in lower.chars() {
if is_word(ch) || is_korean(ch) {
if !current.is_empty() {
let last = current.chars().last().unwrap();
if (is_korean(last) && is_word(ch)) || (is_word(last) && is_korean(ch)) {
if current.len() >= 2 {
tokens.push(current.clone());
}
current.clear();
}
}
current.push(ch);
} else {
if current.len() >= 2 {
tokens.push(current.clone());
}
current.clear();
}
}
if current.len() >= 2 {
tokens.push(current);
test_node_creation function · rust · L133-L139 (7 LOC)src/node.rs
fn test_node_creation() {
let node = Node::new("OI는 momentum의 선행지표다".into());
assert_eq!(node.kind, NodeKind::Hypothesis);
assert_eq!(node.status, NodeStatus::Draft);
assert!(node.abstract_.is_empty());
assert!(node.experiments.is_empty());
}test_node_status function · rust · L142-L148 (7 LOC)src/node.rs
fn test_node_status() {
let mut node = Node::new("test".into());
node.status = NodeStatus::Accept;
assert_eq!(node.status, NodeStatus::Accept);
node.status = NodeStatus::Decline;
assert_eq!(node.status, NodeStatus::Decline);
}test_embed_text function · rust · L151-L156 (6 LOC)src/node.rs
fn test_embed_text() {
let mut node = Node::new("statement".into());
assert_eq!(node.embed_text(), "statement");
node.abstract_ = "abstract summary".into();
assert_eq!(node.embed_text(), "statement abstract summary");
}test_experiment function · rust · L159-L170 (12 LOC)src/node.rs
fn test_experiment() {
let exp = Experiment {
id: Uuid::new_v4(),
kind: ExperimentKind::Universe,
target: "BTC,ETH".into(),
result: serde_json::json!({"IR": 0.5, "t_stat": 2.1}),
verdict: Verdict::Support,
note: Some("좋은 결과".into()),
};
assert_eq!(exp.kind, ExperimentKind::Universe);
assert_eq!(exp.verdict, Verdict::Support);
}test_tokenize function · rust · L173-L178 (6 LOC)src/node.rs
fn test_tokenize() {
let tokens = tokenize("OI momentum은 크립토에서 continuation alpha가 있다");
assert!(tokens.contains(&"momentum".to_string()));
assert!(tokens.contains(&"continuation".to_string()));
assert!(tokens.contains(&"alpha".to_string()));
}test_tokenize_underscore function · rust · L181-L185 (5 LOC)src/node.rs
fn test_tokenize_underscore() {
let tokens = tokenize("open_interest cross_sectional");
assert!(tokens.contains(&"open_interest".to_string()));
assert!(tokens.contains(&"cross_sectional".to_string()));
}save function · rust · L11-L30 (20 LOC)src/persistence.rs
pub fn save(&self, dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
std::fs::create_dir_all(dir)?;
let nodes: Vec<&Node> = self.nodes.values().collect();
let edges: Vec<&Edge> = self.edges.values().collect();
// Write to tmp then rename (atomic)
let nodes_tmp = dir.join("nodes.json.tmp");
let edges_tmp = dir.join("edges.json.tmp");
let nodes_path = dir.join("nodes.json");
let edges_path = dir.join("edges.json");
std::fs::write(&nodes_tmp, serde_json::to_string_pretty(&nodes)?)?;
std::fs::write(&edges_tmp, serde_json::to_string_pretty(&edges)?)?;
std::fs::rename(&nodes_tmp, &nodes_path)?;
std::fs::rename(&edges_tmp, &edges_path)?;
Ok(())
}Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
load function · rust · L33-L56 (24 LOC)src/persistence.rs
pub fn load(dir: &Path) -> Result<Self, Box<dyn std::error::Error>> {
let mut graph = Self::new();
let nodes_path = dir.join("nodes.json");
let edges_path = dir.join("edges.json");
if nodes_path.exists() {
let content = std::fs::read_to_string(&nodes_path)?;
let nodes: Vec<Node> = serde_json::from_str(&content)?;
for node in nodes {
graph.add_node(node);
}
}
if edges_path.exists() {
let content = std::fs::read_to_string(&edges_path)?;
let edges: Vec<Edge> = serde_json::from_str(&content)?;
for edge in edges {
graph.add_edge(edge);
}
}
Ok(graph)
}test_save_load_roundtrip function · rust · L66-L96 (31 LOC)src/persistence.rs
fn test_save_load_roundtrip() {
let dir = tempfile::tempdir().unwrap();
let mut g = AmureGraph::new();
let mut n1 = Node::new("test hypothesis".into());
n1.status = NodeStatus::Accept;
n1.abstract_ = "abstract text".into();
let id1 = n1.id;
let c = g.add_node(n1);
let mut n2 = Node::new("test hypothesis 2".into());
n2.status = NodeStatus::Decline;
let id2 = n2.id;
let r = g.add_node(n2);
g.add_edge(Edge::new(r, c, EdgeKind::Reference, "test reason".into()));
g.save(dir.path()).unwrap();
let g2 = AmureGraph::load(dir.path()).unwrap();
assert_eq!(g2.node_count(), 2);
assert_eq!(g2.edge_count(), 1);
assert!(g2.get_node(&id1).is_some());
assert_eq!(g2.get_node(&id1).unwrap().status, NodeStatus::Accept);
assert_eq!(g2.get_node(&id1).unwrap().abstract_, "abstract text");
assert_eq!(g2.get_node(&id2).unwrap().status, NodeStatutest_load_empty_dir function · rust · L99-L103 (5 LOC)src/persistence.rs
fn test_load_empty_dir() {
let dir = tempfile::tempdir().unwrap();
let g = AmureGraph::load(dir.path()).unwrap();
assert_eq!(g.node_count(), 0);
}page 1 / 2next ›