Find negations and modals
on this page
Which sentences of a legal text are negated, and which carry a modal verb, read off each sentence's dependency tree.
Input
The calls read it as constitution-article-one.txt in the directory you run them from. Save it there:
curl -fLO https://mox-labs.github.io/matra/example-files/negations-and-modals/constitution-article-one.txt or download constitution-article-one.txt.
The text, 3 paragraphs
We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.
All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.
The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature. No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.
The call
Rust
// 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("constitution-article-one.txt"))?;
println!("{}", serde_json::to_string_pretty(&doc)?);
Ok(())
} Python
# pip install 'matra>=0.3'
import json
import matra
engine = matra.Engine() # downloads the English model on first use
doc = engine.analyze(file="constitution-article-one.txt") # a str alone would be text, not a path
print(json.dumps(doc.to_dict(), indent=2, ensure_ascii=False)) CLI
$ matra analyze --json constitution-article-one.txt It prints the output below, inside an envelope that names the command and the input:
{
"format_version": 2,
"command": "analyze",
"input": "constitution-article-one.txt",
"result": /* the output below */,
"error": null
}Output
Trimmed: only result.sections[0].paragraphs[2].sentences, tokens shown as a count, lists cut to the first 2, long strings shortened.
[
{
"span": {
"byte_start": 482,
"byte_end": 739
},
"text": "The House of Representatives shall be composed of Members chosen every …",
"tokens": [ /* 44 items */ ],
"word_count": 42,
"tree_depth": 6,
"passive": true,
"negations": [],
"modals": [
{
"aux_id": 5,
"aux_lemma": "shall",
"head_id": 7
},
{
"aux_id": 28,
"aux_lemma": "shall",
"head_id": 29
}
],
"clausal_complements": [],
"root_adverbials": [],
"hearst_pairs": [],
"root_mood": null
},
{
"span": {
"byte_start": 740,
"byte_end": 982
},
"text": "No Person shall be a Representative who shall not have attained to the …",
"tokens": [ /* 51 items */ ],
"word_count": 46,
"tree_depth": 7,
"passive": true,
"negations": [
{
"cue_id": 1,
"cue_lemma": "no",
"head_id": 2
},
{
"cue_id": 9,
"cue_lemma": "not",
"head_id": 11
}
// … 1 more
],
"modals": [
{
"aux_id": 3,
"aux_lemma": "shall",
"head_id": 6
},
{
"aux_id": 8,
"aux_lemma": "shall",
"head_id": 11
}
// … 2 more
],
"clausal_complements": [],
"root_adverbials": [],
"hearst_pairs": [],
"root_mood": null
}
] 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 primitive of every sentence, marked on the word it is read from and the word it attaches to:
Structural primitives
- 1
We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.
- 2
All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.
- 3
The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.
- 4
No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.
show the data
| # | Primitive | Read from | Attaches to | Field and detail |
|---|---|---|---|---|
| 1 | no primitive | |||
| 2 | modal | 6shall | 8vested | modals |
| 2 | modal | 18shall | 19consist | modals |
| 3 | modal | 5shall | 7composed | modals |
| 3 | modal | 28shall | 29have | modals |
| 4 | negation | 1No | 2Person | negations |
| 4 | negation | 9not | 11attained | negations |
| 4 | negation | 34not | 33shall | negations |
| 4 | modal | 3shall | 6Representative | modals |
| 4 | modal | 8shall | 11attained | modals |
| 4 | modal | 33shall | 41Inhabitant | modals |
| 4 | modal | 48shall | 50chosen | modals |
- negation
- modal
Each primitive is a field matra fills on Sentence from its dependency tree: the tinted
word is the one it is read from, the underlined word the one it attaches to. The root mood is read
off the whole root clause: the Mood feature on the root or its auxiliary. What any of
it means for a text is the reader's call; matra reports the construction.
Input: The Constitution of the United States: the Preamble, and Article I, Sections 1 and 2 (opening), The Constitutional Convention, 1787. Public domain (a founding document of the United States, 1787).
Produced by matra 0.3.0 with the UDPipe model english-ewt-ud-2.5-191206
(SHA-256 784bd0fa85e3). Data: constitution-article-one/primitives.json.
What to notice
- Every sentence has a
negationslist and amodalslist, empty when there is none. A negation names its cue (cue_lemma, at tokencue_id) and the word it attaches to (head_id). A modal names its auxiliary (aux_lemma, ataux_id) and the word it governs (head_id). The ids are token ids within the sentence. - The second sentence of Section 2 has three negations,
noonPersonandnottwice, and four modals, eachshall. To the parser the Constitution'sshallis a modal like any other. - One
notattaches toshallrather than to a verb: in "who shall not, when elected, be an Inhabitant", the parser hung the negation on the auxiliary.head_idis what the tree says, and that is all it says. - To collect the negated sentences, keep those whose
negationsis not empty. What a negation means for your purpose is your code's decision; matra reports where it is.
This page, measured by matra 0.3.0 with english-ewt-ud-2.5-191206: 2 paragraphs, in the margin. the data