public ObservationVectorizer(Iterable<Observation> data) { Map<String, QuestionDef> definitions = new HashMap<String, QuestionDef>(); int index = 0; for (Observation ob : data) { for (Question q : ob.getQuestions()) { if (!definitions.containsKey(q.getId())) definitions.put(q.getId(), new QuestionDef(index++)); definitions.get(q.getId()).addValue(q.getAnswer()); } } this.definitions = definitions; }
public List<Question> getQuestionsSelectedForHomework(int qIds[]) { if (getQuestions() == null) throw new IllegalStateException(); List<Question> selectedQuestions1 = new ArrayList<>(); for (Question question : getQuestions()) for (int qid : qIds) if (question.getId() == qid) selectedQuestions1.add(question); return selectedQuestions1; }
public double[] getVector(Observation data) { double[] result = new double[definitions.size()]; for (Question q : data.getQuestions()) { QuestionDef def = definitions.get(q.getId()); result[def.index] = def.getNumericValue(q.getAnswer()); } return result; }
@Test public void test_question_setId() { // GIVEN Question q = new Question(); long id = 512; // WHEN q.setId(id); // THEN assertEquals(q.getId(), id); }
protected void askFeedback() { // TODO String answerText = etAnswer.getText().toString(); answer = new Answer(answerText, getAnswerer(), AnswerState.UnderReview); question = new Question( question.getId(), question.getQuestion(), question.getAsker(), getAnswerer(), QuestionState.UpForFeedback, null); question.setAnswer(answer); qService.UpdateQuestion(question); aService.CreateAnswer(answer, questionInt); }
@Test public void testCreation() throws Exception { Question q = new Question.Builder("Why is java so hard?").id("10").build(); Assert.assertEquals(q.getQuestion(), "Why is java so hard?"); Assert.assertEquals(q.getId(), "10"); }