本文整理汇总了Java中org.eclipse.rdf4j.model.ValueFactory类的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory类的具体用法?Java ValueFactory怎么用?Java ValueFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueFactory类属于org.eclipse.rdf4j.model包,在下文中一共展示了ValueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IriTermGenerator_withRelativeIRI_usesBaseIRI
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void IriTermGenerator_withRelativeIRI_usesBaseIRI() throws Exception {
ValueFactory f = SimpleValueFactory.getInstance();
String baseIri = "http://base.iri";
TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null);
String ref = "ref";
TermGenerator<Value> generator = tgc.getObjectGenerator(new ObjectMapImpl(ref, null, null, TermType.IRI, null, null, null, null));
String relativeIriPart = "/relativeIriPortion";
EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class);
when(evaluator.apply(ref)).thenReturn(Optional.of(relativeIriPart));
Optional<Value> result = generator.apply(evaluator);
Assert.assertTrue(result.isPresent());
Assert.assertTrue(result.get() instanceof IRI);
Assert.assertEquals(result.get(), f.createIRI(baseIri + relativeIriPart));
}
示例2: IriTermGenerator_withAbsoluteIRI_usesBaseIRI
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void IriTermGenerator_withAbsoluteIRI_usesBaseIRI() throws Exception {
ValueFactory f = SimpleValueFactory.getInstance();
String baseIri = "http://base.iri";
TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null);
String ref = "ref";
TermGenerator<Value> generator = tgc.getObjectGenerator(new ObjectMapImpl(ref, null, null, TermType.IRI, null, null, null, null));
String absoluteIri = "http://foo.bar/absoluteIri";
EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class);
when(evaluator.apply(ref)).thenReturn(Optional.of(absoluteIri));
Optional<Value> result = generator.apply(evaluator);
Assert.assertTrue(result.isPresent());
Assert.assertTrue(result.get() instanceof IRI);
Assert.assertEquals(result.get(), f.createIRI(absoluteIri));
}
示例3: IriTermGenerator_withFaultyIRI_throwsException
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void IriTermGenerator_withFaultyIRI_throwsException() throws Exception {
ValueFactory f = SimpleValueFactory.getInstance();
String baseIri = "?";
TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null);
String ref = "ref";
TermGenerator<Value> generator = tgc.getObjectGenerator(new ObjectMapImpl(ref, null, null, TermType.IRI, null, null, null, null));
String relativeIriPart = "/relativeIriPortion";
EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class);
when(evaluator.apply(ref)).thenReturn(Optional.of(relativeIriPart));
RuntimeException exception = null;
try {
generator.apply(evaluator);
Assert.assertTrue("This code should be unreachable", false);
} catch (RuntimeException e) {
exception = e;
}
Assert.assertNotNull(exception);
Assert.assertTrue(exception.getMessage().startsWith("data error: could not generate a valid iri"));
}
示例4: listObjects_NoDuplicates_WhenSubjectAndPropSimilar
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void listObjects_NoDuplicates_WhenSubjectAndPropSimilar() throws Exception {
// Arrange
RepositoryConnection repositoryConnection = mock(RepositoryConnection.class);
when(repository.getConnection()).thenReturn(repositoryConnection);
ValueFactory valueFactory = SimpleValueFactory.getInstance();
when(repositoryConnection.getValueFactory()).thenReturn(valueFactory);
RepositoryResult queryResult = mock(RepositoryResult.class);
Model model =
new ModelBuilder().add("http://www.test.nl#sub", "http://www.test.nl#pred", "test").build();
when(queryResult.hasNext()).thenReturn(true).thenReturn(false);
when(queryResult.next()).thenReturn(model.stream().findFirst().get());
when(
repositoryConnection.getStatements(any(), any(), isNull(), anyBoolean(), any())).thenReturn(
queryResult);
Value subject = SimpleValueFactory.getInstance().createIRI("http://www.test.nl#test");
Value prop = SimpleValueFactory.getInstance().createIRI("http://www.test.nl#test");
// Act
Collection<Value> values = backend.listObjects(subject, prop);
// Assert
assertThat(values, hasSize(1));
assertThat(values.iterator().next().stringValue(), is("test"));
}
示例5: listSubjects_ListOnlySubjects_InMixedModel
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void listSubjects_ListOnlySubjects_InMixedModel() throws Exception {
// Arrange
RepositoryConnection repositoryConnection = mock(RepositoryConnection.class);
when(repository.getConnection()).thenReturn(repositoryConnection);
ValueFactory valueFactory = SimpleValueFactory.getInstance();
when(repositoryConnection.getValueFactory()).thenReturn(valueFactory);
RepositoryResult queryResult = mock(RepositoryResult.class);
Model model =
new ModelBuilder().add("http://www.test.nl#sub", "http://www.test.nl#pred", "test").build();
when(queryResult.hasNext()).thenReturn(true).thenReturn(false);
when(queryResult.next()).thenReturn(model.stream().findFirst().get());
when(
repositoryConnection.getStatements(isNull(), any(), any(), anyBoolean(), any())).thenReturn(
queryResult);
Value subject = SimpleValueFactory.getInstance().createIRI("http://www.test.nl#test");
Value prop = SimpleValueFactory.getInstance().createIRI("http://www.test.nl#test");
// Act
Collection<Value> values = backend.listSubjects(subject, prop);
// Assert
assertThat(values, hasSize(1));
assertThat(values.iterator().next(),
is(SimpleValueFactory.getInstance().createIRI("http://www.test.nl#sub")));
}
示例6: loadResources_ThrowException_WithUnknownParameterMapper
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void loadResources_ThrowException_WithUnknownParameterMapper() {
// Assert
thrown.expect(ConfigurationException.class);
// Arrange
ValueFactory valueFactory = SimpleValueFactory.getInstance();
final IRI unknownParameterMapper =
valueFactory.createIRI("http://dotwebstack.org/def/elmo", "UnknownParameterMapper");
when(graphQuery.evaluate()).thenReturn(new IteratingGraphQueryResult(ImmutableMap.of(),
ImmutableList.of(
valueFactory.createStatement(DBEERPEDIA.SUBJECT_FROM_URL, RDF.TYPE,
unknownParameterMapper),
valueFactory.createStatement(DBEERPEDIA.SUBJECT_FROM_URL, ELMO.SOURCE_PROP,
HTTP.REQUEST_URI),
valueFactory.createStatement(DBEERPEDIA.SUBJECT_FROM_URL, ELMO.TARGET_PROP,
DBEERPEDIA.SUBJECT_PARAMETER))));
// Act
parameterMapperResourceProvider.loadResources();
}
示例7: convertValue
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
public Value convertValue(Object object) {
if (object instanceof Value) {
return (Value) object;
}
ValueFactory valueFactory = SimpleValueFactory.getInstance();
if (object instanceof String) {
return valueFactory.createLiteral((String) object);
}
if (object instanceof Integer) {
return valueFactory.createLiteral((Integer) object);
}
if (object instanceof Double) {
return valueFactory.createLiteral((Double) object);
}
throw new NotSupportedException("Value is not supported: " + object.getClass());
}
示例8: testBlankNodes
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void testBlankNodes() throws Throwable {
IRI uriA = sail.getValueFactory().createIRI("http://example.org/test/S_POG#a");
IRI uriB = sail.getValueFactory().createIRI("http://example.org/test/S_POG#b");
try (SailConnection sc = getConnection()) {
ValueFactory factory = sail.getValueFactory();
BNode bNode = factory.createBNode();
try {
sc.addStatement(uriA, uriA, bNode);
} catch (SailException se) {
// FIXME: not supporting blank nodes ATM
assertTrue(se.getCause() instanceof UnsupportedOperationException);
}
commit(sc);
}
}
示例9: loadTriples
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
public void loadTriples() throws RepositoryException {
ValueFactory vf = SimpleValueFactory.getInstance();
IRI graph = vf.createIRI("urn:test");
int docSize = 100000;
conn.configureWriteCache(750,750,600); // customise write cache (initDelay interval, delayCache interval, cache size)
conn.begin();
Set<Statement> bulkInsert = new HashSet();
for (int term = 0; term < docSize; term++) {
bulkInsert.add(vf.createStatement
(vf.createIRI("urn:subject:" + term),
vf.createIRI("urn:predicate:" + term),
vf.createIRI("urn:object:" + term)));
}
conn.add(bulkInsert, graph);
conn.commit();
}
示例10: FederationEvalStrategy
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
public FederationEvalStrategy(FedXConnection conn) {
super(new org.eclipse.rdf4j.query.algebra.evaluation.TripleSource() {
@Override
public CloseableIteration<? extends Statement, QueryEvaluationException> getStatements(
Resource subj, IRI pred, Value obj, Resource... contexts)
throws QueryEvaluationException
{
throw new FedXRuntimeException(
"Federation Strategy does not support org.openrdf.query.algebra.evaluation.TripleSource#getStatements." +
" If you encounter this exception, please report it.");
}
@Override
public ValueFactory getValueFactory() {
return SimpleValueFactory.getInstance();
}}, (FederatedServiceResolver)null); // !!! ", null" added
this.conn = conn;
this.executor = conn.getFederation().getExecutor();
this.cache = conn.getFederation().getCache();
this.statistics = conn.getFederation().getStatistics();
}
示例11: verifyStatementPresence
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
private void verifyStatementPresence(Collection<Statement> statements, URI contextUri) throws Exception {
final EntityManager em = emf.createEntityManager();
final Repository repo = em.unwrap(Repository.class);
try (final RepositoryConnection connection = repo.getConnection()) {
final ValueFactory vf = connection.getValueFactory();
final org.eclipse.rdf4j.model.IRI context = vf.createIRI(contextUri.toString());
for (Statement s : statements) {
final RepositoryResult rr = connection
.getStatements(s.getSubject(), s.getPredicate(), s.getObject(), false, context);
assertTrue(rr.hasNext());
rr.close();
}
} finally {
em.close();
}
}
示例12: buildOntoMetaData
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
private <ONTORES> void buildOntoMetaData(Model model, Resource root, ValueFactory factory,
OntoContainer<ONTORES> onto, int number) {
IRI ontologyResource = factory.createIRI(ALIGN_NS + onto.getURI());
if (number == 1) {
model.add(root, ONTO1_PROPERTY, ontologyResource);
} else {
model.add(root, ONTO2_PROPERTY, ontologyResource);
}
model.add(ontologyResource, RDF.TYPE, ONTOLOGY_TYPE);
model.add(ontologyResource, LOCATION_PROPERTY,factory.createLiteral(onto.getURI().toString()));
model.add(ontologyResource, FORMALISM_PROPERTY,factory.createLiteral(onto.getFormalism()));
}
示例13: buildNoMapNode
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
private <ONTORES> void buildNoMapNode(OntoContainer<ONTORES> onto,
NoMappingPossible<ONTORES> noMap, int number, Model model, ValueFactory factory,
Resource alignmentRoot) {
// ordre d'insertion des proprietes necessaires pour avoir une "belle"
// ecriture dans le fichier RDF/XML
// on créé le noeud correspondant a la Cell
BNode cellNode = factory.createBNode();
// on relie l'objet "Alignement" a ce noeud par la propriete "nomap"
model.add(alignmentRoot,NOMAP_PROPERTY,cellNode);
// on donne le type de l'objet "Cell"
model.add(cellNode, RDF.TYPE, CELL_TYPE);
IRI res1 = factory.createIRI(onto.getURI(noMap.getConcept())
.toString());
if (number == 1)
model.add(cellNode,ENTITY1_PROPERTY,res1);
else
model.add(cellNode,ENTITY2_PROPERTY,res1);
}
示例14: testWriteToReadOnly
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test(expected = SailException.class)
public void testWriteToReadOnly() throws Exception {
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "whatevertableRO", true, 0, true, 0, null, null);
sail.initialize();
try {
HTableDescriptor desc = sail.table.getTableDescriptor();
try (Connection con = ConnectionFactory.createConnection(HBaseServerTestInstance.getInstanceConfig())) {
try (Admin ha = con.getAdmin()) {
desc = new HTableDescriptor(desc);
desc.setReadOnly(true);
ha.modifyTable(desc.getTableName(), desc);
}
}
ValueFactory vf = SimpleValueFactory.getInstance();
sail.addStatement(vf.createIRI("http://whatever/subj"), vf.createIRI("http://whatever/pred"), vf.createLiteral("whatever"));
} finally {
sail.shutDown();
}
}
示例15: testEvaluate
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void testEvaluate() throws Exception {
ValueFactory vf = SimpleValueFactory.getInstance();
Resource subj = vf.createIRI("http://whatever/subj/");
IRI pred = vf.createIRI("http://whatever/pred/");
Value obj = vf.createLiteral("whatever");
CloseableIteration<? extends Statement, SailException> iter;
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "whatevertable", true, 0, true, 0, null, null);
SailRepository rep = new SailRepository(sail);
rep.initialize();
sail.addStatement(subj, pred, obj);
sail.commit();
TupleQuery q = rep.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, "select ?s ?p ?o where {<http://whatever/subj/> <http://whatever/pred/> \"whatever\"}");
TupleQueryResult res = q.evaluate();
assertTrue(res.hasNext());
rep.shutDown();
}