Esempio n. 1
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;
  }
Esempio n. 2
0
 @RequestMapping(value = "/performSearch", method = RequestMethod.POST)
 public String performSearch(
     @ModelAttribute("RdfModel") RdfModel rdfModel, Model model, RedirectAttributes attrs) {
   SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
   QueryBuilder qb = QueryBuilders.matchQuery("hasTitle", rdfModel.getHasTitle());
   searchSourceBuilder.query(qb);
   Search search =
       new Search.Builder(searchSourceBuilder.toString()).addIndex("publications").build();
   try {
     SearchResult searchresult = jc.execute(search);
     ArrayList<RdfModel> publications =
         new ArrayList<RdfModel>(searchresult.getSourceAsObjectList(RdfModel.class));
     model.addAttribute("searchResults", publications);
     model.addAttribute("rdfModel", new RdfModel());
   } catch (Exception e) {
     e.printStackTrace();
   }
   return "index";
 }