Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
02801d4
ajouter formtConfig sur Turtle / triG /ntriples
abdessamad-abdoun Jun 17, 2025
f726517
Create turtles Serializer
abdessamad-abdoun Jun 18, 2025
796e45b
Create turtles Serializer
abdessamad-abdoun Jun 18, 2025
84919a2
Create turtles Serializer et correction sonar
abdessamad-abdoun Jun 19, 2025
ef539be
Create Trig Serializer
abdessamad-abdoun Jun 19, 2025
516aa3b
ajouté les tests unitaires pour Turtle et réorganisé le fichier de co…
abdessamad-abdoun Jun 19, 2025
0287b2b
ajouté les tests unitaires pour Turtle
abdessamad-abdoun Jun 19, 2025
09509b9
ajouté les tests unitaires pour trig
abdessamad-abdoun Jun 19, 2025
5ba963c
ajouter RDF.LANGSTRING.getIRI().stringValue()
abdessamad-abdoun Jun 19, 2025
57fe4d8
Serializer to be separated into a factory class for serializers.
abdessamad-abdoun Jun 20, 2025
6267288
ajouter le BufferedWriter directement dans votre méthode write() et i…
abdessamad-abdoun Jun 20, 2025
675a0ac
Serializer to be separated into a factory class for serializers.
abdessamad-abdoun Jun 24, 2025
beff6d8
ajouter xml serializer
abdessamad-abdoun Jun 24, 2025
58dc11d
ajouter xml DefaultSerializerFactoryTest
abdessamad-abdoun Jun 25, 2025
0d567ba
ajouter test unitaire xml serializer
abdessamad-abdoun Jun 26, 2025
bff224c
ajouter plus de test unitaire xml serializer
abdessamad-abdoun Jun 27, 2025
0c39531
Ajout du vocabulaire OWL et refactorisation des constantes de sériali…
abdessamad-abdoun Jun 27, 2025
97a494f
refactor(serialization): Extract common base for line-based serializers
remiceres Jul 1, 2025
7f9c408
Correction des noms d'interfaces (suppression du préfixe "I") et ajou…
abdessamad-abdoun Jul 1, 2025
ba063ca
ajouter une classe commun trig et turtles
abdessamad-abdoun Jul 1, 2025
ebdb7d1
la configuration de la sérialisation
abdessamad-abdoun Jul 4, 2025
c43fa3a
java Doc anglais
abdessamad-abdoun Jul 4, 2025
1967d7e
A factory class to create mocked components
abdessamad-abdoun Jul 4, 2025
ff73b85
ajouter n quads config test
abdessamad-abdoun Jul 4, 2025
47c15ba
ajouter TU de Ntriples config
abdessamad-abdoun Jul 7, 2025
0e11974
ajouter TU de turtle et trig config
abdessamad-abdoun Jul 7, 2025
3783b50
ajouter TU de XML config
abdessamad-abdoun Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/main/java/fr/inria/corese/core/next/api/FormatSerializer.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/fr/inria/corese/core/next/api/RdfSerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.inria.corese.core.next.api;

import fr.inria.corese.core.next.impl.exception.SerializationException;

import java.io.Writer;

