Skip to content

Commit

Permalink
phrase-extract: add syntax-common sub-library
Browse files Browse the repository at this point in the history
And remove some (near-)duplicate code from pcfg-common and score-stsg.
  • Loading branch information
pjwilliams committed Dec 7, 2014
1 parent d966a04 commit 60e56ef
Show file tree
Hide file tree
Showing 58 changed files with 805 additions and 528 deletions.
2 changes: 1 addition & 1 deletion Jamroot
Expand Up @@ -173,7 +173,7 @@ project : requirements
;

#Add directories here if you want their incidental targets too (i.e. tests).
build-projects lm util phrase-extract search moses moses/LM mert moses-cmd mira scripts regression-testing ;
build-projects lm util phrase-extract phrase-extract/syntax-common search moses moses/LM mert moses-cmd mira scripts regression-testing ;

if [ option.get "with-mm" : : "yes" ]
{
Expand Down
2 changes: 1 addition & 1 deletion phrase-extract/pcfg-common/Jamfile
@@ -1 +1 @@
lib pcfg_common : [ glob *.cc ] ..//deps : <include>.. ;
lib pcfg_common : [ glob *.cc ] ..//syntax-common ..//deps : <include>.. ;
46 changes: 0 additions & 46 deletions phrase-extract/pcfg-common/exception.h

This file was deleted.

126 changes: 0 additions & 126 deletions phrase-extract/pcfg-common/numbered_set.h

This file was deleted.

10 changes: 6 additions & 4 deletions phrase-extract/pcfg-common/pcfg.cc
Expand Up @@ -19,14 +19,15 @@

#include "pcfg.h"

#include "exception.h"
#include <cassert>

#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>

#include <cassert>
#include "syntax-common/exception.h"

namespace Moses {
namespace MosesTraining {
namespace Syntax {
namespace PCFG {

void Pcfg::Add(const Key &key, double score) {
Expand Down Expand Up @@ -103,4 +104,5 @@ void Pcfg::Write(const Vocabulary &vocab, std::ostream &output) const {
}

} // namespace PCFG
} // namespace Moses
} // namespace Syntax
} // namespace MosesTraining
37 changes: 14 additions & 23 deletions phrase-extract/pcfg-common/pcfg.h
Expand Up @@ -21,52 +21,43 @@
#ifndef PCFG_PCFG_H_
#define PCFG_PCFG_H_

#include "typedef.h"

#include <istream>
#include <map>
#include <ostream>
#include <vector>

namespace Moses
{
namespace PCFG
{
#include "typedef.h"

namespace MosesTraining {
namespace Syntax {
namespace PCFG {

class Pcfg
{
public:
class Pcfg {
public:
typedef std::vector<std::size_t> Key;
typedef std::map<Key, double> Map;
typedef Map::iterator iterator;
typedef Map::const_iterator const_iterator;

Pcfg() {}

iterator begin() {
return rules_.begin();
}
const_iterator begin() const {
return rules_.begin();
}
iterator begin() { return rules_.begin(); }
const_iterator begin() const { return rules_.begin(); }

iterator end() {
return rules_.end();
}
const_iterator end() const {
return rules_.end();
}
iterator end() { return rules_.end(); }
const_iterator end() const { return rules_.end(); }

void Add(const Key &, double);
bool Lookup(const Key &, double &) const;
void Read(std::istream &, Vocabulary &);
void Write(const Vocabulary &, std::ostream &) const;

private:
private:
Map rules_;
};

} // namespace PCFG
} // namespace Moses
} // namespace Syntax
} // namespace MosesTraining

#endif
39 changes: 16 additions & 23 deletions phrase-extract/pcfg-common/pcfg_tree.h
Expand Up @@ -21,48 +21,40 @@
#ifndef PCFG_PCFG_TREE_H_
#define PCFG_PCFG_TREE_H_

#include <string>

#include "syntax_tree.h"
#include "xml_tree_writer.h"

#include <string>

namespace Moses
{
namespace PCFG
{
namespace MosesTraining {
namespace Syntax {
namespace PCFG {

template<typename DerivedType>
class PcfgTreeBase : public SyntaxTreeBase<std::string, DerivedType>
{
public:
class PcfgTreeBase : public SyntaxTreeBase<std::string, DerivedType> {
public:
typedef std::string LabelType;
typedef SyntaxTreeBase<LabelType, DerivedType> BaseType;

PcfgTreeBase(const LabelType &label) : BaseType(label), score_(0.0) {}

double score() const {
return score_;
}
void set_score(double s) {
score_ = s;
}
double score() const { return score_; }
void set_score(double s) { score_ = s; }

private:
private:
double score_;
};

class PcfgTree : public PcfgTreeBase<PcfgTree>
{
public:
class PcfgTree : public PcfgTreeBase<PcfgTree> {
public:
typedef PcfgTreeBase<PcfgTree> BaseType;
PcfgTree(const BaseType::LabelType &label) : BaseType(label) {}
};

// Specialise XmlOutputHandler for PcfgTree.
template<>
class XmlOutputHandler<PcfgTree>
{
public:
class XmlOutputHandler<PcfgTree> {
public:
typedef std::map<std::string, std::string> AttributeMap;

void GetLabel(const PcfgTree &tree, std::string &label) const {
Expand All @@ -81,6 +73,7 @@ class XmlOutputHandler<PcfgTree>
};

} // namespace PCFG
} // namespace Moses
} // namespace Syntax
} // namespace MosesTraining

#endif

0 comments on commit 60e56ef

Please sign in to comment.