Exemplo n.º 1
0
  public final List<GR> buildMemModel(String dir) {

    System.out.println("Start building rdfmodel in memory.....at: " + DateUtils.now());
    // Create an empty in-memory model and populate it from the graph
    ArrayList<GR> t = new ArrayList<GR>();

    try {

      String[] parsedFiles = getFiles(dir, txtfilter);

      for (int i = 0; i < parsedFiles.length; i++) {
        System.out.println("Parsing file" + parsedFiles[i]);
        // System.out.println("reading file "+dir+"/"+rdfFiles[i]);
        File file = new File(dir + "/" + parsedFiles[i]);

        if (file.length() > 0) {
          Text2Mem tm = new Text2Mem(dir + "/" + parsedFiles[i]);
          t.addAll(tm.buildModel("", ""));
        }
      }
      System.out.println("Finish building model in memory.....at: " + DateUtils.now());

    } catch (Exception ex) {
    }

    return t;
  }
Exemplo n.º 2
0
  public final Model buildRdfModel(String dir) {

    System.out.println("Start building rdfmodel in memory.....at: " + DateUtils.now());
    // Create an empty in-memory model and populate it from the graph
    Model model = ModelFactory.createMemModelMaker().createDefaultModel();

    try {

      String[] rdfFiles = getFiles(dir, rdffilter);
      System.out.println(rdfFiles.length);
      InputStream in;
      in = new FileInputStream(new File(dir + "/" + rdfFiles[0]));
      model.read(in, null);
      for (int i = 0; i < rdfFiles.length; i++) {
        // System.out.println("reading file "+dir+"/"+rdfFiles[i]);
        File file = new File(dir + "/" + rdfFiles[i]);
        Model modelt = ModelFactory.createMemModelMaker().createDefaultModel();

        if (file.length() > 0) {
          in = new FileInputStream(file);

          modelt.read(in, null); // null base URI, since model URIs are absolute
          // model.commit();

          in.close();

          // modelt.write(System.out);
          model.add(modelt);
        }
      }
      System.out.println("Finish building rdfmodel in memory.....at: " + DateUtils.now());

    } catch (Exception ex) {
    }

    return model;
  }
Exemplo n.º 3
0
  public static void buildRdfRepository(
      String pdfDir, String txtDir, String parsedDir, String rdfDir) {

    System.out.println("Start converting pdfs......at: " + DateUtils.now());
    String[] pdffiles = getFiles(pdfDir, pdffilter);
    for (int i = 0; i < pdffiles.length; i++) {

      System.out.println(pdfDir + "/" + pdffiles[i]);
      Pdf2Text pdf = new Pdf2Text(pdfDir + "/" + pdffiles[i]);
      pdf.saveToTextPreProssesd(txtDir + "/" + pdffiles[i].split(".pdf")[0] + ".txt");
    }
    System.out.println("Finish converting pdfs......at: " + DateUtils.now());
    System.out.println("Start parsing (using RASP) ......at: " + DateUtils.now());
    String[] txtfiles = getFiles(txtDir, txtfilter);
    for (int i = 0; i < txtfiles.length; i++) {
      File file = new File(txtDir + "/" + txtfiles[i]);
      if (file.length() > 0) {

        System.out.println(txtDir + "/" + txtfiles[i]);
        System.out.println(parsedDir + "/" + txtfiles[i]);
        ExecuteRASP r = new ExecuteRASP(txtDir + "/" + txtfiles[i], parsedDir + "/" + txtfiles[i]);
        r.callRASP();
      }
    }
    System.out.println("Finish parsing (using RASP) ......at: " + DateUtils.now());
    System.out.println("Start converting to RDF ......at: " + DateUtils.now());
    String[] parsedFiles = getFiles(parsedDir, txtfilter);
    for (int i = 0; i < parsedFiles.length; i++) {
      File file = new File(parsedDir + "/" + parsedFiles[i]);
      if (file.length() > 0) {
        String auth = parsedFiles[i].split("-")[0];
        //					System.out.println("auther is .........."+auth);
        //					System.out.println(rdfDir+"/"+parsedFiles[i].split(".txt")[0]+".rdf");
        Text2RDF t = new Text2RDF(parsedDir + "/" + parsedFiles[i]);
        try {
          t.saveToRdf(rdfDir + "/" + parsedFiles[i].split(".txt")[0] + ".rdf", auth);
        } catch (Exception e) {
          System.out.println(e.getMessage());
        }
      }
    }
    System.out.println("Finish converting to RDF ......at: " + DateUtils.now());
  }