本文整理汇总了Java中org.eclipse.rdf4j.model.ValueFactory类的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory类的具体用法?Java ValueFactory怎么用?Java ValueFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueFactory类属于org.eclipse.rdf4j.model包,在下文中一共展示了ValueFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:carml,项目名称:carml,代码行数:21,代码来源:TermGeneratorCreatorTest.java
示例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));
}
开发者ID:carml,项目名称:carml,代码行数:21,代码来源:TermGeneratorCreatorTest.java
示例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"));
}
开发者ID:carml,项目名称:carml,代码行数:27,代码来源:TermGeneratorCreatorTest.java
示例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"));
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:25,代码来源:Rdf4jRepositoryBackendTest.java
示例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")));
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:26,代码来源:Rdf4jRepositoryBackendTest.java
示例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();
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:23,代码来源:ParameterMapperResourceProviderTest.java
示例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());
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:SparqlHttpStub.java
示例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);
}
}
开发者ID:joshsh,项目名称:graphsail,代码行数:17,代码来源:SailTest.java
示例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();
}
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:19,代码来源:Example4_Load_Triples.java
示例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();
}
开发者ID:dice-group,项目名称:CostFed,代码行数:24,代码来源:FederationEvalStrategy.java
示例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();
}
}
开发者ID:kbss-cvut,项目名称:reporting-tool,代码行数:17,代码来源:OccurrenceReportFormGenDaoTest.java
示例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()));
}
开发者ID:lmazuel,项目名称:onagui,代码行数:17,代码来源:EuzenatRDFImpl.java
示例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);
}
开发者ID:lmazuel,项目名称:onagui,代码行数:23,代码来源:EuzenatRDFImpl.java
示例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();
}
}
开发者ID:Merck,项目名称:Halyard,代码行数:20,代码来源:HBaseSailTest.java
示例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();
}
开发者ID:Merck,项目名称:Halyard,代码行数:18,代码来源:HBaseSailTest.java
示例16: testEvaluateWithContext
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void testEvaluateWithContext() 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");
IRI context = vf.createIRI("http://whatever/context/");
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, context);
sail.commit();
TupleQuery q = rep.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, "select ?s ?p ?o from named <http://whatever/context/> where {<http://whatever/subj/> <http://whatever/pred/> \"whatever\"}");
TupleQueryResult res = q.evaluate();
assertFalse(res.hasNext());
rep.shutDown();
}
开发者ID:Merck,项目名称:Halyard,代码行数:19,代码来源:HBaseSailTest.java
示例17: setup
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Override
protected void setup(Context context) throws IOException, InterruptedException {
FunctionRegistry.getInstance().add(new Function() {
@Override
public String getURI() {
return DECIMATE_FUNCTION_URI;
}
@Override
public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
if (args.length < 3) throw new ValueExprEvaluationException("Minimal number of arguments for " + DECIMATE_FUNCTION_URI + " function is 3");
if (!(args[0] instanceof Literal) || !(args[1] instanceof Literal)) throw new ValueExprEvaluationException("First two two arguments of " + DECIMATE_FUNCTION_URI + " function must be literals");
int index = ((Literal)args[0]).intValue();
int size = ((Literal)args[1]).intValue();
int hash = Arrays.hashCode(Arrays.copyOfRange(args, 2, args.length));
return valueFactory.createLiteral(Math.floorMod(hash, size) == index);
}
});
Configuration conf = context.getConfiguration();
tableName = conf.get(TABLE_NAME_PROPERTY);
elasticIndexURL = conf.get(ELASTIC_INDEX_URL);
defaultTimestamp = conf.getLong(DEFAULT_TIMESTAMP_PROPERTY, System.currentTimeMillis());
}
开发者ID:Merck,项目名称:Halyard,代码行数:24,代码来源:HalyardBulkUpdate.java
示例18: setup
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
File rf = File.createTempFile("HalyardUpdateTest", "");
rf.delete();
rf.mkdirs();
ROOT = rf.toURI().toURL().toString();
if (!ROOT.endsWith("/")) {
ROOT = ROOT + "/";
}
ValueFactory vf = SimpleValueFactory.getInstance();
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null, null);
sail.initialize();
for (int i=0; i<5; i++) {
for (int j=0; j<5; j++) {
sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/pred"), vf.createIRI("http://whatever/obj" + j));
}
}
sail.commit();
sail.shutDown();
HalyardUpdate.conf = HBaseServerTestInstance.getInstanceConfig();
}
开发者ID:Merck,项目名称:Halyard,代码行数:22,代码来源:HalyardUpdateTest.java
示例19: setup
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
File rf = File.createTempFile("HalyardExportTest", "");
rf.delete();
rf.mkdirs();
ROOT = rf.toURI().toURL().toString();
if (!ROOT.endsWith("/")) {
ROOT = ROOT + "/";
}
ValueFactory vf = SimpleValueFactory.getInstance();
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null, null);
sail.initialize();
for (int i=0; i<10; i++) {
for (int j=0; j<10; j++) {
for (int k=0; k<10; k++) {
sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/pred" + j), vf.createLiteral("whatever\n\"\\" + k));
}
}
}
sail.commit();
sail.shutDown();
HalyardExport.conf = HBaseServerTestInstance.getInstanceConfig();
}
开发者ID:Merck,项目名称:Halyard,代码行数:24,代码来源:HalyardExportTest.java
示例20: testExport
import org.eclipse.rdf4j.model.ValueFactory; //导入依赖的package包/类
@Test
public void testExport() throws Exception {
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "exportTable", true, 0, true, 0, null, null);
sail.initialize();
ValueFactory vf = SimpleValueFactory.getInstance();
for (int i = 0; i < 1000; i++) {
sail.addStatement(vf.createIRI("http://whatever/NTsubj"), vf.createIRI("http://whatever/NTpred" + i), vf.createLiteral("whatever NT value " + i));
}
sail.commit();
sail.close();
File root = File.createTempFile("test_export", "");
root.delete();
root.mkdirs();
assertEquals(0, ToolRunner.run(HBaseServerTestInstance.getInstanceConfig(), new HalyardParallelExport(),
new String[]{"-Dmapreduce.job.maps=2", "-s", "exportTable", "-q", "PREFIX halyard: <http://merck.github.io/Halyard/ns#>\nselect * where {?s ?p ?o .\nFILTER (halyard:parallelSplitBy (?p))}", "-t", root.toURI().toURL().toString() + "data{0}.csv"}));
File f0 = new File(root, "data0.csv");
File f1 = new File(root, "data1.csv");
assertTrue(f0.isFile());
assertTrue(f1.isFile());
assertEquals(1002, HalyardExportTest.getLinesCount(f0.toURI().toURL().toString(), null) + HalyardExportTest.getLinesCount(f1.toURI().toURL().toString(), null));
}
开发者ID:Merck,项目名称:Halyard,代码行数:25,代码来源:HalyardParallelExportTest.java
注:本文中的org.eclipse.rdf4j.model.ValueFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论