00001 /********************************* 00002 tercpp: an open-source Translation Edit Rate (TER) scorer tool for Machine Translation. 00003 00004 Copyright 2010-2013, Christophe Servan, LIUM, University of Le Mans, France 00005 Contact: christophe.servan@lium.univ-lemans.fr 00006 00007 The tercpp tool and library are free software: you can redistribute it and/or modify it 00008 under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 2.1 of the licence, or 00010 (at your option) any later version. 00011 00012 This program and library are distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this library; if not, write to the Free Software Foundation, 00019 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 **********************************/ 00021 #include "terShift.h" 00022 00023 using namespace std; 00024 namespace TERCPPNS_TERCpp 00025 { 00026 00027 // terShift::terShift() 00028 // { 00029 // // vector<string> ref; 00030 // // vector<string> hyp; 00031 // // vector<string> aftershift; 00032 // 00033 // // terShift[] allshifts = null; 00034 // 00035 // numEdits=0; 00036 // numWords=0; 00037 // bestRef=""; 00038 // 00039 // numIns=0; 00040 // numDel=0; 00041 // numSub=0; 00042 // numSft=0; 00043 // numWsf=0; 00044 // } 00045 terShift::terShift () 00046 { 00047 start = 0; 00048 end = 0; 00049 moveto = 0; 00050 newloc = 0; 00051 cost=1.0; 00052 shifted.clear(); 00053 alignment.clear(); 00054 aftershift.clear(); 00055 } 00056 terShift::terShift ( int _start, int _end, int _moveto, int _newloc ) 00057 { 00058 start = _start; 00059 end = _end; 00060 moveto = _moveto; 00061 newloc = _newloc; 00062 cost=1.0; 00063 } 00064 00065 terShift::terShift ( int _start, int _end, int _moveto, int _newloc, vector<string> _shifted ) 00066 { 00067 start = _start; 00068 end = _end; 00069 moveto = _moveto; 00070 newloc = _newloc; 00071 shifted = _shifted; 00072 cost=1.0; 00073 } 00074 void terShift::set(terShift l_terShift) 00075 { 00076 start=l_terShift.start; 00077 end=l_terShift.end; 00078 moveto=l_terShift.moveto; 00079 newloc=l_terShift.newloc; 00080 shifted=l_terShift.shifted; 00081 // alignment=l_terShift.alignment; 00082 // aftershift=l_terShift.aftershift; 00083 } 00084 void terShift::set(terShift *l_terShift) 00085 { 00086 start=l_terShift->start; 00087 end=l_terShift->end; 00088 moveto=l_terShift->moveto; 00089 newloc=l_terShift->newloc; 00090 shifted=l_terShift->shifted; 00091 // alignment=l_terShift->alignment; 00092 // aftershift=l_terShift->aftershift; 00093 } 00094 00095 void terShift::erase() 00096 { 00097 start = 0; 00098 end = 0; 00099 moveto = 0; 00100 newloc = 0; 00101 cost=1.0; 00102 shifted.clear(); 00103 alignment.clear(); 00104 aftershift.clear(); 00105 } 00106 00107 00108 00109 // string terShift::vectorToString(vector<string> vec) 00110 // { 00111 // string retour(""); 00112 // for (vector<string>::iterator vecIter=vec.begin();vecIter!=vec.end(); vecIter++) 00113 // { 00114 // retour+=(*vecIter)+"\t"; 00115 // } 00116 // return retour; 00117 // } 00118 00119 string terShift::toString() 00120 { 00121 stringstream s; 00122 s.str ( "" ); 00123 s << "[" << start << ", " << end << ", " << moveto << "/" << newloc << "]"; 00124 if ( ( int ) shifted.size() > 0 ) { 00125 s << " (" << vectorToString ( shifted ) << ")"; 00126 } 00127 // s<< endl; 00128 // if ( ( int ) shifted.size() > 0 ) 00129 // { 00130 // s << " (" << vectorToString ( alignment ) << ")"; 00131 // } 00132 // s<< endl; 00133 // if ( ( int ) shifted.size() > 0 ) 00134 // { 00135 // s << " (" << vectorToString ( aftershift ) << ")"; 00136 // } 00137 return s.str(); 00138 } 00139 00140 /* The distance of the shift. */ 00141 int terShift::distance() 00142 { 00143 if ( moveto < start ) { 00144 return start - moveto; 00145 } else if ( moveto > end ) { 00146 return moveto - end; 00147 } else { 00148 return moveto - start; 00149 } 00150 } 00151 00152 bool terShift::leftShift() 00153 { 00154 return ( moveto < start ); 00155 } 00156 00157 int terShift::size() 00158 { 00159 return ( end - start ) + 1; 00160 } 00161 // terShift terShift::operator=(terShift t) 00162 // { 00163 // 00164 // return t; 00165 // } 00166 00167 00168 }