Main Content

sentenceChart

Plot grammatical dependency parse tree of sentence

Since R2022b

    Description

    sentenceChart(sentence) plots the grammatical dependency chart of sentence.

    This syntax requires Deep Learning Toolbox™ and the Text Analytics Toolbox™ Model for UDify Data support package. If this support package is not installed, then the function provides a download link.

    example

    sentenceChart(token,head,dependency) plots the grammatical dependency chart of the sentence using the dependency details encoded by the tokens token, head details head, and dependency tags dependency.

    sentenceChart(tdetails) plots the grammatical dependency chart of the sentence using the dependency details encoded by the token details table tdetails.

    sentenceChart(___,Name=Value) specifies additional options using one or more name-value arguments.

    example

    sentenceChart(parent,___) creates the sentence chart in the figure, panel, or tab specified by parent.

    sc = sentenceChart(___) returns the DependencyChart object. Use sc to modify properties of the sentence chart after creating it. For a list of properties, see DependencyChart Properties.

    Examples

    collapse all

    Create a string containing a single sentence.

    sentence = "The quick brown fox jumped over the lazy dog.";

    Visualize the dependency details in a sentence chart. Solid lines indicate dependencies and dotted lines indicate subtree labels.

    figure
    sentenceChart(sentence)

    Create a tokenized document object containing a single sentence.

    str = "The quick brown fox jumped over the lazy dog.";
    sentence = tokenizedDocument(str)
    document = 
      tokenizedDocument:
    
       10 tokens: The quick brown fox jumped over the lazy dog .
    
    

    Visualize the dependency details in a sentence chart. Solid lines indicate dependencies and dotted lines indicate subtree labels.

    figure
    sentenceChart(sentence)

    For long sentences, it can be easier to visualize the sentence structure if you orient the chart vertically.

    Create a tokenized document object containing a single sentence.

    str = "The particularly quick brown and white fox swiftly " + ...
        "jumped over the unbelievably lazy fluffy dog with big eyes.";
    sentence = tokenizedDocument(str)
    document = 
      tokenizedDocument:
    
       19 tokens: The particularly quick brown and white fox swiftly jumped over the unbelivably lazy fluffy dog with big eyes .
    
    

    Visualize the dependency details in a sentence chart. For readability, orient the sentence chart vertically by setting the Orientation option to "vertical". Solid lines indicate dependencies and dotted lines indicate subtree labels.

    figure
    sentenceChart(sentence,Orientation="vertical")

    Input Arguments

    collapse all

    Input sentence, specified as a tokenizedDocument object, string scalar, or character vector containing a single sentence.

    Sentence tokens, specified as a string vector or a cell array of character vectors.

    Data Types: string | cell

    Token dependency heads, specified as a vector of nonnegative integers, where head(i) is the index of the head token of token(i) and head(i) is 0 for the root token.

    The dependency structure of head must encode a tree.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Token dependency types, specified as a categorical vector, string vector, or cell array of character vectors. The object stores this input as a categorical vector.

    Data Types: string | cell | categorical

    Token details table, specified as a table with the variables Token, Head, and Dependency.

    • Entries in the Token variable correspond to the sentence tokens and must be string scalars or character vectors.

    • Entries in the Head variable correspond to the token dependency heads and must be nonnegative integers, where tdetails.Head(i) is the index of the head token of tdetails.Token(i) and tdetails.Head(i) is 0 for the root token. The dependency structure of tdetails.Head must encode a tree.

    • Entries in the Dependency variable correspond to the token dependency types and must be categorical values, string scalars, or character vectors.

    Data Types: table

    Parent, specified as a figure, panel, or tab.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: sentenceChart(sentence,Orientation="vertical") plots the dependency chart of sentence with tokens oriented vertically.

    The DependencyChart properties listed here are only a subset. For a complete list, see DependencyChart Properties.

    Display orientation of the sentence, specified as one of these values:

    • "horizontal" — Display the tokens horizontally with the tree reading from top to bottom.

    • "vertical" — Display the tokens vertically with the tree reading from left to right.

    Dependency line width in points, specified as a positive scalar. One point equals 1/72 inch.

    The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

    Note

    If you do not specify LeaderLineWidth, then the function automatically sets LeaderLineWidth to the value of LineWidth. To change the dependency line width only, set LeaderLineWidth to 0.5.

    Dependency line color, specified as an RGB triplet or as a string scalar or character vector containing a color name.

    RGB triplets and hexadecimal color codes are useful for specifying custom colors.

    • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7].

    • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Thus, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

    Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

    Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
    "red""r"[1 0 0]"#FF0000"

    Sample of the color red

    "green""g"[0 1 0]"#00FF00"

    Sample of the color green

    "blue""b"[0 0 1]"#0000FF"

    Sample of the color blue

    "cyan" "c"[0 1 1]"#00FFFF"

    Sample of the color cyan

    "magenta""m"[1 0 1]"#FF00FF"

    Sample of the color magenta

    "yellow""y"[1 1 0]"#FFFF00"

    Sample of the color yellow

    "black""k"[0 0 0]"#000000"

    Sample of the color black

    "white""w"[1 1 1]"#FFFFFF"

    Sample of the color white

    Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

    RGB TripletHexadecimal Color CodeAppearance
    [0 0.4470 0.7410]"#0072BD"

    Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

    [0.8500 0.3250 0.0980]"#D95319"

    Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

    [0.9290 0.6940 0.1250]"#EDB120"

    Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

    [0.4940 0.1840 0.5560]"#7E2F8E"

    Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

    [0.4660 0.6740 0.1880]"#77AC30"

    Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

    [0.3010 0.7450 0.9330]"#4DBEEE"

    Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

    [0.6350 0.0780 0.1840]"#A2142F"

    Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

    Dependency line style, specified as one of the options in this table.

    Line StyleDescriptionResulting Line
    "-"Solid line

    Sample of solid line

    "--"Dashed line

    Sample of dashed line

    ":"Dotted line

    Sample of dotted line

    "-."Dash-dotted line

    Sample of dash-dotted line, with alternating dashes and dots

    "none"No lineNo line

    Leader line width in points, specified as a positive scalar. One point equals 1/72 inch.

    The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

    Leader line color, specified as an RGB triplet or as a string scalar or character vector containing a color name.

    RGB triplets and hexadecimal color codes are useful for specifying custom colors.

    • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7].

    • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Thus, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

    Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

    Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
    "red""r"[1 0 0]"#FF0000"

    Sample of the color red

    "green""g"[0 1 0]"#00FF00"

    Sample of the color green

    "blue""b"[0 0 1]"#0000FF"

    Sample of the color blue

    "cyan" "c"[0 1 1]"#00FFFF"

    Sample of the color cyan

    "magenta""m"[1 0 1]"#FF00FF"

    Sample of the color magenta

    "yellow""y"[1 1 0]"#FFFF00"

    Sample of the color yellow

    "black""k"[0 0 0]"#000000"

    Sample of the color black

    "white""w"[1 1 1]"#FFFFFF"

    Sample of the color white

    Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

    RGB TripletHexadecimal Color CodeAppearance
    [0 0.4470 0.7410]"#0072BD"

    Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

    [0.8500 0.3250 0.0980]"#D95319"

    Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

    [0.9290 0.6940 0.1250]"#EDB120"

    Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

    [0.4940 0.1840 0.5560]"#7E2F8E"

    Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

    [0.4660 0.6740 0.1880]"#77AC30"

    Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

    [0.3010 0.7450 0.9330]"#4DBEEE"

    Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

    [0.6350 0.0780 0.1840]"#A2142F"

    Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

    Leader line style, specified as one of the options in this table.

    Line StyleDescriptionResulting Line
    "-"Solid line

    Sample of solid line

    "--"Dashed line

    Sample of dashed line

    ":"Dotted line

    Sample of dotted line

    "-."Dash-dotted line

    Sample of dash-dotted line, with alternating dashes and dots

    "none"No lineNo line

    Token and label font name, specified as a supported font name. For labels to display and print properly, you must choose a font that your system supports. The default font depends on the specific operating system and locale. For example, Windows® and Linux® systems in English localization use the Helvetica font by default.

    Data Types: char | string

    Token font size in points, specified as a positive scalar. One point equals 1/72 inch.

    Note

    If you do not specify the LabelFontSize option, then the function automatically sets the LabelFontSize option to 0.8*LineWidth. To change the token font size only, set the LabelFontSize option to 8.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Label font name, specified as a supported font name. For labels to display and print properly, you must choose a font that your system supports. The default font depends on the specific operating system and locale. For example, Windows and Linux systems in English localization use the Helvetica font by default.

    Data Types: char | string

    Label font size in points, specified as a positive scalar. One point equals 1/72 inch.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    Grammatical dependency chart, returned as a DependencyChart object. You can modify the properties of a DependencyChart after you create it. For more information, see DependencyChart Properties.

    Version History

    Introduced in R2022b