Пример #1
0
 @RequestMapping(
     value = {"/", "/index"},
     method = RequestMethod.GET)
 public String home(Model model) {
   // Two Test Dataset from datehub.io
   InputStream in2005 =
       servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2005.rdf");
   InputStream in2006 =
       servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2006.rdf");
   try {
     ArrayList<RdfModel> rms2005 = RdfProcess.processRDF(in2005);
     Boolean b = rms2005.addAll(RdfProcess.processRDF(in2006));
     for (int i = 0; i < rms2005.size(); i++)
       jc.execute(
           new Delete.Builder(String.valueOf(i))
               .index("publications")
               .type("publication")
               .build());
     RdfSearch.Indexing(jc, rms2005);
     model.addAttribute("rdfModel", new RdfModel());
   } catch (Exception e) {
     e.printStackTrace();
   }
   return "index";
 }
Пример #2
0
  public static ArrayList<RdfModel> processRDF(InputStream in) {
    Model model = ModelFactory.createDefaultModel();
    ArrayList<RdfModel> result = new ArrayList<RdfModel>();
    if (in != null) {
      model.read(in, "RDF/XML");
      // Now, I only care these propties: has-title, year-of, full-name. All three of them must
      // exist'
      for (final ResIterator it = model.listSubjectsWithProperty(RdfPropertyList.p_hasTitle);
          it.hasNext(); ) {
        RdfModel rm = new RdfModel();
        try {
          final Resource node =
              it.next().asResource(); // node is a resource which has title property
          rm.setHasTitle(node.getProperty(RdfPropertyList.p_hasTitle).getString());

          StringBuilder authors = new StringBuilder();
          StringBuilder dates = new StringBuilder();

          for (final StmtIterator all_props = node.listProperties(); all_props.hasNext(); ) {
            try {
              Resource all_res = all_props.next().getObject().asResource();
              StmtIterator fullnames = all_res.listProperties(RdfPropertyList.p_fullName);
              StmtIterator years = all_res.listProperties(RdfPropertyList.p_year);
              // Just for now I may have mutiple author or dates in a String, seperated by comma
              RdfProcess newprocess = new RdfProcess();

              while (fullnames.hasNext()) {
                String fullname = newprocess.getValue(fullnames.next().getObject());
                if (!fullname.equals("Invalid/Lack of Information")) {
                  authors.append(fullname + " , ");
                }
              }
              while (years.hasNext()) {
                String year = newprocess.getValue(years.next().getObject());
                if (!year.equals("Invalid/Lack of Information")) {
                  dates.append(year + " , ");
                }
              }
            } catch (Exception e) {
            }
          }
          rm.setHasDate(dates.toString());
          rm.setHasAuthor(authors.toString());
        } catch (Exception e) {
        }
        result.add(rm);
      }
    }
    return result;
  }