Record Class QuestionAndAnswer

java.lang.Object
java.lang.Record
org.ek9lang.assist.QuestionAndAnswer
Record Components:
id - Unique question identifier (e.g., 1, 2, 3)
category - Category name (e.g., "Getting Started")
question - The canonical question text
alternatePhrasings - Alternative ways to ask the same question
answer - The answer text (may contain markdown formatting)
ek9Example - Inline EK9 code example or file reference
migrationContext - Which developer backgrounds find this relevant
keywords - Pre-tokenized keywords for matching (no stop words)
typicalErrors - Common mistakes with correct/incorrect code and explanation

public record QuestionAndAnswer(int id, String category, String question, List<String> alternatePhrasings, String answer, String ek9Example, String migrationContext, Set<String> keywords, List<TypicalError> typicalErrors) extends Record
Holds a single Q&A entry for the EK9 knowledge base. Used by the -q CLI for developer queries and -Q for training data export.
  • Constructor Details

    • QuestionAndAnswer

      public QuestionAndAnswer(int id, String category, String question, List<String> alternatePhrasings, String answer, String ek9Example, String migrationContext, Set<String> keywords, List<TypicalError> typicalErrors)
      Creates an instance of a QuestionAndAnswer record class.
      Parameters:
      id - the value for the id record component
      category - the value for the category record component
      question - the value for the question record component
      alternatePhrasings - the value for the alternatePhrasings record component
      answer - the value for the answer record component
      ek9Example - the value for the ek9Example record component
      migrationContext - the value for the migrationContext record component
      keywords - the value for the keywords record component
      typicalErrors - the value for the typicalErrors record component
  • Method Details

    • summary

      public String summary()
      Extract a concise summary from the answer text. Uses the text before the first ALL-CAPS section header (e.g., "BASIC USAGE"). Falls back to first paragraph or word-boundary truncation at 500 chars.
    • keywordTokens

      public Set<String> keywordTokens()
      Keywords with synonyms resolved to canonical form. Used as BM25F field 0 (highest weight) for matching.
    • questionTextTokens

      public Set<String> questionTextTokens()
      Tokenized canonical question text (stop words removed, synonyms resolved). Used as BM25F field 1.
    • alternateTokens

      public Set<String> alternateTokens()
      Tokenized alternate phrasings (stop words removed, synonyms resolved). Used as BM25F field 2.
    • answerTokens

      public Set<String> answerTokens()
      Tokenized answer text for broad-context matching. Used as BM25F field 3. Answer text provides rich signal for queries that mention terms discussed in the answer but not in the question title or keywords.
    • migrationTokens

      public Set<String> migrationTokens()
      Tokenized migration context only. Used as BM25F field 4 (lowest weight). Broadens discovery for tool-specific queries.
    • primaryTokens

      public Set<String> primaryTokens()
      Primary match tokens: resolved keywords plus tokenized canonical question and alternate phrasings.
    • searchableTokens

      public Set<String> searchableTokens()
      All searchable tokens: primary tokens plus answer text and migration context. Used for IDF computation across the full corpus.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public int id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • category

      public String category()
      Returns the value of the category record component.
      Returns:
      the value of the category record component
    • question

      public String question()
      Returns the value of the question record component.
      Returns:
      the value of the question record component
    • alternatePhrasings

      public List<String> alternatePhrasings()
      Returns the value of the alternatePhrasings record component.
      Returns:
      the value of the alternatePhrasings record component
    • answer

      public String answer()
      Returns the value of the answer record component.
      Returns:
      the value of the answer record component
    • ek9Example

      public String ek9Example()
      Returns the value of the ek9Example record component.
      Returns:
      the value of the ek9Example record component
    • migrationContext

      public String migrationContext()
      Returns the value of the migrationContext record component.
      Returns:
      the value of the migrationContext record component
    • keywords

      public Set<String> keywords()
      Returns the value of the keywords record component.
      Returns:
      the value of the keywords record component
    • typicalErrors

      public List<TypicalError> typicalErrors()
      Returns the value of the typicalErrors record component.
      Returns:
      the value of the typicalErrors record component