1. fix "exit(0)" bug when open RDF file failed.
2. update api example code. author: hanshuo
This commit is contained in:
parent
5b046cfcfe
commit
cda9e29e86
|
@ -221,6 +221,7 @@ bool Database::remove(const string& _rdf_file)
|
||||||
bool Database::build(const string& _rdf_file)
|
bool Database::build(const string& _rdf_file)
|
||||||
{
|
{
|
||||||
long tv_build_begin = util::get_cur_time();
|
long tv_build_begin = util::get_cur_time();
|
||||||
|
bool flag = true;
|
||||||
|
|
||||||
std::string store_path = this->name;
|
std::string store_path = this->name;
|
||||||
util::create_dir(store_path);
|
util::create_dir(store_path);
|
||||||
|
@ -233,8 +234,14 @@ bool Database::build(const string& _rdf_file)
|
||||||
|
|
||||||
cout << "begin encode RDF from : " << _rdf_file << " ..." << endl;
|
cout << "begin encode RDF from : " << _rdf_file << " ..." << endl;
|
||||||
// to be switched to new encodeRDF method.
|
// to be switched to new encodeRDF method.
|
||||||
// this->encodeRDF(_rdf_file);
|
// flag = this->encodeRDF(_rdf_file);
|
||||||
this->encodeRDF_new(_rdf_file);
|
flag = this->encodeRDF_new(_rdf_file);
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
std::cout << "encode RDF failed."<< std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
cout << "finish encode." << endl;
|
cout << "finish encode." << endl;
|
||||||
std::string _entry_file = this->getSignatureBFile();
|
std::string _entry_file = this->getSignatureBFile();
|
||||||
(this->kvstore)->open();
|
(this->kvstore)->open();
|
||||||
|
@ -474,27 +481,27 @@ bool Database::encodeRDF(const string _rdf_file)
|
||||||
bool Database::encodeRDF_new(const string _rdf_file)
|
bool Database::encodeRDF_new(const string _rdf_file)
|
||||||
{
|
{
|
||||||
Database::log("In encodeRDF_new");
|
Database::log("In encodeRDF_new");
|
||||||
|
bool flag = true;
|
||||||
|
|
||||||
int ** _p_id_tuples = NULL;
|
int ** _p_id_tuples = NULL;
|
||||||
int _id_tuples_max = 0;
|
int _id_tuples_max = 0;
|
||||||
|
|
||||||
/* map sub2id, pre2id, entity/literal in obj2id, store in kvstore, encode RDF data into signature */
|
/* map sub2id, pre2id, entity/literal in obj2id, store in kvstore, encode RDF data into signature */
|
||||||
this->sub2id_pre2id_obj2id_RDFintoSignature(_rdf_file, _p_id_tuples, _id_tuples_max);
|
flag = this->sub2id_pre2id_obj2id_RDFintoSignature(_rdf_file, _p_id_tuples, _id_tuples_max);
|
||||||
|
if (!flag) return false;
|
||||||
/* map subid 2 objid_list &
|
/* map subid 2 objid_list &
|
||||||
* subIDpreID 2 objid_list &
|
* subIDpreID 2 objid_list &
|
||||||
* subID 2 <preIDobjID>_list */
|
* subID 2 <preIDobjID>_list */
|
||||||
this->s2o_sp2o_s2po(_p_id_tuples, _id_tuples_max);
|
flag = this->s2o_sp2o_s2po(_p_id_tuples, _id_tuples_max);
|
||||||
|
if (!flag) return false;
|
||||||
/* map objid 2 subid_list &
|
/* map objid 2 subid_list &
|
||||||
* objIDpreID 2 subid_list &
|
* objIDpreID 2 subid_list &
|
||||||
* objID 2 <preIDsubID>_list */
|
* objID 2 <preIDsubID>_list */
|
||||||
this->o2s_op2s_o2ps(_p_id_tuples, _id_tuples_max);
|
flag = this->o2s_op2s_o2ps(_p_id_tuples, _id_tuples_max);
|
||||||
|
if (!flag) return false;
|
||||||
|
|
||||||
bool flag = this->saveDBInfoFile();
|
flag = this->saveDBInfoFile();
|
||||||
if (!flag)
|
if (!flag) return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Database::log("finish encodeRDF_new");
|
Database::log("finish encodeRDF_new");
|
||||||
|
|
||||||
|
@ -527,14 +534,14 @@ bool Database::sub2id_pre2id_obj2id_RDFintoSignature(const string _rdf_file, int
|
||||||
ifstream _fin(_rdf_file.c_str());
|
ifstream _fin(_rdf_file.c_str());
|
||||||
if(!_fin){
|
if(!_fin){
|
||||||
cerr << "sub2id&pre2id&obj2id: Fail to open : " << _rdf_file << endl;
|
cerr << "sub2id&pre2id&obj2id: Fail to open : " << _rdf_file << endl;
|
||||||
exit(0);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string _six_tuples_file = this->getSixTuplesFile();
|
std::string _six_tuples_file = this->getSixTuplesFile();
|
||||||
std::ofstream _six_tuples_fout(_six_tuples_file.c_str());
|
std::ofstream _six_tuples_fout(_six_tuples_file.c_str());
|
||||||
if(! _six_tuples_fout){
|
if(! _six_tuples_fout){
|
||||||
cerr << "sub2id&pre2id&obj2id: Fail to open: " << _six_tuples_file << endl;
|
cerr << "sub2id&pre2id&obj2id: Fail to open: " << _six_tuples_file << endl;
|
||||||
exit(0);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TripleWithObjType* triple_array = new TripleWithObjType[RDFParser::TRIPLE_NUM_PER_GROUP];
|
TripleWithObjType* triple_array = new TripleWithObjType[RDFParser::TRIPLE_NUM_PER_GROUP];
|
||||||
|
@ -665,17 +672,18 @@ bool Database::sub2id_pre2id_obj2id_RDFintoSignature(const string _rdf_file, int
|
||||||
//_entity_bitset is used up, double the space
|
//_entity_bitset is used up, double the space
|
||||||
if (this->entity_num >= entitybitset_max)
|
if (this->entity_num >= entitybitset_max)
|
||||||
{
|
{
|
||||||
entitybitset_max *= 2;
|
EntityBitSet** _new_entity_bitset = new EntityBitSet* [entitybitset_max * 2];
|
||||||
EntityBitSet** _new_entity_bitset = new EntityBitSet* [entitybitset_max];
|
memcpy(_new_entity_bitset, _entity_bitset, sizeof(EntityBitSet*) * entitybitset_max);
|
||||||
memcpy(_new_entity_bitset, _entity_bitset, sizeof(EntityBitSet*) * this->entity_num);
|
|
||||||
delete[] _entity_bitset;
|
delete[] _entity_bitset;
|
||||||
_entity_bitset = _new_entity_bitset;
|
_entity_bitset = _new_entity_bitset;
|
||||||
|
|
||||||
for(int i = this->entity_num; i < entitybitset_max; i ++)
|
for(int i = entitybitset_max; i < entitybitset_max * 2; i ++)
|
||||||
{
|
{
|
||||||
_entity_bitset[i] = new EntityBitSet();
|
_entity_bitset[i] = new EntityBitSet();
|
||||||
_entity_bitset[i] -> reset();
|
_entity_bitset[i] -> reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entitybitset_max *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,6 +103,13 @@ gclient is designed as a client to send commands and receive feedbacks.
|
||||||
ip=127.0.0.1 port=3305
|
ip=127.0.0.1 port=3305
|
||||||
->
|
->
|
||||||
|
|
||||||
|
You can also assign gserver's ip and port.
|
||||||
|
|
||||||
|
[root@centos74 Gstore]# ./gclient 172.31.19.15 3307
|
||||||
|
ip=172.31.19.15 port=3307
|
||||||
|
->
|
||||||
|
|
||||||
|
|
||||||
We can use these following commands now:
|
We can use these following commands now:
|
||||||
|
|
||||||
`->import db_name rdf_triple_file_name;`
|
`->import db_name rdf_triple_file_name;`
|
||||||
|
|
|
@ -17,18 +17,18 @@ int main(int argc, char * argv[])
|
||||||
|
|
||||||
// build a new database by a RDF file.
|
// build a new database by a RDF file.
|
||||||
// note that the relative path is related to gserver.
|
// note that the relative path is related to gserver.
|
||||||
gc.build("db_LUBM10", "example/rdf_triple/LUBM_10_GStore.n3");
|
gc.build("db_LUBM10", "example/LUBM_10.n3");
|
||||||
|
|
||||||
// then you can execute SPARQL query on this database.
|
// then you can execute SPARQL query on this database.
|
||||||
std::string sparql = "select ?x where \
|
std::string sparql = "select ?x where \
|
||||||
{ \
|
{ \
|
||||||
?x rdf:type <ub:UndergraduateStudent>. \
|
?x <rdf:type> <ub:UndergraduateStudent>. \
|
||||||
?y ub:name <Course1>. \
|
?y <ub:name> <Course1>. \
|
||||||
?x ub:takesCourse ?y. \
|
?x <ub:takesCourse> ?y. \
|
||||||
?z ub:teacherOf ?y. \
|
?z <ub:teacherOf> ?y. \
|
||||||
?z ub:name <FullProfessor1>. \
|
?z <ub:name> <FullProfessor1>. \
|
||||||
?z ub:worksFor ?w. \
|
?z <ub:worksFor> ?w. \
|
||||||
?w ub:name <Department0>. \
|
?w <ub:name> <Department0>. \
|
||||||
}";
|
}";
|
||||||
std::string answer = gc.query(sparql);
|
std::string answer = gc.query(sparql);
|
||||||
std::cout << answer << std::endl;
|
std::cout << answer << std::endl;
|
||||||
|
|
|
@ -17,18 +17,18 @@ public class JavaAPIExample
|
||||||
|
|
||||||
// build a new database by a RDF file.
|
// build a new database by a RDF file.
|
||||||
// note that the relative path is related to gserver.
|
// note that the relative path is related to gserver.
|
||||||
gc.build("db_LUBM10", "example/rdf_triple/LUBM_10_GStore.n3");
|
gc.build("db_LUBM10", "example/LUBM_10.n3");
|
||||||
|
|
||||||
// then you can execute SPARQL query on this database.
|
// then you can execute SPARQL query on this database.
|
||||||
String sparql = "select ?x where "
|
String sparql = "select ?x where "
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "?x rdf:type <ub:UndergraduateStudent>. "
|
+ "?x <rdf:type> <ub:UndergraduateStudent>. "
|
||||||
+ "?y ub:name <Course1>. "
|
+ "?y <ub:name> <Course1>. "
|
||||||
+ "?x ub:takesCourse ?y. "
|
+ "?x <ub:takesCourse> ?y. "
|
||||||
+ "?z ub:teacherOf ?y. "
|
+ "?z <ub:teacherOf> ?y. "
|
||||||
+ "?z ub:name <FullProfessor1>. "
|
+ "?z <ub:name> <FullProfessor1>. "
|
||||||
+ "?z ub:worksFor ?w. "
|
+ "?z <ub:worksFor> ?w. "
|
||||||
+ "?w ub:name <Department0>. "
|
+ "?w <ub:name> <Department0>. "
|
||||||
+ "}";
|
+ "}";
|
||||||
String answer = gc.query(sparql);
|
String answer = gc.query(sparql);
|
||||||
System.out.println(answer);
|
System.out.println(answer);
|
||||||
|
|
|
@ -25,7 +25,15 @@ int main(int argc, char * argv[])
|
||||||
string _db_path = string(argv[1]);
|
string _db_path = string(argv[1]);
|
||||||
string _rdf = string(argv[2]);
|
string _rdf = string(argv[2]);
|
||||||
Database _db(_db_path);
|
Database _db(_db_path);
|
||||||
_db.build(_rdf);
|
bool flag = _db.build(_rdf);
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
cout << "import RDF file to database done." << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "import RDF file to database failed." << endl;
|
||||||
|
}
|
||||||
system("clock");
|
system("clock");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue