<commit_before>* Modeling the Corporation
** Prerequisites
To understand this document you should be familiar with object-oriented programming and domain modeling.

See:
- http://martinfowler.com/eaaCatalog/domainModel.html
- http://www.martinfowler.com/bliki/AnemicDomainModel.html

** Misc Thoughts
In the financial services industry, UML and XML models for financial transactions exist: ISO 20022 is the basis for SWIFT.

Maybe we can import some of those ideas. A startup investment is, after all, just a special case of a financial transaction.

Corporations are relatively lightweight structures, especially at the startup stage. Even public corporations aren't terribly complex: they have a lot of shareholders, a few directors, and a bunch of bank accounts.

Astonishingly, we have not been able to find a data model schema for a corporation. So here's one.
** Entities
*** Primary Entity: Company

The Models given in this document claim to work for two kinds of primary entities. A Company is assumed to be one of the following:

**** Private Limited Companies                                              :SG:SG_CA50_20160103:

The Resolutions Model claims correctness for Singapore Private Limited Companies.

**** Exempt Private Limited Companies                                       :SG:SG_CA50_20160103:

For the purpose of the Resolutions Model, all facts true of Private Limited Companies are also true of Exempt Private Limited Companies.

*** Secondary Entities                                                                   :general:

Along the way, the following secondary entities will turn up:

**** Natural Person                                                                     :general:

Usually a human being. May be resident in any jurisdiction.

May be the estate, personal representative, attorney, etc, of a human being.

**** Organization                                                                       :general:

Synonymous with a corporate person -- anything that is not a natural person. For example, an investment holding company may be a corporate shareholder.

*** Roles

The following roles exist with-respect-to the Company.

