Skip to content

Commit

Permalink
strom_demo tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhusson committed Nov 4, 2016
1 parent a954022 commit 496cd5f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
1 change: 0 additions & 1 deletion input/url.txt

This file was deleted.

1 change: 0 additions & 1 deletion output/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions output/runs.csv

This file was deleted.

14 changes: 1 addition & 13 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#RUN ALL - STROMATOLITES
#==============================================================================

#path: /Users/jhusson/local/bin/deepdive-0.7.1/deepdive-apps/stromatolites

#==============================================================================

import os, time, subprocess, yaml

#tic
Expand All @@ -18,10 +14,6 @@
#load credentials file
with open('./credentials', 'r') as credential_yaml:
credentials = yaml.load(credential_yaml)


#ensure working directory is proper
#os.chdir("/Users/jhusson/local/bin/deepdive-0.7.1/deepdive-apps/stromatolites")

#INITALIZE THE POSTGRES TABLES
print 'Step 1: Initialize the PSQL tables ...'
Expand Down Expand Up @@ -56,7 +48,7 @@
print 'Step 8: Define the relationships between stromatolite phrases and distant stratigraphic entities/mentions ...'
os.system('python ./udf/ext_strat_target_distant.py')

#DEFINE RELATIONSHIPS BETWEEN TARGET AND DISTANT STRATIGRAPHIC NAMES
#FIND BEGINNING OF REFERENCE LIST
print 'Step 9: Delineate reference section from main body extractions ...'
os.system('python ./udf/ext_references.py')

Expand All @@ -68,10 +60,6 @@
print 'Step 11: Find adjectives describing strom target words ...'
os.system('python ./udf/ext_target_adjective.py')

#POSTGRES DUMP
print 'Step 12: Dump select results from PSQL ...'
output = 'pg_dump -U '+ credentials['postgres']['user'] + ' -t results -t strat_target -t strat_target_distant -t age_check -t refs_location -t bib -t target_adjectives -d ' + credentials['postgres']['database'] + ' > ./output/output.sql'
subprocess.call(output, shell=True)

#summary of performance time
elapsed_time = time.time() - start_time
Expand Down
20 changes: 19 additions & 1 deletion udf/ext_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#GENERATE RESULTS TABLE
#==============================================================================

import time, random, re, yaml, psycopg2, copy
import time, random, re, yaml, psycopg2, copy, csv
from psycopg2.extensions import AsIs

start_time = time.time()
Expand Down Expand Up @@ -164,6 +164,24 @@
#push update
connection.commit()

#write culled results to CSV
cursor.execute("""
SELECT result_id,docid,sentid,target_word,strat_phrase_root,strat_flag,strat_name_id,in_ref,source,phrase
FROM results
WHERE (is_strat_name='yes' AND source='in_sent')
OR (is_strat_name='yes' AND source='out_sent' AND in_ref='no')
""")

results=cursor.fetchall()

with open('./output/results.csv', 'a') as outcsv:
#configure writer to write standard csv file
writer = csv.writer(outcsv, delimiter=',', quoting=csv.QUOTE_ALL, lineterminator='\n')
writer.writerow(['result_id','docid','sentid','target_word','strat_phrase_root','strat_flag','strat_name_id','in_ref','source','phrase'])
for item in results:
#Write item to outcsv
writer.writerow([item[0], item[1], item[2],item[3], item[4], item[5],item[6], item[7], item[8], item[9]])

#close the postgres connection
connection.close()

0 comments on commit 496cd5f

Please sign in to comment.