Commit 4f80b585 authored by Volker Krause's avatar Volker Krause
Browse files

Remove the now unused Context API for extractor scripts

This has been entirely replaced by passing the triggering document tree
node to the extractor method.
parent d684a25d
Pipeline #62793 passed with stages
in 12 minutes and 16 seconds
......@@ -53,6 +53,5 @@ function dumpArgs(content, node, triggerNode)
res.push(wrapper);
res.push(dumpValue(node, 6));
res.push({ triggerNodeEqualsNode: triggerNode == node });
res.push(dumpValue(Context, 6));
return res;
}
......@@ -60,30 +60,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"barcode": "#UT010080000020,\u0002\u0014\u001a绥\u0005��\u001e\r\bh�p���;�\u001bb\u0002\u0014i�ӈ|\u0003W������������\u001f",
"data": [
{
"@type": "TrainReservation",
"reservationNumber": "9E8DXL",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecbin:I1VUMDEwMDgwMDAwMDIwLAIUGue7pQWksx4NCGj9cJzioDvHG2ICFGnc04h8A1eHmpP6hrOkqvuyoaofAAAAADAzNzR4nH2Rv07CUBTGkUFdXHyCJi5QqZ57+p8NbCsNFJMWCMhAiGhsQDSlkuiTsLk4ysqig0lfwEE3H8Zz5Y+YGDvcfvc7v/vd09N6p2QXLGAAqgxggGkbVrMi6am1h+mACAyZygywbMvmoGsBApBhMpQV7hQr5CjMBIVoX3Fa1qnaWg/CRQ4a87eBqmpq5KNvOdis1sveX7QG8oqmOKYFwPtlrHodXXUHN9F5OCKLuiGKhMxFgYSyFCYJDSUmMTMghttAgtcxoCNMJaWWk9lgSBuNZzlRd9i/uI3ijNcNh9n9ozC+o5r+T81YC0HG+2i4hbxQ809cMXCPi6JXEyuemHFKh47jOVmiqFVUL5PHZJa8RIJP4kHoJ9Ozfkfq5A8I0HiL/Kvw+2bqG5mp82krNBONj55qdLOMP+dyozh5Fvy938H8UKPOJ2fMf0o6Tcv7JN56m4xz7dRGrv26GP3T9ufmzmR8vxvS5mNB9IjoLYnpivgC6qKSSw==",
"ticketedSeat": {
"@type": "Seat",
"seatingType": "2"
}
},
"underName": {
"@context": "http://schema.org",
"@type": "Person",
"familyName": "häöür Räß",
"givenName": "kíck_-_:.,stû R"
}
}
],
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -87,9 +87,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -71,42 +71,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"data": [
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "UA",
"name": "United"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "JFK",
"name": "John F. Kennedy International Airport"
},
"arrivalTime": "2027-03-05T06:30:00-05:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "SFO",
"name": "San Francisco Airport"
},
"departureTime": "2027-03-04T20:15:00-08:00",
"flightNumber": "110"
},
"reservationNumber": "RXJ34P",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"@type": "Person",
"name": "Eva Green"
}
}
],
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -77,9 +77,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -89,9 +89,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -14,10 +14,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"barcode": "Hello World!\n",
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -553,53 +553,5 @@
},
{
"triggerNodeEqualsNode": true
},
{
"data": [
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"airplaneSeat": "10E",
"passengerSequenceNumber": "143",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "LX",
"name": "SWISS"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "TXL"
},
"boardingTime": "0001-01-01T20:25:00",
"departureAirport": {
"@type": "Airport",
"geo": {
"@type": "GeoCoordinates",
"latitude": 47.452301025390625,
"longitude": 8.560830116271973
},
"iataCode": "ZRH"
},
"departureDay": "",
"departureGate": "AB",
"flightNumber": "962"
},
"reservationNumber": "XXX007",
"reservationStatus": "http://schema.org/ReservationConfirmed",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:M1KRAUSE/VOLKER EXXX007 ZRHTXLLX 0962 258Y010E0143 15D>5180 M7258BLX 2A724xxxxxxxxxx0 LX LH 123456789012345 N*30600000K09 "
},
"underName": {
"@type": "Person",
"familyName": "KRAUSE",
"givenName": "VOLKER"
}
}
],
"objectName": "",
"pdfPageNumber": -1
}
]
......@@ -44,7 +44,6 @@ set(kitinerary_lib_srcs
jsapi/barcode.cpp
jsapi/bitarray.cpp
jsapi/context.cpp
jsapi/jsonld.cpp
knowledgedb/alphaid.cpp
......
......@@ -12,12 +12,8 @@
#include "logging.h"
#include "jsapi/barcode.h"
#include "jsapi/context.h"
#include "jsapi/jsonld.h"
#include <KItinerary/Uic9183Parser>
#include <KItinerary/VdvTicket>
#include <QFile>
#include <QJSEngine>
#include <QJSValueIterator>
......@@ -31,7 +27,6 @@ public:
bool loadScript(const QString &fileName);
JsApi::Barcode *m_barcodeApi = nullptr;
JsApi::Context *m_context = nullptr;
JsApi::JsonLd *m_jsonLdApi = nullptr;
QJSEngine m_engine;
};
......@@ -47,13 +42,11 @@ void ExtractorScriptEngine::ensureInitialized()
}
d = std::make_unique<ExtractorScriptEnginePrivate>();
d->m_context = new JsApi::Context; // will be deleted by QJSEngine taking ownership
d->m_engine.installExtensions(QJSEngine::ConsoleExtension);
d->m_jsonLdApi = new JsApi::JsonLd(&d->m_engine);
d->m_engine.globalObject().setProperty(QStringLiteral("JsonLd"), d->m_engine.newQObject(d->m_jsonLdApi));
d->m_barcodeApi = new JsApi::Barcode;
d->m_engine.globalObject().setProperty(QStringLiteral("Barcode"), d->m_engine.newQObject(d->m_barcodeApi));
d->m_engine.globalObject().setProperty(QStringLiteral("Context"), d->m_engine.newQObject(d->m_context));
}
void ExtractorScriptEngine::setBarcodeDecoder(BarcodeDecoder *barcodeDecoder)
......@@ -114,31 +107,6 @@ ExtractorResult ExtractorScriptEngine::execute(const ScriptExtractor *extractor,
triggerNode.setScriptEngine(nullptr);
});
// ### legacy context API, replace that by passing trigger node as a third argument eventually
if (triggerNode.result().isEmpty()) {
d->m_context->m_data = {};
} else {
d->m_context->m_data = d->m_engine.toScriptValue(triggerNode.result().jsonLdResult());
}
if (triggerNode.isA<Uic9183Parser>()) {
d->m_context->m_barcode = triggerNode.content<Uic9183Parser>().rawData();
} else if (triggerNode.isA<VdvTicket>()) {
d->m_context->m_barcode = triggerNode.content<VdvTicket>().rawData();
} else if (triggerNode.isA<QByteArray>()) {
d->m_context->m_barcode = triggerNode.content<QByteArray>();
} else if (triggerNode.isA<QString>()) {
d->m_context->m_barcode = triggerNode.content().toString();
} else {
d->m_context->m_barcode.clear();
}
if (triggerNode.location().isNull()) {
d->m_context->m_pdfPageNum = -1;
} else {
d->m_context->m_pdfPageNum = triggerNode.location().toInt();
}
d->m_jsonLdApi->setContextDate(node.contextDateTime());
d->m_barcodeApi->setContextDate(node.contextDateTime());
......
/*
SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "context.h"
using namespace KItinerary;
QJSValue JsApi::Context::data() const
{
return m_data;
}
void JsApi::Context::reset()
{
m_barcode = {};
m_pdfPageNum = -1;
m_data = {};
}
/*
SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QDateTime>
#include <QJSValue>
#include <QObject>
#include <QVariant>
namespace KItinerary {
/** JavaScript API exposed to extractor scripts.
* @see ExtractorEngine
*/
namespace JsApi {
/** The extraction context.
* This object contains information about what is being extracted,
* or where the extracted information is coming from.
*/
class Context : public QObject
{
Q_OBJECT
/** The PDF page number (0-based) if the extractor was triggered by
* content found in a PDF file (typically a barcode).
*/
Q_PROPERTY(int pdfPageNumber MEMBER m_pdfPageNum)
/** If the extractor was triggered by a barcode, this contains the
* corresponding barcode content (either as string or as byte array).
*/
Q_PROPERTY(QVariant barcode MEMBER m_barcode)
/** If the extractor was triggered by results from a preceding generic
* extractor run, this property contains the generic extraction results.
* A typical example are e.g. information retrieved from an IATA barcode.
* This can be used by the extractor script to augment generic extraction results.
*/
Q_PROPERTY(QJSValue data READ data)
public:
///@cond internal
/** Reset context information that are only relevant for a single run. */
QJSValue data() const;
void reset();
QVariant m_barcode;
QJSValue m_data;
int m_pdfPageNum = -1;
///@endcond
};
}
}
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