Commit 5064cb93 authored by Volker Krause's avatar Volker Krause
Browse files

Continue cleaning up GenericExtractor::Result

Next step is make it transparent towards the extracted data being available
in JSON-LD or in decoded form.
parent 78a8c6ea
......@@ -539,7 +539,7 @@ void ExtractorEnginePrivate::determineExtractors()
// check if generic extractors identified documents we have custom extractors for
m_repo.extractorsForJsonLd(genericResult.result, m_extractors);
// check the unrecognized (vendor-specific) barcodes, if any
m_repo.extractorsForBarcode(genericResult.barcode.toString(), m_extractors);
m_repo.extractorsForBarcode(genericResult.barcode().toString(), m_extractors);
}
}
......@@ -601,11 +601,11 @@ void ExtractorEnginePrivate::extractCustomForGenericResults()
{
for (const auto &genericResult : m_genericResults) {
// expose genericResult content to custom extractors via Context object
m_context->m_barcode = genericResult.barcode;
m_context->m_barcode = genericResult.barcode();
if (!genericResult.result.empty()) {
m_context->m_data = m_engine.toScriptValue(genericResult.result);
}
m_context->m_pdfPageNum = genericResult.pageNum;
m_context->m_pdfPageNum = genericResult.pageNumber();
// check if generic extractors identified documents we have custom extractors for
const auto prevResults = m_result.size();
......
......@@ -23,7 +23,7 @@ GenericExtractor::Result::Result() = default;
GenericExtractor::Result::Result(const QJsonArray &result, const QVariant &barcode)
: result(result)
, barcode(barcode)
, m_barcode(barcode)
{
}
......@@ -31,5 +31,20 @@ GenericExtractor::Result::~Result() = default;
bool KItinerary::GenericExtractor::Result::isEmpty() const
{
return result.isEmpty() && barcode.isNull();
return result.isEmpty() && m_barcode.isNull();
}
QVariant GenericExtractor::Result::barcode() const
{
return m_barcode;
}
int GenericExtractor::Result::pageNumber() const
{
return m_pageNum;
}
void GenericExtractor::Result::setPageNumber(int pageNum)
{
m_pageNum = pageNum;
}
......@@ -38,10 +38,21 @@ public:
/** Checks if there is any relevant result set in here. */
bool isEmpty() const;
/** Unrecognized barcode for further processing.
* Can be either a QByteArray or a QString.
*/
QVariant barcode() const;
/** Page number, if result is from a single PDF page. */
int pageNumber() const;
void setPageNumber(int pageNum);
public: // TODO
QJsonArray result; // JSON-LD data extracted from this document or page
QVariant barcode; // unrecognized barcode for further processing
int pageNum = -1; // page number, if result is from a single PDF page
private:
QVariant m_barcode;
int m_pageNum = -1;
};
}
......
......@@ -84,7 +84,7 @@ std::vector<GenericExtractor::Result> GenericPdfExtractor::extract(PdfDocument *
auto r = extractImage(img, result);
if (!r.isEmpty()) {
r.pageNum = i;
r.setPageNumber(i);
result.push_back(r);
}
if (img.hasObjectId()) {
......@@ -99,7 +99,7 @@ std::vector<GenericExtractor::Result> GenericPdfExtractor::extract(PdfDocument *
static bool containsBarcodeResult(const std::vector<GenericExtractor::Result> &results, const QVariant &barcode)
{
const auto it = std::find_if(results.begin(), results.end(), [barcode](const auto &result) {
return result.barcode == barcode;
return result.barcode() == barcode;
});
return it != results.end();
}
......
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