Skip to content

Commit

Permalink
Miscellaneous changes to grammar utilities [part I].
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 641900294
  • Loading branch information
agutkin authored and copybara-github committed Jun 10, 2024
1 parent 033780f commit 9300462
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
1 change: 1 addition & 0 deletions nisaba/interim/grm2/paths/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ cc_library(
hdrs = ["paths.h"],
deps = [
"@org_openfst//:fst",
"@org_openfst//:util",
],
)
3 changes: 3 additions & 0 deletions nisaba/interim/grm2/paths/paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
#include <string>
#include <vector>

#include "fst/arc.h"
#include "fst/fst.h"
#include "fst/properties.h"
#include "fst/string.h"
#include "fst/util.h"

namespace fst {

Expand Down
9 changes: 5 additions & 4 deletions nisaba/interim/grm2/rewrite/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ cc_library(
hdrs = ["base_rule_cascade.h"],
deps = [
":rewrite",
"@com_google_absl//absl/log",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
"@com_google_protobuf//:protobuf_lite",
"@org_openfst//:fst",
"@org_openfst//:lib_lite",
Expand All @@ -35,6 +35,7 @@ cc_library(
hdrs = ["parentheses.h"],
deps = [
"@com_google_absl//absl/log",
"@com_google_absl//absl/types:span",
"@org_openfst//:fst",
],
)
Expand All @@ -46,6 +47,7 @@ cc_library(
"//nisaba/interim/grm2/paths",
"//nisaba/interim/grm2/string:stringprint",
"@com_google_absl//absl/log",
"@com_google_protobuf//:protobuf_lite",
"@org_openfst//:fst",
"@org_openfst//:mpdt",
"@org_openfst//:pdt",
Expand All @@ -66,8 +68,6 @@ cc_library(
"@org_openfst//:far",
"@org_openfst//:fst",
"@org_openfst//:fst-decl",
"@org_openfst//:mpdt",
"@org_openfst//:pdt",
],
)

Expand All @@ -78,6 +78,7 @@ cc_library(
":base_rule_cascade",
":rewrite_manager",
"@com_google_absl//absl/log",
"@org_openfst//:fst",
"@com_google_absl//absl/strings",
"@com_google_protobuf//:protobuf_lite",
],
)
15 changes: 7 additions & 8 deletions nisaba/interim/grm2/rewrite/base_rule_cascade.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
#include <string>
#include <vector>

#ifndef NO_GOOGLE
#include "google/protobuf/repeated_field.h"
#endif // NO_GOOGLE
#include "fst/arcsort.h"
#include "fst/compose.h"
#include "fst/fst.h"
#include "fst/string.h"
#include "fst/symbol-table.h"
#include "absl/log/log.h"
#include "fst/vector-fst.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "nisaba/interim/grm2/rewrite/rewrite.h"
#include "google/protobuf/repeated_ptr_field.h"

namespace rewrite {

Expand Down Expand Up @@ -188,8 +187,8 @@ class BaseRuleCascade {
bool Matches(absl::string_view input, absl::string_view output) const;

private:
bool LabelsToDebugString(const std::string &output,
const std::vector<Label> &labels,
bool LabelsToDebugString(absl::string_view output,
absl::Span<const Label> labels,
std::string *debug) const;

void PrintDebugSymbol(Label label, std::ostream &ostrm) const;
Expand Down Expand Up @@ -500,8 +499,8 @@ bool BaseRuleCascade<Arc>::Matches(absl::string_view input,
// Private methods.

template <class Arc>
bool BaseRuleCascade<Arc>::LabelsToDebugString(const std::string &output,
const std::vector<Label> &labels,
bool BaseRuleCascade<Arc>::LabelsToDebugString(absl::string_view output,
absl::Span<const Label> labels,
std::string *debug) const {
debug->clear();
// This really only makes sense in BYTE mode.
Expand Down
5 changes: 3 additions & 2 deletions nisaba/interim/grm2/rewrite/parentheses.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "fst/fst.h"
#include "absl/log/log.h"
#include "absl/types/span.h"

// This is used by (M)PdtCompose and and associated grammar managers when they
// express parentheses and/or assignments as transducers.
Expand Down Expand Up @@ -76,8 +77,8 @@ void MakeParenthesesVector(
template <class Arc>
void MakeAssignmentsVector(
const ::fst::Fst<Arc> &assignments_transducer,
const std::vector<std::pair<typename Arc::Label, typename Arc::Label>>
&parens,
absl::Span<const std::pair<typename Arc::Label, typename Arc::Label>>
parens,
std::vector<typename Arc::Label> *assignments) {
using Label = typename Arc::Label;
std::map<Label, Label> assignment_map;
Expand Down
3 changes: 1 addition & 2 deletions nisaba/interim/grm2/rewrite/rewrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <utility>
#include <vector>

#ifndef NO_GOOGLE
#endif // NO_GOOGLE
#include "fst/extensions/mpdt/compose.h"
#include "fst/extensions/pdt/compose.h"
#include "fst/arcsort.h"
Expand All @@ -42,6 +40,7 @@
#include "absl/log/log.h"
#include "nisaba/interim/grm2/paths/paths.h"
#include "nisaba/interim/grm2/string/stringprint.h"
#include "google/protobuf/repeated_ptr_field.h"

// Generic rewrite utilities for string inputs.

Expand Down
9 changes: 1 addition & 8 deletions nisaba/interim/grm2/rewrite/rewrite_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
#include <utility>
#include <vector>

#ifndef NO_GOOGLE
#include "google/protobuf/repeated_field.h"
#endif // NO_GOOGLE
#include "fst/extensions/far/far.h"
#include "fst/extensions/mpdt/compose.h"
#include "fst/extensions/mpdt/mpdt.h"
#include "fst/extensions/pdt/compose.h"
#include "fst/extensions/pdt/pdt.h"
#include "fst/extensions/pdt/shortest-path.h"
#include "fst/arcsort.h"
#include "fst/fst-decl.h"
#include "fst/intersect.h"
Expand All @@ -43,6 +35,7 @@
#include "absl/strings/string_view.h"
#include "nisaba/interim/grm2/rewrite/parentheses.h"
#include "nisaba/interim/grm2/rewrite/rewrite.h"
#include "google/protobuf/repeated_ptr_field.h"

namespace rewrite {

Expand Down
6 changes: 4 additions & 2 deletions nisaba/interim/grm2/rewrite/rule_cascade.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <vector>

#include "absl/log/log.h"
#include "absl/strings/string_view.h"
#include "nisaba/interim/grm2/rewrite/base_rule_cascade.h"
#include "nisaba/interim/grm2/rewrite/rewrite_manager.h"
#include "google/protobuf/repeated_ptr_field.h"

namespace rewrite {
namespace internal {
Expand All @@ -35,7 +37,7 @@ namespace internal {
// optional MPDT assignment rule name).
class RuleTriple {
public:
explicit RuleTriple(const std::string &rule_def)
explicit RuleTriple(absl::string_view rule_def)
: RuleTriple(RuleTriple::ParseRuleDef(rule_def)) {}

const std::string &Rule() const { return rules_[0]; }
Expand All @@ -53,7 +55,7 @@ class RuleTriple {
: rules_(std::move(rules)) {}

// Actually parses the rules into the pieces we need.
static std::array<std::string, 3> ParseRuleDef(const std::string &rule_def) {
static std::array<std::string, 3> ParseRuleDef(absl::string_view rule_def) {
std::array<std::string, 3> result;
auto main_pos = rule_def.find('$');
if (main_pos == std::string::npos) main_pos = rule_def.find(':');
Expand Down

0 comments on commit 9300462

Please sign in to comment.