void TTransCorpus::SaveTxt(const TStr& OutFBase, const TStr& OutOrgFNm, const TStr& OutTransFNm, const TStr& OutRefTransFNm, TStrV& OrgFNmV, TStrV& TransFNmV, TStrV& RefTransFNmV, const int& LinesPerFile) { // prepare filenames OrgFNmV.Clr(); TransFNmV.Clr(); RefTransFNmV.Clr(); if (!OutOrgFNm.Empty()) { OrgFNmV.Add(GetOutFNm(OutFBase, 0, LinesPerFile, OutOrgFNm)); } if (!OutTransFNm.Empty()) { TransFNmV.Add(GetOutFNm(OutFBase, 0, LinesPerFile, OutTransFNm)); } if (!OutRefTransFNm.Empty()) { RefTransFNmV.Add(GetOutFNm(OutFBase, 0, LinesPerFile, OutRefTransFNm)); } // open files PSOut OrgSOut = !OutOrgFNm.Empty() ? TFOut::New(OrgFNmV.Last()) : PSOut(); PSOut TransSOut = !OutTransFNm.Empty() ? TFOut::New(TransFNmV.Last()) : PSOut(); PSOut RefTransSOut = !OutRefTransFNm.Empty() ? TFOut::New(RefTransFNmV.Last()) : PSOut(); // check which are given const bool IsOrgP = !OrgSOut.Empty() && IsOrg(); const bool IsTransP = !TransSOut.Empty() && IsTrans(); const bool IsRefTransP = !RefTransSOut.Empty() && IsRefTrans(); // print warnings if (!IsOrgP) { printf("No original sentences!\n"); } if (!IsTransP) { printf("No machine translation sentences!\n"); } if (!IsRefTransP) { printf("No reference translation sentences!\n"); } // go over all the sentences and store them in the file TIntV SentIdV; GetSentIdV(SentIdV); for (int SentIdN = 0; SentIdN < SentIdV.Len(); SentIdN++) { const int SentId = SentIdV[SentIdN]; if (IsOrgP) { OrgSOut->PutStrLn(GetOrgStr(SentId)); } if (IsTransP) { TransSOut->PutStrLn(GetTransStr(SentId)); } if (IsRefTransP) { RefTransSOut->PutStrLn(GetRefTransStrV(SentId)[0]); } // should we break and go to next file? if ((LinesPerFile!=-1) && (SentIdN>0) && (SentIdN % LinesPerFile == 0)) { // prepare filenames if (!OutOrgFNm.Empty()) { OrgFNmV.Add(GetOutFNm(OutFBase, SentIdN, LinesPerFile, OutOrgFNm)); } if (!OutTransFNm.Empty()) { TransFNmV.Add(GetOutFNm(OutFBase, SentIdN, LinesPerFile, OutTransFNm)); } if (!OutRefTransFNm.Empty()) { RefTransFNmV.Add(GetOutFNm(OutFBase, SentIdN, LinesPerFile, OutRefTransFNm)); } // open next files files OrgSOut = !OutOrgFNm.Empty() ? TFOut::New(OrgFNmV.Last()) : PSOut(); TransSOut = !OutTransFNm.Empty() ? TFOut::New(TransFNmV.Last()) : PSOut(); RefTransSOut = !OutRefTransFNm.Empty() ? TFOut::New(RefTransFNmV.Last()) : PSOut(); } } }
void TTb::SaveAssis(const TStr& FNm){ TStr DoFNm=FNm.GetFPath()+"AsDo"+FNm.GetFMid().GetSubStr(0, 3)+".Dat"; TStr DaFNm=FNm.GetFPath()+"AsDa"+FNm.GetFMid().GetSubStr(0, 3)+".Dat"; TOLx DoLx(PSOut(new TFOut(DoFNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr); int Dscs=GetVar(0)->GetVarType()->GetDscs(); Assert(Dscs>0); DoLx.PutInt(Dscs); DoLx.PutDosLn(); for (int DscN=0; DscN<Dscs; DscN++){ TTbVal Val=GetVar(0)->GetVarType()->GetVal(DscN); DoLx.PutStr(GetVar(0)->GetVarType()->GetValStr(Val)); DoLx.PutDosLn(); } DoLx.PutInt(TInt(GetVars()-1)); DoLx.PutDosLn(); for (int VarN=1; VarN<GetVars(); VarN++){ DoLx.PutStr(GetVar(VarN)->GetNm()); DoLx.PutDosLn(); int Dscs=GetVar(VarN)->GetVarType()->GetDscs(); if (Dscs>0){ DoLx.PutInt(Dscs); DoLx.PutDosLn(); for (int DscN=0; DscN<Dscs; DscN++){ TTbVal Val=GetVar(VarN)->GetVarType()->GetVal(DscN); DoLx.PutStr(GetVar(VarN)->GetVarType()->GetValStr(DscN)); DoLx.PutDosLn();} } else { DoLx.PutInt(TInt(0)); DoLx.PutInt(TInt(100)); DoLx.PutDosLn(); } } TOLx DaLx(PSOut(new TFOut(DaFNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr); for (int TupN=0; TupN<GetTups(); TupN++){ for (int VarN=0; VarN<GetVars(); VarN++){ TTbVal Val=GetVal(TupN, VarN); switch (Val.GetValTag()){ case tvtUnknw: DaLx.PutSym(syQuestion); break; case tvtUnimp: DaLx.PutSym(syAsterisk); break; case tvtUnapp: DaLx.PutSym(syAsterisk); break; case tvtDsc: DaLx.PutInt(TInt(1+Val.GetDsc())); break; case tvtFlt: DaLx.PutFlt(Val.GetFlt()); break; default: Fail; } } DaLx.PutDosLn(); } }
void TTb::SaveTxt(const TStr& FNm, const bool& SaveTupNm){ TOLx Lx(PSOut(new TFOut(FNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr|oloTabSep); if (SaveTupNm){Lx.PutStr("Name");} for (int VarN=0; VarN<GetVars(); VarN++){ Lx.PutStr(GetVar(VarN)->GetNm());} Lx.PutLn(); for (int TupN=0; TupN<GetTups(); TupN++){ if (SaveTupNm){Lx.PutStr(GetTupNm(TupN));} for (int VarN=0; VarN<GetVars(); VarN++){ TTbVal Val=GetVal(TupN, VarN); switch (Val.GetValTag()){ case tvtUnknw: Lx.PutSym(syQuestion); break; case tvtUnimp: Lx.PutSym(syAsterisk); break; case tvtUnapp: Lx.PutSym(sySlash); break; case tvtDsc: Lx.PutStr(GetVar(VarN)->GetVarType()->GetValStr(Val)); break; case tvtFlt: Lx.PutFlt(Val.GetFlt()); break; default: Fail; } } Lx.PutLn(); } }
PSOut TFOut::New(const TStr& FNm, const bool& Append, bool& OpenedP){ PSOut SOut=PSOut(new TFOut(FNm, Append, OpenedP)); if (OpenedP){return SOut;} else {return NULL;} }
PSOut TFOut::New(const TStr& FNm, const bool& Append){ return PSOut(new TFOut(FNm, Append)); }
void TSOut::Save(TSIn& SIn, const TSize& BfL){ Fail; if (BfL==0){ //J: used to be ==-1 while (!SIn.Eof()){Save(SIn.GetCh());} } else { for (TSize BfC=0; BfC<BfL; BfC++){Save(SIn.GetCh());} } } TSOut& TSOut::operator<<(TSIn& SIn) { while (!SIn.Eof()) operator<<((char)SIn.GetCh()); return *this; } const PSOut TSOut::StdOut=PSOut(new TStdOut()); TStdOut::TStdOut(): TSBase(TSStr("Standard output")), TSOut("Standard output"){} ///////////////////////////////////////////////// // Standard-Input int TStdIn::GetBf(const void* LBf, const TSize& LBfL){ int LBfS=0; for (TSize LBfC=0; LBfC<LBfL; LBfC++){ LBfS+=(((char*)LBf)[LBfC]=GetCh());} return LBfS; } bool TStdIn::GetNextLnBf(TChA& LnChA){ // not implemented FailR(TStr::Fmt("TStdIn::GetNextLnBf: not implemented").CStr());
PSOut TZipOut::New(const TStr& FNm){ return PSOut(new TZipOut(FNm)); }
void TSch::SaveTxt(const TStr& FNm) const { PSOut SOut=PSOut(new TFOut(FNm)); TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum|oloCsSens|oloVarIndent); SaveTxt(Lx); }