Changes

Jump to navigation Jump to search
no edit summary
[[Category:Internal]]{{Project|Has project output=|Has sponsor=McNair Center|Has title=Patent Data Processing - SQL Steps|Has owner=Shelby Bice,|Has project status=Subsume|Has keywords=Tool}}Return to [[Internal Classification::Legacy| Patent Data (Wiki Page)]].
== Objective ==
The schema for the assignees table in '''patentdata''' database is:
Column | Type | Modifiers -------------+-------------------+----------- patent | integer | asgtype | integer | assignee | character varying | city | character varying | state | character varying | country | character varying | nationality | character varying | residence | character varying | asgseq | integer |
The schema for the assignees table in patent_2015 is :
Column | Type | Modifiers
- --------------+---------+-----------
lastname | text |
firstname | text |
'''Overlapping Columns'''
patent_2015 | patentdata --------------+-------------- orgname | assignee city | city country | country patentnumber | patent state | state
These columns will have entries for most rows in the table, because they exist in both tables. The rest of the columns will be populated based on which table the row is coming from.
'''Final Schema'''
 
Table "public.assignees"
Column | Type | Modifiers ---------------+-------------------+----------- lastname | character varying | firstname | character varying | address | character varying | postcode | character varying | orgname | character varying | city | character varying | country | character varying | patentnumber | integer | state | character varying | patentcountry | character varying | nationality2 | character varying | residence | character varying | asgseq | integer | asgtype | integer |
'''Non-overlapping Columns'''
Therefore, if a row has appropriate values for orgname, state, city ,etc, but 'null' values for lastname, firstname, address and postcode, the row has come from the patentdata table.
 
==== Index ====
Since the table is relatively large, and is likely to be searched often, an index has been imposed on the table.
 
