From 028fa9c9e46db87b8f847e63ec17e7c1a8909da8 Mon Sep 17 00:00:00 2001 From: Cyrille Berger <cyrille.berger@liu.se> Date: Tue, 5 Sep 2023 18:51:03 +0200 Subject: [PATCH] add content type --- extensions/kDBRobotics/Agents.cpp | 4 ++-- extensions/kDBRobotics/Agents.h | 2 +- extensions/kDBRobotics/Stream.cpp | 5 +++++ extensions/kDBRobotics/Stream.h | 1 + extensions/kDBRobotics/Stream_p.h | 2 +- .../kDBRobotics/data/agents_queries.ttl | 22 +++++++++++++------ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/extensions/kDBRobotics/Agents.cpp b/extensions/kDBRobotics/Agents.cpp index 98c8f438..bd017583 100644 --- a/extensions/kDBRobotics/Agents.cpp +++ b/extensions/kDBRobotics/Agents.cpp @@ -584,7 +584,7 @@ knowCore::ReturnValue<Agent> Agents::createAgent(const knowCore::Uri& _typeUri, } } -knowCore::ReturnValue<Stream> Agents::createStream(const knowCore::Uri& _typeUri, const QString& _identifier, const knowCore::Uri& _streamUri) +knowCore::ReturnValue<Stream> Agents::createStream(const knowCore::Uri& _contenttypeUri, const QString& _identifier, const knowCore::Uri& _datatypeUri, const knowCore::Uri& _streamUri) { if(isReadOnly()) { @@ -595,7 +595,7 @@ knowCore::ReturnValue<Stream> Agents::createStream(const knowCore::Uri& _typeUri { return kCrvLogError("Failed to create stream {}, it is already added to a graph.", _streamUri); } - Queries::Agents::StreamInsert::Results r = Queries::Agents::StreamInsert::execute(d->connection, d->definition->uri, _streamUri, _identifier, _typeUri); + Queries::Agents::StreamInsert::Results r = Queries::Agents::StreamInsert::execute(d->connection, d->definition->uri, _streamUri, _identifier, _contenttypeUri, _datatypeUri); if(r.success) { return stream(_streamUri); diff --git a/extensions/kDBRobotics/Agents.h b/extensions/kDBRobotics/Agents.h index 1ef879cb..42136624 100644 --- a/extensions/kDBRobotics/Agents.h +++ b/extensions/kDBRobotics/Agents.h @@ -112,7 +112,7 @@ namespace kDBRobotics /** * Create a new \ref Stream of uri type \p _typeUri with name \p _name and add it to this agent graph. */ - knowCore::ReturnValue<Stream> createStream(const knowCore::Uri& _typeUri, const QString& _identifier, const knowCore::Uri& _streamUri = knowCore::Uri::createUnique({"stream"})); + knowCore::ReturnValue<Stream> createStream(const knowCore::Uri& _contentTypeUri, const QString& _identifier, const knowCore::Uri& _dataTypeUri, const knowCore::Uri& _streamUri = knowCore::Uri::createUnique({"stream"})); private: struct Private; QExplicitlySharedDataPointer<Private> d; diff --git a/extensions/kDBRobotics/Stream.cpp b/extensions/kDBRobotics/Stream.cpp index 5ee19784..d7b3fd5a 100644 --- a/extensions/kDBRobotics/Stream.cpp +++ b/extensions/kDBRobotics/Stream.cpp @@ -34,6 +34,11 @@ knowCore::Uri Stream::datatype() const return d->definition->datatype; } +knowCore::Uri Stream::contentType() const +{ + return d->definition->contentType; +} + knowCore::ReturnValue<bool> Stream::hasProperty(const knowCore::Uri& _property) const { return d->object.hasProperty(_property); diff --git a/extensions/kDBRobotics/Stream.h b/extensions/kDBRobotics/Stream.h index 38c3269d..e33460af 100644 --- a/extensions/kDBRobotics/Stream.h +++ b/extensions/kDBRobotics/Stream.h @@ -17,6 +17,7 @@ namespace kDBRobotics knowCore::Uri uri() const; QString identifier() const; knowCore::Uri datatype() const; + knowCore::Uri contentType() const; /** * @return if the given property is set */ diff --git a/extensions/kDBRobotics/Stream_p.h b/extensions/kDBRobotics/Stream_p.h index cdc0e9b7..89c63d55 100644 --- a/extensions/kDBRobotics/Stream_p.h +++ b/extensions/kDBRobotics/Stream_p.h @@ -15,7 +15,7 @@ namespace kDBRobotics struct Definition { QMutex mutex; - knowCore::Uri uri, datatype; + knowCore::Uri uri, datatype, contentType; QString identifier; knowCore::Uri triplestores; QList<knowCore::Uri> resources_with_stream; diff --git a/extensions/kDBRobotics/data/agents_queries.ttl b/extensions/kDBRobotics/data/agents_queries.ttl index a04c8910..37db64dc 100644 --- a/extensions/kDBRobotics/data/agents_queries.ttl +++ b/extensions/kDBRobotics/data/agents_queries.ttl @@ -111,6 +111,7 @@ INSERT DATA { GRAPH %graph { %stream_uri a askcore_stream:stream ; askcore_stream:identifier %identifier ; + askcore_stream:contenttype %contenttype ; askcore_stream:datatype %datatype . } } @@ -118,7 +119,8 @@ INSERT DATA { askcore_queries:binding [ foaf:name "graph" ; xsi:type xsd:anyURI ; dc:description "URI for the graph where to insert this agent" ] ; askcore_queries:binding [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; askcore_queries:binding [ foaf:name "identifier" ; xsi:type xsd:string ; dc:description "Identifier of the stream (e.g. could be a topic name)" ] ; - askcore_queries:binding [ foaf:name "datatype" ; xsi:type xsd:anyURI ; dc:description "Uri of the datatype" ] ; + askcore_queries:binding [ foaf:name "contenttype" ; xsi:type xsd:anyURI ; dc:description "Uri of the content type" ] ; + askcore_queries:binding [ foaf:name "datatype" ; xsi:type xsd:anyURI ; dc:description "Uri of the data type" ] ; askcore_queries:graph "%graph" . @@ -137,13 +139,15 @@ ASK { GRAPH %graph { %stream_uri a askcore_stream:stream } }""" ; foaf:name "stream_select" ; askcore_queries:query """PREFIX askcore_stream: <http://askco.re/stream#> -SELECT ?datatype ?identifier FROM %graph WHERE { +SELECT ?datatype ?identifier ?contenttype FROM %graph WHERE { %stream_uri a askcore_stream:stream ; askcore_stream:datatype ?datatype ; + askcore_stream:contenttype ?contenttype ; askcore_stream:identifier ?identifier . }""" ; askcore_queries:binding [ foaf:name "graph" ; xsi:type xsd:anyURI ; dc:description "URI for the graph where to get all the agents." ] ; askcore_queries:binding [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; + askcore_queries:result [ foaf:name "contenttype" ; xsi:type xsd:anyURI ; dc:description "contenttype of stream" ] ; askcore_queries:result [ foaf:name "datatype" ; xsi:type xsd:anyURI ; dc:description "Datatype of stream" ] ; askcore_queries:result [ foaf:name "identifier" ; xsi:type xsd:string ; dc:description "Identifier of agent" ] ; askcore_queries:graph "%graph" . @@ -152,13 +156,15 @@ SELECT ?datatype ?identifier FROM %graph WHERE { foaf:name "stream_select_all" ; askcore_queries:query """PREFIX askcore_stream: <http://askco.re/stream#> -SELECT ?stream_uri ?datatype ?identifier FROM %graph WHERE { +SELECT ?stream_uri ?datatype ?identifier ?contenttype FROM %graph WHERE { ?stream_uri a askcore_stream:stream ; askcore_stream:datatype ?datatype ; + askcore_stream:contenttype ?contenttype ; askcore_stream:identifier ?identifier . }""" ; askcore_queries:binding [ foaf:name "graph" ; xsi:type xsd:anyURI ; dc:description "URI for the graph where to get all the agents." ] ; - askcore_queries:result [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; + askcore_queries:result [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; + askcore_queries:result [ foaf:name "contenttype" ; xsi:type xsd:anyURI ; dc:description "contenttype of stream" ] ; askcore_queries:result [ foaf:name "datatype" ; xsi:type xsd:anyURI ; dc:description "Datatype of stream" ] ; askcore_queries:result [ foaf:name "identifier" ; xsi:type xsd:string ; dc:description "Identifier of agent" ] ; askcore_queries:graph "%graph" . @@ -167,15 +173,17 @@ SELECT ?stream_uri ?datatype ?identifier FROM %graph WHERE { foaf:name "stream_select_all_for" ; askcore_queries:query """PREFIX askcore_stream: <http://askco.re/stream#> -SELECT ?stream_uri ?datatype ?identifier FROM %graph WHERE { +SELECT ?stream_uri ?datatype ?identifier ?contenttype FROM %graph WHERE { %resource_uri askcore_stream:has_stream ?stream_uri . ?stream_uri a askcore_stream:stream ; askcore_stream:datatype ?datatype ; + askcore_stream:contenttype ?contenttype ; askcore_stream:identifier ?identifier . }""" ; askcore_queries:binding [ foaf:name "graph" ; xsi:type xsd:anyURI ; dc:description "URI for the graph where to get all the agents." ] ; - askcore_queries:binding [ foaf:name "resource_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the resource" ] ; - askcore_queries:result [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; + askcore_queries:binding [ foaf:name "resource_uri"; xsi:type xsd:anyURI ; dc:description "Uri of the resource" ] ; + askcore_queries:result [ foaf:name "stream_uri" ; xsi:type xsd:anyURI ; dc:description "Uri of the stream" ] ; + askcore_queries:result [ foaf:name "contenttype" ; xsi:type xsd:anyURI ; dc:description "contenttype of stream" ] ; askcore_queries:result [ foaf:name "datatype" ; xsi:type xsd:anyURI ; dc:description "Datatype of stream" ] ; askcore_queries:result [ foaf:name "identifier" ; xsi:type xsd:string ; dc:description "Identifier of agent" ] ; askcore_queries:graph "%graph" . -- GitLab