public static void prepareSurvey() { Map<Integer, SentimentSentence> orderToSentence = importOrderToSentence( PreprocessingForDocumentVector.PYTHON_WORKSPACE + "order-to-sentence.txt"); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("survey"); int count = 0; while (count <= orderToSentence.size()) { Row row = sheet.createRow(count); Cell cellReviewId = row.createCell(0); Cell cellSentenceId = row.createCell(1); Cell cellSentence = row.createCell(2); Cell cellRating = row.createCell(3); if (count == 0) { cellReviewId.setCellValue("review id"); cellSentenceId.setCellValue("sentence id"); cellSentence.setCellValue("sentence"); cellRating.setCellValue("Rating (1, 2, 3 or 4 stars)"); } else { SentimentSentence sentence = orderToSentence.get(count - 1); cellReviewId.setCellValue(sentence.getReviewId()); cellSentenceId.setCellValue(sentence.getId()); cellSentence.setCellValue(sentence.getSentence()); } ++count; } Path outputPath = Paths.get(PreprocessingForDocumentVector.PYTHON_WORKSPACE + "sentiment_survey.xlsx"); try { Files.deleteIfExists(outputPath); wb.write(Files.newOutputStream(outputPath, StandardOpenOption.CREATE)); wb.close(); } catch (IOException e) { e.printStackTrace(); } }
public static void updateSentimentWithVectorMethod( String originalDatasetPath, String updatedDatasetPath) { long startTime = System.currentTimeMillis(); Map<Integer, SentimentSentence> orderToSentence = importOrderToSentence( "src/edu/ucr/cs/dblab/nle020/reviewsdiversity/dataset/doc2vecsent/reviews/all-order-to-sentence.txt"); Map<Integer, Double> orderToSentiment = SentimentExperiment.importSentimentFromRegression( SentimentExperiment.PREDICTED_SENTIMENT_DIR + "full_prediction_ridge.txt"); Map<SentimentSentence, Double> sentenceToSentiment = new HashMap<>(); for (Integer order : orderToSentence.keySet()) { sentenceToSentiment.put(orderToSentence.get(order), orderToSentiment.get(order)); } Map<Integer, List<SentimentReview>> docToSentimentReviews = importDocToSentimentReviews(originalDatasetPath); // Re-assign sentiment of concept in sentence for (Integer docId : docToSentimentReviews.keySet()) { for (SentimentReview review : docToSentimentReviews.get(docId)) { for (SentimentSentence sentence : review.getSentences()) { if (sentenceToSentiment.containsKey(sentence)) { double sentiment = sentenceToSentiment.get(sentence); for (ConceptSentimentPair pair : sentence.getPairs()) { pair.setSentiment((float) sentiment); } } } } } outputDoctorSentimentReviewsToJson(docToSentimentReviews, updatedDatasetPath); System.out.println( "Finish outputing JSON text file to \"" + updatedDatasetPath + "\" in " + (System.currentTimeMillis() - startTime) + " ms"); }