[][src]Struct conllu::graph::Sentence

pub struct Sentence { /* fields omitted */ }

A CoNLL-U dependency graph.

Sentence stores a dependency graph. The nodes in the graph (except the special root node) are tokens that have the fields of the CoNLL-U format. Dependency relations are stored as edges in the graph.

This data structure is a thin wrapper around the petgraph DiGraph data structure that enforces variants such as single-headedness. The into_inner/get_ref methods can be used to unwrap or get a reference to the wrapped graph.

Methods

impl Sentence[src]

pub fn new() -> Self[src]

Construct a new sentence.

The sentence will be constructed such that the first token is the root of the dependency graph:

use conllu::graph::{Node, Sentence};

let sentence = Sentence::new();
assert_eq!(sentence[0], Node::Root);

pub fn comments(&self) -> &[Comment][src]

pub fn comments_mut(&mut self) -> &mut Vec<Comment>[src]

pub fn get_ref(&self) -> &DiGraph<Node, Edge>[src]

Get a reference to the DiGraph of the sentence.

pub fn into_inner(self) -> DiGraph<Node, Edge>[src]

Unwrap the DiGraph of the sentence.

pub fn iter(&self) -> Iter[src]

Get an iterator over the nodes in the graph.

pub fn iter_mut(&mut self) -> IterMut[src]

Get a mutable iterator over the nodes in the graph.

pub fn push(&mut self, token: Token) -> usize[src]

Add a new token to the graph.

Tokens should always be pushed in sentence order.

Returns the index of the token. The first pushed token has index 1, since index 0 is reserved by the root of the graph.

pub fn dep_graph(&self) -> DepGraph[src]

Get the dependency graph.

pub fn dep_graph_mut(&mut self) -> DepGraphMut[src]

Get the graph mutably.

pub fn len(&self) -> usize[src]

Get the number of nodes in the dependency graph.

This is equal to the number of tokens, plus one root node.

pub fn set_comments(&mut self, comments: impl Into<Vec<Comment>>)[src]

Replace the comments by the given comments.

Returns the old comments that are replaced.

Trait Implementations

impl Clone for Sentence[src]

impl Debug for Sentence[src]

impl Default for Sentence[src]

impl Display for Sentence[src]

impl Eq for Sentence[src]

impl<'a> From<&'a Sentence> for &'a DiGraph<Node, Edge>[src]

impl From<Sentence> for DiGraph<Node, Edge>[src]

impl FromIterator<Token> for Sentence[src]

impl Index<usize> for Sentence[src]

type Output = Node

The returned type after indexing.

impl IndexMut<usize> for Sentence[src]

impl<'a> IntoIterator for &'a Sentence[src]

type Item = &'a Node

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a mut Sentence[src]

type Item = &'a mut Node

The type of the elements being iterated over.

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?

impl PartialEq<Sentence> for Sentence[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.