Commit dd91eb47 authored by Volker Krause's avatar Volker Krause
Browse files

Add templates for restaurant and rental car reservations as well

Adapt extractor scripts accordingly.
parent 0d029a2a
......@@ -121,7 +121,7 @@ QJSValue JsApi::JsonLd::newLodgingReservation() const
return res;
}
QJSValue KItinerary::JsApi::JsonLd::newEventReservation() const
QJSValue JsApi::JsonLd::newEventReservation() const
{
auto resFor = newObject(QStringLiteral("Event"));
resFor.setProperty(QStringLiteral("location"), newPlace(QStringLiteral("Place")));
......@@ -138,6 +138,37 @@ QJSValue KItinerary::JsApi::JsonLd::newEventReservation() const
return res;
}
QJSValue JsApi::JsonLd::newFoodEstablishmentReservation() const
{
const auto person = newObject(QStringLiteral("Person"));
const auto resFor = newPlace(QStringLiteral("FoodEstablishment"));
auto res = newObject(QStringLiteral("FoodEstablishmentReservation"));
res.setProperty(QStringLiteral("reservationFor"), resFor);
res.setProperty(QStringLiteral("underName"), person);
return res;
}
QJSValue JsApi::JsonLd::newRentalCarReservation() const
{
const auto pickup = newPlace(QStringLiteral("Place"));
const auto dropoff = newPlace(QStringLiteral("Place"));
const auto person = newObject(QStringLiteral("Person"));
const auto org = newObject(QStringLiteral("Organization"));
auto resFor = newObject(QStringLiteral("RentalCar"));
resFor.setProperty(QStringLiteral("rentalCompany"), org);
auto res = newObject(QStringLiteral("RentalCarReservation"));
res.setProperty(QStringLiteral("reservationFor"), resFor);
res.setProperty(QStringLiteral("pickupLocation"), pickup);
res.setProperty(QStringLiteral("dropoffLocation"), dropoff);
res.setProperty(QStringLiteral("underName"), person);
return res;
}
QDateTime JsApi::JsonLd::toDateTime(const QString &dtStr, const QString &format, const QString &localeName) const
{
QLocale locale(localeName);
......
......@@ -48,7 +48,14 @@ public:
* This can be used by extractor scripts to fill in the extracted information.
*/
Q_INVOKABLE QJSValue newEventReservation() const;
// TODO add the same for restaurant and car rental reservation types
/** Convenience method that generates a full FoodEstablishmentReservation JS object.
* This can be used by extractor scripts to fill in the extracted information.
*/
Q_INVOKABLE QJSValue newFoodEstablishmentReservation() const;
/** Convenience method that generates a full RentalCarReservation JS object.
* This can be used by extractor scripts to fill in the extracted information.
*/
Q_INVOKABLE QJSValue newRentalCarReservation() const;
/** Convert a date/time string to a date/time value.
* @param dtStr The input string containing a date/time value.
......
......@@ -7,12 +7,10 @@
function parseEvent(event)
{
var res;
res = JsonLd.newObject("FoodEstablishmentReservation");
res.reservationFor = JsonLd.newObject("FoodEstablishment");
res = JsonLd.newFoodEstablishmentReservation();
res.reservationFor.name = event.organizer.name;
res.startTime = event.dtStart.toJSON();
res.endTime = event.dtEnd.toJSON();
res.reservationFor.address = JsonLd.newObject("PostalAddress");
var addr = event.location.split(', ');
res.reservationFor.address.streetAddress = addr[1];
res.reservationFor.address.addressLocality = addr[2];
......@@ -32,7 +30,6 @@ function parseEvent(event)
res.reservationFor.url = url[1];
if (event.attendees.length > 0) {
res.underName = JsonLd.newObject("Person");
res.underName.name = event.attendees[0].name;
res.underName.email = event.attendees[0].email;
}
......
......@@ -5,7 +5,7 @@
*/
function main(text) {
var res = JsonLd.newObject("RentalCarReservation");
var res = JsonLd.newRentalCarReservation();
var bookingRef = text.match(/Your reservation number is\s+([A-Z0-9-]+)\s+/);
if (!bookingRef)
......@@ -13,7 +13,6 @@ function main(text) {
res.reservationNumber = bookingRef[1];
var idx = bookingRef.index + bookingRef[0].length;
res.underName = JsonLd.newObject("Person");
var name = text.substr(idx).match(/Customer Name:\s+(.*)/);
if (!name)
return null;
......@@ -25,8 +24,6 @@ function main(text) {
return null;
idx += renting.index + renting[0].length;
var cityPickup = text.substr(idx).match(/City:\s+(.*)/);
res.pickupLocation = JsonLd.newObject("Place");
res.pickupLocation.address = JsonLd.newObject("PostalAddress");
res.pickupLocation.address.addressLocality = cityPickup[1];
idx += cityPickup.index + cityPickup[0].length;
......@@ -53,8 +50,6 @@ function main(text) {
return null;
idx += returnCar.index + returnCar[0].length;
var cityDropoff = text.substr(idx).match(/City:\s+(.*)/);
res.dropoffLocation = JsonLd.newObject("Place");
res.dropoffLocation.address = JsonLd.newObject("PostalAddress");
res.dropoffLocation.address.addressLocality = cityDropoff[1];
idx += cityDropoff.index + cityDropoff[0].length;
......@@ -74,7 +69,6 @@ function main(text) {
res.dropoffTime = JsonLd.toDateTime(dropOffDate[1], "ddd dd MMM yyyy hh:mm A", "en");
idx += dropOffDate.index + dropOffDate[0].length;
res.reservationFor = JsonLd.newObject("RentalCar");
//Fix me it seems to use 2 lines !
var vehiculeType = text.substr(idx).match(/Vehicle:\s+(.*)\s+/)
if (!vehiculeType)
......@@ -82,7 +76,6 @@ function main(text) {
res.reservationFor.model = vehiculeType[1];
idx += vehiculeType.index + vehiculeType[0].length;
res.reservationFor.rentalCompany = JsonLd.newObject("Organization");
res.reservationFor.rentalCompany.name = "Hertz"
return res;
......
......@@ -26,15 +26,11 @@ function parseEvent(event)
res.reservationFor.arrivalAirport.name = to[1];
} else if (event.summary.startsWith("Mietwagen")) {
res = JsonLd.newObject("RentalCarReservation");
res.reservationFor = JsonLd.newObject("RentalCar");
res.reservationFor.rentalCompany = JsonLd.newObject("Organization");
res = JsonLd.newRentalCarReservation();
res.pickupLocation = JsonLd.newObject("Place");
var pickup = event.description.match(/Abgabeort:\s*(.*)\n/);
res.pickupLocation.name = pickup[1]; // TODO split address
res.dropoffLocation = JsonLd.newObject("Place");
var dropoff = event.description.match(/Annahmeort:\s*(.*)\n/);
res.dropoffLocation.name = dropoff[1]; // TODO dito
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment