-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar_proto_mojom_conversion.cc
59 lines (44 loc) · 1.88 KB
/
grammar_proto_mojom_conversion.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ml/grammar_proto_mojom_conversion.h"
#include <utility>
namespace ml {
namespace {
using ::chromeos::machine_learning::mojom::GrammarCheckerCandidate;
using ::chromeos::machine_learning::mojom::GrammarCheckerCandidatePtr;
using ::chromeos::machine_learning::mojom::GrammarCheckerQuery;
using ::chromeos::machine_learning::mojom::GrammarCheckerQueryPtr;
using ::chromeos::machine_learning::mojom::GrammarCheckerResult;
using ::chromeos::machine_learning::mojom::GrammarCheckerResultPtr;
} // namespace
chrome_knowledge::GrammarCheckerRequest GrammarCheckerQueryToProto(
GrammarCheckerQueryPtr query) {
chrome_knowledge::GrammarCheckerRequest request;
request.set_text(query->text);
request.set_language(query->language);
return request;
}
GrammarCheckerQueryPtr GrammarCheckerQueryFromProtoForTesting(
const chrome_knowledge::GrammarCheckerRequest& request_proto) {
GrammarCheckerQueryPtr query = GrammarCheckerQuery::New();
query->text = request_proto.text();
query->language = request_proto.language();
return query;
}
GrammarCheckerResultPtr GrammarCheckerResultFromProto(
const chrome_knowledge::GrammarCheckerResult& result_proto) {
GrammarCheckerResultPtr result = GrammarCheckerResult::New();
// This method is called only when Grammar Check succeeds, so status is
// always set to OK.
result->status = GrammarCheckerResult::Status::OK;
// For candidates.
for (const auto& candidate_proto : result_proto.candidates()) {
GrammarCheckerCandidatePtr candidate = GrammarCheckerCandidate::New();
candidate->text = candidate_proto.text();
candidate->score = candidate_proto.score();
result->candidates.push_back(std::move(candidate));
}
return result;
}
} // namespace ml