Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalgupta authored and Stanford NLP committed Aug 18, 2015
1 parent 3e73356 commit 1071d28
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/edu/stanford/nlp/patterns/SPIEDServlet.java
Expand Up @@ -98,7 +98,7 @@ public static String quote(String string) {
* @param out The writer to write the output to. * @param out The writer to write the output to.
* @param q The query string. * @param q The query string.
*/ */
private void run(PrintWriter out, String q, String seedWords, boolean test, String model) throws Exception{ private void run(PrintWriter out, String q, String seedWords, boolean testmode, String model) throws Exception{
// Clean the string a bit // Clean the string a bit
q = q.trim(); q = q.trim();
if (q.length() == 0) { if (q.length() == 0) {
Expand All @@ -116,8 +116,9 @@ private void run(PrintWriter out, String q, String seedWords, boolean test, Stri
annotate.processText(jsonObject, false, false); annotate.processText(jsonObject, false, false);


String suggestions; String suggestions;
logger.info("Testmode is " + testmode);
// Collect results // Collect results
if(test) if(testmode)
suggestions = annotate.suggestPhrasesTest(); suggestions = annotate.suggestPhrasesTest();
else else
suggestions = annotate.suggestPhrases(); suggestions = annotate.suggestPhrases();
Expand All @@ -140,12 +141,15 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
try { try {
String raw = request.getParameter("q"); String raw = request.getParameter("q");
String seedwords = request.getParameter("seedwords"); String seedwords = request.getParameter("seedwords");
boolean testmode = Boolean.parseBoolean(request.getParameter("testmode")); String test = request.getParameter("testmode");
String model = request.getParameter("model"); boolean testmode = false;
if(test != null)
testmode = Boolean.parseBoolean(test);
//String model = request.getParameter("model");
if (raw == null || "".equals(raw)) { if (raw == null || "".equals(raw)) {
out.print("{\"okay\":false,\"reason\":\"No data provided\"}"); out.print("{\"okay\":false,\"reason\":\"No data provided\"}");
} else { } else {
run(out, raw, seedwords, testmode, model); run(out, raw, seedwords, testmode, "");
} }
} catch (Throwable t) { } catch (Throwable t) {
writeError(t, out, request.toString()); writeError(t, out, request.toString());
Expand Down
17 changes: 15 additions & 2 deletions src/edu/stanford/nlp/patterns/TextAnnotationPatterns.java
Expand Up @@ -9,12 +9,14 @@


import javax.json.*; import javax.json.*;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;


/** /**
* Created by sonalg on 3/10/15. * Created by sonalg on 3/10/15.
Expand All @@ -29,6 +31,16 @@ public class TextAnnotationPatterns {
Map<String, Set<CandidatePhrase>> seedWords = new HashMap<String, Set<CandidatePhrase>>(); Map<String, Set<CandidatePhrase>> seedWords = new HashMap<String, Set<CandidatePhrase>>();
private String backgroundSymbol ="O"; private String backgroundSymbol ="O";


Properties testProps = new Properties();
Logger logger = Logger.getAnonymousLogger();

public TextAnnotationPatterns(){
try{
testProps.load(new FileReader("test.properties"));
}catch(IOException e){
logger.info("COULD NOT LOAD FILE test.properties");
}
}


public String getAllAnnotations() { public String getAllAnnotations() {
JsonObjectBuilder obj = Json.createObjectBuilder(); JsonObjectBuilder obj = Json.createObjectBuilder();
Expand Down Expand Up @@ -85,8 +97,9 @@ public String suggestPhrases() throws IOException, ClassNotFoundException, Illeg
} }


public String suggestPhrasesTest() throws IllegalAccessException, InterruptedException, ExecutionException, IOException, InstantiationException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException { public String suggestPhrasesTest() throws IllegalAccessException, InterruptedException, ExecutionException, IOException, InstantiationException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
GetPatternsFromDataMultiClass<SurfacePattern> model = new GetPatternsFromDataMultiClass<SurfacePattern>(props, Data.sents, seedWords, false, machineAnswerClasses); Properties runProps = new Properties(props);
model.constVars.numIterationsForPatterns = 2; runProps.putAll(testProps);
GetPatternsFromDataMultiClass<SurfacePattern> model = new GetPatternsFromDataMultiClass<SurfacePattern>(runProps, Data.sents, seedWords, false, machineAnswerClasses);
model.iterateExtractApply(); model.iterateExtractApply();
return model.constVars.getLearnedWordsAsJsonLastIteration(); return model.constVars.getLearnedWordsAsJsonLastIteration();
} }
Expand Down
3 changes: 2 additions & 1 deletion src/edu/stanford/nlp/patterns/demo/frontend/index.html
Expand Up @@ -31,7 +31,8 @@
<input id="seedwords" type="text" name="seedwords" class="form-control input-lg" <input id="seedwords" type="text" name="seedwords" class="form-control input-lg"
placeholder="seed words should be written here delimited by comma" placeholder="seed words should be written here delimited by comma"
autofocus="true"autocomplete="off" /> autofocus="true"autocomplete="off" />
<div id="query-button" class="input-group-addon" title="Run"><span class="glyphicon glyphicon-search"></span></div> <input id="testmode" type="text" name="testmode" class="form-control input-lg" placeholder="true or false" autofocus="true" autocomplete="true" />
<div id="query-button" class="input-group-addon" title="Run"><span class="glyphicon glyphicon-search"></span></div>
</div> </div>
</form> </form>
</div> </div>
Expand Down

0 comments on commit 1071d28

Please sign in to comment.