Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ private void handleEndElement(String uri, String localName, String qName) {
IRI predicate = ctx.predicateStack.pop();
Resource subject = ctx.subjectStack.peek();
String datatypeUri = ctx.datatypeStack.isEmpty() ? null : ctx.datatypeStack.pop();
//emitLiteral(subject, predicate, text, datatypeUri);
String lang = ctx.langStack.isEmpty() ? null : ctx.langStack.peek();
emitter.emitLiteral(subject, predicate, text, datatypeUri, lang);
return;
Expand Down Expand Up @@ -213,7 +212,8 @@ private void updateLang(Attributes attrs) {
private void updateDatatype(Attributes attrs) {
String datatype = attrs.getValue(RDF.type.getNamespace(), "datatype");
if (datatype != null) {
ctx.datatypeStack.push(datatype);
String expanded = expandQNameFromQName(datatype);
ctx.datatypeStack.push(expanded);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public static Optional<XSD> resolveDatatype(String datatypeUri) {
return Optional.empty();
}

/**
* Expands a QName string (e.g. "xsd:integer") into a full URI if known.
* Currently supports "xsd:" → XML Schema namespace.
*
* @param qname the QName string
* @return expanded full URI if a known prefix, otherwise returns qname unchanged
*/
public static String expandQNameFromQName(String qname) {
if (qname == null) return null;
if (qname.startsWith("xsd:")) {
return "http://www.w3.org/2001/XMLSchema#" + qname.substring("xsd:".length());
}
return qname;
}

/**
* Extracts a subject resource from RDF/XML attributes.
* Supports rdf:about, rdf:nodeID, rdf:ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ private Model performRoundTrip(Model originalModel) throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with simple model containing basic IRIs and literals")
void testRoundTripWithSimpleModel() throws Exception {
// Given: A simple model with basic triples
Expand All @@ -282,7 +281,6 @@ void testRoundTripWithSimpleModel() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with complex model containing diverse RDF value types")
void testRoundTripWithComplexModel() throws Exception {
// Given: A complex model with various RDF constructs
Expand All @@ -299,7 +297,6 @@ void testRoundTripWithComplexModel() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with empty model")
void testRoundTripWithEmptyModel() throws Exception {
// Given: An empty model
Expand All @@ -315,15 +312,12 @@ void testRoundTripWithEmptyModel() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with model containing only typed literals")
void testRoundTripWithTypedLiterals() throws Exception {
// Given: A model with various typed literals
Model originalModel = createTypedLiteralsTestModel();

// When: Performing round-trip serialization and parsing
Model deserializedModel = performRoundTrip(originalModel);

// Then: All typed literals should be preserved correctly
assertEquals(originalModel.size(), deserializedModel.size(),
"Model sizes should be equal after round-trip");
Expand All @@ -332,7 +326,6 @@ void testRoundTripWithTypedLiterals() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with model containing only language-tagged literals")
void testRoundTripWithLanguageTaggedLiterals() throws Exception {
// Given: A model with language-tagged literals
Expand All @@ -349,7 +342,6 @@ void testRoundTripWithLanguageTaggedLiterals() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with model containing only blank nodes")
void testRoundTripWithBlankNodes() throws Exception {
// Given: A model with blank nodes as subjects and objects
Expand All @@ -367,7 +359,6 @@ void testRoundTripWithBlankNodes() throws Exception {
}

@Test
@Disabled("Waiting for RDF/XML parser implementation from PR #176")
@DisplayName("Round-trip test with model containing special characters and escape sequences")
void testRoundTripWithSpecialCharacters() throws Exception {
// Given: A model with special characters and escape sequences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import fr.inria.corese.core.next.impl.temp.CoreseAdaptedValueFactory;
import fr.inria.corese.core.next.impl.temp.CoreseModel;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -21,6 +23,8 @@
* and unescaping of IRIs and literals, and named graphs.
*/
public class RDFXMLParserTest {
private static final Logger logger = LoggerFactory.getLogger(RDFXMLParserTest.class);

/**
* Helper method to parse the RDF/XML String
* @param rdfXml
Expand All @@ -37,36 +41,45 @@ private Model parseRdfXml(String rdfXml) throws Exception {
return model;
}

/**
* Helper method to print the model.
* @param model
*/
/**
* Helper method to print the model.
* @param model
*/
private void printModel(Model model) {
model.stream().forEach(stmt -> {
Value obj = stmt.getObject();
String subjectString = stmt.getSubject().stringValue();
String predicateString = stmt.getPredicate().stringValue();

if (obj instanceof Literal literal) {
if (literal.getLanguage().isPresent()) {
System.out.printf("(%s, %s, \"%s\"@%s)%n",
stmt.getSubject().stringValue(),
stmt.getPredicate().stringValue(),
literal.getLabel(),
literal.getLanguage().get());
String label = String.valueOf(literal.getLabel());
String languageTag = literal.getLanguage().orElse(null);

if (languageTag != null) {
logger.debug("({}, {}, \"{}\"@{})",
subjectString,
predicateString,
label,
languageTag);
} else {
System.out.printf("(%s, %s, \"%s\")%n",
stmt.getSubject().stringValue(),
stmt.getPredicate().stringValue(),
literal.getLabel());
logger.debug("({}, {}, \"{}\")",
subjectString,
predicateString,
label);
}
} else {
System.out.printf("(%s, %s, %s)%n",
stmt.getSubject().stringValue(),
stmt.getPredicate().stringValue(),
logger.debug("({}, {}, {})",
subjectString,
predicateString,
obj.stringValue());
}
});
}


/**
* Test node elements with IRIs
* @throws Exception
Expand Down