matra
matra's parse of this sentence
show the parse
| # | Word | POS | Head | Relation |
|---|---|---|---|---|
| 1 | Attention | NOUN | 2 restores | nsubj |
| 2 | restores | VERB | 0 (root) | root |
| 3 | worlds | NOUN | 2 restores | obj |
| 4 | . | PUNCT | 2 restores | punct |
on this page
matra parses English text into sections, paragraphs, sentences and words, and returns measures, summaries and keyphrases over them, from Rust, Python or the command line.
Quick start
Install matra, save one sentence, and run matra on it.
Rust
1Install
$ cargo new quickstart && cd quickstart
$ cargo add matra@0.3 serde_json 2Save the text
$ echo 'The committee approved the budget on Tuesday.' > note.txt 3Run: save this as src/main.rs,
then run it
// cargo add matra@0.3 serde_json
use matra::{Engine, Input};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Loads the English model, downloading it on first use.
let engine = Engine::new()?;
let doc = engine.analyze(Input::file("note.txt"))?;
println!("{}", serde_json::to_string_pretty(&doc)?);
Ok(())
} $ cargo run Python
1Install
$ pip install 'matra>=0.3' 2Save the text
$ echo 'The committee approved the budget on Tuesday.' > note.txt 3Run: save this as quickstart.py,
then run it
# pip install 'matra>=0.3'
import json
import matra
engine = matra.Engine() # downloads the English model on first use
doc = engine.analyze(file="note.txt") # a str alone would be text, not a path
print(json.dumps(doc.to_dict(), indent=2, ensure_ascii=False)) $ python quickstart.py CLI
1Install
$ pip install 'matra>=0.3' # or: cargo install matra --version '^0.3' --features cli 2Save the text
$ echo 'The committee approved the budget on Tuesday.' > note.txt 3Run
$ matra analyze --json note.txt It prints JSON; here is the first word:
[
{
"id": 1,
"span": {
"byte_start": 0,
"byte_end": 3
},
"text": "The",
"lemma": "the",
"pos": "DET",
"xpos": "DT",
"features": {
"Definite": "Def",
"PronType": "Art"
},
"head": 2,
"dep": "det",
"deps": "_",
"misc": "",
"is_punct": false
}
// … 7 more
] The whole output: output.json, and what the CLI prints, cli.json. The examples gate runs all three calls and compares what each prints with these files.
Every word, drawn. Each arc runs from a word to the word that depends on it:
Dependency parse
1The committee approved the budget on Tuesday.
show the data
| # | Word | Lemma | POS | Head | Relation |
|---|---|---|---|---|---|
| 1 | The | the | DET | 2committee | det |
| 2 | committee | committee | NOUN | 3approved | nsubj |
| 3 | approved | approve | VERB | 0root | root |
| 4 | the | the | DET | 5budget | det |
| 5 | budget | budget | NOUN | 3approved | obj |
| 6 | on | on | ADP | 7Tuesday | case |
| 7 | Tuesday | Tuesday | PROPN | 5budget | nmod |
| 8 | . | . | PUNCT | 3approved | punct |
- Core argument
- Modifier
- Function word
- Other
Each arc runs from a word's head to the word, whose arrow it ends at, labelled with the relation. The line groups the relations the way Universal Dependencies does: the core arguments of a predicate, the modifiers, and the function words. Point at or tap a word, here or in the table, to keep its arcs and dim the rest.
Input: The committee approved the budget on Tuesday., matra contributors. MIT, as part of the matra repository.
Produced by matra 0.3.0 with the UDPipe model english-ewt-ud-2.5-191206
(SHA-256 784bd0fa85e3). Data: quickstart/parse.json.
Where to go next
- Tutorial: run matra on two short paragraphs and find each part of what it returns. About ten minutes.
- How-to guides: one task each on real texts: summarize a document, extract keyphrases, find negations and modals, compare readability, cluster sentences by meaning.
- Explanation: why the output has the shape it has, with figures you can step through.
- Reference: every type and field, the Rust, Python and command-line surfaces, the methods behind each measure, and every error.