Results
13.05.2024
rdf_sync 1.x-dev ::
src/RdfSyncEncoderCompilerPass.php
use Drupal\rdf_sync\Encoder\RdfSyncEncoder; use Drupal\rdf_sync\Model\RdfSyncFormat; use EasyRdf\Format; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; /** * Creates an RDF encoder service for each format from rdf_sync container param.
13.05.2024
rdf_sync 1.x-dev ::
src/RdfSyncConnectorPluginInterface.php
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use EasyRdf\GraphStore;
use EasyRdf\Sparql\Result;
/**
* Interface of RDF Sync connector plugins.
*/
interface RdfSyncConnectorPluginInterface extends PluginInspectionInterface, ConfigurableInterface {
* The SPARQL query. * * @return \EasyRdf\Sparql\Result * The result object. */ public function query(string $query): Result; /** * Runs a SPARQL update and returns the results.
* The SPARQL query. * * @return \EasyRdf\Sparql\Result * The result object. */ public function update(string $query): Result; /** * Clear the content of an entire graph.
* Creates a graph store. * * @return \EasyRdf\GraphStore * Graph store. */ public function createGraphStore(): GraphStore; }
13.05.2024
rdf_sync 1.x-dev ::
tests/src/Traits/RdfSyncTestTrait.php
use Drupal\rdf_sync\Model\VirtuosoEndpoint;
use EasyRdf\Graph;
use PHPUnit\Framework\Assert;
/**
* Tests reusable code.
*/
trait RdfSyncTestTrait { 13.05.2024
rdf_sync 1.x-dev ::
tests/modules/rdf_sync_test/src/Plugin/rdf_sync/Connector/ARC2.php
use Drupal\rdf_sync\Attribute\RdfSyncConnector; use Drupal\rdf_sync\RdfSyncConnectorPluginPluginBase; use EasyRdf\GraphStore; use EasyRdf\Sparql\Result; /** * In memory quad store connector. * * @phpcs:disable Drupal.NamingConventions.ValidClassName.NoUpperAcronyms */
* The query.
*
* @return \EasyRdf\Sparql\Result
* The EasyRdf result.
*/
protected function doQuery(string $query): Result {
$result = $this->getStore()->query($query);
if (!is_array($result)) {
throw new \RuntimeException('Query failed: ' . $query);
}
*
* @return array[]
* Array to be passed to EasyRdf Result object.
*/
protected function processSelectResults(array $result): array {
$bindings = [];
foreach ($result['result']['rows'] ?? [] as $row) {
$binding = [];
foreach ($result['result']['variables'] as $variable) { 05.10.2020
semantic_connector 8.x-1.1 ::
src/Api/SemanticConnectorSparqlApi.php
* API Class for the PoolParty Thesaurus.
*/
class SemanticConnectorSparqlApi extends \EasyRdf_Sparql_Client {
/** Create a new SPARQL endpoint client
*
* If the query and update endpoints are the same, then you
* only need to give a single URI.
* 05.10.2020
semantic_connector 8.x-1.1 ::
src/Entity/SemanticConnectorSparqlEndpointConnection.php
namespace Drupal\semantic_connector\Entity;
use Drupal\semantic_connector\Api\SemanticConnectorSparqlApi;
use EasyRdf\Http;
/**
* @ConfigEntityType(
* id ="sparql_endpoint_connection",
* label = @Translation("SPARQL endpoint connection"),
* handlers = {
$http_client = Http::getDefaultHttpClient();
// Use basic authentication, Digest is not supported by the way EasyRDF
// currently works.
$http_client->setHeaders('Authorization', 'Basic ' . base64_encode($this->credentials['username'] . ':' . $this->credentials['password']));
Http::setDefaultHttpClient($http_client);
}
return new SemanticConnectorSparqlApi($this->url); 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Encoder/SparqlEncoder.php
use Drupal\sparql_entity_storage\SparqlEncoderInterface;
use EasyRdf\Format;
/**
* Adds RDF encoder support for the Serialization API.
*/
class SparqlEncoder implements SparqlEncoderInterface {
* Memory cache for supported formats.
*
* @var \EasyRdf\Serialiser[]
*/
protected static array $supportedFormats;
/**
* {@inheritdoc}
*/ 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Driver/Database/sparql/Connection.php
use Drupal\Core\Database\StatementInterface;
use Drupal\sparql_entity_storage\Exception\SparqlQueryException;
use EasyRdf\Graph;
use EasyRdf\Http\Exception as EasyRdfException;
use EasyRdf\Sparql\Client;
use EasyRdf\Sparql\Result;
/**
* @addtogroup database
* @{
*/
* The client instance object that performs requests to the SPARQL endpoint. */ protected Client $easyRdfClient; /** * The connection information for this connection object. * * @var array */
* Constructs a new connection instance.
*
* @param \EasyRdf\Sparql\Client $easy_rdf_client
* Object of \EasyRdf\Sparql\Client which is a database connection.
* @param array $connection_options
* An associative array of connection options. See the "Database settings"
* section from 'sites/default/settings.php' a for a detailed description of
* the structure of this array.
*/
public function __construct(Client $easy_rdf_client, array $connection_options) {
*/
public function __construct(Client $easy_rdf_client, array $connection_options) {
$this->easyRdfClient = $easy_rdf_client;
$this->connectionOptions = $connection_options;
}
/**
* {@inheritdoc}
*/
*/
public function getSparqlClient(): Client {
return $this->easyRdfClient;
}
/**
* {@inheritdoc}
*/
public function query(string $query, array $args = [], array $options = []): Result {
* An associative array of options to control how the query is run. * * @return \EasyRdf\Sparql\Result|\EasyRdf\Graph * The query result. * * @throws \InvalidArgumentException * If $args value is passed but arguments replacement is not yet * supported. To be removed in #55. * @throws \Drupal\sparql_entity_storage\Exception\SparqlQueryException
// @todo Implement argument replacement in #1.
// @see https://github.com/ec-europa/sparql_entity_storage/issues/1
$results = $this->easyRdfClient->query($query);
}
catch (EasyRdfException $exception) {
// Re-throw the exception, but with the query as message.
throw new SparqlQueryException("Execution of query failed with message '{$exception->getBody()}'. Query: " . $query, $exception->getCode(), $exception);
}
if ($this->logger) {
$query_end = microtime(TRUE);
// @todo Implement argument replacement in #1.
// @see https://github.com/ec-europa/sparql_entity_storage/issues/1
$result = $this->easyRdfClient->update($query);
}
catch (EasyRdfException $exception) {
// Re-throw the exception, but with the query as message.
throw new SparqlQueryException("Execution of query failed with message '{$exception->getBody()}'. Query: " . $query, $exception->getCode(), $exception);
}
if ($this->logger) {
$query_end = microtime(TRUE);
*/
public function getQueryUri(): string {
return $this->easyRdfClient->getQueryUri();
}
/**
* {@inheritdoc}
*/
public function setLogger(Log $logger): void { 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Driver/Database/sparql/ConnectionInterface.php
use Drupal\Core\Database\Log;
use EasyRdf\Graph;
use EasyRdf\Sparql\Client;
use EasyRdf\Sparql\Result;
/**
* An interface for the Connection class.
*/
interface ConnectionInterface {
* Returns the SPARQL client object. * * @return \EasyRdf\Sparql\Client * The SPARQL client instantiated with the default connection info. */ public function getSparqlClient(): Client; /** * Execute a select/insert/update query, returning a query result.
* An associative array of options to control how the query is run. * * @return \EasyRdf\Sparql\Result * The query result. * * @throws \InvalidArgumentException * If $args value is passed but arguments replacement is not yet * supported. To be removed in #55. *
* An associative array of options to control how the query is run. * * @return \EasyRdf\Graph * The set of triples. * * @throws \InvalidArgumentException * If $args value is passed but arguments replacement is not yet * supported. To be removed in #55. *
* An associative array of options to control how the query is run. * * @return \EasyRdf\Sparql\Result * The result object. * * @throws \InvalidArgumentException * If $args value is passed but arguments replacement is not yet * supported. To be removed in #55. *
* The connection options as defined in settings.php. * * @return \EasyRdf\Sparql\Client * The EasyRdf client instance. */ public static function open(array &$connection_options = []): Client; /** * Tells this connection object what its target value is. *
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/EventSubscriber/SparqlContentTypesSubscriber.php
*/
public function onKernelRequest(RequestEvent $event) {
/** @var \EasyRdf\Format $format */
foreach (SparqlEncoder::getSupportedFormats() as $format) {
$mime = array_keys($format->getMimeTypes());
$event->getRequest()->setFormat($format->getName(), $mime);
}
} 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Entity/Query/Sparql/SparqlArg.php
use Drupal\Component\Utility\UrlHelper; use Drupal\sparql_entity_storage\SparqlEntityStorageFieldHandlerInterface; use EasyRdf\Serialiser\Ntriples; use rdfHelpers\NtriplesUtil; /** * Wrap Sparql arguments. This provides a central point for escaping. * * @todo Return SparqlArgument objects in order to distinguish between
// The serialization should use the escapeIRI but for not, we adhere to the
// spec and support a more limited amount of characters.
// @see \EasyRdf\Serialiser\Ntriples::escapeIri()
// @see https://github.com/sweetrdf/easyrdf/issues/41
$serialized = trim(self::serialize($uri, SparqlEntityStorageFieldHandlerInterface::RESOURCE), '<>');
$escaped = NtriplesUtil::escapeIri($uri);
$unsupported_characters = [];
// Check for characters that were escaped by the serializer e.g. \u00E9.
preg_match_all('/\\\\u[0-9a-fA-F]{4}/', $serialized, $matches); 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Entity/Query/Sparql/Query.php
use Drupal\sparql_entity_storage\SparqlEntityStorageGraphHandlerInterface;
use Drupal\sparql_entity_storage\SparqlEntityStorageInterface;
use EasyRdf\Sparql\Result;
/**
* The base entity query class for SPARQL stored entities.
*/
class Query extends QueryBase implements SparqlQueryInterface {
// SELECT query.
foreach ($this->result as $result) {
// If the query does not return any results, EasyRdf\Sparql\Result still
// contains an empty result object. If this is the case, skip it.
if (!empty((array) $result)) {
$uri = (string) $result->entity;
$uris[$uri] = $uri;
}
} 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/Entity/Query/Sparql/SparqlCondition.php
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\sparql_entity_storage\SparqlEntityStorageFieldHandlerInterface;
use EasyRdf\Serialiser\Ntriples;
/**
* Defines the condition class for the entity query.
*/
class SparqlCondition extends ConditionFundamentals implements SparqlConditionInterface {
* The altered $value.
*
* @throws \EasyRdf\Exception
* Thrown when the bundle does not have a mapping.
*/
protected function escapeValue(string $field, $value, ?string $column = NULL, ?string $lang = NULL) {
if (empty($value)) {
return $value;
} 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlEntityStorageFieldHandler.php
use Drupal\sparql_entity_storage\Exception\NonExistingFieldPropertyException; use Drupal\sparql_entity_storage\Exception\UnmappedFieldException; use EasyRdf\Literal; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Contains helper methods that help with the URI mappings of Drupal elements. * * Mainly, two field maps are created and statically cached:
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlSerializerInterface.php
* An array of options to pass to the serializer. Please, see each * serializer for the specific options. Serializers are under the namespace * \EasyRdf\Serialiser. * * @return string * The serialised entity as a string. */ public function serializeEntity(ContentEntityInterface $entity, string $format = 'turtle', array $options = []): string;
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlEntityStorage.php
use Drupal\sparql_entity_storage\Exception\DuplicatedIdException;
use Drupal\sparql_entity_storage\Exception\UnsupportedCharactersException;
use EasyRdf\Graph;
use EasyRdf\Literal;
use EasyRdf\Sparql\Result;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines an entity storage backend that uses a Sparql endpoint.
*/
class SparqlEntityStorage extends ContentEntityStorageBase implements SparqlEntityStorageInterface {
* The URI of the graph.
*
* @return \EasyRdf\Graph
* The EasyRdf graph object.
*/
protected static function getGraph($graph_uri): Graph {
return new Graph($graph_uri);
}
/**
* from. * * @param \EasyRdf\Sparql\Result|\EasyRdf\Graph $results * A set of query results indexed per graph and entity id. * @param string[] $graph_ids * Graph IDs. * * @return array|null * The entity values indexed by the field mapping ID or NULL in there are no
* @endcode
*
* @param \EasyRdf\Sparql\Result $results
* A set of query results indexed per graph and entity id.
*
* @return array
* The entity values indexed by the field mapping id.
*/
protected function deserializeGraphResults(Result $results): array {
* this is saved to SPARQL backend.
*
* @param \EasyRdf\Graph $graph
* The graph to be altered.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being saved.
*/
protected function alterGraph(Graph &$graph, EntityInterface $entity): void {}
* Insert a graph of triples. * * @param \EasyRdf\Graph $graph * The graph to insert. * @param string $graph_uri * Graph to save to. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity being saved. *
* The entity being saved. * * @return \EasyRdf\Sparql\Result * Response. * * @throws \Drupal\sparql_entity_storage\Exception\SparqlQueryException * If the SPARQL query fails. * @throws \Exception * The query fails with no specific reason.
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlSerializer.php
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\sparql_entity_storage\Driver\Database\sparql\ConnectionInterface;
use EasyRdf\Graph;
/**
* Service to serialise RDF entities into various formats.
*/
class SparqlSerializer implements SparqlSerializerInterface { 17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlEncoderInterface.php
* Builds a list of supported formats. * * @return \EasyRdf\Serialiser[] * List of supported formats. */ public static function getSupportedFormats(): array; }
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlEncoderCompilerPass.php
namespace Drupal\sparql_entity_storage; use EasyRdf\Format; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Collects all RDF encoders and stores them into a service container parameter. */
17.10.2020
sparql_entity_storage 8.x-1.0-alpha8 ::
src/SparqlGraphStoreTrait.php
use Drupal\Core\Database\Database;
use EasyRdf\GraphStore;
/**
* Provides helper methods for graph stores on the current SPARQL connection.
*/
trait SparqlGraphStoreTrait {
* Creates a new Graph Store object using the SPARQL connection.
*
* @return \EasyRdf\GraphStore
* The new graph store object.
*/
public static function createGraphStore(): GraphStore {
$sparql_connection = Database::getConnection('default', 'sparql_default');
$connection_options = $sparql_connection->getConnectionOptions();
$connect_string = "http://{$connection_options['host']}:{$connection_options['port']}/sparql-graph-crud"; 