Skip to content

Commit

Permalink
docstring improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
craiglabenz committed Oct 31, 2023
1 parent cb4dde3 commit 810d4eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import 'package:flutter/foundation.dart';
import 'package:mediapipe_core/mediapipe_core.dart';
import '../../../mediapipe_text_bindings.dart' as bindings;

/// Configuration object for a MediaPipe text classifier.
///
/// See also:
/// * [MediaPipe's TextClassifierOptions documentation](https://developers.google.com/mediapipe/api/solutions/js/tasks-text.textclassifieroptions)
class TextClassifierOptions {
/// Generative constructor.
const TextClassifierOptions({
required this.baseOptions,
ClassifierOptions? classifierOptions,
Expand Down Expand Up @@ -39,9 +44,14 @@ class TextClassifierOptions {
classifierOptions: classifierOptions,
);

/// Container storing options universal to all MediaPipe tasks (namely, which
/// model to use for the task).
final BaseOptions baseOptions;

/// Container storing options universal to all MediaPipe classifiers.
final ClassifierOptions classifierOptions;

/// Converts this [ImageClassifierOptions] instance into its C representation.
Pointer<bindings.TextClassifierOptions> toStruct() {
final struct = calloc<bindings.TextClassifierOptions>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@ import 'package:ffi/ffi.dart';
import 'package:mediapipe_core/mediapipe_core.dart';
import 'package:mediapipe_text/src/mediapipe_text_bindings.dart' as bindings;

/// Container with results of MediaPipe's `classifyText` task.
///
/// See also:
/// * [MediaPipe's textClassifierResult documentation](https://developers.google.com/mediapipe/api/solutions/java/com/google/mediapipe/tasks/text/textclassifier/TextClassifierResult)
class TextClassifierResult {
/// Generative constructor which creates a [TextClassifierResult] instance.
const TextClassifierResult({
required this.classifications,
this.timestamp,
});

// The classification results for each head of the model.
/// The classification results for each head of the model.
final List<Classifications> classifications;

// The optional timestamp (as a Duration) of the start of the chunk of data
// corresponding to these results.
//
// This is only used for classification on time series (e.g. audio
// classification). In these use cases, the amount of data to process might
// exceed the maximum size that the model can process: to solve this, the
// input data is split into multiple chunks starting at different timestamps.
/// The optional timestamp (as a Duration) of the start of the chunk of data
/// corresponding to these results.
///
/// This is only used for classification on time series (e.g. audio
/// classification). In these use cases, the amount of data to process might
/// exceed the maximum size that the model can process: to solve this, the
/// input data is split into multiple chunks starting at different timestamps.
final Duration? timestamp;

/// Factory constructor which converts the C representation of an
/// ImageClassifierResult into an actual [ImageClassifierResult].
factory TextClassifierResult.fromStruct(
bindings.TextClassifierResult struct) {
return TextClassifierResult(
Expand All @@ -34,6 +41,8 @@ class TextClassifierResult {
);
}

/// Deallocates all memory associated with an [bindings.ImageClassifierResult]
/// in C memory.
static void freeStruct(Pointer<bindings.TextClassifierResult> struct) {
Classifications.freeStructs(
struct.ref.classifications,
Expand All @@ -42,6 +51,7 @@ class TextClassifierResult {
calloc.free(struct);
}

/// Convenience helper for the first [Classifications] object.
Classifications? get firstClassification =>
classifications.isNotEmpty ? classifications.first : null;

Expand Down

0 comments on commit 810d4eb

Please sign in to comment.