• 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_UTILS_GRAMMAR_TEXT_CONTEXT_H_
18 #define LIBTEXTCLASSIFIER_UTILS_GRAMMAR_TEXT_CONTEXT_H_
19 
20 #include <vector>
21 
22 #include "annotator/types.h"
23 #include "utils/i18n/locale.h"
24 #include "utils/utf8/unicodetext.h"
25 
26 namespace libtextclassifier3::grammar {
27 
28 // Input to the parser.
29 struct TextContext {
30   // Returns a view on a span of the text.
SpanTextContext31   const UnicodeText Span(const CodepointSpan& span) const {
32     return text.Substring(codepoints[span.first], codepoints[span.second],
33                           /*do_copy=*/false);
34   }
35 
36   // The input text.
37   UnicodeText text;
38 
39   // Pre-enumerated codepoints for fast substring extraction.
40   std::vector<UnicodeText::const_iterator> codepoints;
41 
42   // The tokenized input text.
43   std::vector<Token> tokens;
44 
45   // Locales of the input text.
46   std::vector<Locale> locales;
47 
48   // Text annotations.
49   std::vector<AnnotatedSpan> annotations;
50 
51   // The span of tokens to consider.
52   TokenSpan context_span;
53 };
54 
55 };  // namespace libtextclassifier3::grammar
56 
57 #endif  // LIBTEXTCLASSIFIER_UTILS_GRAMMAR_TEXT_CONTEXT_H_
58