Skip to content

Commit accafa7

Browse files
committed
parse dict.block.size
1 parent a944265 commit accafa7

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dictionary.type <http://purl.org/HDT/hdt#dictionaryFour>
22
triples.type <http://purl.org/HDT/hdt#triplesBitmap>
33
triplesOrder SPO
4+
dict.block.size 32
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dictionary.type <http://purl.org/HDT/hdt#dictionaryFour>
2+
triples.type <http://purl.org/HDT/hdt#triplesBitmap>
3+
triplesOrder SPO
4+
dict.block.size 0

libhdt/src/dictionary/FourSectionDictionary.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ FourSectionDictionary::FourSectionDictionary(HDTSpecification & spec) : blocksiz
6161
blockSizeStr = spec.get("dict.block.size");
6262
}catch(exception& e){}
6363

64-
if(!blockSizeStr.empty() && (blockSizeStr.find_first_not_of("0123456789") == string::npos) && blockSizeStr != "0"){
65-
//blocksize = atoi((const char*)blockSizeStr.c_str());
64+
if(!blockSizeStr.empty() && (blockSizeStr.find_first_not_of("0123456789") == string::npos))
65+
{
66+
blocksize = std::stoi( blockSizeStr );
67+
if ( blocksize <= 0 )
68+
{
69+
throw std::runtime_error("blocksize must be greater than 0");
70+
}
6671
}
6772
}
6873

libhdt/tests/properties.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ split(const std::string &s, char delim)
107107
std::map<std::string, std::tuple<std::string, std::string>> queries =
108108
{
109109
{ "dictionary.type", std::make_tuple("_:dictionary", "<http://purl.org/dc/terms/format>")},
110+
{ "dict.block.size", std::make_tuple("_:dictionary", "<http://purl.org/HDT/hdt#dictionaryblockSize>")},
110111
{ "triples.type", std::make_tuple("_:triples", "<http://purl.org/dc/terms/format>")},
111112
{ "triplesOrder", std::make_tuple("_:triples", "<http://purl.org/HDT/hdt#triplesOrder>")}
112113
};
@@ -191,7 +192,10 @@ int
191192
main(int argc, char** argv)
192193
{
193194
// Given these configuration files
194-
std::vector<std::string> elem = {"../presets/dictionaryfour.hdtcfg", "../presets/dictionaryliteral.hdtcfg", "../presets/ops.hdtcfg"};
195+
std::vector<std::string> elem = {
196+
"../presets/dictionaryfour.hdtcfg",
197+
"../presets/dictionaryliteral.hdtcfg",
198+
"../presets/ops.hdtcfg"};
195199
std::string nt_file_path = "../data/test.nt";
196200
std::string hdt_file_path = "./test.hdt";
197201
int err_creations = 0;
@@ -214,5 +218,22 @@ main(int argc, char** argv)
214218
// If some error, fail test
215219
if ( err_creations > 0 || err_readings > 0 || err_checking > 0)
216220
return 1;
221+
222+
// For wrong files, make sure creation fails
223+
std::vector<std::string> wrong_files = {
224+
"../presets/wrong_dictionaryfour.hdtcfg"
225+
};
226+
err_creations = 0;
227+
for (std::vector<std::string>::const_iterator iter = wrong_files.begin();
228+
iter != wrong_files.end();
229+
++iter)
230+
{
231+
err_creations += create_hdt_file(nt_file_path, *iter, hdt_file_path);
232+
}
233+
std::cout << "Expected fails: " << wrong_files.size()
234+
<< ", Actual fails: " << err_creations << std::endl;
235+
// If expected fails not equal to actual fails, then fail test
236+
if ( err_creations != wrong_files.size() )
237+
return 1;
217238
return 0;
218239
}

0 commit comments

Comments
 (0)