Пример #1
0
  public void gatherData(ObjectBundle bundle) {
    if (haveToGeneratePrefixes) {
      generatePrefixes();
      haveToGeneratePrefixes = false;
    }
    Iterator<BSBMResource> it = bundle.iterator();

    try {
      while (it.hasNext()) {
        BSBMResource obj = it.next();

        // If modular generation is applied
        if (Generator.noOfMachines != -1) {
          if (((currentWriter + 1) % Generator.noOfMachines == Generator.thisMachineId)) {
            if (obj instanceof ProductType) {
              dataFileWriter[currentWriter].append(convertProductType((ProductType) obj));
            } else if (obj instanceof Offer) {
              dataFileWriter[currentWriter].append(convertOffer((Offer) obj));
            } else if (obj instanceof Product) {
              dataFileWriter[currentWriter].append(convertProduct((Product) obj));
            } else if (obj instanceof Person) {
              dataFileWriter[currentWriter].append(convertPerson((Person) obj, bundle));
            } else if (obj instanceof Producer) {
              dataFileWriter[currentWriter].append(convertProducer((Producer) obj));
            } else if (obj instanceof ProductFeature) {
              dataFileWriter[currentWriter].append(convertProductFeature((ProductFeature) obj));
            } else if (obj instanceof Vendor) {
              dataFileWriter[currentWriter].append(convertVendor((Vendor) obj));
            } else if (obj instanceof Review) {
              dataFileWriter[currentWriter].append(convertReview((Review) obj, bundle));
            }
          }
        } else if (currentWriter > (Generator.fromFileId - 2)
            && currentWriter < Generator.toFileId) {
          if (obj instanceof ProductType) {
            dataFileWriter[currentWriter].append(convertProductType((ProductType) obj));
          } else if (obj instanceof Offer) {
            dataFileWriter[currentWriter].append(convertOffer((Offer) obj));
          } else if (obj instanceof Product) {
            dataFileWriter[currentWriter].append(convertProduct((Product) obj));
          } else if (obj instanceof Person) {
            dataFileWriter[currentWriter].append(convertPerson((Person) obj, bundle));
          } else if (obj instanceof Producer) {
            dataFileWriter[currentWriter].append(convertProducer((Producer) obj));
          } else if (obj instanceof ProductFeature) {
            dataFileWriter[currentWriter].append(convertProductFeature((ProductFeature) obj));
          } else if (obj instanceof Vendor) {
            dataFileWriter[currentWriter].append(convertVendor((Vendor) obj));
          } else if (obj instanceof Review) {
            dataFileWriter[currentWriter].append(convertReview((Review) obj, bundle));
          }
        }
        currentWriter = (currentWriter + 1) % dataFileWriter.length;
      }
    } catch (IOException e) {
      System.err.println("Could not write into File!");
      System.err.println(e.getMessage());
      System.exit(-1);
    }
  }
Пример #2
0
 public void serialize() {
   // Close files
   try {
     for (int i = 0; i < dataFileWriter.length; i++) {
       if (Generator.noOfMachines != -1) {
         if (((i + 1) % Generator.noOfMachines) == Generator.thisMachineId) {
           dataFileWriter[i].flush();
           dataFileWriter[i].close();
         }
       } else if (i > (Generator.fromFileId - 2) && i < Generator.toFileId) {
         dataFileWriter[i].flush();
         dataFileWriter[i].close();
       }
     }
   } catch (IOException e) {
     System.err.println(e.getMessage());
     System.exit(-1);
   }
 }
Пример #3
0
  public Turtle(String file, boolean forwardChaining, int nrOfOutputFiles) {
    int nrOfDigits = ((int) Math.log10(nrOfOutputFiles)) + 1;
    String formatString = "%0" + nrOfDigits + "d";
    try {
      dataFileWriter = new FileWriter[nrOfOutputFiles];
      if (nrOfOutputFiles == 1) this.dataFileWriter[0] = new FileWriter(file + ".ttl");
      else
        for (int i = 1; i <= nrOfOutputFiles; i++) {
          if (Generator.noOfMachines != -1) {
            if (i % Generator.noOfMachines == Generator.thisMachineId) {
              dataFileWriter[i - 1] =
                  new FileWriter(file + String.format(formatString, i) + ".ttl");
            }
          } else if (i > (Generator.fromFileId - 1) && i < (Generator.toFileId + 1)) {
            dataFileWriter[i - 1] = new FileWriter(file + String.format(formatString, i) + ".ttl");
          }
        }

    } catch (IOException e) {
      System.err.println("Could not open File for writing.");
      System.err.println(e.getMessage());
      System.exit(-1);
    }

    try {
      for (int i = 0; i < nrOfOutputFiles; i++)
        if (Generator.noOfMachines != -1) {
          if (((i + 1) % Generator.noOfMachines) == Generator.thisMachineId) {
            dataFileWriter[i].append(getNamespaces());
          }
        } else if (i > (Generator.fromFileId - 2) && i < Generator.toFileId) {
          dataFileWriter[i].append(getNamespaces());
        }
    } catch (IOException e) {
      System.err.println(e.getMessage());
    }

    this.forwardChaining = forwardChaining;
    nrTriples = 0l;

    TurtleShutdown sd = new TurtleShutdown(this);
    Runtime.getRuntime().addShutdownHook(sd);
  }