Package uk.ac.cam.ch.wwmm.ptclib.scixml

Examples of uk.ac.cam.ch.wwmm.ptclib.scixml.SciXMLDocument


    List<String> keys = new ArrayList<String>();   
    keys.addAll(counts.keySet());
   
    Collections.sort(keys, Collections.reverseOrder(new CLComparator()));
   
    SciXMLDocument doc = new SciXMLDocument();
   
    Element list = doc.addList();
   
    for(String k : keys) {
      //System.out.printf("%s: %d\n", k, counts.get(k));
      Element li = doc.makeListItem();
      list.appendChild(li);
      if(countsPerInChI.containsKey(k)) {
        String s = "";
        int tot = 0;
        for(String kk : countsPerInChI.get(k).keySet()) {
View Full Code Here


          Document sourceDoc = new Builder().build(new File(f, "source.xml"));         
          PaperToScrapBook.makeScrapBook(sourceDoc, f.getName(), noExperimental, noCaptions);
          response.setContentType("text/plain");
          response.getWriter().write("Paper added OK");
        } else {
          SciXMLDocument doc = SciXMLDocument.makeFromDoc(new Builder().build(markedup));
          if(request.getParameter("minConf") != null) {
            double minConf = Double.parseDouble(request.getParameter("minConf"));
            Nodes n = doc.query("//ne[@confidence]");
            for(int i=0;i<n.size();i++) {
              Element e = (Element)n.get(i);
              double conf = Double.parseDouble(e.getAttributeValue("confidence"));
              if(conf < minConf) {
                XOMTools.removeElementPreservingText(e);
              }
            }
          }
         
          Element p = doc.addPara();
          Element a = doc.makeLink(request.getRequestURI() + "?toscrapbook=full", "Put in scrapbook");
          p.appendChild(a);
          p.appendChild(" ");
          a = doc.makeLink(request.getRequestURI() + "?toscrapbook=noexperimental", "Put in scrapbook (No experimental or captions)");
          p.appendChild(a);
          p.appendChild(" ");
          a = doc.makeLink(request.getRequestURI() + "?toscrapbook=nocaptions", "Put in scrapbook (No captions)");
          p.appendChild(a);
          try {
            int paperId = ResultDbReader.getInstance().getPaperId(f);
            if(paperId > -1) {
              p.appendChild(" ");
              a = doc.makeLink("/SciBorg/papers/" + paperId, " SciBorg Paper " + paperId);           
              p.appendChild(a);
            }           
          } catch (RuntimeException e) {
            //e.printStackTrace();
          }
         
          if(markedup.getName().equals("source.xml")) {
            doc.addServerProcessingInstructions();
            doc.removeViewerProcessingInstruction();
          } else {
            doc.addServerProcessingInstructions();           
          }
          response.setContentType("application/xml");
          new Serializer(response.getOutputStream()).write(doc);
        }
      } catch (Exception e) {
        response.sendError(404);
      }   
    } else if(f.isDirectory()) {
      /* Make sure the browser treats it like one... */
      if(!request.getPathInfo().endsWith("/")) {
        String newPath = request.getPathInfo().substring(request.getPathInfo().lastIndexOf('/') + 1);
        response.sendRedirect(newPath + "/");
        return;
      }
     
      if(request.getParameter("reprocess") != null) {
        List<File> files = FileTools.getFilesFromDirectoryByName(f, "source.xml");
        String traceability = Traceability.getTraceabilityInfo();
        for(File ff : files) {
          if(Oscar3Props.getInstance().verbose) System.out.println(ff.getParentFile());
          Oscar3.processDirectory(ff.getParentFile(), traceability);
        }
        response.sendRedirect(".");
      } else if(request.getParameter("importall") != null) {
        String mode = request.getParameter("importall");
        boolean noExperimental = mode.equals("noexperimental");
        boolean noCaptions = mode.equals("nocaptions");
        List<File> files = FileTools.getFilesFromDirectoryByName(f, "source.xml");
        try {
          for(File ff : files) {
            Document sourceDoc = new Builder().build(ff);         
            PaperToScrapBook.makeScrapBook(sourceDoc, ff.getParentFile().getName(), noExperimental, noCaptions);         
          }         
        } catch (Exception e) {
          e.printStackTrace();
          return;
        }
        response.setContentType("text/plain");
        response.getWriter().write("Imported all files to scrapbook OK");
        return;
      }
     
      SciXMLDocument doc = new SciXMLDocument();
      doc.addServerProcessingInstructions();
      Element para = doc.addPara();
      para.appendChild(doc.makeLink("/ViewPaper" + request.getPathInfo() + "?reprocess", "Reprocess this directory"));
     
      Element list = doc.addList();
     
      File [] children = f.listFiles();
      for(int i=0;i<children.length;i++) {
        if(children[i].isDirectory()) {
          Element a = doc.makeLink("./" + children[i].getName());
          File cm = new File(children[i], "markedup.xml");
          if(!cm.exists()) cm = new File(children[i], "source.xml");
          if(cm.exists()) {
            try {
              Nodes nn = new Builder().build(cm).query(XMLStrings.getInstance().TITLE_XPATH, XMLStrings.getInstance().getXpc());
              if(nn.size() > 0){
                Node n = nn.get(0);
                n.detach();
                a.appendChild(n);
              } else {               
                a.appendChild(children[i].getName());           
              }
            } catch (Exception e) {
              e.printStackTrace();
              a.appendChild(children[i].getName());           
            }
          } else {
            a.appendChild(children[i].getName());                       
          }
          list.appendChild(doc.makeListItem(a));
        }
      }
      response.setContentType("application/xml");
      new Serializer(response.getOutputStream()).write(doc);     
    }
