Commit faa34582 authored by Castillo's avatar Castillo

ngrams api

parent d3eb479b
......@@ -32,7 +32,8 @@ class SQL:
# for item in chunk:
# print(item)
args_str = ','.join(cursor.mogrify("%s", (x, )) for x in chunk)
sql = "INSERT INTO publication (id, year,itemset) VALUES "+args_str+""
# sql = "INSERT INTO "+tablename+" (id, year,itemset) VALUES "+args_str+""
sql = "INSERT INTO "+tablename+" (id, label) VALUES "+args_str+""
# print(sql)
try:
......
# pip install simplejson git+https://github.com/miguelgrinberg/Flask-Runner.git
# pip install biopython
# more: https://flask-runner.readthedocs.io/en/latest/
# sudo su pksm3
# export SPARK_HOME="/opt/spark2"
# export PATH=$SPARK_HOME/bin:$PATH
# source env/bin/activate
# python phylum_srv.py -t 0.0.0.0 -p 8080
from flask import Flask, render_template, request , flash , jsonify , url_for
from flask.ext.runner import Runner #*#
import simplejson as json
from flask_wtf import Form
from wtforms import StringField, TextField, IntegerField, DecimalField, validators
from wtforms.validators import DataRequired
from flask_wtf.csrf import CsrfProtect
csrf = CsrfProtect()
import datetime
import pprint
app = Flask(__name__ , static_url_path='/static' )
app.secret_key = 's3cr3t'
csrf.init_app(app)
runner = Runner(app) #*#
from bigindex import LoadShit
import urllib
I = {}
@app.route("/close", methods=("GET",))
def close_contexts():
for i in I:
I[i].sc.stop()
return json.dumps( ["connections","closed"] )
for i in I:
del I[i]
# p_["scontext"] (value="blabla")
# p_["elemfrequency"] (value="1")
# p_["from_"] (value="1983")
# p_["to_"] (value="1984")
# p_["minfpgsupp"] (value="0.0001")
# p_["minfsetsize"] (value="4")
# p_["minsetdistance"] (value="0.2")
# p_["mram"] (value="0.2")
# p_["ncores"] (value="0.2")
@csrf.exempt
@app.route("/ngrams" , methods=("GET", "POST",))
def test_post():
pprint.pprint( request )
if request.method == "POST":
p_ = {}
print( "did a POST" )
for i in request.form:
print( i , ":", request.form[i] )
p_[i] = request.form[i]
rr = {
"hola": "mundo"
}
return json.dumps( rr )
# return json.dumps( ["post","worked","mofos"] )
return json.dumps( ["regular","get"] )
# return jsonify( data=["normal","return"] )
runner.run()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import glob
import json
import pprint
from datetime import datetime
import time
import re
import json
INPUT = "mesh.json"
# OUTPUT = "folder"
if len(sys.argv)>1 and sys.argv[1]!=None: INPUT = sys.argv[1]
# if len(sys.argv)>2 and sys.argv[2]!=None: OUTPUT = sys.argv[2]
import psycopg2
conn = psycopg2.connect("dbname=meshfiltrd user=pksm3")
c = conn.cursor()
sql_commands = [
"DROP TABLE IF EXISTS june2016;",
"CREATE TABLE june2016( id INTEGER PRIMARY KEY , label VARCHAR(255) )",
]
for command in sql_commands:
c.execute( command )
conn.commit()
f = open( INPUT , "r" )
K = json.load( f )
f.close()
DATA = []
DD = {}
C = 1
for ID in K:
# if C==100:
# break
if ID not in DD:
DD[ID] = True
DATA.append( (ID,K[ID],) )
C += 1
print("")
print("inserting...",len(DATA))
from SQL import SQL
execc = SQL()
execc.InsertInto_modular( connection=conn , cursor=c , tablename="june2016" , data= DATA )
print("creating indexes...")
sql_indexes = [
"CREATE INDEX label_idx ON june2016 (label);"
]
for command in sql_indexes:
c.execute( command )
conn.commit()
conn.close()
# # # # CREATE INDEX # #
# # import psycopg2
# # conn = psycopg2.connect("dbname=pubmed user=pksm3")
# # c = conn.cursor()
# # print("creating indexes...")
# # sql_indexes = [
# # "CREATE INDEX year_idx ON publication (year);"
# # ]
# # for command in sql_indexes:
# # c.execute( command )
# # conn.commit()
# # conn.close()
\ No newline at end of file
......@@ -262,6 +262,7 @@ function pubmed_scan( query ) {
retmax: 0
},
success : function(data) {
console.log( data.esearchresult )
var count = parseInt( data.esearchresult.count )
console.log( "AAAAH "+count )
$("#pubmed_scan-results").html( count+" hits." )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment