Skip to content

Commit

Permalink
Merge pull request #51 from taciano-perez/create-javafx-gui
Browse files Browse the repository at this point in the history
Create javafx gui
  • Loading branch information
taciano-perez authored Oct 15, 2021
2 parents 54d072f + acbce7b commit 4a27f92
Show file tree
Hide file tree
Showing 71 changed files with 12,896 additions and 92 deletions.
25 changes: 2 additions & 23 deletions api/src/main/java/com/o3/storyinspector/api/BlockApi.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.o3.storyinspector.api;

import com.o3.storyinspector.annotation.blocks.SentenceSplitter;
import com.o3.storyinspector.annotation.readability.FleschKincaidReadabilityInspector;
import com.o3.storyinspector.annotation.wordcount.WordCountInspector;
import com.o3.storyinspector.api.user.GoogleId;
import com.o3.storyinspector.api.user.UserInfo;
import com.o3.storyinspector.db.BookDAO;
import com.o3.storyinspector.domain.Block;
import com.o3.storyinspector.domain.Blocks;
import com.o3.storyinspector.domain.Sentence;
import com.o3.storyinspector.storydom.Book;
import com.o3.storyinspector.storydom.io.XmlReader;
import org.slf4j.Logger;
Expand All @@ -18,8 +13,6 @@
import org.springframework.web.bind.annotation.*;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/blocks")
Expand All @@ -40,25 +33,10 @@ public Blocks findAllByBook(@PathVariable final Long bookId, @RequestParam("id_t
final UserInfo user = userValidator.retrieveUserInfo(idToken);
final BookDAO bookDAO = BookDAO.findByBookId(bookId, db);
if (!user.isAdmin()) user.emailMatches(bookDAO.getUserEmail());
final List<Block> blockList = new ArrayList<>();
try {
final String annotatedStoryDom = bookDAO.getAnnotatedStoryDom();
final Book book = XmlReader.readBookFromXmlStream(new StringReader(annotatedStoryDom));
Integer chapterId = 1;
Integer blockId = 1;
for (final com.o3.storyinspector.storydom.Chapter chapter : book.getChapters()) {
final String chapterTitle = "Chapter #" + chapterId++ + " " + chapter.getTitle();
for (final com.o3.storyinspector.storydom.Block domBlock : chapter.getBlocks()) {
final List<Sentence> sentences = new ArrayList<>();
for (final String sentenceText : SentenceSplitter.splitSentences(domBlock)) {
final int wordCount = WordCountInspector.inspectWordCount(sentenceText);
double fkGradeLevel = FleschKincaidReadabilityInspector.inspectFKGradeLevel(sentenceText);
sentences.add(new Sentence(sentenceText, fkGradeLevel, wordCount));
}
blockList.add(new Block(blockId++, domBlock, chapterTitle, sentences));
}
}
return new Blocks(bookDAO.getTitle(), bookDAO.getAuthor(), blockList);
return Blocks.buildBlocks(book, bookDAO.getTitle(), bookDAO.getAuthor());
} catch (final Exception e) {
final String errMsg = "Unexpected error when listing book blocks. Book bookId: " +
bookId + ", Exception: " + e.getLocalizedMessage();
Expand All @@ -68,4 +46,5 @@ public Blocks findAllByBook(@PathVariable final Long bookId, @RequestParam("id_t
}
}


}
62 changes: 2 additions & 60 deletions api/src/main/java/com/o3/storyinspector/api/ChartApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@
import com.o3.storyinspector.api.user.UserInfo;
import com.o3.storyinspector.db.BookDAO;
import com.o3.storyinspector.domain.Chart;
import com.o3.storyinspector.storydom.Block;
import com.o3.storyinspector.storydom.Book;
import com.o3.storyinspector.storydom.Chapter;
import com.o3.storyinspector.storydom.Emotion;
import com.o3.storyinspector.storydom.constants.EmotionType;
import com.o3.storyinspector.storydom.io.XmlReader;
import com.o3.storyinspector.storydom.util.StoryDomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.xml.bind.JAXBException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/charts")
@CrossOrigin(origins = "*", allowedHeaders = "*")
Expand All @@ -43,7 +32,7 @@ public Chart one(@PathVariable final Long id, @RequestParam("id_token") final St
if (!user.isAdmin()) user.emailMatches(bookDAO.getUserEmail());
final Chart chart;
try {
chart = buildSentimentChartFromBook(bookDAO);
chart = Chart.buildSentimentChartFromBook(bookDAO.asBook());
} catch (Exception e) {
final String errMsg = "Unexpected error when building posneg chart. Book id: " +
id + "Exception: " + e.getLocalizedMessage();
Expand All @@ -63,7 +52,7 @@ public Chart one(@PathVariable final Long id, @PathVariable final String emotion
final Chart chart;
try {
final EmotionType emotionType = EmotionType.emotionTypeFor(emotionName);
chart = buildEmotionChartFromBook(bookDAO, emotionType);
chart = Chart.buildEmotionChartFromBook(bookDAO.asBook(), emotionType);
} catch (Exception e) {
final String errMsg = "Unexpected error when building emotion chart. Book id: " +
id + " ,emotion:" + emotionName + " Exception: " + e.getLocalizedMessage();
Expand All @@ -75,51 +64,4 @@ public Chart one(@PathVariable final Long id, @PathVariable final String emotion
return chart;
}

private static Chart buildSentimentChartFromBook(final BookDAO bookDAO) throws JAXBException {
final String annotatedStoryDom = bookDAO.getAnnotatedStoryDom();
final Book book = XmlReader.readBookFromXmlStream(new StringReader(annotatedStoryDom));
final List<String> labels = new ArrayList<>();
final List<String> blocks = new ArrayList<>();
final List<Double> scores = new ArrayList<>();
final List<Integer> chapterDividers = new ArrayList<>();
int counter = 0;
for (final Chapter chapter : book.getChapters()) {
for (final Block block : chapter.getBlocks()) {
counter++;
final double sentimentScore = block.getSentimentScore().doubleValue();
labels.add("#" + counter);
blocks.add(block.getBody());
scores.add(sentimentScore);
}
chapterDividers.add(counter);
}
chapterDividers.remove(chapterDividers.size()-1); // remove last marker
return new Chart(bookDAO.getTitle(), bookDAO.getAuthor(), labels, blocks, scores, chapterDividers);
}

private static Chart buildEmotionChartFromBook(final BookDAO bookDAO, final EmotionType emotionType) throws JAXBException {
final double maxEmotionScore = StoryDomUtils.getMaxEmotionScore(bookDAO.asBook());
final String annotatedStoryDom = bookDAO.getAnnotatedStoryDom();
final Book book = XmlReader.readBookFromXmlStream(new StringReader(annotatedStoryDom));
final List<String> labels = new ArrayList<>();
final List<String> blocks = new ArrayList<>();
final List<Double> scores = new ArrayList<>();
final List<Integer> chapterDividers = new ArrayList<>();
int counter = 0;
for (final Chapter chapter : book.getChapters()) {
for (final Block block : chapter.getBlocks()) {
counter++;
final Emotion emotion = StoryDomUtils.findEmotion(emotionType, block.getEmotions());
final double emotionScore = emotion.getScore().doubleValue();
final double normalizedEmotionScore = emotionScore / maxEmotionScore;
labels.add("#" + counter);
blocks.add(block.getBody());
scores.add(normalizedEmotionScore);
}
chapterDividers.add(counter);
}
chapterDividers.remove(chapterDividers.size()-1); // remove last marker
return new Chart(bookDAO.getTitle(), bookDAO.getAuthor(), labels, blocks, scores, chapterDividers);
}

}
26 changes: 26 additions & 0 deletions api/src/main/java/com/o3/storyinspector/domain/Blocks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.o3.storyinspector.domain;

import com.o3.storyinspector.annotation.blocks.SentenceSplitter;
import com.o3.storyinspector.annotation.readability.FleschKincaidReadabilityInspector;
import com.o3.storyinspector.annotation.wordcount.WordCountInspector;
import com.o3.storyinspector.storydom.Book;

import java.util.ArrayList;
import java.util.List;

public class Blocks {
Expand All @@ -25,4 +31,24 @@ public String getBookAuthor() {
public List<Block> getBlocks() {
return blocks;
}

public static Blocks buildBlocks(final Book book, final String bookTitle, final String author) {
final List<Block> blockList = new ArrayList<>();
int chapterId = 1;
int blockId = 1;
for (final com.o3.storyinspector.storydom.Chapter chapter : book.getChapters()) {
final String chapterTitle = "Chapter #" + chapterId++ + " " + chapter.getTitle();
for (final com.o3.storyinspector.storydom.Block domBlock : chapter.getBlocks()) {
final List<Sentence> sentences = new ArrayList<>();
for (final String sentenceText : SentenceSplitter.splitSentences(domBlock)) {
final int wordCount = WordCountInspector.inspectWordCount(sentenceText);
double fkGradeLevel = FleschKincaidReadabilityInspector.inspectFKGradeLevel(sentenceText);
sentences.add(new Sentence(sentenceText, fkGradeLevel, wordCount));
}
blockList.add(new Block(blockId++, domBlock, chapterTitle, sentences));
}
}
return new Blocks(bookTitle, author, blockList);
}

}
46 changes: 46 additions & 0 deletions api/src/main/java/com/o3/storyinspector/domain/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.o3.storyinspector.storydom.constants.EmotionType;
import com.o3.storyinspector.storydom.util.StoryDomUtils;

import javax.xml.bind.JAXBException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -78,4 +80,48 @@ public static Map<Integer, Double> getEmotionScores(final Book book, final Emoti
return scoresByBlock;
}

public static Chart buildSentimentChartFromBook(final Book book) {
final List<String> labels = new ArrayList<>();
final List<String> blocks = new ArrayList<>();
final List<Double> scores = new ArrayList<>();
final List<Integer> chapterDividers = new ArrayList<>();
int counter = 0;
for (final Chapter chapter : book.getChapters()) {
for (final Block block : chapter.getBlocks()) {
counter++;
final double sentimentScore = block.getSentimentScore().doubleValue();
labels.add("#" + counter);
blocks.add(block.getBody());
scores.add(sentimentScore);
}
chapterDividers.add(counter);
}
chapterDividers.remove(chapterDividers.size()-1); // remove last marker
return new Chart(book.getTitle(), book.getAuthor(), labels, blocks, scores, chapterDividers);
}

public static Chart buildEmotionChartFromBook(final Book book, final EmotionType emotionType) throws JAXBException {
final double maxEmotionScore = StoryDomUtils.getMaxEmotionScore(book);
final List<String> labels = new ArrayList<>();
final List<String> blocks = new ArrayList<>();
final List<Double> scores = new ArrayList<>();
final List<Integer> chapterDividers = new ArrayList<>();
int counter = 0;
for (final Chapter chapter : book.getChapters()) {
for (final Block block : chapter.getBlocks()) {
counter++;
final Emotion emotion = StoryDomUtils.findEmotion(emotionType, block.getEmotions());
final double emotionScore = emotion.getScore().doubleValue();
final double normalizedEmotionScore = emotionScore / maxEmotionScore;
labels.add("#" + counter);
blocks.add(block.getBody());
scores.add(normalizedEmotionScore);
}
chapterDividers.add(counter);
}
chapterDividers.remove(chapterDividers.size()-1); // remove last marker
return new Chart(book.getTitle(), book.getAuthor(), labels, blocks, scores, chapterDividers);
}


}
51 changes: 51 additions & 0 deletions app-gui/installer/inno.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Story Inspector"
#define MyAppVersion "Alpha"
#define MyAppPublisher "Story Inspector"
#define MyAppURL "https://www.storyinspector.com/"
#define MyAppExeName "StoryInspector.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{009B36E9-CAA2-468B-BE4B-30E189361374}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\StoryInspector
DisableDirPage=no
DisableProgramGroupPage=yes
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputDir=C:\Users\tdper\OneDrive\Desktop
OutputBaseFilename=StoryInspector-installer-win-amd64
SetupIconFile=C:\Dev\story-inspector\app-gui\src\main\resources\install.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Dev\story-inspector\app-gui\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Dev\story-inspector\app-gui\JRE\*"; DestDir: "{app}\JRE"; Flags: recursesubdirs createallsubdirs
Source: "C:\Dev\story-inspector\app-gui\A._Conan_Doyle-A_Study_in_Scarlett.storydom"; DestDir: "{app}"; Flags: onlyifdoesntexist
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

32 changes: 32 additions & 0 deletions app-gui/installer/launch4j.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>C:\Dev\story-inspector\app-gui\target\app-gui-1.0-SNAPSHOT.jar</jar>
<outfile>StoryInspector.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>true</stayAlive>
<restartOnCrash>true</restartOnCrash>
<manifest></manifest>
<icon>C:\Dev\story-inspector\app-gui\src\main\resources\logo_Ckp_icon.ico</icon>
<singleInstance>
<mutexName>StoryInspector-Token</mutexName>
<windowTitle>Story Inspector</windowTitle>
</singleInstance>
<jre>
<path>JRE</path>
<bundledJre64Bit>true</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion></minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
<initialHeapSize>2048</initialHeapSize>
<maxHeapSize>9216</maxHeapSize>
</jre>
</launch4jConfig>
Loading

0 comments on commit 4a27f92

Please sign in to comment.