Find negations and modals

on this page
grade11.1density0.55compressionnone

Which sentences of a legal text are negated, and which carry a modal verb, read off each sentence's dependency tree.

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). 165 words.

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.

grade9.8density0.47compressionnone

Every primitive of every sentence, marked on the word it is read from and the word it attaches to:

Structural primitives

  1. 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. 2

    All legislative Powers herein granted shall◇ modal be vested◇ governs in a Congress of the United States, which shall◇ modal consist◇ governs of a Senate and House of Representatives.

  3. 3

    The House of Representatives shall◇ modal be composed◇ governs of Members chosen every second Year by the People of the several States, and the Electors in each State shall◇ modal have◇ governs the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.

  4. 4

    No¬ negation Person¬ negated shall◇ modal be a Representative◇ governs who shall◇ modal not¬ negation have attained¬ negated · ◇ governs to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall¬ negated · ◇ modal not¬ negation, when elected, be an Inhabitant◇ governs of that State in which he shall◇ modal be chosen◇ governs.

show the data
#PrimitiveRead fromAttaches toField and detail
1no primitive
2modal6shall8vestedmodals
2modal18shall19consistmodals
3modal5shall7composedmodals
3modal28shall29havemodals
4negation1No2Personnegations
4negation9not11attainednegations
4negation34not33shallnegations
4modal3shall6Representativemodals
4modal8shall11attainedmodals
4modal33shall41Inhabitantmodals
4modal48shall50chosenmodals
  • 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 negations list and a modals list, empty when there is none. A negation names its cue (cue_lemma, at token cue_id) and the word it attaches to (head_id). A modal names its auxiliary (aux_lemma, at aux_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, no on Person and not twice, and four modals, each shall. To the parser the Constitution's shall is a modal like any other.
  • One not attaches to shall rather than to a verb: in "who shall not, when elected, be an Inhabitant", the parser hung the negation on the auxiliary. head_id is what the tree says, and that is all it says.
  • To collect the negated sentences, keep those whose negations is 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