Class RewriterUtils


  • public class RewriterUtils
    extends java.lang.Object
    Contains common utilities used by rewriters
    Author:
    Karen Sze Wing Lee
    • Constructor Summary

      Constructors 
      Constructor Description
      RewriterUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void error​(java.util.logging.Logger logger, Query query, java.lang.String msg)
      Print error message
      static void error​(java.util.logging.Logger logger, java.lang.String msg)
      Print error message
      static java.lang.String getNormalizedOriginalQuery​(Query query)
      Retrieve normalized original query from query object
      static java.lang.String getQPConfig​(Query query, java.lang.String rewriterName, java.lang.String paramName)
      Get config parameter value set in query profile
      static java.lang.String getRewriteFromFSA​(Query query, java.util.HashMap<java.lang.String,​java.lang.Object> rewriterDicts, java.lang.String dictName, java.lang.String key)
      Retrieve rewrite from FSA given the original query
      static java.util.HashMap<java.lang.String,​java.lang.Object> getRewriteMeta​(Query query)
      Retrieve metadata passed by previous rewriter from query properties Initialize values if this is the first rewriter
      static java.lang.String getRewriterChain​(Query query)
      Get rewriter chain value
      static java.lang.String getSpellCorrected​(Query query, boolean qss_rw, boolean qss_sugg)
      Retrieve spell corrected query with highest score from QLAS
      static java.lang.String getUserParam​(Query query, java.lang.String paramName)
      Get user param value
      static com.yahoo.fsa.FSA loadFSA​(java.io.File file, Query query)
      Load FSA from file
      static com.yahoo.fsa.FSA loadFSA​(java.lang.String filename, Query query)
      Load FSA from file
      static void log​(java.util.logging.Logger logger, Query query, java.lang.String msg)
      Log message
      static void log​(java.util.logging.Logger logger, java.lang.String msg)
      Log message
      static void setRewriteMeta​(Query query, java.util.HashMap<java.lang.String,​java.lang.Object> metadata)
      Pass metadata to the next rewriter through query properties
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RewriterUtils

        public RewriterUtils()
    • Method Detail

      • loadFSA

        public static com.yahoo.fsa.FSA loadFSA​(java.io.File file,
                                                Query query)
                                         throws java.io.IOException
        Load FSA from file
        Parameters:
        file - FSA dictionary file object
        query - Query object from the searcher, could be null if not available
        Returns:
        FSA The FSA object for the input file path
        Throws:
        java.io.IOException
      • loadFSA

        public static com.yahoo.fsa.FSA loadFSA​(java.lang.String filename,
                                                Query query)
                                         throws java.io.IOException
        Load FSA from file
        Parameters:
        filename - FSA dictionary file path
        query - Query object from the searcher, could be null if not available
        Returns:
        FSA The FSA object for the input file path
        Throws:
        java.io.IOException
      • getRewriteFromFSA

        public static java.lang.String getRewriteFromFSA​(Query query,
                                                         java.util.HashMap<java.lang.String,​java.lang.Object> rewriterDicts,
                                                         java.lang.String dictName,
                                                         java.lang.String key)
                                                  throws java.lang.RuntimeException
        Retrieve rewrite from FSA given the original query
        Parameters:
        query - Query object from searcher
        dictName - FSA dictionary name
        rewriterDicts - list of rewriter dictionaries It has the following format: HashMap<dictionary name, FSA>
        key - The original query used to retrieve rewrite from the dictionary
        Returns:
        String The retrieved rewrites, null if query doesn't exist
        Throws:
        java.lang.RuntimeException
      • getQPConfig

        public static java.lang.String getQPConfig​(Query query,
                                                   java.lang.String rewriterName,
                                                   java.lang.String paramName)
        Get config parameter value set in query profile
        Parameters:
        query - Query object from the searcher
        rewriterName - Name of the rewriter
        paramName - parameter to be retrieved
        Returns:
        parameter value or null if not found
      • getRewriterChain

        public static java.lang.String getRewriterChain​(Query query)
        Get rewriter chain value
        Parameters:
        query - Query object from the searcher
        Returns:
        parameter value or null if not found
      • getUserParam

        public static java.lang.String getUserParam​(Query query,
                                                    java.lang.String paramName)
        Get user param value
        Parameters:
        query - Query object from the searcher
        paramName - parameter to be retrieved
        Returns:
        parameter value or null if not found
      • getRewriteMeta

        public static java.util.HashMap<java.lang.String,​java.lang.Object> getRewriteMeta​(Query query)
        Retrieve metadata passed by previous rewriter from query properties Initialize values if this is the first rewriter
        Parameters:
        query - Query object from the searcher
        Returns:
        hashmap containing the metadata
      • setRewriteMeta

        public static void setRewriteMeta​(Query query,
                                          java.util.HashMap<java.lang.String,​java.lang.Object> metadata)
        Pass metadata to the next rewriter through query properties
        Parameters:
        query - Query object from the searcher
        metadata - HashMap containing the metadata
      • getSpellCorrected

        public static java.lang.String getSpellCorrected​(Query query,
                                                         boolean qss_rw,
                                                         boolean qss_sugg)
                                                  throws java.lang.RuntimeException
        Retrieve spell corrected query with highest score from QLAS
        Parameters:
        query - Query object from the searcher
        qss_rw - Whether to consider qss_rw modification
        qss_sugg - Whether ot consider qss_sugg modification
        Returns:
        Spell corrected query or null if not found
        Throws:
        java.lang.RuntimeException
      • getNormalizedOriginalQuery

        public static java.lang.String getNormalizedOriginalQuery​(Query query)
        Retrieve normalized original query from query object
        Parameters:
        query - Query object from searcher
        Returns:
        normalized query
      • log

        public static void log​(java.util.logging.Logger logger,
                               java.lang.String msg)
        Log message
        Parameters:
        logger - Logger used for this msg
        msg - Log message
      • log

        public static void log​(java.util.logging.Logger logger,
                               Query query,
                               java.lang.String msg)
        Log message
        Parameters:
        logger - Logger used for this msg
        query - Query object from searcher
        msg - Log message
      • error

        public static void error​(java.util.logging.Logger logger,
                                 java.lang.String msg)
        Print error message
        Parameters:
        logger - Logger used for this msg
        msg - Error message
      • error

        public static void error​(java.util.logging.Logger logger,
                                 Query query,
                                 java.lang.String msg)
        Print error message
        Parameters:
        logger - Logger used for this msg
        query - Query object from searcher
        msg - Error message