---
title: "TextStructure"
language: "en"
type: "Symbol"
summary: "TextStructure[text] generates a nested collection of TextElement objects representing the grammatical structure of natural language text. TextStructure[text, form] generates a representation of the type specified by form of the grammatical structure of text."
canonical_url: "https://reference.wolfram.com/language/ref/TextStructure.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Text Manipulation"
    link: "https://reference.wolfram.com/language/guide/ProcessingTextualData.en.md"
  - 
    title: "Text Analysis"
    link: "https://reference.wolfram.com/language/guide/TextAnalysis.en.md"
  - 
    title: "Linguistic Data"
    link: "https://reference.wolfram.com/language/guide/LinguisticData.en.md"
  - 
    title: "Machine Learning"
    link: "https://reference.wolfram.com/language/guide/MachineLearning.en.md"
  - 
    title: "Natural Language Processing"
    link: "https://reference.wolfram.com/language/guide/NaturalLanguageProcessing.en.md"
related_functions: 
  - 
    title: "TextElement"
    link: "https://reference.wolfram.com/language/ref/TextElement.en.md"
  - 
    title: "TextContents"
    link: "https://reference.wolfram.com/language/ref/TextContents.en.md"
  - 
    title: "TextCases"
    link: "https://reference.wolfram.com/language/ref/TextCases.en.md"
  - 
    title: "TextWords"
    link: "https://reference.wolfram.com/language/ref/TextWords.en.md"
  - 
    title: "TextSentences"
    link: "https://reference.wolfram.com/language/ref/TextSentences.en.md"
  - 
    title: "PartOfSpeech"
    link: "https://reference.wolfram.com/language/ref/PartOfSpeech.en.md"
  - 
    title: "WordData"
    link: "https://reference.wolfram.com/language/ref/WordData.en.md"
  - 
    title: "GrammarRules"
    link: "https://reference.wolfram.com/language/ref/GrammarRules.en.md"
---
[EXPERIMENTAL]

# TextStructure

TextStructure["text"] generates a nested collection of TextElement objects representing the grammatical structure of natural language text.

TextStructure["text", form] generates a representation of the type specified by form of the grammatical structure of text.

## Details and Options

* ``TextStructure[{text1, text2, …}, …]`` yields a list with the respective results for ``texti``.

* Possible types of text structure include:

|                      |                                               |
| -------------------- | --------------------------------------------- |
| "ConstituentTree"    | nested text elements of phrase structure      |
| "ConstituentGraphs"  | graph of phrase structure                     |
| "ConstituentStrings" | string representing phrase structure          |
| "PartsOfSpeech"      | text elements tagging parts of speech         |
| "DependencyGraphs"   | graph of grammatical dependencies             |
| "DependencyStrings"  | string representing grammatical dependencies  |

* The following option can be given:

