Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Remove cycles from the dependency graph #16

Merged
merged 1 commit into from
Apr 25, 2019
Merged

Remove cycles from the dependency graph #16

merged 1 commit into from
Apr 25, 2019

Conversation

danieldk
Copy link
Member

Applies the strategy suggested by Strzyz et al., 2019 to attach the
leftmost token in a cycle to the first root token.

@danieldk danieldk added the feature New feature or request label Apr 24, 2019
@danieldk danieldk requested a review from sebpuetz April 24, 2019 09:51
Copy link
Collaborator

@sebpuetz sebpuetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments about style, a typo and a possibly redundant filter call. Functionality should be fine, anyways.

/// Break cycles in the graph.
///
/// Panics when a token does not have a head.
pub fn break_cycles(sent: &mut Sentence, root_idx: usize) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think almost all other methods return Errors to indicate failures, why panic here? From what I can tell, the calling method decode returns an Error, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encode/decode return errors for invalid user input. This is a private function and having a head on each token is an invariant. Passing a graph with headless tokens to break_cycles is a programming error and should thus lead to an assertion-type panic and not to a regular error that is communicated to the user.

I have extended the rustdoc a bit that attach_orphans should be called before this function if the graph has headless tokens.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't catch that the post_processing module was crate-private, I only looked at the pub fn break_cycles signature.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll merge this then.

pub fn break_cycles(sent: &mut Sentence, root_idx: usize) {
loop {
let components = {
let digraph: &DiGraph<_, _> = (&*sent).into();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks somewhat ugly, to say the least. Perhaps a .graph() method on Sentence would make for some nicer looking code? I don't remember if we discussed that in the issues at the conllx-rs repo.

let graph = sent.graph();

or even more concise (untested, don't know if lifetimes are an issue here):

let components = tarjan_scc(sent.graph())
                .into_iter()
                .filter(|c| c.len() > 1)
                .collect::<Vec<_>>();

Copy link
Member Author

@danieldk danieldk Apr 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed missing in conllx-rs. Another annoyance is that DepGraphMut does not have a method to remove edges (something like remove_deprel(dependent: usize)). I'll add issues.

What makes things less ergonomic in this case is that type-inference does understand the simple into() call, because sent is &mut and the From implementation is for &. Not providing an &mut implementation was intentional to avoid changing the graph from under our feet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies the strategy suggested by Strzyz et al., 2019 to attach the
leftmost token in a cycle to the first root token.
@danieldk danieldk merged commit 5083778 into master Apr 25, 2019
@danieldk danieldk deleted the break-cycles branch May 9, 2019 12:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants