<commit_before>/* vim: set sw=4 sts=4 et foldmethod=syntax : */

#include <graph/net.hh>
#include <graph/graph.hh>
#include <boost/regex.hpp>
#include <fstream>

using namespace parasols;

InvalidNetFile::InvalidNetFile(const std::string & filename, const std::string & message) throw () :
    _what("Error reading file '" + filename + "': " + message)
{
}

auto InvalidNetFile::what() const throw () -> const char *
{
    return _what.c_str();
}

auto parasols::read_net(const std::string & filename) -> Graph
{
    Graph result(0, true);

    std::ifstream infile{ filename };
    if (! infile)
        throw InvalidNetFile{ filename, "unable to open file" };

    std::string line;
    while (std::getline(infile, line)) {
        if (line.empty())
            continue;

        if (line.at(line.length() - 1) == '\r')
            line.erase(line.length() - 1);

        static const boost::regex
            comment{ R"((%.*)?)" },
            problem{ R"(\*\s*Vertices\s+(\d+))" },
            description{ R"(\d+\s+".*")" },
            edge_start{ R"(\*\s*Edgeslist)" };

        boost::smatch match;
        if (regex_match(line, match, comment)) {
        }
        else if (regex_match(line, match, description)) {
        }
        else if (regex_match(line, match, problem)) {
            if (0 != result.size())
                throw InvalidNetFile{ filename, "multiple '*Vertices' lines encountered" };
            result.resize(std::stoi(match.str(1)));
        }
        else if (regex_match(line, match, edge_start)) {
            break;
        }
        else
            throw InvalidNetFile{ filename, "cannot parse line '" + line + "'" };
    }

    while (std::getline(infile, line)) {
        if (line.empty())
            continue;

        if (line.at(line.length() - 1) == '\r')<commit_msg>Skip arcslist line<commit_after>/* vim: set sw=4 sts=4 et foldmethod=syntax : */

#include <graph/net.hh>
#include <graph/graph.hh>
#include <boost/regex.hpp>
#include <fstream>

using namespace parasols;

InvalidNetFile::InvalidNetFile(const std::string & filename, const std::string & message) throw () :
    _what("Error reading file '" + filename + "': " + message)
{
}

auto InvalidNetFile::what() const throw () -> const char *
{
    return _what.c_str();
}

auto parasols::read_net(const std::string & filename) -> Graph
{
    Graph result(0, true);

    std::ifstream infile{ filename };
    if (! infile)
        throw InvalidNetFile{ filename, "unable to open file" };

    std::string line;
    while (std::getline(infile, line)) {
        if (line.empty())
            continue;

        if (line.at(line.length() - 1) == '\r')
            line.erase(line.length() - 1);

        static const boost::regex
            comment{ R"((%.*)?)" },
            problem{ R"(\*\s*Vertices\s+(\d+))" },
            description{ R"(\d+\s+".*")" },
            arcs{ R"(\*\s*Arcslist)" },
            edge_start{ R"(\*\s*Edgeslist)" };

        boost::smatch match;
        if (regex_match(line, match, comment)) {
        }
        else if (regex_match(line, match, description) || regex_match(line, match, arcs)) {
        }
        else if (regex_match(line, match, problem)) {
            if (0 != result.size())
                throw InvalidNetFile{ filename, "multiple '*Vertices' lines encountered" };
            result.resize(std::stoi(match.str(1)));
        }
        else if (regex_match(line, match, edge_start)) {
            break;
        }
        else
            throw InvalidNetFile{ filename, "cannot parse line '" + line + "'" };
    }

    while (std::getline(infile, line)) {
        if (line.empty())
            continue;

        if (line.at(line.length() - 1) == '\r')
{'fraction_non_alphanumeric': 0.1677888499865338, 'fraction_numerical': 0.0043091839482897925, 'mean_word_length': 2.327956989247312, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1589225', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1157, 'n_words': 276}