{"id":4175,"date":"2010-07-07T07:22:59","date_gmt":"2010-07-07T14:22:59","guid":{"rendered":"http:\/\/palblog.fxpal.com\/?p=4175"},"modified":"2010-07-07T07:21:52","modified_gmt":"2010-07-07T14:21:52","slug":"4175","status":"publish","type":"post","link":"https:\/\/blog.fxpal.net\/?p=4175","title":{"rendered":"Parsing patents, take 2"},"content":{"rendered":"<p>Working on parsing and indexing the patent collection that Google made available has been an interesting education in just how noisy allegedly clean data really is, and in the scale of the collection. I am by no means done; in fact, I&#8217;ve had to start over a couple of times. I have learned a few things so far, in addition to my <a title=\"Parsing patents | FXPAL Blog\" href=\"http:\/\/palblog.fxpal.com\/?p=3980\" target=\"_blank\">earlier observations<\/a>.<\/p>\n<h3><!--more-->Data is messy<\/h3>\n<p>The data that the USPTO provided to Google consists of several formats. Older patents (per 2002) are stored in a text format that I described in an earlier post. The 2002 ZIP archive has two files, one with a v2.4 DTD, and one with a v2.5 DTD. The first file has an .sgm extension, the second .xml.\u00a0 The two files seem to contain the same data, however. In any case,the DTDs for 2002-2004 archives are a crazy set of mostly numbered deeply-nested elements such as SDOBI\/B100\/B110\/DNUM\/PDAT which leads to the patent number, and SDOBI\/B700\/B720\/B721\/PARTY-US\/NAM\/SNM\/STEXT\/PDAT which is an inventor&#8217;s last name.<\/p>\n<p>The DTD for the year 2005 (&#8220;us-patent-grant-v40-2004-12-02.dtd&#8221;) is a  variant on the current one, with just a few annoying differences. For  example, the name of the element that contains the &#8220;field of search&#8221;  codes is different: the 2005 version uses &#8220;field-of-search&#8221; while later  ones use &#8220;us-field-of-classification-search&#8221;. 2006 uses v41, butI have not figured out  what the differences are between the v41 and v42 DTD are. In fact, I was  not aware that the DTD for 2006 was different until quite recently.<\/p>\n<p>Finally, the years 2007-2010 share the v42 DTD (&#8220;us-patent-grant-v42-2006-08-23.dtd&#8221;).<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Years<\/strong><\/td>\n<td><strong>Format<\/strong><\/td>\n<td><strong>DTD<\/strong><\/td>\n<\/tr>\n<tr>\n<td>-2001<\/td>\n<td>text<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<tr>\n<td>2002<\/td>\n<td>SGML?<\/td>\n<td>PUBLIC &#8220;-\/\/USPTO\/\/DTD ST.32 US PATENT GRANT V2.4 2000-09-20\/\/EN&#8221;<\/td>\n<\/tr>\n<tr>\n<td>2002-2004<\/td>\n<td>XML<\/td>\n<td>ST32-US-Grant-025xml.dtd<\/td>\n<\/tr>\n<tr>\n<td>2005<\/td>\n<td>XML<\/td>\n<td>us-patent-grant-v40-2004-12-02.dtd<\/td>\n<\/tr>\n<tr>\n<td>2006<\/td>\n<td>XML<\/td>\n<td>us-patent-grant-v41-2005-08-25.dtd<\/td>\n<\/tr>\n<tr>\n<td>2007-2010<\/td>\n<td>XML<\/td>\n<td>us-patent-grant-v42-2006-08-23.dtd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>These small differences are annoying because they make data extraction an uncertain process. Did I actually get all the differences, or will something crop up later that I hadn&#8217;t seen before? As things stand, for example, there are still two samples (from 2002 and from 2009) that failed to get parsed; one produced the following startling error from the SAX parser:<br \/>\n<code><br \/>\n[Fatal Error] :1:1: The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the application.<br \/>\n<\/code><\/p>\n<p>The upshot is that I guess I won&#8217;t know whether I&#8217;ve been able to parse everything until I actually run the entire dataset.<\/p>\n<p>Another set of hard-to-parse data are the classification codes. I am sure they are documented somewhere, but the sheer variety of them makes parsing and formatting them in a consistent and recognizable way a challenge. I still don&#8217;t know what to do with this one, for example: Patent 04795540 for class 204 has a subclass code that reads &#8220;243 R-247&#8221; in the data, but I could not figure out based on <a title=\"Class   204\tCHEMISTRY: ELECTRICAL AND WAVE ENERGY | USPTO\" href=\"http:\/\/www.uspto.gov\/web\/patents\/classification\/uspc204\/sched204.htm\" target=\"_blank\">USPTO documentation<\/a> what that was or how to render it. Google shows it as &#8220;204\/243R&#8221; (search for <a title=\"Google Patent Search\" href=\"http:\/\/www.google.com\/patents\" target=\"_blank\">patent:4795540<\/a>), the PDF file has it as &#8220;204\/243 R-247&#8221; and the USPTO summary has &#8220;204\/243 R-247\/&#8221; with the trailing slash, something that seems inconsistent with their convention of separating the class from the subclass with the slash.<\/p>\n<p>Even such simple things as country names for patent assignees are messy: some patents will add an X to the end of a country abbreviation, producing &#8216;JPX&#8217; for Japan, &#8216;DEX&#8217; for Germany, etc. Others use &#8216;JP&#8217; and &#8216;DE&#8217;. For US patents, some specify the country name, others don&#8217;t.\u00a0 And by far the most surprising assignee for 62 of the 55K patents I have sampled is listed as &#8220;The United States of America as represented by the Secretary of the Army, Washington, DC&#8221;. I wonder what that means: I thought that Federal employees were not allowed to patent inventions, but it&#8217;s seemingly OK for others to assign their inventions to the government. Odd.<\/p>\n<h3>And there is a lot of it<\/h3>\n<p>I&#8217;ve been trying to do test-driven development on this project to learn how and to cope with the evolving code given my understanding of what I am doing. Overall things have gone pretty well, and I have accumulated a bunch of tests for the various document types and field values. But just pulling out a few examples was inadequate, as digging deeper into the dataset produced more and more variations.<\/p>\n<p>I&#8217;ve taken to running my parser on a sample of documents from the past 22 years (one week&#8217;s worth per year) to get decent coverage, but we&#8217;re talking about processing 675 MB of zipped-up data, which takes a few hours on my reasonably-capable unix box.<\/p>\n<h3>In short<\/h3>\n<p>This has been an interesting (if somewhat painful) learning experience. My initial optimism that I could have enough done to write up a submission for the PAIR workshop led me to take a few shortcuts that cost me quite a bit of time, and a chance at actually writing up the work. But I have certainly learned a lot about working with largish datasets. I expect there will be other unpleasant surprises in store, but at least I won&#8217;t be surprised when my code runs for hours and hours without getting anywhere.<\/p>\n<p>I would love to hear from anyone else who has looked at the data or tried parsing it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working on parsing and indexing the patent collection that Google made available has been an interesting education in just how noisy allegedly clean data really is, and in the scale of the collection. I am by no means done; in fact, I&#8217;ve had to start over a couple of times. I have learned a few [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[123,213],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/posts\/4175"}],"collection":[{"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4175"}],"version-history":[{"count":16,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/posts\/4175\/revisions"}],"predecessor-version":[{"id":4180,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=\/wp\/v2\/posts\/4175\/revisions\/4180"}],"wp:attachment":[{"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fxpal.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}