예제 #1
0
파일: Turtle.java 프로젝트: xgfd/SSBLD
  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
파일: Turtle.java 프로젝트: xgfd/SSBLD
  /*
   * Converts the Person Object into an TriG String
   * representation.
   */
  private String convertPerson(Person person, ObjectBundle bundle) {
    StringBuffer result = new StringBuffer();
    // First the uriref for the subject

    result.append(Person.getPrefixed(person.getNr(), bundle.getPublisherNum()));
    result.append("\n");

    // rdf:type
    result.append(createTriplePO(RDF.prefixed("type"), FOAF.prefixed("Person")));

    // foaf:name
    result.append(createTriplePO(FOAF.prefixed("name"), createLiteral(person.getName())));

    // foaf:mbox_sha1sum
    result.append(
        createTriplePO(FOAF.prefixed("mbox_sha1sum"), createLiteral(person.getMbox_sha1sum())));

    // bsbm:country
    result.append(
        createTriplePO(
            BSBM.prefixed("country"), createURIref(ISO3166.find(person.getCountryCode()))));

    // dc:publisher
    result.append(
        createTriplePO(DC.prefixed("publisher"), RatingSite.getPrefixed(person.getPublisher())));

    // dc:date
    GregorianCalendar date = new GregorianCalendar();
    date.setTimeInMillis(person.getPublishDate());
    String dateString = DateGenerator.formatDate(date);
    result.append(
        createTriplePOEnd(
            DC.prefixed("date"), createDataTypeLiteral(dateString, XSD.prefixed("date"))));

    return result.toString();
  }
예제 #3
0
파일: Turtle.java 프로젝트: xgfd/SSBLD
  /*
   * Converts the Review Object into an TriG String
   * representation.
   */
  private String convertReview(Review review, ObjectBundle bundle) {
    StringBuffer result = new StringBuffer();
    // First the uriref for the subject

    result.append(Review.getPrefixed(review.getNr(), bundle.getPublisherNum()));
    result.append("\n");

    // rdf:type
    result.append(createTriplePO(RDF.prefixed("type"), BSBM.prefixed("Review")));

    // bsbm:reviewFor
    result.append(
        createTriplePO(
            BSBM.prefixed("reviewFor"),
            Product.getPrefixed(review.getProduct(), review.getProducerOfProduct())));

    // rev:reviewer
    result.append(
        createTriplePO(
            REV.prefixed("reviewer"),
            Person.getPrefixed(review.getPerson(), review.getPublisher())));

    // dc:title
    result.append(createTriplePO(DC.prefixed("title"), createLiteral(review.getTitle())));

    // rev:text
    result.append(
        createTriplePO(
            REV.prefixed("text"),
            createLanguageLiteral(review.getText(), ISO3166.language[review.getLanguage()])));

    // bsbm:ratingX
    Integer[] ratings = review.getRatings();
    for (int i = 0, j = 1; i < ratings.length; i++, j++) {
      Integer value = ratings[i];
      if (value != null)
        result.append(
            createTriplePO(
                BSBM.getRatingPrefix(j),
                //                        createDataTypeLiteral(value.toString(),
                // XSD.prefixed("integer"))
                value.toString()));
    }

    // bsbm:reviewDate
    GregorianCalendar reviewDate = new GregorianCalendar();
    reviewDate.setTimeInMillis(review.getReviewDate());
    String reviewDateString = DateGenerator.formatDateTime(reviewDate);
    result.append(
        createTriplePO(
            BSBM.prefixed("reviewDate"),
            createDataTypeLiteral(reviewDateString, XSD.prefixed("dateTime"))));

    // dc:publisher
    result.append(
        createTriplePO(DC.prefixed("publisher"), RatingSite.getPrefixed(review.getPublisher())));

    // dc:date
    GregorianCalendar date = new GregorianCalendar();
    date.setTimeInMillis(review.getPublishDate());
    String dateString = DateGenerator.formatDate(date);
    result.append(
        createTriplePOEnd(
            DC.prefixed("date"), createDataTypeLiteral(dateString, XSD.prefixed("date"))));

    return result.toString();
  }