Skip to content

Commit

Permalink
Merge pull request #3778 from eclipse/merge-main
Browse files Browse the repository at this point in the history
Merge main into develop
  • Loading branch information
hmottestad authored Apr 5, 2022
2 parents 5fe4ed8 + f283fb9 commit 385dd8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Triple;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.util.Literals;
import org.eclipse.rdf4j.rio.helpers.RDFStarUtil;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.sail.base.SailDataset;
import org.eclipse.rdf4j.sail.base.SailSink;
Expand All @@ -60,7 +62,8 @@ class FileIO {
// Version 1: initial version
// Version 2: don't use read/writeUTF() to remove 64k limit on strings,
// removed dummy "up-to-date status" boolean for namespace records
private static final int BMSF_VERSION = 2;
// Version 3: introduced RDF-star triple record type
private static final int BMSF_VERSION = 3;

/* RECORD TYPES */
public static final int NAMESPACE_MARKER = 1;
Expand All @@ -83,6 +86,8 @@ class FileIO {

public static final int DATATYPE_LITERAL_MARKER = 10;

public static final int RDFSTAR_TRIPLE_MARKER = 11;

public static final int EOF_MARKER = 127;

/*-----------*
Expand Down Expand Up @@ -260,13 +265,13 @@ private void readStatement(boolean hasContext, boolean isExplicit, DataInputStre
}

private void writeValue(Value value, DataOutputStream dataOut) throws IOException {
if (value instanceof IRI) {
if (value.isIRI()) {
dataOut.writeByte(URI_MARKER);
writeString(((IRI) value).toString(), dataOut);
} else if (value instanceof BNode) {
writeString(((IRI) value).stringValue(), dataOut);
} else if (value.isBNode()) {
dataOut.writeByte(BNODE_MARKER);
writeString(((BNode) value).getID(), dataOut);
} else if (value instanceof Literal) {
} else if (value.isLiteral()) {
Literal lit = (Literal) value;

String label = lit.getLabel();
Expand All @@ -281,6 +286,9 @@ private void writeValue(Value value, DataOutputStream dataOut) throws IOExceptio
writeString(label, dataOut);
writeValue(datatype, dataOut);
}
} else if (value.isTriple()) {
dataOut.writeByte(RDFSTAR_TRIPLE_MARKER);
writeValue(RDFStarUtil.toRDFEncodedValue(value), dataOut);
} else {
throw new IllegalArgumentException("unexpected value type: " + value.getClass());
}
Expand All @@ -306,6 +314,9 @@ private Value readValue(DataInputStream dataIn) throws IOException, ClassCastExc
String label = readString(dataIn);
IRI datatype = (IRI) readValue(dataIn);
return vf.createLiteral(label, datatype);
} else if (valueTypeMarker == RDFSTAR_TRIPLE_MARKER) {
IRI rdfStarEncodedTriple = (IRI) readValue(dataIn);
return RDFStarUtil.fromRDFEncodedValue(rdfStarEncodedTriple);
} else {
throw new IOException("Invalid value type marker: " + valueTypeMarker);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*******************************************************************************
* Copyright (c) 2020 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
Expand All @@ -7,19 +7,25 @@
*******************************************************************************/
package org.eclipse.rdf4j.sail.memory;

import java.io.File;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.testsuite.repository.RDFStarSupportTest;
import org.junit.jupiter.api.io.TempDir;

/**
* @author jeen
*
*/
public class MemoryRDFStarSupportTest extends RDFStarSupportTest {

@TempDir
File tempDir;

@Override
protected Repository createRepository() {
return new SailRepository(new MemoryStore());
return new SailRepository(new MemoryStore(tempDir));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

/**
* Test cases for RDF-star support in the Repository.
*
* @author Jeen Broekstra
*
*/
@Timeout(value = 10, unit = TimeUnit.MINUTES)
public abstract class RDFStarSupportTest {
/**
* Timeout all individual tests after 10 minutes.
*/
@Rule
public Timeout to = new Timeout(10, TimeUnit.MINUTES);

private Repository testRepository;

Expand All @@ -70,7 +65,7 @@ public abstract class RDFStarSupportTest {

private IRI context2;

@Before
@BeforeEach
public void setUp() throws Exception {
testRepository = createRepository();

Expand All @@ -95,7 +90,7 @@ public void setUp() throws Exception {
context2 = vf.createIRI("urn:x-local:graph2");
}

@After
@AfterEach
public void tearDown() throws Exception {
try {
testCon.close();
Expand Down

0 comments on commit 385dd8e

Please sign in to comment.