The entire US Code is now online in XML

13 years ago (uscodebeta.house.gov)

I find it amusing that here in Germany, we have that for years:

http://www.gesetze-im-internet.de/

All laws are available in XML, HTML, PDF, etc. The site also provides an RSS feed.

In addition, some enthusiasts regularily download stuff from there and apply those to a Git repository:

https://github.com/bundestag/gesetze

That way, this repository contains not only the current laws, but also the history of how the laws developed!

For the Git repository, the XML version is not used directly, but converted to markdown. This produces very readable diffs:

https://github.com/bundestag/gesetze/commit/f90e8fc8eb20f081...

Wouldn't it be cool if we could finally manage our laws of filing pull requests?

  • Likewise in the UK:

    http://www.legislation.gov.uk/developer/formats/

    XML, HTML, RDF/XML for everything, as well as browsable online (often with original source PDFs of the printed laws), with both online and RDF/XML representations showing all alterations to the law (with date, cross-reference to the Act that made the amendment, etc.).

    The website is one of the big success stories of RDF, IMO, as it is all based around a model of the laws in RDF, with everything else just being varying serializations thereof. It also allows the website to show what has been amended — no need for dumping stuff to GitHub and then diffing it! (e.g., see the annotation on 28(1)c in http://www.legislation.gov.uk/ukpga/1998/29/part/IV)

    That all said, there tends to be a delay between the PDF being uploaded and everything being marked up and entered into the RDF database (see the "new legislation" on the home page).

  • I actually wrote a tumblr post about that a while ago. It also included a user engagement aspect that would allow users to subscribe to topics of interest to receive a curated feed of changes that could each have a dialogue/poll emerge. I hadn't really thought through the specifics but its awesome to know that something like this is already started to some degree. Thanks for that!

    Here's the post if interested.

    http://proggr.tumblr.com/post/52801512630/githubberment

  • In France, all is on the Web, but you’re not allowed to crawl it unless you pay :/

I'm really tempted to collect the XML files and put them on github, with periodic checkpoints to update it with the latest.

Watching the evolution of law over time is a fascinating thing and using SW engineering tools to help would be really fun.

Caveat for for many of us overly rational thinkers: the powers that be deliberately are allowed to 'interpret' this code nondeterministically by many different means including its 'spirit,' admissibility of relevant information, manipulation of venue and participants, apparently even extrajudicial proceedings lately.

In short, that allows a lawyer to answer almost any question with "it depends," and start billing.

  • "In short, that allows a lawyer to answer almost any question with "it depends," and start billing. "

    No, this is usually "lack of sufficient facts to answer question".

    If a crime has 4 elements, and you've said you've committed 3 and maybe the 4th depending on how you look at it, the answer to the question "can i be convicted" is "it depends", because it depends on the argument about the 4th element.

    If your followup is to claim that there should never be questions about whether you've achieved some element of a crime, it should be binary, that's simply impossible.

    Crimes, for example, are often about intent and causation. Until science provides us with historical mind reading devices, and completely accurate point-in-time reconstruction of the world, we're going to have to rely on various theories and evidence (much like science relies on theories and evidence).

    Even point-in-time reconstruction wouldn't solve all causation issues, because the issue is often a fairness one: Is it fair to hold the defendant liable for a crime X steps removed from his own action.

    • Right. It should be noted that appellate practice, which is really where the big debates about legal interpretation happen, the "what does this comma mean" work, is not exactly a cash cow for the industry. It's a brand-building practice, but outside boutiques it's not what pays the rent. What pays the rent is factual disputes, where its pretty clear what the law is, but there is disagreement about who did what with what intent and how much did it cost.

  • With respect, only someone who hasn't studied law could say this.

    Law is complicated and filled with ambiguity because the world is complicated and filled with ambiguity.

    Unlike lawyers, we can simply will some of that away. We can make an enum which smooshes together disparate phenomena, that feeds a dropdown list and require the customers to use it. We can ignore very rare corner cases and include a comments field. We can do a lot of things to simply make essential complexity go away while we bicker amongst ourselves about accidental complexity.

    Law can't do that. Law must treat all cases, all combinations, as they arise. Every single day a configuration of people, motives and circumstances emerges that has never before emerged, could not have been foreseen and which may never occur again. The law must still apply.

    Law is hard because the problem domain is everything humans do.

    Let me know how many story points you think that scope is worth.

    • > Law is complicated and filled with ambiguity because the world is complicated and filled with ambiguity.

      True, yet I'm convinced by obvious ambiguity that it's on purpose, to feed the legal industry. That conviction is bolstered by all the "work" Congress does on reviving sunset clauses on laws that had no good reason to sunset.

      5 replies →

    • That's one of the reasons I am a libertarian. Less government means less complex law means less bugs and abuses of the law. If your government tries to say what you can or can not eat, for example, you need complex law to figure out what is cheese and how big the holes in it must be. If you can eat whatever you like and the government couldn't care less, you do not need any of that. So tell me - do we really need a law specifying which size holes in the cheese must be?

      14 replies →

    • Also, if something use case comes up that your software didn't handle, you can write new code to handle it and rerun the old data. You cannot do that with law, you can't write new law and use it to punish past action.

  • Interpretation isn't an unguided, irrational process. When your lawyer answers "it depends" its because you've placed him at one point in what's really a decision tree and asked him: "where does it end?" It's like asking a programmer whether a particular token in a C++ program is a type name or an identifier. It depends.

    If you imagine the universe of human activity as a multi-dimensional space, you can think of laws as carving out subspaces with lines (that may be more or less fuzzy) and attaching significance to particular subspaces. If I ask: "my x coordinate is 5, where am I?" what do you answer?

  • You make this sound like a bad thing. Would you really prefer "black and white" laws that leave zero room for flexibility or interpretation in light of a given situation?

    • This preference isn't even black and white.

      One quote that sticks in my mind is this one from P.J. O'Rourke in Parliament of Whores, concerning Ken Starr's written position on a flag-desecration law:

          Congress had "acted narrowly." (That is, the law is very specific, and you
          can't be arrested for having a smart look on your face near the flag or
          anything like that—which is good because being specific is the essence of
          lawmaking and the whole difference between having a congress and having a
          mom.)
      

      The point here is that specificity is good so that J. Random Citizen can easily know if they are breaking the law or not.

      But this is the reason that we have the ability to have the law interpreted on a case-by-case basis, which is different from interpreting "laws", the specific as-written instances. Note that the Supreme court doesn't hear or decide on a law randomly, only when someone brings a specific case to them.

      The law should be written as "it's a crime to kill someone" (although, that may be too specific, and a more appropriate wording may be "it's a crime to rob someone of their life and livelihood"), and it's up to the executive and judicial branches to decide (or aid in deciding in the case of the executive) what the punishment should be. This is the defendant's "day in court", as it were.

      I think too many people do treat the law as absolute in wording, rather than absolute in spirit. A law that enforces something unjustly on the defendant is just as bad as a law that doesn't justly enforce the plaintiff's rights. Finding that appropriate middle ground is the basis for the grey area that is the interpretation of law.

      IANAL.

      2 replies →

    • Yes, we should have black and white laws, and unit tests for them. So someone could write a unit test for "Will this allow the NSA to create a secret court that is outside the rule of law?" or "Does accessing a university computer that has an open access policy allow for a sentence of 130 years?"

      I believe we'd see a lot simpler laws.

      38 replies →

    • To bring this into context, legislatures have actually been trying to reduce flexibility in several areas of the law recently, most notably in sentencing guidelines.

      This can result in some bizarrely harsh sentences -- where a domestic violence victim firing a warning shot at her abuser gets 20 years in prison, or where someone who knowingly writes a bad check gets 25 years in prison.

    • When that black and white law is:

      Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.

      I'll go with yes. Alas, interpretation then falls to the definition and grammar of every part of said law.

      2 replies →

    • I've never been able to decide whether or not we should rigorously enforce Title 4 Chapter 1. On one hand, such enforcement would be ridiculously overbearing. On the other hand, such enforcement would be ridiculously overbearing.

  • It doesn't matter as much as you say. The fact is, at the very least we can now know better where the fenceposts are, and this will have the undeniable effect of creating a more educated citizenry. A secondary effect is that motivated people can now create tools that reveal ways in which legislators are positioned in relation to those fence posts, and why their interpretations (such as they may be rationalized in accordance with your observation regarding law enforcement) are positioned where they are.

    Perhaps most importantly, this will serve to make the law shallower. Currently, many laws are passed with large parts in reference to other laws, definitions from 400 pages elsewhere in the text (themselves with referential connections to disparate locations), and providing a way to analyze the law programmatically will have inevitable analytical benefits that allow citizens to know exactly how the sausage is made, whose farm the animals are coming from, and how it's been spiced.

  • There is this wonderful article by John Hasnas, "The Myth of the rule of law". It brings a number of very interesting ideas:

    * The law is inconsistent and possess contradictory rules. From contradictory premises, sound arguments

    * It gives concrete examples of legal cases and how completely opposite judgments could be rendered, both being based on correct use of laws and analysis.

    * Laws are not applied impartially, are not neutral, apolitical nor objectively applicable by judges. People who believe they live under "a government of laws and not people" tend to view their nation's legal system as objective and impartial. Obey and subject themselves.

    * There is a cognitive dissonance between the laws and the people who make them. People generally believe that the law are generally good and should be obeyed. People generally believe that politicians tend to be corrupt and influenced. The people who make the law cannot be trusted but yet the laws they write should be.

  • At least for me, accustomed to logic, determinism and mathematical models for laws of nature, this was actually a surprise. Instinctively I still find it distasteful, though I can't say I have anything better to offer other than the unrealistic ideal that all judges would be guaranteed to be truly impartial. I have never directly benefited nor been harmed by the nature of this 'code' either, unless you count getting out of traffic tickets by switching on a learned persona that has people skills.

    • > the unrealistic ideal that all judges would be guaranteed to be truly impartial.

      Even this isn't necessarily a good thing. Part of the value of a judge is having an empathetic element in the position of final arbiter. Decisions aren't always "GUILTY / NOT GUILTY"; they're often long-form essays discussing the merits of the case, the factors under consideration, the logic and reasoning behind the ultimate conclusion and so on.

      Math is nice because it can be reduced to a symbolic language. We're not at the point where we can reduce human beings to symbols yet.

      1 reply →

  • No, judges (who mainly interpret words in laws and partially juries), are not allowed to just make things up all the time, which is what you're implying.

  • I can't believe that comments like this get upvoted by the same people who decry the practice of viewing programmers as monkeys or typists.

    Good luck starting your own country with a legal system that doesn't require interpretation, or heaven forbid, lawyers.

  • If I used a LinkedList in my code instead of an Array will it speed things up?

    It depends...

  • The US legal system is case law. of course, that makes interpretation even more non-deterministic, as you depend on your $10,000/hr legal team to dig up favorable ruleings

This is pretty awesome, and if it were in git/hg would have the ability to write a 'blame' tool to figure out who voted on the part of the law that is pissing you off :-)

  • Actually, you wouldn't. This is the US code, not the legislative info :)

    I actually tried to create this once (with a team behind me, in fact) with what's available or possible with the legislative info.

    THOMAS theoretically published in XML, but it's missing a lot of info.

    Not only is this info not published, it's not even stored. They still are literally passing bills around to each other in some cases. You'd have to sit in on committee markup hearings, etc.

    Even the small amount that is published from markups or whatever doesn't tell you who did it, only that it was done.

    Some committees were willing to give more info. None were willing to essentially publish the in-flight staff attorney or other versions that would tell you for real who changed something.

    Remember also that hg/git diff does not display what really happened.

    It is displaying "how can i produce version B from version A using some minimal or near-minimal set of changes", converted to a line (or sub-line) based set of changes.

    This does not tell you history, only one possible set of changes.

    THOMAS does publish some in-flight versions of bills, but again, it's not really enough to do what you really want to do. I can tell you a bill changed between introduction and markup, and was different again when it got back to the floor. I can even, in some cases, tell you what was amended/deleted. I can't tell you who did it.

    (Well, i can tell you with some percentage accuracy, because we built a machine learning model, but ..)

    • The US system of legislative development is quite flawed. There are a lot of places where changes can be made without attribution, emerging from committees without saying who added what.

      In most Parliamentary democracies you can only propose amendments from one of the two chambers, so any amendment can always be traced to the Parliamentarian who moved it.

      2 replies →

  • You can already do this - Congressional voting records are publicly available. However, even if you correlated these records with specific legislation, you would be making a dangerous mistake by missing the big picture.

    Many laws are passed jn bundles and require compromise. Just because your Senator voted to support farm subsidies, doesn't mean he likes them - it just means he wanted a minimum wage increase to pass more.

This actually makes law accessible to the technologically-savvy out there, and is going to launch a thousand apps giving specialized legal advice.

This could in turn mean a reduction in the cost of litigation, which would hopefully be passed on to the rest of us.

Hopefully I won't get sued for that statement.

  • Hopefully, as a result, the disturbing statements like the ones below will become obsolete:

    James Duane, Regent Law School professor, defense attorney:

    "Estimates of the current size of the body of federal criminal law vary. It has been reported that the Congressional Research Service cannot even count the current number of federal crimes. These laws are scattered in over 50 titles of the United States Code, encompassing roughly 27,000 pages. Worse yet, the statutory code sections often incorporate, by reference, the provisions and sanctions of administrative regulations promulgated by various regulatory agencies under congressional authorization. Estimates of how many such regulations exist are even less well settled, but the ABA thinks there are ”nearly 10,000.” http://youtu.be/6wXkI4t7nuc?t=5m18s

    Supreme Court Justice Breyer:

    "the complexity of modern federal criminal law, codified in several thousand sections of the United States Code and the virtually infinite variety of factual circumstances that might trigger an investigation into a possible violation of the law, make it difficult for anyone to know, in advance, just when a particular set of statements might later appear (to a prosecutor) to be relevant to some such investigation." http://www.law.cornell.edu/supct/html/98-93.ZD.html

  • or, after people get burned a few times with bad legal advice from those apps, it'd drive up demand for actual legal advice.

