コード例 #1
0
	int PhraseAlignment::Compare(const PhraseAlignment &other) const
	{
		if (this == &other) // comparing with itself
			return 0;

		if (GetTarget() != other.GetTarget()) 
			return ( GetTarget() < other.GetTarget() ) ? -1 : +1;

		if (GetSource() != other.GetSource())
			return ( GetSource() < other.GetSource() ) ? -1 : +1;

		if (!hierarchicalFlag) 
			return 0;

		// loop over all words (note: 0 = left hand side of rule)
		for(size_t i=0; i<phraseT.size()-1; i++) {
			if (isNonTerminal( vcbT.getWord( phraseT[i] ) )) {
				size_t thisAlign = *(alignedToT[i].begin());
				size_t otherAlign = *(other.alignedToT[i].begin());

				if (alignedToT[i].size() != 1 ||
					other.alignedToT[i].size() != 1 ||
					thisAlign != otherAlign)
				{
					int ret = (thisAlign < otherAlign) ? -1 : +1;
					return ret;
				}
			}
		}
		return 0;

	}
コード例 #2
0
ファイル: PhraseAlignment.cpp プロジェクト: Kalep/ctx-phrase
    int PhraseAlignment::Compare(const PhraseAlignment &other) const
    {
        if (this == &other) // comparing with itself
            return 0;

        if (GetTarget() != other.GetTarget()) //先比的是目标端
            return ( GetTarget() < other.GetTarget() ) ? -1 : +1;

        if (GetSource() != other.GetSource())
            return ( GetSource() < other.GetSource() ) ? -1 : +1;

        return 0;

    }
コード例 #3
0
	// check if two word alignments between a phrase pair are the same
	bool PhraseAlignment::equals( const PhraseAlignment& other )
	{
		if (this == &other) return true;
		if (other.GetTarget() != GetTarget()) return false;
		if (other.GetSource() != GetSource()) return false;
		if (other.alignedToT != alignedToT) return false;
		if (other.alignedToS != alignedToS) return false;
		return true;
	}
コード例 #4
0
	// check if two word alignments between a phrase pairs "match"
	// i.e. they do not differ in the alignment of non-termimals
	bool PhraseAlignment::match( const PhraseAlignment& other )
	{
		if (this == &other) return true;
		if (other.GetTarget() != GetTarget()) return false;
		if (other.GetSource() != GetSource()) return false;
		if (!hierarchicalFlag) return true;

		assert(phraseT.size() == alignedToT.size() + 1);
		assert(alignedToT.size() == other.alignedToT.size());

		// loop over all words (note: 0 = left hand side of rule)
		for(size_t i=0; i<phraseT.size()-1; i++) {
			if (isNonTerminal( vcbT.getWord( phraseT[i] ) )) {
				if (alignedToT[i].size() != 1 ||
					other.alignedToT[i].size() != 1 ||
					*(alignedToT[i].begin()) != *(other.alignedToT[i].begin()))
					return false;
			}
		}
		return true;
	}