Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
alundgard committed Mar 21, 2018
0 parents commit 0e9e074
Show file tree
Hide file tree
Showing 6 changed files with 284,606 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
/node_modules
284,137 changes: 284,137 additions & 0 deletions AllFlexData_ProfileID.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const express = require('express')
const app = express()

app.get('/', (req, res) => {

const num = req.query.num;
const { spawn } = require('child_process');
const pyProg = spawn('python',['./mixer.py', num]);

pyProg.stdout.on('data', function(data) {

// console.log(data.toString());
res.write(data);
// res.end('end');

});
})

app.listen(4000, () => console.log('app listening on port 4000!'))
72 changes: 72 additions & 0 deletions mixer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import json
import random
import sys

# Form a new dialog using paraphrases according to the given index (specify dialogs)
def formDialog(index):
dialog = flexData[index]
newDialog = []
for sen in dialog[1]:
numPara = len(sen[2])
newSen = sen[4]
if numPara > 0:
ranSenInx = random.sample(xrange(0, numPara - 1), 1)[0]
newSen = sen[2][ranSenInx]
newDialog.append([sen[3], sen[0], sen[1], newSen])
newDialogs.append(newDialog)

inputName = "AllFlexData_ProfileID.json" # The input file name
numWantDialog = (int)(sys.argv[1]) # How many new dialogs do you want to generate
flexData = []
# Read input json file
with open(inputName) as json_file:
allData = json.load(json_file)
for ad in allData: # for each dataset
for data in ad["data"]: # for each dialog
flexData.append([data["dialogName"], []])
for sen in data["content"]: # for each sentence in that dialog
paras = [sen["role"], sen["dialogAct"], [], 0, sen["oriSen"]]
sql = "N"
if "sql_annotation" in sen:
if len(sen["sql_annotation"]) > 0:
sql = "Y"
for para in sen["paraphrases"]: # for each paraphrase of this sentence
paras[2].append(para)
paras[3] = sql
index = len(flexData) - 1
flexData[index][1].append(paras)

numDialogs = len(flexData)
divide = numWantDialog / numDialogs
remainder = numWantDialog % numDialogs
newDialogs = []

# randomly select remainder number of dialogs
remDialogs = random.sample(xrange(0, numDialogs), remainder)
for index in remDialogs:
formDialog(index)

# if # of wanted paraphrasing-dialogs > # of original dialogs, then every original dialog will be reformed accordingly
for i in range(0, divide):
for j in range(0, numDialogs):
formDialog(j)

# output new dialogs
dic = []
for i in range(0, len(newDialogs)):
newDialog = {}
dialogId = "dialog" + str(i)
newDialog["dialogId"] = dialogId
newDialog["dialog"] = []
for sen in newDialogs[i]:
newDialog["dialog"].append({"sql" : sen[0], "role" : sen[1], "dialogAct" : sen[2], "sen" : sen[3]})
dic.append(newDialog)

# Write to output json file
# file = open("NewDialogs.json", "w")
# file.write(json.dumps(dic, sort_keys=True, indent=2))

# Send data back to node
dataToSendBack = json.dumps(dic, sort_keys=True, indent=2)
print(dataToSendBack)
sys.stdout.flush()
Loading

0 comments on commit 0e9e074

Please sign in to comment.