KItinerary

extractorpostprocessor.h
1 /*
2  SPDX-FileCopyrightText: 2017 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "kitinerary_export.h"
10 
11 #include <QVariant>
12 #include <QVector>
13 
14 #include <memory>
15 
16 namespace KItinerary {
17 
18 class ExtractorPostprocessorPrivate;
19 
20 /** Post-process extracted data to filter out garbage and augment data from other sources.
21  *
22  * In detail, this performs the tasks listed below for all data elements fed into it.
23  *
24  * @section postproc_normalize Normalization
25  *
26  * Basic normalization for e.g. renamed properties of older schema.org versions is already
27  * covered by JsonLdImportFilter, post-processing covers the more elaborate normalization steps,
28  * such as:
29  * - translate human readable and possibly localized country names into ISO 3166-1 codes.
30  * - expand IATA BCBP ticket tokens (see IataParser).
31  *
32  * @section postproc_augment Augmentation
33  *
34  * That is, add additional information derived from a built-in knowledge base (see KnowledgeDb).
35  * This includes:
36  * - Add timezone information to arrival and departure times.
37  * - Add geo coordinates and country information to known airports or train stations.
38  *
39  * @section postproc_merge Merge Duplicates
40  *
41  * Duplicate elements that might have been the result of two overlapping extractors (e.g. when
42  * extracting two different MIME parts of an email referring to the same reservation) are merged.
43  *
44  * @section postproc_validation Validation
45  *
46  * At this point, all invalid elements are discarded. The definition of invalid is fairly loose though,
47  * and typically only covers elements that are explicitly considered unusable. Examples:
48  * - A Flight missing a departure day or destination.
49  * - A LodigingReservation without an attached LodgingBusiness.
50  * - etc.
51  *
52  * Validation can be disabled and done separately using KItinerary::ExtractorValidator, in case you
53  * want more control over which elements are considered valid. See setValidationEnabled().
54  *
55  * @section postproc_sort Sorting
56  *
57  * Finally the remaining elements are sorted based on their relevant date (see SortUtil). This
58  * makes the data usable for basic display right away, but it for example doesn't do multi-traveler
59  * aggregation, that's still left for the display layer.
60  */
61 class KITINERARY_EXPORT ExtractorPostprocessor
62 {
63 public:
68 
69  /** This will normalize and augment the given data elements and merge them with
70  * already added data elements if applicable.
71  */
72  void process(const QVector<QVariant> &data);
73 
74  /** This returns the final result of all previously executed processing steps
75  * followed by sorting and filtering out all invalid data elements.
76  */
77  QVector<QVariant> result() const;
78 
79  /** The date the reservation(s) processed here have been made, if known.
80  * This is used for determining the year of incomplete dates provided by
81  * various sources. Therefore this has to be somewhen before the reservation
82  * becomes due.
83  */
84  void setContextDate(const QDateTime &dt);
85 
86  /** Enable or disable validation.
87  * By default this is enabled, and will discard all unknown types
88  * and incomplete items. If you need more control over this, disable
89  * this here and pass the items through ExtractorValidator yourself
90  * (or even use an entirely different validation mechanism entirely).
91  * @see ExtractorValidator.
92  */
93  void setValidationEnabled(bool validate);
94 
95 private:
96  std::unique_ptr<ExtractorPostprocessorPrivate> d;
97 };
98 
99 }
100 
Post-process extracted data to filter out garbage and augment data from other sources.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Jun 28 2022 04:02:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.