Commit be7a8999 authored by calberti's avatar calberti Committed by GitHub
Browse files

SyntaxNet cleanups (#281)

Cleanup changes for syntaxnet.
parent 0a40f8d5
......@@ -58,8 +58,8 @@ limitations under the License.
//
// See also creators.Add() for more convenience functions.
#ifndef $TARGETDIR_POPULATE_TEST_INPUTS_H_
#define $TARGETDIR_POPULATE_TEST_INPUTS_H_
#ifndef SYNTAXNET_POPULATE_TEST_INPUTS_H_
#define SYNTAXNET_POPULATE_TEST_INPUTS_H_
#include <functional>
#include <string>
......@@ -150,4 +150,4 @@ class PopulateTestInputs {
} // namespace syntaxnet
#endif // $TARGETDIR_POPULATE_TEST_INPUTS_H_
#endif // SYNTAXNET_POPULATE_TEST_INPUTS_H_
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef $TARGETDIR_PROTO_IO_H_
#define $TARGETDIR_PROTO_IO_H_
#ifndef SYNTAXNET_PROTO_IO_H_
#define SYNTAXNET_PROTO_IO_H_
#include <iostream>
#include <memory>
......@@ -194,7 +194,7 @@ class TextReader {
private:
string filename_;
int sentence_count_ = 0;
std::unique_ptr<tensorflow::RandomAccessFile> file_;
std::unique_ptr<tensorflow::RandomAccessFile> file_; // must outlive buffer_
std::unique_ptr<tensorflow::io::InputBuffer> buffer_;
std::unique_ptr<DocumentFormat> format_;
};
......@@ -241,4 +241,4 @@ class TextWriter {
} // namespace syntaxnet
#endif // $TARGETDIR_PROTO_IO_H_
#endif // SYNTAXNET_PROTO_IO_H_
......@@ -15,17 +15,17 @@ limitations under the License.
#include <math.h>
#include <deque>
#include <unordered_map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "syntaxnet/base.h"
#include "syntaxnet/feature_extractor.h"
#include "syntaxnet/parser_state.h"
#include "syntaxnet/parser_transitions.h"
#include "syntaxnet/sentence_batch.h"
#include "syntaxnet/sentence.pb.h"
#include "syntaxnet/sentence_batch.h"
#include "syntaxnet/shared_store.h"
#include "syntaxnet/sparse.pb.h"
#include "syntaxnet/task_context.h"
......@@ -206,7 +206,7 @@ class ParsingReader : public OpKernel {
int additional_output_index() const { return feature_size_ + 1; }
ParserState *state(int i) const { return states_[i].get(); }
const ParserTransitionSystem &transition_system() const {
return *transition_system_.get();
return *transition_system_;
}
// Parser task context.
......
......@@ -18,7 +18,7 @@ limitations under the License.
namespace syntaxnet {
// Global list of all component registries.
RegistryMetadata *global_registry_list = NULL;
RegistryMetadata *global_registry_list = nullptr;
void RegistryMetadata::Register(RegistryMetadata *registry) {
registry->set_link(global_registry_list);
......
......@@ -50,8 +50,8 @@ limitations under the License.
// Function *f = Function::Lookup("cos");
// double result = f->Evaluate(arg);
#ifndef $TARGETDIR_REGISTRY_H_
#define $TARGETDIR_REGISTRY_H_
#ifndef SYNTAXNET_REGISTRY_H_
#define SYNTAXNET_REGISTRY_H_
#include <string.h>
#include <string>
......@@ -70,7 +70,7 @@ class ComponentMetadata {
class_name_(class_name),
file_(file),
line_(line),
link_(NULL) {}
link_(nullptr) {}
// Returns component name.
const char *name() const { return name_; }
......@@ -131,7 +131,7 @@ struct ComponentRegistry {
: ComponentMetadata(type, class_name, file, line), object_(object) {
// Register registry in master registry if this is the first registered
// component of this type.
if (registry->components == NULL) {
if (registry->components == nullptr) {
RegistryMetadata::Register(new RegistryMetadata(
registry->name, registry->class_name, registry->file,
registry->line,
......@@ -160,8 +160,8 @@ struct ComponentRegistry {
// Finds registrar for named component in registry.
const Registrar *GetComponent(const char *type) const {
Registrar *r = components;
while (r != NULL && strcmp(type, r->type()) != 0) r = r->next();
if (r == NULL) {
while (r != nullptr && strcmp(type, r->type()) != 0) r = r->next();
if (r == nullptr) {
LOG(FATAL) << "Unknown " << name << " component: '" << type << "'.";
}
return r;
......@@ -240,4 +240,4 @@ class RegisterableInstance {
} // namespace syntaxnet
#endif // $TARGETDIR_REGISTRY_H_
#endif // SYNTAXNET_REGISTRY_H_
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef $TARGETDIR_SENTENCE_BATCH_H_
#define $TARGETDIR_SENTENCE_BATCH_H_
#ifndef SYNTAXNET_SENTENCE_BATCH_H_
#define SYNTAXNET_SENTENCE_BATCH_H_
#include <memory>
#include <string>
......@@ -75,4 +75,4 @@ class SentenceBatch {
} // namespace syntaxnet
#endif // $TARGETDIR_SENTENCE_BATCH_H_
#endif // SYNTAXNET_SENTENCE_BATCH_H_
......@@ -17,8 +17,8 @@ limitations under the License.
// in this header so they may be re-used via composition into other more
// advanced feature classes.
#ifndef $TARGETDIR_SENTENCE_FEATURES_H_
#define $TARGETDIR_SENTENCE_FEATURES_H_
#ifndef SYNTAXNET_SENTENCE_FEATURES_H_
#define SYNTAXNET_SENTENCE_FEATURES_H_
#include "syntaxnet/affix.h"
#include "syntaxnet/feature_extractor.h"
......@@ -103,7 +103,7 @@ class TermFrequencyMapFeature : public TokenLookupFeature {
void Init(TaskContext *context) override;
// Number of unique values.
virtual int64 NumValues() const { return term_map_->Size() + 1; }
int64 NumValues() const override { return term_map_->Size() + 1; }
// Special value for strings not in the map.
FeatureValue UnknownValue() const { return term_map_->Size(); }
......@@ -314,4 +314,4 @@ typedef FeatureExtractor<Sentence, int> SentenceExtractor;
} // namespace syntaxnet
#endif // $TARGETDIR_SENTENCE_FEATURES_H_
#endif // SYNTAXNET_SENTENCE_FEATURES_H_
......@@ -18,14 +18,14 @@ limitations under the License.
#include <string>
#include <vector>
#include <gmock/gmock.h>
#include "syntaxnet/utils.h"
#include "syntaxnet/feature_extractor.h"
#include "syntaxnet/populate_test_inputs.h"
#include "syntaxnet/sentence.pb.h"
#include "syntaxnet/task_context.h"
#include "syntaxnet/task_spec.pb.h"
#include "syntaxnet/utils.h"
#include "syntaxnet/workspace.h"
#include <gmock/gmock.h>
using testing::UnorderedElementsAreArray;
......
......@@ -15,8 +15,8 @@ limitations under the License.
// Utility for creating read-only objects once and sharing them across threads.
#ifndef $TARGETDIR_SHARED_STORE_H_
#define $TARGETDIR_SHARED_STORE_H_
#ifndef SYNTAXNET_SHARED_STORE_H_
#define SYNTAXNET_SHARED_STORE_H_
#include <functional>
#include <string>
......@@ -231,4 +231,4 @@ class SharedStoreUtils {
} // namespace syntaxnet
#endif // $TARGETDIR_SHARED_STORE_H_
#endif // SYNTAXNET_SHARED_STORE_H_
......@@ -17,8 +17,8 @@ limitations under the License.
#include <string>
#include <gmock/gmock.h>
#include "syntaxnet/utils.h"
#include <gmock/gmock.h>
#include "tensorflow/core/lib/core/threadpool.h"
using ::testing::_;
......@@ -98,7 +98,7 @@ class PointerSet {
class SharedStoreTest : public testing::Test {
protected:
~SharedStoreTest() {
~SharedStoreTest() override {
// Clear the shared store after each test, otherwise objects created
// in one test may interfere with other tests.
SharedStore::Clear();
......
......@@ -53,7 +53,7 @@ class TaggerTransitionState : public ParserTransitionState {
}
// Reads gold tags for each token.
void Init(ParserState *state) {
void Init(ParserState *state) override {
tag_.resize(state->sentence().token_size(), -1);
gold_tag_.resize(state->sentence().token_size(), -1);
for (int pos = 0; pos < state->sentence().token_size(); ++pos) {
......@@ -150,7 +150,7 @@ class TaggerTransitionSystem : public ParserTransitionSystem {
}
// Reads tag map and tag to category map.
void Init(TaskContext *context) {
void Init(TaskContext *context) override {
const string tag_map_path = TaskContext::InputFile(*input_tag_map_);
tag_map_ = SharedStoreUtils::GetWithDefaultName<TermFrequencyMap>(
tag_map_path, 0, 0);
......
......@@ -16,7 +16,6 @@ limitations under the License.
#include <memory>
#include <string>
#include "syntaxnet/utils.h"
#include "syntaxnet/parser_state.h"
#include "syntaxnet/parser_transitions.h"
#include "syntaxnet/populate_test_inputs.h"
......@@ -24,6 +23,7 @@ limitations under the License.
#include "syntaxnet/task_context.h"
#include "syntaxnet/task_spec.pb.h"
#include "syntaxnet/term_frequency_map.h"
#include "syntaxnet/utils.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
......
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef $TARGETDIR_TASK_CONTEXT_H_
#define $TARGETDIR_TASK_CONTEXT_H_
#ifndef SYNTAXNET_TASK_CONTEXT_H_
#define SYNTAXNET_TASK_CONTEXT_H_
#include <string>
#include <vector>
......@@ -77,4 +77,4 @@ class TaskContext {
} // namespace syntaxnet
#endif // $TARGETDIR_TASK_CONTEXT_H_
#endif // SYNTAXNET_TASK_CONTEXT_H_
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef $TARGETDIR_TERM_FREQUENCY_MAP_H_
#define $TARGETDIR_TERM_FREQUENCY_MAP_H_
#ifndef SYNTAXNET_TERM_FREQUENCY_MAP_H_
#define SYNTAXNET_TERM_FREQUENCY_MAP_H_
#include <stddef.h>
#include <memory>
......@@ -114,4 +114,4 @@ class TagToCategoryMap {
} // namespace syntaxnet
#endif // $TARGETDIR_TERM_FREQUENCY_MAP_H_
#endif // SYNTAXNET_TERM_FREQUENCY_MAP_H_
......@@ -92,7 +92,7 @@ class CoNLLSyntaxFormat : public DocumentFormat {
// Split line into tab-separated fields.
fields.clear();
fields = utils::Split(lines[i], '\t');
if (fields.size() == 0) continue;
if (fields.empty()) continue;
// Skip comment lines.
if (fields[0][0] == '#') continue;
......
......@@ -20,8 +20,8 @@ limitations under the License.
#include <utility>
#include <vector>
#include "syntaxnet/utils.h"
#include "syntaxnet/sparse.pb.h"
#include "syntaxnet/utils.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor.h"
......
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef $TARGETDIR_UTILS_H_
#define $TARGETDIR_UTILS_H_
#ifndef SYNTAXNET_UTILS_H_
#define SYNTAXNET_UTILS_H_
#include <functional>
#include <string>
......@@ -168,4 +168,4 @@ void NormalizeDigits(string *form);
} // namespace utils
} // namespace syntaxnet
#endif // $TARGETDIR_UTILS_H_
#endif // SYNTAXNET_UTILS_H_
......@@ -17,8 +17,8 @@ limitations under the License.
// specifically, the registry machinery is thread-safe, as long as each thread
// performs feature extraction on a different Sentence object.
#ifndef $TARGETDIR_WORKSPACE_H_
#define $TARGETDIR_WORKSPACE_H_
#ifndef SYNTAXNET_WORKSPACE_H_
#define SYNTAXNET_WORKSPACE_H_
#include <string>
#include <typeindex>
......@@ -212,4 +212,4 @@ class VectorVectorIntWorkspace : public Workspace {
} // namespace syntaxnet
#endif // $TARGETDIR_WORKSPACE_H_
#endif // SYNTAXNET_WORKSPACE_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment