-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ASvyatkovskiy/from_cartesian
Section level support, n-gram features
- Loading branch information
Showing
8 changed files
with
105 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
|
||
import simplejson | ||
import re | ||
|
||
#switch between primary key as a long integer and primary key as a string | ||
use_cryptic_pk = True | ||
|
||
finput = open("/scratch/network/alexeys/bills/lexs/bills_50000.json","r") | ||
|
||
#data first | ||
foutput = open("/scratch/network/alexeys/bills/lexs/sectioned_bills_50000.json","wa") | ||
|
||
#step through JSON. Tokenize "content" string | ||
sec_output_dicts = list() | ||
for line in finput.readlines(): | ||
output_dict = simplejson.loads(line) | ||
sections = re.split("SECTION \d|section \d",output_dict['content']) | ||
filtered = filter(lambda x: len(x) > 170,sections) | ||
for j,section in enumerate(filtered): | ||
sec_output_dict = {'primary_key':'', 'content':None} | ||
|
||
sec_output_dict['content'] = section | ||
sec_output_dict['primary_key'] = str(j)+"_"+output_dict['primary_key'] | ||
sec_output_dicts.append(sec_output_dict) | ||
|
||
for i, sec_output_dict in enumerate(sec_output_dicts): | ||
if not use_cryptic_pk: sec_output_dict['primary_key'] = i | ||
simplejson.dump(sec_output_dict, foutput) | ||
foutput.write('\n') | ||
|
||
#metadata | ||
#FIXME yes... | ||
finput = open("/scratch/network/alexeys/bills/lexs/bills_50000.json","r") | ||
finput_meta = open("/scratch/network/alexeys/bills/lexs/bills_metadata_50000.json","r") | ||
foutput_meta = open("/scratch/network/alexeys/bills/lexs/sectioned_bills_metadata_50000.json","wa") | ||
|
||
#step through JSON. Tokenize "content" string | ||
sec_output_dicts_meta = list() | ||
for line_meta, line in zip(finput_meta.readlines(),finput.readlines()): | ||
output_dict_meta = simplejson.loads(line_meta) | ||
output_dict = simplejson.loads(line) | ||
sections = re.split("SECTION \d|section \d",output_dict['content']) | ||
filtered = filter(lambda x: len(x) > 170,sections) | ||
for j in range(len(filtered)): | ||
sec_output_dict_meta = {'year':None, 'state':'','docid':'', 'docversion':'', 'primary_key':''} | ||
sec_output_dict_meta['primary_key'] = str(j)+"_"+output_dict_meta['primary_key'] | ||
sec_output_dict_meta['year'] = output_dict_meta['year'] | ||
sec_output_dict_meta['state'] = output_dict_meta['state'] | ||
sec_output_dict_meta['docid'] = output_dict_meta['docid'] | ||
sec_output_dict_meta['docversion'] = output_dict_meta['docversion'] | ||
sec_output_dicts_meta.append(sec_output_dict_meta) | ||
|
||
for i, sec_output_dict_meta in enumerate(sec_output_dicts_meta): | ||
if not use_cryptic_pk: sec_output_dict_meta['primary_key'] = i | ||
simplejson.dump(sec_output_dict_meta, foutput_meta) | ||
foutput_meta.write('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
adhocAnalyzer { | ||
numTextFeatures = 5000, | ||
numTextFeatures = 16384, | ||
addNGramFeatures = false, | ||
nGramGranularity = 2, | ||
measureName = "cosine", | ||
inputBillsFile = "file:///scratch/network/alexeys/bills/lexs/bills_3b.json", | ||
inputPairsFile = "/user/alexeys/valid_pairs", | ||
outputMainFile = "/user/alexeys/test_main_output" | ||
inputBillsFile = "file:///scratch/network/alexeys/bills/lexs/sectioned_bills_50000.json", | ||
inputPairsFile = "/user/alexeys/valid_section_pairs_50000test", | ||
outputMainFile = "/user/alexeys/sectioned_output_cosine_50000test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.