Package org.terrier.querying.parser

Examples of org.terrier.querying.parser.Query


  //but I would prefer the separate method)
  /** runPreProcessing */
  public void runPreProcessing(SearchRequest srq)
  {
    Request rq = (Request)srq;
    Query query = rq.getQuery();
    //System.out.println(query);
    //get the controls
    try{
                boolean rtr = ! query.obtainControls(Allowed_Controls, rq.getControlHashtable());
    //we check that there is stil something left in the query
    if (! rtr)
    {
      rq.setEmpty(true);
      return;
    }
             
    /*if(ApplicationSetup.getProperty("querying.manager.sendlang","").equals("true"))
    {
      String lang = rq.getControl("lang").toLowerCase();
      String marker = ApplicationSetup.getProperty("termpipelines.languageselector.markerlang", "||LANG:");
      if(lang.length() > 0)
      {
        if(logger.isDebugEnabled()){
          logger.debug("Sending marker through pipeline "+marker+lang);
        }
        pipelineTerm(marker+lang);
       
      }
    }*/
    synchronized(this) {
      rtr = query.applyTermPipeline(tpa);
      tpa.resetPipeline();
    }
    Map<String,String> controls = rq.getControlHashtable();
     
    for(int i=0; i<PreProcesses_Order.length; i++)
    {
      String PreProcesses_Name = PreProcesses_Order[i];
      for(int j=0; j<PreProcesses_Controls[i].length; j++)
      {
        String ControlName = PreProcesses_Controls[i][j];
        String value = (String)controls.get(ControlName);
        //System.err.println(ControlName+ "("+ControlName+") => "+value);
        if (value == null)
          continue;
        value = value.toLowerCase();
        if(! (value.equals("off") || value.equals("false")))
        {
          if (logger.isDebugEnabled()){
            logger.debug("Processing: "+PreProcesses_Name);
          }
          getPreProcessModule(PreProcesses_Name).process(this, srq);
          //we've now run this pre process module, no need to check the rest of the controls for it.
          break;
        }
      }
    }
    String lastPP = null;
    if ((lastPP = ApplicationSetup.getProperty("querying.lastpreprocess",null)) != null)
    {
      getPreProcessModule(lastPP).process(this, srq);
    }   

    if (! rtr)
    {
      rq.setEmpty(true);
      return;
    }

    if (ApplicationSetup.getProperty("querying.no.negative.requirement", "").equals("true"))
    {
      ArrayList<org.terrier.querying.parser.Query> terms = new ArrayList<org.terrier.querying.parser.Query>();
      query.getTermsOf(org.terrier.querying.parser.SingleTermQuery.class, terms, true);
      for(Query sqt : terms)
        ((org.terrier.querying.parser.SingleTermQuery)sqt).setRequired(0);
    }

    MatchingQueryTerms queryTerms = new MatchingQueryTerms(rq.getQueryID(), rq);
   
    query.obtainQueryTerms(queryTerms);
    rq.setMatchingQueryTerms(queryTerms);
                  }
                catch(Exception e){
                }
  }
View Full Code Here


      if (logger.isDebugEnabled()){
        logger.debug("weighting model: " + wmodel.getInfo());
      }
      MatchingQueryTerms mqt = rq.getMatchingQueryTerms();
      mqt.setDefaultTermWeightingModel((WeightingModel)wmodel);
      Query q = rq.getQuery();
     
      /* now propagate fields into requirements, and apply boolean matching
         for the decorated terms. */
      ArrayList<Query> requirement_list = new ArrayList<Query>();
      ArrayList<Query> field_list = new ArrayList<Query>();
     
      q.getTermsOf(RequirementQuery.class, requirement_list, true);
      q.getTermsOf(FieldQuery.class, field_list, true);
                     //  System.out.println(requirement_list);
                      //  System.out.println(field_list);
      for (int i=0; i<field_list.size(); i++)
        if (!requirement_list.contains(field_list.get(i)))
          requirement_list.add(field_list.get(i));
View Full Code Here

  private void runQuery() {
    String query = jTextField.getText();
    if (query == null || query.length() == 0)
      return;
    try {
      Query q = null;
      try{
        q = QueryParser.parseQuery(query);
      } catch (Exception e) {
        //century kludge!
        //remove everything except character and spaces, and retry
        q = QueryParser.parseQuery(query.replaceAll("[^a-zA-Z0-9 ]", ""))
      }
     
      if (q == null)
      {
        //give up
        return;
      }
      if (queryingManager == null)
      {
        return;
      }
      jTextField.setText(q.toString())
      SearchRequest srq = queryingManager.newSearchRequest();
      srq.setQuery(q);
      srq.addMatchingModel(mModel, wModel);
      srq.setControl("c", "1.0d");
      queryingManager.runPreProcessing(srq);
View Full Code Here

  }
 
  @Test public void checkParsedSingleTerm() throws Exception
  {
    final String term = "term1";
    Query q = QueryParser.parseQuery(term);
    MatchingQueryTerms mqt = new MatchingQueryTerms();
    q.obtainQueryTerms(mqt);
    assertEquals(1, mqt.length())
    assertEquals(1, mqt.getTerms().length)
    assertEquals(term, mqt.getTerms()[0]);
    assertEquals(1.0d, mqt.getTermWeight(term), 0.0d);
    assertNull(mqt.getStatistics(term));
View Full Code Here

  }
 
  @Test public void checkParsedSingleSynonym() throws Exception
  {
    String term = "{term1 term2}"
    Query q = QueryParser.parseQuery(term);
    term = "term1|term2"; //internal notation is different
    MatchingQueryTerms mqt = new MatchingQueryTerms();
    q.obtainQueryTerms(mqt);
    assertEquals(1, mqt.length())
    assertEquals(1, mqt.getTerms().length)
    assertEquals(term, mqt.getTerms()[0]);
    assertEquals(1.0d, mqt.getTermWeight(term), 0.0d);
    assertNull(mqt.getStatistics(term));
View Full Code Here

 
  @Test public void checkParsedTwoTerms() throws Exception
  {
    final String term1 = "zebra";
    final String term2 = "crossing";
    Query q = QueryParser.parseQuery(term1+"^0.5 " + term2 + "^1.0");
    MatchingQueryTerms mqt = new MatchingQueryTerms();
    q.obtainQueryTerms(mqt);
    assertEquals(2, mqt.length())
    assertEquals(2, mqt.getTerms().length)
    assertEquals(term1, mqt.getTerms()[0]);
    assertEquals(term2, mqt.getTerms()[1]);
   
View Full Code Here

TOP

Related Classes of org.terrier.querying.parser.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.