Removed language_detection_result and moved the necessary containers to language_detector.h
This commit is contained in:
parent
882ec323f0
commit
91c5f84f9c
|
@ -99,17 +99,24 @@ cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "language_detection_result",
|
||||
hdrs = ["language_detection_result.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "language_detection_result_converter",
|
||||
srcs = ["language_detection_result_converter.cc"],
|
||||
hdrs = ["language_detection_result_converter.h"],
|
||||
deps = [
|
||||
":language_detection_result",
|
||||
"//mediapipe/tasks/c/text/language_detector:language_detector",
|
||||
"//mediapipe/tasks/cc/text/language_detector:language_detector",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "language_detection_result_converter_test",
|
||||
srcs = ["language_detection_result_converter_test.cc"],
|
||||
deps = [
|
||||
":language_detection_result_converter",
|
||||
"//mediapipe/framework/port:gtest",
|
||||
"//mediapipe/tasks/c/text/language_detector:language_detector",
|
||||
"//mediapipe/tasks/cc/text/language_detector:language_detector",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/* Copyright 2023 The MediaPipe Authors.
|
||||
|
||||
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.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_LANGUAGE_DETECTION_RESULT_H_
|
||||
#define MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_LANGUAGE_DETECTION_RESULT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// A language code and its probability.
|
||||
struct LanguageDetectorPrediction {
|
||||
// An i18n language / locale code, e.g. "en" for English, "uz" for Uzbek,
|
||||
// "ja"-Latn for Japanese (romaji).
|
||||
char* language_code;
|
||||
|
||||
float probability;
|
||||
};
|
||||
|
||||
// Task output.
|
||||
struct LanguageDetectorResult {
|
||||
struct LanguageDetectorPrediction* predictions;
|
||||
|
||||
// Keep the count of predictions.
|
||||
uint32_t predictions_count;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_LANGUAGE_DETECTION_RESULT_H_
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "mediapipe/tasks/c/components/containers/language_detection_result.h"
|
||||
#include "mediapipe/tasks/c/text/language_detector/language_detector.h"
|
||||
#include "mediapipe/tasks/cc/text/language_detector/language_detector.h"
|
||||
|
||||
namespace mediapipe::tasks::c::components::containers {
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
#ifndef MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_LANGUAGE_DETECTION_RESULT_CONVERTER_H_
|
||||
#define MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_LANGUAGE_DETECTION_RESULT_CONVERTER_H_
|
||||
|
||||
#include "mediapipe/tasks/c/components/containers/language_detection_result.h"
|
||||
#include "mediapipe/tasks/c/text/language_detector/language_detector.h"
|
||||
#include "mediapipe/tasks/cc/text/language_detector/language_detector.h"
|
||||
|
||||
namespace mediapipe::tasks::c::components::containers {
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* Copyright 2023 The MediaPipe Authors.
|
||||
|
||||
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.
|
||||
==============================================================================*/
|
||||
|
||||
#include "mediapipe/tasks/c/components/containers/language_detection_result_converter.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/tasks/c/text/language_detector/language_detector.h"
|
||||
#include "mediapipe/tasks/cc/text/language_detector/language_detector.h"
|
||||
|
||||
namespace mediapipe::tasks::c::components::containers {
|
||||
|
||||
TEST(LanguageDetectionResultConverterTest,
|
||||
ConvertsLanguageDetectionResultCustomResult) {
|
||||
mediapipe::tasks::text::language_detector::LanguageDetectorResult
|
||||
cpp_detector_result = {{/* language_code= */ "fr",
|
||||
/* probability= */ 0.5},
|
||||
{/* language_code= */ "en",
|
||||
/* probability= */ 0.5}};
|
||||
|
||||
LanguageDetectorResult c_detector_result;
|
||||
CppConvertToLanguageDetectionResult(cpp_detector_result, &c_detector_result);
|
||||
EXPECT_NE(c_detector_result.predictions, nullptr);
|
||||
EXPECT_EQ(c_detector_result.predictions_count, 2);
|
||||
EXPECT_NE(c_detector_result.predictions[0].language_code, "fr");
|
||||
EXPECT_EQ(c_detector_result.predictions[0].probability, 0.5);
|
||||
|
||||
CppCloseLanguageDetectionResult(&c_detector_result);
|
||||
}
|
||||
|
||||
TEST(LanguageDetectionResultConverterTest, FreesMemory) {
|
||||
mediapipe::tasks::text::language_detector::LanguageDetectorResult
|
||||
cpp_detector_result = {{"fr", 0.5}};
|
||||
|
||||
LanguageDetectorResult c_detector_result;
|
||||
CppConvertToLanguageDetectionResult(cpp_detector_result, &c_detector_result);
|
||||
EXPECT_NE(c_detector_result.predictions, nullptr);
|
||||
|
||||
CppCloseLanguageDetectionResult(&c_detector_result);
|
||||
EXPECT_EQ(c_detector_result.predictions, nullptr);
|
||||
}
|
||||
|
||||
} // namespace mediapipe::tasks::c::components::containers
|
|
@ -22,7 +22,6 @@ cc_library(
|
|||
hdrs = ["language_detector.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/tasks/c/components/containers:language_detection_result",
|
||||
"//mediapipe/tasks/c/components/containers:language_detection_result_converter",
|
||||
"//mediapipe/tasks/c/components/processors:classifier_options",
|
||||
"//mediapipe/tasks/c/components/processors:classifier_options_converter",
|
||||
|
@ -69,6 +68,15 @@ cc_binary(
|
|||
deps = [":language_detector_lib"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "language_detector",
|
||||
hdrs = ["language_detector.h"],
|
||||
deps = [
|
||||
"//mediapipe/tasks/c/components/processors:classifier_options",
|
||||
"//mediapipe/tasks/c/core:base_options",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "language_detector_test",
|
||||
srcs = ["language_detector_test.cc"],
|
||||
|
|
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||
#ifndef MEDIAPIPE_TASKS_C_TEXT_LANGUAGE_DETECTOR_LANGUAGE_DETECTOR_H_
|
||||
#define MEDIAPIPE_TASKS_C_TEXT_LANGUAGE_DETECTOR_LANGUAGE_DETECTOR_H_
|
||||
|
||||
#include "mediapipe/tasks/c/components/containers/language_detection_result.h"
|
||||
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
|
||||
#include "mediapipe/tasks/c/core/base_options.h"
|
||||
|
||||
|
@ -28,6 +27,23 @@ limitations under the License.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// A language code and its probability.
|
||||
struct LanguageDetectorPrediction {
|
||||
// An i18n language / locale code, e.g. "en" for English, "uz" for Uzbek,
|
||||
// "ja"-Latn for Japanese (romaji).
|
||||
char* language_code;
|
||||
|
||||
float probability;
|
||||
};
|
||||
|
||||
// Task output.
|
||||
struct LanguageDetectorResult {
|
||||
struct LanguageDetectorPrediction* predictions;
|
||||
|
||||
// The count of predictions.
|
||||
uint32_t predictions_count;
|
||||
};
|
||||
|
||||
// The options for configuring a MediaPipe language detector task.
|
||||
struct LanguageDetectorOptions {
|
||||
// Base options for configuring MediaPipe Tasks, such as specifying the model
|
||||
|
|
Loading…
Reference in New Issue
Block a user