LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
train_params.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 <string>
7#include <boost/filesystem.hpp>
8
9#include "conllu/treebank.h"
10#include "train_params.h"
11
12namespace deeplima
13{
14namespace train
15{
16
17 void train_params_t::guess_data_sets(const std::string& ud_path, const std::string& corpus)
18 {
19 boost::filesystem::path path = boost::filesystem::path(ud_path) / corpus;
20
21 for (boost::filesystem::directory_entry& entry : boost::filesystem::directory_iterator(path))
22 {
23 if (entry.path().extension().string() == ".conllu")
24 {
25 std::map<std::string, std::string> fields;
26 if (!CoNLLU::parse_ud_file_name(entry.path().filename().string(), fields)
27 || fields.end() == fields.find("part")
28 || fields["part"].size() == 0)
29 {
30 throw std::logic_error("Can't parse file name \"" + entry.path().filename().string() + "\"");
31 }
32
33 if (m_train_set_fn.empty() && fields["part"] == "train")
34 {
35 m_train_set_fn = entry.path().string();
36 }
37 else if (m_dev_set_fn.empty() && fields["part"] == "dev")
38 {
39 m_dev_set_fn = entry.path().string();
40 }
41 }
42 }
43 }
44
45} // namespace train
46} // namespace deeplima
bool parse_ud_file_name(const std::string &fn, map< string, string > &fields)
Definition treebank.cpp:362
virtual void guess_data_sets(const std::string &ud_path, const std::string &corpus)