コード例 #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;
    }
コード例 #2
0
ファイル: arceager_state.cpp プロジェクト: biug/xParser
	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;
		}
	}
コード例 #3
0
ファイル: NonProjNivre.cpp プロジェクト: HITalexwang/nnparser
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";
}
コード例 #4
0
ファイル: eisner_run.cpp プロジェクト: yangzhixuan/xParser
    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();
    }
コード例 #5
0
ファイル: arceager_state.cpp プロジェクト: biug/xParser
	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;
			}
		}
	}