-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt RDFox adapter to implement cursor for query:
Summary: Added RequestBuilder to manage HTTP interactions with RDFox, improving the consistency of request handling across different features. Simplified request setup for various operations, such as creating connections, cursors, and querying. Implemented functionality to support cursor-based queries for efficient data pagination. Added unit tests to validate the creation of connections with RDFox. Enhanced the mock setup for the RDFox Adapter to avoid code duplication in tests. Added comprehensive integration tests for RDFox Adapter functionalities, ensuring compatibility with multiple formats and scenarios. Verified the correctness of SPARQL query results across different RDF formats (e.g., Turtle, JSON-LD, RDF/XML). Extended the query functionality to support various content types such as Turtle, CSV, JSON-LD, RDF/XML, and N-Triples. Created parameterised tests to validate data consistency across supported input and output formats. Update related documentation. Tests to run new features: rdfox_adapter_unit_test rdfox_adapter_integration_test Signed-off-by: q632394 <[email protected]>
- Loading branch information
q632394
committed
Jan 29, 2025
1 parent
98e2e73
commit f378d3e
Showing
17 changed files
with
1,538 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 90 additions & 11 deletions
101
cdsp/knowledge-layer/symbolic-reasoner/rdfox/src/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,106 @@ | ||
# RDFoxAdapter | ||
|
||
`RDFoxAdapter` is responsible for communicating with the RDFox server over HTTP. It checks if the datastore is active, loads RDF data, and queries the RDF data using [SPARQL](https://www.w3.org/TR/sparql11-query/). | ||
`RDFoxAdapter` is responsible for communicating with the RDFox server using RESTful APIs. This adapter allows users to perform various operations such as creating connections, loading data, querying data (using [SPARQL](https://www.w3.org/TR/sparql11-query/)), and managing cursors efficiently. | ||
|
||
> [!NOTE] Data store | ||
> When the RDFoxAdapter initializes creates (if is does not exists) a datastore called `vehicle_ds` in the RDFox server. | ||
> | ||
> ## Features | ||
- **Initialize a Datastore:** Checks if a specified datastore exists on the RDFox server. If not, it creates the datastore. | ||
- **Load Data:** Loads Turtle data into a specified datastore. | ||
- **Query Data:** Executes SPARQL queries against the RDFox datastore and retrieves results. | ||
- **Delete Datastore:** Removes a specified datastore from the RDFox server. | ||
## Features | ||
|
||
**Example Usage** | ||
|
||
- **Data Store Management**: | ||
- Initialize and ensure the existence of the datastore. | ||
- Load data into the datastore in various formats (e.g., Turtle, JSON-LD, RDF/XML). | ||
- Delete the datastore. | ||
|
||
- **Data Querying**: | ||
- Query data using SPARQL queries. | ||
- Support for multiple response content types such as `table/csv`, `application/sparql-results+json`, etc. | ||
|
||
- **Connection Management**: | ||
- Create and manage connections to the RDFox datastore. | ||
- Validate existing connections. | ||
|
||
- **Cursor Management**: | ||
- Create cursors for large query results. | ||
- Advance or open cursors for efficient pagination. | ||
- Delete cursors after usage. | ||
|
||
### Example Usage | ||
|
||
**Initializing the Adapter** | ||
|
||
```cpp | ||
RDFoxAdapter adapter("<rdf_host>", "<port>", "<auth>", "<datastore>"); | ||
if (adapter.checkDataStore()) { | ||
adapter.loadData("<your_ttl_data>"); | ||
std::string result = adapter.queryData("SELECT ?s ?p ?o WHERE { ?s ?p ?o }"); | ||
#include "rdfox_adapter.h" | ||
|
||
int main() { | ||
RDFoxAdapter adapter("<rdf_host>", "<port>", "<auth>", "<datastore>"); | ||
|
||
try { | ||
adapter.initialize(); | ||
std::cout << "Datastore initialized successfully!" << std::endl; | ||
} catch (const std::runtime_error& e) { | ||
std::cerr << "Error initializing datastore: " << e.what() << std::endl; | ||
} | ||
|
||
return 0; | ||
} | ||
``` | ||
|
||
**Loading Data** | ||
|
||
```cpp | ||
std::string turtle_data = R"( | ||
@prefix ex: <http://example.com/> . | ||
ex:subject a ex:Object . | ||
)"; | ||
adapter.loadData(turtle_data, "text/turtle"); | ||
``` | ||
|
||
**Querying Data** | ||
|
||
```cpp | ||
std::string sparql_query = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"; | ||
std::string result = adapter.queryData(sparql_query, "application/sparql-results+json"); | ||
std::cout << "Query Result: " << result << std::endl; | ||
``` | ||
|
||
**Managing Cursors** | ||
```cpp | ||
std::pair<std::string, std::string> connection = adapter.createConnection(); | ||
std::string cursor_id = adapter.createCursor(connection.first, connection.second, sparql_query); | ||
|
||
std::string cursor_result; | ||
adapter.advanceCursor(connection.first, connection.second, cursor_id, | ||
"application/sparql-results+json", "open", 100, &cursor_result); | ||
|
||
std::cout << "Cursor Result: " << cursor_result << std::endl; | ||
|
||
adapter.deleteCursor(connection.first, cursor_id); | ||
``` | ||
|
||
> [!NOTE] Allowed Operations for Advancing the Cursor | ||
> The `RDFoxAdapter::advanceCursor` method allows two operations: | ||
> - **`open`:** Opens the cursor for the first time and retrieves data starting from the beginning. | ||
> - **`advance`:** Advances the cursor from its current position to the next set of results. | ||
## Supported Data Formats | ||
|
||
### For Loading Data | ||
|
||
- text/turtle | ||
- application/ld+json | ||
- application/n-triples | ||
- application/n-quads | ||
|
||
### For Query Responses | ||
|
||
- table/csv | ||
- text/plain | ||
- application/sparql-results+json | ||
- application/sparql-results+xml | ||
|
||
# Testing | ||
|
||
Unit and Integration [tests](../tests/) are provided to ensure functionality. Tests cover the main components (`RDFoxAdapter`) to verify RDF data transfer, and error handling. |
Oops, something went wrong.