If you were to start a new country, what would the legislative process look like there? For example, how should new "startup nations" like BlueSeed (http://blueseed.co) inspired by Seasteading Institute go about passing and storing laws? Should they have some sort of open github repo to which anyone can make pull requests? How do you see the congress of the future?

  • You can look at relatively small jurisdictions and copy what's appropriate. Throw out hunting and fishing and take Alaska's laws in 1959 and you've got the minimum for a jurisdiction. Same for the Canal Zone. You can add legislation from other jurisdictions that works, like New Zealand's torrens (not torrent) system. Alberta's condo laws. I wrote a set of laws for a new jurisdiction, there's no reason to start from scratch.

Doesn't appear to include codes and standards which are included by reference such as NFPA, IBC, IRC, SAE, etc. (see [1] for a non-gov't project to publish those)

Nevertheless it is a very good thing to see the the gov't publish (most of) the law in an easy to use format.

[1] https://public.resource.org/

For those of us who don't know anything about it, what are the uses of machine readable law?

  • Just from a Natural Language perspective, this is amazing. By using the code as as a corpus, we can see how differently legal language differs from day-to-day parlance. Such an analysis might be fascinating, especially if we compare to word frequency in Google Ngram's historical index. I suspect legal language trails several decades behind modern lingo.

    Semi-intelligent queries can be executed, such that ignorance of the law might be abated. Imagine saying "Siri, is it illegal to do X?" and Siri answering you. This is important, because of the "Three Felonies a Day" syndrome with unwitting violations of the law. http://www.amazon.com/Three-Felonies-Day-Target-Innocent/dp/...

  • The law can be interpreted as a set of rules matched against an action in a particular context to determine whether said action is legal.

    Right now lots of people do this manually.

    Maybe computers can do it better.

    If computers can do it better, maybe people could focus on writing new laws and refactoring old ones instead of repeatedly interpreting old laws for each case.

    • Yup, legal code isn't that different from computer code where a judge is the interpreter and evidence is fed as input.

      If we could invent a computer interpreter that acts as a judge, laws and contracts being its code might make it obvious to lawyers why it doesn't make sense to allow code to be patented.

      Every time lawyers would write laws or contracts they would have to avoid using legal ideas that have already been patented subjecting them to the same legal difficulties software developers face every time they write code.

      I guess I should patent that invention.

      3 replies →

