blob: 561c040af91239a45a6672dc69ce4cf178c44488 (
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
|
// 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.cpp
* @brief Concept network manager class implementation.
*
*/
#include "conceptnetmanager.h"
namespace fsa {
// {{{ ConceptNetManager::~ConceptNetManager()
ConceptNetManager::~ConceptNetManager()
{
for(LibraryIterator it=_library.begin(); it!=_library.end();++it){
delete it->second;
}
}
// }}}
// {{{ ConceptNetManager::load()
bool ConceptNetManager::load(const std::string &id, const std::string &fsafile, const std::string &datafile)
{
ConceptNet::Handle *newcn = new ConceptNet::Handle(fsafile.c_str(), datafile.length()>0?datafile.c_str():NULL);
if(newcn==NULL || !(*newcn)->isOk()){
delete newcn;
return false;
}
_lock.wrLock();
{
LibraryIterator it = _library.find(id);
if(it!=_library.end()){
delete it->second;
it->second = newcn;
}
else
_library.insert(Library::value_type(id,newcn));
}
_lock.unlock();
return true;
}
// }}}
// {{{ ConceptNetManager::get()
ConceptNet::Handle* ConceptNetManager::get(const std::string &id) const
{
ConceptNet::Handle *newhandle=NULL;
_lock.rdLock();
{
LibraryConstIterator it = _library.find(id);
if(it!=_library.end()){
newhandle = new ConceptNet::Handle(*(it->second));
}
}
_lock.unlock();
return newhandle;
}
// }}}
// {{{ ConceptNetManager::drop()
void ConceptNetManager::drop(const std::string &id)
{
_lock.wrLock();
{
LibraryIterator it = _library.find(id);
if(it!=_library.end()){
delete it->second;
_library.erase(it);
}
}
_lock.unlock();
}
// }}}
// {{{ ConceptNetManager::clear()
void ConceptNetManager::clear()
{
_lock.wrLock();
{
for(LibraryIterator it = _library.begin(); it!=_library.end(); ++it)
delete it->second;
_library.clear();
}
_lock.unlock();
}
// }}}
} // namespace fsa
|