public synchronized void process(JCas jcas) throws AnalysisEngineProcessException { JCas questionView; try { questionView = jcas; } catch (Exception e) { throw new AnalysisEngineProcessException(e); } QuestionInfo qi = JCasUtil.selectSingle(questionView, QuestionInfo.class); /*{"qId": "...", "sv": "...", "LAT" : [ {...}, {...}, {...}]} */ String line = "{\"qId\": " + "\"" + qi.getQuestionId() + "\"" + ", " + "\"SV\": "; String SVtmp = "["; for (Iterator SVIterator = JCasUtil.select(jcas, SV.class).iterator(); SVIterator.hasNext(); ) { SV sv = (SV) SVIterator.next(); SVtmp += "\"" + sv.getCoveredText() + "\""; if (SVIterator.hasNext()) { SVtmp += ", "; } } SVtmp += "], "; line += SVtmp; line += "\"LAT\": "; String LATtmp = "["; for (Iterator iterator = JCasUtil.select(jcas, LAT.class).iterator(); iterator.hasNext(); ) { LAT l = (LAT) iterator.next(); /*{"synset" : "...", "text" : "...", "specificity" : "..." "type" : "..."}*/ LATtmp += "{"; if (l.getSynset() != 0) { // only add synset when it is not zero LATtmp += "\"synset\": " + "\"" + l.getSynset() + "\", "; } // add the rest LATtmp += "\"text\": \"" + l.getText() + "\"," + " \"specificity\": \"" + l.getSpecificity() + "\", " + "\"type\": " + "\"" + l.getClass().getSimpleName() + "\"}"; // not last, add comma if (iterator.hasNext()) { LATtmp += ", "; } } LATtmp += "], "; line += LATtmp; line += "\"Concept\": "; String Concepttmp = "["; for (Iterator iterator = JCasUtil.select(jcas, Concept.class).iterator(); iterator.hasNext(); ) { Concept c = (Concept) iterator.next(); Concepttmp += "{"; Concepttmp += "\"fullLabel\": \"" + c.getFullLabel().replaceAll("\"", "\\\"") + "\", "; Concepttmp += "\"cookedLabel\": \"" + c.getCookedLabel().replaceAll("\"", "\\\"") + "\", "; Concepttmp += "\"pageID\": \"" + c.getPageID() + "\""; Concepttmp += "}"; // not last, add comma if (iterator.hasNext()) { Concepttmp += ", "; } } Concepttmp += "], "; line += Concepttmp; line += "}"; output(line); // Question q = QuestionDashboard.getInstance().get(qi.getQuestionId()); // QuestionDashboard.getInstance().finishQuestion(q); }
public void process(JCas jcas) throws AnalysisEngineProcessException { String rtn = ""; JCas questionView, answerHitlist; try { questionView = jcas.getView("Question"); answerHitlist = jcas.getView("AnswerHitlist"); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } QuestionInfo qi = JCasUtil.selectSingle(questionView, QuestionInfo.class); FSIndex idx = answerHitlist.getJFSIndexRepository().getIndex("SortedAnswers"); FSIterator answers = idx.iterator(); if (answers.hasNext()) { // int counter = 0; int i = 1; while (answers.hasNext()) { Answer answer = (Answer) answers.next(); StringBuilder sb = new StringBuilder(); sb.append(i++); sb.append(". "); sb.append(answer.getText()); sb.append(" (conf. "); sb.append(answer.getConfidence()); sb.append(")"); /* PRINT the passages assigned to this answer sb.append("\n"); for(int ID: answer.getPassageIDs().toArray()){ sb.append(" "); sb.append(counter++); sb.append(". "); sb.append(QuestionDashboard.getInstance().getPassage(ID)); sb.append(" ("); sb.append(ID); sb.append(")"); sb.append("\n"); } counter = 0; */ if (answer.getResources() != null) { for (FeatureStructure resfs : answer.getResources().toArray()) { sb.append(" "); sb.append(((AnswerResource) resfs).getIri()); } } System.out.println(sb.toString()); rtn = rtn + sb.toString() + "\n"; } } else { System.out.println("No answer found."); rtn = "No answer found."; } Question q = QuestionDashboard.getInstance().get(qi.getQuestionId()); // q.setAnswers(answers); XXX QuestionDashboard.getInstance().finishQuestion(q); final_answer = rtn; }