Skip to content

Commit bd36abc

Browse files
committed
Apply rustfmt formatting across src and browse.py
1 parent f3be793 commit bd36abc

6 files changed

Lines changed: 49 additions & 50 deletions

File tree

python/treesearch/browse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
Static,
1616
TextArea,
1717
)
18+
1819
if __name__ == "__main__":
1920
import sys, os
21+
2022
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
2123
import treesearch
2224
import asyncio

src/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use hashbrown::HashMap;
22
use hashbrown::hash_map::RawEntryMut;
3+
use parking_lot::Mutex;
34
use rustc_hash::{FxBuildHasher, FxHasher};
45
use std::hash::{Hash, Hasher};
56
use std::num::NonZeroU32;
6-
use parking_lot::Mutex;
77
use std::sync::Arc;
88

99
pub const STRING_POOL_CAPACITY: usize = 5000;

src/conllu.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use crate::bytes::{BytestringPool, bs_atoi, bs_split_once};
1010
use crate::tree::{Dep, Features, Misc, TokenId, Tree, WordId};
1111
use flate2::read::GzDecoder;
12-
use zstd::stream::read::Decoder as ZstdDecoder;
1312
use std::collections::HashMap;
1413
use std::fs::File;
1514
use std::io::{BufRead, BufReader, Read};
1615
use std::path::Path;
1716
use thiserror::Error;
17+
use zstd::stream::read::Decoder as ZstdDecoder;
1818

1919
/// Error during CoNLL-U parsing
2020
#[derive(Debug, Error)]
@@ -97,15 +97,15 @@ impl<R: BufRead> TreeIterator<R> {
9797
}
9898

9999
let token_id_field = &line[..tabs[0]];
100-
let form = &line[tabs[0] + 1..tabs[1]];
101-
let lemma = &line[tabs[1] + 1..tabs[2]];
102-
let upos = &line[tabs[2] + 1..tabs[3]];
103-
let xpos = &line[tabs[3] + 1..tabs[4]];
104-
let feats_field = &line[tabs[4] + 1..tabs[5]];
105-
let head_field = &line[tabs[5] + 1..tabs[6]];
106-
let deprel = &line[tabs[6] + 1..tabs[7]];
107-
let deps_field = &line[tabs[7] + 1..tabs[8]];
108-
let misc_field = &line[tabs[8] + 1..];
100+
let form = &line[tabs[0] + 1..tabs[1]];
101+
let lemma = &line[tabs[1] + 1..tabs[2]];
102+
let upos = &line[tabs[2] + 1..tabs[3]];
103+
let xpos = &line[tabs[3] + 1..tabs[4]];
104+
let feats_field = &line[tabs[4] + 1..tabs[5]];
105+
let head_field = &line[tabs[5] + 1..tabs[6]];
106+
let deprel = &line[tabs[6] + 1..tabs[7]];
107+
let deps_field = &line[tabs[7] + 1..tabs[8]];
108+
let misc_field = &line[tabs[8] + 1..];
109109

110110
// Skip multiword tokens (e.g., "1-2")
111111
if memchr::memchr(b'-', token_id_field).is_some() {
@@ -120,7 +120,9 @@ impl<R: BufRead> TreeIterator<R> {
120120
}
121121
let misc = self.parse_features(misc_field)?;
122122

123-
tree.add_word(word_id, token_id, form, lemma, upos, xpos, feats, head, deprel, misc);
123+
tree.add_word(
124+
word_id, token_id, form, lemma, upos, xpos, feats, head, deprel, misc,
125+
);
124126
Ok(())
125127
}
126128