allpatent=# CREATE INDEX ON assignees (orgname);
CREATE INDEX
====Sample insert and copy commands ====
==Patents ==
==== INDEX CREATION ====Patent numbers are distinct in this table, and are central to the rest of the fields in the table. A primary key can therefore be imposed on the column. Also, since a number of searches are likely to be conducted on this table, an index has been imposed as well.'''Patentdata Schema:'''
Code: ALTER TABLE patents ADD PRIMARY KEY (patentnumber); -- RESULT : ALTER TABLE allpatent=# CREATE UNIQUE INDEX patent_idx ON patents (patentnumber); Since the table is relatively large, and is likely to be searched often, an index has been imposed on the table. allpatent=# CREATE INDEX ON assignees (orgname); CREATE INDEX Patentdata: Column | Type | Modifiers- --------+-------------------+-----------
patent | integer |
kind | character varying |
appyear | integer |
'''Patent_2015Schema:''' 
Column | Type | Modifiers
-------------------------------+---------+-----------
filename | varchar |
''' Overlapping Columns '''
patent_data patent_2015
--------------+-------------
patent | patentnumber
kind | kind
claims | numberofclaims
apptype | type
appnum | applicationnumber
gdate | grantdate
appdate | filingdate
'''Combined Schema:'''
Column NamesThe final schema of the patents table is : patent int, kind varchar, claims int, apptype int, appnum int, gdate date, gyear int, appdate date, appyear int
Column | Type | Modifiers
----------------------+-------------------+-----------
patent | integer | not null
grantdate | date |
prioritydate | date |
prioritycountry | character varying |
prioritypatentnumber | character varying |
cpcsubgroup | character varying |
pctpatentnumber | character varying |
claims | integer |
appnum | integer |
gyear | integer |
appdate | date |
appyear | integer |
nber | integer |
uspc | character varying |
uspc_sub | character varying |
From the total list of columns belonging to both the tables (patentdata and patent_2015), a few columns, most of them related to classification of patents, have been dropped since the data in the tables was not clean.
patentnumber intAdditionally, three columns -- patent kind varchar, -- kind grantdate date, --gdate type varchar, applicationnumber varcharnber, filingdate dateuspc, prioritydate dateuspc_sub have been added from the historicalpatentdata,a table built from data downloaded from the USPTO Bulk Data Storage. The join was executed on the patent number. prioritycountry varchar, prioritypatentnumber varchar, ussubclass varchar, maingroup varchar, subgroup varchar, cpcsubclass varchar, cpcmaingroup varchar, cpcsubgroup varchar, classificationnationalcountry varchar, classificationnationalclass varchar, title varchar, numberofclaims int, primaryexaminerfirstname varchar, primaryexaminerlastname varchar, primaryexaminerdepartment varchar, pctpatentnumber varchar, filename varchar claims int, apptype int, appnum int, gyear int, appdate date, appyear int Output Schema Note : patents CREATE TABLE patents_merged( patentnumber intThe addition, kind varchar, grantdate date, type varchar, applicationnumber varchar, filingdate date, prioritydate datedeletion of columns as through separate [[Patent Data Cleanup - June 2016 |scripts]], prioritycountry varchar, prioritypatentnumber varchar, ussubclass varchar, maingroup varchar, subgroup varchar, cpcsubclass varchar, cpcmaingroup varchar, cpcsubgroup varchar, classificationnationalcountry varchar, classificationnationalclass varchar, title varchar, numberofclaims int, primaryexaminerfirstname varchar, primaryexaminerlastname varchar, primaryexaminerdepartment varchar, pctpatentnumber varchar, filename varchar, claims int, apptype int, appnum int, gyear int, appdate date, appyear int );therefore the scripts below will be slightly discrepant.
'''==== Index and Key Creation ====Patent numbers are distinct in this table, and are central to the rest of the fields in the table. A primary key can therefore be imposed on the column. Also, since a number of searches are likely to be conducted on this table, an index has been imposed as well. Code: ALTER TABLE patents ADD PRIMARY KEY (patentnumber); -- RESULT : ALTER TABLE allpatent=# CREATE UNIQUE INDEX patent_idx ON patents (patentnumber);   ====Sample Insert and Copy Statements''' ====
patentdata:
INSERT INTO patents_merged
(
SELECT patent, kind, gdate, 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', -1, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', claims, apptype, appnum, gyear, appdate, appyear FROM patents ); -- RESULT : INSERT 0 3984771
patent_2015:
COPY SCRIPTS:
patentdata:
\COPY patents_merged TO '/tmp/merged_patents_export1.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; --COPY 3984771
patent_2015:
\COPY patents_merged TO '/tmp/merged_patents_export.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; --COPY 1646225
PATENTS TABLE
\COPY patents FROM '/tmp/merged_patents_export1.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; -- RESULT : COPY 3984771 \COPY patents FROM '/tmp/merged_patents_export.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; -- RESULT : COPY 1646225 
====TESTING ====
select count(*) FROM (SELECT DISTINCT patentnumber FROM patents) AS t; --RESULT: 5411151 EXPECTED: 5426566
We found some copies of a few rows, where both the patent_2015 and patentdata
SELECT COUNT(*), * FROM patents GROUP BY patentnumber,
kind,
grantdate,
appdate,
appyear
HAVING COUNT(*) > 1;
SELECT patentnumber, count(*) FROM patents GROUP BY patentnumber HAVING count(*)>1; --7640598
SELECT * FROM patents op WHERE op.patentnumber IN
(
SELECT ip.patentnumber
HAVING COUNT(*)>1
)
ORDER BY op.patentnumber;
( SELECT * INTO patentsCleaned FROM patents op WHERE op.patentnumber IN
(
SELECT ip.patentnumber
HAVING COUNT(*)=1
)
ORDER BY op.patentnumber ) --SELECT 5191306
INSERT INTO patentsCleaned( SELECT * FROM patents op WHERE op.patentnumber IN
(
SELECT ip.patentnumber
HAVING COUNT(*)>1
)
AND op.applicationnumber NOT LIKE 'NULL' ORDER BY op.patentnumber );
--219845
====TESTING:==== allpatent=# select count(*) from patentsCleaned; count --------- 5411151 (1 row)
allpatent=# select count(*), patentnumber FROM patentsCleaned group by patentnumber having count(*) > 1; count | patentnumber -------+-------------- (0 rows)
== Citations==
********** INDEX CREATION ************** ALTER TABLE patents ADD PRIMARY KEY In the citations table, we needed to define another function that would convert a textual patent number into a number (patentnumber);-- RESULT : ALTER TABLEallpatent=# CREATE UNIQUE INDEX patent_idx ON big int, since the patents (patentnumber); allpatent=# CREATE INDEX ON assignees (orgnamenumber were exceeding the range of regular integers.);CREATE INDEX == Citations==
To Extract Patents with Numbers Only and to Ignore Other RegExes
CREATE OR REPLACE FUNCTION cleanpatno (text) RETURNS bigint AS $$
if ($_[0]) {
my $var=$_[0];
$$ LANGUAGE plperl;
patentdata:
Column | Type | Modifiers
-------------+-------------------+-----------
patent | integer |
cit_date | date |
cit_name | character varying |
cit_kind | character varying |
cit_country | character varying |
citation | integer |
category | character varying |
citseq | integer |
SELECT patent as citingpatentnumber, citation AS citedpatentnumber
INTO citations_merged
FROM citations;
--SELECT 38452957
'''patentdata schema:'''  Column | Type | Modifiers ------------+-------------------+----------- patent | integer | cit_date | date | cit_name | character varying | cit_kind | character varying | cit_country | character varying | citation | integer | category | character varying | citseq | integer |   SELECT patent as citingpatentnumber, citation AS citedpatentnumber INTO citations_merged FROM citations; --SELECT 38452957 '''patent_2015schema:''' Column | Type | Modifiers ---------------------+---------+----------- citingpatentnumber | integer | citingpatentcountry | text | citedpatentnumber | text | citedpatentcountry | text |
SELECT CAST(citingpatentnumber AS bigint), CAST(cleanpatno( citedpatentnumber) AS bigint) as citedpatentnumber INTO citations_merged FROM citations; -- RESULT : SELECT 59227881
FINAL TABLE:'''Overlapping Columns'''
CREATE TABLE citations patent_2015 | patentdata |( ---------------------+---------------+ citingpatentnumber | patent | citedpatentnumber | citation | ''' Combined Schema:'''  Column | Type | Modifiers--------------------+--------+----------- citingpatentnumber | bigint,| citedpatentnumber | bigint);|
patentdata:
\COPY citations_merged TO '/tmp/merged_citations_export1.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; --COPY 38452957
patent_2015:
\COPY citations_merged TO '/tmp/merged_citations_export.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; -- RESULT : COPY 59227881
allpatent:
\COPY citations FROM '/tmp/merged_citations_export.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; --RESULT : COPY 59227881
\COPY citations FROM '/tmp/merged_citations_export1.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV; --RESULT: COPY 38452957
== USPTO Consolidated Patent Data ==
ScriptsThe USPTO has a repository of patent data on their Bulk Data Storage system. We have this data downloaded and loaded into a table on the patent database. Here are the steps followed:* Download file from the BDS system - we have access to CSV files.* Create table with required specs* use the \COPY command to copy the data from the file into the table.  Script follows. '''Script:'''  /* creating patent data tables from : https://bulkdata.uspto.gov/data2/patent/maintenancefee/*/
/* creating patent data tables from : https://bulkdata.uspto.gov/data2/patent/maintenancefee/*/ CREATE TABLE PatentMaintenanceFee( patentnumber varchar, applicationnumber int, smallentity varchar, filingdate date, grantissuedate date, maintenancefeedate date, maintenancefeecode varchar );
CREATE TABLE \COPY PatentMaintenanceFee(FROM '/bulk/USPTO_Consolidated/MaintFeeEvents_20160613.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV;patentnumber varchar,applicationnumber int,smallentity varchar,filingdate date,grantissuedate date,maintenancefeedate date,maintenancefeecode varchar); -- RESULT : COPY 14042059
\COPY PatentMaintenanceFee FROM ' /bulk/USPTO_Consolidated* creating tables for historical patent data - USPTO */MaintFeeEvents_20160613.txt' DELIMITER AS E'\t' HEADER NULL AS '' CSV;-- RESULT : COPY 14042059
/* creating tables for historical patent data - USPTO */ CREATE TABLE HistoricalPatentData( applicationid int, pubno varchar, patentnumber varchar, NBER int, USPC varchar, USPC_sub varchar, applicationdate date, prioritydate date, pubdate date, displaydate date, disptype varchar, exp_dt date, exp_dt_max date, pta int );
CREATE TABLE HistoricalPatentData(applicationid int \COPY historicalpatentdata FROM '/bulk/USPTO_Consolidated/HistoricalFiles/historical_masterfile.csv' DELIMITER AS ',pubno varchar,patentnumber varchar,NBER int,USPC varchar,USPC_sub varchar,applicationdate date,prioritydate date,pubdate date,displaydate date,disptype varchar,exp_dt date,exp_dt_max date,pta int)' HEADER NULL AS '' CSV;
\ --COPY historicalpatentdata FROM '/bulk/USPTO_Consolidated/HistoricalFiles/historical_masterfile.csv' DELIMITER AS ',' HEADER NULL AS '' CSV;11191813
--COPY 11191813[[Category:Internal]][[Internal Classification::Legacy| ]][[Category:Patent]]

Navigation menu