Package edu.mit.simile.fresnel.results

Examples of edu.mit.simile.fresnel.results.Selection


   * @throws IOException
   */
  public void fresnelView(HttpServletRequest request, HttpServletResponse response) throws IOException  {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(response.getOutputStream() , "UTF-8"));
    String errorString = null;
    Selection selected = null;
    List<org.apache.commons.httpclient.URI> retrievedURLs = null;
    Resource focalResource = null;
    Configuration conf = null;
    String redirectLocation = null;
   
    try {
      /* Reload the Fresnel configuration using the provided language */
      String langPref = (request.getParameter("lang") != null ? request.getParameter("lang") : "en");
      loadFresnelConfig(langPref);

      conf = new Configuration(confRepository, ontoRepository);
     
      /* Create the focal resource */
      if (request.getParameter("uri") != null) {
        String uriString = request.getParameter("uri");
        if (uriString.startsWith("_:")) /* blank node */
          focalResource = valueFactory.createBNode(uriString.substring(2));
        else
          focalResource = valueFactory.createURI(uriString);
         
        /* Collect data about the focal resource */
        if (request.getParameter("skipload") == null) {
          retrievedURLs = semwebClient.discoverResource(focalResource, true /* wait */);   
        } /* skip */
       
        /* Initiate manual owl:sameAs inference */
        if (request.getParameter("skipInference") == null) {
          sameAsInferencer.addInferredForResource(focalResource);
        }
     
        if (conf.hasWarnings())
          writer.println(conf.getWarningsString());
       
        Purpose purpose = null;
       
        /* Look up the requested lens purpose */
        if (request.getParameter("purpose") != null && (!request.getParameter("purpose").equals("defaultPurpose")))
          purpose = new Purpose(new URIImpl(Constants.nsFresnelExt + request.getParameter("purpose")));
        else
          purpose = new Purpose(new URIImpl("http://www.w3.org/2004/09/fresnel#defaultLens")); /* this must be provided, or a random lens is chosen */

        try {
          /* Perform Fresnel selection using the requested display purpose and language */
          selected = conf.select(dataRepository, focalResource, purpose, langPref);
   
          /* Perform Fresnel formatting */
          selected = conf.format(dataRepository, selected);
        }
        catch (NoResultsException e) {
         
              /*
               * If no results are found, redirect the user to the resource
               * if it is not an RDF document.
               * This code is not reached when there already is some data about the resource.
               */
              RepositoryConnection metaDataConn = null;
            try {
              metaDataConn = metaDataRepository.getConnection();
             
            /* Manual support for one level of redirects */
              String resourceRedirect = cacheController.getCachedHeaderDataValue(metaDataConn, focalResource, "location");
              Resource resourceURI = (resourceRedirect == null ? focalResource : new URIImpl(resourceRedirect));
 
              /* Get target content type */
              String contentType = cacheController.getCachedHeaderDataValue(metaDataConn, resourceURI, "content-type");
            if (contentType != null && !ContentTypes.isRDF(contentType)) {
              redirectLocation = focalResource.toString();
            }
          } catch (RepositoryException re) {
            re.printStackTrace();
          } catch (IllegalArgumentException ie) {
            ie.printStackTrace();
          }
          finally {
            try {
              if (metaDataConn != null)
                metaDataConn.close();
              }
            catch (RepositoryException re) {
              re.printStackTrace();
            }
          }
        }
      } /* uri != null */
    } catch (Exception e) {
      e.printStackTrace();
      errorString = e.getMessage();
   
   
    /* Output */
    try {
      /* Handle redirection to non-RDF data */
      if (redirectLocation != null) {
        response.setHeader("Location", redirectLocation);
        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
      }
      else { /* Perform XSL output */
       
        /*
         * When there are no results, we still need a selection object in
         * order to render the fresnel tree
         */
        if (selected == null)
          selected = new Selection(conf);
       
        Document fresnelTree = selected.render();
        addSources(fresnelTree, retrievedURLs);
       
        /* Prepare XSLT */
        StreamSource styleSource = new StreamSource(new File(dataRoot + "/" + xslDirectory + "/" + xslTransformation));
        net.sf.saxon.TransformerFactoryImpl tf = new net.sf.saxon.TransformerFactoryImpl();
View Full Code Here


    if (conf.hasWarnings())
      logger.error(conf.getWarningsString());
  }
 
  public void testSelection() throws Exception {
    Selection selected = conf.select(dataRepo);
    selected = conf.format(dataRepo, selected);
    Document o = selected.render();
   
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document expected = db.parse(out);
View Full Code Here

    if (conf.hasWarnings())
      logger.error(conf.getWarningsString());
  }
 
  public void testSelection() throws Exception {
    Selection selected = conf.select(dataRepo);
    selected = conf.format(dataRepo, selected);
    Document o = selected.render();
   
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document expected = db.parse(out);
View Full Code Here

    }
   
    try {
      Configuration conf = new Configuration(confRepo, ontoRepo);
      if (conf.hasWarnings()) System.err.println(conf.getWarningsString());
      Selection selected = conf.select(dataRepo);
      selected = conf.format(dataRepo, selected);
      Document out = selected.render();
      if (opts.isDebug()) {
        System.out.println(conf);
      } else {
        DOMSource in = new DOMSource(out);
        StreamResult res = new StreamResult(System.out);
View Full Code Here

   * @return A subgraph <code>Selection</code>
   * @throws ParserConfigurationException When a problem with the XML parsing code is encountered
   * @throws NoResultsException When no results can be generated from the given configuration and data
   */
  public Selection select(Repository in, String langPref) throws NoResultsException, ParserConfigurationException {
    Selection answer = null;

    Group group = null;
    if (this._groups.size() > 0) {
      // this just takes the first group if it's undefined;
      // a smarter way to do it would be to do some fast analysis on which
View Full Code Here

    // exception if no matches
    if (this._lensMatches.size() == 0)
      throw new NoResultsException("No lenses matching the data could be found.");

    Selection answer = new Selection(this);
    answer.setLangPref(langPref);

    Iterator<?> resources = this._lensMatches.keySet().iterator();
    while (resources.hasNext()) {
      Resource subject = (Resource) resources.next();
      LensMatchSet match = this._lensMatches.getMatch(subject);
      Lens best = match.topMatch();
      answer.addPrimary(answer.applyLens(grouping, in, best, subject, 0, MAXIMUM_LENS_DEPTH));
    }

    return answer;
  }
View Full Code Here

   * @return A subgraph <code>Selection</code>
   * @throws ParserConfigurationException When a problem with the XML parsing code is encountered
   * @throws NoResultsException When no results can be generated from the given configuration and data
   */
  public Selection select(Repository in, Resource focus, String langPref) throws NoResultsException, ParserConfigurationException {
    Selection answer = null;

    Group group = null;
    if (this._groups.size() > 0) {
      // this just takes the first group if it's undefined;
      // a smarter way to do it would be to do some fast analysis on which
View Full Code Here

    // exception if no matches
    if (null == match)
      throw new NoResultsException("No lenses matching the data could be found.");

    Selection answer = new Selection(this);
    answer.setLangPref(langPref);

    Lens best = match.topMatch();

    // check purposes
    for (Iterator<Lens> pli = match.lensIterator(); pli.hasNext(); ) {
      Lens potential = pli.next();
      if (potential.hasPurpose(purpose)) {
        best = potential;
        break;
      }
    }
    answer.addPrimary(answer.applyLens(grouping, in, best, focus, 0, MAXIMUM_LENS_DEPTH));

    return answer;
  }
View Full Code Here

    // exception if no matches
    if (null == match)
      throw new NoResultsException("No lenses matching the data could be found.");

    Selection answer = new Selection(this);
    answer.setLangPref(langPref);
   
    Lens best = match.topMatch();
    answer.addPrimary(answer.applyLens(grouping, in, best, focus, 0, MAXIMUM_LENS_DEPTH));

    return answer;
  }
View Full Code Here

    if (conf.hasWarnings())
      logger.error(conf.getWarningsString());
  }
 
  public void testSelection() throws Exception {
    Selection selected = conf.select(dataRepo);
    Document o = selected.render();
   
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document expected = db.parse(out);
View Full Code Here

TOP

Related Classes of edu.mit.simile.fresnel.results.Selection

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.