blob: fcb1e4fb8d2510d616f222123249fe0f10ca92f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* @author Peter Boros
* @date 2004/10/01
* @version $Id$
* @file conceptnetmanager.h
* @brief Concept network manager class definition.
*
*/
#pragma once
#include <string>
#include <map>
#include "singleton.h"
#include "rwlock.h"
#include "conceptnethandle.h"
namespace fsa {
// {{{ class ConceptNetManager
/**
* @class ConceptNetManager
* @brief Class for managing concept networks.
*
* This class provides a single point of access to all concept networks
* used by the applications.
*/
class ConceptNetManager : public Singleton<ConceptNetManager> {
protected:
friend class Singleton<ConceptNetManager>;
/** Default constructor. Protected to avoid accidental creation */
ConceptNetManager() : _library(), _lock() {}
private:
/** Private unimplemented copy constructor */
ConceptNetManager(const ConceptNetManager&);
/** Private unimplemented assignment operator */
ConceptNetManager& operator=(const ConceptNetManager&);
/** %ConceptNet library type */
using Library = std::map<std::string,ConceptNet::Handle*>;
/** %ConceptNet library iterator type */
using LibraryIterator = std::map<std::string,ConceptNet::Handle*>::iterator;
/** %ConceptNet library const iterator type */
using LibraryConstIterator = std::map<std::string,ConceptNet::Handle*>::const_iterator;
Library _library; /**< Library of concept networks. */
mutable RWLock _lock; /**< Read-write lock for library synchronization. */
public:
/** Destructor */
~ConceptNetManager();
/**
* @brief Load a concept network into memory.
*
* @param id Concept network id (to be used in later get() or drop() calls).
* @param fsafile Concept net %FSA file name
* @param datafile Concept net data file name (defaults to empty
* string which means use the fsa file name but
* replace .fsa extension with .dat).
*/
bool load(const std::string &id,
const std::string &fsafile,
const std::string &datafile=std::string(""));
/**
* @brief Get a handle to a concept net.
*
* @param id Concept net id.
* @return Newly allocated handle, must be deleted by the
* caller. (NULL if no concept net with the given id was found.)
*/
ConceptNet::Handle* get(const std::string &id) const;
/**
* @brief Drop a concept net from the library.
*
* Drop a concept net from the library. The concept net object will
* be deleted automagically when there are no more handles referring
* to it.
*
* @param id Concept net id.
*/
void drop(const std::string &id);
/**
* @brief Drop all concept nets from the library.
*/
void clear();
};
// }}}
} // namespace fsa
|