| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
#ifdef KONCLUDE_REDLAND_INTEGRATION |
| 21 |
|
| 22 |
#include "CRDFRedlandExternalTriplesDSNConnectingParser.h" |
| 23 |
|
| 24 |
|
| 25 |
namespace Konclude { |
| 26 |
|
| 27 |
namespace Parser { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
CRDFRedlandExternalTriplesDSNConnectingParser::CRDFRedlandExternalTriplesDSNConnectingParser(COntologyBuilder* ontologyBuilder, CConfiguration* configuration) : CLogIdentifier("::Konclude::Parser::RDFRedlandRemoteDataLinkingParser", this) { |
| 32 |
mOntologyBuilder = ontologyBuilder; |
| 33 |
mConfiguration = configuration; |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CRDFRedlandExternalTriplesDSNConnectingParser::~CRDFRedlandExternalTriplesDSNConnectingParser() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
bool CRDFRedlandExternalTriplesDSNConnectingParser::connectExternalTriples(const QString& triplesDBName, const QString& dsnConfig) { |
| 44 |
|
| 45 |
bool localTriplesDataFlag = false; |
| 46 |
CRedlandStoredTriplesData* prevTripleData = (CRedlandStoredTriplesData*)mOntologyBuilder->getLatestTriplesData(false, &localTriplesDataFlag); |
| 47 |
CRedlandStoredTriplesData* tripleData = nullptr; |
| 48 |
|
| 49 |
|
| 50 |
if (!tripleData) { |
| 51 |
tripleData = new CRedlandStoredTriplesData(); |
| 52 |
tripleData->initTriplesData(CTRIPLES_DATA_UPDATE_TYPE::TRIPLES_DATA_NEW, prevTripleData); |
| 53 |
} |
| 54 |
|
| 55 |
librdf_world* world = tripleData->getRedlandWorld(); |
| 56 |
if (!world) { |
| 57 |
world = librdf_new_world(); |
| 58 |
librdf_world_open(world); |
| 59 |
tripleData->setRedlandWorldData(world); |
| 60 |
} |
| 61 |
|
| 62 |
QByteArray triplesDBNameArray = triplesDBName.toUtf8(); |
| 63 |
QByteArray dsnConfigArray = dsnConfig.toUtf8(); |
| 64 |
|
| 65 |
librdf_storage* indexedStorage = tripleData->getRedlandIndexedStorage(); |
| 66 |
if (!indexedStorage && world) { |
| 67 |
//indexedStorage = librdf_new_storage(world, "virtuoso", "http://LUBM-test", "dsn='VirtuosoTest',user='dba',password='dba'"); |
| 68 |
indexedStorage = librdf_new_storage(world, "virtuoso", triplesDBNameArray.constData(), dsnConfigArray.constData()); |
| 69 |
tripleData->setRedlandIndexedStorageData(indexedStorage); |
| 70 |
} |
| 71 |
|
| 72 |
librdf_model* indexedModel = tripleData->getRedlandIndexedModel(); |
| 73 |
if (!indexedModel && indexedStorage) { |
| 74 |
indexedModel = librdf_new_model(world, indexedStorage, NULL); |
| 75 |
tripleData->setRedlandIndexedModelData(indexedModel); |
| 76 |
} |
| 77 |
|
| 78 |
//QString filename = QString("./Tests/lubm-univ-bench-data-1.ttl"); |
| 79 |
//QString filenameUri = QString("file://./Tests/lubm-univ-bench-data-1.ttl"); |
| 80 |
//QByteArray filenameUriByteArray(filenameUri.toUtf8()); |
| 81 |
//const char* filenameBaseUri = filenameUriByteArray.constData(); |
| 82 |
//librdf_uri *baseUri = librdf_new_uri(tripleData->getRedlandWorld(), (const unsigned char*)filenameBaseUri); |
| 83 |
|
| 84 |
|
| 85 |
//QString redlandParsingFormat = QString("turtle"); |
| 86 |
//QByteArray mRedlandParsingFormatByteArray = redlandParsingFormat.toUtf8(); |
| 87 |
//const char* parser_name = mRedlandParsingFormatByteArray.constData(); |
| 88 |
//librdf_parser* parser = librdf_new_parser(tripleData->getRedlandWorld(), parser_name, NULL, NULL); |
| 89 |
//if (!parser) { |
| 90 |
// mParsingError = true; |
| 91 |
//} |
| 92 |
|
| 93 |
//QByteArray filenameByteArray(filename.toUtf8()); |
| 94 |
//FILE* file = fopen(filenameByteArray.constData(), "r"); |
| 95 |
//// parser closes file |
| 96 |
//if (parser && librdf_parser_parse_file_handle_into_model(parser, file, 1, baseUri, tripleData->getRedlandIndexedModel())) { |
| 97 |
// mParsingError = true; |
| 98 |
//} |
| 99 |
//if (parser) { |
| 100 |
// librdf_free_parser(parser); |
| 101 |
//} |
| 102 |
|
| 103 |
|
| 104 |
/*else { |
| 105 |
model = librdf_new_model_from_model(prevModel); |
| 106 |
tripleData->setRedlandModelData(model); |
| 107 |
}*/ |
| 108 |
|
| 109 |
|
| 110 |
if (!indexedModel) { |
| 111 |
mParsingError = true; |
| 112 |
delete tripleData; |
| 113 |
tripleData = nullptr; |
| 114 |
} |
| 115 |
|
| 116 |
if (mParsingError) { |
| 117 |
delete tripleData; |
| 118 |
tripleData = nullptr; |
| 119 |
} else { |
| 120 |
mOntologyBuilder->addTriplesData(tripleData); |
| 121 |
} |
| 122 |
|
| 123 |
return !mParsingError; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
QString CRDFRedlandExternalTriplesDSNConnectingParser::getErrorString() { |
| 133 |
return mErrorString; |
| 134 |
} |
| 135 |
|
| 136 |
bool CRDFRedlandExternalTriplesDSNConnectingParser::hasError() { |
| 137 |
return mParsingError; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
}; // end namespace Parser |
| 143 |
|
| 144 |
}; // end namespace Konclude |
| 145 |
|
| 146 |
#endif // !KONCLUDE_REDLAND_INTEGRATION |