**** General Role Attributes
a role relationship starts and stops in time. So we need [[https://en.wikipedia.org/wiki/Bitemporal_data][bitemporality]].

**** Director Role                                                                      :general:

**** Shareholder Role                                                                   :general:

May be of a specific class of shares.

**** Bondholder Role                                                                    :general:

Of a specific security.

**** Warrantholder Role                                                                 :general:

Of a specific security.

**** Investor Role                                                                      :general:

**** Member Role                                                            :SG:SG_CA50_20160103:

Often synonymous with shareholder, but specifically defined as a person entitled to receive notices of meetings.

Not tagged as global because the notion of a member may not be common outside Singapore jurisdiction.

*** Entities Out of Scope                                                                :general:

The resolution model does not claim to cover:

**** Companies Limited by Guarantee
**** Trusts
**** Public Companies

* Modeling the Drafting
Within a contract, we deal with terms and content. This model cares about the conceptual/abstract representation, also known as the formal representation. It also cares about the physical text in a natural language. The physical text may include formatting instructions.

** Contract-Level Examples
*** Example 1A: definition
#+NAME: 1A round definition series seed
#+BEGIN_SRC js
  var investment = newRound( {
    security: "SeriesSeed",
    parties: {
      company: "MyCompany",
      new_investors: [ { name: "Alice", commitment: 100000 },
                       { name: "Bob",   commitment:  50000 },
                       { name: "Carol", commitment:  20000 } ] },
    terms: {
      pre_money_valuation: 10000000,
      round_size:           1000000,
      esop:                      15
    }
  } );
#+END_SRC

This is the formal representation defining a simple Series Seed investment round. The meat of the definition is your basic JSON data structure, which could be constructed by a UI or read out of a spreadsheet.

*** Example 1B: export to natural language
#+NAME: 1B export natural
#+BEGIN_SRC js
investment.workflows().export_as({format:"XML", lang:"en-US"});
#+END_SRC

This outputs all the paperwork required to effect the round, in XML format, suitable for import into InDesign and subsequent output to PDF.

In practice the workflows() method runs prerequisites(), agreements(), and filings().

*** Example 1C: export to formal representation
#+NAME: 1C export formal
#+BEGIN_SRC js
investment.agreements("shareholder").export_as(format:"javascript");
#+END_SRC

produces a bunch of Javascript. See the next example for a microscopic view of the clause-level exports.

** Clause-Level Examples

The Series Seed v3.2 Certificate of Incorporation contains a clause:

#+BEGIN_QUOTE
Mandatory Conversion. Upon either (a) the closing of the sale of shares of Common Stock to the public in a firm-commitment underwritten public offering pursuant to a prospectus filed under the Securities and Futures Act or (b) the date and time, or the occurrence of an event, specified by vote or written consent of the Requisite Holders at the time of such vote or consent, voting as a single class on an as-converted basis (the time of such closing or the date and time specified or the time of the event specified in such vote or written consent,the <b><i>“Mandatory Conversion Time”</i></b>), (i) all outstanding shares of Series Seed Preferred Stock will automatically convert into shares of Common Stock, at the applicable ratio described in Section <xref to="conversionratio" /> as the same may be adjusted from time to time in accordance with Section <xref to="conversion" /> and (ii) such shares may not be reissued by the Company.
#+END_QUOTE

In this example, we'll see how Legalese represents that clause. In particular, we are interested in how the formal representation affords natural language generation.

*** Exposition in Lay Terms

The Gentle Reader may not be familiar with the semantics of this clause. If you need help understanding the clause, read on.

The context: the Company's constitution defines a class of shares called "Series Seed". A class attribute is "mandatory conversion". This clause describes when mandatory conversion can happen.

What does conversion mean? Series Seed shares turn into Common Stock.

What does mandatory conversion mean? That the conversion happens automatically, when some other condition is met. Neither the Company nor the Series Seed Holders can block the conversion.

What conditions trigger mandatory conversions? It turns out there are three possible triggers.

First trigger: there is an IPO -- an Initial Public Offering. Shares of the company are sold to the public in a public offering.

Second trigger: a certain voting majority of the Series Seed Holders agree to 

If any of these triggers occurs, then mandatory conversion follows.

*** Example 2A: Conversion
#+NAME: 2A conversion clause retrieval
#+BEGIN_SRC js
var clauses = investment.clauses_matching("conversion");
#+END_SRC

returns

#+NAME: 2B conversion clause content
#+BEGIN_SRC js
  [ { clauseName: { "en-US": "Mandatory Conversion" },
      handler: function(events) {
    for (var event_i in events) {
      var event = events[event_i];
      var parties = event.parties;
      var respect = event.respect; // party with deontic obligation perspective
      if (event.name == "IPO" ||
          event.name == "classVote") {
        var company = this;
      }
    }
      }
    } ]
#+END_SRC


*** Example 2B: 

** Prerequisites
To understand this section, you should:
- read <NAME>, A Manual of Style for Contract Drafting
- understand what a context-free grammar is, and be familiar with Backus-Naur Form
- read https://drive.google.com/open?id=0BxOaYa8pqqSwTC04OTF5b1hYams Some computational properties of a model for electronic documents, TBC 1989
- view https://drive.google.com/open?id=0BxOaYa8pqqSwUWlCajFJQURXdG8 introducing deontic logics, Gorin 2010
- read http://wyner.info/research/Papers/WynerPetersJURIX2011.pdf -- Wyner 2011, /On Rule Extraction from Regulations/
- read https://drive.google.com/a/legalese.io/file/d/0BxOaYa8pqqSwWk9NallEck83T2M/view -- CLAN 2009
- read https://drive.google.com/a/legalese.io/file/d/0BxOaYa8pqqSwSjRMeGtzVGhIaWs/view -- FormaLex 2011

** Formal Representation

Formally, a legal document obeys a grammar. In this document, we treat "grammar" and "schema" as [[https://www.w3.org/People/Bos/Schema/schemas][rough homomorphisms]], with schemas being slightly more specific and grammars being slightly more general.

Different jurisdictions may impose different schemas. For example, a contract written in the US style will look different from a contract written in the UK style. However, both documents will exhibit a high degree of structure. A family of UK documents will share the same schema.

A rough schema for a contract could be: title, date, parties, recitals, definitions, conditions precedent, main part, standard bits, signatures. The main part is composed of a list of clauses.

A rough schema for a directors' resolution could be: letterhead, item [...], signatures. Each item is either a Resolved or a Noted.


** Primitives

*** The Schema
*** The Clause / Article / Section
*** The Definition

** Dimensions
There are many ways to represent a given clause. Some dimensions of interest are:

*** Formal vs Natural Language Representation

A concept may be expressed formally.

A concept may be expressed naturally, in a language like English.

A concept may be expressed in a hybrid of formal and natural -- see [[https://en.wikipedia.org/wiki/Controlled_natural_language][Controlled Natural Languages]], e.g. [[https://en.wikipedia.org/wiki/Attempto_Controlled_English][Attempto]].

*** Compactness vs Completeness

For compactness, we want to be able to summarize a clause as tersely as possible.

For completeness, we want to be able to expand a clause, to "look inside" it both syntactically and semantically.

*** Locality and Coupling

Some clauses are limited in scope. A standalone clause does not modify, and is not modified by, any other clause.

Other clauses are highly coupled. A coupled clause explicitly modifies, or is explicitly modified by, another clause.
<commit_msg>more thoughts<commit_after>* Modeling the Corporation
** Prerequisites
To understand this document you should be familiar with object-oriented programming and domain modeling.

See:
- http://martinfowler.com/eaaCatalog/domainModel.html
- http://www.martinfowler.com/bliki/AnemicDomainModel.html

** Misc Thoughts
In the financial services industry, UML and XML models for financial transactions exist: ISO 20022 is the basis for SWIFT.

Maybe we can import some of those ideas. A startup investment is, after all, just a special case of a financial transaction.

Corporations are relatively lightweight structures, especially at the startup stage. Even public corporations aren't terribly complex: they have a lot of shareholders, a few directors, and a bunch of bank accounts.

Astonishingly, we have not been able to find a data model schema for a corporation. So here's one.
** Entities
*** Primary Entity: Company

The Models given in this document claim to work for two kinds of primary entities. A Company is assumed to be one of the following:

**** Private Limited Companies                                              :SG:SG_CA50_20160103:

The Resolutions Model claims correctness for Singapore Private Limited Companies.

**** Exempt Private Limited Companies                                       :SG:SG_CA50_20160103:

For the purpose of the Resolutions Model, all facts true of Private Limited Companies are also true of Exempt Private Limited Companies.

*** Secondary Entities                                                                   :general:

Along the way, the following secondary entities will turn up:

**** Natural Person                                                                     :general:

Usually a human being. May be resident in any jurisdiction.

May be the estate, personal representative, attorney, etc, of a human being.

**** Organization                                                                       :general:

Synonymous with a corporate person -- anything that is not a natural person. For example, an investment holding company may be a corporate shareholder.

*** Roles

The following roles exist with-respect-to the Company.

**** General Role Attributes
a role relationship starts and stops in time. So we need [[https://en.wikipedia.org/wiki/Bitemporal_data][bitemporality]].

**** Director Role                                                                      :general:

**** Shareholder Role                                                                   :general:

May be of a specific class of shares.

**** Bondholder Role                                                                    :general:

Of a specific security.

**** Warrantholder Role                                                                 :general:

Of a specific security.

**** Investor Role                                                                      :general:

**** Member Role                                                            :SG:SG_CA50_20160103:

Often synonymous with shareholder, but specifically defined as a person entitled to receive notices of meetings.

Not tagged as global because the notion of a member may not be common outside Singapore jurisdiction.

*** Entities Out of Scope                                                                :general:

The resolution model does not claim to cover:

**** Companies Limited by Guarantee
**** Trusts
**** Public Companies

* Modeling the Drafting
Within a contract, we deal with terms and content. This model cares about the conceptual/abstract representation, also known as the formal representation. It also cares about the physical text in a natural language. The physical text may include formatting instructions.

** Contract-Level Examples
*** Example 1A: definition
#+NAME: 1A round definition series seed
#+BEGIN_SRC js
  var investment = newRound( {
    security: "SeriesSeed",
    parties: {
      company: "MyCompany",
      new_investors: [ { name: "Alice", commitment: 100000 },
                       { name: "Bob",   commitment:  50000 },
                       { name: "Carol", commitment:  20000 } ] },
    terms: {
      pre_money_valuation: 10000000,
      round_size:           1000000,
      esop:                      15
    }
  } );
#+END_SRC

This is the formal representation defining a simple Series Seed investment round. The meat of the definition is your basic JSON data structure, which could be constructed by a UI or read out of a spreadsheet.

*** Example 1B: export to natural language
#+NAME: 1B export natural
#+BEGIN_SRC js
investment.workflows().export_as({format:"XML", lang:"en-US"});
#+END_SRC

This outputs all the paperwork required to effect the round, in XML format, suitable for import into InDesign and subsequent output to PDF.

In practice the workflows() method runs prerequisites(), agreements(), and filings().

*** Example 1C: export to formal representation
#+NAME: 1C export formal
#+BEGIN_SRC js
investment.agreements("shareholder").export_as(format:"javascript");
#+END_SRC

produces a bunch of Javascript. See the next example for a microscopic view of the clause-level exports.

** Clause-Level Examples

The Series Seed v3.2 Certificate of Incorporation contains a clause:

#+BEGIN_QUOTE
Mandatory Conversion. Upon either (a) the closing of the sale of shares of Common Stock to the public in a firm-commitment underwritten public offering pursuant to a prospectus filed under the Securities and Futures Act or (b) the date and time, or the occurrence of an event, specified by vote or written consent of the Requisite Holders at the time of such vote or consent, voting as a single class on an as-converted basis (the time of such closing or the date and time specified or the time of the event specified in such vote or written consent,the <b><i>“Mandatory Conversion Time”</i></b>), (i) all outstanding shares of Series Seed Preferred Stock will automatically convert into shares of Common Stock, at the applicable ratio described in Section <xref to="conversionratio" /> as the same may be adjusted from time to time in accordance with Section <xref to="conversion" /> and (ii) such shares may not be reissued by the Company.
#+END_QUOTE

In this example, we'll see how Legalese represents that clause. In particular, we are interested in how the formal representation affords natural language generation.

*** Exposition in Lay Terms

The Gentle Reader may not be familiar with the semantics of this clause. If you need help understanding the clause, read on.

The context: the Company's constitution defines a class of shares called "Series Seed". A class attribute is "mandatory conversion". This clause describes when mandatory conversion can happen.

What does conversion mean? Series Seed shares turn into Common Stock.

What does mandatory conversion mean? That the conversion happens automatically, when some other condition is met. Neither the Company nor the Series Seed Holders can block the conversion.

What conditions trigger mandatory conversions? It turns out there are three possible triggers.

First trigger: there is an IPO -- an Initial Public Offering. Shares of the company are sold to the public in a public offering.

Second trigger: a certain voting majority of the Series Seed Holders agree to 

If any of these triggers occurs, then mandatory conversion follows.

*** Example 2A: Conversion
#+NAME: 2A conversion clause retrieval
#+BEGIN_SRC js
var clauses = investment.clauses_matching("conversion");
#+END_SRC

returns

#+NAME: 2B conversion clause content
#+BEGIN_SRC js
  [ { clauseName: { "en-US": "Mandatory Conversion" },
      handler: function(events) {
    for (var event_i in events) {
      var event = events[event_i];
      var parties = event.parties;
      var respect = event.respect; // party with deontic obligation perspective
      if (event.name == "IPO" ||
          event.name == "classVote") {
        var company = this;
      }
    }
      }
    } ]
#+END_SRC


*** Example 2B: 

** Prerequisites
To understand this section, you should:
- be reading <NAME>, A Manual of Style for Contract Drafting
- understand what a context-free grammar is, and be familiar with Backus-Naur Form
- read https://drive.google.com/open?id=0BxOaYa8pqqSwTC04OTF5b1hYams Some computational properties of a model for electronic documents, TBC 1989
- view https://drive.google.com/open?id=0BxOaYa8pqqSwUWlCajFJQURXdG8 introducing deontic logics, Gorin 2010
- read http://wyner.info/research/Papers/2014/NL_DeonticConcepts_Lux_2014.pdf another perspective on deontic logic
- read http://wyner.info/research/Papers/2013/WynerICAIL2013Tutorial.pdf discussing text extraction
- read http://wyner.info/research/Papers/2013/OASISLegalRuleML.pdf on LegalRuleML.
- read http://wyner.info/research/Papers/WynerPetersJURIX2011.pdf -- Wyner 2011, /On Rule Extraction from Regulations/
- read https://drive.google.com/a/legalese.io/file/d/0BxOaYa8pqqSwWk9NallEck83T2M/view -- CLAN 2009
- read https://drive.google.com/a/legalese.io/file/d/0BxOaYa8pqqSwSjRMeGtzVGhIaWs/view -- FormaLex 2011

** Formal Representation

Formally, a legal document obeys a grammar. In this document, we treat "grammar" and "schema" as [[https://www.w3.org/People/Bos/Schema/schemas][rough homomorphisms]], with schemas being slightly more specific and grammars being slightly more general.

Different jurisdictions may impose different schemas. For example, a contract written in the US style will look different from a contract written in the UK style. However, both documents will exhibit a high degree of structure. A family of UK documents will share the same schema.

A rough schema for a contract could be: title, date, parties, recitals, definitions, conditions precedent, main part, standard bits, signatures. The main part is composed of a list of clauses.

A rough schema for a directors' resolution could be: letterhead, item [...], signatures. Each item is either a Resolved or a Noted.

** Regulations and Contracts as Business Logic

In an application, "business logic" is typically encoded in machine-executable form by a domain expert. Sometimes, DSLs are employed.

In the legal domain, we consider business logic to take two forms: regulatory constraints; and legal agreements and other resolutions. For short, we call these "public" and "private" legal logic respectively.

The public legal logic imposes constraints -- /involuntary/ deontics.

The private legal logic expresses constraints -- /voluntary/ deontics -- and performative statements.

Public and private logics interact constantly. For example, if a corporation performs action A by executing paperwork P, then a legally mandated filing F must be performed by date D else the corporation will be subject to penalties. A and P are private. F and D are public.

The academic literature has explored the formalization of regulations, typically in the form of XML syntax or linguistic parse trees.

The academic literature has explored the automation of the formalization of regulations, using software like GATE.

The academic literature has explored the formalization of contracts.

The literature has not, however, explored the generation of natural-language contracts from a formalization.

The literature also has not explored the generation of the formalization from the constraint.

Our goal is to produce an executable program, whose correspondences with the regulations are semantic, not syntactical.

Our approach departs from the prior art in a key way: we treat the formalization problem and goal as a problem in business logic modeling, rather than a problem in linguistic parsing.

At present, a domain expert is required to encode such business logic. We seek to advance the state of the art from syntax to semantics.



At present, once business logic is encoded into an application, that logic is executed by machine, but the whys and wherefores that led to a particular outcome are often obscured. We 


** Primitives

*** The Schema
*** The Clause / Article / Section
*** The Definition

** Dimensions
There are many ways to represent a given clause. Some dimensions of interest are:

*** Formal vs Natural Language Representation

A concept may be expressed formally.

A concept may be expressed naturally, in a language like English.

A concept may be expressed in a hybrid of formal and natural -- see [[https://en.wikipedia.org/wiki/Controlled_natural_language][Controlled Natural Languages]], e.g. [[https://en.wikipedia.org/wiki/Attempto_Controlled_English][Attempto]].

*** Compactness vs Completeness

For compactness, we want to be able to summarize a clause as tersely as possible.

For completeness, we want to be able to expand a clause, to "look inside" it both syntactically and semantically.

*** Locality and Coupling

Some clauses are limited in scope. A standalone clause does not modify, and is not modified by, any other clause.

Other clauses are highly coupled. A coupled clause explicitly modifies, or is explicitly modified by, another clause.

{'fraction_non_alphanumeric': 0.06341013051324017, 'fraction_numerical': 0.011078937429182928, 'mean_word_length': 3.2080169521455058, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 16, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853001', 'n_tokens_mistral': 6097, 'n_tokens_neox': 5630, 'n_words': 2907}