Added iOS language detector results

This commit is contained in:
Prianka Liz Kariat 2023-10-03 19:20:45 +05:30
parent 3c13e4b6d6
commit 38de7493df
3 changed files with 119 additions and 0 deletions

View File

@ -25,3 +25,11 @@ objc_library(
deps = ["//mediapipe/tasks/ios/core:MPPTaskOptions"],
)
objc_library(
name = "MPPLanguageDetectorResult",
srcs = ["sources/MPPLanguageDetectorResult.m"],
hdrs = ["sources/MPPLanguageDetectorResult.h"],
deps = [
"//mediapipe/tasks/ios/core:MPPTaskResult",
],
)

View File

@ -0,0 +1,70 @@
// 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.
#import <Foundation/Foundation.h>
#import "mediapipe/tasks/ios/core/sources/MPPTaskResult.h"
NS_ASSUME_NONNULL_BEGIN
NS_SWIFT_NAME(LanguagePrediction)
@interface MPPLanguagePrediction : NSObject
/** The i18n language / locale code for the prediction. */
@property(nonatomic, readonly) NSString *languageCode;
/** The probability for the prediction. */
@property(nonatomic, readonly) float probability;
/**
* Initializes a new `LanguagePrediction` with the given language code and probability.
*
* @param languageCode The i18n language / locale code for the prediction.
* @param probability The probability for the prediction.
*
* @return An instance of `LanguagePrediction` initialized with the given language code and
* probability.
*/
- (instancetype)initWithLanguageCode:(NSString *)languageCode probability:(float)probability;
@end
/** Represents the results generated by `LanguageDetector`. **/
NS_SWIFT_NAME(LanguageDetectorResult)
@interface MPPLanguageDetectorResult : MPPTaskResult
/** A list of language predictions. */
@property(nonatomic, readonly) NSArray<MPPLanguagePrediction *> *languagePredictions;
/**
* Initializes a new `LanguageDetectorResult` with the given array of language predictions and
* timestamp (in milliseconds).
*
* @param languagePrediction The array of language predictions in this result.
* @param timestampInMilliseconds The timestamp (in milliseconds) for this result.
*
* @return An instance of `LanguageDetectorResult` initialized with the given array of language
* predictions and timestamp (in milliseconds).
*/
- (instancetype)initWithLanguagePredictions:(NSArray<MPPLanguagePrediction *> *)languagePredictions
timestampInMilliseconds:(NSInteger)timestampInMilliseconds;
- (instancetype)initWithTimestampInMilliseconds:(NSInteger)timestampInMilliseconds NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,41 @@
// 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.
#import "mediapipe/tasks/ios/text/language_detector/sources/MPPLanguageDetectorResult.h"
@implementation MPPLanguagePrediction
- (instancetype)initWithLanguageCode:(NSString *)languageCode probability:(float)probability {
self = [super init];
if (self) {
_languageCode = languageCode;
_probability = probability;
}
return self;
}
@end
@implementation MPPLanguageDetectorResult
- (instancetype)initWithLanguagePredictions:(NSArray<MPPLanguagePrediction *> *)languagePredictions
timestampInMilliseconds:(NSInteger)timestampInMilliseconds {
self = [super initWithTimestampInMilliseconds:timestampInMilliseconds];
if (self) {
_languagePredictions = languagePredictions;
}
return self;
}
@end