Ejemplo n.º 1
0
    void Run::parse(const std::string &sInputFile, const std::string &sOutputFile,
                    const std::string &sFeatureFile) const {

        Sentence sentence;
        DependencyTree tree;

        std::cout << "Parsing started" << std::endl;

        auto time_begin = time(NULL);

        std::unique_ptr<DepParser> parser(new DepParser(sFeatureFile, sFeatureFile, ParserState::PARSE));
        std::ifstream input(sInputFile);
        std::ofstream output(sOutputFile);
        if (input) {
            while (input >> sentence) {
                if (sentence.size() < MAX_SENTENCE_SIZE) {
                    parser->parse(sentence, &tree);
                    output << tree;
                    tree.clear();
                }
            }
        }
        input.close();
        output.close();

        auto time_end = time(NULL);

        auto seconds = difftime(time_end, time_begin);

        std::cout << "Parsing has finished successfully. Total time taken is: " << difftime(time_end, time_begin) <<
        "s" << std::endl;
    }
Ejemplo n.º 2
0
	void StateItem::generateTree(const DependencyTree & sent, DependencyTree & tree) const {
		int i = 0;
		tree.clear();
		for (const auto & token : sent) {
			tree.push_back(DependencyTreeNode(TREENODE_POSTAGGEDWORD(token), m_lHeads[i], TDepLabel::key(m_lLabels[i])));
			++i;
		}
	}
Ejemplo n.º 3
0
const string NonProjNivre::get_oracle(
        Configuration& c,
        DependencyTree& tree)
{
    int w1 = c.get_stack(1);
    int w2 = c.get_stack(0);

    int k = c.buffer.empty() ? -1 : c.buffer.back();
    if (w1 > 0
            && tree.get_head(w1) == w2
            && !c.has_other_child(w1, tree))
        return "L(" + tree.get_label(w1) + ")";
    else if (w1 >= 0
            && tree.get_head(w2) == w1
            && !c.has_other_child(w2, tree))
        return "R(" + tree.get_label(w2) + ")";
    else if (w1 < w2 && tree.proj_order[w1] > tree.proj_order[w2] &&
            (k == -1 || tree.mpc[w2] != tree.mpc[k]))
    // else if (w1 < w2 && tree.proj_order[w1] > tree.proj_order[w2])
        return "E";
    else
        return "S";
}
Ejemplo n.º 4
0
    void Run::parse(const std::string &sInputFile, const std::string &sOutputFile,
                    const std::string &sFeatureFile) const {

        Sentence sentence;
        DependencyTree tree;

        std::cout << "Parsing started" << std::endl;

        std::unique_ptr<DepParser> parser(new DepParser(sFeatureFile, sFeatureFile, ParserState::PARSE));
        std::ifstream input(sInputFile);
        std::ofstream output(sOutputFile);
        if (input) {
            while (input >> sentence) {
                if (sentence.size() < MAX_SENTENCE_SIZE) {
                    parser->parse(sentence, &tree);
                    output << tree;
                    tree.clear();
                }
            }
        }
        input.close();
        output.close();
    }
Ejemplo n.º 5
0
	bool StateItem::standardMove(const DependencyTree & tree) {
		int top;
		if (m_nNextWord == tree.size()) {
			if (m_nStackBack > 0) {
				reduce();
				return true;
			}
			else {
				popRoot();
				return false;
			}
		}
		if (m_nStackBack >= 0) {
			top = m_lStack[m_nStackBack];
			while (!(m_lHeads[top] == -1)) {
				top = m_lHeads[top];
			}
			if (TREENODE_HEAD(tree[top]) == m_nNextWord) {
				if (top == m_lStack[m_nStackBack]) {
					arcLeft(TDepLabel::code(TREENODE_LABEL(tree[top])));
					return true;
				}
				else {
					reduce();
					return true;
				}
			}
		}
		if (TREENODE_HEAD(tree[m_nNextWord]) == -1 || TREENODE_HEAD(tree[m_nNextWord]) > m_nNextWord) {
			shift();
			return true;
		}
		else {
			top = m_lStack[m_nStackBack];
			if (TREENODE_HEAD(tree[m_nNextWord]) == top) {
				arcRight(TDepLabel::code(TREENODE_LABEL(tree[m_nNextWord])));
				return true;
			}
			else {
				reduce();
				return true;
			}
		}
	}