LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
file.cpp
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include <fstream>
7
8#include "file.h"
9
10using namespace std;
11
12namespace deeplima
13{
14namespace CoNLLU
15{
16 void CoNLLUFile::load(const string& filename)
17 {
18 ifstream input(filename);
19 if (!input.is_open())
20 {
21 throw invalid_argument(string("Can't open file \"") + filename + "\"");
22 }
23
24 string line;
25 size_t n = 0;
26 while (getline(input, line))
27 {
28 CoNLLULine l(line);
29 _lines.push_back(l);
30 n += 1;
31 }
32 }
33
35 void CoNLLUFile::save(const string& filename, bool /*force*/)
36 {
37 ofstream output(filename);
38 if (!output.is_open())
39 {
40 throw invalid_argument(string("Can't open file \"") + filename + "\"");
41 }
42
43 for (const CoNLLULine& l : _lines)
44 {
45 string s = l.write();
46 output << s << endl;
47 }
48 }
49
50} // namespace CoNLLU
51} // namespace deeplima
52
void save(const std::string &filename, bool force=false)
TODO implement the force parameter.
Definition file.cpp:35
std::vector< CoNLLULine > _lines
Definition file.h:40
void load(const std::string &filename)
Definition file.cpp:16
STL namespace.