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