Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to py3 #35

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
/web2py/parameters_*.py
/web2py/welcome.w2p
/web2py/NEWINSTALL
/db
/apps/temp*
/apps/20newsgroups_*
**/*.bak
3 changes: 2 additions & 1 deletion bin/export_corpus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys
sys.path.append("web2py")

Expand All @@ -9,7 +10,7 @@

def ExportCorpus(database_path, corpus_filename):
database_filename = '{}/corpus.db'.format(database_path)
print 'Exporting database [{}] to file [{}]'.format(database_filename, corpus_filename)
print('Exporting database [{}] to file [{}]'.format(database_filename, corpus_filename))

with Corpus_DB(database_path) as corpusDB:
corpusDB.ExportToFile(corpus_filename)
Expand Down
3 changes: 2 additions & 1 deletion bin/export_spreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys
sys.path.append("web2py")

Expand All @@ -12,7 +13,7 @@

def ExportSpreadsheet(database_path, spreadsheet_filename, id_key, content_key, is_csv):
database_filename = '{}/corpus.db'.format(database_path)
print 'Exporting database [{}] to spreadsheet [{}]'.format(database_filename, spreadsheet_filename)
print('Exporting database [{}] to spreadsheet [{}]'.format(database_filename, spreadsheet_filename))

with Corpus_DB(database_path) as corpus_db:
corpus_db.ExportToSpreadsheet(spreadsheet_filename, is_csv = is_csv, id_key = id_key, content_key = content_key)
Expand Down
5 changes: 3 additions & 2 deletions bin/import_corpus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys
sys.path.append("web2py")

Expand All @@ -13,10 +14,10 @@ def ImportCorpus(corpus_filename_or_folder, database_path):

with Corpus_DB(database_path, isInit=True) as corpus_db:
if os.path.isfile(corpus_filename_or_folder):
print 'Importing file [{}] into database [{}]'.format(corpus_filename_or_folder, database_filename)
print('Importing file [{}] into database [{}]'.format(corpus_filename_or_folder, database_filename))
corpus_db.ImportFromFile(corpus_filename_or_folder)
else:
print 'Importing folder [{}] into database [{}]'.format(corpus_filename_or_folder, database_filename)
print('Importing folder [{}] into database [{}]'.format(corpus_filename_or_folder, database_filename))
corpus_db.ImportFromFolder(corpus_filename_or_folder)

def main():
Expand Down
3 changes: 2 additions & 1 deletion bin/import_spreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys
sys.path.append("web2py")

Expand All @@ -12,7 +13,7 @@

def ImportSpreadsheet(spreadsheet_filename, database_path, id_key, content_key, is_csv):
database_filename = '{}/corpus.db'.format(database_path)
print 'Importing spreadsheet [{}] into database [{}]'.format(spreadsheet_filename, database_filename)
print('Importing spreadsheet [{}] into database [{}]'.format(spreadsheet_filename, database_filename))

with Corpus_DB(database_path, isInit=True) as corpus_db:
corpus_db.ImportFromSpreadsheet(spreadsheet_filename, is_csv = is_csv, id_key = id_key, content_key = content_key)
Expand Down
1 change: 1 addition & 0 deletions bin/read_treetm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import sys
# This adds web2py to path, so that stuff like gluon can be imported properly
sys.path.append("web2py")

import argparse
Expand Down
2 changes: 1 addition & 1 deletion bin/setup_treetm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function __setup_treetm__ {
mkdir -p $EXTERNALS_PATH
mkdir -p $EXTERNALS_SUBPATH
echo " Downloading..."
curl --insecure --location http://www.cs.umd.edu/~ynhu/code/tree-TM.zip > $EXTERNALS_SUBPATH/tree-tm.zip
curl --insecure --location https://github.com/BYU-NLP-Lab/ITM_Mallet/raw/master/tree-TM.zip > $EXTERNALS_SUBPATH/tree-tm.zip
echo " Extracting README..."
unzip $EXTERNALS_SUBPATH/tree-tm.zip tree-TM/readme.txt -d $EXTERNALS_SUBPATH &&\
mv $EXTERNALS_SUBPATH/tree-TM/readme.txt $EXTERNALS_SUBPATH/README &&\
Expand Down
6 changes: 4 additions & 2 deletions bin/unpack_ChinaRuns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division
from past.utils import old_div
import sys
sys.path.append("web2py")

Expand Down Expand Up @@ -49,11 +51,11 @@ def main():
"value" : topic_weight
})
for elem in data:
elem['value'] = elem['value'] / max_value
elem['value'] = old_div(elem['value'], max_value)

filename = '{}/meta.json'.format(path)
with open(filename, 'w') as f:
json.dump(data, f, encoding = 'utf-8', indent = 2, sort_keys = True)
json.dump(data, f, indent = 2, sort_keys = True)

if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions bin/unpack_PoliblogRuns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division
from past.utils import old_div
import sys
sys.path.append("web2py")

Expand Down Expand Up @@ -51,11 +53,11 @@ def main():
"value" : topic_weight
})
for elem in data:
elem['value'] = elem['value'] / max_value
elem['value'] = old_div(elem['value'], max_value)

filename = '{}/meta.json'.format(path)
with open(filename, 'w') as f:
json.dump(data, f, encoding = 'utf-8', indent = 2, sort_keys = True)
json.dump(data, f, indent = 2, sort_keys = True)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions dataset_src/controllers/upload.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from builtins import str
import csv
import os
from db.Corpus_DB import Corpus_DB
Expand Down
21 changes: 11 additions & 10 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import argparse
import subprocess

Expand All @@ -13,9 +14,9 @@
def Shell(command):
p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
while p.poll() is None:
line = p.stdout.readline().rstrip('\n')
line = p.stdout.readline().decode('UTF-8').strip('\n')
if len(line) > 0:
print line
print(line)

def Demonstrate(dataset, model, is_quiet, force_overwrite):
database_folder = 'data/demo/{}/corpus'.format(dataset)
Expand Down Expand Up @@ -59,15 +60,15 @@ def ImportModel():
command.append('--overwrite')
Shell(command)

print '--------------------------------------------------------------------------------'
print 'Build a topic model ({}) using a demo dataset ({})'.format(model, dataset)
print ' database = {}'.format(database_folder)
print ' corpus = {}'.format(corpus_folder)
print ' model = {}'.format(model_folder)
print ' app = {}'.format(app_name)
print '--------------------------------------------------------------------------------'
print('--------------------------------------------------------------------------------')
print('Build a topic model ({}) using a demo dataset ({})'.format(model, dataset))
print(' database = {}'.format(database_folder))
print(' corpus = {}'.format(corpus_folder))
print(' model = {}'.format(model_folder))
print(' app = {}'.format(app_name))
print('--------------------------------------------------------------------------------')

PrepareDataset()
# PrepareDataset()
PrepareModel()
PrepareOthers()
TrainModel()
Expand Down
7 changes: 4 additions & 3 deletions echo_src/controllers/default.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from builtins import str
import json

def index():
Expand All @@ -9,8 +10,8 @@ def index():
value = envObject[ key ]
if isinstance( value, dict ) or \
isinstance( value, list ) or isinstance( value, tuple ) or \
isinstance( value, str ) or isinstance( value, unicode ) or \
isinstance( value, int ) or isinstance( value, long ) or isinstance( value, float ) or \
isinstance( value, str ) or isinstance( value, str ) or \
isinstance( value, int ) or isinstance( value, int ) or isinstance( value, float ) or \
value is None or value is True or value is False:
envJSON[ key ] = value
else:
Expand All @@ -30,6 +31,6 @@ def index():
'extension' : request.extension,
'now' : str( request.now )
}
dataStr = json.dumps( data, encoding = 'utf-8', indent = 2, sort_keys = True )
dataStr = json.dumps(data, indent = 2, sort_keys = True )
response.headers['Content-Type'] = 'application/json'
return dataStr
2 changes: 1 addition & 1 deletion server_src/controllers/GroupInBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def gib():
handler.UpdateModel()
handler.InspectModel()
handler.LoadGIB()
dataStr = json.dumps(handler.content, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(handler.content, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr
2 changes: 1 addition & 1 deletion server_src/controllers/ScatterPlot1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def gib():
handler.UpdateModel()
handler.InspectModel()
handler.LoadGIB()
dataStr = json.dumps(handler.content, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(handler.content, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr
8 changes: 4 additions & 4 deletions server_src/controllers/TermTopicMatrix1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def StateModel():
with LDA_DB() as lda_db:
handler = TermTopicMatrix1(request, response, bow_db, lda_db)
data = handler.GetStateModel()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr

Expand All @@ -26,7 +26,7 @@ def SeriatedTermTopicProbabilityModel():
with LDA_DB() as lda_db:
handler = TermTopicMatrix1(request, response, bow_db, lda_db)
data = handler.GetSeriatedTermTopicProbabilityModel()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr

Expand All @@ -35,7 +35,7 @@ def FilteredTermTopicProbabilityModel():
with LDA_DB() as lda_db:
handler = TermTopicMatrix1(request, response, bow_db, lda_db)
data = handler.GetFilteredTermTopicProbabilityModel()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr

Expand All @@ -44,6 +44,6 @@ def TermFrequencyModel():
with LDA_DB() as lda_db:
handler = TermTopicMatrix1(request, response, bow_db, lda_db)
data = handler.GetTermFrequencyModel()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr
2 changes: 1 addition & 1 deletion server_src/controllers/TermTopicMatrix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def GetEntry():
with LDA_DB() as lda_db:
handler = TermTopicMatrix2(request, response, bow_db, lda_db)
data = handler.GetEntry()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr
6 changes: 3 additions & 3 deletions server_src/controllers/TermTopicMatrix3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def GetTerms():
with LDA_DB() as lda_db:
handler = TermTopicMatrix3(request, response, bow_db, lda_db)
data = handler.GetTerms()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr

Expand All @@ -26,7 +26,7 @@ def GetTopics():
with LDA_DB() as lda_db:
handler = TermTopicMatrix3(request, response, bow_db, lda_db)
data = handler.GetTopics()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr

Expand All @@ -35,6 +35,6 @@ def GetTermTopicMatrix():
with LDA_DB() as lda_db:
handler = TermTopicMatrix3(request, response, bow_db, lda_db)
data = handler.GetTermTopicMatrix()
dataStr = json.dumps(data, encoding='utf-8', indent=2, sort_keys=True)
dataStr = json.dumps(data, indent=2, sort_keys=True)
response.headers['Content-Type'] = 'application/json'
return dataStr
3 changes: 2 additions & 1 deletion server_src/modules/apps/CreateApp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from builtins import object
import logging
import os
import random
Expand Down Expand Up @@ -29,7 +30,7 @@ def __init__( self, appName, APPS_ROOT = 'apps' ):
def RunCommand( self, command ):
p = subprocess.Popen( command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
while p.poll() is None:
line = p.stdout.readline().rstrip('\n')
line = p.stdout.readline().decode('UTF-8').strip('\n')
if len(line) > 0:
self.logger.debug( line )

Expand Down
5 changes: 3 additions & 2 deletions server_src/modules/apps/SplitSentences.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from builtins import object
import logging
import subprocess

class SplitSentences():
class SplitSentences(object):

SENTENCE_SPLITTER = 'utils/corenlp/SentenceSplitter.jar'

Expand All @@ -16,6 +17,6 @@ def __init__( self, inputCorpusFilename, outputSentenceFilename ):
def Shell( self, command ):
p = subprocess.Popen( command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
while p.poll() is None:
line = p.stdout.readline().rstrip('\n')
line = p.stdout.readline().decode('UTF-8').strip('\n')
if len(line) > 0:
self.logger.debug( line )
Loading