1*993b0882SAndroid Build Coastguard Worker /* 2*993b0882SAndroid Build Coastguard Worker * Copyright (C) 2018 The Android Open Source Project 3*993b0882SAndroid Build Coastguard Worker * 4*993b0882SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*993b0882SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*993b0882SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*993b0882SAndroid Build Coastguard Worker * 8*993b0882SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*993b0882SAndroid Build Coastguard Worker * 10*993b0882SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*993b0882SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*993b0882SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*993b0882SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*993b0882SAndroid Build Coastguard Worker * limitations under the License. 15*993b0882SAndroid Build Coastguard Worker */ 16*993b0882SAndroid Build Coastguard Worker 17*993b0882SAndroid Build Coastguard Worker #ifndef LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_GRAMMAR_PARSER_H_ 18*993b0882SAndroid Build Coastguard Worker #define LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_GRAMMAR_PARSER_H_ 19*993b0882SAndroid Build Coastguard Worker 20*993b0882SAndroid Build Coastguard Worker #include <string> 21*993b0882SAndroid Build Coastguard Worker #include <vector> 22*993b0882SAndroid Build Coastguard Worker 23*993b0882SAndroid Build Coastguard Worker #include "annotator/datetime/datetime-grounder.h" 24*993b0882SAndroid Build Coastguard Worker #include "annotator/datetime/parser.h" 25*993b0882SAndroid Build Coastguard Worker #include "annotator/model_generated.h" 26*993b0882SAndroid Build Coastguard Worker #include "annotator/types.h" 27*993b0882SAndroid Build Coastguard Worker #include "utils/base/statusor.h" 28*993b0882SAndroid Build Coastguard Worker #include "utils/grammar/analyzer.h" 29*993b0882SAndroid Build Coastguard Worker #include "utils/i18n/locale-list.h" 30*993b0882SAndroid Build Coastguard Worker #include "utils/utf8/unicodetext.h" 31*993b0882SAndroid Build Coastguard Worker 32*993b0882SAndroid Build Coastguard Worker namespace libtextclassifier3 { 33*993b0882SAndroid Build Coastguard Worker 34*993b0882SAndroid Build Coastguard Worker // Parses datetime expressions in the input and resolves them to actual absolute 35*993b0882SAndroid Build Coastguard Worker // time. 36*993b0882SAndroid Build Coastguard Worker class GrammarDatetimeParser : public DatetimeParser { 37*993b0882SAndroid Build Coastguard Worker public: 38*993b0882SAndroid Build Coastguard Worker explicit GrammarDatetimeParser(const grammar::Analyzer& analyzer, 39*993b0882SAndroid Build Coastguard Worker const DatetimeGrounder& datetime_grounder, 40*993b0882SAndroid Build Coastguard Worker const float target_classification_score, 41*993b0882SAndroid Build Coastguard Worker const float priority_score, 42*993b0882SAndroid Build Coastguard Worker ModeFlag enabled_modes); 43*993b0882SAndroid Build Coastguard Worker 44*993b0882SAndroid Build Coastguard Worker // Parses the dates in 'input' and fills result. Makes sure that the results 45*993b0882SAndroid Build Coastguard Worker // do not overlap. 46*993b0882SAndroid Build Coastguard Worker // If 'anchor_start_end' is true the extracted results need to start at the 47*993b0882SAndroid Build Coastguard Worker // beginning of 'input' and end at the end of it. 48*993b0882SAndroid Build Coastguard Worker StatusOr<std::vector<DatetimeParseResultSpan>> Parse( 49*993b0882SAndroid Build Coastguard Worker const std::string& input, int64 reference_time_ms_utc, 50*993b0882SAndroid Build Coastguard Worker const std::string& reference_timezone, const LocaleList& locale_list, 51*993b0882SAndroid Build Coastguard Worker ModeFlag mode, AnnotationUsecase annotation_usecase, 52*993b0882SAndroid Build Coastguard Worker bool anchor_start_end) const override; 53*993b0882SAndroid Build Coastguard Worker 54*993b0882SAndroid Build Coastguard Worker // Same as above but takes UnicodeText. 55*993b0882SAndroid Build Coastguard Worker StatusOr<std::vector<DatetimeParseResultSpan>> Parse( 56*993b0882SAndroid Build Coastguard Worker const UnicodeText& input, int64 reference_time_ms_utc, 57*993b0882SAndroid Build Coastguard Worker const std::string& reference_timezone, const LocaleList& locale_list, 58*993b0882SAndroid Build Coastguard Worker ModeFlag mode, AnnotationUsecase annotation_usecase, 59*993b0882SAndroid Build Coastguard Worker bool anchor_start_end) const override; 60*993b0882SAndroid Build Coastguard Worker 61*993b0882SAndroid Build Coastguard Worker private: 62*993b0882SAndroid Build Coastguard Worker const grammar::Analyzer& analyzer_; 63*993b0882SAndroid Build Coastguard Worker const DatetimeGrounder& datetime_grounder_; 64*993b0882SAndroid Build Coastguard Worker const float target_classification_score_; 65*993b0882SAndroid Build Coastguard Worker const float priority_score_; 66*993b0882SAndroid Build Coastguard Worker const ModeFlag enabled_modes_; 67*993b0882SAndroid Build Coastguard Worker }; 68*993b0882SAndroid Build Coastguard Worker 69*993b0882SAndroid Build Coastguard Worker } // namespace libtextclassifier3 70*993b0882SAndroid Build Coastguard Worker 71*993b0882SAndroid Build Coastguard Worker #endif // LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_GRAMMAR_PARSER_H_ 72