/**
* Factory interface for creating {@link RdfSerializer} instances.
* This interface defines a contract for classes that are responsible
* for providing appropriate RDF serializers based on the desired
* {@link fr.inria.corese.core.next.impl.common.serialization.RdfFormat}, a {@link Model} to be serialized, and
* {@link SerializationConfig}.
* Implementations of this factory can manage the instantiation
* and configuration of various RDF serializers, promoting
* loose coupling and extensibility in the serialization process.
*/
public interface RdfSerializer {

/**
* A serializer that converts a {@link Model} instance
* into a specific output format and writes it to a character stream.
* Implementations may follow standard RDF serialization formats
* (e.g., Turtle, N-Triples, JSON-LD, TriG , XML ), or define custom formats.
*
* @param writer the destination {@link Writer} for the serialized
* output
* @throws SerializationException if an error occurs during the serialization
* process
*/
void write(Writer writer) throws SerializationException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.inria.corese.core.next.api;


/**
* Marker interface for configuration objects used in RDF serialization.
* This interface provides a common type for all serialization configuration
* implementations, promoting abstraction and flexibility in how serialization
* options are defined and provided.
* Implementations of this interface (e.g., SerializerConfig) will define the
* specific parameters and settings relevant to a particular serialization process.
*/
public interface SerializationConfig {

}
19 changes: 19 additions & 0 deletions src/main/java/fr/inria/corese/core/next/api/SerializerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.inria.corese.core.next.api;

import fr.inria.corese.core.next.impl.common.serialization.RdfFormat;

/**
* Factory interface for creating {@link RdfSerializer} instances.
* This interface defines a contract for classes that are responsible
* for providing appropriate RDF serializers based on the desired
* {@link RdfFormat}, a {@link Model} to be serialized, and
* {@link SerializationConfig}.
* Implementations of this factory can manage the instantiation
* and configuration of various RDF serializers, promoting
* loose coupling and extensibility in the serialization process.
*/
public interface SerializerFactory {


RdfSerializer createSerializer(RdfFormat format, Model model, SerializationConfig config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package fr.inria.corese.core.next.impl.common.serialization;

import fr.inria.corese.core.next.api.Model;
import fr.inria.corese.core.next.api.RdfSerializer;
import fr.inria.corese.core.next.api.SerializationConfig;
import fr.inria.corese.core.next.api.SerializerFactory;
import fr.inria.corese.core.next.impl.common.serialization.config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;

/**
* Default implementation of {@link SerializerFactory}.
* This factory is responsible for creating instances of {@link RdfSerializer}
* based on the requested {@link RdfFormat}. It uses a registry pattern
* to map each format to its corresponding serializer constructor,
* providing a flexible and extensible way to manage serializer instances.
*
* <p>It adapts the generic {@link SerializationConfig} provided to the specific
* configuration type expected by each serializer in the hierarchy, with a fallback
* to default configurations if an incompatible type is provided.</p>
*/
public class DefaultSerializerFactory implements SerializerFactory {

private static final Logger logger = LoggerFactory.getLogger(DefaultSerializerFactory.class);

private final Map<RdfFormat, BiFunction<Model, SerializationConfig, RdfSerializer>> registry;

/**
* Constructs a {@code DefaultSerializerFactory} and populates its registry
* with constructors for all known {@link RdfFormat} implementations.
* Each constructor attempts to cast the generic {@link SerializationConfig} to the
* specific configuration type required by the serializer. If the cast is not possible,
* it falls back to the format's default configuration.
*/
public DefaultSerializerFactory() {
Map<RdfFormat, BiFunction<Model, SerializationConfig, RdfSerializer>> tempRegistry = new HashMap<>();

tempRegistry.put(RdfFormat.TURTLE, (model, genericConfig) -> {
if (genericConfig instanceof TurtleConfig specificConfig) {
return new TurtleSerializer(model, specificConfig);
} else {
logger.warn("Provided config for TURTLE is not TurtleConfig (was {}). Using default TurtleConfig.",
genericConfig.getClass().getSimpleName());
return new TurtleSerializer(model, TurtleConfig.defaultConfig());
}
});

tempRegistry.put(RdfFormat.NTRIPLES, (model, genericConfig) -> {
if (genericConfig instanceof NTriplesConfig specificConfig) {
return new NTriplesSerializer(model, specificConfig);
} else {
logger.warn("Provided config for NTRIPLES is not NTriplesConfig (was {}). Using default NTriplesConfig.",
genericConfig.getClass().getSimpleName());
return new NTriplesSerializer(model, NTriplesConfig.defaultConfig());
}
});

tempRegistry.put(RdfFormat.NQUADS, (model, genericConfig) -> {
if (genericConfig instanceof NQuadsConfig specificConfig) {
return new NQuadsSerializer(model, specificConfig);
} else {
logger.warn("Provided config for NQUADS is not NQuadsConfig (was {}). Using default NQuadsConfig.",
genericConfig.getClass().getSimpleName());
return new NQuadsSerializer(model, NQuadsConfig.defaultConfig());
}
});

tempRegistry.put(RdfFormat.TRIG, (model, genericConfig) -> {
if (genericConfig instanceof TriGConfig specificConfig) {
return new TriGSerializer(model, specificConfig);
} else {
logger.warn("Provided config for TRIG is not TriGConfig (was {}). Using default TriGConfig.",
genericConfig.getClass().getSimpleName());
return new TriGSerializer(model, TriGConfig.defaultConfig());
}
});

tempRegistry.put(RdfFormat.RDFXML, (model, genericConfig) -> {
if (genericConfig instanceof XmlConfig specificConfig) {
return new XmlSerializer(model, specificConfig);
} else {
logger.warn("Provided config for RDFXML is not RdfXmlConfig (was {}). Using default RdfXmlConfig.",
genericConfig.getClass().getSimpleName());
return new XmlSerializer(model, XmlConfig.defaultConfig());
}
});

this.registry = Collections.unmodifiableMap(tempRegistry);
}

/**
* Creates an {@link RdfSerializer} instance for the specified format, model, and configuration.
*
* @param format the {@link RdfFormat} for which to create the serializer. Must not be null.
* @param model the {@link Model} to be serialized. Must not be null.
* @param config the {@link SerializationConfig} to apply during serialization. Must not be null.
* @return a new instance of {@link RdfSerializer} configured for the specified format.
* @throws NullPointerException if any of the arguments (format, model, config) are null.
* @throws IllegalArgumentException if the provided format is not supported by this factory.
*/
@Override
public RdfSerializer createSerializer(RdfFormat format, Model model, SerializationConfig config) {

Objects.requireNonNull(format, "RdfFormat cannot be null");
Objects.requireNonNull(model, "Model cannot be null");
Objects.requireNonNull(config, "SerializationConfig cannot be null");

BiFunction<Model, SerializationConfig, RdfSerializer> constructor = registry.get(format);

if (constructor == null) {
throw new IllegalArgumentException("Unsupported RdfFormat: " + format.getName());
}

return constructor.apply(model, config);
}
}

This file was deleted.

Loading