• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PARSER_H_
18 #define LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_PARSER_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "annotator/types.h"
25 #include "utils/base/statusor.h"
26 #include "utils/i18n/locale-list.h"
27 #include "utils/i18n/locale.h"
28 #include "utils/utf8/unicodetext.h"
29 
30 namespace libtextclassifier3 {
31 
32 // Parses datetime expressions in the input and resolves them to actual absolute
33 // time.
34 class DatetimeParser {
35  public:
36   virtual ~DatetimeParser() = default;
37 
38   // Parses the dates in 'input' and fills result. Makes sure that the results
39   // do not overlap.
40   // If 'anchor_start_end' is true the extracted results need to start at the
41   // beginning of 'input' and end at the end of it.
42   virtual StatusOr<std::vector<DatetimeParseResultSpan>> Parse(
43       const std::string& input, int64 reference_time_ms_utc,
44       const std::string& reference_timezone, const LocaleList& locale_list,
45       ModeFlag mode, AnnotationUsecase annotation_usecase,
46       bool anchor_start_end) const = 0;
47 
48   // Same as above but takes UnicodeText.
49   virtual StatusOr<std::vector<DatetimeParseResultSpan>> Parse(
50       const UnicodeText& input, int64 reference_time_ms_utc,
51       const std::string& reference_timezone, const LocaleList& locale_list,
52       ModeFlag mode, AnnotationUsecase annotation_usecase,
53       bool anchor_start_end) const = 0;
54 };
55 }  // namespace libtextclassifier3
56 
57 #endif  // LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_PARSER_H_
58