88
99use crate :: RelationType ;
1010use 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+ } ;
1214use crate :: query:: { QueryError , compile_query} ;
1315use crate :: tree:: Word ;
1416use 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