liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
serializer.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_SERIALIZATION_SERIALIZER_H
2#define LIBLEVENSHTEIN_SERIALIZATION_SERIALIZER_H
3
4#include <cstdint>
5#include <filesystem>
6#include <iostream>
7#include <map>
8#include <set>
9#include <utility>
10
13#include "liblevenshtein/proto/liblevenshtein.pb.h"
14
15namespace fs = std::filesystem;
16
17namespace llp = liblevenshtein::proto;
18
19namespace liblevenshtein {
20
28auto serialize_protobuf(Dawg *dawg, const fs::path &path) -> bool;
29
37auto serialize_protobuf(Dawg *dawg, const std::string &path) -> bool;
38
46auto serialize_protobuf(Dawg *dawg, const char *path) -> bool;
47
55auto serialize_protobuf(Dawg *dawg, std::ostream &output) -> bool;
56
64auto deserialize_protobuf(const fs::path &path) -> Dawg *;
65
73auto deserialize_protobuf(const std::string &path) -> Dawg *;
74
82auto deserialize_protobuf(const char *path) -> Dawg *;
83
91auto deserialize_protobuf(std::istream &input) -> Dawg *;
92
101void collect_nodes(DawgNode *source, std::set<uint64_t> &node_ids,
102 std::set<uint64_t> &final_node_ids);
103
112void collect_edges(DawgNode *source,
113 std::map<std::pair<uint64_t, char>, uint64_t> &edges);
114
121auto to_protobuf(Dawg *dawg) -> llp::Dictionary *;
122
130auto from_protobuf(const llp::Dictionary &dict_proto) -> Dawg *;
131
132} // namespace liblevenshtein
133
134#endif // LIBLEVENSHTEIN_SERIALIZATION_SERIALIZER_H
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25
Various utilities regarding Levenshtein transducers.
Definition namespaces.dox:9
auto to_protobuf(Dawg *dawg) -> llp::Dictionary *
Serializes a Dawg to its protobuf equivalent.
void collect_nodes(DawgNode *source, std::set< uint64_t > &node_ids, std::set< uint64_t > &final_node_ids)
Collects the DawgNode IDs and final DawgNode IDs of all nodes reachable from the source.
auto from_protobuf(const llp::Dictionary &dict_proto) -> Dawg *
Deserializes a Dawg from its protobuf equivalent.
void collect_edges(DawgNode *source, std::map< std::pair< uint64_t, char >, uint64_t > &edges)
Collects the transitions from each source to its destination, and the respective character labels.
auto deserialize_protobuf(const fs::path &path) -> Dawg *
Deserializes the protobuf containing a Dawg at the given path or returns nullptr if none exists.
auto serialize_protobuf(Dawg *dawg, const fs::path &path) -> bool
Serializes the given Dawg to protobuf at the given path.