Examples of TreeSearchResults


Examples of org.cipres.treebase.domain.search.TreeSearchResults

        taxon[i] = convertStars(taxon[i]);
      }
      LOGGER.debug("input " + i + " = '" + taxon[i] + "'");
    }

    TreeSearchResults oldRes; 

    {
      SearchResults<?> sr = (TreeSearchResults) searchResults(request);
      if (sr != null) {
        oldRes = (TreeSearchResults) sr; // (TreeSearchResults) sr.convertToTrees();
      } else {
        oldRes = new TreeSearchResults ();   // TODO: Convert existing search results to new type 
      }
    }
   
    LOGGER.info("doSearch old results contained " + oldRes.size() + " item(s)");
    Collection<PhyloTree> newRes;
    PhyloTreeService treeService = getSearchService().getPhyloTreeService()
   
    TaxonVariant[] taxonVariant = new TaxonVariant[taxon.length];
    List<String> resolutionError = new LinkedList<String> ();
    for (int i=0; i<taxon.length; i++) {
      if (taxon[i] == null) continue;
      if (taxon[i].equals(""))
        resolutionError.add("TaxonVariant name " + i + " missing");
      Set<TaxonVariant> tvSet = getTaxonLabelService().findTaxonVariantByName(taxon[i]);
      taxonVariant[i] = tvSet.isEmpty() ? null : tvSet.iterator().next(); // FIXME: This is not really the right behavior
      if (taxonVariant[i] == null)
        resolutionError.add("Couldn't resolve TaxonVariant '" + taxon[i] + "'");
      else
        LOGGER.debug("input '" + taxon[i] + "' resolved to TV " + taxonVariant[i].getId() + " ('" + taxonVariant[i].getFullName() + "')");
    }
    if (! resolutionError.isEmpty()) {
      addMessages(request, resolutionError);
      return new ModelAndView("search/treeTopSearch", Constants.RESULT_SET, oldRes);
    }
       
    switch (searchType) {
    case topology3Search:
      checkTaxa(taxonVariant, 3);
      newRes = treeService.findByTopology3(taxonVariant[0], taxonVariant[1], taxonVariant[2]);
      break;
    case topology4aSearch:
      checkTaxa(taxonVariant, 4);
      newRes = treeService.findByTopology4a(taxonVariant[0], taxonVariant[1], taxonVariant[2], taxonVariant[3]);
      break;
    case topology4sSearch:
      checkTaxa(taxonVariant, 4);
      newRes = treeService.findByTopology4s(taxonVariant[0], taxonVariant[1], taxonVariant[2], taxonVariant[3]);
      break;
    default:
      throw new Error ("Unknown search type '" + searchType + "'");
    }
   
    if (newRes != null) { LOGGER.info("doSearch '" + searchType + "' found " + newRes.size() + " result(s)"); }
    if (newRes == null || newRes.isEmpty()) {
      addMessage(request, "No matching trees found");
    } else {
      if (oldRes == null) {
        oldRes = new TreeSearchResults(newRes);
      } else { oldRes.intersect(newRes); }
    }
    saveSearchResults(request, oldRes);
    LOGGER.info("doSearch '" + searchType + "' after intersection: " + oldRes.size() + " result(s)");

    return new ModelAndView("search/treeTopSearch", Constants.RESULT_SET, oldRes);
  }
View Full Code Here

Examples of org.cipres.treebase.domain.search.TreeSearchResults

   
    if (formName.equals("treeSimple")) {
      String buttonName = request.getParameter("searchButton");
      String searchTerm = convertStars(request.getParameter("searchTerm"));
      Collection<PhyloTree> matches = null;
      TreeSearchResults oldRes; 
      {
        SearchResults<?> sr = searchResults(request);
        if (sr != null) {
          oldRes = (TreeSearchResults) sr.convertToTrees();
        } else {
          oldRes = new TreeSearchResults ();   // TODO: Convert existing search results to new type 
        }
      }     
      if (buttonName.equals("treeID")) {
        matches = doSearch(request, response, SearchType.byID, errors, searchTerm);
      } else if  (buttonName.equals("treeTitle")) {
        matches =  doSearch(request, response, SearchType.byTitle, errors, searchTerm);
      } else if  (buttonName.equals("treeType")) {
        matches = doSearch(request, response, SearchType.byType, errors, searchTerm);
      } else if  (buttonName.equals("treeKind")) {
        matches = doSearch(request, response, SearchType.byKind, errors, searchTerm);
      } else if  (buttonName.equals("treeQuality")) {
        matches = doSearch(request, response, SearchType.byQuality, errors, searchTerm);
      } else if  (buttonName.equals("treeNTAX")) {
        matches = doSearch(request, response, SearchType.byNTAX, errors, searchTerm);
      } else {
        throw new Error("Unknown search button name '" + buttonName + "'");
      }
     
      // XXX need to filter out orphaned matrices or matrices whose studies are unpublished
      Collection<PhyloTree> orphanedTrees = new HashSet<PhyloTree>();
      for ( PhyloTree t : matches ) {
        if (t.getStudy() == null || (t.getStudy().isPublished() == false)){
          orphanedTrees.add(t);
        }   
      }
      matches.removeAll(orphanedTrees);

      SearchResults<PhyloTree> newRes = intersectSearchResults(oldRes, new TreeSearchResults(matches),
      new RequestMessageSetter(request), "No matching trees found")
      saveSearchResults(request, newRes)
      if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) {     
        return new ModelAndView("search/treeSearch", Constants.RESULT_SET, newRes);      
      }
View Full Code Here

Examples of org.cipres.treebase.domain.search.TreeSearchResults

    //String query = request.getParameter("query");
    CQLParser parser = new CQLParser();
    CQLNode root = parser.parse(query);
    root = normalizeParseTree(root);
    Set<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request, response, errors);
    TreeSearchResults tsr = new TreeSearchResults(queryResults);
    saveSearchResults(request, tsr);
    if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) {     
      return new ModelAndView("search/treeSearch", Constants.RESULT_SET, tsr);
    }
    else {
      SearchResults<?> res = tsr;
      String schema = null;
      if ( ! TreebaseUtil.isEmpty(request.getParameter("recordSchema")) ) {
        schema = request.getParameter("recordSchema");
        if ( schema.equals("matrix") ) {
          res = tsr.convertToMatrices();
        }
        else if ( schema.equals("taxon") ) {
          res = tsr.convertToTaxa();
        }
        else if ( schema.equals("study") ) {
          res = tsr.convertToStudies();
        }
      }
      this.saveSearchResults(request, res);
      return this.searchResultsAsRDF(res, request, root,schema,"tree");
    }
View Full Code Here

Examples of org.cipres.treebase.domain.search.TreeSearchResults

    //
    CQLParser parser = new CQLParser();
    CQLNode root = parser.parse(query);
    root = normalizeParseTree(root);
    HashSet<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request, response, errors);
    TreeSearchResults tsr = new TreeSearchResults(queryResults);
    saveSearchResults(request, tsr);
   
    if ( TreebaseUtil.isEmpty(request.getParameter("format")) || ! request.getParameter("format").equals("rss1") ) {     
      return new ModelAndView("search/classificationSearch", Constants.RESULT_SET, tsr);
    }
    else {
      SearchResults<?> res = tsr;
      String schema = null;
      if ( ! TreebaseUtil.isEmpty(request.getParameter("recordSchema")) ) {
        schema = request.getParameter("recordSchema");
        if ( schema.equals("matrix") ) {
          res = tsr.convertToMatrices();
        }
        else if ( schema.equals("taxon") ) {
          res = tsr.convertToTaxa();
        }
        else if ( schema.equals("study") ) {
          res = tsr.convertToStudies();
        }
      }
      this.saveSearchResults(request, res);
      return this.searchResultsAsRDF(res, request, root,schema,"tree");
    }
View Full Code Here

Examples of org.cipres.treebase.domain.search.TreeSearchResults

  }
 
  public void testTreeSearchSerialization() {
    Document doc = DocumentFactory.safeCreateDocument();
    NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc);   
    TreeSearchResults tsr = ssr.convertToTrees();
    ndw.fromTreeBaseToXml(tsr);
    assertNotNull(doc.getXmlString());
  }
View Full Code Here

Examples of org.cipres.treebase.domain.search.TreeSearchResults

    // TODO Auto-generated method stub
   
    try {
      java.util.Date date= new java.util.Date();

      TreeSearchResults treeResults = searchResults(request).convertToTrees();

      String fileName = "TB" + date.getTime();
      StringBuilder builder = new StringBuilder();
     
      if ( getFormat(request) == FORMAT_NEXML ) {
        Document doc = DocumentFactory.safeCreateDocument();
        NexmlDocumentWriter ndw = new NexmlDocumentWriter(null,getTaxonLabelHome(), doc);   
        ndw.fromTreeBaseToXml(treeResults);
        builder.append(doc.getXmlString());
      }
      else {
        Set<PhyloTree> trees =  treeResults.getResults();
        TreeBlock treeBlock = new TreeBlock();
        TaxonLabelSet taxonLabelSet = new TaxonLabelSet();
        List<String> taxonLabels = new ArrayList<String>();

       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.