[`PerformanceGoal`](https://reference.wolfram.com/language/ref/PerformanceGoal.en.md) 	[`Automatic`](https://reference.wolfram.com/language/ref/Automatic.en.md)	favor algorithms with specific advantages

---

## Examples (10)

### Basic Examples (2)

Display the grammatical structure of a sentence:

```wl
In[1]:= TextStructure["The cat sat on the mat."]

Out[1]=
TextElement[
 {TextElement[{TextElement[{TextElement["The", Association["GrammaticalUnit" -> 
         Entity["GrammaticalUnit", "Determiner"]]], TextElement["cat", 
       Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Noun"]]]}, 
    ... tion["GrammaticalUnit" -> Entity["GrammaticalUnit", "VerbPhrase"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]
```

---

Display parts of speech tags:

```wl
In[1]:= TextStructure["The cat sat on the mat.", "PartsOfSpeech"]

Out[1]=
TextElement[
 {TextElement[{TextElement["The", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", 
        "Determiner"]]], TextElement["cat", Association["GrammaticalUnit" -> 
       Entity["GrammaticalUnit", "Noun"]]], TextElement["sat",  ... ssociation["GrammaticalUnit" -> Entity["GrammaticalUnit", "Noun"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]
```

### Scope (6)

Display the constituent tree of a sentence:

```wl
In[1]:= TextStructure["Time flies like an arrow.", "ConstituentTree"]

Out[1]=
TextElement[
 {TextElement[{TextElement[{TextElement["Time", Association["GrammaticalUnit" -> 
         Entity["GrammaticalUnit", "ProperNoun"]]]}, 
     Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "NounPhrase"]]], 
    TextElement[{ ... tion["GrammaticalUnit" -> Entity["GrammaticalUnit", "VerbPhrase"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]
```

---

Return the constituent tree as a graph:

```wl
In[1]:= TextStructure["The cat sat on the mat.", "ConstituentGraphs"]

Out[1]= {[image]}
```

---

Return the constituent tree as a string of nested parentheses:

```wl
In[1]:= TextStructure["The cat sat on the mat.", "ConstituentStrings"]

Out[1]= {"(Sentence, ((NounPhrase, (Determiner, The), (Noun, cat)), (VerbPhrase, (Verb, sat), (PrepositionalPhrase, (Preposition, on), (NounPhrase, (Determiner, the), (Noun, mat)))), (Punctuation, .)))"}
```

---

Return the grammatical dependencies as a graph:

```wl
In[1]:= TextStructure["The cat sat on the mat.", "DependencyGraphs"]

Out[1]= {[image]}
```

---

Display the dependency tree as a string of nested brackets:

```wl
In[1]:= TextStructure["The cat sat on the mat.", "DependencyStrings"]

Out[1]= {"(sat, 3)((nsubj, (cat, 2)((det, (The, 1)))), (prep, (on, 4)((pobj, (mat, 6)((det, (the, 5)))))))"}
```

---

Display the grammatical structure of several sentences at once:

```wl
In[1]:= TextStructure["The cat sat on the mat. The bat and a rat sat on a mat."]

Out[1]=
TextElement[
 {TextElement[{TextElement[{TextElement["The", Association["GrammaticalUnit" -> 
         Entity["GrammaticalUnit", "Determiner"]]], TextElement["cat", 
       Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Noun"]]]}, 
    ... tion["GrammaticalUnit" -> Entity["GrammaticalUnit", "VerbPhrase"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]
```

### Options (1)

#### PerformanceGoal (1)

Faster parts of speech tagging can be achieved by using ``PerformanceGoal -> "Speed"`` :

```wl
In[1]:= RepeatedTiming[TextStructure["The cat sat on the mat. The bat and a rat sat on a mat.", "PartsOfSpeech"]]

Out[1]=
{0.041, TextElement[
 {TextElement[{TextElement["The", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", 
        "Determiner"]]], TextElement["cat", Association["GrammaticalUnit" -> 
       Entity["GrammaticalUnit", "Noun"]]], TextElement ... sociation["GrammaticalUnit" -> Entity["GrammaticalUnit", "Noun"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]}

In[2]:= RepeatedTiming[TextStructure["The cat sat on the mat. The bat and a rat sat on a mat.", "PartsOfSpeech", PerformanceGoal -> "Speed"]]

Out[2]=
{0.006, TextElement[
 {TextElement[{TextElement["The", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", 
        "Determiner"]]], TextElement["cat", Association["GrammaticalUnit" -> 
       Entity["GrammaticalUnit", "Noun"]]], TextElement ... sociation["GrammaticalUnit" -> Entity["GrammaticalUnit", "Noun"]]], 
    TextElement[".", Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Punctuation"]]]}, 
   Association["GrammaticalUnit" -> Entity["GrammaticalUnit", "Sentence"]]]}]}
```

### Applications (1)

Get the text content of a Wikipedia page using ``WikipediaData`` :

```wl
In[1]:= wiki = WikipediaData["monkey"];

In[2]:= StringLength[wiki]

Out[2]= 14076
```

Extract the first paragraph using ``TextCases`` :

```wl
In[3]:= paragraph = First@TextCases[wiki, "Paragraph", 1]

Out[3]= "Monkey is a common name that may refer to most mammals of the infraorder Simiiformes, also known as the simians. Traditionally, all animals in the group now known as simians are counted as monkeys except the apes, a grouping known as paraphyletic; ... e monkeys was already realized by Georges-Louis Leclerc, Comte de Buffon in the 18th century.Monkeys, including apes, can be distinguished from other primates by having only two pectoral nipples, a pendulous penis, and a lack of sensory whiskers."
```

Use ``TextStructure`` to visualize the grammatical structure of this paragraph:

```wl
In[4]:= TextStructure[paragraph]

Out[4]= TextElement[«1»]
```

## See Also

* [`TextElement`](https://reference.wolfram.com/language/ref/TextElement.en.md)
* [`TextContents`](https://reference.wolfram.com/language/ref/TextContents.en.md)
* [`TextCases`](https://reference.wolfram.com/language/ref/TextCases.en.md)
* [`TextWords`](https://reference.wolfram.com/language/ref/TextWords.en.md)
* [`TextSentences`](https://reference.wolfram.com/language/ref/TextSentences.en.md)
* [`PartOfSpeech`](https://reference.wolfram.com/language/ref/PartOfSpeech.en.md)
* [`WordData`](https://reference.wolfram.com/language/ref/WordData.en.md)
* [`GrammarRules`](https://reference.wolfram.com/language/ref/GrammarRules.en.md)

## Related Guides

* [Text Manipulation](https://reference.wolfram.com/language/guide/ProcessingTextualData.en.md)
* [Text Analysis](https://reference.wolfram.com/language/guide/TextAnalysis.en.md)
* [Linguistic Data](https://reference.wolfram.com/language/guide/LinguisticData.en.md)
* [Machine Learning](https://reference.wolfram.com/language/guide/MachineLearning.en.md)
* [Natural Language Processing](https://reference.wolfram.com/language/guide/NaturalLanguageProcessing.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Natural Language Understanding](https://www.wolfram.com/language/elementary-introduction/35-natural-language-understanding.html)

## History

* [Introduced in 2015 (10.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn103.en.md) \| [Updated in 2019 (12.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn120.en.md)