1 // Implementation of CCorpusWord methods
2 // Copyright © 2009 The University of Chicago
3 #include "CorpusWord.h"
5 #include "CompoundCollection.h"
9 //--------------------------------------------------------------------
10 // Construction/Destruction
11 //--------------------------------------------------------------------
13 CCorpusWord::CCorpusWord(CMiniLexicon
* lex
): CLParse( lex
)
15 m_morphemes
.resize( m_PieceCount
);
21 CCorpusWord::CCorpusWord(const CStringSurrogate
& ssCorpusWord
, CMiniLexicon
* lex
): CLParse( ssCorpusWord
, lex
)
23 m_morphemes
.resize( m_PieceCount
);
29 CCorpusWord::CCorpusWord(CCorpusWord
& CorpusWord
): CLParse( CorpusWord
, NULL
)
31 m_morphemes
.resize( m_PieceCount
);
37 CCorpusWord::CCorpusWord(const CLParse
& LParse
): CLParse( LParse
, LParse
.GetMyMini() )
39 m_morphemes
.resize( m_PieceCount
);
45 CCorpusWord::CCorpusWord(const CParse
& Parse
, CMiniLexicon
* lex
): CLParse( Parse
, lex
)
47 m_morphemes
.resize( m_PieceCount
);
53 CCorpusWord::~CCorpusWord()
58 //-----------------------------------------------------------------
59 // Overloaded operators
60 //-----------------------------------------------------------------
62 void CCorpusWord::operator= (const CCorpusWord
& RHS
)
66 m_morphemes
.resize( m_PieceCount
);
70 void CCorpusWord::Copy (CCorpusWord
& RHS
)
74 m_morphemes
.resize( m_PieceCount
);
78 //--------------------------------------------------
79 // Public accessor methods
80 //--------------------------------------------------
82 CLParse
* CCorpusWord::GetMorpheme( int i
) const
84 if( i
> 0 && i
<= Size() ) return m_morphemes
[i
-1];
88 //--------------------------------------------------
89 // Public mutator methods
90 //--------------------------------------------------
92 void CCorpusWord::CutRightBeforeHere( int i
)
94 CParse::CutRightBeforeHere(i
);
96 m_morphemes
.resize( m_PieceCount
);
98 Q_ASSERT( m_LengthOfPieceVector
>= Size() );
100 for( int j
= Size() - 1; j
> 0; j
-- )
102 if( m_Pieces
[j
+1] > i
) m_morphemes
.insert( j
, m_morphemes
[j
-1] );
107 void CCorpusWord::MergePieces( int i
)
109 for (int j
= i
; j
< m_PieceCount
- 1; ++j
)
110 m_morphemes
.insert( j
, m_morphemes
[j
+1] );
111 m_morphemes
.remove( m_PieceCount
- 1 );
113 CParse::MergePieces(i
);
114 m_morphemes
.resize( m_PieceCount
);
118 void CCorpusWord::SetMorpheme( int i
, CLParse
* pMorph
)
120 if( i
> 0 && i
<= Size() ) m_morphemes
.insert( i
- 1, pMorph
);
124 void CCorpusWord::SimplifyParseStructure()
126 CParse::SimplifyParseStructure();
128 m_morphemes
.resize( m_PieceCount
);
132 void CCorpusWord::CopyParseStructure( CCompound
* other
)
134 CParse::CopyParseStructure( *other
);
139 m_morphemes
.resize( m_PieceCount
);
141 for( int i
= 1; i
<= other
->Size(); i
++ )
143 pStems
= other
->GetComponent(i
);
144 if( pStems
) m_morphemes
.insert( i
- 1, pStems
->at(0) );
147 pLinker
= other
->GetLinker(i
);
148 if( pLinker
) m_morphemes
.insert( i
- 1, pLinker
);
149 else m_morphemes
.remove(i
);
155 void CCorpusWord::SetLengthOfPieceVector(int i
)
157 m_LengthOfPieceVector
= i
;
158 m_morphemes
.resize( m_PieceCount
);