summaryrefslogtreecommitdiff
path: root/native/annotator
diff options
context:
space:
mode:
authorTony Mak <tonymak@google.com>2020-05-28 15:25:17 +0100
committerTony Mak <tonymak@google.com>2020-05-28 16:20:31 +0100
commitc121edde42813cdda735d226c51d5fd6538ca039 (patch)
tree923ac7a59ecb6513948acb04c55e982dc6f4da47 /native/annotator
parent9d2d90eaf67374f07f7dbad9e415fd82db29664d (diff)
downloadlibtextclassifier-c121edde42813cdda735d226c51d5fd6538ca039.tar.gz
Export libtextclassifier
Bug: 157134682 Test: atest TextClassifierServiceTest Change-Id: I008e36d4af9bb27e889c68a6b881f87f9878b77d
Diffstat (limited to 'native/annotator')
-rw-r--r--native/annotator/annotator.cc27
-rw-r--r--native/annotator/datetime/extractor.cc1
-rw-r--r--native/annotator/experimental/experimental-dummy.h3
-rwxr-xr-xnative/annotator/experimental/experimental.fbs16
-rw-r--r--native/annotator/grammar/dates/utils/date-match.cc28
5 files changed, 60 insertions, 15 deletions
diff --git a/native/annotator/annotator.cc b/native/annotator/annotator.cc
index 4b11c7e..6ee983f 100644
--- a/native/annotator/annotator.cc
+++ b/native/annotator/annotator.cc
@@ -699,8 +699,8 @@ bool Annotator::InitializePersonNameEngineFromFileDescriptor(int fd, int offset,
bool Annotator::InitializeExperimentalAnnotators() {
if (ExperimentalAnnotator::IsEnabled()) {
- experimental_annotator_.reset(
- new ExperimentalAnnotator(*selection_feature_processor_, *unilib_));
+ experimental_annotator_.reset(new ExperimentalAnnotator(
+ model_->experimental_model(), *selection_feature_processor_, *unilib_));
return true;
}
return false;
@@ -2496,13 +2496,22 @@ bool Annotator::ParseAndFillInMoneyAmount(
LoadAndVerifyMutableFlatbuffer<libtextclassifier3::EntityData>(
*serialized_entity_data);
if (data == nullptr) {
- TC3_LOG(ERROR)
- << "Data field is null when trying to parse Money Entity Data";
+ if (model_->version() >= 706) {
+ // This way of parsing money entity data is enabled for models newer than
+ // v706, consequently logging errors only for them (b/156634162).
+ TC3_LOG(ERROR)
+ << "Data field is null when trying to parse Money Entity Data";
+ }
return false;
}
if (data->money->unnormalized_amount.empty()) {
- TC3_LOG(ERROR) << "Data unnormalized_amount is empty when trying to parse "
- "Money Entity Data";
+ if (model_->version() >= 706) {
+ // This way of parsing money entity data is enabled for models newer than
+ // v706, consequently logging errors only for them (b/156634162).
+ TC3_LOG(ERROR)
+ << "Data unnormalized_amount is empty when trying to parse "
+ "Money Entity Data";
+ }
return false;
}
@@ -2593,7 +2602,11 @@ bool Annotator::RegexChunk(const UnicodeText& context_unicode,
if (regex_pattern.config->collection_name()->str() ==
Collections::Money()) {
if (!ParseAndFillInMoneyAmount(&serialized_entity_data)) {
- TC3_LOG(ERROR) << "Could not parse and fill in money amount.";
+ if (model_->version() >= 706) {
+ // This way of parsing money entity data is enabled for models
+ // newer than v706 => logging errors only for them (b/156634162).
+ TC3_LOG(ERROR) << "Could not parse and fill in money amount.";
+ }
}
}
}
diff --git a/native/annotator/datetime/extractor.cc b/native/annotator/datetime/extractor.cc
index ebcf091..b8e1b7a 100644
--- a/native/annotator/datetime/extractor.cc
+++ b/native/annotator/datetime/extractor.cc
@@ -473,6 +473,7 @@ bool DatetimeExtractor::ParseRelationAndConvertToRelativeCount(
{DatetimeExtractorType_NEXT, 1},
{DatetimeExtractorType_NEXT_OR_SAME, 1},
{DatetimeExtractorType_LAST, -1},
+ {DatetimeExtractorType_PAST, -1},
},
relative_count);
}
diff --git a/native/annotator/experimental/experimental-dummy.h b/native/annotator/experimental/experimental-dummy.h
index 0d50bca..389aae1 100644
--- a/native/annotator/experimental/experimental-dummy.h
+++ b/native/annotator/experimental/experimental-dummy.h
@@ -33,7 +33,8 @@ class ExperimentalAnnotator {
// always disabled;
static constexpr bool IsEnabled() { return false; }
- explicit ExperimentalAnnotator(const FeatureProcessor& feature_processor,
+ explicit ExperimentalAnnotator(const ExperimentalModel* model,
+ const FeatureProcessor& feature_processor,
const UniLib& unilib) {}
bool Annotate(const UnicodeText& context,
diff --git a/native/annotator/experimental/experimental.fbs b/native/annotator/experimental/experimental.fbs
index fff2d9e..6e15d04 100755
--- a/native/annotator/experimental/experimental.fbs
+++ b/native/annotator/experimental/experimental.fbs
@@ -1,3 +1,19 @@
+//
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
namespace libtextclassifier3;
table ExperimentalModel {
}
diff --git a/native/annotator/grammar/dates/utils/date-match.cc b/native/annotator/grammar/dates/utils/date-match.cc
index 1ab1e6a..d9fca52 100644
--- a/native/annotator/grammar/dates/utils/date-match.cc
+++ b/native/annotator/grammar/dates/utils/date-match.cc
@@ -225,6 +225,18 @@ DatetimeComponent::RelativeQualifier DateMatch::GetRelativeQualifier() const {
return DatetimeComponent::RelativeQualifier::UNSPECIFIED;
}
+// Embed RelativeQualifier information of DatetimeComponent as a sign of
+// relative counter field of datetime component i.e. relative counter is
+// negative when relative qualifier RelativeQualifier::PAST.
+int GetAdjustedRelativeCounter(
+ const DatetimeComponent::RelativeQualifier& relative_qualifier,
+ const int relative_counter) {
+ if (DatetimeComponent::RelativeQualifier::PAST == relative_qualifier) {
+ return -relative_counter;
+ }
+ return relative_counter;
+}
+
Optional<DatetimeComponent> CreateDatetimeComponent(
const DatetimeComponent::ComponentType& component_type,
const DatetimeComponent::RelativeQualifier& relative_qualifier,
@@ -232,13 +244,15 @@ Optional<DatetimeComponent> CreateDatetimeComponent(
if (absolute_value == NO_VAL && relative_value == NO_VAL) {
return Optional<DatetimeComponent>();
}
- return Optional<DatetimeComponent>(
- DatetimeComponent(component_type,
- (relative_value != NO_VAL)
- ? relative_qualifier
- : DatetimeComponent::RelativeQualifier::UNSPECIFIED,
- (absolute_value != NO_VAL) ? absolute_value : 0,
- (relative_value != NO_VAL) ? relative_value : 0));
+ return Optional<DatetimeComponent>(DatetimeComponent(
+ component_type,
+ (relative_value != NO_VAL)
+ ? relative_qualifier
+ : DatetimeComponent::RelativeQualifier::UNSPECIFIED,
+ (absolute_value != NO_VAL) ? absolute_value : 0,
+ (relative_value != NO_VAL)
+ ? GetAdjustedRelativeCounter(relative_qualifier, relative_value)
+ : 0));
}
Optional<DatetimeComponent> CreateDayOfWeekComponent(