src/pattern.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ impl BasePattern {
208208
self.add_var(&edge_constraint.from, Constraint::Any);
209209
if let Some(label) = &edge_constraint.label {
210210
if !edge_constraint.negated {
211-
self.add_var(
212-
&edge_constraint.to,
213-
Constraint::DepRel(label.clone()),
214-
);
211+
self.add_var(&edge_constraint.to, Constraint::DepRel(label.clone()));
215212
} else {
216213
self.add_var(&edge_constraint.to, Constraint::Any);
217214
}

src/query.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ mod tests {
370370
assert_eq!(edge_constraint.from, "Help");
371371
assert_eq!(edge_constraint.to, "To");
372372
assert_eq!(edge_constraint.relation, RelationType::Child);
373-
assert_eq!(edge_constraint.label, Some(ConstraintValue::Literal("xcomp".to_string())));
373+
assert_eq!(
374+
edge_constraint.label,
375+
Some(ConstraintValue::Literal("xcomp".to_string()))
376+
);
374377
}
375378

376379
#[test]
@@ -426,7 +429,10 @@ mod tests {
426429
assert_eq!(edge_constraint.from, "Help");
427430
assert_eq!(edge_constraint.to, "To");
428431
assert_eq!(edge_constraint.relation, RelationType::Child);
429-
assert_eq!(edge_constraint.label, Some(ConstraintValue::Literal("xcomp".to_string())));
432+
assert_eq!(
433+
edge_constraint.label,
434+
Some(ConstraintValue::Literal("xcomp".to_string()))
435+
);
430436
assert_eq!(edge_constraint.negated, true);
431437
}
432438

src/searcher.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
99
use crate::RelationType;
1010
use crate::bytes::Sym;
11-
use crate::pattern::{BasePattern, Constraint, ConstraintValue, DirectedEdge, EdgeConstraint, Pattern};
11+
use crate::pattern::{
12+
BasePattern, Constraint, ConstraintValue, DirectedEdge, EdgeConstraint, Pattern,
13+
};
1214
use crate::query::{QueryError, compile_query};
1315
use crate::tree::Word;
1416
use crate::tree::{Tree, WordId};
@@ -81,9 +83,9 @@ fn satisfies_var_constraint(tree: &Tree, word: &Word, constraint: &Constraint) -
8183
}
8284
Constraint::HasChild(label) => {
8385
if let Some(cv) = label {
84-
word.children
85-
.iter()
86-
.any(|&child_id| matches_constraint_value(tree, tree.words[child_id].deprel, cv))
86+
word.children.iter().any(|&child_id| {
87+
matches_constraint_value(tree, tree.words[child_id].deprel, cv)
88+
})
8789
} else {
8890
!word.children.is_empty()
8991
}
@@ -100,13 +102,10 @@ fn satisfies_arc_constraint(
100102
let satisfies_constraint = match edge_constraint.relation {
101103
RelationType::Child => {
102104
tree.check_rel(from_word_id, to_word_id)
103-
&& edge_constraint
104-
.label
105-
.as_ref()
106-
.is_none_or(|cv| {
107-
let actual_deprel = tree.word(to_word_id).unwrap().deprel;
108-
matches_constraint_value(tree, actual_deprel, cv)
109-
})
105+
&& edge_constraint.label.as_ref().is_none_or(|cv| {
106+
let actual_deprel = tree.word(to_word_id).unwrap().deprel;
107+
matches_constraint_value(tree, actual_deprel, cv)
108+
})
110109
}
111110
RelationType::Precedes => from_word_id < to_word_id,
112111
RelationType::ImmediatelyPrecedes => to_word_id == from_word_id + 1,
@@ -313,7 +312,7 @@ fn dfs(
313312

314313
// AllDifferent: Remove word_id from all variable domains
315314
for domain in &mut new_domains {
316-
domain.reset(word_id);
315+
domain.reset(word_id);
317316
}
318317
if !(0..pattern.n_vars)
319318
.all(|var_id| new_assign[var_id].is_some() || new_domains[var_id].count_ones() > 0)
@@ -403,18 +402,18 @@ fn check_arc_consistency(
403402
DirectedEdge::Out(edge_id) => {
404403
let ec = &pattern.edge_constraints[edge_id];
405404
let target_var_id = pattern.var_ids[&ec.to];
406-
if assign[target_var_id].is_some_and(|tw| {
407-
!satisfies_arc_constraint(tree, word_id, tw, ec)
408-
}) {
405+
if assign[target_var_id]
406+
.is_some_and(|tw| !satisfies_arc_constraint(tree, word_id, tw, ec))
407+
{
409408
return false;
410409
}
411410
}
412411
DirectedEdge::In(edge_id) => {
413412
let ec = &pattern.edge_constraints[edge_id];
414413
let source_var_id = pattern.var_ids[&ec.from];
415-
if assign[source_var_id].is_some_and(|sw| {
416-
!satisfies_arc_constraint(tree, sw, word_id, ec)
417-
}) {
414+
if assign[source_var_id]
415+
.is_some_and(|sw| !satisfies_arc_constraint(tree, sw, word_id, ec))
416+
{
418417
return false;
419418
}
420419
}
@@ -1563,20 +1562,15 @@ mod tests {
15631562

15641563
// Negated regex edge: V is parent of C but deprel does NOT match obj|xcomp
15651564
// Use VERB constraint on V to limit combinations
1566-
let matches: Vec<_> = search_tree_query(
1567-
tree.clone(),
1568-
r#"MATCH { V []; C []; V -/obj|xcomp/-> C; }"#,
1569-
)
1570-
.unwrap();
1565+
let matches: Vec<_> =
1566+
search_tree_query(tree.clone(), r#"MATCH { V []; C []; V -/obj|xcomp/-> C; }"#)
1567+
.unwrap();
15711568
// Only helped(0)->us(1, obj) and helped(0)->win(3, xcomp) match
15721569
assert_eq!(matches.len(), 2);
15731570

15741571
// Anonymous regex edge
1575-
let matches: Vec<_> = search_tree_query(
1576-
tree.clone(),
1577-
r#"MATCH { C []; _ -/obj|xcomp/-> C; }"#,
1578-
)
1579-
.unwrap();
1572+
let matches: Vec<_> =
1573+
search_tree_query(tree.clone(), r#"MATCH { C []; _ -/obj|xcomp/-> C; }"#).unwrap();
15801574
assert_eq!(matches.len(), 2); // us (obj) and win (xcomp)
15811575
}
15821576

@@ -1594,8 +1588,7 @@ mod tests {
15941588

15951589
// VERB | AUX should match both verbs
15961590
let matches: Vec<_> =
1597-
search_tree_query(tree.clone(), r#"MATCH { V [upos="VERB" | upos="AUX"]; }"#)
1598-
.unwrap();
1591+
search_tree_query(tree.clone(), r#"MATCH { V [upos="VERB" | upos="AUX"]; }"#).unwrap();
15991592
assert_eq!(matches.len(), 2);
16001593
}
16011594

@@ -1605,8 +1598,7 @@ mod tests {
16051598

16061599
// NOUN | ADJ should not match anything
16071600
let matches: Vec<_> =
1608-
search_tree_query(tree.clone(), r#"MATCH { N [upos="NOUN" | upos="ADJ"]; }"#)
1609-
.unwrap();
1601+
search_tree_query(tree.clone(), r#"MATCH { N [upos="NOUN" | upos="ADJ"]; }"#).unwrap();
16101602
assert_eq!(matches.len(), 0);
16111603
}
16121604
}

0 commit comments

Comments
 (0)