Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int compareTo(IRI o) {
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
if (! (o instanceof IRI))
return false;
AbstractIRI that = (AbstractIRI) o;
return this.stringValue().equals(that.stringValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ public interface RDFSerializer {
* process
*/
void write(final Writer writer) throws SerializationException;

/**
* Returns the format name for error messages and logging.
*
* @return the format name (e.g., "TriG", "Turtle").
*/
default String getFormatName() {
return getRDFFormat().getName();
};

/**
* Gets the RDF format that this serializer generates.
*/
RDFFormat getRDFFormat();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.inria.corese.core.next.impl.common.vocabulary;

import fr.inria.corese.core.next.api.IRI;
import fr.inria.corese.core.next.impl.common.BasicIRI;

public enum FOAF implements Vocabulary {
;

private final IRI iri;

FOAF(String localName) {
this.iri = new BasicIRI(getNamespace(), localName);
}

@Override
public IRI getIRI() {
return this.iri;
}

@Override
public String getNamespace() {
return getVocabularyNamespace(); // Referencing the directly defined static NS
}

@Override
public String getPreferredPrefix() {
return getVocabularyPreferredPrefix();
}

public static String getVocabularyNamespace() {
return "http://xmlns.com/foaf/0.1/";
}

public static String getVocabularyPreferredPrefix() {
return "foaf";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public enum OWL implements Vocabulary {

private final IRI iri;

public static final String NS = "http://www.w3.org/2002/07/owl#";

OWL(String localName) {
this.iri = new BasicIRI(getNamespace(), localName);
}
Expand All @@ -64,11 +62,19 @@ public IRI getIRI() {

@Override
public String getNamespace() {
return NS; // Referencing the directly defined static NS
return getVocabularyNamespace(); // Referencing the directly defined static NS
}

@Override
public String getPreferredPrefix() {
return getVocabularyPreferredPrefix();
}

public static String getVocabularyNamespace() {
return "http://www.w3.org/2002/07/owl#";
}

public static String getVocabularyPreferredPrefix() {
return "owl";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ public IRI getIRI() {

@Override
public String getNamespace() {
return "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
return getVocabularyNamespace();
}

@Override
public String getPreferredPrefix() {
return getVocabularyPreferredPrefix();
}

public static String getVocabularyNamespace() {
return "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
}

public static String getVocabularyPreferredPrefix() {
return "rdf";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public enum RDFS implements Vocabulary {

@Override
public String getNamespace() {
return "http://www.w3.org/2000/01/rdf-schema#";
return getVocabularyNamespace();
}

@Override
Expand All @@ -97,6 +97,14 @@ public IRI getIRI() {

@Override
public String getPreferredPrefix() {
return getVocabularyPreferredPrefix();
}

public static String getVocabularyNamespace() {
return "http://www.w3.org/2000/01/rdf-schema#";
}

public static String getVocabularyPreferredPrefix() {
return "rdfs";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public interface Vocabulary {
* @return the preferred prefix of this vocabulary
*/
String getPreferredPrefix();

static String getVocabularyNamespace() {
throw new RuntimeException("Unimplemented function");
}

static String getVocabularyPreferredPrefix() {
throw new RuntimeException("Unimplemented function");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,19 @@ public IRI getIRI() {

@Override
public String getNamespace() {
return "http://www.w3.org/2001/XMLSchema#";
return getVocabularyNamespace();
}

@Override
public String getPreferredPrefix() {
return getVocabularyPreferredPrefix();
}

public static String getVocabularyNamespace() {
return "http://www.w3.org/2001/XMLSchema#";
}

public static String getVocabularyPreferredPrefix() {
return "xsd";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class SerializationException extends CoreseException {
private final int lineNumber;
private final int columnNumber;

public static final String DEFAULT_FORMAT = "unknown";

public SerializationException(String message, String formatName) {
this(message, formatName, -1, -1, null);
}
Expand All @@ -27,7 +29,7 @@ public SerializationException(String message, String formatName) {
* the {@link #getMessage()} method).
* @param formatName the name of the RDF format being processed when the error
* occurred.
* Use "unknown" if the format is not applicable or cannot be
* Use DEFAULT_FORMAT if the format is not applicable or cannot be
* determined.
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method).
Expand Down Expand Up @@ -71,7 +73,7 @@ public SerializationException(String message, String formatName, int lineNumber,
*/
private static String buildMessage(String base, String format, int line, int col) {
StringBuilder sb = new StringBuilder(base);
if (!"unknown".equals(format)) {
if (!DEFAULT_FORMAT.equals(format)) {
sb.append(" [Format: ").append(format).append("]");
}
if (line > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package fr.inria.corese.core.next.impl.io.common;

import fr.inria.corese.core.util.Property;

/**
* Shared constants between serializers and parsers
*/
public class IOConstants {

protected IOConstants() {

}

// Generic characters

public static final String POINT = ".";

public static final String SEMICOLON = ";";

public static final String COMMA = ",";

public static final String COLON = ":";

public static final String SPACE = " ";

public static final String TAB = "\t";

public static final String LINE_FEED = "\n";

public static final String HASH = "#";

public static final String CARRIAGE_RETURN = "\r";

public static final String SLASH = "/";

public static final String QUOTE = "\"";

public static final String AT = "@";

public static final String LT = "<"; // Less than

public static final String GT = ">"; // Greater than

// RDF-specific characters

/**
* The blank node prefix.
*/
public static final String BLANK_NODE_PREFIX = "_:";

public static final String IRI_START = "<";

public static final String IRI_END = ">";

public static final String RDF_TYPE_SHORTCUT = "a";

/**
* Returns the configured default base URI for IRI resolution.
* The value is configurable via {@code Property.Value.DEFAULT_BASE_URI}.
*
* @return the default base URI from configuration, or null if not set
*/
public static String getDefaultBaseURI() {
String configuredValue = Property.getStringValue(Property.Value.DEFAULT_BASE_URI);
if (configuredValue == null || configuredValue.isEmpty()) {
return "http://example.org/";
}
return configuredValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.inria.corese.core.next.impl.io.option;
package fr.inria.corese.core.next.impl.io.common;

import java.net.URI;
import java.time.Duration;
Expand All @@ -18,7 +18,7 @@
* @see <a href=
* "https://javadoc.io/doc/com.apicatalog/titanium-json-ld/latest/com/apicatalog/jsonld/JsonLdOptions.html">JsonLdOptions</a>
*/
public class JSONLDProcessorOptions extends AbstractIOOptions
public class JSONLDOptions extends AbstractIOOptions
implements BaseIRIOptions {

private final Builder builder;
Expand All @@ -28,7 +28,7 @@ public class JSONLDProcessorOptions extends AbstractIOOptions
*
* @param builder the builder containing the options for this processor
*/
protected JSONLDProcessorOptions(Builder builder) {
protected JSONLDOptions(Builder builder) {
this.builder = builder;
}

Expand Down Expand Up @@ -141,18 +141,18 @@ public String getBaseIRI() {
}

/**
* Builder for creating instances of JSONLDProcessorOptions.
* Builder for creating instances of JSONLDOptions.
* This nested static class provides a fluent API for configuring the
* various options before building the final
* {@code JSONLDProcessorOptions} object.
* {@code JSONLDOptions} object.
*/
public static class Builder extends AbstractIOOptions.Builder<JSONLDProcessorOptions> {
public static class Builder extends AbstractIOOptions.Builder<JSONLDOptions> {

private final JsonLdOptions options = new JsonLdOptions();

@Override
public JSONLDProcessorOptions build() {
return new JSONLDProcessorOptions(this);
public JSONLDOptions build() {
return new JSONLDOptions(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String resolveIRI(String raw) {
try {
raw = raw.trim();

if (raw.equals(ParserConstants.A)) {
if (raw.equals(ParserConstants.RDF_TYPE_SHORTCUT)) {
return RDF.type.getIRI().stringValue();
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public String buildURI(String scheme, String authority, String path, String quer
result.append(ParserConstants.QUERY_MARK).append(query);
}
if (fragment != null) {
result.append(ParserConstants.FRAGMENT).append(fragment);
result.append(ParserConstants.HASH).append(fragment);
}
return normalizeURI(result.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import fr.inria.corese.core.next.impl.common.literal.XSD;
import fr.inria.corese.core.next.impl.common.util.IRIUtils;
import fr.inria.corese.core.next.impl.exception.ParsingErrorException;
import fr.inria.corese.core.next.impl.io.option.JSONLDProcessorOptions;
import fr.inria.corese.core.next.impl.io.common.JSONLDOptions;

/**
* Parser for JSON-LD RDF files. This parser is based on the Titanium JSON-LD library.
Expand All @@ -43,7 +43,7 @@ public class JSONLDParser extends AbstractRDFParser {
* @param factory the value factory used to create RDF values
*/
public JSONLDParser(Model model, ValueFactory factory) {
this(model, factory, new JSONLDProcessorOptions.Builder().build());
this(model, factory, new JSONLDOptions.Builder().build());
}

/**
Expand Down Expand Up @@ -96,8 +96,8 @@ public void parse(Reader reader, String baseURI) {
private void parseJSONLDDocument(Document document, String baseURI) {
try {
JsonLdOptions options = new JsonLdOptions();
if(this.getConfig() instanceof JSONLDProcessorOptions) {
options = ((JSONLDProcessorOptions) this.getConfig()).getJsonLdOptions();
if(this.getConfig() instanceof JSONLDOptions) {
options = ((JSONLDOptions) this.getConfig()).getJsonLdOptions();
}
if(baseURI != null && !baseURI.isEmpty()) {
options.setBase(URI.create(baseURI));
Expand Down Expand Up @@ -148,7 +148,7 @@ public RdfQuadConsumer quad(String subject, String predicate, String object, Str
} else if(IRIUtils.isStandardIRI(object)) {
objValue = getValueFactory().createIRI(object);
} else {
throw new RdfConsumerException("Invalid object: " + object);
throw new ParsingErrorException("Invalid object: " + object);
}

// Graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.inria.corese.core.next.impl.common.literal.XSD;
import fr.inria.corese.core.next.impl.common.vocabulary.RDF;
import fr.inria.corese.core.next.impl.exception.IncorrectFormatException;
import fr.inria.corese.core.next.impl.exception.ParsingErrorException;
import fr.inria.corese.core.next.impl.io.parser.util.ParserConstants;
import org.xml.sax.*;
import java.util.List;
Expand Down Expand Up @@ -104,7 +105,7 @@ public static String resolveAgainstBase(String iri, String baseURI) {
try {
return new java.net.URI(baseURI).resolve(iri).toString();
} catch (Exception e) {
throw new IncorrectFormatException("Failed to resolve IRI: " + iri + " against base: " + baseURI, e);
throw new ParsingErrorException("Failed to resolve IRI: " + iri + " against base: " + baseURI, e);
}
}

Expand Down
Loading