public enum QuestionType {
  factoid, list, yesno, summary
} public final class Snippet {

  private String document;

  private String text;

  private int offsetInBeginSection;

  private int offsetInEndSection;

  private String beginSection;

  private String endSection;

  public Snippet(String document, String text, int offsetInBeginSection, int offsetInEndSection,
          String beginSection, String endSection) {
    super();
    this.document = document;
    this.text = text;
    this.offsetInBeginSection = offsetInBeginSection;
    this.offsetInEndSection = offsetInEndSection;
    this.beginSection = beginSection;
    this.endSection = endSection;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((beginSection == null) ? 0 : beginSection.hashCode());
    result = prime * result + ((document == null) ? 0 : document.hashCode());
    result = prime * result + ((endSection == null) ? 0 : endSection.hashCode());
    result = prime * result + offsetInBeginSection;
    result = prime * result + offsetInEndSection;
    result = prime * result + ((text == null) ? 0 : text.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Snippet other = (Snippet) obj;
    if (beginSection == null) {
      if (other.beginSection != null)
        return false;
    } else if (!beginSection.equals(other.beginSection))
      return false;
    if (document == null) {
      if (other.document != null)
        return false;
    } else if (!document.equals(other.document))
      return false;
    if (endSection == null) {
      if (other.endSection != null)
        return false;
    } else if (!endSection.equals(other.endSection))
      return false;
    if (offsetInBeginSection != other.offsetInBeginSection)
      return false;
    if (offsetInEndSection != other.offsetInEndSection)
      return false;
    if (text == null) {
      if (other.text != null)
        return false;
    } else if (!text.equals(other.text))
      return false;
    return true;
  }

  public String getDocument() {
    return document;
  }

  public void setDocument(String document) {
    this.document = document;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public int getOffsetInBeginSection() {
    return offsetInBeginSection;
  }

  public void setOffsetInBeginSection(int offsetInBeginSection) {
    this.offsetInBeginSection = offsetInBeginSection;
  }

  public int getOffsetInEndSection() {
    return offsetInEndSection;
  }

  public void setOffsetInEndSection(int offsetInEndSection) {
    this.offsetInEndSection = offsetInEndSection;
  }

  public String getBeginSection() {
    return beginSection;
  }

  public void setBeginSection(String beginSection) {
    this.beginSection = beginSection;
  }

  public String getEndSection() {
    return endSection;
  }

  public void setEndSection(String endSection) {
    this.endSection = endSection;
  }

} public class TestFactoidQuestion extends TestQuestion {

  @SerializedName("exact_answer")
  private List<List<String>> exactAnswer;

  public TestFactoidQuestion(String id, String body, QuestionType type, List<String> documents,
          List<Snippet> snippets, List<String> concepts, List<Triple> triples, String idealAnswer,
          List<List<String>> exactAnswer) {
    super(id, body, type, documents, snippets, concepts, triples, idealAnswer);
    this.exactAnswer = exactAnswer;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((exactAnswer == null) ? 0 : exactAnswer.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    TestFactoidQuestion other = (TestFactoidQuestion) obj;
    if (exactAnswer == null) {
      if (other.exactAnswer != null)
        return false;
    } else if (!exactAnswer.equals(other.exactAnswer))
      return false;
    return true;
  }

  public List<List<String>> getExactAnswer() {
    return exactAnswer;
  }

  public void setExactAnswer(List<List<String>> exactAnswer) {
    this.exactAnswer = exactAnswer;
  }

} public class TestListQuestion extends TestQuestion {

  @SerializedName("exact_answer")
  private List<List<String>> exactAnswer;

  public TestListQuestion(String id, String body, QuestionType type, List<String> documents,
          List<Snippet> snippets, List<String> concepts, List<Triple> triples, String idealAnswer,
          List<List<String>> exactAnswer) {
    super(id, body, type, documents, snippets, concepts, triples, idealAnswer);
    this.exactAnswer = exactAnswer;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((exactAnswer == null) ? 0 : exactAnswer.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    TestListQuestion other = (TestListQuestion) obj;
    if (exactAnswer == null) {
      if (other.exactAnswer != null)
        return false;
    } else if (!exactAnswer.equals(other.exactAnswer))
      return false;
    return true;
  }

  public List<List<String>> getExactAnswer() {
    return exactAnswer;
  }

  public void setExactAnswer(List<List<String>> exactAnswer) {
    this.exactAnswer = exactAnswer;
  }

} public class TestQuestion extends Question {

  @SerializedName("ideal_answer")
  private String idealAnswer;

  public TestQuestion(String id, String body, QuestionType type, List<String> documents,
          List<Snippet> snippets, List<String> concepts, List<Triple> triples, String idealAnswer) {
    super(id, body, type, documents, snippets, concepts, triples);
    this.idealAnswer = idealAnswer;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((idealAnswer == null) ? 0 : idealAnswer.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    TestQuestion other = (TestQuestion) obj;
    if (idealAnswer == null) {
      if (other.idealAnswer != null)
        return false;
    } else if (!idealAnswer.equals(other.idealAnswer))
      return false;
    return true;
  }

  public String getIdealAnswer() {
    return idealAnswer;
  }

  public void setIdealAnswer(String idealAnswer) {
    this.idealAnswer = idealAnswer;
  }

} public class TestSummaryQuestion extends TestQuestion {

  public TestSummaryQuestion(String id, String body, QuestionType type, List<String> documents,
          List<Snippet> snippets, List<String> concepts, List<Triple> triples, String idealAnswer) {
    super(id, body, type, documents, snippets, concepts, triples, idealAnswer);
  }

} public class TestYesNoQuestion extends TestQuestion {

  @SerializedName("exact_answer")
  private String exactAnswer;

  public TestYesNoQuestion(String id, String body, QuestionType type, List<String> documents,
          List<Snippet> snippets, List<String> concepts, List<Triple> triples, String idealAnswer,
          String exactAnswer) {
    super(id, body, type, documents, snippets, concepts, triples, idealAnswer);
    this.exactAnswer = exactAnswer;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((exactAnswer == null) ? 0 : exactAnswer.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    TestYesNoQuestion other = (TestYesNoQuestion) obj;
    if (exactAnswer == null) {
      if (other.exactAnswer != null)
        return false;
    } else if (!exactAnswer.equals(other.exactAnswer))
      return false;
    return true;
  }

  public String getExactAnswer() {
    return exactAnswer;
  }

} public final class Triple {

  private String s;

  private String p;

  private String o;

  public Triple(String s, String p, String o) {
    super();
    this.s = s;
    this.p = p;
    this.o = o;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((o == null) ? 0 : o.hashCode());
    result = prime * result + ((p == null) ? 0 : p.hashCode());
    result = prime * result + ((s == null) ? 0 : s.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Triple other = (Triple) obj;
    if (o == null) {
      if (other.o != null)
        return false;
    } else if (!o.equals(other.o))
      return false;
    if (p == null) {
      if (other.p != null)
        return false;
    } else if (!p.equals(other.p))
      return false;
    if (s == null) {
      if (other.s != null)
        return false;
    } else if (!s.equals(other.s))
      return false;
    return true;
  }

  public String getS() {
    return s;
  }

  public void setS(String s) {
    this.s = s;
  }

  public String getP() {
    return p;
  }

  public void setP(String p) {
    this.p = p;
  }

  public String getO() {
    return o;
  }

  public void setO(String o) {
    this.o = o;
  }

} public class Answer extends TOP {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Answer.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected Answer() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public Answer(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public Answer(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: text

  /** getter for text - gets The actual answer string.
   * @generated
   * @return value of the feature 
   */
  public String getText() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Answer");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Answer_Type)jcasType).casFeatCode_text);}
    
  /** setter for text - sets The actual answer string. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setText(String v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setStringValue(addr, ((Answer_Type)jcasType).casFeatCode_text, v);}    
   
    
  //*--------------*
  //* Feature: score

  /** getter for score - gets The score associated with the answer.
   * @generated
   * @return value of the feature 
   */
  public double getScore() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Answer");
    return jcasType.ll_cas.ll_getDoubleValue(addr, ((Answer_Type)jcasType).casFeatCode_score);}
    
  /** setter for score - sets The score associated with the answer. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setScore(double v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setDoubleValue(addr, ((Answer_Type)jcasType).casFeatCode_score, v);}    
   
    
  //*--------------*
  //* Feature: variants

  /** getter for variants - gets List of candidate answer variants that were merged into this final answer.
   * @generated
   * @return value of the feature 
   */
  public FSList getVariants() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Answer");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Answer_Type)jcasType).casFeatCode_variants)));}
    
  /** setter for variants - sets List of candidate answer variants that were merged into this final answer. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setVariants(FSList v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setRefValue(addr, ((Answer_Type)jcasType).casFeatCode_variants, jcasType.ll_cas.ll_getFSRef(v));}    
  } public class Summary extends TOP {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Summary.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected Summary() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public Summary(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public Summary(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: text

  /** getter for text - gets The actual answer string.
   * @generated
   * @return value of the feature 
   */
  public String getText() {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Summary");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Summary_Type)jcasType).casFeatCode_text);}
    
  /** setter for text - sets The actual answer string. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setText(String v) {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Summary");
    jcasType.ll_cas.ll_setStringValue(addr, ((Summary_Type)jcasType).casFeatCode_text, v);}    
   
    
  //*--------------*
  //* Feature: score

  /** getter for score - gets The score associated with the answer.
   * @generated
   * @return value of the feature 
   */
  public double getScore() {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Summary");
    return jcasType.ll_cas.ll_getDoubleValue(addr, ((Summary_Type)jcasType).casFeatCode_score);}
    
  /** setter for score - sets The score associated with the answer. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setScore(double v) {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Summary");
    jcasType.ll_cas.ll_setDoubleValue(addr, ((Summary_Type)jcasType).casFeatCode_score, v);}    
   
    
  //*--------------*
  //* Feature: variants

  /** getter for variants - gets List of alternative answer summaries.
   * @generated
   * @return value of the feature 
   */
  public StringList getVariants() {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Summary");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Summary_Type)jcasType).casFeatCode_variants)));}
    
  /** setter for variants - sets List of alternative answer summaries. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setVariants(StringList v) {
    if (Summary_Type.featOkTst && ((Summary_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Summary");
    jcasType.ll_cas.ll_setRefValue(addr, ((Summary_Type)jcasType).casFeatCode_variants, jcasType.ll_cas.ll_getFSRef(v));}    
  } public class Question extends Annotation {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Question.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected Question() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public Question(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public Question(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   * @param begin offset to the begin spot in the SofA
   * @param end offset to the end spot in the SofA 
  */  
  public Question(JCas jcas, int begin, int end) {
    super(jcas);
    setBegin(begin);
    setEnd(end);
    readObject();
  }   

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: id

  /** getter for id - gets A unique id for the question.
   * @generated
   * @return value of the feature 
   */
  public String getId() {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_id == null)
      jcasType.jcas.throwFeatMissing("id", "edu.cmu.lti.oaqa.type.input.Question");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Question_Type)jcasType).casFeatCode_id);}
    
  /** setter for id - sets A unique id for the question. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setId(String v) {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_id == null)
      jcasType.jcas.throwFeatMissing("id", "edu.cmu.lti.oaqa.type.input.Question");
    jcasType.ll_cas.ll_setStringValue(addr, ((Question_Type)jcasType).casFeatCode_id, v);}    
   
    
  //*--------------*
  //* Feature: source

  /** getter for source - gets The source of the question, e.g., TREC11, Jeopardy, etc.
   * @generated
   * @return value of the feature 
   */
  public String getSource() {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_source == null)
      jcasType.jcas.throwFeatMissing("source", "edu.cmu.lti.oaqa.type.input.Question");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Question_Type)jcasType).casFeatCode_source);}
    
  /** setter for source - sets The source of the question, e.g., TREC11, Jeopardy, etc. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setSource(String v) {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_source == null)
      jcasType.jcas.throwFeatMissing("source", "edu.cmu.lti.oaqa.type.input.Question");
    jcasType.ll_cas.ll_setStringValue(addr, ((Question_Type)jcasType).casFeatCode_source, v);}    
   
    
  //*--------------*
  //* Feature: questionType

  /** getter for questionType - gets The class of the question, determined by either an automatic question classification process or human judgment.
   * @generated
   * @return value of the feature 
   */
  public String getQuestionType() {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_questionType == null)
      jcasType.jcas.throwFeatMissing("questionType", "edu.cmu.lti.oaqa.type.input.Question");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Question_Type)jcasType).casFeatCode_questionType);}
    
  /** setter for questionType - sets The class of the question, determined by either an automatic question classification process or human judgment. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setQuestionType(String v) {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_questionType == null)
      jcasType.jcas.throwFeatMissing("questionType", "edu.cmu.lti.oaqa.type.input.Question");
    jcasType.ll_cas.ll_setStringValue(addr, ((Question_Type)jcasType).casFeatCode_questionType, v);}    
   
    
  //*--------------*
  //* Feature: text

  /** getter for text - gets The question content.
   * @generated
   * @return value of the feature 
   */
  public String getText() {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.input.Question");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Question_Type)jcasType).casFeatCode_text);}
    
  /** setter for text - sets The question content. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setText(String v) {
    if (Question_Type.featOkTst && ((Question_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.input.Question");
    jcasType.ll_cas.ll_setStringValue(addr, ((Question_Type)jcasType).casFeatCode_text, v);}    
  } public class Concept extends TOP {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Concept.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected Concept() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public Concept(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public Concept(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: names

  /** getter for names - gets All name variants (preferred/default name, synonyms, lexicial variants, etc) of the concept.
   * @generated
   * @return value of the feature 
   */
  public StringList getNames() {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_names == null)
      jcasType.jcas.throwFeatMissing("names", "edu.cmu.lti.oaqa.type.kb.Concept");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Concept_Type)jcasType).casFeatCode_names)));}
    
  /** setter for names - sets All name variants (preferred/default name, synonyms, lexicial variants, etc) of the concept. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setNames(StringList v) {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_names == null)
      jcasType.jcas.throwFeatMissing("names", "edu.cmu.lti.oaqa.type.kb.Concept");
    jcasType.ll_cas.ll_setRefValue(addr, ((Concept_Type)jcasType).casFeatCode_names, jcasType.ll_cas.ll_getFSRef(v));}    
   
    
  //*--------------*
  //* Feature: uris

  /** getter for uris - gets Array of uris that identify this named entity. There may be more than one uri if this named entity is ambiguous.
   * @generated
   * @return value of the feature 
   */
  public StringList getUris() {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_uris == null)
      jcasType.jcas.throwFeatMissing("uris", "edu.cmu.lti.oaqa.type.kb.Concept");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Concept_Type)jcasType).casFeatCode_uris)));}
    
  /** setter for uris - sets Array of uris that identify this named entity. There may be more than one uri if this named entity is ambiguous. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setUris(StringList v) {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_uris == null)
      jcasType.jcas.throwFeatMissing("uris", "edu.cmu.lti.oaqa.type.kb.Concept");
    jcasType.ll_cas.ll_setRefValue(addr, ((Concept_Type)jcasType).casFeatCode_uris, jcasType.ll_cas.ll_getFSRef(v));}    
   
    
  //*--------------*
  //* Feature: ids

  /** getter for ids - gets A list of IDs (e.g. UI in UMLS) associated with this concept.
   * @generated
   * @return value of the feature 
   */
  public StringList getIds() {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_ids == null)
      jcasType.jcas.throwFeatMissing("ids", "edu.cmu.lti.oaqa.type.kb.Concept");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Concept_Type)jcasType).casFeatCode_ids)));}
    
  /** setter for ids - sets A list of IDs (e.g. UI in UMLS) associated with this concept. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setIds(StringList v) {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_ids == null)
      jcasType.jcas.throwFeatMissing("ids", "edu.cmu.lti.oaqa.type.kb.Concept");
    jcasType.ll_cas.ll_setRefValue(addr, ((Concept_Type)jcasType).casFeatCode_ids, jcasType.ll_cas.ll_getFSRef(v));}    
   
    
  //*--------------*
  //* Feature: mentions

  /** getter for mentions - gets A list of ConceptMentions (text spans) that might be surface forms to this concept.
   * @generated
   * @return value of the feature 
   */
  public FSList getMentions() {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_mentions == null)
      jcasType.jcas.throwFeatMissing("mentions", "edu.cmu.lti.oaqa.type.kb.Concept");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Concept_Type)jcasType).casFeatCode_mentions)));}
    
  /** setter for mentions - sets A list of ConceptMentions (text spans) that might be surface forms to this concept. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setMentions(FSList v) {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_mentions == null)
      jcasType.jcas.throwFeatMissing("mentions", "edu.cmu.lti.oaqa.type.kb.Concept");
    jcasType.ll_cas.ll_setRefValue(addr, ((Concept_Type)jcasType).casFeatCode_mentions, jcasType.ll_cas.ll_getFSRef(v));}    
   
    
  //*--------------*
  //* Feature: types

  /** getter for types - gets A list of concept types that the concept belongs to.
   * @generated
   * @return value of the feature 
   */
  public FSList getTypes() {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_types == null)
      jcasType.jcas.throwFeatMissing("types", "edu.cmu.lti.oaqa.type.kb.Concept");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Concept_Type)jcasType).casFeatCode_types)));}
    
  /** setter for types - sets A list of concept types that the concept belongs to. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setTypes(FSList v) {
    if (Concept_Type.featOkTst && ((Concept_Type)jcasType).casFeat_types == null)
      jcasType.jcas.throwFeatMissing("types", "edu.cmu.lti.oaqa.type.kb.Concept");
    jcasType.ll_cas.ll_setRefValue(addr, ((Concept_Type)jcasType).casFeatCode_types, jcasType.ll_cas.ll_getFSRef(v));}    
  } public class ConceptSearchResult extends AnswerSearchResult {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(ConceptSearchResult.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected ConceptSearchResult() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public ConceptSearchResult(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public ConceptSearchResult(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: concept

  /** getter for concept - gets The relevant concept searched in the ontology.
   * @generated
   * @return value of the feature 
   */
  public Concept getConcept() {
    if (ConceptSearchResult_Type.featOkTst && ((ConceptSearchResult_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.retrieval.ConceptSearchResult");
    return (Concept)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((ConceptSearchResult_Type)jcasType).casFeatCode_concept)));}
    
  /** setter for concept - sets The relevant concept searched in the ontology. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setConcept(Concept v) {
    if (ConceptSearchResult_Type.featOkTst && ((ConceptSearchResult_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.retrieval.ConceptSearchResult");
    jcasType.ll_cas.ll_setRefValue(addr, ((ConceptSearchResult_Type)jcasType).casFeatCode_concept, jcasType.ll_cas.ll_getFSRef(v));}    
  } public class Document extends SearchResult {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Document.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected Document() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public Document(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public Document(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: title

  /** getter for title - gets The title of the document.
   * @generated
   * @return value of the feature 
   */
  public String getTitle() {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_title == null)
      jcasType.jcas.throwFeatMissing("title", "edu.cmu.lti.oaqa.type.retrieval.Document");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Document_Type)jcasType).casFeatCode_title);}
    
  /** setter for title - sets The title of the document. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setTitle(String v) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_title == null)
      jcasType.jcas.throwFeatMissing("title", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.ll_cas.ll_setStringValue(addr, ((Document_Type)jcasType).casFeatCode_title, v);}    
   
    
  //*--------------*
  //* Feature: docId

  /** getter for docId - gets A unique identifier for this document.
   * @generated
   * @return value of the feature 
   */
  public String getDocId() {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.retrieval.Document");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Document_Type)jcasType).casFeatCode_docId);}
    
  /** setter for docId - sets A unique identifier for this document. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setDocId(String v) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.ll_cas.ll_setStringValue(addr, ((Document_Type)jcasType).casFeatCode_docId, v);}    
   
    
  //*--------------*
  //* Feature: sections

  /** getter for sections - gets Content of sections in the document.
   * @generated
   * @return value of the feature 
   */
  public StringArray getSections() {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sections == null)
      jcasType.jcas.throwFeatMissing("sections", "edu.cmu.lti.oaqa.type.retrieval.Document");
    return (StringArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections)));}
    
  /** setter for sections - sets Content of sections in the document. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setSections(StringArray v) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sections == null)
      jcasType.jcas.throwFeatMissing("sections", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.ll_cas.ll_setRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections, jcasType.ll_cas.ll_getFSRef(v));}    
    
  /** indexed getter for sections - gets an indexed value - Content of sections in the document.
   * @generated
   * @param i index in the array to get
   * @return value of the element at index i 
   */
  public String getSections(int i) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sections == null)
      jcasType.jcas.throwFeatMissing("sections", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections), i);
    return jcasType.ll_cas.ll_getStringArrayValue(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections), i);}

  /** indexed setter for sections - sets an indexed value - Content of sections in the document.
   * @generated
   * @param i index in the array to set
   * @param v value to set into the array 
   */
  public void setSections(int i, String v) { 
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sections == null)
      jcasType.jcas.throwFeatMissing("sections", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections), i);
    jcasType.ll_cas.ll_setStringArrayValue(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sections), i, v);}
   
    
  //*--------------*
  //* Feature: sectionLabels

  /** getter for sectionLabels - gets Section labels in the document, e.g. sections.0, sections1, etc.
   * @generated
   * @return value of the feature 
   */
  public StringArray getSectionLabels() {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sectionLabels == null)
      jcasType.jcas.throwFeatMissing("sectionLabels", "edu.cmu.lti.oaqa.type.retrieval.Document");
    return (StringArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels)));}
    
  /** setter for sectionLabels - sets Section labels in the document, e.g. sections.0, sections1, etc. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setSectionLabels(StringArray v) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sectionLabels == null)
      jcasType.jcas.throwFeatMissing("sectionLabels", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.ll_cas.ll_setRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels, jcasType.ll_cas.ll_getFSRef(v));}    
    
  /** indexed getter for sectionLabels - gets an indexed value - Section labels in the document, e.g. sections.0, sections1, etc.
   * @generated
   * @param i index in the array to get
   * @return value of the element at index i 
   */
  public String getSectionLabels(int i) {
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sectionLabels == null)
      jcasType.jcas.throwFeatMissing("sectionLabels", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels), i);
    return jcasType.ll_cas.ll_getStringArrayValue(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels), i);}

  /** indexed setter for sectionLabels - sets an indexed value - Section labels in the document, e.g. sections.0, sections1, etc.
   * @generated
   * @param i index in the array to set
   * @param v value to set into the array 
   */
  public void setSectionLabels(int i, String v) { 
    if (Document_Type.featOkTst && ((Document_Type)jcasType).casFeat_sectionLabels == null)
      jcasType.jcas.throwFeatMissing("sectionLabels", "edu.cmu.lti.oaqa.type.retrieval.Document");
    jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels), i);
    jcasType.ll_cas.ll_setStringArrayValue(jcasType.ll_cas.ll_getRefValue(addr, ((Document_Type)jcasType).casFeatCode_sectionLabels), i, v);}
  } public class TripleSearchResult extends AnswerSearchResult {
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(TripleSearchResult.class);
  /** @generated
   * @ordered 
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type  
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}
 
  /** Never called.  Disable default constructor
   * @generated */
  protected TripleSearchResult() {/* intentionally empty block */}
    
  /** Internal - constructor used by generator 
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure 
   */
  public TripleSearchResult(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }
  
  /** @generated
   * @param jcas JCas to which this Feature Structure belongs 
   */
  public TripleSearchResult(JCas jcas) {
    super(jcas);
    readObject();   
  } 

  /** 
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable 
   */
  private void readObject() {/*default - does nothing empty block */}
     
 
    
  //*--------------*
  //* Feature: triple

  /** getter for triple - gets The relevant triple searched in the RDF store.
   * @generated
   * @return value of the feature 
   */
  public Triple getTriple() {
    if (TripleSearchResult_Type.featOkTst && ((TripleSearchResult_Type)jcasType).casFeat_triple == null)
      jcasType.jcas.throwFeatMissing("triple", "edu.cmu.lti.oaqa.type.retrieval.TripleSearchResult");
    return (Triple)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((TripleSearchResult_Type)jcasType).casFeatCode_triple)));}
    
  /** setter for triple - sets The relevant triple searched in the RDF store. 
   * @generated
   * @param v value to set into the feature 
   */
  public void setTriple(Triple v) {
    if (TripleSearchResult_Type.featOkTst && ((TripleSearchResult_Type)jcasType).casFeat_triple == null)
      jcasType.jcas.throwFeatMissing("triple", "edu.cmu.lti.oaqa.type.retrieval.TripleSearchResult");
    jcasType.ll_cas.ll_setRefValue(addr, ((TripleSearchResult_Type)jcasType).casFeatCode_triple, jcasType.ll_cas.ll_getFSRef(v));}    
  } public class TypeUtil {

  public static Question getQuestion(JCas jcas) {
    return JCasUtil.selectSingle(jcas, Question.class);
  }

  public static List<Token> getOrderedTokens(JCas jcas) {
    return JCasUtil.select(jcas, Token.class).stream().sorted(Comparator.comparing(Token::getBegin))
            .collect(toList());
  }

  public static Focus getFocus(JCas jcas) {
    return JCasUtil.select(jcas, Focus.class).stream().findAny().orElse(null);
  }

  public static Token getHeadTokenOfAnnotation(Annotation annotation) {
    try {
      return getHeadTokenInRange(annotation.getCAS().getJCas(), annotation.getBegin(),
              annotation.getEnd());
    } catch (CASException e) {
      return null;
    }
  }

  public static Token getHeadTokenInRange(JCas jcas, int begin, int end) {
    // check if the span is smaller than a single token. If yes, return the covering token
    List<Token> tokens = firstNotEmpty(JCasUtil.selectCovered(jcas, Token.class, begin, end),
            JCasUtil.selectCovering(jcas, Token.class, begin, end));
    if (tokens.isEmpty()) {
      return null;
    }
    // get path to root for the first token
    List<Token> pathToRoot = new ArrayList<>();
    Token hop = tokens.get(0);
    do {
      pathToRoot.add(hop);
    } while ((hop = hop.getHead()) != null);
    // prune the path to contain only the common sub path to the root of each remaining token
    for (Token token : tokens) {
      hop = token;
      do {
        int index;
        if ((index = pathToRoot.indexOf(hop)) >= 0) {
          pathToRoot = pathToRoot.subList(index, pathToRoot.size());
          break;
        }
      } while ((hop = hop.getHead()) != null);
      assert false;
    }
    // get the head of the resulting path to root
    assert!pathToRoot.isEmpty();
    return pathToRoot.get(0);
  }

  public static <T extends Collection<?>> T firstNotEmpty(T first, T second) {
    if (first.isEmpty()) {
      return second;
    } else {
      return first;
    }
  }

  public static Collection<Concept> getConcepts(JCas jcas) {
    return JCasUtil.select(jcas, Concept.class);
  }

  public static String toString(Concept concept) {
    return TypeUtil.getConceptNames(concept) + " " + TypeUtil.getConceptIds(concept) + " " +
            TypeUtil.getConceptTypeNames(concept);
  }

  public static Collection<ConceptType> getConceptTypes(JCas jcas) {
    return JCasUtil.select(jcas, ConceptType.class);
  }

  public static Collection<ConceptType> getConceptTypes(Concept concept) {
    return FSCollectionFactory.create(concept.getTypes(), ConceptType.class);
  }

  public static Collection<String> getConceptTypeNames(Concept concept) {
    return getConceptTypes(concept).stream().map(ConceptType::getName)
            .collect(toCollection(ArrayList::new));
  }

  public static Collection<String> getConceptNames(Concept concept) {
    return FSCollectionFactory.create(concept.getNames());
  }

  public static String getConceptPreferredName(Concept concept) {
    return concept.getNames().getNthElement(0);
  }

  public static Collection<String> getConceptUris(Concept concept) {
    return FSCollectionFactory.create(concept.getUris());
  }

  public static Collection<String> getConceptIds(Concept concept) {
    return FSCollectionFactory.create(concept.getIds());
  }

  public static String getFirstConceptId(Concept concept) {
    return getConceptIds(concept).stream().findFirst().get();
  }

  public static void mergeConcept(JCas jcas, Concept dst, Concept src) {
    List<String> names = Stream.concat(getConceptNames(dst).stream(), getConceptNames(src).stream())
            .filter(Objects::nonNull).distinct().collect(toList());
    dst.setNames(FSCollectionFactory.createStringList(jcas, names));
    List<String> ids = Stream.concat(getConceptIds(dst).stream(), getConceptIds(src).stream())
            .filter(Objects::nonNull).distinct().collect(toList());
    dst.setIds(FSCollectionFactory.createStringList(jcas, ids));
    List<String> uris = Stream.concat(getConceptUris(dst).stream(), getConceptUris(src).stream())
            .filter(Objects::nonNull).distinct().collect(toList());
    dst.setUris(FSCollectionFactory.createStringList(jcas, uris));
    List<ConceptType> types = Stream
            .concat(getConceptTypes(dst).stream(), getConceptTypes(src).stream())
            .filter(Objects::nonNull).distinct().collect(toList());
    dst.setTypes(FSCollectionFactory.createFSList(jcas, types));
    List<ConceptMention> mentions = Stream
            .concat(getConceptMentions(dst).stream(), getConceptMentions(src).stream())
            .filter(Objects::nonNull).distinct().collect(toList());
    dst.setMentions(FSCollectionFactory.createFSList(jcas, mentions));
  }

  public static Collection<ConceptMention> getConceptMentions(JCas jcas) {
    return JCasUtil.select(jcas, ConceptMention.class);
  }

  public static Collection<ConceptMention> getConceptMentions(Concept concept) {
    return FSCollectionFactory.create(concept.getMentions(), ConceptMention.class);
  }

  public static List<ConceptMention> getOrderedConceptMentions(JCas jcas) {
    return JCasUtil.select(jcas, ConceptMention.class).stream()
            .sorted(Comparator.comparing(ConceptMention::getBegin)).collect(toList());
  }

  public static Collection<AbstractQuery> getAbstractQueries(JCas jcas) {
    return JCasUtil.select(jcas, AbstractQuery.class);
  }

  @Deprecated
  public static AbstractQuery getAbstractQueriesCombined(JCas jcas) {
    List<QueryConcept> conceptsCombined = getAbstractQueries(jcas).stream()
            .flatMap(a -> FSCollectionFactory.create(a.getConcepts(), QueryConcept.class).stream())
            .collect(toList());
    return TypeFactory.createAbstractQuery(jcas, conceptsCombined);
  }

  public static Collection<QueryConcept> getQueryConcepts(AbstractQuery aquery) {
    return FSCollectionFactory.create(aquery.getConcepts(), QueryConcept.class);
  }

  public static final Comparator<SearchResult> SEARCH_RESULT_SCORE_COMPARATOR = Comparator
          .comparing(SearchResult::getScore, Comparator.reverseOrder());

  public static <T extends SearchResult> List<T> rankedSearchResultsByScore(Collection<T> results,
          int hitSize) {
    List<T> sorted = results.stream().sorted(SEARCH_RESULT_SCORE_COMPARATOR).limit(hitSize)
            .collect(toList());
    IntStream.range(0, sorted.size()).forEach(rank -> sorted.get(rank).setRank(rank));
    return sorted;
  }

  public static final Comparator<SearchResult> SEARCH_RESULT_RANK_COMPARATOR = Comparator
          .comparing(SearchResult::getRank);

  private static <T extends SearchResult> List<T> rankedSearchResultsByRank(Collection<T> results) {
    return results.stream().sorted(SEARCH_RESULT_RANK_COMPARATOR).collect(toList());
  }

  public static List<ConceptSearchResult> getRankedConceptSearchResults(JCas jcas) {
    return rankedSearchResultsByRank(JCasUtil.select(jcas, ConceptSearchResult.class));
  }

  public static String toString(ConceptSearchResult result) {
    return result.getScore() + " " + result.getUri() + " " + toString(result.getConcept());
  }

  public static List<TripleSearchResult> getRankedTripleSearchResults(JCas jcas) {
    return rankedSearchResultsByRank(JCasUtil.select(jcas, TripleSearchResult.class));
  }

  public static List<Document> getRankedDocuments(JCas jcas) {
    return rankedSearchResultsByRank(JCasUtil.select(jcas, Document.class));
  }

  public static String toString(Document result) {
    return  result.getScore() + " " + result.getUri() + " " + result.getTitle();
  }

  public static List<Passage> getRankedPassages(JCas jcas) {
    return rankedSearchResultsByRank(JCasUtil.select(jcas, Passage.class));
  }

  public static String getUriOffsets(Passage result, String delim) {
    return String.join(delim, result.getUri(), result.getBeginSection(), result.getEndSection(),
            String.valueOf(result.getOffsetInBeginSection()),
            String.valueOf(result.getOffsetInEndSection()));
  }

  public static String toString(Passage result) {
    return result.getScore() + " " + getUriOffsets(result, " ");
  }

  public static Collection<LexicalAnswerType> getLexicalAnswerTypes(JCas jcas) {
    return JCasUtil.select(jcas, LexicalAnswerType.class);
  }

  public static final Comparator<Answer> ANSWER_SCORE_COMPARATOR = Comparator
          .comparing(Answer::getScore, Comparator.reverseOrder());

  public static List<Answer> getRankedAnswers(JCas jcas) {
    return JCasUtil.select(jcas, Answer.class).stream().sorted(ANSWER_SCORE_COMPARATOR)
            .collect(toList());
  }

  public static final Comparator<Summary> SUMMARY_SCORE_COMPARATOR = Comparator
          .comparing(Summary::getScore, Comparator.reverseOrder());

  public static List<Summary> getRankedSummary(JCas jcas) {
    return JCasUtil.select(jcas, Summary.class).stream().sorted(SUMMARY_SCORE_COMPARATOR)
            .collect(toList());
  }

  public static Collection<CandidateAnswerVariant> getCandidateAnswerVariants(JCas jcas) {
    return JCasUtil.select(jcas, CandidateAnswerVariant.class);
  }

  public static Collection<CandidateAnswerVariant> getCandidateAnswerVariants(Answer answer) {
    return FSCollectionFactory.create(answer.getVariants(), CandidateAnswerVariant.class);
  }

  public static List<String> getCandidateAnswerVariantNames(Answer answer) {
    return getCandidateAnswerVariants(answer).stream().map(TypeUtil::getCandidateAnswerVariantNames)
            .flatMap(Collection::stream).collect(toList());
  }

  public static Collection<String> getCandidateAnswerVariantNames(CandidateAnswerVariant cav) {
    return FSCollectionFactory.create(cav.getNames());
  }

  public static Collection<CandidateAnswerOccurrence> getCandidateAnswerOccurrences(JCas jcas) {
    return JCasUtil.select(jcas, CandidateAnswerOccurrence.class);
  }

  public static Collection<CandidateAnswerOccurrence> getCandidateAnswerOccurrences(
          CandidateAnswerVariant cav) {
    return FSCollectionFactory.create(cav.getOccurrences(), CandidateAnswerOccurrence.class);
  }

  public static Range<Integer> spanRange(Annotation annotation) {
    return Range.closedOpen(annotation.getBegin(), annotation.getEnd());
  }

  public static Range<Integer> spanRangeInSection(Passage passage) {
    return Range.closedOpen(passage.getOffsetInBeginSection(), passage.getOffsetInEndSection());
  }

  public static int hash(Passage passage) {
    return Objects.hash(passage.getUri(), passage.getDocId(), passage.getOffsetInBeginSection(),
            passage.getOffsetInEndSection(), passage.getBeginSection(), passage.getEndSection());
  }

  public static String annotationOffset(Annotation annotation) {
    return annotation.getView().getViewName() + ":" + annotation.getBegin() + ":" +
            annotation.getEnd();
  }

}
import static java.util.stream.Collectors.toList;
import java.util.Collection;
import java.util.List;
import org.apache.uima.fit.util.FSCollectionFactory;
import org.apache.uima.jcas.JCas;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.QuestionType;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.Snippet;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.TestFactoidQuestion;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.TestListQuestion;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.TestQuestion;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.TestSummaryQuestion;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.TestYesNoQuestion;
import edu.cmu.lti.oaqa.baseqa.collection.json.gson.Triple;
import edu.cmu.lti.oaqa.type.answer.Answer;
import edu.cmu.lti.oaqa.type.answer.Summary;
import edu.cmu.lti.oaqa.type.input.Question;
import edu.cmu.lti.oaqa.type.kb.Concept;
import edu.cmu.lti.oaqa.type.retrieval.ConceptSearchResult;
import edu.cmu.lti.oaqa.type.retrieval.Document;
import edu.cmu.lti.oaqa.type.retrieval.TripleSearchResult;
import edu.cmu.lti.oaqa.util.TypeUtil;
package edu.cmu.lti.oaqa.baseqa.collection.json;





public class JsonCasConsumerHelper {

  public static TestQuestion getQuestionFromIndex(JCas jcas, int documentLimit, int snippetLimit,
          int conceptLimit, int tripleLimit, int factoidAnswerLimit, int listAnswerLimit) {
    Question question = TypeUtil.getQuestion(jcas);
    String id = question.getId();
    // question text and type are required
    QuestionType type = convertQuestionType(question.getQuestionType());
    String body = question.getText();
    // retrieve documents, snippets, concepts, and triples from CAS
    List<String> documents = TypeUtil.getRankedDocuments(jcas).stream().limit(documentLimit)
            .map(Document::getUri).collect(toList());
    List<Snippet> snippets = TypeUtil.getRankedPassages(jcas).stream().limit(snippetLimit)
            .map(passage -> new Snippet(passage.getUri(), passage.getText(),
                    passage.getOffsetInBeginSection(), passage.getOffsetInEndSection(),
                    passage.getBeginSection(), passage.getEndSection()))
            .collect(toList());
    List<String> concepts = TypeUtil.getRankedConceptSearchResults(jcas).stream()
            .limit(conceptLimit).map(ConceptSearchResult::getConcept).map(Concept::getUris)