use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class NamespacesTest method testAsMapMultiple.
/**
* Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#asMap(java.util.Set)}.
*/
@Test
public final void testAsMapMultiple() {
Set<Namespace> input = new HashSet<Namespace>();
input.add(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
input.add(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
input.add(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
input.add(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
input.add(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));
Map<String, String> map = Namespaces.asMap(input);
assertFalse(map.isEmpty());
assertEquals(5, map.size());
assertTrue(map.containsKey(RDF.PREFIX));
assertEquals(RDF.NAMESPACE, map.get(RDF.PREFIX));
assertTrue(map.containsKey(RDFS.PREFIX));
assertEquals(RDFS.NAMESPACE, map.get(RDFS.PREFIX));
assertTrue(map.containsKey(DC.PREFIX));
assertEquals(DC.NAMESPACE, map.get(DC.PREFIX));
assertTrue(map.containsKey(SKOS.PREFIX));
assertEquals(SKOS.NAMESPACE, map.get(SKOS.PREFIX));
assertTrue(map.containsKey(SESAME.PREFIX));
assertEquals(SESAME.NAMESPACE, map.get(SESAME.PREFIX));
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class NamespacesTest method testWrapEntrySet.
/**
* Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
*/
@Test
public final void testWrapEntrySet() throws Exception {
Set<Namespace> testSet = new LinkedHashSet<Namespace>();
Map<String, String> testMap = Namespaces.wrap(testSet);
Set<Entry<String, String>> entrySet1 = testMap.entrySet();
assertNotNull(entrySet1);
assertTrue(entrySet1.isEmpty());
testSet.add(new SimpleNamespace(testPrefix1, testName1));
Set<Entry<String, String>> entrySet2 = testMap.entrySet();
assertNotNull(entrySet2);
assertFalse(entrySet2.isEmpty());
assertEquals(1, entrySet2.size());
Entry<String, String> nextEntry = entrySet2.iterator().next();
assertEquals(testPrefix1, nextEntry.getKey());
assertEquals(testName1, nextEntry.getValue());
testSet.clear();
Set<Entry<String, String>> entrySet3 = testMap.entrySet();
assertNotNull(entrySet3);
assertTrue(entrySet3.isEmpty());
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class NamespacesTest method testWrapContainsKey.
/**
* Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#wrap(java.util.Set)}.
*/
@Test
public final void testWrapContainsKey() throws Exception {
Set<Namespace> testSet = new LinkedHashSet<Namespace>();
Map<String, String> testMap = Namespaces.wrap(testSet);
// Check no exceptions when calling containsKey on empty backing set
assertFalse(testMap.containsKey(testPrefix1));
testSet.add(new SimpleNamespace(testPrefix1, testName1));
assertTrue(testMap.containsKey(testPrefix1));
testSet.clear();
assertFalse(testMap.containsKey(testPrefix1));
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class JSONLDParserHandlerTest method writeJSONLD.
/**
* Helper method to write the given model to JSON-LD and return an InputStream containing the results.
*
* @param statements
* @return An {@link InputStream} containing the results.
* @throws RDFHandlerException
*/
private InputStream writeJSONLD(Model statements) throws RDFHandlerException {
final StringWriter writer = new StringWriter();
final RDFWriter jsonldWriter = new JSONLDWriter(writer);
jsonldWriter.startRDF();
for (final Namespace prefix : statements.getNamespaces()) {
jsonldWriter.handleNamespace(prefix.getPrefix(), prefix.getName());
}
for (final Statement nextStatement : statements) {
jsonldWriter.handleStatement(nextStatement);
}
jsonldWriter.endRDF();
return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class Rio method write.
/**
* Writes the given statements to the given {@link RDFHandler}.
* <p>
* If the collection is a {@link Model}, its namespaces will also be written.
*
* @param model
* A collection of statements, such as a {@link Model}, to be written.
* @throws RDFHandlerException
* Thrown if there is an error writing the statements.
*/
public static void write(Iterable<Statement> model, RDFHandler writer) throws RDFHandlerException {
writer.startRDF();
if (model instanceof NamespaceAware) {
for (Namespace nextNamespace : ((NamespaceAware) model).getNamespaces()) {
writer.handleNamespace(nextNamespace.getPrefix(), nextNamespace.getName());
}
}
for (final Statement st : model) {
writer.handleStatement(st);
}
writer.endRDF();
}
Aggregations