It's tragic that the United States (Federal) Legislative Model (USLM) is defined in terms of W3C XML Schema Definition language (XSD) instead of the comparably sane RELAX NG and its easily interpreted compact syntax. You would think that something this important ought to be made clear and understandable.

EDITED TO CLARIFY: The tragic part isn't that the schema is given in XSD but that it's defined in XSD, which lacks RELAX NG's simple semantics and composibility rules. For a good summary of what I'm referring to, see James Clark's message to the IETF on the subject:

http://www.imc.org/ietf-xml-use/mail-archive/msg00217.html

  • In practice, it probably doesn't make any difference. Assuming, for the sake of argument, that XSD is expressive enough to allow the authors to say what they're trying to say, in an unambiguous way, it's more or less a moot point. RELAX/NG is awesome, sure... but to some extent the "war" between it and XSD is a religious war.

    Pretty much every popular & widely used language / platform has XSD support... hell, it's so commonplace there are probably schema aware xml parsers in Brainfuck, INTERCAL and Befunge.

    RELAX NG may well be a better choice, but saying this is "tragic" strikes me as a bit of excessive hyperbole.

This reminds me of a recent discussion where someone mentioned tools over process. (http://rc3.org/2013/07/29/seven-signs-of-dysfunctional-engin...)

I would say that the 'law' is just subjective manual process, and we desperately need more tools for every-day judgement and decision making.

For example, if there were a computer system that logged all corporate financial transactions including income, then we could automatically tax large corporations, rather than waiting for them to report income through loopholes.

now if the same could be provided for bills(ideally before they are voted on), and that should go in github or something.

  • Maybe try to organize some tech-minded staffers on the hill? Get them to put bills onto a github repo when they are made public, maybe even XMLizing it to make it more exposed to machine analysis. It'd be a huge step in congressional transparency, especially now that bills are going into the high hundreds and thousands of pages (not a dig at the healthcare bill in particular, just a trend).

Since this is hacker news, I was curious to see which code the subject was talking about and surprisingly not the code I was thinking of. I wonder how much more of this gov code has actually been read by the people in all those countries where it's been available longer.

Putting something online is very different than actually getting meaning out of it. I'm afraid that this will push us towards more laws rather than less. But... Perhaps there will be good machine learning apps that can make sense out of all the contradictions.

This is awesome. They even have a stylesheet apparently.

However though the file claims to be UTF-8, vim seems to disagree, at least for title 10. I can't tell what encoding it really is though, doesn't seem to be latin1 or windows-1252 either.

  • The encoding looks like valid UTF-8, at least for the first few pages that I glanced at.

    I did notice the section references look a little strange in vim, e.g. "act Aug. 10, 1956, ch. 1041, § 1" near the top; it consists of c2 a7 (section sign), which looks fine, followed by e2 80 af (narrow no-break space), which shows up as a box in vim.

Does anyone know what software is used by the hill staffers when drafting new bills? How do they make sure that the laws do not contradict each other?

I can't wait to look for the law whereby Congress established a church in violation of the Establishment Clause. But no one complained.

I'm annoyed that Title 38 - Veteran's Benefits is out of alphabetical order. Was it originally called Pensions or something?

The USC has been available in HTML or ASCII for many years. From house.gov, gpo.gov and cornell.edu, to name a few sources.

does that mean these are all the current federal laws?..

  • This is only the codified portion of the federal law. So called "Statues at Large" that are passed by Congress but not codified into USC are not included. Plus this does not include the federal common law based on the rulings of federal courts.

    • Also there is the Code of Federal Regulations to contend with, but those are available online already.

XML? this should be in json!

  • As the schema guide explains, in 1999 they picked XML based on the study from 1996:

    "Following a 1999 feasibility study on XML/SGML, the Committee on House Administration adopted XML as a data standard for the exchange of legislative documents" http://uscodebeta.house.gov/download/resources/USLM-User-Gui...

    It took the US Govt 17 years to release 200,000 pages of the US code in XML.

    • I think the most time consuming part of the conversion is from text to digital. That's what took so long.

      Interchanging formats should be relatively easy. Back in 1999, json wasn't even around.

      IMO in today's API centric, and javascript ruled world. json would be a lot more useful.

      2 replies →

  • Considering typical timescales for this sort of projects, i'd say we should be happy it's not in CSV or SGML.

  • I hope you're joking.

    XML is a superior format for semantically marking up content from a very detail-oriented dataset like this.

  • Given the level of detail in the XML, I shudder to think what monstrosity that would create.

    Heck they didn't even bother to include a way to inherit styles, they are just included in every case.

    • This is surely an artifact of the conversion process. They are not storing the documents internally like this :)