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