View Full Code Here

      Query oldbq = bq;
      bq = new BooleanQuery();
      bq.add(new BooleanClause(oldbq, BooleanClause.Occur.SHOULD));
      bq.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
    }*/ 
    SciXMLDocument resultsDoc;
    if(uq.rt == ResultsType.SNIPPETS) {
      int hitsNeeded = uq.size + uq.skip;
      TopDocCollector tdc = new TopDocCollector(hitsNeeded);
      searcher.search(bq, tdc);
      resultsDoc = getResultsDocument(tdc, inchis, words, ontIDs, nq, uq, searcher.getIndexReader());     
View Full Code Here

    ChemQuery cq = new ChemQuery(inchiMap);
    return cq;
  }
 
  private SciXMLDocument getResultsDocument(TopDocCollector tdc, Collection<String> inchis, Collection<String> words, Collection<String> ontIDs, Query q, UserQuery lq, IndexReader ir) throws Exception {
    SciXMLDocument doc = new SciXMLDocument();
    doc.setTitle("Search Results");
    int hitsTotal = tdc.getTotalHits();
    if(lq.size + lq.skip > hitsTotal) {
      lq.size = hitsTotal - lq.skip;
    }
    Element p = doc.addPara();
    p.appendChild("Results " + Integer.toString(lq.skip + 1) + " to " + Integer.toString(lq.size + lq.skip) + " of " + Integer.toString(hitsTotal) + ": ");
    if(lq.skip > 0) p.appendChild(doc.makeLink(lq.getQueryURL(Math.max(lq.skip - lq.size, 0), lq.size), "prev"));
    p.appendChild(" ");
    if(lq.size + lq.skip < hitsTotal) p.appendChild(doc.makeLink(lq.getQueryURL(lq.skip + lq.size, lq.size), "next"));
    TopDocs td = tdc.topDocs();
    for(int i=lq.skip;i<lq.skip+lq.size;i++) {
     
      File f = new File(ir.document(td.scoreDocs[i].doc).get("filename"));
      Element body = doc.getBody();
      try {
        String href;
        if(f.getName().equals("scrapbook.xml")) {
          String sbname = f.getParentFile().getName();
          href = "ScrapBook?action=show&name=" + sbname;
        } else {
          String fname = f.getParent();
          fname = fname.split("corpora")[1].substring(1);
          href = "ViewPaper/" + fname;
        }
        QueryDigester qd = new QueryDigester(q);
        List<TermVectorOffsetInfo> offsets = qd.getOffsets(ir, td.scoreDocs[i].doc, "txt");
        //List<TermVectorOffsetInfo> offsets = getOffsets(ir, td.scoreDocs[i].doc, "txt", words);
        //List<TermVectorOffsetInfo> offsets = getOffsets(ir, td.scoreDocs[i].doc, "InChI", inchis);
        //List<TermVectorOffsetInfo> offsets = getOffsets(ir, td.scoreDocs[i].doc, "Ontology", ontIDs);
        body.appendChild(SnippetGetter.getSearchResult(inchis, offsets, ontIDs, new Builder().build(f), href, td.scoreDocs[i].doc, lq, f.getParentFile()));
        //System.out.println(f + "\t" + hits.score(i));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    doc.getDiv().appendChild(XOMTools.safeCopy(p));
    return doc;
  }
View Full Code Here

  public SciXMLDocument getBigCompoundsList() throws Exception {   
    IndexSearcher searcher = new IndexSearcher(indexFile.getAbsolutePath());
    SimpleHitCollector shc = new SimpleHitCollector();
    searcher.search(new MatchAllDocsQuery(), shc);
    Set<File> files = getFilesFromSimpleHitCollector(shc, searcher.getIndexReader());
    SciXMLDocument resultsDoc = CompoundsList.makeCompundsList(files);
    searcher.close();
    return resultsDoc;
  }
View Full Code Here

    String ontIDs = request.getParameter("ontids");
   
    boolean cutDown = Oscar3Props.getInstance().serverType.equals("cutdown");
   
    try {
      SciXMLDocument doc = NEPage.makeNEPage(name, type, smiles, inchi, ontIDs, cutDown);
     
      doc.addServerProcessingInstructions();
      new Serializer(response.getOutputStream()).write(doc);
    } catch (Exception e) {
      e.printStackTrace();
      response.setContentType("text/plain");
      response.getWriter().println("Error in Named Entity viewer!");
View Full Code Here

*/
@SuppressWarnings("serial")
public final class NETypesServlet extends HttpServlet {

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SciXMLDocument doc = NETypes.getSciXMLDoc();
    doc.addServerProcessingInstructions();
    response.setContentType("application/xml");
    new Serializer(response.getOutputStream()).write(doc);
   
  }
View Full Code Here

 
  protected void doPost(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    String in = request.getParameter("contents");
    SciXMLDocument doc = null;
    if(in == null) {
      in = request.getParameter("SciXML");
      try  {
        Document d = new Builder().build(in, "/");
        doc = SciXMLDocument.makeFromDoc(d);
View Full Code Here

TOP

Related Classes of uk.ac.cam.ch.wwmm.ptclib.scixml.SciXMLDocument

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.