From 4eedba319ee61cc41a08c3851b9f95882c86bb43 Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Wed, 17 May 2017 19:48:28 -0300 Subject: [PATCH 1/6] Avoid unnecessary return statements --- .../fake/fakeqa/src/lucida/thrift/LucidaService.java | 1 - lucida/calendar/CalendarClient/CalendarClient.java | 12 +++++------- .../atype/extractor/EnglishFeatureExtractor.java | 11 +++++------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java index 9aa9d1adf..447a03205 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java @@ -94,7 +94,6 @@ public void recv_create() throws org.apache.thrift.TException { create_result result = new create_result(); receiveBase(result, "create"); - return; } public void learn(String LUCID, QuerySpec knowledge) throws org.apache.thrift.TException diff --git a/lucida/calendar/CalendarClient/CalendarClient.java b/lucida/calendar/CalendarClient/CalendarClient.java index fbe4ac5dd..4220caf93 100755 --- a/lucida/calendar/CalendarClient/CalendarClient.java +++ b/lucida/calendar/CalendarClient/CalendarClient.java @@ -5,7 +5,7 @@ import java.util.ArrayList; import java.util.Properties; -//Thrift java libraries +//Thrift java libraries import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -16,9 +16,9 @@ //Generated code import thrift.*; -/** -* A Calendar Client that get the upcoming events from Calendar Server and prints the results. -*/ +/** + * A Calendar Client that get the upcoming events from Calendar Server and prints the results. + */ public class CalendarClient { public static void main(String [] args) throws IOException { @@ -44,7 +44,7 @@ public static void main(String [] args) QuerySpec query_spec = new QuerySpec(); query_spec.content = new ArrayList(); query_spec.content.add(query_input); - + // Initialize thrift objects. // TTransport transport = new TSocket("clarity08.eecs.umich.edu", port); TTransport transport = new TSocket("localhost", port); @@ -62,7 +62,5 @@ public static void main(String [] args) } catch (TException e) { e.printStackTrace(); } - - return; } } diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/extractor/EnglishFeatureExtractor.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/extractor/EnglishFeatureExtractor.java index 3893a3cbe..31724eb45 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/extractor/EnglishFeatureExtractor.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/extractor/EnglishFeatureExtractor.java @@ -182,21 +182,20 @@ private static void addSyntacticFeatures(MutableInstance instance, List te } } } - + // FOCUS_ADJ Tree focusNode = TreeHelper.findFirstPreterminalWithPrecedingPreterminal(tree, "RB|JJ", "WRB"); - if (focusNode != null) + if (focusNode != null) instance.addBinary(new Feature("FOCUS_ADJ"+"."+focusNode.getHeadWord())); - + } - + private static void addSemanticFeatures(MutableInstance instance, Term focusTerm) { // FOCUS_TYPE String focusType = WordNetAnswerTypeMapping.getAnswerType(focusTerm); - if (focusType == null) + if (focusType == null) focusType = "-"; instance.addBinary(new Feature("FOCUS_TYPE"+"."+focusType)); - return; } /** From 99cb896a23d7ce56d0a4cf31a6e94508317c500c Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Wed, 17 May 2017 20:05:43 -0300 Subject: [PATCH 2/6] Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals(). --- .../OpenEphyra/src/info/ephyra/nlp/indices/IrregularVerbs.java | 2 +- .../src/info/ephyra/questionanalysis/atype/FocusFinder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/indices/IrregularVerbs.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/indices/IrregularVerbs.java index b937f6bc7..078b37413 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/indices/IrregularVerbs.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/indices/IrregularVerbs.java @@ -36,7 +36,7 @@ private static boolean matches(String word, String words) { String[] list = words.split("/"); for (String elem : list) - if (elem.toLowerCase().equals(word.toLowerCase())) return true; + if (elem.equalsIgnoreCase(word)) return true; return false; } diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/FocusFinder.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/FocusFinder.java index 682403409..a8cc97783 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/FocusFinder.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/questionanalysis/atype/FocusFinder.java @@ -175,7 +175,7 @@ public static Tree findFocusNode (Tree tree) { nodes = new ArrayList(); for (ListIterator it = tags.listIterator(); it.hasNext();) { Tree tag = it.next(); - if (tag.getHeadWord().toLowerCase().equals("how") && + if (tag.getHeadWord().equalsIgnoreCase("how") && it.next().getHeadWord().toLowerCase().matches("many|much")) { for (ListIterator it2 = tags.listIterator(it.nextIndex()); it2.hasNext() && it2.next().getLabel().matches("NN.?");) { From f8aafc755443bce69fb09ff936057369e8a0cda9 Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Wed, 17 May 2017 20:38:02 -0300 Subject: [PATCH 3/6] Avoid unused imports --- .../src/lucida/handler/QAServiceHandler.java | 4 -- .../fake/fakeqa/src/lucida/main/QADaemon.java | 7 --- .../src/lucida/thrift/LucidaService.java | 6 --- .../fakeqa/src/lucida/thrift/QueryInput.java | 25 ++++----- .../fakeqa/src/lucida/thrift/QuerySpec.java | 27 ++++------ .../main/java/calendar/CAServiceHandler.java | 4 -- .../main/java/calendar/CalendarDaemon.java | 11 ---- .../src/main/java/calendar/TextProcessor.java | 1 - .../src/info/ephyra/OpenEphyra.java | 4 +- .../src/info/ephyra/OpenEphyraServer.java | 2 - .../ephyra/answerselection/AnswerPattern.java | 8 +-- .../filters/AnswerPatternFilter.java | 4 +- .../src/info/ephyra/nlp/NETagger.java | 6 +-- .../src/info/ephyra/nlp/StanfordNeTagger.java | 9 ++-- .../src/lucida/handler/QAServiceHandler.java | 2 - .../OpenEphyra/src/lucida/main/QADaemon.java | 53 +++++++++---------- 16 files changed, 57 insertions(+), 116 deletions(-) diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/handler/QAServiceHandler.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/handler/QAServiceHandler.java index 75f980795..6e53df50e 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/handler/QAServiceHandler.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/handler/QAServiceHandler.java @@ -1,9 +1,5 @@ package lucida.handler; -// Java packages -import java.util.List; -import java.util.ArrayList; - import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/main/QADaemon.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/main/QADaemon.java index d0469b0aa..e20a210f3 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/main/QADaemon.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/main/QADaemon.java @@ -1,20 +1,13 @@ package lucida.main; import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.ArrayList; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.server.TNonblockingServer; -import org.apache.thrift.server.TServer; -import org.apache.thrift.server.TThreadedSelectorServer; import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TNonblockingServerSocket; import org.apache.thrift.transport.TNonblockingServerTransport; import org.apache.thrift.transport.TTransportException; -import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java index 447a03205..36feb4870 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java @@ -11,8 +11,6 @@ import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; -import org.apache.thrift.protocol.TProtocolException; -import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.server.AbstractNonblockingServer.*; @@ -21,13 +19,9 @@ import java.util.Map; import java.util.HashMap; import java.util.EnumMap; -import java.util.Set; -import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; -import java.nio.ByteBuffer; -import java.util.Arrays; import javax.annotation.Generated; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java index d61281fea..ccef3adfd 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java @@ -11,7 +11,6 @@ import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; -import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; @@ -21,16 +20,10 @@ import java.util.Map; import java.util.HashMap; import java.util.EnumMap; -import java.util.Set; -import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; -import java.nio.ByteBuffer; -import java.util.Arrays; import javax.annotation.Generated; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) @Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-5-2") @@ -445,11 +438,11 @@ public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot) throws TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot) throws TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @@ -487,7 +480,7 @@ public String toString() { return sb.toString(); } - public void validate() throws org.apache.thrift.TException { + public void validate() throws TException { // check for required fields // check for sub-struct validity } @@ -495,7 +488,7 @@ public void validate() throws org.apache.thrift.TException { private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { + } catch (TException te) { throw new java.io.IOException(te); } } @@ -503,7 +496,7 @@ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOExcept private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { + } catch (TException te) { throw new java.io.IOException(te); } } @@ -516,7 +509,7 @@ public QueryInputStandardScheme getScheme() { private static class QueryInputStandardScheme extends StandardScheme { - public void read(org.apache.thrift.protocol.TProtocol iprot, QueryInput struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot, QueryInput struct) throws TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) @@ -581,7 +574,7 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, QueryInput struct) struct.validate(); } - public void write(org.apache.thrift.protocol.TProtocol oprot, QueryInput struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot, QueryInput struct) throws TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); @@ -631,7 +624,7 @@ public QueryInputTupleScheme getScheme() { private static class QueryInputTupleScheme extends TupleScheme { @Override - public void write(org.apache.thrift.protocol.TProtocol prot, QueryInput struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol prot, QueryInput struct) throws TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetType()) { @@ -668,7 +661,7 @@ public void write(org.apache.thrift.protocol.TProtocol prot, QueryInput struct) } @Override - public void read(org.apache.thrift.protocol.TProtocol prot, QueryInput struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol prot, QueryInput struct) throws TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(3); if (incoming.get(0)) { diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QuerySpec.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QuerySpec.java index 0eac263f4..71230e0b1 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QuerySpec.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QuerySpec.java @@ -11,26 +11,17 @@ import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; -import org.apache.thrift.protocol.TProtocolException; -import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; -import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.server.AbstractNonblockingServer.*; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.EnumMap; -import java.util.Set; -import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; -import java.nio.ByteBuffer; -import java.util.Arrays; import javax.annotation.Generated; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) @Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-5-2") @@ -357,11 +348,11 @@ public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot) throws TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot) throws TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @@ -391,7 +382,7 @@ public String toString() { return sb.toString(); } - public void validate() throws org.apache.thrift.TException { + public void validate() throws TException { // check for required fields // check for sub-struct validity } @@ -399,7 +390,7 @@ public void validate() throws org.apache.thrift.TException { private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { + } catch (TException te) { throw new java.io.IOException(te); } } @@ -407,7 +398,7 @@ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOExcept private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { + } catch (TException te) { throw new java.io.IOException(te); } } @@ -420,7 +411,7 @@ public QuerySpecStandardScheme getScheme() { private static class QuerySpecStandardScheme extends StandardScheme { - public void read(org.apache.thrift.protocol.TProtocol iprot, QuerySpec struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot, QuerySpec struct) throws TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) @@ -468,7 +459,7 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, QuerySpec struct) t struct.validate(); } - public void write(org.apache.thrift.protocol.TProtocol oprot, QuerySpec struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot, QuerySpec struct) throws TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); @@ -506,7 +497,7 @@ public QuerySpecTupleScheme getScheme() { private static class QuerySpecTupleScheme extends TupleScheme { @Override - public void write(org.apache.thrift.protocol.TProtocol prot, QuerySpec struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol prot, QuerySpec struct) throws TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetName()) { @@ -531,7 +522,7 @@ public void write(org.apache.thrift.protocol.TProtocol prot, QuerySpec struct) t } @Override - public void read(org.apache.thrift.protocol.TProtocol prot, QuerySpec struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol prot, QuerySpec struct) throws TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { diff --git a/lucida/calendar/src/main/java/calendar/CAServiceHandler.java b/lucida/calendar/src/main/java/calendar/CAServiceHandler.java index 0ccd60378..6d85c7a2e 100644 --- a/lucida/calendar/src/main/java/calendar/CAServiceHandler.java +++ b/lucida/calendar/src/main/java/calendar/CAServiceHandler.java @@ -1,9 +1,5 @@ package calendar; -import java.util.List; -import java.io.File; -import java.util.ArrayList; - import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; diff --git a/lucida/calendar/src/main/java/calendar/CalendarDaemon.java b/lucida/calendar/src/main/java/calendar/CalendarDaemon.java index f16b8d892..facce0fdc 100644 --- a/lucida/calendar/src/main/java/calendar/CalendarDaemon.java +++ b/lucida/calendar/src/main/java/calendar/CalendarDaemon.java @@ -3,28 +3,17 @@ import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.ArrayList; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; import java.util.Properties; import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.server.TNonblockingServer; -import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadedSelectorServer; import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TNonblockingServerSocket; import org.apache.thrift.transport.TNonblockingServerTransport; import org.apache.thrift.transport.TTransportException; -import org.apache.thrift.async.AsyncMethodCallback; -import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TFramedTransport; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; import thrift.*; diff --git a/lucida/calendar/src/main/java/calendar/TextProcessor.java b/lucida/calendar/src/main/java/calendar/TextProcessor.java index 4e62ea491..85ee4382b 100644 --- a/lucida/calendar/src/main/java/calendar/TextProcessor.java +++ b/lucida/calendar/src/main/java/calendar/TextProcessor.java @@ -17,7 +17,6 @@ import java.util.Calendar; import java.text.SimpleDateFormat; -import calendar.CAServiceHandler; import edu.stanford.nlp.ling.CoreAnnotations; import edu.stanford.nlp.pipeline.*; import edu.stanford.nlp.time.*; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java index a2c43cc18..0f70b359b 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java @@ -13,7 +13,7 @@ import info.ephyra.answerselection.filters.ScoreSorterFilter; import info.ephyra.answerselection.filters.StopwordFilter; import info.ephyra.answerselection.filters.TruncationFilter; -import info.ephyra.answerselection.filters.WebDocumentFetcherFilter; +//import info.ephyra.answerselection.filters.WebDocumentFetcherFilter; import info.ephyra.io.Logger; import info.ephyra.io.MsgPrinter; import info.ephyra.nlp.LingPipe; @@ -41,7 +41,7 @@ import info.ephyra.questionanalysis.QuestionNormalizer; import info.ephyra.search.Result; import info.ephyra.search.Search; -import info.ephyra.search.searchers.BingKM; +//import info.ephyra.search.searchers.BingKM; import info.ephyra.search.searchers.IndriKM; import java.util.ArrayList; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyraServer.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyraServer.java index db33691b3..36c15cd3e 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyraServer.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyraServer.java @@ -13,7 +13,6 @@ import info.ephyra.answerselection.filters.ScoreSorterFilter; import info.ephyra.answerselection.filters.StopwordFilter; import info.ephyra.answerselection.filters.TruncationFilter; -import info.ephyra.answerselection.filters.WebDocumentFetcherFilter; import info.ephyra.io.Logger; import info.ephyra.io.MsgPrinter; import info.ephyra.nlp.LingPipe; @@ -42,7 +41,6 @@ import info.ephyra.search.Result; import info.ephyra.search.Search; import info.ephyra.search.searchers.IndriKM; -import info.ephyra.search.searchers.IndriDocumentKM; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java index b07efbfd3..d62ea8c19 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java @@ -1,9 +1,9 @@ package info.ephyra.answerselection; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.PrintWriter; +//import java.io.File; +//import java.io.FileNotFoundException; +//import java.io.FileOutputStream; +//import java.io.PrintWriter; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java index b7f62d63d..3bc7fdc99 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java @@ -12,8 +12,8 @@ import info.ephyra.util.StringUtils; import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; +// import java.io.FileNotFoundException; +// import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java index 526e2dff8..c65d1e274 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java @@ -7,11 +7,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; +// import java.io.FileNotFoundException; +// import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; -import java.io.PrintWriter; +// import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java index 09cdfedd9..24ba32f0e 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java @@ -7,11 +7,10 @@ import edu.stanford.nlp.ie.AbstractSequenceClassifier; import edu.stanford.nlp.ie.crf.CRFClassifier; -import info.ephyra.util.StringUtils; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.PrintWriter; +// import java.io.File; +// import java.io.FileNotFoundException; +// import java.io.FileOutputStream; +// import java.io.PrintWriter; /** * Wrapper for the Stanford named entity recognizer. diff --git a/lucida/questionanswering/OpenEphyra/src/lucida/handler/QAServiceHandler.java b/lucida/questionanswering/OpenEphyra/src/lucida/handler/QAServiceHandler.java index ecd9dadf2..367aba0f5 100644 --- a/lucida/questionanswering/OpenEphyra/src/lucida/handler/QAServiceHandler.java +++ b/lucida/questionanswering/OpenEphyra/src/lucida/handler/QAServiceHandler.java @@ -6,9 +6,7 @@ import info.ephyra.io.MsgPrinter; // Java packages -import java.util.List; import java.io.File; -import java.util.ArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; diff --git a/lucida/questionanswering/OpenEphyra/src/lucida/main/QADaemon.java b/lucida/questionanswering/OpenEphyra/src/lucida/main/QADaemon.java index 21681525a..d60da1d69 100644 --- a/lucida/questionanswering/OpenEphyra/src/lucida/main/QADaemon.java +++ b/lucida/questionanswering/OpenEphyra/src/lucida/main/QADaemon.java @@ -1,26 +1,21 @@ package lucida.main; // Thrift java libraries -import org.apache.thrift.server.TNonblockingServer; + import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TNonblockingServerSocket; import org.apache.thrift.transport.TNonblockingServerTransport; import org.apache.thrift.server.TThreadedSelectorServer; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; import java.io.IOException; import java.io.FileInputStream; import java.io.InputStream; -import java.util.ArrayList; import java.util.Properties; -import org.apache.thrift.TException; import org.apache.thrift.TProcessor; // Thrift client-side code for registering w/ sirius import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; // Generated code import lucida.thrift.*; @@ -33,27 +28,27 @@ * Starts the question-answer server and listens for requests. */ public class QADaemon { - /** - * Entry point for question-answer. - * @param args the argument list. Provide port numbers - * for both sirius and qa. - */ - public static void main(String [] args) - throws TTransportException, IOException, InterruptedException { - Properties port_cfg = new Properties(); - InputStream input = new FileInputStream("../../config.properties"); - port_cfg.load(input); - String port_str = port_cfg.getProperty("QA_PORT"); - Integer port = Integer.valueOf(port_str); - TProcessor proc = new LucidaService.AsyncProcessor( - new QAServiceHandler.AsyncQAServiceHandler()); - TNonblockingServerTransport transport = new TNonblockingServerSocket(port); - TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) - .processor(proc) - .protocolFactory(new TBinaryProtocol.Factory()) - .transportFactory(new TFramedTransport.Factory()); - final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); - System.out.println("QA at port " + port_str); - server.serve(); - } + /** + * Entry point for question-answer. + * + * @param args the argument list. Provide port numbers + * for both Lucida and QA. + */ + public static void main(String[] args) + throws TTransportException, IOException, InterruptedException { + Properties port_cfg = new Properties(); + InputStream input = new FileInputStream("../../config.properties"); + port_cfg.load(input); + String port_str = port_cfg.getProperty("QA_PORT"); + Integer port = Integer.valueOf(port_str); + TProcessor proc = new LucidaService.AsyncProcessor(new QAServiceHandler.AsyncQAServiceHandler()); + TNonblockingServerTransport transport = new TNonblockingServerSocket(port); + TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) + .processor(proc) + .protocolFactory(new TBinaryProtocol.Factory()) + .transportFactory(new TFramedTransport.Factory()); + final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); + System.out.println("QA at port " + port_str); + server.serve(); + } } From b7edc60af4b59274356ba1da76f591d3a5f5941e Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Wed, 17 May 2017 23:00:10 -0300 Subject: [PATCH 4/6] Avoid unnecessary return statements --- .../asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java index 36feb4870..d3ecc8c06 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/LucidaService.java @@ -108,7 +108,6 @@ public void recv_learn() throws org.apache.thrift.TException { learn_result result = new learn_result(); receiveBase(result, "learn"); - return; } public String infer(String LUCID, QuerySpec query) throws org.apache.thrift.TException From e9afe1dfa7060a6a39ccbee05923f9fc9f91c67c Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Wed, 17 May 2017 23:02:33 -0300 Subject: [PATCH 5/6] Avoid unused imports --- .../asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java index ccef3adfd..95c0852ec 100644 --- a/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java +++ b/lucida/asyncthrift/fake/fakeqa/src/lucida/thrift/QueryInput.java @@ -11,9 +11,7 @@ import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; -import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; -import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.server.AbstractNonblockingServer.*; import java.util.List; import java.util.ArrayList; From cc9566d604777f4009fb3f40bc796b934f121b22 Mon Sep 17 00:00:00 2001 From: Cassio Santos Date: Thu, 8 Jun 2017 18:44:46 -0300 Subject: [PATCH 6/6] Remove comments --- .../src/info/ephyra/OpenEphyra.java | 6 ----- .../ephyra/answerselection/AnswerPattern.java | 16 ------------- .../filters/AnswerPatternFilter.java | 24 ++----------------- .../src/info/ephyra/nlp/NETagger.java | 14 ----------- .../src/info/ephyra/nlp/StanfordNeTagger.java | 14 ----------- 5 files changed, 2 insertions(+), 72 deletions(-) diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java index 0f70b359b..0b37d7e59 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/OpenEphyra.java @@ -13,7 +13,6 @@ import info.ephyra.answerselection.filters.ScoreSorterFilter; import info.ephyra.answerselection.filters.StopwordFilter; import info.ephyra.answerselection.filters.TruncationFilter; -//import info.ephyra.answerselection.filters.WebDocumentFetcherFilter; import info.ephyra.io.Logger; import info.ephyra.io.MsgPrinter; import info.ephyra.nlp.LingPipe; @@ -41,7 +40,6 @@ import info.ephyra.questionanalysis.QuestionNormalizer; import info.ephyra.search.Result; import info.ephyra.search.Search; -//import info.ephyra.search.searchers.BingKM; import info.ephyra.search.searchers.IndriKM; import java.util.ArrayList; @@ -274,9 +272,6 @@ protected void initFactoid() { // search // - knowledge miners for unstructured knowledge sources Search.clearKnowledgeMiners(); -// Search.addKnowledgeMiner(new BingKM()); -// Search.addKnowledgeMiner(new GoogleKM()); -// Search.addKnowledgeMiner(new YahooKM()); for (String[] indriIndices : IndriKM.getIndriIndices()) Search.addKnowledgeMiner(new IndriKM(indriIndices, false)); // for (String[] indriServers : IndriKM.getIndriServers()) @@ -290,7 +285,6 @@ protected void initFactoid() { // - answer extraction filters AnswerSelection.addFilter(new AnswerTypeFilter()); AnswerSelection.addFilter(new AnswerPatternFilter()); - //AnswerSelection.addFilter(new WebDocumentFetcherFilter()); AnswerSelection.addFilter(new PredicateExtractionFilter()); AnswerSelection.addFilter(new FactoidsFromPredicatesFilter()); AnswerSelection.addFilter(new TruncationFilter()); diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java index d62ea8c19..4eff00495 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/AnswerPattern.java @@ -1,9 +1,5 @@ package info.ephyra.answerselection; -//import java.io.File; -//import java.io.FileNotFoundException; -//import java.io.FileOutputStream; -//import java.io.PrintWriter; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -364,16 +360,6 @@ public String[] getPropertyTypes() { * not match the pattern */ public String[] apply(String sentence) { - - /*PrintWriter pw = null; - try { - pw = new PrintWriter(new FileOutputStream(new File("regex_data.txt"),true)); - } catch (FileNotFoundException ex) { - System.out.println("File not found exception!!"); - }*/ - - // pw.printf("%s ----- %s\n", pattern.pattern(), sentence); - Matcher m = pattern.matcher(sentence); ArrayList results = new ArrayList(); @@ -387,8 +373,6 @@ public String[] apply(String sentence) { m.region(m.start() + 1, sentence.length()); } - // pw.close(); - return results.toArray(new String[results.size()]); } } diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java index 3bc7fdc99..0e0bd60cf 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/answerselection/filters/AnswerPatternFilter.java @@ -12,8 +12,6 @@ import info.ephyra.util.StringUtils; import java.io.BufferedReader; import java.io.File; -// import java.io.FileNotFoundException; -// import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; @@ -284,26 +282,10 @@ private static void extractPos(Result result) { tokens[i] = NETagger.tokenize(originalSentences[i]); sentences[i] = StringUtils.concatWithSpaces(tokens[i]); } - - /* PrintWriter pw = null; - try { - pw = new PrintWriter(new FileOutputStream(new File("netagger_data.txt"),true)); - } catch (FileNotFoundException ex) { - System.out.println("File not found exception!!"); - }*/ - + // extract named entities String[][][] nes = NETagger.extractNes(tokens); - - // pw.printf("%s ----- %s\n", tokens.toString(), nes.toString()); - - /*PrintWriter pw2 = null; - try { - pw2 = new PrintWriter(new FileOutputStream(new File("regex_data.txt"),true)); - } catch (FileNotFoundException ex) { - System.out.println("File not found exception!!"); - }*/ - + for (int i = 0; i < sentences.length; i++) { // prepare sentence for answer extraction sentences[i] = prepSentence(sentences[i], to, cos, nes[i]); @@ -336,8 +318,6 @@ private static void extractPos(Result result) { } } } - // pw.close(); - // pw2.close(); } /** diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java index c65d1e274..ddb77678f 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/NETagger.java @@ -7,11 +7,8 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; -// import java.io.FileNotFoundException; -// import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; -// import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -847,26 +844,15 @@ public static String[][][] extractNes(String[][] sentences) { nes[s][finders.length + allPatternNames.length + i] = neList.toArray(new String[neList.size()]); } - - /* PrintWriter pw = null; - try { - pw = new PrintWriter(new FileOutputStream(new File("StanfordNeTagger_data.txt"),true)); - } catch (FileNotFoundException ex) { - System.out.println("File not found exception!!"); - }*/ // apply stanford tagger HashMap allStanfordNEs = StanfordNeTagger.extractNEs(StringUtils.concatWithSpaces(sentences[s])); - //pw.printf("%s\n", StringUtils.concatWithSpaces(sentences[s])); - // pw.printf("%s ----- %s\n", StringUtils.concatWithSpaces(sentences[s]), nes.toString()); - for (int i = 0; i < stanfordNames.length; i++) { String[] stanfordNEs = allStanfordNEs.get(stanfordNames[i]); if (stanfordNEs == null) stanfordNEs = new String[0]; nes[s][finders.length + allPatternNames.length + lists.length + i] = stanfordNEs; } - //pw.close(); } return nes; diff --git a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java index 24ba32f0e..5d065ec05 100644 --- a/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java +++ b/lucida/questionanswering/OpenEphyra/src/info/ephyra/nlp/StanfordNeTagger.java @@ -7,10 +7,6 @@ import edu.stanford.nlp.ie.AbstractSequenceClassifier; import edu.stanford.nlp.ie.crf.CRFClassifier; -// import java.io.File; -// import java.io.FileNotFoundException; -// import java.io.FileOutputStream; -// import java.io.PrintWriter; /** * Wrapper for the Stanford named entity recognizer. @@ -108,13 +104,6 @@ public static HashMap extractNEs(String sentence) { sentence.matches("\\W*+")) return new HashMap(); - /* PrintWriter pw = null; - try { - pw = new PrintWriter(new FileOutputStream(new File("StanfordNeTagger_data.txt"),true)); - } catch (FileNotFoundException ex) { - System.out.println("File not found exception!!"); - }*/ - String neString = ""; try { neString = classifier.testString(sentence); @@ -126,9 +115,6 @@ public static HashMap extractNEs(String sentence) { MsgPrinter.printErrorMsg(e.toString()); } - //pw.printf("%s ----- %s\n", sentence, neString); - //pw.close(); - String[] neTokens = neString.split("\\s"); String mark = "O"; String ne = "";