From 0957eb598e9a855966d9d43a65296ce6b7d6a3e4 Mon Sep 17 00:00:00 2001 From: Mateusz Kopeć <m.kopec@ipipan.waw.pl> Date: Fri, 17 Jul 2015 11:43:15 +0200 Subject: [PATCH] Package renaming --- AbsSumAnnotator/.classpath | 21 --------------------- AbsSumAnnotator/.gitignore | 8 ++++---- AbsSumAnnotator/README.txt | 3 --- AbsSumAnnotator/pom.xml | 17 ++++++++++++++--- AbsSumAnnotator/src/main/java/log4j.properties | 5 ----- AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/basic/Text.java | 46 ---------------------------------------------- AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/io/SummaryFileIO.java | 137 ----------------------------------------------------------------------------------------------------------------------------------------- AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/AbsSumAnnotator.java | 365 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/MyTab.java | 171 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/basic/Text.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/io/SummaryFileIO.java | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/AbsSumAnnotator.java | 364 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/MyTab.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AbsSumAnnotator/src/main/resources/log4j.properties | 5 +++++ ClauseAnnotator/.classpath | 25 ------------------------- ClauseAnnotator/.gitignore | 8 ++++---- ClauseAnnotator/pom.xml | 19 +++++++++++++++---- ClauseAnnotator/src/main/java/log4j.properties | 5 ----- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Clause.java | 117 --------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Document.java | 62 -------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Marker.java | 81 --------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Sentence.java | 100 ---------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Word.java | 76 ---------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/IdGenerator.java | 59 ----------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLReader.java | 195 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLWriter.java | 184 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/BottomPanel.java | 213 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Clauseannotator.java | 315 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/FixIds.java | 21 --------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainDocument.java | 301 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainSplitPanel.java | 57 --------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainTextPane.java | 214 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Styles.java | 51 --------------------------------------------------- ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Clause.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Document.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Marker.java | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Sentence.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Word.java | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/IdGenerator.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLReader.java | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLWriter.java | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/BottomPanel.java | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/ClauseAnnotator.java | 314 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/FixIds.java | 20 ++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainDocument.java | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainSplitPanel.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainTextPane.java | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/Styles.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseAnnotator/src/main/resources/log4j.properties | 5 +++++ ClauseSumAnnotator/.classpath | 25 ------------------------- ClauseSumAnnotator/.gitignore | 8 ++++---- ClauseSumAnnotator/pom.xml | 21 ++++++++++++++++----- ClauseSumAnnotator/src/main/java/log4j.properties | 5 ----- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Clause.java | 41 ----------------------------------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Word.java | 15 --------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/SummaryFileIO.java | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/XMLReader.java | 122 -------------------------------------------------------------------------------------------------------------------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseSumAnnotator.java | 397 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseTable.java | 187 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTab.java | 126 ------------------------------------------------------------------------------------------------------------------------------ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTabChangeListener.java | 12 ------------ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Clause.java | 40 ++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Word.java | 15 +++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/SummaryFileIO.java | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/XMLReader.java | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseSumAnnotator.java | 397 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseTable.java | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTab.java | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTabChangeListener.java | 11 +++++++++++ ClauseSumAnnotator/src/main/resources/log4j.properties | 5 +++++ ExtrSumAnnotator/.classpath | 25 ------------------------- ExtrSumAnnotator/.gitignore | 8 ++++---- ExtrSumAnnotator/pom.xml | 19 +++++++++++++++---- ExtrSumAnnotator/src/main/java/log4j.properties | 5 ----- ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/basic/Text.java | 43 ------------------------------------------- ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/io/SummaryFileIO.java | 135 --------------------------------------------------------------------------------------------------------------------------------------- ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/ExtrSumAnnotator.java | 384 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTab.java | 325 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTabChangeListener.java | 13 ------------- ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/basic/Text.java | 43 +++++++++++++++++++++++++++++++++++++++++++ ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/io/SummaryFileIO.java | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/ExtrSumAnnotator.java | 383 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTab.java | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTabChangeListener.java | 13 +++++++++++++ ExtrSumAnnotator/src/main/resources/log4j.properties | 5 +++++ 85 files changed, 4789 insertions(+), 4867 deletions(-) delete mode 100644 AbsSumAnnotator/.classpath delete mode 100644 AbsSumAnnotator/README.txt delete mode 100644 AbsSumAnnotator/src/main/java/log4j.properties delete mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/basic/Text.java delete mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/io/SummaryFileIO.java delete mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/AbsSumAnnotator.java delete mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/MyTab.java create mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/basic/Text.java create mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/io/SummaryFileIO.java create mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/AbsSumAnnotator.java create mode 100644 AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/MyTab.java create mode 100644 AbsSumAnnotator/src/main/resources/log4j.properties delete mode 100644 ClauseAnnotator/.classpath delete mode 100644 ClauseAnnotator/src/main/java/log4j.properties delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Clause.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Document.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Marker.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Sentence.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Word.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/IdGenerator.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLReader.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLWriter.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/BottomPanel.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Clauseannotator.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/FixIds.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainDocument.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainSplitPanel.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainTextPane.java delete mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Styles.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Clause.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Document.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Marker.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Sentence.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Word.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/IdGenerator.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLReader.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLWriter.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/BottomPanel.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/ClauseAnnotator.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/FixIds.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainDocument.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainSplitPanel.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainTextPane.java create mode 100644 ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/Styles.java create mode 100644 ClauseAnnotator/src/main/resources/log4j.properties delete mode 100644 ClauseSumAnnotator/.classpath delete mode 100644 ClauseSumAnnotator/src/main/java/log4j.properties delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Clause.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Word.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/SummaryFileIO.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/XMLReader.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseSumAnnotator.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseTable.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTab.java delete mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTabChangeListener.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Clause.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Word.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/SummaryFileIO.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/XMLReader.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseSumAnnotator.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseTable.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTab.java create mode 100644 ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTabChangeListener.java create mode 100644 ClauseSumAnnotator/src/main/resources/log4j.properties delete mode 100644 ExtrSumAnnotator/.classpath delete mode 100644 ExtrSumAnnotator/src/main/java/log4j.properties delete mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/basic/Text.java delete mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/io/SummaryFileIO.java delete mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/ExtrSumAnnotator.java delete mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTab.java delete mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTabChangeListener.java create mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/basic/Text.java create mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/io/SummaryFileIO.java create mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/ExtrSumAnnotator.java create mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTab.java create mode 100644 ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTabChangeListener.java create mode 100644 ExtrSumAnnotator/src/main/resources/log4j.properties diff --git a/AbsSumAnnotator/.classpath b/AbsSumAnnotator/.classpath deleted file mode 100644 index b65cf41..0000000 --- a/AbsSumAnnotator/.classpath +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> - <classpathentry kind="output" path="target/classes"/> -</classpath> diff --git a/AbsSumAnnotator/.gitignore b/AbsSumAnnotator/.gitignore index 6b743b9..6cb1223 100644 --- a/AbsSumAnnotator/.gitignore +++ b/AbsSumAnnotator/.gitignore @@ -1,4 +1,4 @@ -*.class -*~ -.settings/* -target +/target/ +.project +.settings +.classpath diff --git a/AbsSumAnnotator/README.txt b/AbsSumAnnotator/README.txt deleted file mode 100644 index 9d39fd0..0000000 --- a/AbsSumAnnotator/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -== Abstract Summary Annotator == - -This is the README file. \ No newline at end of file diff --git a/AbsSumAnnotator/pom.xml b/AbsSumAnnotator/pom.xml index 1f52a23..6d82593 100644 --- a/AbsSumAnnotator/pom.xml +++ b/AbsSumAnnotator/pom.xml @@ -1,10 +1,13 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>ipipan.atlas</groupId> + <groupId>pl.waw.ipipan.zil.summarizer</groupId> <artifactId>abssumannotator</artifactId> - <version>0.1</version> + <version>1.0</version> <name>AbsSumAnnotator</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <build> <plugins> <plugin> @@ -12,7 +15,7 @@ <configuration> <archive> <manifest> - <mainClass>ipipan.atlas.abssumannotator.main.AbsSumAnnotator</mainClass> + <mainClass>pl.waw.ipipan.zil.summarizer.abssumannotator.main.AbsSumAnnotator</mainClass> </manifest> </archive> <descriptorRefs> @@ -20,6 +23,14 @@ </descriptorRefs> </configuration> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> </plugins> </build> <dependencies> diff --git a/AbsSumAnnotator/src/main/java/log4j.properties b/AbsSumAnnotator/src/main/java/log4j.properties deleted file mode 100644 index 9500239..0000000 --- a/AbsSumAnnotator/src/main/java/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n - -log4j.logger.pl.waw.ipipan.zil.summarization.abssumannotator=INFO, stderr \ No newline at end of file diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/basic/Text.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/basic/Text.java deleted file mode 100644 index 50293f7..0000000 --- a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/basic/Text.java +++ /dev/null @@ -1,46 +0,0 @@ -package pl.waw.ipipan.zil.summarization.abssumannotator.basic; - -import java.util.List; - -public class Text { - - private String text; - - private List<String> summaries; - - public void setText(String text) { - this.text = text; - } - - public String getText() { - return text; - } - - public int getTextWordsCount() { - return getStringWordCount(text); - } - - public int getSummaryWordsCount(int number) { - return getStringWordCount(getSummary(number)); - } - - public static int getStringWordCount(String string) { - return string.split("[ ]+").length; - } - - public void setSummaries(List<String> summaries) { - this.summaries = summaries; - } - - public String getSummary(int number) { - return summaries.get(number); - } - - public List<String> getSummaries() { - return summaries; - } - - public void setSummary(int summNumber, String sum) { - summaries.set(summNumber, sum); - } -} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/io/SummaryFileIO.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/io/SummaryFileIO.java deleted file mode 100644 index 234b4ee..0000000 --- a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/io/SummaryFileIO.java +++ /dev/null @@ -1,137 +0,0 @@ -package pl.waw.ipipan.zil.summarization.abssumannotator.io; - - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.abssumannotator.basic.Text; -import pl.waw.ipipan.zil.summarization.abssumannotator.main.AbsSumAnnotator; - -public class SummaryFileIO { - - private static final String SUMMARIES = "#### SUMMARIES ####"; - private static final String SUMMARY_START = "#### SUMMARY START ####"; - private static final String SUMMARY_END = "#### SUMMARY END ####"; - - private static final Logger logger = Logger.getLogger(SummaryFileIO.class); - - public static boolean saveSummary(File summaryFile, Text text) { - logger.info("Saving text with summaries in file: " + summaryFile); - BufferedWriter bw = null; - - try { - bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(summaryFile), "UTF-8")); - - bw.append(text.getText() + "\n"); - bw.append(SUMMARIES + "\n"); - - for (String summary : text.getSummaries()) - writeSummary(bw, summary); - - } catch (IOException e) { - logger.error("Error writing summary: " + e.getLocalizedMessage()); - return false; - } finally { - if (bw != null) - try { - bw.close(); - } catch (IOException e) { - logger.error("Error closing summary file: " + e.getLocalizedMessage()); - return false; - } - } - return true; - } - - private static void writeSummary(BufferedWriter bw, String summary) throws IOException { - bw.append(SUMMARY_START + "\n"); - bw.append(summary + "\n"); - bw.append(SUMMARY_END + "\n"); - } - - public static Text loadText(File input) { - - logger.info("Loading text with summaries from file: " + input); - BufferedReader br = null; - - Text t = new Text(); - - try { - br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8")); - String line = null; - StringBuffer fullText = new StringBuffer(); - List<String> summaries = new ArrayList<String>(); - while ((line = br.readLine()) != null) { - if (line.startsWith(SUMMARIES)) - summaries = loadSummaries(br); - else - fullText.append(line + "\n"); - } - - while (summaries.size() < AbsSumAnnotator.SUMMARIES_COUNT) { - summaries.add(""); - } - - t.setSummaries(summaries); - t.setText(fullText.toString()); - - } catch (IOException e) { - logger.error("Error reading text: " + e.getLocalizedMessage()); - return null; - } finally { - try { - if (br != null) - br.close(); - } catch (IOException e) { - logger.error("Error closing text file: " + e.getLocalizedMessage()); - return null; - } - } - - return t; - } - - private static List<String> loadSummaries(BufferedReader br) throws IOException { - - List<String> summaries = new ArrayList<String>(); - - String summary = null; - while ((summary = loadSummary(br)) != null) - summaries.add(summary); - - return summaries; - } - - private static String loadSummary(BufferedReader br) throws IOException { - StringBuffer summary = new StringBuffer(); - - String line = null; - boolean inside = false; - while ((line = br.readLine()) != null) { - if (line.startsWith(SUMMARY_END)) - break; - - if (inside) - summary.append(line + "\n"); - - if (line.startsWith(SUMMARY_START)) - inside = true; - } - - if (summary.length() == 0 && !inside) - return null; - - return summary.toString(); - } - -} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/AbsSumAnnotator.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/AbsSumAnnotator.java deleted file mode 100644 index a4eecba..0000000 --- a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/AbsSumAnnotator.java +++ /dev/null @@ -1,365 +0,0 @@ -package pl.waw.ipipan.zil.summarization.abssumannotator.main; - - -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Insets; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Enumeration; - -import javax.swing.ButtonGroup; -import javax.swing.JEditorPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.filechooser.FileFilter; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.abssumannotator.basic.Text; -import pl.waw.ipipan.zil.summarization.abssumannotator.io.SummaryFileIO; - -public class AbsSumAnnotator extends JFrame implements Runnable { - - public static final int SUMMARIES_COUNT = 3; - - private static final String WINDOW_TITLE = "ASE v0.9"; - - private static final long serialVersionUID = -3830790411182131318L; - - private static final Logger logger = Logger.getLogger(AbsSumAnnotator.class); - - private static final int TEXT_HEIGTH = 400; - private static final int HEIGTH = 600; - private static final int WIDTH = 800; - - private JMenuItem save; - - private File currentFile = null; - private boolean unsavedChanges = false; - - private JTabbedPane tabbedPane; - private JTextArea textPane; - - private float displayFontSize; - - private Text currentText; - - public static void main(String[] args) { - if (args.length != 0 && args.length != 1) { - logger.error("Wrong usage! Should be: java -jar " + AbsSumAnnotator.class.getSimpleName() + " [input file]"); - return; - } - final AbsSumAnnotator summanno = new AbsSumAnnotator(); - try { - SwingUtilities.invokeAndWait(summanno); - } catch (Exception e) { - logger.error("Error starting application: " + e.getLocalizedMessage()); - e.printStackTrace(); - return; - } - - if (args.length == 1) { - final File input = new File(args[0]); - if (input.exists()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - summanno.loadFile(input); - } - }); - } else { - logger.error("Input file: " + input + " doesn't exist!"); - } - } - } - - @Override - public void run() { - displayFontSize = loadDisplayFontSize(); - - textPane = new JTextArea(); - textPane.setEditable(false); - textPane.setLineWrap(true); - textPane.setWrapStyleWord(true); - textPane.setMargin(new Insets(10, 10, 10, 10)); - - tabbedPane = new JTabbedPane(); - - JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - splitPane.setTopComponent(new JScrollPane(textPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); - splitPane.setBottomComponent(tabbedPane); - splitPane.setDividerLocation(TEXT_HEIGTH); - this.getContentPane().add(splitPane); - - this.setTitle(WINDOW_TITLE); - this.createMenu(); - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.addWindowListener(new MainWindowListener()); - this.setSize(WIDTH, HEIGTH); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); - this.setVisible(true); - } - - private float loadDisplayFontSize() { - float result = 12f; - logger.info("Using default font size."); - return result; - } - - private void createMenu() { - JMenuBar menu = new JMenuBar(); - this.setJMenuBar(menu); - - JMenu file = new JMenu("File"); - menu.add(file); - - JMenuItem open = new JMenuItem("Open"); - open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); - open.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestOpenFile(); - } - }); - file.add(open); - - save = new JMenuItem("Save"); - save.setEnabled(false); - save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); - save.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestSaveFile(); - } - }); - file.add(save); - - JMenuItem exit = new JMenuItem("Exit"); - exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - exit.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestExit(); - } - }); - file.add(exit); - - JMenu other = new JMenu("Other"); - - ButtonGroup fontSizeButtonGroup = new ButtonGroup(); - JMenu setFontSize = new JMenu("Change font size"); - for (int z = 8; z < 25; z = z + 2) { - - final int currentFontSize = z; - - JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); - if (z == displayFontSize) { - temp.setSelected(true); - } - temp.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent ae) { - requestSetFontSize(currentFontSize); - } - }); - fontSizeButtonGroup.add(temp); - setFontSize.add(temp); - } - other.add(setFontSize); - - JMenuItem help = new JMenuItem("Help"); - help.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestShowHelp(); - } - }); - other.add(help); - - menu.add(other); - } - - protected void requestSetFontSize(float currentFontSize) { - logger.info("Setting font size: " + currentFontSize); - displayFontSize = currentFontSize; - - Enumeration<Object> enumer = UIManager.getDefaults().keys(); - while (enumer.hasMoreElements()) { - Object key = enumer.nextElement(); - Object value = UIManager.get(key); - if (value instanceof Font) { - UIManager.put(key, new javax.swing.plaf.FontUIResource(((Font) value).deriveFont(currentFontSize))); - } - } - SwingUtilities.updateComponentTreeUI(this); - } - - private final void requestShowHelp() { - JFrame helpFrame = new JFrame("Help"); - helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JEditorPane editorPane = new JEditorPane(); - editorPane.setEditable(false); - URL helpURL = AbsSumAnnotator.class.getClassLoader().getResource("help.html"); - if (helpURL != null) { - try { - editorPane.setPage(helpURL); - } catch (IOException e) { - logger.error("Attempted to read a bad URL: " + helpURL); - } - } else { - logger.error("Couldn't find file: help.html"); - } - - // Put the editor pane in a scroll pane. - JScrollPane editorScrollPane = new JScrollPane(editorPane); - editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setPreferredSize(new Dimension(800, 600)); - editorScrollPane.setMinimumSize(new Dimension(30, 30)); - - helpFrame.getContentPane().add(editorScrollPane); - helpFrame.pack(); - helpFrame.setVisible(true); - } - - private void requestSaveFile() { - boolean success = SummaryFileIO.saveSummary(currentFile, currentText); - - if (success) { - unsavedChanges = false; - setTitle(WINDOW_TITLE + " file: " + currentFile.getName()); - save.setEnabled(false); - } else { - showError("Error saving file: " + currentFile); - } - } - - private final void requestOpenFile() { - if (!askToSaveChanges()) - return; - - JFileChooser chooser; - if (currentFile == null) - chooser = new JFileChooser(); - else - chooser = new JFileChooser(currentFile.getParentFile()); - - chooser.setFileFilter(new SummannotatorFileFilter()); - int result = chooser.showOpenDialog(this); - - if (result == JFileChooser.APPROVE_OPTION) { - this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - this.loadFile(chooser.getSelectedFile()); - this.setCursor(null); - } - } - - private boolean askToSaveChanges() { - if (!unsavedChanges) - return true; - - int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); - - if (result == JOptionPane.CANCEL_OPTION) - return false; - - if (result == JOptionPane.YES_OPTION) - requestSaveFile(); - - return true; - } - - private final void requestExit() { - if (!askToSaveChanges()) - return; - - logger.info("Exiting."); - System.exit(0); - } - - private final void loadFile(File input) { - tabbedPane.removeAll(); - - if (!input.exists()) { - String err = "File " + input + " doesn't exist!"; - logger.error(err); - showError(err); - return; - } - - currentText = SummaryFileIO.loadText(input); - textPane.setText(currentText.getText()); - textPane.setCaretPosition(0); - - int allWords = currentText.getTextWordsCount(); - double[] proportions = { 0.2, 0.1, 0.05 }; - String[] labels = { "20%", "10%", "5%" }; - - for (int i = 0; i < 3; i++) { - int wordsInSumm = (int) (allWords * proportions[i]); - MyTab tab = new MyTab(this, currentText.getSummary(i), i, allWords, wordsInSumm); - tabbedPane.addTab(labels[i] + " summary", tab); - } - - currentFile = input; - setTitle(WINDOW_TITLE + " file: " + currentFile.getName()); - } - - private void showError(String string) { - JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); - } - - private final class SummannotatorFileFilter extends FileFilter { - @Override - public String getDescription() { - return "TXT files"; - } - - @Override - public boolean accept(File f) { - return f.getName().endsWith(".txt") || f.isDirectory(); - } - } - - private class MainWindowListener extends WindowAdapter { - - @Override - public void windowClosing(WindowEvent we) { - requestExit(); - } - } - - public void summaryChanged(int summNumber, String text) { - unsavedChanges = true; - save.setEnabled(true); - setTitle(WINDOW_TITLE + " file: " + currentFile.getName() + " " + "[unsaved changes]"); - currentText.setSummary(summNumber, text); - } - -} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/MyTab.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/MyTab.java deleted file mode 100644 index 87e7a58..0000000 --- a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/abssumannotator/main/MyTab.java +++ /dev/null @@ -1,171 +0,0 @@ -package pl.waw.ipipan.zil.summarization.abssumannotator.main; - - -import java.awt.BorderLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; - -import javax.swing.AbstractAction; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.KeyStroke; -import javax.swing.event.UndoableEditEvent; -import javax.swing.event.UndoableEditListener; -import javax.swing.undo.CannotRedoException; -import javax.swing.undo.UndoManager; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.abssumannotator.basic.Text; - -public class MyTab extends JPanel { - - private static final long serialVersionUID = 3656861958564714263L; - - private static final Logger logger = Logger.getLogger(MyTab.class); - - private JTextArea textArea; - private JProgressBar pb; - - private int targetSegmentCount; - private int allSegmentCount; - - private AbsSumAnnotator sumanno; - private int summNumber; - - private UndoManager undoManager; - private JButton undoButton; - private JButton redoButton; - - public MyTab(AbsSumAnnotator absSumAnnotator, String summary, int summNumber, int allSegmentCount, - int targetSegmentCount) { - - this.sumanno = absSumAnnotator; - this.summNumber = summNumber; - - this.targetSegmentCount = targetSegmentCount; - this.allSegmentCount = allSegmentCount; - - textArea = new JTextArea(summary); - textArea.setLineWrap(true); - textArea.setWrapStyleWord(true); - textArea.setMargin(new Insets(10, 10, 10, 10)); - - undoManager = new UndoManager(); - UndoAction undoAction = new UndoAction(); - RedoAction redoAction = new RedoAction(); - undoButton = new JButton(undoAction); - redoButton = new JButton(redoAction); - - textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { - @Override - public void undoableEditHappened(UndoableEditEvent e) { - undoManager.addEdit(e.getEdit()); - summaryChanged(false); - updateButtons(); - } - }); - - this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( - KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), "undo"); - this.getActionMap().put("undo", undoAction); - this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( - KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_MASK), "redo"); - this.getActionMap().put("redo", redoAction); - - JScrollPane textAreaScrollPane = new JScrollPane(textArea); - - pb = new JProgressBar(0, targetSegmentCount); - JLabel all = new JLabel("Words in text: " + allSegmentCount); - JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); - - JPanel bottomLeftPanel = new JPanel(); - bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); - bottomLeftPanel.add(pb); - bottomLeftPanel.add(all); - bottomLeftPanel.add(summ); - bottomLeftPanel.add(Box.createVerticalStrut(8)); - bottomLeftPanel.add(undoButton); - bottomLeftPanel.add(Box.createVerticalStrut(3)); - bottomLeftPanel.add(redoButton); - - this.setLayout(new BorderLayout()); - this.add(textAreaScrollPane, BorderLayout.CENTER); - this.add(bottomLeftPanel, BorderLayout.LINE_START); - - summaryChanged(true); - updateButtons(); - } - - protected void updateButtons() { - undoButton.setText(undoManager.getUndoPresentationName() + " (CTRL+Z)"); - redoButton.setText(undoManager.getRedoPresentationName() + " (CTRL+Y)"); - undoButton.setEnabled(undoManager.canUndo()); - redoButton.setEnabled(undoManager.canRedo()); - } - - private void summaryChanged(boolean quiet) { - int chosenWords = Text.getStringWordCount(textArea.getText()); - - pb.setValue(chosenWords); - pb.setStringPainted(true); - if (targetSegmentCount == 0) - pb.setString(chosenWords + "/0 = -- %"); - else - pb.setString(chosenWords + "/" + targetSegmentCount + " = " + (100 * chosenWords / targetSegmentCount) - + "%"); - - if (!quiet) - sumanno.summaryChanged(summNumber, textArea.getText()); - } - - public String getName() { - return (int) (targetSegmentCount * 100.0 / allSegmentCount) + "% summary"; - } - - private class UndoAction extends AbstractAction { - - private static final long serialVersionUID = 640721327092571644L; - - @Override - public void actionPerformed(ActionEvent e) { - if (undoManager.canUndo()) { - try { - undoManager.undo(); - summaryChanged(false); - } catch (CannotRedoException cre) { - logger.error("Error when undoing:" + cre.getLocalizedMessage()); - } - updateButtons(); - } - } - - } - - private class RedoAction extends AbstractAction { - - private static final long serialVersionUID = 640721327092571644L; - - @Override - public void actionPerformed(ActionEvent e) { - if (undoManager.canRedo()) { - try { - undoManager.redo(); - summaryChanged(false); - } catch (CannotRedoException cre) { - logger.error("Error when redoing:" + cre.getLocalizedMessage()); - } - updateButtons(); - } - } - - } -} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/basic/Text.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/basic/Text.java new file mode 100644 index 0000000..cd414d0 --- /dev/null +++ b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/basic/Text.java @@ -0,0 +1,46 @@ +package pl.waw.ipipan.zil.summarizer.abssumannotator.basic; + +import java.util.List; + +public class Text { + + private String text; + + private List<String> summaries; + + public void setText(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public int getTextWordsCount() { + return getStringWordCount(text); + } + + public int getSummaryWordsCount(int number) { + return getStringWordCount(getSummary(number)); + } + + public static int getStringWordCount(String string) { + return string.split("[ ]+").length; + } + + public void setSummaries(List<String> summaries) { + this.summaries = summaries; + } + + public String getSummary(int number) { + return summaries.get(number); + } + + public List<String> getSummaries() { + return summaries; + } + + public void setSummary(int summNumber, String sum) { + summaries.set(summNumber, sum); + } +} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/io/SummaryFileIO.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/io/SummaryFileIO.java new file mode 100644 index 0000000..9d735b5 --- /dev/null +++ b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/io/SummaryFileIO.java @@ -0,0 +1,136 @@ +package pl.waw.ipipan.zil.summarizer.abssumannotator.io; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.abssumannotator.basic.Text; +import pl.waw.ipipan.zil.summarizer.abssumannotator.main.AbsSumAnnotator; + +public class SummaryFileIO { + + private static final String SUMMARIES = "#### SUMMARIES ####"; + private static final String SUMMARY_START = "#### SUMMARY START ####"; + private static final String SUMMARY_END = "#### SUMMARY END ####"; + + private static final Logger logger = Logger.getLogger(SummaryFileIO.class); + + public static boolean saveSummary(File summaryFile, Text text) { + logger.info("Saving text with summaries in file: " + summaryFile); + BufferedWriter bw = null; + + try { + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(summaryFile), "UTF-8")); + + bw.append(text.getText() + "\n"); + bw.append(SUMMARIES + "\n"); + + for (String summary : text.getSummaries()) + writeSummary(bw, summary); + + } catch (IOException e) { + logger.error("Error writing summary: " + e.getLocalizedMessage()); + return false; + } finally { + if (bw != null) + try { + bw.close(); + } catch (IOException e) { + logger.error("Error closing summary file: " + e.getLocalizedMessage()); + return false; + } + } + return true; + } + + private static void writeSummary(BufferedWriter bw, String summary) throws IOException { + bw.append(SUMMARY_START + "\n"); + bw.append(summary + "\n"); + bw.append(SUMMARY_END + "\n"); + } + + public static Text loadText(File input) { + + logger.info("Loading text with summaries from file: " + input); + BufferedReader br = null; + + Text t = new Text(); + + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8")); + String line = null; + StringBuffer fullText = new StringBuffer(); + List<String> summaries = new ArrayList<String>(); + while ((line = br.readLine()) != null) { + if (line.startsWith(SUMMARIES)) + summaries = loadSummaries(br); + else + fullText.append(line + "\n"); + } + + while (summaries.size() < AbsSumAnnotator.SUMMARIES_COUNT) { + summaries.add(""); + } + + t.setSummaries(summaries); + t.setText(fullText.toString()); + + } catch (IOException e) { + logger.error("Error reading text: " + e.getLocalizedMessage()); + return null; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + logger.error("Error closing text file: " + e.getLocalizedMessage()); + return null; + } + } + + return t; + } + + private static List<String> loadSummaries(BufferedReader br) throws IOException { + + List<String> summaries = new ArrayList<String>(); + + String summary = null; + while ((summary = loadSummary(br)) != null) + summaries.add(summary); + + return summaries; + } + + private static String loadSummary(BufferedReader br) throws IOException { + StringBuffer summary = new StringBuffer(); + + String line = null; + boolean inside = false; + while ((line = br.readLine()) != null) { + if (line.startsWith(SUMMARY_END)) + break; + + if (inside) + summary.append(line + "\n"); + + if (line.startsWith(SUMMARY_START)) + inside = true; + } + + if (summary.length() == 0 && !inside) + return null; + + return summary.toString(); + } + +} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/AbsSumAnnotator.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/AbsSumAnnotator.java new file mode 100644 index 0000000..7156e68 --- /dev/null +++ b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/AbsSumAnnotator.java @@ -0,0 +1,364 @@ +package pl.waw.ipipan.zil.summarizer.abssumannotator.main; + +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; + +import javax.swing.ButtonGroup; +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.filechooser.FileFilter; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.abssumannotator.basic.Text; +import pl.waw.ipipan.zil.summarizer.abssumannotator.io.SummaryFileIO; + +public class AbsSumAnnotator extends JFrame implements Runnable { + + public static final int SUMMARIES_COUNT = 3; + + private static final String WINDOW_TITLE = "ASE v1.0"; + + private static final long serialVersionUID = -3830790411182131318L; + + private static final Logger logger = Logger.getLogger(AbsSumAnnotator.class); + + private static final int TEXT_HEIGTH = 400; + private static final int HEIGTH = 600; + private static final int WIDTH = 800; + + private JMenuItem save; + + private File currentFile = null; + private boolean unsavedChanges = false; + + private JTabbedPane tabbedPane; + private JTextArea textPane; + + private float displayFontSize; + + private Text currentText; + + public static void main(String[] args) { + if (args.length != 0 && args.length != 1) { + logger.error("Wrong usage! Should be: java -jar " + AbsSumAnnotator.class.getSimpleName() + " [input file]"); + return; + } + final AbsSumAnnotator summanno = new AbsSumAnnotator(); + try { + SwingUtilities.invokeAndWait(summanno); + } catch (Exception e) { + logger.error("Error starting application: " + e.getLocalizedMessage()); + e.printStackTrace(); + return; + } + + if (args.length == 1) { + final File input = new File(args[0]); + if (input.exists()) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + summanno.loadFile(input); + } + }); + } else { + logger.error("Input file: " + input + " doesn't exist!"); + } + } + } + + @Override + public void run() { + displayFontSize = loadDisplayFontSize(); + + textPane = new JTextArea(); + textPane.setEditable(false); + textPane.setLineWrap(true); + textPane.setWrapStyleWord(true); + textPane.setMargin(new Insets(10, 10, 10, 10)); + + tabbedPane = new JTabbedPane(); + + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPane.setTopComponent(new JScrollPane(textPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); + splitPane.setBottomComponent(tabbedPane); + splitPane.setDividerLocation(TEXT_HEIGTH); + this.getContentPane().add(splitPane); + + this.setTitle(WINDOW_TITLE); + this.createMenu(); + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new MainWindowListener()); + this.setSize(WIDTH, HEIGTH); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); + this.setVisible(true); + } + + private float loadDisplayFontSize() { + float result = 12f; + logger.info("Using default font size."); + return result; + } + + private void createMenu() { + JMenuBar menu = new JMenuBar(); + this.setJMenuBar(menu); + + JMenu file = new JMenu("File"); + menu.add(file); + + JMenuItem open = new JMenuItem("Open"); + open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); + open.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestOpenFile(); + } + }); + file.add(open); + + save = new JMenuItem("Save"); + save.setEnabled(false); + save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); + save.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestSaveFile(); + } + }); + file.add(save); + + JMenuItem exit = new JMenuItem("Exit"); + exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); + exit.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestExit(); + } + }); + file.add(exit); + + JMenu other = new JMenu("Other"); + + ButtonGroup fontSizeButtonGroup = new ButtonGroup(); + JMenu setFontSize = new JMenu("Change font size"); + for (int z = 8; z < 25; z = z + 2) { + + final int currentFontSize = z; + + JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); + if (z == displayFontSize) { + temp.setSelected(true); + } + temp.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + requestSetFontSize(currentFontSize); + } + }); + fontSizeButtonGroup.add(temp); + setFontSize.add(temp); + } + other.add(setFontSize); + + JMenuItem help = new JMenuItem("Help"); + help.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestShowHelp(); + } + }); + other.add(help); + + menu.add(other); + } + + protected void requestSetFontSize(float currentFontSize) { + logger.info("Setting font size: " + currentFontSize); + displayFontSize = currentFontSize; + + Enumeration<Object> enumer = UIManager.getDefaults().keys(); + while (enumer.hasMoreElements()) { + Object key = enumer.nextElement(); + Object value = UIManager.get(key); + if (value instanceof Font) { + UIManager.put(key, new javax.swing.plaf.FontUIResource(((Font) value).deriveFont(currentFontSize))); + } + } + SwingUtilities.updateComponentTreeUI(this); + } + + private final void requestShowHelp() { + JFrame helpFrame = new JFrame("Help"); + helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JEditorPane editorPane = new JEditorPane(); + editorPane.setEditable(false); + URL helpURL = AbsSumAnnotator.class.getClassLoader().getResource("help.html"); + if (helpURL != null) { + try { + editorPane.setPage(helpURL); + } catch (IOException e) { + logger.error("Attempted to read a bad URL: " + helpURL); + } + } else { + logger.error("Couldn't find file: help.html"); + } + + // Put the editor pane in a scroll pane. + JScrollPane editorScrollPane = new JScrollPane(editorPane); + editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setPreferredSize(new Dimension(800, 600)); + editorScrollPane.setMinimumSize(new Dimension(30, 30)); + + helpFrame.getContentPane().add(editorScrollPane); + helpFrame.pack(); + helpFrame.setVisible(true); + } + + private void requestSaveFile() { + boolean success = SummaryFileIO.saveSummary(currentFile, currentText); + + if (success) { + unsavedChanges = false; + setTitle(WINDOW_TITLE + " file: " + currentFile.getName()); + save.setEnabled(false); + } else { + showError("Error saving file: " + currentFile); + } + } + + private final void requestOpenFile() { + if (!askToSaveChanges()) + return; + + JFileChooser chooser; + if (currentFile == null) + chooser = new JFileChooser(); + else + chooser = new JFileChooser(currentFile.getParentFile()); + + chooser.setFileFilter(new SummannotatorFileFilter()); + int result = chooser.showOpenDialog(this); + + if (result == JFileChooser.APPROVE_OPTION) { + this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + this.loadFile(chooser.getSelectedFile()); + this.setCursor(null); + } + } + + private boolean askToSaveChanges() { + if (!unsavedChanges) + return true; + + int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); + + if (result == JOptionPane.CANCEL_OPTION) + return false; + + if (result == JOptionPane.YES_OPTION) + requestSaveFile(); + + return true; + } + + private final void requestExit() { + if (!askToSaveChanges()) + return; + + logger.info("Exiting."); + System.exit(0); + } + + private final void loadFile(File input) { + tabbedPane.removeAll(); + + if (!input.exists()) { + String err = "File " + input + " doesn't exist!"; + logger.error(err); + showError(err); + return; + } + + currentText = SummaryFileIO.loadText(input); + textPane.setText(currentText.getText()); + textPane.setCaretPosition(0); + + int allWords = currentText.getTextWordsCount(); + double[] proportions = { 0.2, 0.1, 0.05 }; + String[] labels = { "20%", "10%", "5%" }; + + for (int i = 0; i < 3; i++) { + int wordsInSumm = (int) (allWords * proportions[i]); + MyTab tab = new MyTab(this, currentText.getSummary(i), i, allWords, wordsInSumm); + tabbedPane.addTab(labels[i] + " summary", tab); + } + + currentFile = input; + setTitle(WINDOW_TITLE + " file: " + currentFile.getName()); + } + + private void showError(String string) { + JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); + } + + private final class SummannotatorFileFilter extends FileFilter { + @Override + public String getDescription() { + return "TXT files"; + } + + @Override + public boolean accept(File f) { + return f.getName().endsWith(".txt") || f.isDirectory(); + } + } + + private class MainWindowListener extends WindowAdapter { + + @Override + public void windowClosing(WindowEvent we) { + requestExit(); + } + } + + public void summaryChanged(int summNumber, String text) { + unsavedChanges = true; + save.setEnabled(true); + setTitle(WINDOW_TITLE + " file: " + currentFile.getName() + " " + "[unsaved changes]"); + currentText.setSummary(summNumber, text); + } + +} diff --git a/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/MyTab.java b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/MyTab.java new file mode 100644 index 0000000..7a60ff6 --- /dev/null +++ b/AbsSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/abssumannotator/main/MyTab.java @@ -0,0 +1,170 @@ +package pl.waw.ipipan.zil.summarizer.abssumannotator.main; + +import java.awt.BorderLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import javax.swing.AbstractAction; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.event.UndoableEditEvent; +import javax.swing.event.UndoableEditListener; +import javax.swing.undo.CannotRedoException; +import javax.swing.undo.UndoManager; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.abssumannotator.basic.Text; + +public class MyTab extends JPanel { + + private static final long serialVersionUID = 3656861958564714263L; + + private static final Logger logger = Logger.getLogger(MyTab.class); + + private JTextArea textArea; + private JProgressBar pb; + + private int targetSegmentCount; + private int allSegmentCount; + + private AbsSumAnnotator sumanno; + private int summNumber; + + private UndoManager undoManager; + private JButton undoButton; + private JButton redoButton; + + public MyTab(AbsSumAnnotator absSumAnnotator, String summary, int summNumber, int allSegmentCount, + int targetSegmentCount) { + + this.sumanno = absSumAnnotator; + this.summNumber = summNumber; + + this.targetSegmentCount = targetSegmentCount; + this.allSegmentCount = allSegmentCount; + + textArea = new JTextArea(summary); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + textArea.setMargin(new Insets(10, 10, 10, 10)); + + undoManager = new UndoManager(); + UndoAction undoAction = new UndoAction(); + RedoAction redoAction = new RedoAction(); + undoButton = new JButton(undoAction); + redoButton = new JButton(redoAction); + + textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { + @Override + public void undoableEditHappened(UndoableEditEvent e) { + undoManager.addEdit(e.getEdit()); + summaryChanged(false); + updateButtons(); + } + }); + + this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), "undo"); + this.getActionMap().put("undo", undoAction); + this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_MASK), "redo"); + this.getActionMap().put("redo", redoAction); + + JScrollPane textAreaScrollPane = new JScrollPane(textArea); + + pb = new JProgressBar(0, targetSegmentCount); + JLabel all = new JLabel("Words in text: " + allSegmentCount); + JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); + + JPanel bottomLeftPanel = new JPanel(); + bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); + bottomLeftPanel.add(pb); + bottomLeftPanel.add(all); + bottomLeftPanel.add(summ); + bottomLeftPanel.add(Box.createVerticalStrut(8)); + bottomLeftPanel.add(undoButton); + bottomLeftPanel.add(Box.createVerticalStrut(3)); + bottomLeftPanel.add(redoButton); + + this.setLayout(new BorderLayout()); + this.add(textAreaScrollPane, BorderLayout.CENTER); + this.add(bottomLeftPanel, BorderLayout.LINE_START); + + summaryChanged(true); + updateButtons(); + } + + protected void updateButtons() { + undoButton.setText(undoManager.getUndoPresentationName() + " (CTRL+Z)"); + redoButton.setText(undoManager.getRedoPresentationName() + " (CTRL+Y)"); + undoButton.setEnabled(undoManager.canUndo()); + redoButton.setEnabled(undoManager.canRedo()); + } + + private void summaryChanged(boolean quiet) { + int chosenWords = Text.getStringWordCount(textArea.getText()); + + pb.setValue(chosenWords); + pb.setStringPainted(true); + if (targetSegmentCount == 0) + pb.setString(chosenWords + "/0 = -- %"); + else + pb.setString(chosenWords + "/" + targetSegmentCount + " = " + (100 * chosenWords / targetSegmentCount) + + "%"); + + if (!quiet) + sumanno.summaryChanged(summNumber, textArea.getText()); + } + + public String getName() { + return (int) (targetSegmentCount * 100.0 / allSegmentCount) + "% summary"; + } + + private class UndoAction extends AbstractAction { + + private static final long serialVersionUID = 640721327092571644L; + + @Override + public void actionPerformed(ActionEvent e) { + if (undoManager.canUndo()) { + try { + undoManager.undo(); + summaryChanged(false); + } catch (CannotRedoException cre) { + logger.error("Error when undoing:" + cre.getLocalizedMessage()); + } + updateButtons(); + } + } + + } + + private class RedoAction extends AbstractAction { + + private static final long serialVersionUID = 640721327092571644L; + + @Override + public void actionPerformed(ActionEvent e) { + if (undoManager.canRedo()) { + try { + undoManager.redo(); + summaryChanged(false); + } catch (CannotRedoException cre) { + logger.error("Error when redoing:" + cre.getLocalizedMessage()); + } + updateButtons(); + } + } + + } +} diff --git a/AbsSumAnnotator/src/main/resources/log4j.properties b/AbsSumAnnotator/src/main/resources/log4j.properties new file mode 100644 index 0000000..6d8f00a --- /dev/null +++ b/AbsSumAnnotator/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n + +log4j.logger.pl.waw.ipipan.zil=INFO, stderr \ No newline at end of file diff --git a/ClauseAnnotator/.classpath b/ClauseAnnotator/.classpath deleted file mode 100644 index fc321d6..0000000 --- a/ClauseAnnotator/.classpath +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> diff --git a/ClauseAnnotator/.gitignore b/ClauseAnnotator/.gitignore index 6b743b9..6cb1223 100644 --- a/ClauseAnnotator/.gitignore +++ b/ClauseAnnotator/.gitignore @@ -1,4 +1,4 @@ -*.class -*~ -.settings/* -target +/target/ +.project +.settings +.classpath diff --git a/ClauseAnnotator/pom.xml b/ClauseAnnotator/pom.xml index a089c52..2b9c81f 100644 --- a/ClauseAnnotator/pom.xml +++ b/ClauseAnnotator/pom.xml @@ -1,10 +1,13 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>ipipan.atlas</groupId> + <groupId>pl.waw.ipipan.zil.summarizer</groupId> <artifactId>clauseannotator</artifactId> - <version>0.1</version> - <name>Clauseannotator</name> + <version>1.0</version> + <name>ClauseAnnotator</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <build> <plugins> <plugin> @@ -12,7 +15,7 @@ <configuration> <archive> <manifest> - <mainClass>ipipan.atlas.clauseannotator.main.Clauseannotator</mainClass> + <mainClass>pl.waw.ipipan.zil.summarizer.clauseannotator.main.ClauseAnnotator</mainClass> </manifest> </archive> <descriptorRefs> @@ -20,6 +23,14 @@ </descriptorRefs> </configuration> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> </plugins> </build> <dependencies> diff --git a/ClauseAnnotator/src/main/java/log4j.properties b/ClauseAnnotator/src/main/java/log4j.properties deleted file mode 100644 index 0f9039c..0000000 --- a/ClauseAnnotator/src/main/java/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n - -log4j.logger.pl.waw.ipipan.zil.summarization.clauseannotator=INFO, stderr \ No newline at end of file diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Clause.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Clause.java deleted file mode 100644 index 052980f..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Clause.java +++ /dev/null @@ -1,117 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.basic; - -import java.util.ArrayList; -import java.util.List; - -public class Clause { - - private Sentence sentence; - private final List<Word> words = new ArrayList<Word>(); - - private Clause cont = null; - - public void add(Word currentWord) { - this.words.add(currentWord); - currentWord.setClause(this); - } - - public void addFirst(Word currentWord) { - this.words.add(0, currentWord); - currentWord.setClause(this); - } - - public List<Word> getWords() { - return words; - } - - public Sentence getSentence() { - return this.sentence; - } - - public void setSentence(Sentence sentence) { - this.sentence = sentence; - } - - public List<Clause> split(Word w) { - Clause c1 = new Clause(); - Clause c2 = new Clause(); - - boolean toC1 = true; - for (Word word : words) { - if (toC1) { - if (word.equals(w)) { - toC1 = false; - c2.add(word); - } else { - c1.add(word); - } - } else { - c2.add(word); - } - } - - ArrayList<Clause> l = new ArrayList<Clause>(); - l.add(c1); - l.add(c2); - return l; - } - - public Clause getContinuedClause() { - return cont; - } - - public boolean isFirstInSentence() { - return this.sentence.getClauses().get(0).equals(this); - } - - public boolean isLastInSentence() { - return this.sentence.getLastClause().equals(this); - } - - public String toTrimmedString(int len) { - StringBuffer sb = new StringBuffer(); - boolean first = true; - for (Word w : words) - if (first) { - sb.append(w.toString()); - first = false; - } else { - sb.append(" " + w.toString()); - } - - String trimmed = sb.toString().substring(0, Math.min(sb.toString().length(), len)); - - return sb.toString().length() < len ? trimmed : trimmed + "..."; - } - - @Override - public String toString() { - return toTrimmedString(80); - } - - public void setContinuedClause(Clause clause) { - this.cont = clause; - } - - public List<Word> getWordsSequence(Word startWord, Word stopWord) { - int start = -1; - int stop = -1; - for (int i = 0; i < words.size(); i++) { - Word w = words.get(i); - if (w.equals(startWord)) { - start = i; - } - if (w.equals(stopWord)) { - stop = i; - break; - } - } - - return new ArrayList<Word>(this.words.subList(start, stop + 1)); - } - - public Word getFirstWord() { - return this.words.get(0); - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Document.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Document.java deleted file mode 100644 index 74c3a67..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Document.java +++ /dev/null @@ -1,62 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.basic; - -import java.util.ArrayList; -import java.util.List; - -public class Document { - - private List<Sentence> sentences = new ArrayList<Sentence>(); - - public void add(Sentence currentSentence) { - this.sentences.add(currentSentence); - currentSentence.setDocument(this); - } - - public List<Sentence> getSentences() { - return sentences; - } - - public List<Sentence> getSentenceNeighbourhood(Sentence s) { - int pos = -1; - for (int i = 0; i < sentences.size(); i++) { - if (sentences.get(i).equals(s)) { - pos = i; - break; - } - } - - int first = Math.max(0, pos - 1); - int last = Math.min(sentences.size() - 1, pos + 1); - - return new ArrayList<Sentence>(sentences.subList(first, last + 1)); - } - - public void splitSentence(Sentence s, Word selectedWord) { - int pos = -1; - for (int i = 0; i < sentences.size(); i++) { - if (sentences.get(i).equals(s)) { - pos = i; - break; - } - } - sentences.remove(pos); - - s.splitClause(selectedWord.getClause(), selectedWord); - List<Clause> clauses1 = s.getClausesBefore(selectedWord.getClause()); - List<Clause> clauses2 = new ArrayList<Clause>(s.getClauses()); - clauses2.removeAll(clauses1); - - Sentence s1 = new Sentence(); - Sentence s2 = new Sentence(); - for (Clause c : clauses1) - s1.add(c); - for (Clause c : clauses2) - s2.add(c); - - sentences.add(pos, s1); - sentences.add(pos + 1, s2); - s1.setDocument(this); - s2.setDocument(this); - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Marker.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Marker.java deleted file mode 100644 index 0ad5038..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Marker.java +++ /dev/null @@ -1,81 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.basic; - -import java.util.ArrayList; -import java.util.List; - -public class Marker { - - private final List<Word> words = new ArrayList<Word>(); - - private String nuc = ""; - private String connect = ""; - private String type = ""; - - public Marker(List<Word> selectedWords) { - for (Word w : selectedWords) - add(w); - } - - public void add(Word w) { - this.words.add(w); - w.setMarker(this); - } - - public Marker(String nuc, String connect) { - if (nuc != null) - this.nuc = nuc; - if (connect != null) - setConnect(connect); - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - for (Word w : words) - sb.append(" " + w.getOrth()); - - return sb.substring(1); - } - - public Clause getClause() { - return this.words.get(0).getClause(); - } - - public void setNUC(String nuc) { - this.nuc = nuc; - } - - public String getNUC() { - return nuc; - } - - public Word getFirstWord() { - return words.get(0); - } - - public void deleteMe() { - for (Word w : words) - w.setMarker(null); - } - - public List<Word> getWords() { - return words; - } - - public String getConnect() { - return connect; - } - - public String getType() { - return type; - } - - public void setConnect(String connect) { - this.connect = connect; - if (!connect.equals("")) - this.type = "ext"; - else - this.type = "int"; - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Sentence.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Sentence.java deleted file mode 100644 index 23d7dc7..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Sentence.java +++ /dev/null @@ -1,100 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.basic; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class Sentence { - - private List<Clause> clauses = new ArrayList<Clause>(); - private Document document; - - public void add(Clause clause) { - this.clauses.add(clause); - clause.setSentence(this); - } - - public List<Clause> getClauses() { - return clauses; - } - - public void splitClause(Clause c, Word w) { - int pos = -1; - for (int i = 0; i < clauses.size(); i++) { - if (clauses.get(i).equals(c)) { - pos = i; - break; - } - } - List<Clause> split = c.split(w); - deleteClause(c); - - clauses.addAll(pos, split); - for (Clause cl : split) { - cl.setSentence(this); - } - } - - public void mergeClauseWithPrevious(Clause c) { - int pos = -1; - for (int i = 0; i < clauses.size(); i++) { - if (clauses.get(i).equals(c)) { - pos = i; - break; - } - } - Clause prevClause = clauses.get(pos - 1); - for (Word w : c.getWords()) - prevClause.add(w); - - deleteClause(c); - } - - public void mergeClauseWithNext(Clause c) { - int pos = -1; - for (int i = 0; i < clauses.size(); i++) { - if (clauses.get(i).equals(c)) { - pos = i; - break; - } - } - Clause nextClause = clauses.get(pos + 1); - List<Word> words = new ArrayList<Word>(c.getWords()); - Collections.reverse(words); - for (Word w : words) - nextClause.addFirst(w); - - deleteClause(c); - } - - private void deleteClause(Clause c) { - for (Clause clause : clauses) - if (c.equals(clause.getContinuedClause())) - clause.setContinuedClause(null); - - clauses.remove(c); - } - - public List<Clause> getClausesBefore(Clause c) { - int pos = 0; - for (int i = 0; i < clauses.size(); i++) - if (clauses.get(i).equals(c)) { - pos = i; - break; - } - - return new ArrayList<Clause>(clauses.subList(0, pos)); - } - - public Clause getLastClause() { - return clauses.get(clauses.size() - 1); - } - - public void setDocument(Document document) { - this.document = document; - } - - public Document getDocument() { - return this.document; - } -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Word.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Word.java deleted file mode 100644 index 8e9d70e..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/basic/Word.java +++ /dev/null @@ -1,76 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.basic; - -import pl.waw.ipipan.zil.summarization.clauseannotator.main.Clauseannotator; - -public class Word { - - private Clause clause = null; - - private String orth = null; - private String pos; - private String lemma; - - private Marker marker = null; - - public Word(String pos, String lemma) { - this.pos = pos; - this.lemma = lemma; - } - - public void setOrth(String orth) { - this.orth = orth; - } - - public String toString() { - return orth; - } - - public String getOrth() { - return this.orth; - } - - public Clause getClause() { - return this.clause; - } - - public void setClause(Clause clause) { - this.clause = clause; - } - - public String getPos() { - return this.pos; - } - - public String getLemma() { - return this.lemma; - } - - public boolean isFirstInClause() { - return this.clause.getFirstWord().equals(this); - } - - public boolean isVerb() { - if (Clauseannotator.VERB_POS_REGEXP == null) - return false; - return pos.matches(Clauseannotator.VERB_POS_REGEXP); - } - - public Marker getMarker() { - return this.marker; - } - - public void setMarker(Marker marker) { - this.marker = marker; - } - - public boolean isInMiddleOfMarker() { - if (marker == null) - return false; - - if (marker.getFirstWord().equals(this)) - return false; - - return true; - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/IdGenerator.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/IdGenerator.java deleted file mode 100644 index 6c732da..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/IdGenerator.java +++ /dev/null @@ -1,59 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.io; - -import java.util.HashMap; -import java.util.Map; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - - -public class IdGenerator { - - private int nextWordId = 0; - private int nextClauseId = 0; - private int nextSentenceId = 0; - private int nextMarkerId = 0; - - private Map<Word, String> word2Id = new HashMap<Word, String>(); - private Map<Clause, String> clause2Id = new HashMap<Clause, String>(); - private Map<Sentence, String> sentence2Id = new HashMap<Sentence, String>(); - private Map<Marker, String> marker2Id = new HashMap<Marker, String>(); - - public String getId(Word w) { - if (word2Id.containsKey(w)) - return word2Id.get(w); - - String newId = "W" + nextWordId++; - word2Id.put(w, newId); - return newId; - } - - public String getId(Marker m) { - if (marker2Id.containsKey(m)) - return marker2Id.get(m); - - String newId = "MARKER" + nextMarkerId++; - marker2Id.put(m, newId); - return newId; - } - - public String getId(Sentence s) { - if (sentence2Id.containsKey(s)) - return sentence2Id.get(s); - - String newId = "S" + nextSentenceId++; - sentence2Id.put(s, newId); - return newId; - } - - public String getId(Clause c) { - if (clause2Id.containsKey(c)) - return clause2Id.get(c); - - String newId = "CLAUSE" + nextClauseId++; - clause2Id.put(c, newId); - return newId; - } -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLReader.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLReader.java deleted file mode 100644 index 954ced3..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLReader.java +++ /dev/null @@ -1,195 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.io; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.log4j.Logger; -import org.codehaus.stax2.XMLInputFactory2; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Document; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class XMLReader { - - private static final Logger logger = Logger.getLogger(XMLReader.class); - - private static final XMLInputFactory xif = XMLInputFactory2.newInstance(); - - public static String loadText(File input, Document document) { - logger.info("Loading text from file: " + input); - - String error = null; - - InputStream is = null; - XMLStreamReader sr = null; - try { - is = new FileInputStream(input); - sr = xif.createXMLStreamReader(is); - - Sentence currentSentence = null; - Clause currentClause = null; - Word currentWord = null; - Marker currentMarker = null; - - Map<String, Clause> id2Clause = new HashMap<String, Clause>(); - - Map<Clause, String> clause2ContId = new HashMap<Clause, String>(); - - while (sr.hasNext()) { - sr.next(); - - if (sr.isStartElement()) { - String name = sr.getName().getLocalPart(); - - if (name.equalsIgnoreCase("S")) { - - currentSentence = new Sentence(); - - // artificial clause for first-time read - currentClause = new Clause(); - - } else if (name.equalsIgnoreCase("CLAUSE")) { - - String id = sr.getAttributeValue(null, "ID"); - String cont = sr.getAttributeValue(null, "CONTINUE"); - - if (id == null) - throw new Exception("Clause without id in line: " + sr.getLocation().getLineNumber()); - - currentClause = new Clause(); - id2Clause.put(id, currentClause); - - if (cont != null && !cont.equals("")) - clause2ContId.put(currentClause, cont); - - } else if (name.equalsIgnoreCase("W")) { - - String pos = sr.getAttributeValue(null, "POS"); - String lemma = sr.getAttributeValue(null, "LEMMA"); - if (pos == null) - pos = sr.getAttributeValue(null, "pos"); - if (lemma == null) - lemma = sr.getAttributeValue(null, "lemma"); - - if (currentWord != null) - throw new Exception("Word starting before previous word finished in line: " - + sr.getLocation().getLineNumber()); - - currentWord = new Word(pos, lemma); - - } else if (name.equalsIgnoreCase("MARKER")) { - - String nuc = sr.getAttributeValue(null, "NUC"); - String connect = sr.getAttributeValue(null, "CONNECT"); - - currentMarker = new Marker(nuc, connect); - } - - } else if (sr.isEndElement()) { - - String name = sr.getName().getLocalPart(); - - if (name.equalsIgnoreCase("S")) { - - if (currentSentence == null) - throw new Exception("Sentence ending before starting in line: " - + sr.getLocation().getLineNumber()); - - // for first-time read - if (currentClause != null) - currentSentence.add(currentClause); - - document.add(currentSentence); - currentSentence = null; - - } else if (name.equalsIgnoreCase("CLAUSE")) { - - currentSentence.add(currentClause); - currentClause = null; - - } else if (name.equalsIgnoreCase("W")) { - - if (currentWord == null) - throw new Exception("Word ending before starting in line: " - + sr.getLocation().getLineNumber()); - - if (currentClause == null) - throw new Exception("Word not in a clause in line: " + sr.getLocation().getLineNumber()); - - if (currentMarker != null) { - currentMarker.add(currentWord); - } - - if (currentWord.getPos() == null) - throw new Exception("Word without pos attribute in line: " - + sr.getLocation().getLineNumber()); - - currentClause.add(currentWord); - currentWord = null; - - } else if (name.equalsIgnoreCase("MARKER")) { - - if (currentClause == null) - throw new Exception("Marker not in a clause in line: " + sr.getLocation().getLineNumber()); - - if (currentMarker == null) - throw new Exception("Marker ended before started in line: " - + sr.getLocation().getLineNumber()); - - currentMarker = null; - } - - } else if (sr.isWhiteSpace()) { - - } else if (sr.isCharacters()) { - if (currentWord != null) { - if (currentWord.getOrth() != null) - throw new Exception("Second word orth in line: " + sr.getLocation().getLineNumber()); - - currentWord.setOrth(sr.getText()); - } - } - } - - for (Entry<Clause, String> e : clause2ContId.entrySet()) { - Clause c = e.getKey(); - String contId = e.getValue(); - - Clause cont = id2Clause.get(contId); - if (cont == null) - throw new Exception("Clause with id: " + contId + " not found in line: " - + sr.getLocation().getLineNumber()); - - c.setContinuedClause(cont); - } - - } catch (Exception e) { - error = "Error reading file: " + e.getLocalizedMessage(); - - } finally { - try { - if (is != null) - is.close(); - if (sr != null) - sr.close(); - } catch (Exception e) { - error = "Error closing file: " + input + " Details: " + e.getLocalizedMessage(); - } - } - - logger.info(document.getSentences().size() + " sentences found."); - - return error; - } -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLWriter.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLWriter.java deleted file mode 100644 index 44825d8..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/io/XMLWriter.java +++ /dev/null @@ -1,184 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.io; - - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.List; - -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.log4j.Logger; -import org.codehaus.stax2.XMLOutputFactory2; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class XMLWriter { - - private static final Logger logger = Logger.getLogger(XMLWriter.class); - private static final XMLOutputFactory xof = XMLOutputFactory2.newInstance(); - - private static final String INDENT = " "; - - public static boolean saveFile(File targetFile, List<Sentence> sentences) { - return saveFile(targetFile, sentences, false, false); - } - - public static boolean saveFile(File targetFile, List<Sentence> sentences, boolean omitClauses, boolean omitMarkers) { - logger.info("Saving sentences in file: " + targetFile); - BufferedWriter bw = null; - XMLStreamWriter xsw = null; - try { - - bw = new BufferedWriter(new FileWriter(targetFile)); - xsw = xof.createXMLStreamWriter(bw); - - IdGenerator gen = new IdGenerator(); - writeDocument(xsw, sentences, gen, omitClauses, omitMarkers); - - } catch (Exception e) { - logger.error("Error saving file: " + e.getLocalizedMessage()); - return false; - - } finally { - try { - if (xsw != null) - xsw.close(); - if (bw != null) - bw.close(); - - } catch (Exception e) { - logger.error("Error closing file: " + e.getLocalizedMessage()); - return false; - } - } - return true; - } - - private static void writeSentence(XMLStreamWriter xsw, Sentence s, int i, IdGenerator gen, boolean omitClauses, - boolean omitMarkers) throws XMLStreamException { - - indent(xsw, i); - xsw.writeStartElement("S"); - xsw.writeAttribute("ID", gen.getId(s)); - xsw.writeCharacters("\n"); - - for (Clause c : s.getClauses()) - writeClause(xsw, c, i + 1, gen, omitClauses, omitMarkers); - - indent(xsw, i); - xsw.writeEndElement(); // S - xsw.writeCharacters("\n"); - } - - private static void writeClause(XMLStreamWriter xsw, Clause c, int i, IdGenerator gen, boolean omitClauses, - boolean omitMarkers) throws XMLStreamException { - - if (!omitClauses) { - indent(xsw, i); - xsw.writeStartElement("CLAUSE"); - - xsw.writeAttribute("ID", gen.getId(c)); - - Clause cont = c.getContinuedClause(); - if (cont != null) - xsw.writeAttribute("CONTINUE", gen.getId(c.getContinuedClause())); - - xsw.writeCharacters("\n"); - } else { - i--; - } - - Marker prevMarker = null; - for (Word w : c.getWords()) { - Marker currentMarker = w.getMarker(); - - if (omitMarkers || currentMarker == null) { - - if (!omitMarkers && prevMarker != null) - endMarker(xsw, i + 1); - - writeWord(xsw, w, i + 1, gen); - - } else { - - if (prevMarker == null) { - startMarker(xsw, currentMarker, i + 1, gen); - - } else if (!prevMarker.equals(currentMarker)) { - endMarker(xsw, i + 1); - startMarker(xsw, currentMarker, i + 1, gen); - } - - writeWord(xsw, w, i + 2, gen); - } - - prevMarker = currentMarker; - } - - if (!omitMarkers && prevMarker != null) - endMarker(xsw, i + 1); - - if (!omitClauses) { - indent(xsw, i); - xsw.writeEndElement(); // CLAUSE - xsw.writeCharacters("\n"); - } - } - - private static void endMarker(XMLStreamWriter xsw, int i) throws XMLStreamException { - indent(xsw, i); - xsw.writeEndElement(); // MARKER - xsw.writeCharacters("\n"); - } - - private static void startMarker(XMLStreamWriter xsw, Marker currentMarker, int i, IdGenerator gen) - throws XMLStreamException { - indent(xsw, i); - xsw.writeStartElement("MARKER"); - xsw.writeAttribute("ID", gen.getId(currentMarker)); - xsw.writeAttribute("NUC", currentMarker.getNUC()); - xsw.writeAttribute("TYPE", currentMarker.getType()); - xsw.writeAttribute("CONNECT", currentMarker.getConnect()); - - xsw.writeCharacters("\n"); - } - - private static void writeWord(XMLStreamWriter xsw, Word w, int i, IdGenerator gen) throws XMLStreamException { - indent(xsw, i); - xsw.writeStartElement("W"); - xsw.writeAttribute("ID", gen.getId(w)); - xsw.writeAttribute("LEMMA", w.getLemma()); - xsw.writeAttribute("POS", w.getPos()); - - xsw.writeCharacters(w.getOrth()); - - xsw.writeEndElement(); // W - xsw.writeCharacters("\n"); - } - - private static void indent(XMLStreamWriter xsw, int i) throws XMLStreamException { - for (int j = 0; j < i; j++) - xsw.writeCharacters(INDENT); - } - - private static void writeDocument(XMLStreamWriter xsw, List<Sentence> sentences, IdGenerator gen, - boolean omitClauses, boolean omitMarkers) throws XMLStreamException { - xsw.writeStartDocument("utf-8", "1.0"); - xsw.writeCharacters("\n"); - xsw.writeStartElement("DOCUMENT"); - xsw.writeCharacters("\n"); - - for (Sentence s : sentences) - writeSentence(xsw, s, 1, gen, omitClauses, omitMarkers); - - xsw.writeEndElement(); // DOCUMENT - xsw.writeEndDocument(); - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/BottomPanel.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/BottomPanel.java deleted file mode 100644 index cd9e784..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/BottomPanel.java +++ /dev/null @@ -1,213 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.List; - -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class BottomPanel extends JPanel implements ItemListener { - - private static final long serialVersionUID = 285048609353220598L; - private static final Logger logger = Logger.getLogger(BottomPanel.class); - - private final MainTextPane textPane; - - // clause stuff - private final JComboBox<Object> cont = new JComboBox<Object>(); - private final JLabel currentClause = new JLabel(""); - - // marker stuff - private final JComboBox<String> markerNUC = new JComboBox<String>(); - private final JComboBox<String> markerConnect = new JComboBox<String>(); - private final JLabel currentMarker = new JLabel(""); - - { - markerNUC.addItem(""); - - markerNUC.addItem("_NN"); - markerNUC.addItem("_NS"); - markerNUC.addItem("_SN"); - - markerNUC.addItem("N_N"); - markerNUC.addItem("N_S"); - markerNUC.addItem("S_N"); - - markerNUC.addItem("NN_"); - markerNUC.addItem("NS_"); - markerNUC.addItem("SN_"); - - markerConnect.addItem(""); - - markerConnect.addItem("relate"); - markerConnect.addItem("fulfil"); - markerConnect.addItem("expect"); - } - - public BottomPanel(MainTextPane mainTextPane) { - super(); - this.textPane = mainTextPane; - - clearClauseSelection(); - clearMarkerSelection(); - - cont.addItemListener(this); - markerConnect.addItemListener(this); - markerNUC.addItemListener(this); - - this.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(5, 5, 5, 5); - - // labels - c.fill = GridBagConstraints.NONE; - c.gridx = 0; - c.gridy = GridBagConstraints.RELATIVE; - - this.add(new JLabel("Current clause:"), c); - this.add(new JLabel("Continues:"), c); - this.add(new JLabel("Current marker:"), c); - this.add(new JLabel("Current marker nuc:"), c); - this.add(new JLabel("Current marker connect:"), c); - - // values: - c.weightx = 1; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = GridBagConstraints.RELATIVE; - - this.add(currentClause, c); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - this.add(cont, c); - this.add(currentMarker, c); - this.add(markerNUC, c); - this.add(markerConnect, c); - } - - private synchronized void clearMarkerSelection() { - markerNUC.setEnabled(false); - markerConnect.setEnabled(false); - - currentMarker.setText("No marker selected"); - markerNUC.setSelectedIndex(0); - markerConnect.setSelectedIndex(0); - } - - private synchronized void clearClauseSelection() { - cont.setEnabled(false); - cont.removeAllItems(); - currentClause.setText("No clause selected"); - } - - public void selectionChanged(final List<Word> selectedSequence, final Marker m) { - if (selectedSequence == null) { - selectMarker(null); - selectClause(null); - } else { - Clause c = selectedSequence.get(0).getClause(); - - selectClause(c); - selectMarker(m); - } - } - - private synchronized void selectClause(Clause clause) { - - if (clause == null) { - clearClauseSelection(); - - } else { - currentClause.setText(clause.toString()); - - cont.setEnabled(false); - cont.removeAllItems(); - cont.addItem(""); - int sel = 0; - int i = 1; - - for (Clause c : clause.getSentence().getClausesBefore(clause)) { - if (c.equals(clause.getContinuedClause())) - sel = i; - - cont.addItem(c); - i++; - } - - cont.setSelectedIndex(sel); - cont.setEnabled(true); - } - } - - private synchronized void selectMarker(Marker m) { - - if (m == null) { - clearMarkerSelection(); - - } else { - currentMarker.setText(m.toString()); - - markerNUC.setEnabled(false); - markerNUC.setSelectedItem(m.getNUC()); - markerNUC.setEnabled(true); - - markerConnect.setEnabled(false); - markerConnect.setSelectedItem(m.getConnect()); - markerConnect.setEnabled(true); - } - } - - public synchronized void itemStateChanged(ItemEvent e) { - - // we don't care about deselection events - if (e.getStateChange() == ItemEvent.DESELECTED) - return; - - Component c = (Component) e.getSource(); - - if (c.isEnabled()) { - - if (c.equals(cont)) { - if (cont.getSelectedIndex() > 0) { - Clause clause = (Clause) cont.getSelectedItem(); - logger.debug("Continuing clause selection changed for: " + clause); - - textPane.setContinuingClause(clause); - } else { - textPane.setContinuingClause(null); - } - - } else if (c.equals(markerNUC)) { - - if (markerNUC.getSelectedIndex() >= 0) { - String nuc = (String) markerNUC.getSelectedItem(); - logger.debug("Marker nuc selection changed for: " + nuc); - - textPane.setMarkerNUC(nuc); - } - } else if (c.equals(markerConnect)) { - - if (markerConnect.getSelectedIndex() >= 0) { - String connect = (String) markerConnect.getSelectedItem(); - logger.debug("Marker connect selection changed for: " + connect); - - textPane.setMarkerConnect(connect); - } - } - } - } -} \ No newline at end of file diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Clauseannotator.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Clauseannotator.java deleted file mode 100644 index 0f0f32c..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Clauseannotator.java +++ /dev/null @@ -1,315 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.regex.Pattern; - -import javax.swing.JEditorPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.filechooser.FileFilter; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Document; -import pl.waw.ipipan.zil.summarization.clauseannotator.io.XMLReader; -import pl.waw.ipipan.zil.summarization.clauseannotator.io.XMLWriter; - -public class Clauseannotator extends JFrame implements Runnable { - - private static final String WINDOW_TITLE = "Clause and marker annotator"; - - private static final long serialVersionUID = -3830790411182131318L; - - private static final Logger logger = Logger.getLogger(Clauseannotator.class); - - private static final int HEIGTH = 600; - private static final int WIDTH = 800; - - public static final String verbposregexpFilename = "verb.regexp"; - public static String VERB_POS_REGEXP = null; - - static { - loadVerPosRegexp(); - } - - private JMenuItem save; - - private File currentFile = null; - - private MainSplitPanel mainSplitPane; - - public static void main(String[] args) { - if (args.length != 0 && args.length != 1) { - logger.error("Wrong usage! Should be: java -jar " + Clauseannotator.class.getSimpleName() + " [input file]"); - return; - } - final Clauseannotator clauseannotator = new Clauseannotator(); - try { - SwingUtilities.invokeAndWait(clauseannotator); - } catch (Exception e) { - logger.error("Error starting application: " + e.getLocalizedMessage()); - e.printStackTrace(); - return; - } - - if (args.length == 1) { - final File input = new File(args[0]); - if (input.exists()) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - clauseannotator.loadFile(input); - } - }); - } else { - logger.error("Input file: " + input + " doesn't exist!"); - } - } - } - - private static void loadVerPosRegexp() { - InputStream f = Clauseannotator.class.getClassLoader().getResourceAsStream(verbposregexpFilename); - if (f != null) { - String regex = null; - try { - BufferedReader bw = new BufferedReader(new InputStreamReader(f)); - regex = bw.readLine(); - - Pattern.compile(regex); - } catch (Exception e) { - logger.error("Error reading regexp file: " + e.getLocalizedMessage()); - return; - } - VERB_POS_REGEXP = regex; - logger.info("Loaded verb regexp: " + regex); - } - } - - public void run() { - this.setTitle(WINDOW_TITLE); - mainSplitPane = new MainSplitPanel(this); - this.getContentPane().add(mainSplitPane); - this.createMenu(); - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.addWindowListener(new MainWindowListener(this)); - this.setSize(WIDTH, HEIGTH); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); - this.setVisible(true); - } - - private void createMenu() { - JMenuBar menu = new JMenuBar(); - this.setJMenuBar(menu); - - JMenu file = new JMenu("File"); - menu.add(file); - - JMenuItem open = new JMenuItem("Open"); - open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); - open.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - requestOpenFile(); - } - }); - file.add(open); - - save = new JMenuItem("Save"); - save.setEnabled(false); - save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); - save.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - requestSaveFile(); - } - }); - file.add(save); - - JMenuItem exit = new JMenuItem("Exit"); - exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - exit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - requestExit(); - } - }); - file.add(exit); - - JMenu other = new JMenu("Other"); - JMenuItem help = new JMenuItem("Help"); - help.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - requestShowHelp(); - } - }); - - other.add(help); - menu.add(other); - } - - private void requestSaveFile() { - boolean success = XMLWriter.saveFile(currentFile, mainSplitPane.getSentences()); - - if (success) { - setTitle(WINDOW_TITLE); - save.setEnabled(false); - } else { - showError("Error saving file: " + currentFile); - } - } - - private final void requestOpenFile() { - if (!askToSaveChanges()) - return; - - JFileChooser chooser; - if (currentFile == null) - chooser = new JFileChooser(); - else - chooser = new JFileChooser(currentFile.getParentFile()); - - chooser.setFileFilter(new SummannotatorFileFilter()); - int result = chooser.showOpenDialog(this); - - if (result == JFileChooser.APPROVE_OPTION) { - this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - this.loadFile(chooser.getSelectedFile()); - this.setCursor(null); - } - } - - private boolean askToSaveChanges() { - if (!save.isEnabled()) - return true; - - int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); - - if (result == JOptionPane.CANCEL_OPTION) - return false; - - if (result == JOptionPane.YES_OPTION) - requestSaveFile(); - - return true; - } - - private final void requestExit() { - if (!askToSaveChanges()) - return; - - logger.info("Exiting."); - System.exit(0); - } - - private final void requestShowHelp() { - JFrame helpFrame = new JFrame("Help"); - helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JEditorPane editorPane = new JEditorPane(); - editorPane.setEditable(false); - URL helpURL = Clauseannotator.class.getClassLoader().getResource("help.html"); - if (helpURL != null) { - try { - editorPane.setPage(helpURL); - } catch (IOException e) { - logger.error("Attempted to read a bad URL: " + helpURL); - } - } else { - logger.error("Couldn't find file: help.html"); - } - - // Put the editor pane in a scroll pane. - JScrollPane editorScrollPane = new JScrollPane(editorPane); - editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setPreferredSize(new Dimension(800, 600)); - editorScrollPane.setMinimumSize(new Dimension(30, 30)); - - helpFrame.getContentPane().add(editorScrollPane); - helpFrame.pack(); - helpFrame.setVisible(true); - } - - private final void loadFile(File input) { - if (!input.exists()) { - String err = "File " + input + " doesn't exist!"; - logger.error(err); - showError(err); - return; - } - Document doc = new Document(); - String error = XMLReader.loadText(input, doc); - if (error != null) { - logger.error(error); - showError(error); - return; - } - if (doc.getSentences().size() == 0) { - String err = "No clauses found in file: " + input; - logger.error(err); - showError(err); - return; - } - - mainSplitPane.setSentences(doc.getSentences()); - - currentFile = input; - save.setEnabled(false); - setTitle(WINDOW_TITLE); - } - - private void showError(String string) { - JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); - } - - private final class SummannotatorFileFilter extends FileFilter { - @Override - public String getDescription() { - return "XML files"; - } - - @Override - public boolean accept(File f) { - return f.getName().endsWith(".xml") || f.isDirectory(); - } - } - - public void annotationChanged() { - save.setEnabled(true); - setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); - } - - private class MainWindowListener extends WindowAdapter { - - private Clauseannotator summanotator; - - public MainWindowListener(Clauseannotator sumannotator) { - this.summanotator = sumannotator; - } - - public void windowClosing(WindowEvent we) { - this.summanotator.requestExit(); - } - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/FixIds.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/FixIds.java deleted file mode 100644 index 26afa9b..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/FixIds.java +++ /dev/null @@ -1,21 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.io.File; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Document; -import pl.waw.ipipan.zil.summarization.clauseannotator.io.XMLReader; -import pl.waw.ipipan.zil.summarization.clauseannotator.io.XMLWriter; - -public class FixIds { - - public static void main(String[] args) { - - File dir = new File(args[0]); - for (File f : dir.listFiles()) { - Document doc = new Document(); - XMLReader.loadText(f, doc); - XMLWriter.saveFile(f, doc.getSentences(), false, true); - } - } -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainDocument.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainDocument.java deleted file mode 100644 index 3ecb7e7..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainDocument.java +++ /dev/null @@ -1,301 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.Caret; -import javax.swing.text.DefaultStyledDocument; -import javax.swing.text.SimpleAttributeSet; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class MainDocument extends DefaultStyledDocument implements CaretListener, KeyListener { - - private static final long serialVersionUID = 4276485351817531583L; - private static final Logger logger = Logger.getLogger(MainDocument.class); - - private final MainTextPane textPane; - - private List<Word> selectedWords = null; - private Marker selectedMarker = null; - - private List<Word> posToWord = null; - private Map<Word, Integer> wordToStartPos = null; - private List<Sentence> sentences = null; - - private boolean ignoreCaretUpdate = false; - - public MainDocument(MainTextPane mainTextPane) { - this.textPane = mainTextPane; - } - - public synchronized void setSentences(final List<Sentence> sents) { - - ignoreCaretUpdate = true; - - try { - remove(0, getLength()); - } catch (BadLocationException e) { - logger.error("Error clearing document: " + e.getLocalizedMessage()); - } - - sentences = sents; - - posToWord = new ArrayList<Word>(); - wordToStartPos = new HashMap<Word, Integer>(); - - int pos = 0; - try { - for (Sentence s : sentences) { - - for (Clause c : s.getClauses()) { - - insertString(pos, "[ ", Styles.getHandleStyle()); - pos += 2; - posToWord.add(null); - posToWord.add(null); - - Word prev = null; - for (Word w : c.getWords()) { - if (prev != null) { - insertString(pos, " ", Styles.getWhitespaceStyle()); - pos += 1; - posToWord.add(prev); - } - - String orth = w.getOrth(); - boolean selected = selectedWords != null && selectedWords.contains(w); - insertString(pos, orth, Styles.getWordStyle(w, selected)); - int length = orth.length(); - wordToStartPos.put(w, pos); - for (int i = 0; i < length; i++) - posToWord.add(w); - pos += length; - - prev = w; - } - - insertString(pos, " ]", Styles.getHandleStyle()); - pos += 2; - posToWord.add(null); - posToWord.add(null); - } - insertString(pos, "\n\n", Styles.getWhitespaceStyle()); - pos += 2; - posToWord.add(null); - posToWord.add(null); - } - // for last dot - posToWord.add(null); - - } catch (BadLocationException e) { - logger.error("Error setting document: " + e.getLocalizedMessage()); - } - - ignoreCaretUpdate = false; - } - - public synchronized List<Sentence> getSentences() { - return sentences; - } - - public void caretUpdate(final CaretEvent e) { - if (ignoreCaretUpdate) - return; - - int dot = e.getDot(); - int mark = e.getMark(); - selectionOcurred(mark, dot); - } - - private synchronized void selectionOcurred(int mark, int dot) { - - if (posToWord == null) - return; - - Word startWord; - Word stopWord; - if (mark > dot) { - startWord = posToWord.get(dot); - stopWord = posToWord.get(mark); - } else { - startWord = posToWord.get(mark); - stopWord = posToWord.get(dot); - } - - if (startWord == null || stopWord == null) { - this.setSelectedWords(null, dot); - return; - } - - Clause clause1 = startWord.getClause(); - Clause clause2 = stopWord.getClause(); - - if (!clause1.equals(clause2)) { - this.setSelectedWords(null, dot); - return; - } - - List<Word> selectedSequence = clause1.getWordsSequence(startWord, stopWord); - - this.setSelectedWords(selectedSequence, dot); - } - - public synchronized void setSelectedWords(List<Word> selectedSequence, int mark) { - - if (wordToStartPos == null) - return; - - logger.debug("Setting selected words: " + selectedSequence); - - // remove previous selection - if (this.selectedWords != null) { - for (Word w : selectedWords) { - SimpleAttributeSet att = Styles.getWordStyle(w, false); - int start = wordToStartPos.get(w); - int len = w.toString().length(); - this.setCharacterAttributes(start, len, att, true); - } - } - - // mark new selection - if (selectedSequence != null) { - for (Word w : selectedSequence) { - SimpleAttributeSet att = Styles.getWordStyle(w, true); - int start = wordToStartPos.get(w); - int len = w.toString().length(); - this.setCharacterAttributes(start, len, att, true); - } - } - - this.selectedWords = selectedSequence; - this.selectedMarker = getMarkerFromSelection(selectedSequence); - - if (this.ignoreCaretUpdate) { - this.textPane.selectionChanged(selectedSequence, selectedMarker, mark); - } else { - this.ignoreCaretUpdate = true; - this.textPane.selectionChanged(selectedSequence, selectedMarker, mark); - this.ignoreCaretUpdate = false; - } - - } - - private Marker getMarkerFromSelection(List<Word> selectedSequence) { - if (selectedSequence == null) - return null; - - Marker m = null; - for (Word w : selectedSequence) { - if (w.getMarker() != null) { - if (m == null) { - m = w.getMarker(); - } else if (!m.equals(w.getMarker())) { - m = null; - break; - } - } - } - return m; - } - - public synchronized Word getFirstSelectedWord() { - if (selectedWords == null) - return null; - return this.selectedWords.get(0); - } - - public synchronized int getFirstSelectedWordStartPos() { - Word firstSelectedWord = getFirstSelectedWord(); - if (firstSelectedWord == null || wordToStartPos == null) - return 0; - return wordToStartPos.get(firstSelectedWord); - } - - public void keyTyped(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) { - ignoreCaretUpdate = true; - } - } - - public void keyReleased(final KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - textPane.splitClause(); - } else if (e.getKeyCode() == KeyEvent.VK_P) { - textPane.mergeClauseWithPrevious(); - } else if (e.getKeyCode() == KeyEvent.VK_N) { - textPane.mergeClauseWithNext(); - } else if (e.getKeyCode() == KeyEvent.VK_M) { - textPane.createMarker(); - } else if (e.getKeyCode() == KeyEvent.VK_D) { - textPane.deleteMarker(); - } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { - ignoreCaretUpdate = false; - Caret c = textPane.getCaret(); - selectionOcurred(c.getDot(), c.getMark()); - } - // } else if (e.getKeyCode() == KeyEvent.VK_S) { - // textPane.splitSentence(); - // } - - } - - public synchronized List<Word> getSelectedWords() { - return this.selectedWords; - } - - public synchronized Marker getSelectedMarker() { - return this.selectedMarker; - } - - public synchronized void refreshCurrentMarkerStyle() { - if (selectedMarker == null || wordToStartPos == null) - return; - - for (Word w : selectedMarker.getWords()) { - boolean selected = false; - if (selectedWords.contains(w)) - selected = true; - - SimpleAttributeSet att = Styles.getWordStyle(w, selected); - int start = wordToStartPos.get(w); - int len = w.toString().length(); - this.setCharacterAttributes(start, len, att, true); - } - } - - public synchronized void refreshCurrentClauseStyle() { - if (selectedWords == null || wordToStartPos == null) - return; - - Clause c = selectedWords.get(0).getClause(); - - for (Word w : c.getWords()) { - boolean selected = false; - if (selectedWords.contains(w)) - selected = true; - - SimpleAttributeSet att = Styles.getWordStyle(w, selected); - int start = wordToStartPos.get(w); - int len = w.toString().length(); - this.setCharacterAttributes(start, len, att, true); - } - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainSplitPanel.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainSplitPanel.java deleted file mode 100644 index df55787..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainSplitPanel.java +++ /dev/null @@ -1,57 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.util.List; - -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class MainSplitPanel extends JSplitPane { - - private static final long serialVersionUID = 3656861958564714263L; - private static final Logger logger = Logger.getLogger(MainSplitPanel.class); - - private Clauseannotator clauseannotator; - - private MainTextPane mainTextPane; - private BottomPanel bottomPanel; - - public MainSplitPanel(Clauseannotator clauseannotator) { - super(JSplitPane.VERTICAL_SPLIT); - - this.clauseannotator = clauseannotator; - - logger.info("Creating main panel..."); - - mainTextPane = new MainTextPane(this); - bottomPanel = new BottomPanel(mainTextPane); - - this.setTopComponent(new JScrollPane(mainTextPane)); - this.setBottomComponent(bottomPanel); - this.setOneTouchExpandable(true); - this.setDividerLocation(350); - } - - public void setSentences(final List<Sentence> sentences) { - mainTextPane.setSentences(sentences); - } - - public List<Sentence> getSentences() { - return mainTextPane.getSentences(); - } - - public void selectionChanged(List<Word> selectedSequence, Marker m) { - bottomPanel.selectionChanged(selectedSequence, m); - } - - public void annotationChanged() { - this.clauseannotator.annotationChanged(); - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainTextPane.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainTextPane.java deleted file mode 100644 index 3c076ab..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/MainTextPane.java +++ /dev/null @@ -1,214 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.awt.Insets; -import java.util.List; - -import javax.swing.JTextPane; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Marker; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Sentence; -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class MainTextPane extends JTextPane { - - private static final long serialVersionUID = 3709902726162446568L; - private static final Logger logger = Logger.getLogger(MainTextPane.class); - - private MainSplitPanel mainSplitPanel; - - private MainDocument document; - - public MainTextPane(MainSplitPanel mainSplitPanel) { - super(); - - this.mainSplitPanel = mainSplitPanel; - this.document = new MainDocument(this); - - this.setStyledDocument(document); - this.setMargin(new Insets(5, 5, 5, 5)); - this.setEditable(false); - - this.addCaretListener(document); - this.addKeyListener(document); - } - - public void setSentences(List<Sentence> sentences) { - selectionChanged(null, null, 0); - document.setSentences(sentences); - this.setCaretPosition(0); - this.getCaret().setVisible(true); - } - - public List<Sentence> getSentences() { - return document.getSentences(); - } - - public void selectionChanged(List<Word> selectedSequence, Marker m, int dot) { - this.select(dot, dot); - this.getCaret().setVisible(true); - mainSplitPanel.selectionChanged(selectedSequence, m); - } - - private void reloadSentences() { - document.setSentences(document.getSentences()); - final int caretPos = document.getFirstSelectedWordStartPos(); - this.select(caretPos, caretPos); - this.getCaret().setVisible(true); - this.mainSplitPanel.annotationChanged(); - } - - private void reloadCurrentClause() { - document.refreshCurrentClauseStyle(); - this.mainSplitPanel.annotationChanged(); - } - - private void reloadCurrentMarker() { - document.refreshCurrentMarkerStyle(); - this.mainSplitPanel.annotationChanged(); - } - - /* ACTIONS */ - - public synchronized void splitClause() { - Word selectedWord = document.getFirstSelectedWord(); - if (selectedWord == null) - return; - - if (selectedWord.isFirstInClause()) - return; - - if (selectedWord.isInMiddleOfMarker()) - return; - - Clause c = selectedWord.getClause(); - logger.info("Splitting clause: " + c + " starting from word: " + selectedWord); - Sentence s = c.getSentence(); - s.splitClause(c, selectedWord); - - reloadSentences(); - } - - public synchronized void mergeClauseWithPrevious() { - Word selectedWord = document.getFirstSelectedWord(); - if (selectedWord == null) - return; - Clause c = selectedWord.getClause(); - - if (c.isFirstInSentence()) - return; - - logger.info("Merging clause: " + c + " into previous one"); - Sentence s = c.getSentence(); - s.mergeClauseWithPrevious(c); - - reloadSentences(); - } - - public synchronized void mergeClauseWithNext() { - Word selectedWord = document.getFirstSelectedWord(); - if (selectedWord == null) - return; - Clause c = selectedWord.getClause(); - - if (c.isLastInSentence()) - return; - - logger.info("Merging clause: " + c + " into next one"); - Sentence s = c.getSentence(); - s.mergeClauseWithNext(c); - - reloadSentences(); - } - - public synchronized void setContinuingClause(Clause cont) { - Word selectedWord = document.getFirstSelectedWord(); - if (selectedWord == null) { - logger.error("Trying to continiuing clause when no clause chosen!"); - return; - } - - Clause c = selectedWord.getClause(); - logger.info("Setting continiuing clause: " + cont + " for clause: " + c); - c.setContinuedClause(cont); - - reloadCurrentClause(); - } - - public synchronized void createMarker() { - List<Word> selectedWords = document.getSelectedWords(); - if (selectedWords == null) - return; - - for (Word w : selectedWords) - if (w.getMarker() != null) - return; - - logger.info("Creating new marker from words: " + selectedWords); - new Marker(selectedWords); - - reloadSentences(); - } - - public synchronized void deleteMarker() { - Marker selectedMarker = document.getSelectedMarker(); - if (selectedMarker == null) - return; - - logger.info("Deleting marker: " + selectedMarker); - selectedMarker.deleteMe(); - - reloadSentences(); - } - - public synchronized void setMarkerNUC(String nuc) { - Marker m = document.getSelectedMarker(); - if (m == null) { - logger.error("Trying to set marker nuc when no marker chosen!"); - return; - } - - logger.info("Setting nuc " + nuc + " for marker: " + m); - m.setNUC(nuc); - - reloadCurrentMarker(); - } - - public void splitSentence() { - Word selectedWord = document.getFirstSelectedWord(); - if (selectedWord == null) - return; - - if (selectedWord.isFirstInClause()) - return; - - if (selectedWord.isInMiddleOfMarker()) - return; - - Clause c = selectedWord.getClause(); - Sentence s = c.getSentence(); - logger.info("Splitting sentence: " + s + " starting from word: " + selectedWord); - - s.getDocument().splitSentence(s, selectedWord); - - reloadSentences(); - - } - - public void setMarkerConnect(String connect) { - Marker m = document.getSelectedMarker(); - if (m == null) { - logger.error("Trying to set marker connect when no marker chosen!"); - return; - } - - logger.info("Setting connect " + connect + " for marker: " + m); - m.setConnect(connect); - - reloadCurrentMarker(); - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Styles.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Styles.java deleted file mode 100644 index 26ae5ce..0000000 --- a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clauseannotator/main/Styles.java +++ /dev/null @@ -1,51 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clauseannotator.main; - - -import java.awt.Color; - -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.StyleConstants; - -import pl.waw.ipipan.zil.summarization.clauseannotator.basic.Word; - -public class Styles { - - private static SimpleAttributeSet handleStyle; - private static SimpleAttributeSet whitespaceStyle; - - static { - handleStyle = new SimpleAttributeSet(); - StyleConstants.setBold(handleStyle, true); - - whitespaceStyle = new SimpleAttributeSet(); - } - - public static SimpleAttributeSet getWordStyle(Word w, boolean selected) { - SimpleAttributeSet defaultStyle = new SimpleAttributeSet(); - if (w.getClause().getContinuedClause() != null) - StyleConstants.setBackground(defaultStyle, Color.getHSBColor(0.069f, 0.20f, 0.99f)); - - if (w.getMarker() != null) { - StyleConstants.setUnderline(defaultStyle, true); - if (w.getMarker().getNUC().equals("")) - StyleConstants.setBackground(defaultStyle, Color.magenta); - } - - if (selected) - StyleConstants.setBackground(defaultStyle, Color.yellow); - - if (w.isVerb()) - StyleConstants.setBold(defaultStyle, true); - - return defaultStyle; - } - - public static SimpleAttributeSet getHandleStyle() { - return handleStyle; - } - - public static SimpleAttributeSet getWhitespaceStyle() { - return whitespaceStyle; - } - -} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Clause.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Clause.java new file mode 100644 index 0000000..ffa8970 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Clause.java @@ -0,0 +1,117 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.basic; + +import java.util.ArrayList; +import java.util.List; + +public class Clause { + + private Sentence sentence; + private final List<Word> words = new ArrayList<Word>(); + + private Clause cont = null; + + public void add(Word currentWord) { + this.words.add(currentWord); + currentWord.setClause(this); + } + + public void addFirst(Word currentWord) { + this.words.add(0, currentWord); + currentWord.setClause(this); + } + + public List<Word> getWords() { + return words; + } + + public Sentence getSentence() { + return this.sentence; + } + + public void setSentence(Sentence sentence) { + this.sentence = sentence; + } + + public List<Clause> split(Word w) { + Clause c1 = new Clause(); + Clause c2 = new Clause(); + + boolean toC1 = true; + for (Word word : words) { + if (toC1) { + if (word.equals(w)) { + toC1 = false; + c2.add(word); + } else { + c1.add(word); + } + } else { + c2.add(word); + } + } + + ArrayList<Clause> l = new ArrayList<Clause>(); + l.add(c1); + l.add(c2); + return l; + } + + public Clause getContinuedClause() { + return cont; + } + + public boolean isFirstInSentence() { + return this.sentence.getClauses().get(0).equals(this); + } + + public boolean isLastInSentence() { + return this.sentence.getLastClause().equals(this); + } + + public String toTrimmedString(int len) { + StringBuffer sb = new StringBuffer(); + boolean first = true; + for (Word w : words) + if (first) { + sb.append(w.toString()); + first = false; + } else { + sb.append(" " + w.toString()); + } + + String trimmed = sb.toString().substring(0, Math.min(sb.toString().length(), len)); + + return sb.toString().length() < len ? trimmed : trimmed + "..."; + } + + @Override + public String toString() { + return toTrimmedString(80); + } + + public void setContinuedClause(Clause clause) { + this.cont = clause; + } + + public List<Word> getWordsSequence(Word startWord, Word stopWord) { + int start = -1; + int stop = -1; + for (int i = 0; i < words.size(); i++) { + Word w = words.get(i); + if (w.equals(startWord)) { + start = i; + } + if (w.equals(stopWord)) { + stop = i; + break; + } + } + + return new ArrayList<Word>(this.words.subList(start, stop + 1)); + } + + public Word getFirstWord() { + return this.words.get(0); + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Document.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Document.java new file mode 100644 index 0000000..08616c4 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Document.java @@ -0,0 +1,62 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.basic; + +import java.util.ArrayList; +import java.util.List; + +public class Document { + + private List<Sentence> sentences = new ArrayList<Sentence>(); + + public void add(Sentence currentSentence) { + this.sentences.add(currentSentence); + currentSentence.setDocument(this); + } + + public List<Sentence> getSentences() { + return sentences; + } + + public List<Sentence> getSentenceNeighbourhood(Sentence s) { + int pos = -1; + for (int i = 0; i < sentences.size(); i++) { + if (sentences.get(i).equals(s)) { + pos = i; + break; + } + } + + int first = Math.max(0, pos - 1); + int last = Math.min(sentences.size() - 1, pos + 1); + + return new ArrayList<Sentence>(sentences.subList(first, last + 1)); + } + + public void splitSentence(Sentence s, Word selectedWord) { + int pos = -1; + for (int i = 0; i < sentences.size(); i++) { + if (sentences.get(i).equals(s)) { + pos = i; + break; + } + } + sentences.remove(pos); + + s.splitClause(selectedWord.getClause(), selectedWord); + List<Clause> clauses1 = s.getClausesBefore(selectedWord.getClause()); + List<Clause> clauses2 = new ArrayList<Clause>(s.getClauses()); + clauses2.removeAll(clauses1); + + Sentence s1 = new Sentence(); + Sentence s2 = new Sentence(); + for (Clause c : clauses1) + s1.add(c); + for (Clause c : clauses2) + s2.add(c); + + sentences.add(pos, s1); + sentences.add(pos + 1, s2); + s1.setDocument(this); + s2.setDocument(this); + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Marker.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Marker.java new file mode 100644 index 0000000..90964fa --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Marker.java @@ -0,0 +1,81 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.basic; + +import java.util.ArrayList; +import java.util.List; + +public class Marker { + + private final List<Word> words = new ArrayList<Word>(); + + private String nuc = ""; + private String connect = ""; + private String type = ""; + + public Marker(List<Word> selectedWords) { + for (Word w : selectedWords) + add(w); + } + + public void add(Word w) { + this.words.add(w); + w.setMarker(this); + } + + public Marker(String nuc, String connect) { + if (nuc != null) + this.nuc = nuc; + if (connect != null) + setConnect(connect); + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Word w : words) + sb.append(" " + w.getOrth()); + + return sb.substring(1); + } + + public Clause getClause() { + return this.words.get(0).getClause(); + } + + public void setNUC(String nuc) { + this.nuc = nuc; + } + + public String getNUC() { + return nuc; + } + + public Word getFirstWord() { + return words.get(0); + } + + public void deleteMe() { + for (Word w : words) + w.setMarker(null); + } + + public List<Word> getWords() { + return words; + } + + public String getConnect() { + return connect; + } + + public String getType() { + return type; + } + + public void setConnect(String connect) { + this.connect = connect; + if (!connect.equals("")) + this.type = "ext"; + else + this.type = "int"; + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Sentence.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Sentence.java new file mode 100644 index 0000000..4c7e4a1 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Sentence.java @@ -0,0 +1,100 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.basic; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Sentence { + + private List<Clause> clauses = new ArrayList<Clause>(); + private Document document; + + public void add(Clause clause) { + this.clauses.add(clause); + clause.setSentence(this); + } + + public List<Clause> getClauses() { + return clauses; + } + + public void splitClause(Clause c, Word w) { + int pos = -1; + for (int i = 0; i < clauses.size(); i++) { + if (clauses.get(i).equals(c)) { + pos = i; + break; + } + } + List<Clause> split = c.split(w); + deleteClause(c); + + clauses.addAll(pos, split); + for (Clause cl : split) { + cl.setSentence(this); + } + } + + public void mergeClauseWithPrevious(Clause c) { + int pos = -1; + for (int i = 0; i < clauses.size(); i++) { + if (clauses.get(i).equals(c)) { + pos = i; + break; + } + } + Clause prevClause = clauses.get(pos - 1); + for (Word w : c.getWords()) + prevClause.add(w); + + deleteClause(c); + } + + public void mergeClauseWithNext(Clause c) { + int pos = -1; + for (int i = 0; i < clauses.size(); i++) { + if (clauses.get(i).equals(c)) { + pos = i; + break; + } + } + Clause nextClause = clauses.get(pos + 1); + List<Word> words = new ArrayList<Word>(c.getWords()); + Collections.reverse(words); + for (Word w : words) + nextClause.addFirst(w); + + deleteClause(c); + } + + private void deleteClause(Clause c) { + for (Clause clause : clauses) + if (c.equals(clause.getContinuedClause())) + clause.setContinuedClause(null); + + clauses.remove(c); + } + + public List<Clause> getClausesBefore(Clause c) { + int pos = 0; + for (int i = 0; i < clauses.size(); i++) + if (clauses.get(i).equals(c)) { + pos = i; + break; + } + + return new ArrayList<Clause>(clauses.subList(0, pos)); + } + + public Clause getLastClause() { + return clauses.get(clauses.size() - 1); + } + + public void setDocument(Document document) { + this.document = document; + } + + public Document getDocument() { + return this.document; + } +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Word.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Word.java new file mode 100644 index 0000000..2dd0f53 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/basic/Word.java @@ -0,0 +1,76 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.basic; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.main.ClauseAnnotator; + +public class Word { + + private Clause clause = null; + + private String orth = null; + private String pos; + private String lemma; + + private Marker marker = null; + + public Word(String pos, String lemma) { + this.pos = pos; + this.lemma = lemma; + } + + public void setOrth(String orth) { + this.orth = orth; + } + + public String toString() { + return orth; + } + + public String getOrth() { + return this.orth; + } + + public Clause getClause() { + return this.clause; + } + + public void setClause(Clause clause) { + this.clause = clause; + } + + public String getPos() { + return this.pos; + } + + public String getLemma() { + return this.lemma; + } + + public boolean isFirstInClause() { + return this.clause.getFirstWord().equals(this); + } + + public boolean isVerb() { + if (ClauseAnnotator.VERB_POS_REGEXP == null) + return false; + return pos.matches(ClauseAnnotator.VERB_POS_REGEXP); + } + + public Marker getMarker() { + return this.marker; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public boolean isInMiddleOfMarker() { + if (marker == null) + return false; + + if (marker.getFirstWord().equals(this)) + return false; + + return true; + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/IdGenerator.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/IdGenerator.java new file mode 100644 index 0000000..54f5cdc --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/IdGenerator.java @@ -0,0 +1,58 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.io; + +import java.util.HashMap; +import java.util.Map; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class IdGenerator { + + private int nextWordId = 0; + private int nextClauseId = 0; + private int nextSentenceId = 0; + private int nextMarkerId = 0; + + private Map<Word, String> word2Id = new HashMap<Word, String>(); + private Map<Clause, String> clause2Id = new HashMap<Clause, String>(); + private Map<Sentence, String> sentence2Id = new HashMap<Sentence, String>(); + private Map<Marker, String> marker2Id = new HashMap<Marker, String>(); + + public String getId(Word w) { + if (word2Id.containsKey(w)) + return word2Id.get(w); + + String newId = "W" + nextWordId++; + word2Id.put(w, newId); + return newId; + } + + public String getId(Marker m) { + if (marker2Id.containsKey(m)) + return marker2Id.get(m); + + String newId = "MARKER" + nextMarkerId++; + marker2Id.put(m, newId); + return newId; + } + + public String getId(Sentence s) { + if (sentence2Id.containsKey(s)) + return sentence2Id.get(s); + + String newId = "S" + nextSentenceId++; + sentence2Id.put(s, newId); + return newId; + } + + public String getId(Clause c) { + if (clause2Id.containsKey(c)) + return clause2Id.get(c); + + String newId = "CLAUSE" + nextClauseId++; + clause2Id.put(c, newId); + return newId; + } +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLReader.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLReader.java new file mode 100644 index 0000000..9a53fc8 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLReader.java @@ -0,0 +1,194 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.log4j.Logger; +import org.codehaus.stax2.XMLInputFactory2; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Document; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class XMLReader { + + private static final Logger logger = Logger.getLogger(XMLReader.class); + + private static final XMLInputFactory xif = XMLInputFactory2.newInstance(); + + public static String loadText(File input, Document document) { + logger.info("Loading text from file: " + input); + + String error = null; + + InputStream is = null; + XMLStreamReader sr = null; + try { + is = new FileInputStream(input); + sr = xif.createXMLStreamReader(is); + + Sentence currentSentence = null; + Clause currentClause = null; + Word currentWord = null; + Marker currentMarker = null; + + Map<String, Clause> id2Clause = new HashMap<String, Clause>(); + + Map<Clause, String> clause2ContId = new HashMap<Clause, String>(); + + while (sr.hasNext()) { + sr.next(); + + if (sr.isStartElement()) { + String name = sr.getName().getLocalPart(); + + if (name.equalsIgnoreCase("S")) { + + currentSentence = new Sentence(); + + // artificial clause for first-time read + currentClause = new Clause(); + + } else if (name.equalsIgnoreCase("CLAUSE")) { + + String id = sr.getAttributeValue(null, "ID"); + String cont = sr.getAttributeValue(null, "CONTINUE"); + + if (id == null) + throw new Exception("Clause without id in line: " + sr.getLocation().getLineNumber()); + + currentClause = new Clause(); + id2Clause.put(id, currentClause); + + if (cont != null && !cont.equals("")) + clause2ContId.put(currentClause, cont); + + } else if (name.equalsIgnoreCase("W")) { + + String pos = sr.getAttributeValue(null, "POS"); + String lemma = sr.getAttributeValue(null, "LEMMA"); + if (pos == null) + pos = sr.getAttributeValue(null, "pos"); + if (lemma == null) + lemma = sr.getAttributeValue(null, "lemma"); + + if (currentWord != null) + throw new Exception("Word starting before previous word finished in line: " + + sr.getLocation().getLineNumber()); + + currentWord = new Word(pos, lemma); + + } else if (name.equalsIgnoreCase("MARKER")) { + + String nuc = sr.getAttributeValue(null, "NUC"); + String connect = sr.getAttributeValue(null, "CONNECT"); + + currentMarker = new Marker(nuc, connect); + } + + } else if (sr.isEndElement()) { + + String name = sr.getName().getLocalPart(); + + if (name.equalsIgnoreCase("S")) { + + if (currentSentence == null) + throw new Exception("Sentence ending before starting in line: " + + sr.getLocation().getLineNumber()); + + // for first-time read + if (currentClause != null) + currentSentence.add(currentClause); + + document.add(currentSentence); + currentSentence = null; + + } else if (name.equalsIgnoreCase("CLAUSE")) { + + currentSentence.add(currentClause); + currentClause = null; + + } else if (name.equalsIgnoreCase("W")) { + + if (currentWord == null) + throw new Exception("Word ending before starting in line: " + + sr.getLocation().getLineNumber()); + + if (currentClause == null) + throw new Exception("Word not in a clause in line: " + sr.getLocation().getLineNumber()); + + if (currentMarker != null) { + currentMarker.add(currentWord); + } + + if (currentWord.getPos() == null) + throw new Exception("Word without pos attribute in line: " + + sr.getLocation().getLineNumber()); + + currentClause.add(currentWord); + currentWord = null; + + } else if (name.equalsIgnoreCase("MARKER")) { + + if (currentClause == null) + throw new Exception("Marker not in a clause in line: " + sr.getLocation().getLineNumber()); + + if (currentMarker == null) + throw new Exception("Marker ended before started in line: " + + sr.getLocation().getLineNumber()); + + currentMarker = null; + } + + } else if (sr.isWhiteSpace()) { + + } else if (sr.isCharacters()) { + if (currentWord != null) { + if (currentWord.getOrth() != null) + throw new Exception("Second word orth in line: " + sr.getLocation().getLineNumber()); + + currentWord.setOrth(sr.getText()); + } + } + } + + for (Entry<Clause, String> e : clause2ContId.entrySet()) { + Clause c = e.getKey(); + String contId = e.getValue(); + + Clause cont = id2Clause.get(contId); + if (cont == null) + throw new Exception("Clause with id: " + contId + " not found in line: " + + sr.getLocation().getLineNumber()); + + c.setContinuedClause(cont); + } + + } catch (Exception e) { + error = "Error reading file: " + e.getLocalizedMessage(); + + } finally { + try { + if (is != null) + is.close(); + if (sr != null) + sr.close(); + } catch (Exception e) { + error = "Error closing file: " + input + " Details: " + e.getLocalizedMessage(); + } + } + + logger.info(document.getSentences().size() + " sentences found."); + + return error; + } +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLWriter.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLWriter.java new file mode 100644 index 0000000..2fcdd61 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/io/XMLWriter.java @@ -0,0 +1,183 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.io; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.List; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.log4j.Logger; +import org.codehaus.stax2.XMLOutputFactory2; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class XMLWriter { + + private static final Logger logger = Logger.getLogger(XMLWriter.class); + private static final XMLOutputFactory xof = XMLOutputFactory2.newInstance(); + + private static final String INDENT = " "; + + public static boolean saveFile(File targetFile, List<Sentence> sentences) { + return saveFile(targetFile, sentences, false, false); + } + + public static boolean saveFile(File targetFile, List<Sentence> sentences, boolean omitClauses, boolean omitMarkers) { + logger.info("Saving sentences in file: " + targetFile); + BufferedWriter bw = null; + XMLStreamWriter xsw = null; + try { + + bw = new BufferedWriter(new FileWriter(targetFile)); + xsw = xof.createXMLStreamWriter(bw); + + IdGenerator gen = new IdGenerator(); + writeDocument(xsw, sentences, gen, omitClauses, omitMarkers); + + } catch (Exception e) { + logger.error("Error saving file: " + e.getLocalizedMessage()); + return false; + + } finally { + try { + if (xsw != null) + xsw.close(); + if (bw != null) + bw.close(); + + } catch (Exception e) { + logger.error("Error closing file: " + e.getLocalizedMessage()); + return false; + } + } + return true; + } + + private static void writeSentence(XMLStreamWriter xsw, Sentence s, int i, IdGenerator gen, boolean omitClauses, + boolean omitMarkers) throws XMLStreamException { + + indent(xsw, i); + xsw.writeStartElement("S"); + xsw.writeAttribute("ID", gen.getId(s)); + xsw.writeCharacters("\n"); + + for (Clause c : s.getClauses()) + writeClause(xsw, c, i + 1, gen, omitClauses, omitMarkers); + + indent(xsw, i); + xsw.writeEndElement(); // S + xsw.writeCharacters("\n"); + } + + private static void writeClause(XMLStreamWriter xsw, Clause c, int i, IdGenerator gen, boolean omitClauses, + boolean omitMarkers) throws XMLStreamException { + + if (!omitClauses) { + indent(xsw, i); + xsw.writeStartElement("CLAUSE"); + + xsw.writeAttribute("ID", gen.getId(c)); + + Clause cont = c.getContinuedClause(); + if (cont != null) + xsw.writeAttribute("CONTINUE", gen.getId(c.getContinuedClause())); + + xsw.writeCharacters("\n"); + } else { + i--; + } + + Marker prevMarker = null; + for (Word w : c.getWords()) { + Marker currentMarker = w.getMarker(); + + if (omitMarkers || currentMarker == null) { + + if (!omitMarkers && prevMarker != null) + endMarker(xsw, i + 1); + + writeWord(xsw, w, i + 1, gen); + + } else { + + if (prevMarker == null) { + startMarker(xsw, currentMarker, i + 1, gen); + + } else if (!prevMarker.equals(currentMarker)) { + endMarker(xsw, i + 1); + startMarker(xsw, currentMarker, i + 1, gen); + } + + writeWord(xsw, w, i + 2, gen); + } + + prevMarker = currentMarker; + } + + if (!omitMarkers && prevMarker != null) + endMarker(xsw, i + 1); + + if (!omitClauses) { + indent(xsw, i); + xsw.writeEndElement(); // CLAUSE + xsw.writeCharacters("\n"); + } + } + + private static void endMarker(XMLStreamWriter xsw, int i) throws XMLStreamException { + indent(xsw, i); + xsw.writeEndElement(); // MARKER + xsw.writeCharacters("\n"); + } + + private static void startMarker(XMLStreamWriter xsw, Marker currentMarker, int i, IdGenerator gen) + throws XMLStreamException { + indent(xsw, i); + xsw.writeStartElement("MARKER"); + xsw.writeAttribute("ID", gen.getId(currentMarker)); + xsw.writeAttribute("NUC", currentMarker.getNUC()); + xsw.writeAttribute("TYPE", currentMarker.getType()); + xsw.writeAttribute("CONNECT", currentMarker.getConnect()); + + xsw.writeCharacters("\n"); + } + + private static void writeWord(XMLStreamWriter xsw, Word w, int i, IdGenerator gen) throws XMLStreamException { + indent(xsw, i); + xsw.writeStartElement("W"); + xsw.writeAttribute("ID", gen.getId(w)); + xsw.writeAttribute("LEMMA", w.getLemma()); + xsw.writeAttribute("POS", w.getPos()); + + xsw.writeCharacters(w.getOrth()); + + xsw.writeEndElement(); // W + xsw.writeCharacters("\n"); + } + + private static void indent(XMLStreamWriter xsw, int i) throws XMLStreamException { + for (int j = 0; j < i; j++) + xsw.writeCharacters(INDENT); + } + + private static void writeDocument(XMLStreamWriter xsw, List<Sentence> sentences, IdGenerator gen, + boolean omitClauses, boolean omitMarkers) throws XMLStreamException { + xsw.writeStartDocument("utf-8", "1.0"); + xsw.writeCharacters("\n"); + xsw.writeStartElement("DOCUMENT"); + xsw.writeCharacters("\n"); + + for (Sentence s : sentences) + writeSentence(xsw, s, 1, gen, omitClauses, omitMarkers); + + xsw.writeEndElement(); // DOCUMENT + xsw.writeEndDocument(); + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/BottomPanel.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/BottomPanel.java new file mode 100644 index 0000000..a2c83cc --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/BottomPanel.java @@ -0,0 +1,212 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class BottomPanel extends JPanel implements ItemListener { + + private static final long serialVersionUID = 285048609353220598L; + private static final Logger logger = Logger.getLogger(BottomPanel.class); + + private final MainTextPane textPane; + + // clause stuff + private final JComboBox<Object> cont = new JComboBox<Object>(); + private final JLabel currentClause = new JLabel(""); + + // marker stuff + private final JComboBox<String> markerNUC = new JComboBox<String>(); + private final JComboBox<String> markerConnect = new JComboBox<String>(); + private final JLabel currentMarker = new JLabel(""); + + { + markerNUC.addItem(""); + + markerNUC.addItem("_NN"); + markerNUC.addItem("_NS"); + markerNUC.addItem("_SN"); + + markerNUC.addItem("N_N"); + markerNUC.addItem("N_S"); + markerNUC.addItem("S_N"); + + markerNUC.addItem("NN_"); + markerNUC.addItem("NS_"); + markerNUC.addItem("SN_"); + + markerConnect.addItem(""); + + markerConnect.addItem("relate"); + markerConnect.addItem("fulfil"); + markerConnect.addItem("expect"); + } + + public BottomPanel(MainTextPane mainTextPane) { + super(); + this.textPane = mainTextPane; + + clearClauseSelection(); + clearMarkerSelection(); + + cont.addItemListener(this); + markerConnect.addItemListener(this); + markerNUC.addItemListener(this); + + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + + // labels + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + + this.add(new JLabel("Current clause:"), c); + this.add(new JLabel("Continues:"), c); + this.add(new JLabel("Current marker:"), c); + this.add(new JLabel("Current marker nuc:"), c); + this.add(new JLabel("Current marker connect:"), c); + + // values: + c.weightx = 1; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = GridBagConstraints.RELATIVE; + + this.add(currentClause, c); + + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + this.add(cont, c); + this.add(currentMarker, c); + this.add(markerNUC, c); + this.add(markerConnect, c); + } + + private synchronized void clearMarkerSelection() { + markerNUC.setEnabled(false); + markerConnect.setEnabled(false); + + currentMarker.setText("No marker selected"); + markerNUC.setSelectedIndex(0); + markerConnect.setSelectedIndex(0); + } + + private synchronized void clearClauseSelection() { + cont.setEnabled(false); + cont.removeAllItems(); + currentClause.setText("No clause selected"); + } + + public void selectionChanged(final List<Word> selectedSequence, final Marker m) { + if (selectedSequence == null) { + selectMarker(null); + selectClause(null); + } else { + Clause c = selectedSequence.get(0).getClause(); + + selectClause(c); + selectMarker(m); + } + } + + private synchronized void selectClause(Clause clause) { + + if (clause == null) { + clearClauseSelection(); + + } else { + currentClause.setText(clause.toString()); + + cont.setEnabled(false); + cont.removeAllItems(); + cont.addItem(""); + int sel = 0; + int i = 1; + + for (Clause c : clause.getSentence().getClausesBefore(clause)) { + if (c.equals(clause.getContinuedClause())) + sel = i; + + cont.addItem(c); + i++; + } + + cont.setSelectedIndex(sel); + cont.setEnabled(true); + } + } + + private synchronized void selectMarker(Marker m) { + + if (m == null) { + clearMarkerSelection(); + + } else { + currentMarker.setText(m.toString()); + + markerNUC.setEnabled(false); + markerNUC.setSelectedItem(m.getNUC()); + markerNUC.setEnabled(true); + + markerConnect.setEnabled(false); + markerConnect.setSelectedItem(m.getConnect()); + markerConnect.setEnabled(true); + } + } + + public synchronized void itemStateChanged(ItemEvent e) { + + // we don't care about deselection events + if (e.getStateChange() == ItemEvent.DESELECTED) + return; + + Component c = (Component) e.getSource(); + + if (c.isEnabled()) { + + if (c.equals(cont)) { + if (cont.getSelectedIndex() > 0) { + Clause clause = (Clause) cont.getSelectedItem(); + logger.debug("Continuing clause selection changed for: " + clause); + + textPane.setContinuingClause(clause); + } else { + textPane.setContinuingClause(null); + } + + } else if (c.equals(markerNUC)) { + + if (markerNUC.getSelectedIndex() >= 0) { + String nuc = (String) markerNUC.getSelectedItem(); + logger.debug("Marker nuc selection changed for: " + nuc); + + textPane.setMarkerNUC(nuc); + } + } else if (c.equals(markerConnect)) { + + if (markerConnect.getSelectedIndex() >= 0) { + String connect = (String) markerConnect.getSelectedItem(); + logger.debug("Marker connect selection changed for: " + connect); + + textPane.setMarkerConnect(connect); + } + } + } + } +} \ No newline at end of file diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/ClauseAnnotator.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/ClauseAnnotator.java new file mode 100644 index 0000000..4970d92 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/ClauseAnnotator.java @@ -0,0 +1,314 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.regex.Pattern; + +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Document; +import pl.waw.ipipan.zil.summarizer.clauseannotator.io.XMLReader; +import pl.waw.ipipan.zil.summarizer.clauseannotator.io.XMLWriter; + +public class ClauseAnnotator extends JFrame implements Runnable { + + private static final String WINDOW_TITLE = "Clause and marker annotator"; + + private static final long serialVersionUID = -3830790411182131318L; + + private static final Logger logger = Logger.getLogger(ClauseAnnotator.class); + + private static final int HEIGTH = 600; + private static final int WIDTH = 800; + + public static final String verbposregexpFilename = "verb.regexp"; + public static String VERB_POS_REGEXP = null; + + static { + loadVerPosRegexp(); + } + + private JMenuItem save; + + private File currentFile = null; + + private MainSplitPanel mainSplitPane; + + public static void main(String[] args) { + if (args.length != 0 && args.length != 1) { + logger.error("Wrong usage! Should be: java -jar " + ClauseAnnotator.class.getSimpleName() + " [input file]"); + return; + } + final ClauseAnnotator clauseannotator = new ClauseAnnotator(); + try { + SwingUtilities.invokeAndWait(clauseannotator); + } catch (Exception e) { + logger.error("Error starting application: " + e.getLocalizedMessage()); + e.printStackTrace(); + return; + } + + if (args.length == 1) { + final File input = new File(args[0]); + if (input.exists()) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + clauseannotator.loadFile(input); + } + }); + } else { + logger.error("Input file: " + input + " doesn't exist!"); + } + } + } + + private static void loadVerPosRegexp() { + InputStream f = ClauseAnnotator.class.getClassLoader().getResourceAsStream(verbposregexpFilename); + if (f != null) { + String regex = null; + try { + BufferedReader bw = new BufferedReader(new InputStreamReader(f)); + regex = bw.readLine(); + + Pattern.compile(regex); + } catch (Exception e) { + logger.error("Error reading regexp file: " + e.getLocalizedMessage()); + return; + } + VERB_POS_REGEXP = regex; + logger.info("Loaded verb regexp: " + regex); + } + } + + public void run() { + this.setTitle(WINDOW_TITLE); + mainSplitPane = new MainSplitPanel(this); + this.getContentPane().add(mainSplitPane); + this.createMenu(); + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new MainWindowListener(this)); + this.setSize(WIDTH, HEIGTH); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); + this.setVisible(true); + } + + private void createMenu() { + JMenuBar menu = new JMenuBar(); + this.setJMenuBar(menu); + + JMenu file = new JMenu("File"); + menu.add(file); + + JMenuItem open = new JMenuItem("Open"); + open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); + open.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + requestOpenFile(); + } + }); + file.add(open); + + save = new JMenuItem("Save"); + save.setEnabled(false); + save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); + save.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + requestSaveFile(); + } + }); + file.add(save); + + JMenuItem exit = new JMenuItem("Exit"); + exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); + exit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + requestExit(); + } + }); + file.add(exit); + + JMenu other = new JMenu("Other"); + JMenuItem help = new JMenuItem("Help"); + help.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + requestShowHelp(); + } + }); + + other.add(help); + menu.add(other); + } + + private void requestSaveFile() { + boolean success = XMLWriter.saveFile(currentFile, mainSplitPane.getSentences()); + + if (success) { + setTitle(WINDOW_TITLE); + save.setEnabled(false); + } else { + showError("Error saving file: " + currentFile); + } + } + + private final void requestOpenFile() { + if (!askToSaveChanges()) + return; + + JFileChooser chooser; + if (currentFile == null) + chooser = new JFileChooser(); + else + chooser = new JFileChooser(currentFile.getParentFile()); + + chooser.setFileFilter(new SummannotatorFileFilter()); + int result = chooser.showOpenDialog(this); + + if (result == JFileChooser.APPROVE_OPTION) { + this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + this.loadFile(chooser.getSelectedFile()); + this.setCursor(null); + } + } + + private boolean askToSaveChanges() { + if (!save.isEnabled()) + return true; + + int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); + + if (result == JOptionPane.CANCEL_OPTION) + return false; + + if (result == JOptionPane.YES_OPTION) + requestSaveFile(); + + return true; + } + + private final void requestExit() { + if (!askToSaveChanges()) + return; + + logger.info("Exiting."); + System.exit(0); + } + + private final void requestShowHelp() { + JFrame helpFrame = new JFrame("Help"); + helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JEditorPane editorPane = new JEditorPane(); + editorPane.setEditable(false); + URL helpURL = ClauseAnnotator.class.getClassLoader().getResource("help.html"); + if (helpURL != null) { + try { + editorPane.setPage(helpURL); + } catch (IOException e) { + logger.error("Attempted to read a bad URL: " + helpURL); + } + } else { + logger.error("Couldn't find file: help.html"); + } + + // Put the editor pane in a scroll pane. + JScrollPane editorScrollPane = new JScrollPane(editorPane); + editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setPreferredSize(new Dimension(800, 600)); + editorScrollPane.setMinimumSize(new Dimension(30, 30)); + + helpFrame.getContentPane().add(editorScrollPane); + helpFrame.pack(); + helpFrame.setVisible(true); + } + + private final void loadFile(File input) { + if (!input.exists()) { + String err = "File " + input + " doesn't exist!"; + logger.error(err); + showError(err); + return; + } + Document doc = new Document(); + String error = XMLReader.loadText(input, doc); + if (error != null) { + logger.error(error); + showError(error); + return; + } + if (doc.getSentences().size() == 0) { + String err = "No clauses found in file: " + input; + logger.error(err); + showError(err); + return; + } + + mainSplitPane.setSentences(doc.getSentences()); + + currentFile = input; + save.setEnabled(false); + setTitle(WINDOW_TITLE); + } + + private void showError(String string) { + JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); + } + + private final class SummannotatorFileFilter extends FileFilter { + @Override + public String getDescription() { + return "XML files"; + } + + @Override + public boolean accept(File f) { + return f.getName().endsWith(".xml") || f.isDirectory(); + } + } + + public void annotationChanged() { + save.setEnabled(true); + setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); + } + + private class MainWindowListener extends WindowAdapter { + + private ClauseAnnotator summanotator; + + public MainWindowListener(ClauseAnnotator sumannotator) { + this.summanotator = sumannotator; + } + + public void windowClosing(WindowEvent we) { + this.summanotator.requestExit(); + } + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/FixIds.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/FixIds.java new file mode 100644 index 0000000..275de71 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/FixIds.java @@ -0,0 +1,20 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.io.File; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Document; +import pl.waw.ipipan.zil.summarizer.clauseannotator.io.XMLReader; +import pl.waw.ipipan.zil.summarizer.clauseannotator.io.XMLWriter; + +public class FixIds { + + public static void main(String[] args) { + + File dir = new File(args[0]); + for (File f : dir.listFiles()) { + Document doc = new Document(); + XMLReader.loadText(f, doc); + XMLWriter.saveFile(f, doc.getSentences(), false, true); + } + } +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainDocument.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainDocument.java new file mode 100644 index 0000000..9d87e37 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainDocument.java @@ -0,0 +1,300 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import javax.swing.text.DefaultStyledDocument; +import javax.swing.text.SimpleAttributeSet; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class MainDocument extends DefaultStyledDocument implements CaretListener, KeyListener { + + private static final long serialVersionUID = 4276485351817531583L; + private static final Logger logger = Logger.getLogger(MainDocument.class); + + private final MainTextPane textPane; + + private List<Word> selectedWords = null; + private Marker selectedMarker = null; + + private List<Word> posToWord = null; + private Map<Word, Integer> wordToStartPos = null; + private List<Sentence> sentences = null; + + private boolean ignoreCaretUpdate = false; + + public MainDocument(MainTextPane mainTextPane) { + this.textPane = mainTextPane; + } + + public synchronized void setSentences(final List<Sentence> sents) { + + ignoreCaretUpdate = true; + + try { + remove(0, getLength()); + } catch (BadLocationException e) { + logger.error("Error clearing document: " + e.getLocalizedMessage()); + } + + sentences = sents; + + posToWord = new ArrayList<Word>(); + wordToStartPos = new HashMap<Word, Integer>(); + + int pos = 0; + try { + for (Sentence s : sentences) { + + for (Clause c : s.getClauses()) { + + insertString(pos, "[ ", Styles.getHandleStyle()); + pos += 2; + posToWord.add(null); + posToWord.add(null); + + Word prev = null; + for (Word w : c.getWords()) { + if (prev != null) { + insertString(pos, " ", Styles.getWhitespaceStyle()); + pos += 1; + posToWord.add(prev); + } + + String orth = w.getOrth(); + boolean selected = selectedWords != null && selectedWords.contains(w); + insertString(pos, orth, Styles.getWordStyle(w, selected)); + int length = orth.length(); + wordToStartPos.put(w, pos); + for (int i = 0; i < length; i++) + posToWord.add(w); + pos += length; + + prev = w; + } + + insertString(pos, " ]", Styles.getHandleStyle()); + pos += 2; + posToWord.add(null); + posToWord.add(null); + } + insertString(pos, "\n\n", Styles.getWhitespaceStyle()); + pos += 2; + posToWord.add(null); + posToWord.add(null); + } + // for last dot + posToWord.add(null); + + } catch (BadLocationException e) { + logger.error("Error setting document: " + e.getLocalizedMessage()); + } + + ignoreCaretUpdate = false; + } + + public synchronized List<Sentence> getSentences() { + return sentences; + } + + public void caretUpdate(final CaretEvent e) { + if (ignoreCaretUpdate) + return; + + int dot = e.getDot(); + int mark = e.getMark(); + selectionOcurred(mark, dot); + } + + private synchronized void selectionOcurred(int mark, int dot) { + + if (posToWord == null) + return; + + Word startWord; + Word stopWord; + if (mark > dot) { + startWord = posToWord.get(dot); + stopWord = posToWord.get(mark); + } else { + startWord = posToWord.get(mark); + stopWord = posToWord.get(dot); + } + + if (startWord == null || stopWord == null) { + this.setSelectedWords(null, dot); + return; + } + + Clause clause1 = startWord.getClause(); + Clause clause2 = stopWord.getClause(); + + if (!clause1.equals(clause2)) { + this.setSelectedWords(null, dot); + return; + } + + List<Word> selectedSequence = clause1.getWordsSequence(startWord, stopWord); + + this.setSelectedWords(selectedSequence, dot); + } + + public synchronized void setSelectedWords(List<Word> selectedSequence, int mark) { + + if (wordToStartPos == null) + return; + + logger.debug("Setting selected words: " + selectedSequence); + + // remove previous selection + if (this.selectedWords != null) { + for (Word w : selectedWords) { + SimpleAttributeSet att = Styles.getWordStyle(w, false); + int start = wordToStartPos.get(w); + int len = w.toString().length(); + this.setCharacterAttributes(start, len, att, true); + } + } + + // mark new selection + if (selectedSequence != null) { + for (Word w : selectedSequence) { + SimpleAttributeSet att = Styles.getWordStyle(w, true); + int start = wordToStartPos.get(w); + int len = w.toString().length(); + this.setCharacterAttributes(start, len, att, true); + } + } + + this.selectedWords = selectedSequence; + this.selectedMarker = getMarkerFromSelection(selectedSequence); + + if (this.ignoreCaretUpdate) { + this.textPane.selectionChanged(selectedSequence, selectedMarker, mark); + } else { + this.ignoreCaretUpdate = true; + this.textPane.selectionChanged(selectedSequence, selectedMarker, mark); + this.ignoreCaretUpdate = false; + } + + } + + private Marker getMarkerFromSelection(List<Word> selectedSequence) { + if (selectedSequence == null) + return null; + + Marker m = null; + for (Word w : selectedSequence) { + if (w.getMarker() != null) { + if (m == null) { + m = w.getMarker(); + } else if (!m.equals(w.getMarker())) { + m = null; + break; + } + } + } + return m; + } + + public synchronized Word getFirstSelectedWord() { + if (selectedWords == null) + return null; + return this.selectedWords.get(0); + } + + public synchronized int getFirstSelectedWordStartPos() { + Word firstSelectedWord = getFirstSelectedWord(); + if (firstSelectedWord == null || wordToStartPos == null) + return 0; + return wordToStartPos.get(firstSelectedWord); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + ignoreCaretUpdate = true; + } + } + + public void keyReleased(final KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + textPane.splitClause(); + } else if (e.getKeyCode() == KeyEvent.VK_P) { + textPane.mergeClauseWithPrevious(); + } else if (e.getKeyCode() == KeyEvent.VK_N) { + textPane.mergeClauseWithNext(); + } else if (e.getKeyCode() == KeyEvent.VK_M) { + textPane.createMarker(); + } else if (e.getKeyCode() == KeyEvent.VK_D) { + textPane.deleteMarker(); + } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + ignoreCaretUpdate = false; + Caret c = textPane.getCaret(); + selectionOcurred(c.getDot(), c.getMark()); + } + // } else if (e.getKeyCode() == KeyEvent.VK_S) { + // textPane.splitSentence(); + // } + + } + + public synchronized List<Word> getSelectedWords() { + return this.selectedWords; + } + + public synchronized Marker getSelectedMarker() { + return this.selectedMarker; + } + + public synchronized void refreshCurrentMarkerStyle() { + if (selectedMarker == null || wordToStartPos == null) + return; + + for (Word w : selectedMarker.getWords()) { + boolean selected = false; + if (selectedWords.contains(w)) + selected = true; + + SimpleAttributeSet att = Styles.getWordStyle(w, selected); + int start = wordToStartPos.get(w); + int len = w.toString().length(); + this.setCharacterAttributes(start, len, att, true); + } + } + + public synchronized void refreshCurrentClauseStyle() { + if (selectedWords == null || wordToStartPos == null) + return; + + Clause c = selectedWords.get(0).getClause(); + + for (Word w : c.getWords()) { + boolean selected = false; + if (selectedWords.contains(w)) + selected = true; + + SimpleAttributeSet att = Styles.getWordStyle(w, selected); + int start = wordToStartPos.get(w); + int len = w.toString().length(); + this.setCharacterAttributes(start, len, att, true); + } + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainSplitPanel.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainSplitPanel.java new file mode 100644 index 0000000..77785c7 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainSplitPanel.java @@ -0,0 +1,56 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.util.List; + +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class MainSplitPanel extends JSplitPane { + + private static final long serialVersionUID = 3656861958564714263L; + private static final Logger logger = Logger.getLogger(MainSplitPanel.class); + + private ClauseAnnotator clauseannotator; + + private MainTextPane mainTextPane; + private BottomPanel bottomPanel; + + public MainSplitPanel(ClauseAnnotator clauseannotator) { + super(JSplitPane.VERTICAL_SPLIT); + + this.clauseannotator = clauseannotator; + + logger.info("Creating main panel..."); + + mainTextPane = new MainTextPane(this); + bottomPanel = new BottomPanel(mainTextPane); + + this.setTopComponent(new JScrollPane(mainTextPane)); + this.setBottomComponent(bottomPanel); + this.setOneTouchExpandable(true); + this.setDividerLocation(350); + } + + public void setSentences(final List<Sentence> sentences) { + mainTextPane.setSentences(sentences); + } + + public List<Sentence> getSentences() { + return mainTextPane.getSentences(); + } + + public void selectionChanged(List<Word> selectedSequence, Marker m) { + bottomPanel.selectionChanged(selectedSequence, m); + } + + public void annotationChanged() { + this.clauseannotator.annotationChanged(); + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainTextPane.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainTextPane.java new file mode 100644 index 0000000..2408333 --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/MainTextPane.java @@ -0,0 +1,213 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.awt.Insets; +import java.util.List; + +import javax.swing.JTextPane; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Marker; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Sentence; +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class MainTextPane extends JTextPane { + + private static final long serialVersionUID = 3709902726162446568L; + private static final Logger logger = Logger.getLogger(MainTextPane.class); + + private MainSplitPanel mainSplitPanel; + + private MainDocument document; + + public MainTextPane(MainSplitPanel mainSplitPanel) { + super(); + + this.mainSplitPanel = mainSplitPanel; + this.document = new MainDocument(this); + + this.setStyledDocument(document); + this.setMargin(new Insets(5, 5, 5, 5)); + this.setEditable(false); + + this.addCaretListener(document); + this.addKeyListener(document); + } + + public void setSentences(List<Sentence> sentences) { + selectionChanged(null, null, 0); + document.setSentences(sentences); + this.setCaretPosition(0); + this.getCaret().setVisible(true); + } + + public List<Sentence> getSentences() { + return document.getSentences(); + } + + public void selectionChanged(List<Word> selectedSequence, Marker m, int dot) { + this.select(dot, dot); + this.getCaret().setVisible(true); + mainSplitPanel.selectionChanged(selectedSequence, m); + } + + private void reloadSentences() { + document.setSentences(document.getSentences()); + final int caretPos = document.getFirstSelectedWordStartPos(); + this.select(caretPos, caretPos); + this.getCaret().setVisible(true); + this.mainSplitPanel.annotationChanged(); + } + + private void reloadCurrentClause() { + document.refreshCurrentClauseStyle(); + this.mainSplitPanel.annotationChanged(); + } + + private void reloadCurrentMarker() { + document.refreshCurrentMarkerStyle(); + this.mainSplitPanel.annotationChanged(); + } + + /* ACTIONS */ + + public synchronized void splitClause() { + Word selectedWord = document.getFirstSelectedWord(); + if (selectedWord == null) + return; + + if (selectedWord.isFirstInClause()) + return; + + if (selectedWord.isInMiddleOfMarker()) + return; + + Clause c = selectedWord.getClause(); + logger.info("Splitting clause: " + c + " starting from word: " + selectedWord); + Sentence s = c.getSentence(); + s.splitClause(c, selectedWord); + + reloadSentences(); + } + + public synchronized void mergeClauseWithPrevious() { + Word selectedWord = document.getFirstSelectedWord(); + if (selectedWord == null) + return; + Clause c = selectedWord.getClause(); + + if (c.isFirstInSentence()) + return; + + logger.info("Merging clause: " + c + " into previous one"); + Sentence s = c.getSentence(); + s.mergeClauseWithPrevious(c); + + reloadSentences(); + } + + public synchronized void mergeClauseWithNext() { + Word selectedWord = document.getFirstSelectedWord(); + if (selectedWord == null) + return; + Clause c = selectedWord.getClause(); + + if (c.isLastInSentence()) + return; + + logger.info("Merging clause: " + c + " into next one"); + Sentence s = c.getSentence(); + s.mergeClauseWithNext(c); + + reloadSentences(); + } + + public synchronized void setContinuingClause(Clause cont) { + Word selectedWord = document.getFirstSelectedWord(); + if (selectedWord == null) { + logger.error("Trying to continiuing clause when no clause chosen!"); + return; + } + + Clause c = selectedWord.getClause(); + logger.info("Setting continiuing clause: " + cont + " for clause: " + c); + c.setContinuedClause(cont); + + reloadCurrentClause(); + } + + public synchronized void createMarker() { + List<Word> selectedWords = document.getSelectedWords(); + if (selectedWords == null) + return; + + for (Word w : selectedWords) + if (w.getMarker() != null) + return; + + logger.info("Creating new marker from words: " + selectedWords); + new Marker(selectedWords); + + reloadSentences(); + } + + public synchronized void deleteMarker() { + Marker selectedMarker = document.getSelectedMarker(); + if (selectedMarker == null) + return; + + logger.info("Deleting marker: " + selectedMarker); + selectedMarker.deleteMe(); + + reloadSentences(); + } + + public synchronized void setMarkerNUC(String nuc) { + Marker m = document.getSelectedMarker(); + if (m == null) { + logger.error("Trying to set marker nuc when no marker chosen!"); + return; + } + + logger.info("Setting nuc " + nuc + " for marker: " + m); + m.setNUC(nuc); + + reloadCurrentMarker(); + } + + public void splitSentence() { + Word selectedWord = document.getFirstSelectedWord(); + if (selectedWord == null) + return; + + if (selectedWord.isFirstInClause()) + return; + + if (selectedWord.isInMiddleOfMarker()) + return; + + Clause c = selectedWord.getClause(); + Sentence s = c.getSentence(); + logger.info("Splitting sentence: " + s + " starting from word: " + selectedWord); + + s.getDocument().splitSentence(s, selectedWord); + + reloadSentences(); + + } + + public void setMarkerConnect(String connect) { + Marker m = document.getSelectedMarker(); + if (m == null) { + logger.error("Trying to set marker connect when no marker chosen!"); + return; + } + + logger.info("Setting connect " + connect + " for marker: " + m); + m.setConnect(connect); + + reloadCurrentMarker(); + } + +} diff --git a/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/Styles.java b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/Styles.java new file mode 100644 index 0000000..1ba856a --- /dev/null +++ b/ClauseAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clauseannotator/main/Styles.java @@ -0,0 +1,50 @@ +package pl.waw.ipipan.zil.summarizer.clauseannotator.main; + +import java.awt.Color; + +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; + +import pl.waw.ipipan.zil.summarizer.clauseannotator.basic.Word; + +public class Styles { + + private static SimpleAttributeSet handleStyle; + private static SimpleAttributeSet whitespaceStyle; + + static { + handleStyle = new SimpleAttributeSet(); + StyleConstants.setBold(handleStyle, true); + + whitespaceStyle = new SimpleAttributeSet(); + } + + public static SimpleAttributeSet getWordStyle(Word w, boolean selected) { + SimpleAttributeSet defaultStyle = new SimpleAttributeSet(); + if (w.getClause().getContinuedClause() != null) + StyleConstants.setBackground(defaultStyle, Color.getHSBColor(0.069f, 0.20f, 0.99f)); + + if (w.getMarker() != null) { + StyleConstants.setUnderline(defaultStyle, true); + if (w.getMarker().getNUC().equals("")) + StyleConstants.setBackground(defaultStyle, Color.magenta); + } + + if (selected) + StyleConstants.setBackground(defaultStyle, Color.yellow); + + if (w.isVerb()) + StyleConstants.setBold(defaultStyle, true); + + return defaultStyle; + } + + public static SimpleAttributeSet getHandleStyle() { + return handleStyle; + } + + public static SimpleAttributeSet getWhitespaceStyle() { + return whitespaceStyle; + } + +} diff --git a/ClauseAnnotator/src/main/resources/log4j.properties b/ClauseAnnotator/src/main/resources/log4j.properties new file mode 100644 index 0000000..6d8f00a --- /dev/null +++ b/ClauseAnnotator/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n + +log4j.logger.pl.waw.ipipan.zil=INFO, stderr \ No newline at end of file diff --git a/ClauseSumAnnotator/.classpath b/ClauseSumAnnotator/.classpath deleted file mode 100644 index fc321d6..0000000 --- a/ClauseSumAnnotator/.classpath +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> diff --git a/ClauseSumAnnotator/.gitignore b/ClauseSumAnnotator/.gitignore index 6b743b9..6cb1223 100644 --- a/ClauseSumAnnotator/.gitignore +++ b/ClauseSumAnnotator/.gitignore @@ -1,4 +1,4 @@ -*.class -*~ -.settings/* -target +/target/ +.project +.settings +.classpath diff --git a/ClauseSumAnnotator/pom.xml b/ClauseSumAnnotator/pom.xml index 88f78a2..d0d5ec3 100644 --- a/ClauseSumAnnotator/pom.xml +++ b/ClauseSumAnnotator/pom.xml @@ -1,10 +1,13 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>ipipan.atlas</groupId> - <artifactId>sumannotator</artifactId> - <version>0.1</version> - <name>Sumannotator</name> + <groupId>pl.waw.ipipan.zil.summarizer</groupId> + <artifactId>clausesumannotator</artifactId> + <version>1.0</version> + <name>ClauseSumAnnotator</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <build> <plugins> <plugin> @@ -12,7 +15,7 @@ <configuration> <archive> <manifest> - <mainClass>ipipan.atlas.sumannotator.main.Sumannotator</mainClass> + <mainClass>pl.waw.ipipan.zil.summarizer.clausesumannotator.main.ClauseSumAnnotator</mainClass> </manifest> </archive> <descriptorRefs> @@ -20,6 +23,14 @@ </descriptorRefs> </configuration> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> </plugins> </build> <dependencies> diff --git a/ClauseSumAnnotator/src/main/java/log4j.properties b/ClauseSumAnnotator/src/main/java/log4j.properties deleted file mode 100644 index c397541..0000000 --- a/ClauseSumAnnotator/src/main/java/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n - -log4j.logger.pl.waw.ipipan.zil.summarization.clausesumannotator=INFO, stderr \ No newline at end of file diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Clause.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Clause.java deleted file mode 100644 index cb9b295..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Clause.java +++ /dev/null @@ -1,41 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.basic; - - -import java.util.ArrayList; -import java.util.List; - -public class Clause { - - private List<Word> words = new ArrayList<Word>(); - private String id; - private String cont; - - public Clause(String id, String cont) { - this.id = id; - this.cont = cont; - } - - public void add(Word currentWord) { - this.words.add(currentWord); - } - - public String getId() { - return this.id; - } - - public List<Word> getWords() { - return words; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - for (Word w : words) - sb.append(" " + w.getOrth()); - return sb.toString(); - } - - public String getContinue() { - return this.cont; - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Word.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Word.java deleted file mode 100644 index 17417aa..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/basic/Word.java +++ /dev/null @@ -1,15 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.basic; - -public class Word { - - private String orth = null; - - public void setOrth(String orth) { - this.orth = orth; - } - - public String getOrth() { - return orth; - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/SummaryFileIO.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/SummaryFileIO.java deleted file mode 100644 index 9a2cdfd..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/SummaryFileIO.java +++ /dev/null @@ -1,151 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.io; - - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.HashSet; -import java.util.Set; - -import javax.swing.JTabbedPane; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clausesumannotator.main.MyTab; - -public class SummaryFileIO { - - private static final Logger logger = Logger.getLogger(SummaryFileIO.class); - - public static boolean loadSummary(File summaryFile, JTabbedPane tabbedPane) { - logger.info("Loading summary from file: " + summaryFile); - BufferedReader br = null; - - try { - br = new BufferedReader(new FileReader(summaryFile)); - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - MyTab tab = (MyTab) tabbedPane.getComponent(i); - readTab(br, tab); - } - } catch (IOException e) { - logger.error("Error reading summary: " + e.getLocalizedMessage()); - return false; - } finally { - try { - if (br != null) - br.close(); - } catch (IOException e) { - logger.error("Error closing summary file: " + e.getLocalizedMessage()); - return false; - } - } - return true; - } - - public static boolean saveSummary(File summaryFile, JTabbedPane tabbedPane) { - logger.info("Saving summary in file: " + summaryFile); - BufferedWriter bw = null; - - try { - bw = new BufferedWriter(new FileWriter(summaryFile)); - - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - MyTab tab = (MyTab) tabbedPane.getComponent(i); - writeTab(bw, tab); - } - - } catch (IOException e) { - logger.error("Error writing summary: " + e.getLocalizedMessage()); - return false; - } finally { - if (bw != null) - try { - bw.close(); - } catch (IOException e) { - logger.error("Error closing summary file: " + e.getLocalizedMessage()); - return false; - } - } - return true; - } - - private static void readTab(BufferedReader br, MyTab tab) throws IOException { - br.readLine(); - - Set<String> clauseIds = new HashSet<String>(); - while (true) { - String line = br.readLine(); - if (line == null) - break; - if (line.equals("")) - break; - clauseIds.add(line); - } - - tab.setChosenClauses(clauseIds); - - while (true) { - String line = br.readLine(); - if (line == null) - break; - if (line.equals("")) - break; - } - } - - private static void writeTab(Writer writer, MyTab tab) throws IOException { - writer.append("A " + tab.getName() + " should contain:\n"); - - int maxContLen = 0; - int maxIdLen = 0; - for (Clause c : tab.getChosenClauses()) { - int contLen = getCont(c).length(); - int idLen = getId(c).length(); - if (contLen > maxContLen) - maxContLen = contLen; - if (idLen > maxIdLen) - maxIdLen = idLen; - - writer.append(c.getId() + "\n"); - } - - writer.append("\n"); - - for (Clause c : tab.getChosenClauses()) { - String id = fill(getId(c), maxIdLen + 1); - String cont = fill(getCont(c), maxContLen + 1); - String full = id + " " + cont + " " + c.toString(); - writer.append(full + "\n"); - } - - writer.append("\n"); - } - - public static File getTargetFile(File currentFile) { - File parent = currentFile.getParentFile(); - String targetName = currentFile.getName().substring(0, currentFile.getName().lastIndexOf(".")) + ".summ"; - return new File(parent + File.separator + targetName); - } - - private static String getId(Clause c) { - return "ID=\"" + c.getId() + "\""; - } - - private static String getCont(Clause c) { - return "CONTINUE=\"" + c.getContinue() + "\""; - } - - private static String fill(String string, int spaceCount) { - StringBuffer sb = new StringBuffer(string); - int toFill = Math.max(0, spaceCount - string.length()); - for (int i = 0; i < toFill; i++) - sb.append(" "); - return sb.toString(); - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/XMLReader.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/XMLReader.java deleted file mode 100644 index bcd8213..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/io/XMLReader.java +++ /dev/null @@ -1,122 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.io; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.List; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.log4j.Logger; -import org.codehaus.stax2.XMLInputFactory2; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Word; - -public class XMLReader { - - private static final Logger logger = Logger.getLogger(XMLReader.class); - - private static final XMLInputFactory xif = XMLInputFactory2.newInstance(); - - public static String loadText(File input, List<Clause> allClauses) { - logger.info("Loading text from file: " + input); - - String error = null; - - InputStream is = null; - XMLStreamReader sr = null; - try { - is = new FileInputStream(input); - sr = xif.createXMLStreamReader(is); - - Clause currentClause = null; - Word currentWord = null; - - while (sr.hasNext()) { - sr.next(); - - if (sr.isStartElement()) { - String name = sr.getName().getLocalPart(); - if (name.equals("CLAUSE")) { - String id = sr.getAttributeValue(null, "ID"); - String cont = sr.getAttributeValue(null, "CONTINUE"); - - if (cont == null) - cont = ""; - - if (id == null) { - error = "Clause without id in line: " - + sr.getLocation().getLineNumber(); - break; - } - - if (currentClause != null) { - error = "Clause starting before previous clause finished in line: " - + sr.getLocation().getLineNumber(); - break; - } - - currentClause = new Clause(id, cont); - } else if (name.equals("W")) { - if (currentWord != null) { - error = "Word starting before previous word finished in line: " - + sr.getLocation().getLineNumber(); - break; - } - currentWord = new Word(); - } - } else if (sr.isEndElement()) { - String name = sr.getName().getLocalPart(); - if (name.equals("CLAUSE")) { - if (currentClause == null) { - error = "Clause ending before starting in line: " + sr.getLocation().getLineNumber(); - break; - } - - allClauses.add(currentClause); - currentClause = null; - } else if (name.equals("W")) { - if (currentWord == null) { - error = "Word ending before starting in line: " + sr.getLocation().getLineNumber(); - break; - } - if (currentClause == null) { - error = "Word not inside a clause in line: " + sr.getLocation().getLineNumber(); - break; - } - currentClause.add(currentWord); - currentWord = null; - } - } else if (sr.isWhiteSpace()) { - - } else if (sr.isCharacters()) { - if (currentWord != null) { - if (currentWord.getOrth() != null) { - error = "Second word orth in line: " + sr.getLocation().getLineNumber(); - break; - } - currentWord.setOrth(sr.getText()); - } - } - } - } catch (Exception e) { - error = "Error reading file: " + e.getLocalizedMessage(); - } finally { - try { - if (is != null) - is.close(); - if (sr != null) - sr.close(); - } catch (Exception e) { - error = "Error closing file: " + input + " Details: " + e.getLocalizedMessage(); - } - } - - logger.info(allClauses.size() + " clauses found."); - - return error; - } -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseSumAnnotator.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseSumAnnotator.java deleted file mode 100644 index bc454a9..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseSumAnnotator.java +++ /dev/null @@ -1,397 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.main; - - -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.ButtonGroup; -import javax.swing.JEditorPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.filechooser.FileFilter; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; -import pl.waw.ipipan.zil.summarization.clausesumannotator.io.SummaryFileIO; -import pl.waw.ipipan.zil.summarization.clausesumannotator.io.XMLReader; - -public class ClauseSumAnnotator extends JFrame implements Runnable, MyTabChangeListener { - - private static final String WINDOW_TITLE = "Extraction summary creator"; - - private static final long serialVersionUID = -3830790411182131318L; - - private static final Logger logger = Logger.getLogger(ClauseSumAnnotator.class); - - private static final int HEIGTH = 600; - private static final int WIDTH = 800; - - private JMenuItem save; - - private File currentFile = null; - private boolean unsavedChanges = false; - - private JTabbedPane tabbedPane; - - private float displayFontSize; - - public static void main(String[] args) { - if (args.length != 0 && args.length != 1) { - logger.error("Wrong usage! Should be: java -jar " + ClauseSumAnnotator.class.getSimpleName() + " [input file]"); - return; - } - final ClauseSumAnnotator summanno = new ClauseSumAnnotator(); - try { - SwingUtilities.invokeAndWait(summanno); - } catch (Exception e) { - logger.error("Error starting application: " + e.getLocalizedMessage()); - e.printStackTrace(); - return; - } - - if (args.length == 1) { - final File input = new File(args[0]); - if (input.exists()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - summanno.loadFile(input); - } - }); - } else { - logger.error("Input file: " + input + " doesn't exist!"); - } - } - } - - @Override - public void run() { - displayFontSize = loadDisplayFontSize(); - tabbedPane = new JTabbedPane(); - this.getContentPane().add(tabbedPane); - this.setTitle(WINDOW_TITLE); - this.createMenu(); - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.addWindowListener(new MainWindowListener(this)); - this.setSize(WIDTH, HEIGTH); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); - this.setVisible(true); - } - - private float loadDisplayFontSize() { - float result = 12f; - // File fontsizeFile = new File(fontsizePath); - // if (fontsizeFile.exists()) { - // try { - // Scanner s = new Scanner(fontsizeFile); - // result = s.nextFloat(); - // s.close(); - // logger.info("Font size found in file: " + fontsizeFile); - // } catch (FileNotFoundException e) { - // logger.error(e.getLocalizedMessage()); - // } - // } else { - // logger.info("Font size not found in file: " + fontsizeFile); - logger.info("Using default font size."); - // } - return result; - } - - private void createMenu() { - JMenuBar menu = new JMenuBar(); - this.setJMenuBar(menu); - - JMenu file = new JMenu("File"); - menu.add(file); - - JMenuItem open = new JMenuItem("Open"); - open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); - open.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestOpenFile(); - } - }); - file.add(open); - - save = new JMenuItem("Save"); - save.setEnabled(false); - save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); - save.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestSaveFile(); - } - }); - file.add(save); - - JMenuItem exit = new JMenuItem("Exit"); - exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - exit.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestExit(); - } - }); - file.add(exit); - - JMenu other = new JMenu("Other"); - - ButtonGroup fontSizeButtonGroup = new ButtonGroup(); - JMenu setFontSize = new JMenu("Change font size"); - for (int z = 8; z < 30; z = z + 2) { - - final int currentFontSize = z; - - JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); - if (z == displayFontSize) { - temp.setSelected(true); - } - temp.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent ae) { - requestSetFontSize(currentFontSize); - } - }); - fontSizeButtonGroup.add(temp); - setFontSize.add(temp); - } - other.add(setFontSize); - - JMenuItem help = new JMenuItem("Help"); - help.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - requestShowHelp(); - } - }); - other.add(help); - - menu.add(other); - } - - protected void requestSetFontSize(int currentFontSize) { - logger.info("Setting font size: " + currentFontSize); - displayFontSize = currentFontSize; - - // File fontsizeFile = new File(fontsizePath); - // logger.info("Saving font size in file: " + fontsizeFile); - // - // try { - // Writer w = new FileWriter(fontsizeFile); - // w.write(Float.toString(displayFontSize)); - // w.write("\n"); - // w.close(); - // } catch (IOException e) { - // logger.error(e.getLocalizedMessage()); - // } - } - - private final void requestShowHelp() { - JFrame helpFrame = new JFrame("Help"); - helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JEditorPane editorPane = new JEditorPane(); - editorPane.setEditable(false); - URL helpURL = ClauseSumAnnotator.class.getClassLoader().getResource("help.html"); - if (helpURL != null) { - try { - editorPane.setPage(helpURL); - } catch (IOException e) { - logger.error("Attempted to read a bad URL: " + helpURL); - } - } else { - logger.error("Couldn't find file: help.html"); - } - - // Put the editor pane in a scroll pane. - JScrollPane editorScrollPane = new JScrollPane(editorPane); - editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setPreferredSize(new Dimension(800, 600)); - editorScrollPane.setMinimumSize(new Dimension(30, 30)); - - helpFrame.getContentPane().add(editorScrollPane); - helpFrame.pack(); - helpFrame.setVisible(true); - } - - private void requestSaveFile() { - File targetFile = SummaryFileIO.getTargetFile(currentFile); - boolean success = SummaryFileIO.saveSummary(targetFile, tabbedPane); - - if (success) { - unsavedChanges = false; - setTitle(WINDOW_TITLE); - save.setEnabled(false); - } else { - showError("Error saving file: " + targetFile); - } - } - - private final void requestOpenFile() { - if (!askToSaveChanges()) - return; - - JFileChooser chooser; - if (currentFile == null) - chooser = new JFileChooser(); - else - chooser = new JFileChooser(currentFile.getParentFile()); - - chooser.setFileFilter(new SummannotatorFileFilter()); - int result = chooser.showOpenDialog(this); - - if (result == JFileChooser.APPROVE_OPTION) { - this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - this.loadFile(chooser.getSelectedFile()); - this.setCursor(null); - } - } - - private boolean askToSaveChanges() { - if (!unsavedChanges) - return true; - - int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); - - if (result == JOptionPane.CANCEL_OPTION) - return false; - - if (result == JOptionPane.YES_OPTION) - requestSaveFile(); - - return true; - } - - private final void requestExit() { - if (!askToSaveChanges()) - return; - - logger.info("Exiting."); - System.exit(0); - } - - private final void loadFile(File input) { - tabbedPane.removeAll(); - - if (!input.exists()) { - String err = "File " + input + " doesn't exist!"; - logger.error(err); - showError(err); - return; - } - List<Clause> clauses = new ArrayList<Clause>(); - String error = XMLReader.loadText(input, clauses); - if (error != null) { - logger.error(error); - showError(error); - return; - } - if (clauses.size() == 0) { - String err = "No clauses found in file: " + input; - logger.error(err); - showError(err); - return; - } - - int all = getAllWordsCount(clauses); - - MyTab tab1 = new MyTab(all, 0.2, displayFontSize); - MyTab tab2 = new MyTab(all, 0.1, displayFontSize); - MyTab tab3 = new MyTab(all, 0.05, displayFontSize); - - tab1.addChangeListener(tab2); - tab2.addChangeListener(tab3); - tab1.clausesChanged(clauses); - - tabbedPane.addTab(tab1.getName(), tab1); - tabbedPane.addTab(tab2.getName(), tab2); - tabbedPane.addTab(tab3.getName(), tab3); - - currentFile = input; - - File summaryFile = SummaryFileIO.getTargetFile(input); - if (summaryFile.exists()) { - boolean success = SummaryFileIO.loadSummary(summaryFile, tabbedPane); - if (success) { - logger.info("Summary file found and loaded: " + summaryFile); - } else { - showError("Error loading summary file: " + summaryFile); - } - } - - tab1.addChangeListener(this); - tab2.addChangeListener(this); - tab3.addChangeListener(this); - } - - private void showError(String string) { - JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); - } - - private static int getAllWordsCount(List<Clause> clauses) { - int all = 0; - for (Clause c : clauses) - all += c.getWords().size(); - return all; - } - - private final class SummannotatorFileFilter extends FileFilter { - @Override - public String getDescription() { - return "XML files"; - } - - @Override - public boolean accept(File f) { - return f.getName().endsWith(".xml") || f.isDirectory(); - } - } - - private class MainWindowListener extends WindowAdapter { - - private final ClauseSumAnnotator summanotator; - - public MainWindowListener(ClauseSumAnnotator sumannotator) { - this.summanotator = sumannotator; - } - - @Override - public void windowClosing(WindowEvent we) { - this.summanotator.requestExit(); - } - } - - @Override - public void clausesChanged(List<Clause> clauses) { - unsavedChanges = true; - save.setEnabled(true); - setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseTable.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseTable.java deleted file mode 100644 index 9167866..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/ClauseTable.java +++ /dev/null @@ -1,187 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.main; - - -import java.awt.Color; -import java.awt.Component; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.ListSelectionModel; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableCellRenderer; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; - -public class ClauseTable extends JTable implements MouseListener, KeyListener { - - private static final long serialVersionUID = 5865240498654370980L; - - private final List<Clause> allClauses = new ArrayList<Clause>(); - private final Set<Clause> chosenClauses = new HashSet<Clause>(); - - private final AbstractTableModel model; - - private final MyTab parentTab; - - public ClauseTable(MyTab parentTab, float displayFontSize) { - this.parentTab = parentTab; - - setFillsViewportHeight(true); - setTableHeader(null); - addMouseListener(this); - addKeyListener(this); - setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - setDefaultRenderer(Object.class, new MyCellRenderer(displayFontSize)); - - model = new SimpleClauseTableModel(); - setModel(model); - } - - public synchronized void setClauseList(List<Clause> clauses) { - allClauses.clear(); - allClauses.addAll(clauses); - chosenClauses.retainAll(allClauses); - model.fireTableDataChanged(); - } - - public synchronized void rowsSelected() { - if (this.getSelectedRows().length == 0) - return; - - for (int i : this.getSelectedRows()) { - changeRowStatus(i); - } - clearSelection(); - parentTab.chosenClausesChanged(); - } - - public synchronized void changeRowStatus(int row) { - Clause c = allClauses.get(row); - if (chosenClauses.contains(c)) - chosenClauses.remove(c); - else - chosenClauses.add(c); - } - - private boolean isClauseChosen(Clause value) { - return chosenClauses.contains(value); - } - - public List<Clause> getChosenClauses() { - List<Clause> result = new ArrayList<Clause>(); - for (Clause c : allClauses) - if (chosenClauses.contains(c)) - result.add(c); - return result; - } - - public synchronized void setChosenClauses(Set<String> clauseIds) { - chosenClauses.clear(); - for (Clause c : allClauses) - if (clauseIds.contains(c.getId())) - chosenClauses.add(c); - parentTab.chosenClausesChanged(); - } - - /************* listeners ******************************/ - - @Override - public void mouseClicked(MouseEvent e) { - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - } - - @Override - public void keyPressed(KeyEvent arg0) { - } - - @Override - public void keyTyped(KeyEvent arg0) { - } - - @Override - public void mouseReleased(MouseEvent e) { - rowsSelected(); - } - - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_SPACE) - rowsSelected(); - } - - private final class SimpleClauseTableModel extends AbstractTableModel { - - private static final long serialVersionUID = 5563319901787241258L; - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - return allClauses.get(rowIndex); - } - - @Override - public int getRowCount() { - return allClauses.size(); - } - - @Override - public int getColumnCount() { - return 1; - } - } - - /********************** cell renderer **************************/ - - private class MyCellRenderer extends JTextArea implements TableCellRenderer { - - private static final long serialVersionUID = 3003554184145715021L; - - public MyCellRenderer(float displayFontSize) { - super(); - setFont(getFont().deriveFont(displayFontSize)); - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int col) { - - String text = value.toString(); - setLineWrap(true); - setWrapStyleWord(true); - setText(text); - setSize(table.getWidth(), table.getRowHeight()); - - if (isSelected) - setBackground(Color.gray); - else if (isClauseChosen((Clause) value)) - setBackground(Color.yellow); - else - setBackground(null); - - int heightWanted = getPreferredSize().height; - if (heightWanted != table.getRowHeight(row)) - table.setRowHeight(row, heightWanted); - - return this; - } - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTab.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTab.java deleted file mode 100644 index 5ee6918..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTab.java +++ /dev/null @@ -1,126 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.main; - - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.swing.BoxLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; - -public class MyTab extends JSplitPane implements MyTabChangeListener { - - private static final long serialVersionUID = 3656861958564714263L; - - private final ClauseTable table; - private final JTextArea textArea; - private final JProgressBar pb; - - private final int targetSegmentCount; - - private final Set<MyTabChangeListener> listeners = new HashSet<MyTabChangeListener>(); - - private final double desired; - - public MyTab(int allSegments, double desired, float displayFontSize) { - super(JSplitPane.VERTICAL_SPLIT); - - this.targetSegmentCount = (int) (desired * allSegments); - this.desired = desired; - - textArea = new JTextArea("empty"); - textArea.setLineWrap(true); - textArea.setWrapStyleWord(true); - textArea.setFont(textArea.getFont().deriveFont(displayFontSize)); - JScrollPane textAreaScrollPane = new JScrollPane(textArea); - - pb = new JProgressBar(0, targetSegmentCount); - JLabel all = new JLabel("Words in text: " + allSegments); - JLabel prop = new JLabel("Summary proportion: " + (int) (desired * 100) + "%"); - JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); - - // pb.setFont(pb.getFont().deriveFont(displayFontSize)); - // all.setFont(all.getFont().deriveFont(displayFontSize)); - // prop.setFont(prop.getFont().deriveFont(displayFontSize)); - // summ.setFont(summ.getFont().deriveFont(displayFontSize)); - - JPanel bottomLeftPanel = new JPanel(); - bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); - bottomLeftPanel.add(pb); - bottomLeftPanel.add(all); - bottomLeftPanel.add(prop); - bottomLeftPanel.add(summ); - bottomLeftPanel.setPreferredSize(new Dimension(prop.getPreferredSize().width + 10, 100)); - - JPanel bottomPane = new JPanel(new BorderLayout()); - bottomPane.add(textAreaScrollPane, BorderLayout.CENTER); - bottomPane.add(bottomLeftPanel, BorderLayout.LINE_START); - - table = new ClauseTable(this, displayFontSize); - - JScrollPane topPane = new JScrollPane(table); - - this.setTopComponent(topPane); - this.setBottomComponent(bottomPane); - this.setOneTouchExpandable(true); - this.setDividerLocation(350); - } - - private void notifyAllListeners() { - for (MyTabChangeListener tab : listeners) - tab.clausesChanged(table.getChosenClauses()); - } - - public void addChangeListener(MyTabChangeListener tab) { - listeners.add(tab); - } - - @Override - public void clausesChanged(List<Clause> clauses) { - table.setClauseList(clauses); - chosenClausesChanged(); - } - - public void chosenClausesChanged() { - StringBuffer sb = new StringBuffer(); - int chosenWords = 0; - for (Clause c : table.getChosenClauses()) { - sb.append(c); - chosenWords += c.getWords().size(); - } - - pb.setValue(chosenWords); - pb.setStringPainted(true); - if (targetSegmentCount == 0) - pb.setString(chosenWords + "/0 = -- %"); - else - pb.setString(chosenWords + "/" + targetSegmentCount + " = " + (100 * chosenWords / targetSegmentCount) - + "%"); - textArea.setText(sb.toString()); - - notifyAllListeners(); - } - - @Override - public String getName() { - return (int) (desired * 100) + "% summary"; - } - - public List<Clause> getChosenClauses() { - return table.getChosenClauses(); - } - - public void setChosenClauses(Set<String> clauseIds) { - table.setChosenClauses(clauseIds); - } - -} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTabChangeListener.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTabChangeListener.java deleted file mode 100644 index 283a535..0000000 --- a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/clausesumannotator/main/MyTabChangeListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package pl.waw.ipipan.zil.summarization.clausesumannotator.main; - - -import java.util.List; - -import pl.waw.ipipan.zil.summarization.clausesumannotator.basic.Clause; - -public interface MyTabChangeListener { - - public abstract void clausesChanged(List<Clause> clauses); - -} \ No newline at end of file diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Clause.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Clause.java new file mode 100644 index 0000000..56653fe --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Clause.java @@ -0,0 +1,40 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.basic; + +import java.util.ArrayList; +import java.util.List; + +public class Clause { + + private List<Word> words = new ArrayList<Word>(); + private String id; + private String cont; + + public Clause(String id, String cont) { + this.id = id; + this.cont = cont; + } + + public void add(Word currentWord) { + this.words.add(currentWord); + } + + public String getId() { + return this.id; + } + + public List<Word> getWords() { + return words; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Word w : words) + sb.append(" " + w.getOrth()); + return sb.toString(); + } + + public String getContinue() { + return this.cont; + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Word.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Word.java new file mode 100644 index 0000000..c9580e7 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/basic/Word.java @@ -0,0 +1,15 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.basic; + +public class Word { + + private String orth = null; + + public void setOrth(String orth) { + this.orth = orth; + } + + public String getOrth() { + return orth; + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/SummaryFileIO.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/SummaryFileIO.java new file mode 100644 index 0000000..3caf15b --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/SummaryFileIO.java @@ -0,0 +1,150 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.io; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.HashSet; +import java.util.Set; + +import javax.swing.JTabbedPane; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clausesumannotator.main.MyTab; + +public class SummaryFileIO { + + private static final Logger logger = Logger.getLogger(SummaryFileIO.class); + + public static boolean loadSummary(File summaryFile, JTabbedPane tabbedPane) { + logger.info("Loading summary from file: " + summaryFile); + BufferedReader br = null; + + try { + br = new BufferedReader(new FileReader(summaryFile)); + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + MyTab tab = (MyTab) tabbedPane.getComponent(i); + readTab(br, tab); + } + } catch (IOException e) { + logger.error("Error reading summary: " + e.getLocalizedMessage()); + return false; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + logger.error("Error closing summary file: " + e.getLocalizedMessage()); + return false; + } + } + return true; + } + + public static boolean saveSummary(File summaryFile, JTabbedPane tabbedPane) { + logger.info("Saving summary in file: " + summaryFile); + BufferedWriter bw = null; + + try { + bw = new BufferedWriter(new FileWriter(summaryFile)); + + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + MyTab tab = (MyTab) tabbedPane.getComponent(i); + writeTab(bw, tab); + } + + } catch (IOException e) { + logger.error("Error writing summary: " + e.getLocalizedMessage()); + return false; + } finally { + if (bw != null) + try { + bw.close(); + } catch (IOException e) { + logger.error("Error closing summary file: " + e.getLocalizedMessage()); + return false; + } + } + return true; + } + + private static void readTab(BufferedReader br, MyTab tab) throws IOException { + br.readLine(); + + Set<String> clauseIds = new HashSet<String>(); + while (true) { + String line = br.readLine(); + if (line == null) + break; + if (line.equals("")) + break; + clauseIds.add(line); + } + + tab.setChosenClauses(clauseIds); + + while (true) { + String line = br.readLine(); + if (line == null) + break; + if (line.equals("")) + break; + } + } + + private static void writeTab(Writer writer, MyTab tab) throws IOException { + writer.append("A " + tab.getName() + " should contain:\n"); + + int maxContLen = 0; + int maxIdLen = 0; + for (Clause c : tab.getChosenClauses()) { + int contLen = getCont(c).length(); + int idLen = getId(c).length(); + if (contLen > maxContLen) + maxContLen = contLen; + if (idLen > maxIdLen) + maxIdLen = idLen; + + writer.append(c.getId() + "\n"); + } + + writer.append("\n"); + + for (Clause c : tab.getChosenClauses()) { + String id = fill(getId(c), maxIdLen + 1); + String cont = fill(getCont(c), maxContLen + 1); + String full = id + " " + cont + " " + c.toString(); + writer.append(full + "\n"); + } + + writer.append("\n"); + } + + public static File getTargetFile(File currentFile) { + File parent = currentFile.getParentFile(); + String targetName = currentFile.getName().substring(0, currentFile.getName().lastIndexOf(".")) + ".summ"; + return new File(parent + File.separator + targetName); + } + + private static String getId(Clause c) { + return "ID=\"" + c.getId() + "\""; + } + + private static String getCont(Clause c) { + return "CONTINUE=\"" + c.getContinue() + "\""; + } + + private static String fill(String string, int spaceCount) { + StringBuffer sb = new StringBuffer(string); + int toFill = Math.max(0, spaceCount - string.length()); + for (int i = 0; i < toFill; i++) + sb.append(" "); + return sb.toString(); + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/XMLReader.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/XMLReader.java new file mode 100644 index 0000000..d32dcd9 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/io/XMLReader.java @@ -0,0 +1,120 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.log4j.Logger; +import org.codehaus.stax2.XMLInputFactory2; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Word; + +public class XMLReader { + + private static final Logger logger = Logger.getLogger(XMLReader.class); + + private static final XMLInputFactory xif = XMLInputFactory2.newInstance(); + + public static String loadText(File input, List<Clause> allClauses) { + logger.info("Loading text from file: " + input); + + String error = null; + + InputStream is = null; + XMLStreamReader sr = null; + try { + is = new FileInputStream(input); + sr = xif.createXMLStreamReader(is); + + Clause currentClause = null; + Word currentWord = null; + + while (sr.hasNext()) { + sr.next(); + + if (sr.isStartElement()) { + String name = sr.getName().getLocalPart(); + if (name.equals("CLAUSE")) { + String id = sr.getAttributeValue(null, "ID"); + String cont = sr.getAttributeValue(null, "CONTINUE"); + + if (cont == null) + cont = ""; + + if (id == null) { + error = "Clause without id in line: " + sr.getLocation().getLineNumber(); + break; + } + + if (currentClause != null) { + error = "Clause starting before previous clause finished in line: " + + sr.getLocation().getLineNumber(); + break; + } + + currentClause = new Clause(id, cont); + } else if (name.equals("W")) { + if (currentWord != null) { + error = "Word starting before previous word finished in line: " + + sr.getLocation().getLineNumber(); + break; + } + currentWord = new Word(); + } + } else if (sr.isEndElement()) { + String name = sr.getName().getLocalPart(); + if (name.equals("CLAUSE")) { + if (currentClause == null) { + error = "Clause ending before starting in line: " + sr.getLocation().getLineNumber(); + break; + } + + allClauses.add(currentClause); + currentClause = null; + } else if (name.equals("W")) { + if (currentWord == null) { + error = "Word ending before starting in line: " + sr.getLocation().getLineNumber(); + break; + } + if (currentClause == null) { + error = "Word not inside a clause in line: " + sr.getLocation().getLineNumber(); + break; + } + currentClause.add(currentWord); + currentWord = null; + } + } else if (sr.isWhiteSpace()) { + + } else if (sr.isCharacters()) { + if (currentWord != null) { + if (currentWord.getOrth() != null) { + error = "Second word orth in line: " + sr.getLocation().getLineNumber(); + break; + } + currentWord.setOrth(sr.getText()); + } + } + } + } catch (Exception e) { + error = "Error reading file: " + e.getLocalizedMessage(); + } finally { + try { + if (is != null) + is.close(); + if (sr != null) + sr.close(); + } catch (Exception e) { + error = "Error closing file: " + input + " Details: " + e.getLocalizedMessage(); + } + } + + logger.info(allClauses.size() + " clauses found."); + + return error; + } +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseSumAnnotator.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseSumAnnotator.java new file mode 100644 index 0000000..a5b7e64 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseSumAnnotator.java @@ -0,0 +1,397 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.main; + +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ButtonGroup; +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; +import pl.waw.ipipan.zil.summarizer.clausesumannotator.io.SummaryFileIO; +import pl.waw.ipipan.zil.summarizer.clausesumannotator.io.XMLReader; + +public class ClauseSumAnnotator extends JFrame implements Runnable, MyTabChangeListener { + + private static final String WINDOW_TITLE = "Clause-extraction summary annotator"; + + private static final long serialVersionUID = -3830790411182131318L; + + private static final Logger logger = Logger.getLogger(ClauseSumAnnotator.class); + + private static final int HEIGTH = 600; + private static final int WIDTH = 800; + + private JMenuItem save; + + private File currentFile = null; + private boolean unsavedChanges = false; + + private JTabbedPane tabbedPane; + + private float displayFontSize; + + public static void main(String[] args) { + if (args.length != 0 && args.length != 1) { + logger.error("Wrong usage! Should be: java -jar " + ClauseSumAnnotator.class.getSimpleName() + + " [input file]"); + return; + } + final ClauseSumAnnotator summanno = new ClauseSumAnnotator(); + try { + SwingUtilities.invokeAndWait(summanno); + } catch (Exception e) { + logger.error("Error starting application: " + e.getLocalizedMessage()); + e.printStackTrace(); + return; + } + + if (args.length == 1) { + final File input = new File(args[0]); + if (input.exists()) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + summanno.loadFile(input); + } + }); + } else { + logger.error("Input file: " + input + " doesn't exist!"); + } + } + } + + @Override + public void run() { + displayFontSize = loadDisplayFontSize(); + tabbedPane = new JTabbedPane(); + this.getContentPane().add(tabbedPane); + this.setTitle(WINDOW_TITLE); + this.createMenu(); + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new MainWindowListener(this)); + this.setSize(WIDTH, HEIGTH); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); + this.setVisible(true); + } + + private float loadDisplayFontSize() { + float result = 12f; + // File fontsizeFile = new File(fontsizePath); + // if (fontsizeFile.exists()) { + // try { + // Scanner s = new Scanner(fontsizeFile); + // result = s.nextFloat(); + // s.close(); + // logger.info("Font size found in file: " + fontsizeFile); + // } catch (FileNotFoundException e) { + // logger.error(e.getLocalizedMessage()); + // } + // } else { + // logger.info("Font size not found in file: " + fontsizeFile); + logger.info("Using default font size."); + // } + return result; + } + + private void createMenu() { + JMenuBar menu = new JMenuBar(); + this.setJMenuBar(menu); + + JMenu file = new JMenu("File"); + menu.add(file); + + JMenuItem open = new JMenuItem("Open"); + open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); + open.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestOpenFile(); + } + }); + file.add(open); + + save = new JMenuItem("Save"); + save.setEnabled(false); + save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); + save.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestSaveFile(); + } + }); + file.add(save); + + JMenuItem exit = new JMenuItem("Exit"); + exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); + exit.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestExit(); + } + }); + file.add(exit); + + JMenu other = new JMenu("Other"); + + ButtonGroup fontSizeButtonGroup = new ButtonGroup(); + JMenu setFontSize = new JMenu("Change font size"); + for (int z = 8; z < 30; z = z + 2) { + + final int currentFontSize = z; + + JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); + if (z == displayFontSize) { + temp.setSelected(true); + } + temp.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + requestSetFontSize(currentFontSize); + } + }); + fontSizeButtonGroup.add(temp); + setFontSize.add(temp); + } + other.add(setFontSize); + + JMenuItem help = new JMenuItem("Help"); + help.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + requestShowHelp(); + } + }); + other.add(help); + + menu.add(other); + } + + protected void requestSetFontSize(int currentFontSize) { + logger.info("Setting font size: " + currentFontSize); + displayFontSize = currentFontSize; + + // File fontsizeFile = new File(fontsizePath); + // logger.info("Saving font size in file: " + fontsizeFile); + // + // try { + // Writer w = new FileWriter(fontsizeFile); + // w.write(Float.toString(displayFontSize)); + // w.write("\n"); + // w.close(); + // } catch (IOException e) { + // logger.error(e.getLocalizedMessage()); + // } + } + + private final void requestShowHelp() { + JFrame helpFrame = new JFrame("Help"); + helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JEditorPane editorPane = new JEditorPane(); + editorPane.setEditable(false); + URL helpURL = ClauseSumAnnotator.class.getClassLoader().getResource("help.html"); + if (helpURL != null) { + try { + editorPane.setPage(helpURL); + } catch (IOException e) { + logger.error("Attempted to read a bad URL: " + helpURL); + } + } else { + logger.error("Couldn't find file: help.html"); + } + + // Put the editor pane in a scroll pane. + JScrollPane editorScrollPane = new JScrollPane(editorPane); + editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setPreferredSize(new Dimension(800, 600)); + editorScrollPane.setMinimumSize(new Dimension(30, 30)); + + helpFrame.getContentPane().add(editorScrollPane); + helpFrame.pack(); + helpFrame.setVisible(true); + } + + private void requestSaveFile() { + File targetFile = SummaryFileIO.getTargetFile(currentFile); + boolean success = SummaryFileIO.saveSummary(targetFile, tabbedPane); + + if (success) { + unsavedChanges = false; + setTitle(WINDOW_TITLE); + save.setEnabled(false); + } else { + showError("Error saving file: " + targetFile); + } + } + + private final void requestOpenFile() { + if (!askToSaveChanges()) + return; + + JFileChooser chooser; + if (currentFile == null) + chooser = new JFileChooser(); + else + chooser = new JFileChooser(currentFile.getParentFile()); + + chooser.setFileFilter(new SummannotatorFileFilter()); + int result = chooser.showOpenDialog(this); + + if (result == JFileChooser.APPROVE_OPTION) { + this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + this.loadFile(chooser.getSelectedFile()); + this.setCursor(null); + } + } + + private boolean askToSaveChanges() { + if (!unsavedChanges) + return true; + + int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); + + if (result == JOptionPane.CANCEL_OPTION) + return false; + + if (result == JOptionPane.YES_OPTION) + requestSaveFile(); + + return true; + } + + private final void requestExit() { + if (!askToSaveChanges()) + return; + + logger.info("Exiting."); + System.exit(0); + } + + private final void loadFile(File input) { + tabbedPane.removeAll(); + + if (!input.exists()) { + String err = "File " + input + " doesn't exist!"; + logger.error(err); + showError(err); + return; + } + List<Clause> clauses = new ArrayList<Clause>(); + String error = XMLReader.loadText(input, clauses); + if (error != null) { + logger.error(error); + showError(error); + return; + } + if (clauses.size() == 0) { + String err = "No clauses found in file: " + input; + logger.error(err); + showError(err); + return; + } + + int all = getAllWordsCount(clauses); + + MyTab tab1 = new MyTab(all, 0.2, displayFontSize); + MyTab tab2 = new MyTab(all, 0.1, displayFontSize); + MyTab tab3 = new MyTab(all, 0.05, displayFontSize); + + tab1.addChangeListener(tab2); + tab2.addChangeListener(tab3); + tab1.clausesChanged(clauses); + + tabbedPane.addTab(tab1.getName(), tab1); + tabbedPane.addTab(tab2.getName(), tab2); + tabbedPane.addTab(tab3.getName(), tab3); + + currentFile = input; + + File summaryFile = SummaryFileIO.getTargetFile(input); + if (summaryFile.exists()) { + boolean success = SummaryFileIO.loadSummary(summaryFile, tabbedPane); + if (success) { + logger.info("Summary file found and loaded: " + summaryFile); + } else { + showError("Error loading summary file: " + summaryFile); + } + } + + tab1.addChangeListener(this); + tab2.addChangeListener(this); + tab3.addChangeListener(this); + } + + private void showError(String string) { + JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); + } + + private static int getAllWordsCount(List<Clause> clauses) { + int all = 0; + for (Clause c : clauses) + all += c.getWords().size(); + return all; + } + + private final class SummannotatorFileFilter extends FileFilter { + @Override + public String getDescription() { + return "XML files"; + } + + @Override + public boolean accept(File f) { + return f.getName().endsWith(".xml") || f.isDirectory(); + } + } + + private class MainWindowListener extends WindowAdapter { + + private final ClauseSumAnnotator summanotator; + + public MainWindowListener(ClauseSumAnnotator sumannotator) { + this.summanotator = sumannotator; + } + + @Override + public void windowClosing(WindowEvent we) { + this.summanotator.requestExit(); + } + } + + @Override + public void clausesChanged(List<Clause> clauses) { + unsavedChanges = true; + save.setEnabled(true); + setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseTable.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseTable.java new file mode 100644 index 0000000..15130e5 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/ClauseTable.java @@ -0,0 +1,186 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.main; + +import java.awt.Color; +import java.awt.Component; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.ListSelectionModel; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellRenderer; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; + +public class ClauseTable extends JTable implements MouseListener, KeyListener { + + private static final long serialVersionUID = 5865240498654370980L; + + private final List<Clause> allClauses = new ArrayList<Clause>(); + private final Set<Clause> chosenClauses = new HashSet<Clause>(); + + private final AbstractTableModel model; + + private final MyTab parentTab; + + public ClauseTable(MyTab parentTab, float displayFontSize) { + this.parentTab = parentTab; + + setFillsViewportHeight(true); + setTableHeader(null); + addMouseListener(this); + addKeyListener(this); + setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + setDefaultRenderer(Object.class, new MyCellRenderer(displayFontSize)); + + model = new SimpleClauseTableModel(); + setModel(model); + } + + public synchronized void setClauseList(List<Clause> clauses) { + allClauses.clear(); + allClauses.addAll(clauses); + chosenClauses.retainAll(allClauses); + model.fireTableDataChanged(); + } + + public synchronized void rowsSelected() { + if (this.getSelectedRows().length == 0) + return; + + for (int i : this.getSelectedRows()) { + changeRowStatus(i); + } + clearSelection(); + parentTab.chosenClausesChanged(); + } + + public synchronized void changeRowStatus(int row) { + Clause c = allClauses.get(row); + if (chosenClauses.contains(c)) + chosenClauses.remove(c); + else + chosenClauses.add(c); + } + + private boolean isClauseChosen(Clause value) { + return chosenClauses.contains(value); + } + + public List<Clause> getChosenClauses() { + List<Clause> result = new ArrayList<Clause>(); + for (Clause c : allClauses) + if (chosenClauses.contains(c)) + result.add(c); + return result; + } + + public synchronized void setChosenClauses(Set<String> clauseIds) { + chosenClauses.clear(); + for (Clause c : allClauses) + if (clauseIds.contains(c.getId())) + chosenClauses.add(c); + parentTab.chosenClausesChanged(); + } + + /************* listeners ******************************/ + + @Override + public void mouseClicked(MouseEvent e) { + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + } + + @Override + public void mousePressed(MouseEvent e) { + } + + @Override + public void keyPressed(KeyEvent arg0) { + } + + @Override + public void keyTyped(KeyEvent arg0) { + } + + @Override + public void mouseReleased(MouseEvent e) { + rowsSelected(); + } + + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SPACE) + rowsSelected(); + } + + private final class SimpleClauseTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 5563319901787241258L; + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + return allClauses.get(rowIndex); + } + + @Override + public int getRowCount() { + return allClauses.size(); + } + + @Override + public int getColumnCount() { + return 1; + } + } + + /********************** cell renderer **************************/ + + private class MyCellRenderer extends JTextArea implements TableCellRenderer { + + private static final long serialVersionUID = 3003554184145715021L; + + public MyCellRenderer(float displayFontSize) { + super(); + setFont(getFont().deriveFont(displayFontSize)); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int col) { + + String text = value.toString(); + setLineWrap(true); + setWrapStyleWord(true); + setText(text); + setSize(table.getWidth(), table.getRowHeight()); + + if (isSelected) + setBackground(Color.gray); + else if (isClauseChosen((Clause) value)) + setBackground(Color.yellow); + else + setBackground(null); + + int heightWanted = getPreferredSize().height; + if (heightWanted != table.getRowHeight(row)) + table.setRowHeight(row, heightWanted); + + return this; + } + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTab.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTab.java new file mode 100644 index 0000000..e526090 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTab.java @@ -0,0 +1,125 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.main; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextArea; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; + +public class MyTab extends JSplitPane implements MyTabChangeListener { + + private static final long serialVersionUID = 3656861958564714263L; + + private final ClauseTable table; + private final JTextArea textArea; + private final JProgressBar pb; + + private final int targetSegmentCount; + + private final Set<MyTabChangeListener> listeners = new HashSet<MyTabChangeListener>(); + + private final double desired; + + public MyTab(int allSegments, double desired, float displayFontSize) { + super(JSplitPane.VERTICAL_SPLIT); + + this.targetSegmentCount = (int) (desired * allSegments); + this.desired = desired; + + textArea = new JTextArea("empty"); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + textArea.setFont(textArea.getFont().deriveFont(displayFontSize)); + JScrollPane textAreaScrollPane = new JScrollPane(textArea); + + pb = new JProgressBar(0, targetSegmentCount); + JLabel all = new JLabel("Words in text: " + allSegments); + JLabel prop = new JLabel("Summary proportion: " + (int) (desired * 100) + "%"); + JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); + + // pb.setFont(pb.getFont().deriveFont(displayFontSize)); + // all.setFont(all.getFont().deriveFont(displayFontSize)); + // prop.setFont(prop.getFont().deriveFont(displayFontSize)); + // summ.setFont(summ.getFont().deriveFont(displayFontSize)); + + JPanel bottomLeftPanel = new JPanel(); + bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); + bottomLeftPanel.add(pb); + bottomLeftPanel.add(all); + bottomLeftPanel.add(prop); + bottomLeftPanel.add(summ); + bottomLeftPanel.setPreferredSize(new Dimension(prop.getPreferredSize().width + 10, 100)); + + JPanel bottomPane = new JPanel(new BorderLayout()); + bottomPane.add(textAreaScrollPane, BorderLayout.CENTER); + bottomPane.add(bottomLeftPanel, BorderLayout.LINE_START); + + table = new ClauseTable(this, displayFontSize); + + JScrollPane topPane = new JScrollPane(table); + + this.setTopComponent(topPane); + this.setBottomComponent(bottomPane); + this.setOneTouchExpandable(true); + this.setDividerLocation(350); + } + + private void notifyAllListeners() { + for (MyTabChangeListener tab : listeners) + tab.clausesChanged(table.getChosenClauses()); + } + + public void addChangeListener(MyTabChangeListener tab) { + listeners.add(tab); + } + + @Override + public void clausesChanged(List<Clause> clauses) { + table.setClauseList(clauses); + chosenClausesChanged(); + } + + public void chosenClausesChanged() { + StringBuffer sb = new StringBuffer(); + int chosenWords = 0; + for (Clause c : table.getChosenClauses()) { + sb.append(c); + chosenWords += c.getWords().size(); + } + + pb.setValue(chosenWords); + pb.setStringPainted(true); + if (targetSegmentCount == 0) + pb.setString(chosenWords + "/0 = -- %"); + else + pb.setString(chosenWords + "/" + targetSegmentCount + " = " + (100 * chosenWords / targetSegmentCount) + + "%"); + textArea.setText(sb.toString()); + + notifyAllListeners(); + } + + @Override + public String getName() { + return (int) (desired * 100) + "% summary"; + } + + public List<Clause> getChosenClauses() { + return table.getChosenClauses(); + } + + public void setChosenClauses(Set<String> clauseIds) { + table.setChosenClauses(clauseIds); + } + +} diff --git a/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTabChangeListener.java b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTabChangeListener.java new file mode 100644 index 0000000..008ba13 --- /dev/null +++ b/ClauseSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/clausesumannotator/main/MyTabChangeListener.java @@ -0,0 +1,11 @@ +package pl.waw.ipipan.zil.summarizer.clausesumannotator.main; + +import java.util.List; + +import pl.waw.ipipan.zil.summarizer.clausesumannotator.basic.Clause; + +public interface MyTabChangeListener { + + public abstract void clausesChanged(List<Clause> clauses); + +} \ No newline at end of file diff --git a/ClauseSumAnnotator/src/main/resources/log4j.properties b/ClauseSumAnnotator/src/main/resources/log4j.properties new file mode 100644 index 0000000..6d8f00a --- /dev/null +++ b/ClauseSumAnnotator/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n + +log4j.logger.pl.waw.ipipan.zil=INFO, stderr \ No newline at end of file diff --git a/ExtrSumAnnotator/.classpath b/ExtrSumAnnotator/.classpath deleted file mode 100644 index fc321d6..0000000 --- a/ExtrSumAnnotator/.classpath +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> diff --git a/ExtrSumAnnotator/.gitignore b/ExtrSumAnnotator/.gitignore index 6b743b9..6cb1223 100644 --- a/ExtrSumAnnotator/.gitignore +++ b/ExtrSumAnnotator/.gitignore @@ -1,4 +1,4 @@ -*.class -*~ -.settings/* -target +/target/ +.project +.settings +.classpath diff --git a/ExtrSumAnnotator/pom.xml b/ExtrSumAnnotator/pom.xml index 4e5acf8..682d229 100644 --- a/ExtrSumAnnotator/pom.xml +++ b/ExtrSumAnnotator/pom.xml @@ -1,10 +1,13 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>ipipan.atlas</groupId> + <groupId>pl.waw.ipipan.zil.summarizer</groupId> <artifactId>extrsumannotator</artifactId> - <version>0.1</version> + <version>1.0</version> <name>ExtrSumAnnotator</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <build> <plugins> <plugin> @@ -12,7 +15,7 @@ <configuration> <archive> <manifest> - <mainClass>ipipan.atlas.extrsumannotator.main.ExtrSumAnnotator</mainClass> + <mainClass>pl.waw.ipipan.zil.summarizer.extrsumannotator.main.ExtrSumAnnotator</mainClass> </manifest> </archive> <descriptorRefs> @@ -20,6 +23,14 @@ </descriptorRefs> </configuration> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> </plugins> </build> <dependencies> @@ -34,4 +45,4 @@ <version>3.1.1</version> </dependency> </dependencies> -</project> \ No newline at end of file +</project> diff --git a/ExtrSumAnnotator/src/main/java/log4j.properties b/ExtrSumAnnotator/src/main/java/log4j.properties deleted file mode 100644 index 2258654..0000000 --- a/ExtrSumAnnotator/src/main/java/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n - -log4j.logger.pl.waw.ipipan.zil.summarization.extrsumannotator=INFO, stderr \ No newline at end of file diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/basic/Text.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/basic/Text.java deleted file mode 100644 index e3bc98b..0000000 --- a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/basic/Text.java +++ /dev/null @@ -1,43 +0,0 @@ -package pl.waw.ipipan.zil.summarization.extrsumannotator.basic; - -import java.util.List; -import java.util.SortedSet; - -public class Text { - - private String text = null; - private List<SortedSet<Integer>> summaries; - - public Text(String string, List<SortedSet<Integer>> summaries) { - this.text = string; - this.summaries = summaries; - } - - public String getText() { - return text; - } - - public int getTextWordsCount() { - return getStringWordCount(text); - } - - public static int getStringWordCount(String string) { - return string.split("[ ]+").length; - } - - public void setSummaries(List<SortedSet<Integer>> summaries) { - this.summaries = summaries; - } - - public SortedSet<Integer> getSummary(int number) { - return summaries.get(number); - } - - public List<SortedSet<Integer>> getSummaries() { - return summaries; - } - - public void setSummary(int summNumber, SortedSet<Integer> sum) { - summaries.set(summNumber, sum); - } -} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/io/SummaryFileIO.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/io/SummaryFileIO.java deleted file mode 100644 index a87a9ad..0000000 --- a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/io/SummaryFileIO.java +++ /dev/null @@ -1,135 +0,0 @@ -package pl.waw.ipipan.zil.summarization.extrsumannotator.io; - - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.extrsumannotator.basic.Text; -import pl.waw.ipipan.zil.summarization.extrsumannotator.main.ExtrSumAnnotator; - -public class SummaryFileIO { - - private static final String SUMMARIES = "#### SUMMARIES ####"; - private static final String SUMMARY_START = "#### SUMMARY START ####"; - private static final String SUMMARY_END = "#### SUMMARY END ####"; - - private static final Logger logger = Logger.getLogger(SummaryFileIO.class); - - public static boolean saveSummary(File summaryFile, Text text) { - logger.info("Saving text with summaries in file: " + summaryFile); - BufferedWriter bw = null; - - try { - bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(summaryFile), "UTF-8")); - - bw.append(text.getText() + "\n"); - - bw.append(SUMMARIES + "\n"); - - for (SortedSet<Integer> sum : text.getSummaries()) { - bw.append(SUMMARY_START + "\n"); - for (Integer idx : sum) - bw.append(idx + " "); - bw.append("\n"); - bw.append(SUMMARY_END + "\n"); - } - - } catch (IOException e) { - logger.error("Error writing summary: " + e.getLocalizedMessage()); - return false; - } finally { - if (bw != null) - try { - bw.close(); - } catch (IOException e) { - logger.error("Error closing summary file: " + e.getLocalizedMessage()); - return false; - } - } - return true; - } - - public static Text loadText(File input) { - - logger.info("Loading text with summaries from file: " + input); - BufferedReader br = null; - - try { - br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8")); - String line = null; - StringBuffer fullText = new StringBuffer(); - List<SortedSet<Integer>> summaries = new ArrayList<SortedSet<Integer>>(); - while ((line = br.readLine()) != null) { - if (line.startsWith(SUMMARIES)) - loadSummaries(br, summaries); - else - fullText.append(line + "\n"); - } - - while (summaries.size() < ExtrSumAnnotator.SUMMARIES_SIZES.length) { - summaries.add(new TreeSet<Integer>()); - } - - Text t = new Text(fullText.toString(), summaries); - return t; - - } catch (IOException e) { - logger.error("Error reading text: " + e.getLocalizedMessage()); - return null; - } finally { - try { - if (br != null) - br.close(); - } catch (IOException e) { - logger.error("Error closing text file: " + e.getLocalizedMessage()); - return null; - } - } - } - - private static void loadSummaries(BufferedReader br, List<SortedSet<Integer>> summaries) throws IOException { - SortedSet<Integer> summary = null; - while ((summary = loadSummary(br)) != null) - summaries.add(summary); - } - - private static SortedSet<Integer> loadSummary(BufferedReader br) throws IOException { - SortedSet<Integer> summary = new TreeSet<Integer>(); - - String line = null; - boolean inside = false; - while ((line = br.readLine()) != null) { - if (line.startsWith(SUMMARY_END)) - break; - - if (inside) { - Scanner sc = new Scanner(line); - while (sc.hasNextInt()) - summary.add(sc.nextInt()); - sc.close(); - } - - if (line.startsWith(SUMMARY_START)) - inside = true; - } - - if (summary.size() == 0 && !inside) - return null; - - return summary; - } - -} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/ExtrSumAnnotator.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/ExtrSumAnnotator.java deleted file mode 100644 index bba3303..0000000 --- a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/ExtrSumAnnotator.java +++ /dev/null @@ -1,384 +0,0 @@ -package pl.waw.ipipan.zil.summarization.extrsumannotator.main; - - -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.swing.ButtonGroup; -import javax.swing.JEditorPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.filechooser.FileFilter; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.extrsumannotator.basic.Text; -import pl.waw.ipipan.zil.summarization.extrsumannotator.io.SummaryFileIO; - -public class ExtrSumAnnotator extends JFrame implements Runnable, MyTabChangeListener { - - private static final String WINDOW_TITLE = "ESE v0.9"; - - private static final long serialVersionUID = -3830790411182131318L; - - private static final Logger logger = Logger.getLogger(ExtrSumAnnotator.class); - - private static final int HEIGTH = 600; - private static final int WIDTH = 800; - - public static double[] SUMMARIES_SIZES = new double[] { 0.2, 0.1, 0.05 }; - - private JMenuItem save; - - private File currentFile = null; - private boolean unsavedChanges = false; - - private JTabbedPane tabbedPane; - - private float displayFontSize; - - private Text currentText; - - public static void main(String[] args) { - if (args.length != 0 && args.length != 1) { - logger.error("Wrong usage! Should be: java -jar " + ExtrSumAnnotator.class.getSimpleName() - + " [input file]"); - return; - } - final ExtrSumAnnotator summanno = new ExtrSumAnnotator(); - try { - SwingUtilities.invokeAndWait(summanno); - } catch (Exception e) { - logger.error("Error starting application: " + e.getLocalizedMessage()); - e.printStackTrace(); - return; - } - - if (args.length == 1) { - final File input = new File(args[0]); - if (input.exists()) { - SwingUtilities.invokeLater(new Runnable() { - - public void run() { - summanno.loadFile(input); - } - }); - } else { - logger.error("Input file: " + input + " doesn't exist!"); - } - } - } - - public void run() { - displayFontSize = loadDisplayFontSize(); - tabbedPane = new JTabbedPane(); - this.getContentPane().add(tabbedPane); - this.setTitle(WINDOW_TITLE); - this.createMenu(); - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.addWindowListener(new MainWindowListener(this)); - this.setSize(WIDTH, HEIGTH); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); - this.setVisible(true); - } - - private float loadDisplayFontSize() { - float result = 12f; - logger.info("Using default font size."); - return result; - } - - private void createMenu() { - JMenuBar menu = new JMenuBar(); - this.setJMenuBar(menu); - - JMenu file = new JMenu("File"); - menu.add(file); - - JMenuItem open = new JMenuItem("Open"); - open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); - open.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - requestOpenFile(); - } - }); - file.add(open); - - save = new JMenuItem("Save"); - save.setEnabled(false); - save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); - save.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - requestSaveFile(); - } - }); - file.add(save); - - JMenuItem exit = new JMenuItem("Exit"); - exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); - exit.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - requestExit(); - } - }); - file.add(exit); - - JMenu other = new JMenu("Other"); - - ButtonGroup fontSizeButtonGroup = new ButtonGroup(); - JMenu setFontSize = new JMenu("Change font size"); - for (int z = 8; z < 30; z = z + 2) { - - final int currentFontSize = z; - - JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); - if (z == displayFontSize) { - temp.setSelected(true); - } - temp.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent ae) { - requestSetFontSize(currentFontSize); - } - }); - fontSizeButtonGroup.add(temp); - setFontSize.add(temp); - } - other.add(setFontSize); - - JMenuItem help = new JMenuItem("Help"); - help.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - requestShowHelp(); - } - }); - other.add(help); - - menu.add(other); - } - - protected void requestSetFontSize(float currentFontSize) { - logger.info("Setting font size: " + currentFontSize); - displayFontSize = currentFontSize; - - Enumeration<Object> enumer = UIManager.getDefaults().keys(); - while (enumer.hasMoreElements()) { - Object key = enumer.nextElement(); - Object value = UIManager.get(key); - if (value instanceof Font) { - UIManager.put(key, new javax.swing.plaf.FontUIResource(((Font) value).deriveFont(currentFontSize))); - } - } - SwingUtilities.updateComponentTreeUI(this); - } - - private final void requestShowHelp() { - JFrame helpFrame = new JFrame("Help"); - helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JEditorPane editorPane = new JEditorPane(); - editorPane.setEditable(false); - URL helpURL = ExtrSumAnnotator.class.getClassLoader().getResource("help.html"); - if (helpURL != null) { - try { - editorPane.setPage(helpURL); - } catch (IOException e) { - logger.error("Attempted to read a bad URL: " + helpURL); - } - } else { - logger.error("Couldn't find file: help.html"); - } - - // Put the editor pane in a scroll pane. - JScrollPane editorScrollPane = new JScrollPane(editorPane); - editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - editorScrollPane.setPreferredSize(new Dimension(800, 600)); - editorScrollPane.setMinimumSize(new Dimension(30, 30)); - - helpFrame.getContentPane().add(editorScrollPane); - helpFrame.pack(); - helpFrame.setVisible(true); - } - - private void requestSaveFile() { - - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - MyTab tab = (MyTab) tabbedPane.getComponentAt(i); - currentText.setSummary(i, tab.getSelectedIndices()); - } - - boolean success = SummaryFileIO.saveSummary(currentFile, currentText); - - if (success) { - unsavedChanges = false; - setTitle(WINDOW_TITLE); - save.setEnabled(false); - } else { - showError("Error saving file: " + currentFile); - } - } - - private final void requestOpenFile() { - if (!askToSaveChanges()) - return; - - JFileChooser chooser; - if (currentFile == null) - chooser = new JFileChooser(); - else - chooser = new JFileChooser(currentFile.getParentFile()); - - chooser.setFileFilter(new SummannotatorFileFilter()); - int result = chooser.showOpenDialog(this); - - if (result == JFileChooser.APPROVE_OPTION) { - this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - this.loadFile(chooser.getSelectedFile()); - this.setCursor(null); - } - } - - private boolean askToSaveChanges() { - if (!unsavedChanges) - return true; - - int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); - - if (result == JOptionPane.CANCEL_OPTION) - return false; - - if (result == JOptionPane.YES_OPTION) - requestSaveFile(); - - return true; - } - - private final void requestExit() { - if (!askToSaveChanges()) - return; - - logger.info("Exiting."); - System.exit(0); - } - - private final void loadFile(File input) { - tabbedPane.removeAll(); - - if (!input.exists()) { - String err = "File " + input + " doesn't exist!"; - logger.error(err); - showError(err); - return; - } - - currentText = SummaryFileIO.loadText(input); - - int all = currentText.getTextWordsCount(); - List<MyTab> allTabs = new ArrayList<MyTab>(); - - MyTab firstTab = new MyTab((int) (SUMMARIES_SIZES[0] * all), currentText.getText()); - allTabs.add(firstTab); - - MyTab toListen = firstTab; - for (int i = 1; i < SUMMARIES_SIZES.length; i++) { - MyTab tab = new MyTab((int) (SUMMARIES_SIZES[i] * all), currentText.getText()); - toListen.addChangeListener(tab); - toListen = tab; - allTabs.add(tab); - } - - SortedSet<Integer> fullSelection = new TreeSet<Integer>(); - for (int i = 0; i < currentText.getText().length(); i++) - fullSelection.add(i); - firstTab.fullTextChanged(fullSelection); - - int i = 0; - for (SortedSet<Integer> sum : currentText.getSummaries()) { - allTabs.get(i++).setSummary(sum); - } - - i = 0; - for (MyTab tab : allTabs) { - tab.addChangeListener(this); - tabbedPane.addTab(((int) (SUMMARIES_SIZES[i++] * 100)) + "% summary", tab); - } - - currentFile = input; - } - - private void showError(String string) { - JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); - } - - private final class SummannotatorFileFilter extends FileFilter { - @Override - public String getDescription() { - return "TXT files"; - } - - @Override - public boolean accept(File f) { - return f.getName().endsWith(".txt") || f.isDirectory(); - } - } - - private class MainWindowListener extends WindowAdapter { - - private final ExtrSumAnnotator summanotator; - - public MainWindowListener(ExtrSumAnnotator sumannotator) { - this.summanotator = sumannotator; - } - - @Override - public void windowClosing(WindowEvent we) { - this.summanotator.requestExit(); - } - } - - public void fullTextChanged(SortedSet<Integer> selectedCharsIndices) { - unsavedChanges = true; - save.setEnabled(true); - setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); - } - - public void undo() { - } - - public void saveStateForUndo(boolean thisTabChanged) { - } - -} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTab.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTab.java deleted file mode 100644 index a4d84e0..0000000 --- a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTab.java +++ /dev/null @@ -1,325 +0,0 @@ -package pl.waw.ipipan.zil.summarization.extrsumannotator.main; - - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.swing.AbstractAction; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.KeyStroke; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultHighlighter; -import javax.swing.text.Highlighter.HighlightPainter; - -import org.apache.log4j.Logger; - -import pl.waw.ipipan.zil.summarization.extrsumannotator.basic.Text; - -public class MyTab extends JSplitPane implements MyTabChangeListener { - - private static final Logger logger = Logger.getLogger(MyTab.class); - - private static final long serialVersionUID = 3656861958564714263L; - - private final JTextToSummarizeArea fullTextPane; - private final JTextArea summaryPane; - - private final JProgressBar pb; - - private final int targetSegmentCount; - private final int allSegmentCount; - - private final Set<MyTabChangeListener> listeners = new HashSet<MyTabChangeListener>(); - - private final String originalText; - - public SortedSet<Integer> previousIndices = null; - - private final JButton undoButton; - - public MyTab(int targetCount, String originalText) { - super(JSplitPane.VERTICAL_SPLIT); - - this.originalText = originalText; - - this.targetSegmentCount = targetCount; - this.allSegmentCount = Text.getStringWordCount(originalText); - - fullTextPane = new JTextToSummarizeArea(); - fullTextPane.setLineWrap(true); - fullTextPane.setEditable(false); - fullTextPane.setWrapStyleWord(true); - fullTextPane.setMargin(new Insets(10, 10, 10, 10)); - - summaryPane = new JTextArea(); - summaryPane.setLineWrap(true); - summaryPane.setEditable(false); - summaryPane.setWrapStyleWord(true); - summaryPane.setMargin(new Insets(10, 10, 10, 10)); - - pb = new JProgressBar(0, targetSegmentCount); - JLabel all = new JLabel("Words in text: " + allSegmentCount); - JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); - - UndoAction undoAction = new UndoAction(); - this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( - KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), "undo"); - this.getActionMap().put("undo", undoAction); - undoButton = new JButton(undoAction); - undoButton.setEnabled(false); - undoButton.setText("Undo last action (CTRL+Z)"); - - JPanel bottomLeftPanel = new JPanel(); - bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); - bottomLeftPanel.add(pb); - bottomLeftPanel.add(all); - bottomLeftPanel.add(summ); - bottomLeftPanel.add(Box.createVerticalStrut(8)); - bottomLeftPanel.add(undoButton); - - JPanel bottomPane = new JPanel(new BorderLayout()); - bottomPane.add(new JScrollPane(summaryPane), BorderLayout.CENTER); - bottomPane.add(bottomLeftPanel, BorderLayout.LINE_START); - - this.setTopComponent(new JScrollPane(fullTextPane)); - this.setBottomComponent(bottomPane); - this.setOneTouchExpandable(true); - this.setDividerLocation(350); - } - - public void addChangeListener(MyTabChangeListener tab) { - listeners.add(tab); - } - - public void selectionChanged(SortedSet<Integer> selectedCharsIndices) { - String summ = getTextByIndices(this.originalText, selectedCharsIndices); - int summWC = Text.getStringWordCount(summ); - - pb.setValue(summWC); - pb.setStringPainted(true); - if (targetSegmentCount == 0) - pb.setString(summWC + "/0 = -- %"); - else - pb.setString(summWC + "/" + targetSegmentCount + " = " + (100 * summWC / targetSegmentCount) + "%"); - - summaryPane.setText(summ); - - for (MyTabChangeListener l : listeners) - l.fullTextChanged(selectedCharsIndices); - } - - private String getTextByIndices(String text, SortedSet<Integer> selectedCharsIndices) { - StringBuffer sb = new StringBuffer(); - for (Integer idx : selectedCharsIndices) - sb.append(text.substring(idx, idx + 1)); - String summ = sb.toString(); - return summ; - } - - public void fullTextChanged(SortedSet<Integer> selectedCharsIndices) { - fullTextPane.setOriginalText(selectedCharsIndices); - } - - public SortedSet<Integer> getSelectedIndices() { - return fullTextPane.getSelectedIndices(); - } - - public void setSummary(SortedSet<Integer> sum) { - fullTextPane.setSummary(sum); - } - - public void saveStateForUndo(boolean thisTabChanged) { - logger.debug("Saving state for undo... (tab: " + targetSegmentCount + ")"); - previousIndices = getSelectedIndices(); - logger.debug(previousIndices); - - if (thisTabChanged) - undoButton.setEnabled(true); - else - undoButton.setEnabled(false); - - for (MyTabChangeListener l : listeners) - l.saveStateForUndo(false); - } - - public void undo() { - if (previousIndices != null) { - logger.debug("Undoing... (tab: " + targetSegmentCount + ")"); - logger.debug(previousIndices); - this.undoButton.setEnabled(false); - - try { - this.setSummary(previousIndices); - } catch (Exception ex) { - logger.error("Error undoing... (tab: " + targetSegmentCount + ")"); - } - - previousIndices = null; - for (MyTabChangeListener l : listeners) - l.undo(); - } else { - logger.debug("Nothing to undo... (tab: " + targetSegmentCount + ")"); - } - } - - private class JTextToSummarizeArea extends JTextArea implements CaretListener { - - private static final long serialVersionUID = -8674213151313542475L; - - private SortedSet<Integer> selectedCharsIndices = new TreeSet<Integer>(); - - private final Map<Integer, Integer> mappingOrig2This = new HashMap<Integer, Integer>(); - private final Map<Integer, Integer> mappingThis2Orig = new HashMap<Integer, Integer>(); - - private final Color hlColor = new Color(255, 0, 0, 100); - private final HighlightPainter hlPainter = new DefaultHighlighter.DefaultHighlightPainter(hlColor); - - public JTextToSummarizeArea() { - super(); - this.addCaretListener(this); - } - - public void setSummary(SortedSet<Integer> sum) { - selectedCharsIndices.clear(); - for (Integer idx : sum) - selectedCharsIndices.add(mappingOrig2This.get(idx)); - refreshView(); - } - - public SortedSet<Integer> getSelectedIndices() { - SortedSet<Integer> origSelectedCharsIndices = new TreeSet<Integer>(); - for (Integer i : this.selectedCharsIndices) - origSelectedCharsIndices.add(mappingThis2Orig.get(i)); - - return origSelectedCharsIndices; - } - - public void setOriginalText(SortedSet<Integer> newOriginalTextIndices) { - if (mappingOrig2This != null) { - SortedSet<Integer> newSelectedCharsIndices = new TreeSet<Integer>(); - int i = 0; - for (Integer idx : newOriginalTextIndices) { - Integer oldIdx = mappingOrig2This.get(idx); - if (oldIdx != null && selectedCharsIndices.contains(oldIdx)) - newSelectedCharsIndices.add(i); - i++; - } - selectedCharsIndices = newSelectedCharsIndices; - } - - mappingOrig2This.clear(); - int i = 0; - for (Integer idx : newOriginalTextIndices) - mappingOrig2This.put(idx, i++); - - mappingThis2Orig.clear(); - i = 0; - for (Integer idx : newOriginalTextIndices) - mappingThis2Orig.put(i++, idx); - - String summ = getTextByIndices(originalText, newOriginalTextIndices); - - this.setText(summ); - this.setCaretPosition(0); - refreshView(); - } - - public void caretUpdate(CaretEvent e) { - int dot = e.getDot(); - int mark = e.getMark(); - - if (dot == mark) - return; - - if (dot < mark) { - int tmp = mark; - mark = dot; - dot = tmp; - } - - saveStateForUndo(true); - - boolean allSelected = true; - for (int i = mark; i < dot; i++) - if (!this.selectedCharsIndices.contains(i)) - allSelected = false; - - for (int i = mark; i < dot; i++) - if (!allSelected) - this.selectedCharsIndices.add(i); - else - this.selectedCharsIndices.remove(i); - - refreshView(); - } - - private void refreshView() { - - this.getHighlighter().removeAllHighlights(); - - Integer start = null; - Integer end = null; - - Iterator<Integer> it = selectedCharsIndices.iterator(); - while (it.hasNext()) { - int idx = it.next(); - if (start == null) { - start = idx; - end = idx; - } else { - if (idx == end + 1) - end = idx; - else { - addHighlight(start, end + 1); - start = idx; - end = idx; - } - } - } - if (start != null && end != null) - addHighlight(start, end + 1); - - selectionChanged(getSelectedIndices()); - } - - private void addHighlight(Integer start, Integer end) { - try { - this.getHighlighter().addHighlight(start, end, this.hlPainter); - } catch (BadLocationException e) { - logger.error("Error highlighting... " + e.getLocalizedMessage()); - } - } - } - - private class UndoAction extends AbstractAction { - - private static final long serialVersionUID = 640721327092571644L; - - public void actionPerformed(ActionEvent e) { - if (undoButton.isEnabled()) { - undo(); - } - } - } -} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTabChangeListener.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTabChangeListener.java deleted file mode 100644 index c0bb108..0000000 --- a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarization/extrsumannotator/main/MyTabChangeListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package pl.waw.ipipan.zil.summarization.extrsumannotator.main; - -import java.util.SortedSet; - -public interface MyTabChangeListener { - - public abstract void fullTextChanged(SortedSet<Integer> selectedCharsIndices); - - public abstract void undo(); - - public abstract void saveStateForUndo(boolean thisTabChanged); - -} \ No newline at end of file diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/basic/Text.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/basic/Text.java new file mode 100644 index 0000000..5336c55 --- /dev/null +++ b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/basic/Text.java @@ -0,0 +1,43 @@ +package pl.waw.ipipan.zil.summarizer.extrsumannotator.basic; + +import java.util.List; +import java.util.SortedSet; + +public class Text { + + private String text = null; + private List<SortedSet<Integer>> summaries; + + public Text(String string, List<SortedSet<Integer>> summaries) { + this.text = string; + this.summaries = summaries; + } + + public String getText() { + return text; + } + + public int getTextWordsCount() { + return getStringWordCount(text); + } + + public static int getStringWordCount(String string) { + return string.split("[ ]+").length; + } + + public void setSummaries(List<SortedSet<Integer>> summaries) { + this.summaries = summaries; + } + + public SortedSet<Integer> getSummary(int number) { + return summaries.get(number); + } + + public List<SortedSet<Integer>> getSummaries() { + return summaries; + } + + public void setSummary(int summNumber, SortedSet<Integer> sum) { + summaries.set(summNumber, sum); + } +} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/io/SummaryFileIO.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/io/SummaryFileIO.java new file mode 100644 index 0000000..3ee5ab3 --- /dev/null +++ b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/io/SummaryFileIO.java @@ -0,0 +1,134 @@ +package pl.waw.ipipan.zil.summarizer.extrsumannotator.io; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.extrsumannotator.basic.Text; +import pl.waw.ipipan.zil.summarizer.extrsumannotator.main.ExtrSumAnnotator; + +public class SummaryFileIO { + + private static final String SUMMARIES = "#### SUMMARIES ####"; + private static final String SUMMARY_START = "#### SUMMARY START ####"; + private static final String SUMMARY_END = "#### SUMMARY END ####"; + + private static final Logger logger = Logger.getLogger(SummaryFileIO.class); + + public static boolean saveSummary(File summaryFile, Text text) { + logger.info("Saving text with summaries in file: " + summaryFile); + BufferedWriter bw = null; + + try { + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(summaryFile), "UTF-8")); + + bw.append(text.getText() + "\n"); + + bw.append(SUMMARIES + "\n"); + + for (SortedSet<Integer> sum : text.getSummaries()) { + bw.append(SUMMARY_START + "\n"); + for (Integer idx : sum) + bw.append(idx + " "); + bw.append("\n"); + bw.append(SUMMARY_END + "\n"); + } + + } catch (IOException e) { + logger.error("Error writing summary: " + e.getLocalizedMessage()); + return false; + } finally { + if (bw != null) + try { + bw.close(); + } catch (IOException e) { + logger.error("Error closing summary file: " + e.getLocalizedMessage()); + return false; + } + } + return true; + } + + public static Text loadText(File input) { + + logger.info("Loading text with summaries from file: " + input); + BufferedReader br = null; + + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8")); + String line = null; + StringBuffer fullText = new StringBuffer(); + List<SortedSet<Integer>> summaries = new ArrayList<SortedSet<Integer>>(); + while ((line = br.readLine()) != null) { + if (line.startsWith(SUMMARIES)) + loadSummaries(br, summaries); + else + fullText.append(line + "\n"); + } + + while (summaries.size() < ExtrSumAnnotator.SUMMARIES_SIZES.length) { + summaries.add(new TreeSet<Integer>()); + } + + Text t = new Text(fullText.toString(), summaries); + return t; + + } catch (IOException e) { + logger.error("Error reading text: " + e.getLocalizedMessage()); + return null; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + logger.error("Error closing text file: " + e.getLocalizedMessage()); + return null; + } + } + } + + private static void loadSummaries(BufferedReader br, List<SortedSet<Integer>> summaries) throws IOException { + SortedSet<Integer> summary = null; + while ((summary = loadSummary(br)) != null) + summaries.add(summary); + } + + private static SortedSet<Integer> loadSummary(BufferedReader br) throws IOException { + SortedSet<Integer> summary = new TreeSet<Integer>(); + + String line = null; + boolean inside = false; + while ((line = br.readLine()) != null) { + if (line.startsWith(SUMMARY_END)) + break; + + if (inside) { + Scanner sc = new Scanner(line); + while (sc.hasNextInt()) + summary.add(sc.nextInt()); + sc.close(); + } + + if (line.startsWith(SUMMARY_START)) + inside = true; + } + + if (summary.size() == 0 && !inside) + return null; + + return summary; + } + +} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/ExtrSumAnnotator.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/ExtrSumAnnotator.java new file mode 100644 index 0000000..3a67534 --- /dev/null +++ b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/ExtrSumAnnotator.java @@ -0,0 +1,383 @@ +package pl.waw.ipipan.zil.summarizer.extrsumannotator.main; + +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.swing.ButtonGroup; +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.filechooser.FileFilter; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.extrsumannotator.basic.Text; +import pl.waw.ipipan.zil.summarizer.extrsumannotator.io.SummaryFileIO; + +public class ExtrSumAnnotator extends JFrame implements Runnable, MyTabChangeListener { + + private static final String WINDOW_TITLE = "ESE v1.0"; + + private static final long serialVersionUID = -3830790411182131318L; + + private static final Logger logger = Logger.getLogger(ExtrSumAnnotator.class); + + private static final int HEIGTH = 600; + private static final int WIDTH = 800; + + public static double[] SUMMARIES_SIZES = new double[] { 0.2, 0.1, 0.05 }; + + private JMenuItem save; + + private File currentFile = null; + private boolean unsavedChanges = false; + + private JTabbedPane tabbedPane; + + private float displayFontSize; + + private Text currentText; + + public static void main(String[] args) { + if (args.length != 0 && args.length != 1) { + logger.error("Wrong usage! Should be: java -jar " + ExtrSumAnnotator.class.getSimpleName() + + " [input file]"); + return; + } + final ExtrSumAnnotator summanno = new ExtrSumAnnotator(); + try { + SwingUtilities.invokeAndWait(summanno); + } catch (Exception e) { + logger.error("Error starting application: " + e.getLocalizedMessage()); + e.printStackTrace(); + return; + } + + if (args.length == 1) { + final File input = new File(args[0]); + if (input.exists()) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + summanno.loadFile(input); + } + }); + } else { + logger.error("Input file: " + input + " doesn't exist!"); + } + } + } + + public void run() { + displayFontSize = loadDisplayFontSize(); + tabbedPane = new JTabbedPane(); + this.getContentPane().add(tabbedPane); + this.setTitle(WINDOW_TITLE); + this.createMenu(); + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new MainWindowListener(this)); + this.setSize(WIDTH, HEIGTH); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation((screenSize.width - WIDTH) / 2, (screenSize.height - HEIGTH) / 2); + this.setVisible(true); + } + + private float loadDisplayFontSize() { + float result = 12f; + logger.info("Using default font size."); + return result; + } + + private void createMenu() { + JMenuBar menu = new JMenuBar(); + this.setJMenuBar(menu); + + JMenu file = new JMenu("File"); + menu.add(file); + + JMenuItem open = new JMenuItem("Open"); + open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); + open.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + requestOpenFile(); + } + }); + file.add(open); + + save = new JMenuItem("Save"); + save.setEnabled(false); + save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); + save.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + requestSaveFile(); + } + }); + file.add(save); + + JMenuItem exit = new JMenuItem("Exit"); + exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); + exit.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + requestExit(); + } + }); + file.add(exit); + + JMenu other = new JMenu("Other"); + + ButtonGroup fontSizeButtonGroup = new ButtonGroup(); + JMenu setFontSize = new JMenu("Change font size"); + for (int z = 8; z < 30; z = z + 2) { + + final int currentFontSize = z; + + JRadioButtonMenuItem temp = new JRadioButtonMenuItem(z + ""); + if (z == displayFontSize) { + temp.setSelected(true); + } + temp.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent ae) { + requestSetFontSize(currentFontSize); + } + }); + fontSizeButtonGroup.add(temp); + setFontSize.add(temp); + } + other.add(setFontSize); + + JMenuItem help = new JMenuItem("Help"); + help.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + requestShowHelp(); + } + }); + other.add(help); + + menu.add(other); + } + + protected void requestSetFontSize(float currentFontSize) { + logger.info("Setting font size: " + currentFontSize); + displayFontSize = currentFontSize; + + Enumeration<Object> enumer = UIManager.getDefaults().keys(); + while (enumer.hasMoreElements()) { + Object key = enumer.nextElement(); + Object value = UIManager.get(key); + if (value instanceof Font) { + UIManager.put(key, new javax.swing.plaf.FontUIResource(((Font) value).deriveFont(currentFontSize))); + } + } + SwingUtilities.updateComponentTreeUI(this); + } + + private final void requestShowHelp() { + JFrame helpFrame = new JFrame("Help"); + helpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JEditorPane editorPane = new JEditorPane(); + editorPane.setEditable(false); + URL helpURL = ExtrSumAnnotator.class.getClassLoader().getResource("help.html"); + if (helpURL != null) { + try { + editorPane.setPage(helpURL); + } catch (IOException e) { + logger.error("Attempted to read a bad URL: " + helpURL); + } + } else { + logger.error("Couldn't find file: help.html"); + } + + // Put the editor pane in a scroll pane. + JScrollPane editorScrollPane = new JScrollPane(editorPane); + editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + editorScrollPane.setPreferredSize(new Dimension(800, 600)); + editorScrollPane.setMinimumSize(new Dimension(30, 30)); + + helpFrame.getContentPane().add(editorScrollPane); + helpFrame.pack(); + helpFrame.setVisible(true); + } + + private void requestSaveFile() { + + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + MyTab tab = (MyTab) tabbedPane.getComponentAt(i); + currentText.setSummary(i, tab.getSelectedIndices()); + } + + boolean success = SummaryFileIO.saveSummary(currentFile, currentText); + + if (success) { + unsavedChanges = false; + setTitle(WINDOW_TITLE); + save.setEnabled(false); + } else { + showError("Error saving file: " + currentFile); + } + } + + private final void requestOpenFile() { + if (!askToSaveChanges()) + return; + + JFileChooser chooser; + if (currentFile == null) + chooser = new JFileChooser(); + else + chooser = new JFileChooser(currentFile.getParentFile()); + + chooser.setFileFilter(new SummannotatorFileFilter()); + int result = chooser.showOpenDialog(this); + + if (result == JFileChooser.APPROVE_OPTION) { + this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + this.loadFile(chooser.getSelectedFile()); + this.setCursor(null); + } + } + + private boolean askToSaveChanges() { + if (!unsavedChanges) + return true; + + int result = JOptionPane.showOptionDialog(this, "Do you want to save changes?", "Unsaved changes", + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); + + if (result == JOptionPane.CANCEL_OPTION) + return false; + + if (result == JOptionPane.YES_OPTION) + requestSaveFile(); + + return true; + } + + private final void requestExit() { + if (!askToSaveChanges()) + return; + + logger.info("Exiting."); + System.exit(0); + } + + private final void loadFile(File input) { + tabbedPane.removeAll(); + + if (!input.exists()) { + String err = "File " + input + " doesn't exist!"; + logger.error(err); + showError(err); + return; + } + + currentText = SummaryFileIO.loadText(input); + + int all = currentText.getTextWordsCount(); + List<MyTab> allTabs = new ArrayList<MyTab>(); + + MyTab firstTab = new MyTab((int) (SUMMARIES_SIZES[0] * all), currentText.getText()); + allTabs.add(firstTab); + + MyTab toListen = firstTab; + for (int i = 1; i < SUMMARIES_SIZES.length; i++) { + MyTab tab = new MyTab((int) (SUMMARIES_SIZES[i] * all), currentText.getText()); + toListen.addChangeListener(tab); + toListen = tab; + allTabs.add(tab); + } + + SortedSet<Integer> fullSelection = new TreeSet<Integer>(); + for (int i = 0; i < currentText.getText().length(); i++) + fullSelection.add(i); + firstTab.fullTextChanged(fullSelection); + + int i = 0; + for (SortedSet<Integer> sum : currentText.getSummaries()) { + allTabs.get(i++).setSummary(sum); + } + + i = 0; + for (MyTab tab : allTabs) { + tab.addChangeListener(this); + tabbedPane.addTab(((int) (SUMMARIES_SIZES[i++] * 100)) + "% summary", tab); + } + + currentFile = input; + } + + private void showError(String string) { + JOptionPane.showMessageDialog(this, string, "Error", JOptionPane.ERROR_MESSAGE); + } + + private final class SummannotatorFileFilter extends FileFilter { + @Override + public String getDescription() { + return "TXT files"; + } + + @Override + public boolean accept(File f) { + return f.getName().endsWith(".txt") || f.isDirectory(); + } + } + + private class MainWindowListener extends WindowAdapter { + + private final ExtrSumAnnotator summanotator; + + public MainWindowListener(ExtrSumAnnotator sumannotator) { + this.summanotator = sumannotator; + } + + @Override + public void windowClosing(WindowEvent we) { + this.summanotator.requestExit(); + } + } + + public void fullTextChanged(SortedSet<Integer> selectedCharsIndices) { + unsavedChanges = true; + save.setEnabled(true); + setTitle(WINDOW_TITLE + " " + "[unsaved changes]"); + } + + public void undo() { + } + + public void saveStateForUndo(boolean thisTabChanged) { + } + +} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTab.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTab.java new file mode 100644 index 0000000..eb92e8b --- /dev/null +++ b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTab.java @@ -0,0 +1,324 @@ +package pl.waw.ipipan.zil.summarizer.extrsumannotator.main; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.swing.AbstractAction; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultHighlighter; +import javax.swing.text.Highlighter.HighlightPainter; + +import org.apache.log4j.Logger; + +import pl.waw.ipipan.zil.summarizer.extrsumannotator.basic.Text; + +public class MyTab extends JSplitPane implements MyTabChangeListener { + + private static final Logger logger = Logger.getLogger(MyTab.class); + + private static final long serialVersionUID = 3656861958564714263L; + + private final JTextToSummarizeArea fullTextPane; + private final JTextArea summaryPane; + + private final JProgressBar pb; + + private final int targetSegmentCount; + private final int allSegmentCount; + + private final Set<MyTabChangeListener> listeners = new HashSet<MyTabChangeListener>(); + + private final String originalText; + + public SortedSet<Integer> previousIndices = null; + + private final JButton undoButton; + + public MyTab(int targetCount, String originalText) { + super(JSplitPane.VERTICAL_SPLIT); + + this.originalText = originalText; + + this.targetSegmentCount = targetCount; + this.allSegmentCount = Text.getStringWordCount(originalText); + + fullTextPane = new JTextToSummarizeArea(); + fullTextPane.setLineWrap(true); + fullTextPane.setEditable(false); + fullTextPane.setWrapStyleWord(true); + fullTextPane.setMargin(new Insets(10, 10, 10, 10)); + + summaryPane = new JTextArea(); + summaryPane.setLineWrap(true); + summaryPane.setEditable(false); + summaryPane.setWrapStyleWord(true); + summaryPane.setMargin(new Insets(10, 10, 10, 10)); + + pb = new JProgressBar(0, targetSegmentCount); + JLabel all = new JLabel("Words in text: " + allSegmentCount); + JLabel summ = new JLabel("Words in summary: " + targetSegmentCount); + + UndoAction undoAction = new UndoAction(); + this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), "undo"); + this.getActionMap().put("undo", undoAction); + undoButton = new JButton(undoAction); + undoButton.setEnabled(false); + undoButton.setText("Undo last action (CTRL+Z)"); + + JPanel bottomLeftPanel = new JPanel(); + bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.Y_AXIS)); + bottomLeftPanel.add(pb); + bottomLeftPanel.add(all); + bottomLeftPanel.add(summ); + bottomLeftPanel.add(Box.createVerticalStrut(8)); + bottomLeftPanel.add(undoButton); + + JPanel bottomPane = new JPanel(new BorderLayout()); + bottomPane.add(new JScrollPane(summaryPane), BorderLayout.CENTER); + bottomPane.add(bottomLeftPanel, BorderLayout.LINE_START); + + this.setTopComponent(new JScrollPane(fullTextPane)); + this.setBottomComponent(bottomPane); + this.setOneTouchExpandable(true); + this.setDividerLocation(350); + } + + public void addChangeListener(MyTabChangeListener tab) { + listeners.add(tab); + } + + public void selectionChanged(SortedSet<Integer> selectedCharsIndices) { + String summ = getTextByIndices(this.originalText, selectedCharsIndices); + int summWC = Text.getStringWordCount(summ); + + pb.setValue(summWC); + pb.setStringPainted(true); + if (targetSegmentCount == 0) + pb.setString(summWC + "/0 = -- %"); + else + pb.setString(summWC + "/" + targetSegmentCount + " = " + (100 * summWC / targetSegmentCount) + "%"); + + summaryPane.setText(summ); + + for (MyTabChangeListener l : listeners) + l.fullTextChanged(selectedCharsIndices); + } + + private String getTextByIndices(String text, SortedSet<Integer> selectedCharsIndices) { + StringBuffer sb = new StringBuffer(); + for (Integer idx : selectedCharsIndices) + sb.append(text.substring(idx, idx + 1)); + String summ = sb.toString(); + return summ; + } + + public void fullTextChanged(SortedSet<Integer> selectedCharsIndices) { + fullTextPane.setOriginalText(selectedCharsIndices); + } + + public SortedSet<Integer> getSelectedIndices() { + return fullTextPane.getSelectedIndices(); + } + + public void setSummary(SortedSet<Integer> sum) { + fullTextPane.setSummary(sum); + } + + public void saveStateForUndo(boolean thisTabChanged) { + logger.debug("Saving state for undo... (tab: " + targetSegmentCount + ")"); + previousIndices = getSelectedIndices(); + logger.debug(previousIndices); + + if (thisTabChanged) + undoButton.setEnabled(true); + else + undoButton.setEnabled(false); + + for (MyTabChangeListener l : listeners) + l.saveStateForUndo(false); + } + + public void undo() { + if (previousIndices != null) { + logger.debug("Undoing... (tab: " + targetSegmentCount + ")"); + logger.debug(previousIndices); + this.undoButton.setEnabled(false); + + try { + this.setSummary(previousIndices); + } catch (Exception ex) { + logger.error("Error undoing... (tab: " + targetSegmentCount + ")"); + } + + previousIndices = null; + for (MyTabChangeListener l : listeners) + l.undo(); + } else { + logger.debug("Nothing to undo... (tab: " + targetSegmentCount + ")"); + } + } + + private class JTextToSummarizeArea extends JTextArea implements CaretListener { + + private static final long serialVersionUID = -8674213151313542475L; + + private SortedSet<Integer> selectedCharsIndices = new TreeSet<Integer>(); + + private final Map<Integer, Integer> mappingOrig2This = new HashMap<Integer, Integer>(); + private final Map<Integer, Integer> mappingThis2Orig = new HashMap<Integer, Integer>(); + + private final Color hlColor = new Color(255, 0, 0, 100); + private final HighlightPainter hlPainter = new DefaultHighlighter.DefaultHighlightPainter(hlColor); + + public JTextToSummarizeArea() { + super(); + this.addCaretListener(this); + } + + public void setSummary(SortedSet<Integer> sum) { + selectedCharsIndices.clear(); + for (Integer idx : sum) + selectedCharsIndices.add(mappingOrig2This.get(idx)); + refreshView(); + } + + public SortedSet<Integer> getSelectedIndices() { + SortedSet<Integer> origSelectedCharsIndices = new TreeSet<Integer>(); + for (Integer i : this.selectedCharsIndices) + origSelectedCharsIndices.add(mappingThis2Orig.get(i)); + + return origSelectedCharsIndices; + } + + public void setOriginalText(SortedSet<Integer> newOriginalTextIndices) { + if (mappingOrig2This != null) { + SortedSet<Integer> newSelectedCharsIndices = new TreeSet<Integer>(); + int i = 0; + for (Integer idx : newOriginalTextIndices) { + Integer oldIdx = mappingOrig2This.get(idx); + if (oldIdx != null && selectedCharsIndices.contains(oldIdx)) + newSelectedCharsIndices.add(i); + i++; + } + selectedCharsIndices = newSelectedCharsIndices; + } + + mappingOrig2This.clear(); + int i = 0; + for (Integer idx : newOriginalTextIndices) + mappingOrig2This.put(idx, i++); + + mappingThis2Orig.clear(); + i = 0; + for (Integer idx : newOriginalTextIndices) + mappingThis2Orig.put(i++, idx); + + String summ = getTextByIndices(originalText, newOriginalTextIndices); + + this.setText(summ); + this.setCaretPosition(0); + refreshView(); + } + + public void caretUpdate(CaretEvent e) { + int dot = e.getDot(); + int mark = e.getMark(); + + if (dot == mark) + return; + + if (dot < mark) { + int tmp = mark; + mark = dot; + dot = tmp; + } + + saveStateForUndo(true); + + boolean allSelected = true; + for (int i = mark; i < dot; i++) + if (!this.selectedCharsIndices.contains(i)) + allSelected = false; + + for (int i = mark; i < dot; i++) + if (!allSelected) + this.selectedCharsIndices.add(i); + else + this.selectedCharsIndices.remove(i); + + refreshView(); + } + + private void refreshView() { + + this.getHighlighter().removeAllHighlights(); + + Integer start = null; + Integer end = null; + + Iterator<Integer> it = selectedCharsIndices.iterator(); + while (it.hasNext()) { + int idx = it.next(); + if (start == null) { + start = idx; + end = idx; + } else { + if (idx == end + 1) + end = idx; + else { + addHighlight(start, end + 1); + start = idx; + end = idx; + } + } + } + if (start != null && end != null) + addHighlight(start, end + 1); + + selectionChanged(getSelectedIndices()); + } + + private void addHighlight(Integer start, Integer end) { + try { + this.getHighlighter().addHighlight(start, end, this.hlPainter); + } catch (BadLocationException e) { + logger.error("Error highlighting... " + e.getLocalizedMessage()); + } + } + } + + private class UndoAction extends AbstractAction { + + private static final long serialVersionUID = 640721327092571644L; + + public void actionPerformed(ActionEvent e) { + if (undoButton.isEnabled()) { + undo(); + } + } + } +} diff --git a/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTabChangeListener.java b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTabChangeListener.java new file mode 100644 index 0000000..6e5f031 --- /dev/null +++ b/ExtrSumAnnotator/src/main/java/pl/waw/ipipan/zil/summarizer/extrsumannotator/main/MyTabChangeListener.java @@ -0,0 +1,13 @@ +package pl.waw.ipipan.zil.summarizer.extrsumannotator.main; + +import java.util.SortedSet; + +public interface MyTabChangeListener { + + public abstract void fullTextChanged(SortedSet<Integer> selectedCharsIndices); + + public abstract void undo(); + + public abstract void saveStateForUndo(boolean thisTabChanged); + +} \ No newline at end of file diff --git a/ExtrSumAnnotator/src/main/resources/log4j.properties b/ExtrSumAnnotator/src/main/resources/log4j.properties new file mode 100644 index 0000000..6d8f00a --- /dev/null +++ b/ExtrSumAnnotator/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=[%p] [%C{1}] %m%n + +log4j.logger.pl.waw.ipipan.zil=INFO, stderr \ No newline at end of file -- libgit2 0.22.2